From dc982b000c4db765ef4e6805cfc75dcdeee6d4f7 Mon Sep 17 00:00:00 2001 From: Sollace Date: Thu, 24 Sep 2020 21:02:03 +0200 Subject: [PATCH] Added a villager behaviour --- .../entity/behaviour/EntityBehaviour.java | 1 + .../entity/behaviour/VillagerBehaviour.java | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 src/main/java/com/minelittlepony/unicopia/entity/behaviour/VillagerBehaviour.java 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 6202378b..1c4bf91c 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/EntityBehaviour.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/EntityBehaviour.java @@ -176,6 +176,7 @@ public class EntityBehaviour { } static { + register(VillagerBehaviour::new, EntityType.VILLAGER, EntityType.WANDERING_TRADER); register(SheepBehaviour::new, EntityType.SHEEP); register(EndermanBehaviour::new, EntityType.ENDERMAN); register(SpellcastingIllagerBehaviour::new, EntityType.ILLUSIONER, EntityType.EVOKER); diff --git a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/VillagerBehaviour.java b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/VillagerBehaviour.java new file mode 100644 index 00000000..f2878dc6 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/VillagerBehaviour.java @@ -0,0 +1,26 @@ +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.AbstractTraderEntity; +import net.minecraft.sound.SoundEvents; + +public class VillagerBehaviour extends EntityBehaviour { + @Override + public void update(Caster source, AbstractTraderEntity entity, Spell spell) { + + if (source instanceof Pony) { + Pony player = (Pony)source; + + if (player.sneakingChanged() && player.getOwner().isSneaking()) { + entity.setHeadRollingTimeLeft(40); + + if (!entity.world.isClient()) { + entity.playSound(SoundEvents.ENTITY_VILLAGER_NO, 1, 1); + } + } + } + } +}