diff --git a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/EntityBehaviour.java b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/EntityBehaviour.java index 2662ef70..bd2e55f8 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/EntityBehaviour.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/EntityBehaviour.java @@ -241,6 +241,7 @@ public class EntityBehaviour { register(TraderBehaviour::new, EntityType.VILLAGER, EntityType.WANDERING_TRADER); register(SheepBehaviour::new, EntityType.SHEEP); register(BeeBehaviour::new, EntityType.BEE); + register(GhastBehaviour::new, EntityType.GHAST); register(EndermanBehaviour::new, EntityType.ENDERMAN); EntityBehaviour.register(() -> new RangedAttackBehaviour<>(SoundEvents.ENTITY_LLAMA_SPIT, LlamaSpitEntity::new), EntityType.LLAMA, EntityType.TRADER_LLAMA); EntityBehaviour.register(() -> new RangedAttackBehaviour<>(SoundEvents.ENTITY_SNOW_GOLEM_SHOOT, SnowballEntity::new), EntityType.SNOW_GOLEM); diff --git a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/GhastBehaviour.java b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/GhastBehaviour.java new file mode 100644 index 00000000..5e776f1c --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/GhastBehaviour.java @@ -0,0 +1,51 @@ +package com.minelittlepony.unicopia.entity.behaviour; + +import com.minelittlepony.unicopia.ability.magic.spell.DisguiseSpell; +import com.minelittlepony.unicopia.entity.player.Pony; + +import net.minecraft.entity.mob.GhastEntity; +import net.minecraft.entity.projectile.FireballEntity; +import net.minecraft.util.math.Vec3d; + +public class GhastBehaviour extends MobBehaviour { + + @Override + public void update(Pony player, GhastEntity entity, DisguiseSpell spell) { + + if (player.sneakingChanged()) { + boolean sneaking = player.getOwner().isSneaking(); + entity.setShooting(sneaking); + entity.setTarget(sneaking ? findTarget(player, entity) : null); + + if (sneaking) { + if (!entity.isSilent()) { + entity.world.syncWorldEvent(null, 1015, entity.getBlockPos(), 0); + } + } else { + Vec3d vec3d = entity.getRotationVec(1); + + if (!entity.isSilent()) { + entity.world.syncWorldEvent(null, 1016, entity.getBlockPos(), 0); + } + + Vec3d rot = player.getEntity().getRotationVec(1); + + FireballEntity fireballEntity = new FireballEntity(entity.world, entity, rot.getX(), rot.getY(), rot.getZ()); + fireballEntity.explosionPower = entity.getFireballStrength(); + fireballEntity.setOwner(player.getOwner()); + fireballEntity.updatePosition(entity.getX() + vec3d.x * 4, entity.getBodyY(0.5D) + 0.5D, fireballEntity.getZ() + vec3d.z * 4); + + entity.world.spawnEntity(fireballEntity); + } + } + } + + @Override + protected GhastEntity getDummy(GhastEntity entity) { + GhastEntity dummy = super.getDummy(entity); + + Vec3d pos = entity.getCameraPosVec(1).add(entity.getRotationVec(1)); + dummy.setPos(pos.x, pos.y, pos.z); + return dummy; + } +} diff --git a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/MobBehaviour.java b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/MobBehaviour.java index 3bdd46bd..db763a6b 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/MobBehaviour.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/MobBehaviour.java @@ -7,33 +7,37 @@ import com.minelittlepony.unicopia.util.RayTraceHelper; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.mob.MobEntity; -public class MobBehaviour extends EntityBehaviour { +public class MobBehaviour extends EntityBehaviour { - private MobEntity dummy; + private T dummy; @Override - public void onDestroy(MobEntity entity) { + public void onDestroy(T entity) { entity.setAiDisabled(false); super.onDestroy(entity); } @Override - public void update(Pony player, MobEntity entity, DisguiseSpell spell) { + public void update(Pony player, T entity, DisguiseSpell spell) { if (player.sneakingChanged() && isSneakingOnGround(player)) { - - LivingEntity target = RayTraceHelper.findEntity(player.getEntity(), 6, 1, - e -> e instanceof LivingEntity && e != entity && e != player.getOwner()) - .orElseGet(() -> getDummy(entity)); - + LivingEntity target = findTarget(player, entity); entity.tryAttack(target); target.setAttacker(player.getOwner()); } } - private MobEntity getDummy(MobEntity entity) { + protected LivingEntity findTarget(Pony player, T entity) { + return RayTraceHelper.findEntity(player.getEntity(), 6, 1, + e -> e instanceof LivingEntity && e != entity && e != player.getOwner()) + .orElseGet(() -> getDummy(entity)); + } + + @SuppressWarnings("unchecked") + protected T getDummy(T entity) { if (dummy == null) { - dummy = (MobEntity)entity.getType().create(entity.world); + dummy = (T)entity.getType().create(entity.world); } + return dummy; } }