Skip to content

Commit

Permalink
attach tags
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Aug 2, 2021
1 parent d795493 commit 8c93e7e
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2688,6 +2688,68 @@ else if (object.getBukkitEntity() instanceof Hanging) {
}
return new ElementTag(((FishHook) object.getBukkitEntity()).isInOpenWater());
});

// <--[tag]
// @attribute <EntityTag.attached_entities[(<player>)]>
// @returns ListTag(EntityTag)
// @description
// Returns the entities attached to this entity by <@link command attach>.
// Optionally, specify a player. If specified, will return entities attached visible to that player. If not specified, returns entities globally attached.
// -->
registerSpawnedOnlyTag("attached_entities", (attribute, object) -> {
PlayerTag player = attribute.hasContext(1) ? attribute.contextAsType(1, PlayerTag.class) : null;
EntityAttachmentHelper.EntityAttachedToMap data = EntityAttachmentHelper.toEntityToData.get(object.getUUID());
ListTag result = new ListTag();
if (data == null) {
return result;
}
for (EntityAttachmentHelper.PlayerAttachMap map : data.attachedToMap.values()) {
if (player == null || map.getAttachment(player.getUUID()) != null) {
result.addObject(map.attached);
}
}
return result;
});

// <--[tag]
// @attribute <EntityTag.attached_to[(<player>)]>
// @returns EntityTag
// @description
// Returns the entity that this entity was attached to by <@link command attach>.
// Optionally, specify a player. If specified, will return entity attachment visible to that player. If not specified, returns any entity global attachment.
// -->
registerSpawnedOnlyTag("attached_to", (attribute, object) -> {
PlayerTag player = attribute.hasContext(1) ? attribute.contextAsType(1, PlayerTag.class) : null;
EntityAttachmentHelper.PlayerAttachMap data = EntityAttachmentHelper.attachedEntityToData.get(object.getUUID());
if (data == null) {
return null;
}
EntityAttachmentHelper.AttachmentData attached = data.getAttachment(player == null ? null : player.getUUID());
if (attached == null) {
return null;
}
return attached.to;
});

// <--[tag]
// @attribute <EntityTag.attached_offset[(<player>)]>
// @returns LocationTag
// @description
// Returns the offset of an attachment for this entity to another that was attached by <@link command attach>.
// Optionally, specify a player. If specified, will return entity attachment visible to that player. If not specified, returns any entity global attachment.
// -->
registerSpawnedOnlyTag("attached_offset", (attribute, object) -> {
PlayerTag player = attribute.hasContext(1) ? attribute.contextAsType(1, PlayerTag.class) : null;
EntityAttachmentHelper.PlayerAttachMap data = EntityAttachmentHelper.attachedEntityToData.get(object.getUUID());
if (data == null) {
return null;
}
EntityAttachmentHelper.AttachmentData attached = data.getAttachment(player == null ? null : player.getUUID());
if (attached == null) {
return null;
}
return attached.positionalOffset == null ? null : new LocationTag(attached.positionalOffset);
});
}

public EntityTag describe(TagContext context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ public AttachCommand() {
// It may be ideal to change setting "Packets.Auto init" in the Denizen config to "true" to guarantee this command functions as expected.
//
// @Tags
// None
// <EntityTag.attached_entities[(<player>)]>
// <EntityTag.attached_to[(<player>)]>
// <EntityTag.attached_offset[(<player>)]>
//
// @Usage
// Use to attach random NPC to the air 3 blocks above a linked NPC.
Expand Down

0 comments on commit 8c93e7e

Please sign in to comment.