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 266ed34d..7c72d0c9 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/EntityBehaviour.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/EntityBehaviour.java @@ -218,6 +218,7 @@ public class EntityBehaviour { static { register(FallingBlockBehaviour::new, EntityType.FALLING_BLOCK); register(RavagerBehaviour::new, EntityType.RAVAGER); + register(RabbitBehaviour::new, EntityType.RABBIT); register(VillagerBehaviour::new, EntityType.VILLAGER, EntityType.WANDERING_TRADER); register(SheepBehaviour::new, EntityType.SHEEP); register(BeeBehaviour::new, EntityType.BEE); diff --git a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/RabbitBehaviour.java b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/RabbitBehaviour.java new file mode 100644 index 00000000..0c0e585c --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/RabbitBehaviour.java @@ -0,0 +1,27 @@ +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.Entity; +import net.minecraft.entity.passive.RabbitEntity; + +public class RabbitBehaviour extends EntityBehaviour { + @Override + public void update(Caster source, RabbitEntity entity, Spell spell) { + + if (source instanceof Pony) { + Pony player = (Pony)source; + + if (player.getEntity().isOnGround()) { + if (Entity.squaredHorizontalLength(player.getEntity().getVelocity()) > 0.01) { + player.getOwner().jump(); + entity.startJump(); + } + } else if (player.landedChanged()) { + entity.startJump(); + } + } + } +} diff --git a/src/main/java/com/minelittlepony/unicopia/entity/player/Pony.java b/src/main/java/com/minelittlepony/unicopia/entity/player/Pony.java index 181c4cdb..0712cf17 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/Pony.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/Pony.java @@ -75,6 +75,7 @@ public class Pony implements Caster, Equine, Transmi private boolean speciesSet; private boolean speciesPersisted; private boolean prevSneaking; + private boolean prevLanded; @Nullable private Race clientPreferredRace; @@ -108,6 +109,10 @@ public class Pony implements Caster, Equine, Transmi return entity.isSneaking() != prevSneaking; } + public boolean landedChanged() { + return entity.isOnGround() != prevLanded; + } + @Override public void setSpecies(Race race) { race = race.validate(entity); @@ -278,6 +283,7 @@ public class Pony implements Caster, Equine, Transmi } prevSneaking = entity.isSneaking(); + prevLanded = entity.isOnGround(); } public Optional onImpact(float distance, float damageMultiplier) {