Skip to content

Commit

Permalink
support shulker_bullet targets
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Feb 25, 2021
1 parent 7fb9cfb commit 895feab
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
Expand Up @@ -894,13 +894,18 @@ else if (isFake) {
*/

public void target(LivingEntity target) {

if (!isSpawned() || !(entity instanceof Creature)) {
Debug.echoError(identify() + " is not a valid creature entity!");
if (!isSpawned()) {
return;
}

NMSHandler.getEntityHelper().setTarget((Creature) entity, target);
if (entity instanceof Creature) {
NMSHandler.getEntityHelper().setTarget((Creature) entity, target);
}
else if (entity instanceof ShulkerBullet) {
((ShulkerBullet) entity).setTarget(target);
}
else {
Debug.echoError(identify() + " is not an entity type that can hold a target!");
}
}

public void setEntity(Entity entity) {
Expand Down Expand Up @@ -1997,7 +2002,7 @@ else if (object.getBukkitEntity() instanceof Villager) {
// @returns EntityTag
// @group attributes
// @description
// Returns the target entity of the creature, if any.
// Returns the target entity of the creature or shulker_bullet, if any.
// This is the entity that a hostile mob is currently trying to attack.
// -->
registerSpawnedOnlyTag("target", (attribute, object) -> {
Expand All @@ -2007,6 +2012,12 @@ else if (object.getBukkitEntity() instanceof Villager) {
return new EntityTag(target);
}
}
else if (object.getBukkitEntity() instanceof ShulkerBullet) {
Entity target = ((ShulkerBullet) object.getLivingEntity()).getTarget();
if (target != null) {
return new EntityTag(target);
}
}
return null;
});

Expand Down
Expand Up @@ -132,7 +132,7 @@ public void execute(final ScriptEntry scriptEntry) {
if (persistent && entity.isLivingEntity()) {
entity.getLivingEntity().setRemoveWhenFarAway(false);
}
if (target != null && target.isLivingEntity()) {
if (target != null) {
entity.target(target.getLivingEntity());
}
}
Expand Down

0 comments on commit 895feab

Please sign in to comment.