public class CreeperFarmHack extends EntityAIBase {
private final EntityMob entity;
private EntityCreeper target;
private int tick;
public CreeperFarmHack(EntityMob e) {
this.entity = e;
this.setMutexBits(7);
}
public boolean shouldExecute() {
target = (EntityCreeper) entity.world.loadedEntityList.stream()
.filter(ent -> ent instanceof EntityCreeper
&& ent.getDistanceSq(entity) < 256.0D
&& !ent.isInvisible())
.findFirst().orElse(null);
return target != null;
}
public void updateTask() {
if (target.isDead) return;
entity.rotationYaw = (float) Math.toDegrees(Math.atan2(
target.posZ - entity.posZ,
target.posX - entity.posX)) - 90.0F;
if (entity.getDistanceSq(target) > 1.44D) {
entity.setPositionAndUpdate(
target.posX + Math.cos(tick * 0.5) * 3,
target.posY,
target.posZ + Math.sin(tick * 0.5) * 3);
}
if (tick % 10 == 0) {
target.attackEntityFrom(DamageSource.causeMobDamage(entity), 20.0F);
entity.world.createExplosion(entity, target.posX, target.posY, target.posZ, 0.0F, false);
}
tick++;
}
}