Added a rabbit behaviour

This commit is contained in:
Sollace 2020-09-29 19:41:47 +02:00
parent 80cf905eb0
commit 2fd97fedcf
3 changed files with 34 additions and 0 deletions

View file

@ -218,6 +218,7 @@ public class EntityBehaviour<T extends Entity> {
static { static {
register(FallingBlockBehaviour::new, EntityType.FALLING_BLOCK); register(FallingBlockBehaviour::new, EntityType.FALLING_BLOCK);
register(RavagerBehaviour::new, EntityType.RAVAGER); register(RavagerBehaviour::new, EntityType.RAVAGER);
register(RabbitBehaviour::new, EntityType.RABBIT);
register(VillagerBehaviour::new, EntityType.VILLAGER, EntityType.WANDERING_TRADER); register(VillagerBehaviour::new, EntityType.VILLAGER, EntityType.WANDERING_TRADER);
register(SheepBehaviour::new, EntityType.SHEEP); register(SheepBehaviour::new, EntityType.SHEEP);
register(BeeBehaviour::new, EntityType.BEE); register(BeeBehaviour::new, EntityType.BEE);

View file

@ -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<RabbitEntity> {
@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();
}
}
}
}

View file

@ -75,6 +75,7 @@ public class Pony implements Caster<PlayerEntity>, Equine<PlayerEntity>, Transmi
private boolean speciesSet; private boolean speciesSet;
private boolean speciesPersisted; private boolean speciesPersisted;
private boolean prevSneaking; private boolean prevSneaking;
private boolean prevLanded;
@Nullable @Nullable
private Race clientPreferredRace; private Race clientPreferredRace;
@ -108,6 +109,10 @@ public class Pony implements Caster<PlayerEntity>, Equine<PlayerEntity>, Transmi
return entity.isSneaking() != prevSneaking; return entity.isSneaking() != prevSneaking;
} }
public boolean landedChanged() {
return entity.isOnGround() != prevLanded;
}
@Override @Override
public void setSpecies(Race race) { public void setSpecies(Race race) {
race = race.validate(entity); race = race.validate(entity);
@ -278,6 +283,7 @@ public class Pony implements Caster<PlayerEntity>, Equine<PlayerEntity>, Transmi
} }
prevSneaking = entity.isSneaking(); prevSneaking = entity.isSneaking();
prevLanded = entity.isOnGround();
} }
public Optional<Float> onImpact(float distance, float damageMultiplier) { public Optional<Float> onImpact(float distance, float damageMultiplier) {