Skip to content

Commit

Permalink
entity Persistent tag/mech, also bit of EntityTag cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Aug 1, 2020
1 parent b26e3f9 commit 0c6d1fd
Showing 1 changed file with 21 additions and 24 deletions.
Expand Up @@ -2047,13 +2047,18 @@ else if (mtr.angle == BlockFace.EAST) {
});

// <--[tag]
// @attribute <EntityTag.remove_when_far>
// @attribute <EntityTag.persistent>
// @returns ElementTag(Boolean)
// @group attributes
// @mechanism EntityTag.persistent
// @description
// Returns whether the entity despawns when away from players.
// Returns whether the entity should be be saved to file when chunks unload (otherwise, the entity is gone entirely if despawned for any reason).
// -->
registerSpawnedOnlyTag("persistent", (attribute, object) -> {
return new ElementTag(!object.getLivingEntity().getRemoveWhenFarAway());
});
registerSpawnedOnlyTag("remove_when_far", (attribute, object) -> {
Deprecations.entityRemoveWhenFar.warn(attribute.context);
return new ElementTag(object.getLivingEntity().getRemoveWhenFarAway());
});

Expand Down Expand Up @@ -2790,8 +2795,7 @@ public void adjust(Mechanism mechanism) {
// @tags
// <EntityTag.left_shoulder>
// -->
if (getLivingEntity() instanceof HumanEntity
&& mechanism.matches("release_left_shoulder")) {
if (mechanism.matches("release_left_shoulder") && getLivingEntity() instanceof HumanEntity) {
Entity bukkitEnt = ((HumanEntity) getLivingEntity()).getShoulderEntityLeft();
if (bukkitEnt != null) {
EntityTag ent = new EntityTag(bukkitEnt);
Expand All @@ -2813,8 +2817,7 @@ public void adjust(Mechanism mechanism) {
// @tags
// <EntityTag.right_shoulder>
// -->
if (getLivingEntity() instanceof HumanEntity
&& mechanism.matches("release_right_shoulder")) {
if (mechanism.matches("release_right_shoulder") && getLivingEntity() instanceof HumanEntity) {
Entity bukkitEnt = ((HumanEntity) getLivingEntity()).getShoulderEntityRight();
if (bukkitEnt != null) {
EntityTag ent = new EntityTag(bukkitEnt);
Expand All @@ -2839,8 +2842,7 @@ public void adjust(Mechanism mechanism) {
// @tags
// <EntityTag.left_shoulder>
// -->
if (getLivingEntity() instanceof HumanEntity
&& mechanism.matches("left_shoulder")) {
if (mechanism.matches("left_shoulder") && getLivingEntity() instanceof HumanEntity) {
if (mechanism.hasValue()) {
if (mechanism.requireObject(EntityTag.class)) {
((HumanEntity) getLivingEntity()).setShoulderEntityLeft(mechanism.valueAsType(EntityTag.class).getBukkitEntity());
Expand All @@ -2864,8 +2866,7 @@ public void adjust(Mechanism mechanism) {
// @tags
// <EntityTag.right_shoulder>
// -->
if (getLivingEntity() instanceof HumanEntity
&& mechanism.matches("right_shoulder")) {
if (mechanism.matches("right_shoulder") && getLivingEntity() instanceof HumanEntity) {
if (mechanism.hasValue()) {
if (mechanism.requireObject(EntityTag.class)) {
((HumanEntity) getLivingEntity()).setShoulderEntityRight(mechanism.valueAsType(EntityTag.class).getBukkitEntity());
Expand All @@ -2878,15 +2879,19 @@ public void adjust(Mechanism mechanism) {

// <--[mechanism]
// @object EntityTag
// @name remove_when_far_away
// @name persistent
// @input ElementTag(Boolean)
// @description
// Sets whether the entity should be removed entirely when despawned.
// Sets whether the entity should be be saved to file when chunks unload (otherwise, the entity is gone entirely if despawned for any reason).
// The entity must be living.
// @tags
// <EntityTag.remove_when_far>
// <EntityTag.persistent>
// -->
if (mechanism.matches("persistent") && mechanism.requireBoolean()) {
getLivingEntity().setRemoveWhenFarAway(!mechanism.getValue().asBoolean());
}
if (mechanism.matches("remove_when_far_away") && mechanism.requireBoolean()) {
Deprecations.entityRemoveWhenFar.warn(mechanism.context);
getLivingEntity().setRemoveWhenFarAway(mechanism.getValue().asBoolean());
}

Expand All @@ -2899,8 +2904,7 @@ public void adjust(Mechanism mechanism) {
// @tags
// <EntityTag.is_sheared>
// -->
if (mechanism.matches("sheared") && mechanism.requireBoolean()
&& getBukkitEntity() instanceof Sheep) {
if (mechanism.matches("sheared") && mechanism.requireBoolean() && getBukkitEntity() instanceof Sheep) {
((Sheep) getBukkitEntity()).setSheared(mechanism.getValue().asBoolean());
}

Expand All @@ -2914,8 +2918,7 @@ && getBukkitEntity() instanceof Sheep) {
// @tags
// <EntityTag.is_collidable>
// -->
if (mechanism.matches("collidable")
&& mechanism.requireBoolean()) {
if (mechanism.matches("collidable") && mechanism.requireBoolean()) {
getLivingEntity().setCollidable(mechanism.getValue().asBoolean());
}

Expand Down Expand Up @@ -2983,14 +2986,8 @@ && getBukkitEntity() instanceof Sheep) {
NMSHandler.getEntityHelper().forceInteraction(getPlayer(), interactLocation);
}

// <--[mechanism]
// @object EntityTag
// @name play_death
// @input None
// @description
// Animates the entity dying.
// -->
if (mechanism.matches("play_death")) {
Deprecations.entityPlayDeath.warn(mechanism.context);
getLivingEntity().playEffect(EntityEffect.DEATH);
}

Expand Down

0 comments on commit 0c6d1fd

Please sign in to comment.