Added behaviours for slimes and magma cubes

This commit is contained in:
Sollace 2020-09-30 22:18:47 +02:00
parent 0059e92c2e
commit dd2e2a1f81
5 changed files with 35 additions and 10 deletions

View file

@ -89,7 +89,7 @@ public class Disguise implements NbtSerialisable {
public void remove() { public void remove() {
attachments.clear(); attachments.clear();
if (entity != null) { if (entity != null) {
entity.remove(); EntityBehaviour.forEntity(entity).onDestroy(entity);
entity = null; entity = null;
} }
if (blockEntity != null) { if (blockEntity != null) {

View file

@ -51,6 +51,12 @@ public class EntityBehaviour<T extends Entity> {
return entity; return entity;
} }
public void onDestroy(T entity) {
entity.setInvulnerable(false);
entity.setNoGravity(false);
entity.remove();
}
public Optional<EntityDimensions> getDimensions(T entity, Optional<EntityDimensions> current) { public Optional<EntityDimensions> getDimensions(T entity, Optional<EntityDimensions> current) {
if (entity == null) { if (entity == null) {
return Optional.empty(); return Optional.empty();
@ -231,7 +237,7 @@ public class EntityBehaviour<T extends Entity> {
static { static {
register(FallingBlockBehaviour::new, EntityType.FALLING_BLOCK); register(FallingBlockBehaviour::new, EntityType.FALLING_BLOCK);
register(MobBehaviour::new, EntityType.RAVAGER, EntityType.IRON_GOLEM); register(MobBehaviour::new, EntityType.RAVAGER, EntityType.IRON_GOLEM);
register(RabbitBehaviour::new, EntityType.RABBIT); register(HoppingBehaviour::new, EntityType.RABBIT, EntityType.SLIME, EntityType.MAGMA_CUBE);
register(TraderBehaviour::new, EntityType.VILLAGER, EntityType.WANDERING_TRADER); register(TraderBehaviour::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

@ -24,18 +24,27 @@ import net.minecraft.state.property.Properties;
import net.minecraft.tag.BlockTags; import net.minecraft.tag.BlockTags;
import net.minecraft.util.Tickable; import net.minecraft.util.Tickable;
import net.minecraft.util.math.Direction; import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Direction.Axis;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
import net.minecraft.util.shape.VoxelShape;
public class FallingBlockBehaviour extends EntityBehaviour<FallingBlockEntity> { public class FallingBlockBehaviour extends EntityBehaviour<FallingBlockEntity> {
private static final Vec3d UP = Vec3d.of(Direction.UP.getVector()); private static final Vec3d UP = Vec3d.of(Direction.UP.getVector());
private static final Optional<EntityDimensions> FULL_BLOCK = Optional.of(EntityDimensions.changing(1, 0.9F)); // private static final Optional<EntityDimensions> FULL_BLOCK = Optional.of(EntityDimensions.changing(0.6F, 0.9F));
@Override @Override
public Optional<EntityDimensions> getDimensions(FallingBlockEntity entity, Optional<EntityDimensions> current) { public Optional<EntityDimensions> getDimensions(FallingBlockEntity entity, Optional<EntityDimensions> current) {
return FULL_BLOCK;
VoxelShape shape = entity.getBlockState().getCollisionShape(entity.world, entity.getBlockPos());
float height = (float)shape.getMax(Axis.Y);
if (!current.isPresent() || current.get().height != height) {
return Optional.of(EntityDimensions.changing(0.6F, height));
}
return current;
} }
@Override @Override

View file

@ -4,19 +4,24 @@ import com.minelittlepony.unicopia.ability.magic.spell.DisguiseSpell;
import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.entity.player.Pony;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.passive.RabbitEntity; import net.minecraft.entity.passive.RabbitEntity;
public class RabbitBehaviour extends EntityBehaviour<RabbitEntity> { public class HoppingBehaviour extends EntityBehaviour<LivingEntity> {
@Override @Override
public void update(Pony player, RabbitEntity entity, DisguiseSpell spell) { public void update(Pony player, LivingEntity entity, DisguiseSpell spell) {
if (player.getEntity().isOnGround()) { if (player.getEntity().isOnGround()) {
if (Entity.squaredHorizontalLength(player.getEntity().getVelocity()) > 0.01) { if (Entity.squaredHorizontalLength(player.getEntity().getVelocity()) > 0.01) {
player.getOwner().jump(); player.getOwner().jump();
entity.startJump(); if (entity instanceof RabbitEntity) {
((RabbitEntity)entity).startJump();
}
} }
} else if (player.landedChanged()) { } else if (player.landedChanged()) {
entity.startJump(); if (entity instanceof RabbitEntity) {
((RabbitEntity)entity).startJump();
}
} }
} }
} }

View file

@ -12,8 +12,13 @@ public class MobBehaviour extends EntityBehaviour<MobEntity> {
private MobEntity dummy; private MobEntity dummy;
@Override @Override
public void update(Pony player, MobEntity entity, DisguiseSpell spell) { public void onDestroy(MobEntity entity) {
entity.setAiDisabled(false);
super.onDestroy(entity);
}
@Override
public void update(Pony player, MobEntity entity, DisguiseSpell spell) {
if (player.sneakingChanged() && isSneakingOnGround(player)) { if (player.sneakingChanged() && isSneakingOnGround(player)) {
LivingEntity target = RayTraceHelper.<LivingEntity>findEntity(player.getEntity(), 6, 1, LivingEntity target = RayTraceHelper.<LivingEntity>findEntity(player.getEntity(), 6, 1,