From e177f74c8fe65ba678b130d359c301057cd821e9 Mon Sep 17 00:00:00 2001 From: Sollace Date: Sun, 27 Sep 2020 20:47:27 +0200 Subject: [PATCH] Added llama behaviours --- .../entity/behaviour/CreeperBehaviour.java | 7 ---- .../entity/behaviour/EntityBehaviour.java | 6 +++ .../entity/behaviour/LlamaBehaviour.java | 39 +++++++++++++++++++ 3 files changed, 45 insertions(+), 7 deletions(-) create mode 100644 src/main/java/com/minelittlepony/unicopia/entity/behaviour/LlamaBehaviour.java diff --git a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/CreeperBehaviour.java b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/CreeperBehaviour.java index 2f5c99cb..1887648f 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/CreeperBehaviour.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/CreeperBehaviour.java @@ -3,9 +3,7 @@ package com.minelittlepony.unicopia.entity.behaviour; import com.minelittlepony.unicopia.ability.magic.Caster; import com.minelittlepony.unicopia.ability.magic.Spell; -import net.minecraft.entity.Entity; import net.minecraft.entity.mob.CreeperEntity; -import net.minecraft.entity.player.PlayerEntity; public class CreeperBehaviour extends EntityBehaviour { @Override @@ -18,9 +16,4 @@ public class CreeperBehaviour extends EntityBehaviour { entity.getVisibilityCache().clear(); } } - - protected boolean isSneakingOnGround(Caster source) { - Entity e = source.getEntity(); - return e.isSneaking() && (e.isOnGround() || !(e instanceof PlayerEntity && ((PlayerEntity)e).abilities.flying)); - } } 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 8757dd19..b2030742 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/EntityBehaviour.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/EntityBehaviour.java @@ -172,6 +172,11 @@ public class EntityBehaviour { return false; } + protected boolean isSneakingOnGround(Caster source) { + Entity e = source.getEntity(); + return e.isSneaking() && (e.isOnGround() || !(e instanceof PlayerEntity && ((PlayerEntity)e).abilities.flying)); + } + public static void register(Supplier> behaviour, EntityType... types) { for (EntityType type : types) { Registry.register(REGISTRY, EntityType.getId(type), behaviour.get()); @@ -192,6 +197,7 @@ public class EntityBehaviour { register(SheepBehaviour::new, EntityType.SHEEP); register(BeeBehaviour::new, EntityType.BEE); register(EndermanBehaviour::new, EntityType.ENDERMAN); + register(LlamaBehaviour::new, EntityType.LLAMA, EntityType.TRADER_LLAMA); register(SpellcastingIllagerBehaviour::new, EntityType.ILLUSIONER, EntityType.EVOKER); register(ShulkerBehaviour::new, EntityType.SHULKER); register(CreeperBehaviour::new, EntityType.CREEPER); diff --git a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/LlamaBehaviour.java b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/LlamaBehaviour.java new file mode 100644 index 00000000..7be7e470 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/LlamaBehaviour.java @@ -0,0 +1,39 @@ +package com.minelittlepony.unicopia.entity.behaviour; + +import com.minelittlepony.unicopia.ability.magic.Caster; +import com.minelittlepony.unicopia.ability.magic.Spell; +import com.minelittlepony.unicopia.entity.player.Pony; +import net.minecraft.entity.passive.LlamaEntity; +import net.minecraft.entity.projectile.LlamaSpitEntity; +import net.minecraft.sound.SoundEvents; +import net.minecraft.util.math.Vec3d; + +public class LlamaBehaviour extends EntityBehaviour { + + @Override + public void update(Caster source, LlamaEntity entity, Spell spell) { + + if (source instanceof Pony) { + Pony player = (Pony)source; + + if (player.sneakingChanged() && isSneakingOnGround(player)) { + + LlamaSpitEntity spit = new LlamaSpitEntity(entity.world, entity); + + Vec3d rot = source.getEntity().getRotationVec(1); + + spit.setVelocity(rot.getX(), rot.getY(), rot.getZ(), 1.5F, 3); + spit.setOwner(source.getOwner()); + + if (!entity.isSilent()) { + entity.world.playSound(null, entity.getX(), entity.getY(), entity.getZ(), + SoundEvents.ENTITY_LLAMA_SPIT, entity.getSoundCategory(), 1, + 1 + (entity.world.random.nextFloat() - entity.world.random.nextFloat()) * 0.2F); + } + + entity.world.spawnEntity(spit); + } + } + + } +}