diff --git a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/BeeBehaviour.java b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/BeeBehaviour.java index d6a2bc17..6ab1284b 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/BeeBehaviour.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/BeeBehaviour.java @@ -1,7 +1,8 @@ package com.minelittlepony.unicopia.entity.behaviour; import com.minelittlepony.unicopia.ability.magic.Caster; -import com.minelittlepony.unicopia.ability.magic.Spell; +import com.minelittlepony.unicopia.ability.magic.spell.DisguiseSpell; + import net.minecraft.client.MinecraftClient; import net.minecraft.client.sound.AggressiveBeeSoundInstance; import net.minecraft.client.sound.PassiveBeeSoundInstance; @@ -20,7 +21,7 @@ public class BeeBehaviour extends EntityBehaviour { } @Override - public void update(Caster source, BeeEntity entity, Spell spell) { + public void update(Caster source, BeeEntity entity, DisguiseSpell spell) { if (source.getOwner().isSneaking()) { entity.setAngerTime(10); diff --git a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/ChickenBehaviour.java b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/ChickenBehaviour.java index 846d2008..d9294ea0 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/ChickenBehaviour.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/ChickenBehaviour.java @@ -1,7 +1,7 @@ package com.minelittlepony.unicopia.entity.behaviour; import com.minelittlepony.unicopia.ability.magic.Caster; -import com.minelittlepony.unicopia.ability.magic.Spell; +import com.minelittlepony.unicopia.ability.magic.spell.DisguiseSpell; import com.minelittlepony.unicopia.entity.player.Pony; import net.minecraft.entity.Entity; @@ -21,7 +21,7 @@ public class ChickenBehaviour extends EntityBehaviour { } @Override - public void update(Caster source, ChickenEntity entity, Spell spell) { + public void update(Caster source, ChickenEntity entity, DisguiseSpell spell) { entity.eggLayTime = Integer.MAX_VALUE; if (source instanceof Pony) { 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 1887648f..36da18ab 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/CreeperBehaviour.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/CreeperBehaviour.java @@ -1,13 +1,13 @@ package com.minelittlepony.unicopia.entity.behaviour; import com.minelittlepony.unicopia.ability.magic.Caster; -import com.minelittlepony.unicopia.ability.magic.Spell; +import com.minelittlepony.unicopia.ability.magic.spell.DisguiseSpell; import net.minecraft.entity.mob.CreeperEntity; public class CreeperBehaviour extends EntityBehaviour { @Override - public void update(Caster source, CreeperEntity entity, Spell spell) { + public void update(Caster source, CreeperEntity entity, DisguiseSpell spell) { if (isSneakingOnGround(source)) { entity.setFuseSpeed(1); } else { diff --git a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/EndermanBehaviour.java b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/EndermanBehaviour.java index 910f9c6d..c88efd9d 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/EndermanBehaviour.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/EndermanBehaviour.java @@ -1,7 +1,7 @@ package com.minelittlepony.unicopia.entity.behaviour; import com.minelittlepony.unicopia.ability.magic.Caster; -import com.minelittlepony.unicopia.ability.magic.Spell; +import com.minelittlepony.unicopia.ability.magic.spell.DisguiseSpell; import net.minecraft.entity.mob.EndermanEntity; import net.minecraft.item.BlockItem; @@ -10,7 +10,7 @@ import net.minecraft.util.Hand; public class EndermanBehaviour extends EntityBehaviour { @Override - public void update(Caster source, EndermanEntity entity, Spell spell) { + public void update(Caster source, EndermanEntity entity, DisguiseSpell spell) { if (source.getOwner().isSneaking() || source.getOwner().isSprinting()) { entity.setTarget(entity); } else { 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 a44a6728..7798c624 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/EntityBehaviour.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/EntityBehaviour.java @@ -6,8 +6,9 @@ import java.util.function.Supplier; import javax.annotation.Nullable; import com.minelittlepony.unicopia.ability.magic.Caster; -import com.minelittlepony.unicopia.ability.magic.Spell; +import com.minelittlepony.unicopia.ability.magic.spell.DisguiseSpell; import com.minelittlepony.unicopia.entity.ItemWielder; +import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.util.Registries; import net.minecraft.entity.Entity; @@ -35,7 +36,13 @@ public class EntityBehaviour { private static final EntityBehaviour DEFAULT = new EntityBehaviour<>(); private static final Registry> REGISTRY = Registries.createSimple(new Identifier("unicopia", "entity_behaviour")); - public void update(Caster source, T entity, Spell spell) { + public void update(Caster source, T entity, DisguiseSpell spell) { + if (source instanceof Pony) { + update((Pony)source, entity, spell); + } + } + + protected void update(Pony pony, T entity, DisguiseSpell spell) { } @@ -224,7 +231,7 @@ public class EntityBehaviour { register(FallingBlockBehaviour::new, EntityType.FALLING_BLOCK); register(MobBehaviour::new, EntityType.RAVAGER, EntityType.IRON_GOLEM); register(RabbitBehaviour::new, EntityType.RABBIT); - register(VillagerBehaviour::new, EntityType.VILLAGER, EntityType.WANDERING_TRADER); + register(TraderBehaviour::new, EntityType.VILLAGER, EntityType.WANDERING_TRADER); register(SheepBehaviour::new, EntityType.SHEEP); register(BeeBehaviour::new, EntityType.BEE); register(EndermanBehaviour::new, EntityType.ENDERMAN); diff --git a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/FallingBlockBehaviour.java b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/FallingBlockBehaviour.java index c00c3272..ddf0717e 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/FallingBlockBehaviour.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/FallingBlockBehaviour.java @@ -4,7 +4,6 @@ import java.util.List; import java.util.Optional; import com.minelittlepony.unicopia.ability.magic.Caster; -import com.minelittlepony.unicopia.ability.magic.Spell; import com.minelittlepony.unicopia.ability.magic.spell.DisguiseSpell; import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.mixin.MixinBlockEntity; @@ -68,7 +67,7 @@ public class FallingBlockBehaviour extends EntityBehaviour { } @Override - public void update(Caster source, FallingBlockEntity entity, Spell spell) { + public void update(Caster source, FallingBlockEntity entity, DisguiseSpell spell) { BlockState state = entity.getBlockState(); if (state.contains(Properties.WATERLOGGED)) { @@ -76,12 +75,12 @@ public class FallingBlockBehaviour extends EntityBehaviour { if (state.get(Properties.WATERLOGGED) != logged) { entity = new FallingBlockEntity(entity.world, entity.getX(), entity.getY(), entity.getZ(), state.with(Properties.WATERLOGGED, logged)); - ((DisguiseSpell)spell).getDisguise().setAppearance(entity); + spell.getDisguise().setAppearance(entity); return; } } - Disguise disguise = ((DisguiseSpell)spell).getDisguise(); + Disguise disguise = spell.getDisguise(); List attachments = disguise.getAttachments(); if (attachments.size() > 0) { copyBaseAttributes(source.getOwner(), attachments.get(0), UP); diff --git a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/MinecartBehaviour.java b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/MinecartBehaviour.java index 0115025d..64b5fadd 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/MinecartBehaviour.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/MinecartBehaviour.java @@ -1,7 +1,7 @@ package com.minelittlepony.unicopia.entity.behaviour; import com.minelittlepony.unicopia.ability.magic.Caster; -import com.minelittlepony.unicopia.ability.magic.Spell; +import com.minelittlepony.unicopia.ability.magic.spell.DisguiseSpell; import net.minecraft.client.MinecraftClient; import net.minecraft.client.sound.MovingMinecartSoundInstance; @@ -20,7 +20,7 @@ public class MinecartBehaviour extends EntityBehaviour { } @Override - public void update(Caster source, AbstractMinecartEntity entity, Spell spell) { + public void update(Caster source, AbstractMinecartEntity entity, DisguiseSpell spell) { entity.yaw -= 90; entity.prevYaw -= 90; diff --git a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/MobBehaviour.java b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/MobBehaviour.java index e4312f29..9758e036 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/MobBehaviour.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/MobBehaviour.java @@ -1,7 +1,6 @@ package com.minelittlepony.unicopia.entity.behaviour; -import com.minelittlepony.unicopia.ability.magic.Caster; -import com.minelittlepony.unicopia.ability.magic.Spell; +import com.minelittlepony.unicopia.ability.magic.spell.DisguiseSpell; import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.util.RayTraceHelper; @@ -10,14 +9,10 @@ import net.minecraft.entity.mob.MobEntity; public class MobBehaviour extends EntityBehaviour { @Override - public void update(Caster source, MobEntity entity, Spell spell) { + public void update(Pony player, MobEntity entity, DisguiseSpell spell) { - if (source instanceof Pony) { - Pony player = (Pony)source; - - if (player.sneakingChanged() && isSneakingOnGround(source)) { - entity.tryAttack(RayTraceHelper.findEntity(source.getEntity(), 6, 1, e -> e instanceof LivingEntity).orElse(entity)); - } + if (player.sneakingChanged() && isSneakingOnGround(player)) { + entity.tryAttack(RayTraceHelper.findEntity(player.getEntity(), 6, 1, e -> e instanceof LivingEntity).orElse(entity)); } } } diff --git a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/RabbitBehaviour.java b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/RabbitBehaviour.java index 0c0e585c..55927d2c 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/RabbitBehaviour.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/RabbitBehaviour.java @@ -1,7 +1,6 @@ package com.minelittlepony.unicopia.entity.behaviour; -import com.minelittlepony.unicopia.ability.magic.Caster; -import com.minelittlepony.unicopia.ability.magic.Spell; +import com.minelittlepony.unicopia.ability.magic.spell.DisguiseSpell; import com.minelittlepony.unicopia.entity.player.Pony; import net.minecraft.entity.Entity; @@ -9,19 +8,15 @@ import net.minecraft.entity.passive.RabbitEntity; public class RabbitBehaviour extends EntityBehaviour { @Override - public void update(Caster source, RabbitEntity entity, Spell spell) { + public void update(Pony player, RabbitEntity entity, DisguiseSpell 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()) { + 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/behaviour/RangedAttackBehaviour.java b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/RangedAttackBehaviour.java index da994ae1..bb7e7c31 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/RangedAttackBehaviour.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/RangedAttackBehaviour.java @@ -1,8 +1,7 @@ package com.minelittlepony.unicopia.entity.behaviour; import java.util.function.BiFunction; -import com.minelittlepony.unicopia.ability.magic.Caster; -import com.minelittlepony.unicopia.ability.magic.Spell; +import com.minelittlepony.unicopia.ability.magic.spell.DisguiseSpell; import com.minelittlepony.unicopia.entity.player.Pony; import net.minecraft.entity.Entity; @@ -24,28 +23,24 @@ public class RangedAttackBehaviour extends E } @Override - public void update(Caster source, T entity, Spell spell) { + public void update(Pony player, T entity, DisguiseSpell spell) { - if (source instanceof Pony) { - Pony player = (Pony)source; + if (player.sneakingChanged() && isSneakingOnGround(player)) { - if (player.sneakingChanged() && isSneakingOnGround(player)) { + ProjectileEntity spit = projectileSupplier.apply(entity.world, entity); - ProjectileEntity spit = projectileSupplier.apply(entity.world, entity); + Vec3d rot = player.getEntity().getRotationVec(1); - Vec3d rot = source.getEntity().getRotationVec(1); + spit.setVelocity(rot.getX(), rot.getY(), rot.getZ(), 1.5F, 3); + spit.setOwner(player.getOwner()); - 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(), - sound, entity.getSoundCategory(), 1, - 1 + (entity.world.random.nextFloat() - entity.world.random.nextFloat()) * 0.2F); - } - - entity.world.spawnEntity(spit); + if (!entity.isSilent()) { + entity.world.playSound(null, entity.getX(), entity.getY(), entity.getZ(), + sound, entity.getSoundCategory(), 1, + 1 + (entity.world.random.nextFloat() - entity.world.random.nextFloat()) * 0.2F); } + + entity.world.spawnEntity(spit); } } } diff --git a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/SheepBehaviour.java b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/SheepBehaviour.java index e37407c7..11f03619 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/SheepBehaviour.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/SheepBehaviour.java @@ -2,8 +2,7 @@ package com.minelittlepony.unicopia.entity.behaviour; import java.util.Random; -import com.minelittlepony.unicopia.ability.magic.Caster; -import com.minelittlepony.unicopia.ability.magic.Spell; +import com.minelittlepony.unicopia.ability.magic.spell.DisguiseSpell; import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.mixin.MixinSheepEntity; import com.minelittlepony.unicopia.util.WorldEvent; @@ -20,57 +19,54 @@ import net.minecraft.util.math.BlockPos; public class SheepBehaviour extends EntityBehaviour { @Override - public void update(Caster source, SheepEntity entity, Spell spell) { - if (source instanceof Pony) { - Pony player = (Pony)source; + public void update(Pony player, SheepEntity entity, DisguiseSpell spell) { - if (player.sneakingChanged()) { + if (player.sneakingChanged()) { - BlockPos pos = entity.getBlockPos().down(); - BlockState state = entity.world.getBlockState(pos); - boolean grass = state.isOf(Blocks.GRASS_BLOCK); + BlockPos pos = entity.getBlockPos().down(); + BlockState state = entity.world.getBlockState(pos); + boolean grass = state.isOf(Blocks.GRASS_BLOCK); - if (player.getOwner().isSneaking()) { - if (grass && entity.world.isClient && entity.isSheared()) { - entity.handleStatus((byte)10); - } - } else { - if (entity.isSheared() && grass) { - WorldEvent.play(WorldEvent.DESTROY_BLOCK, entity.world, pos, state); - entity.world.setBlockState(pos, Blocks.DIRT.getDefaultState(), 2); - - entity.onEatingGrass(); - } else if (!entity.isSheared()) { - ItemStack dropType = new ItemStack(MixinSheepEntity.getDrops().get(entity.getColor()).asItem()); - - player.getOwner().playSound(SoundEvents.ENTITY_SHEEP_SHEAR, SoundCategory.PLAYERS, 1, 1); - entity.setSheared(true); - - Random rng = entity.world.random; - PlayerInventory inv = player.getOwner().inventory; - - int dropAmount = rng.nextInt(3); - int slot; - - do { - slot = inv.method_7371(dropType); - if (slot < 0) { - break; - } - inv.removeStack(slot, 1); - ItemEntity itemEntity = entity.dropItem(dropType.getItem(), 1); - if (itemEntity != null) { - itemEntity.setVelocity(itemEntity.getVelocity().add( - (rng.nextFloat() - rng.nextFloat()) * 0.1F, - rng.nextFloat() * 0.05F, - (rng.nextFloat() - rng.nextFloat()) * 0.1F - )); - itemEntity.setPickupDelay(40); - } - } while (dropAmount-- > 0); - } - spell.setDirty(true); + if (player.getOwner().isSneaking()) { + if (grass && entity.world.isClient && entity.isSheared()) { + entity.handleStatus((byte)10); } + } else { + if (entity.isSheared() && grass) { + WorldEvent.play(WorldEvent.DESTROY_BLOCK, entity.world, pos, state); + entity.world.setBlockState(pos, Blocks.DIRT.getDefaultState(), 2); + + entity.onEatingGrass(); + } else if (!entity.isSheared()) { + ItemStack dropType = new ItemStack(MixinSheepEntity.getDrops().get(entity.getColor()).asItem()); + + player.getOwner().playSound(SoundEvents.ENTITY_SHEEP_SHEAR, SoundCategory.PLAYERS, 1, 1); + entity.setSheared(true); + + Random rng = entity.world.random; + PlayerInventory inv = player.getOwner().inventory; + + int dropAmount = rng.nextInt(3); + int slot; + + do { + slot = inv.method_7371(dropType); + if (slot < 0) { + break; + } + inv.removeStack(slot, 1); + ItemEntity itemEntity = entity.dropItem(dropType.getItem(), 1); + if (itemEntity != null) { + itemEntity.setVelocity(itemEntity.getVelocity().add( + (rng.nextFloat() - rng.nextFloat()) * 0.1F, + rng.nextFloat() * 0.05F, + (rng.nextFloat() - rng.nextFloat()) * 0.1F + )); + itemEntity.setPickupDelay(40); + } + } while (dropAmount-- > 0); + } + spell.setDirty(true); } } } diff --git a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/ShulkerBehaviour.java b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/ShulkerBehaviour.java index 1af79c3c..2464ff37 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/ShulkerBehaviour.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/ShulkerBehaviour.java @@ -1,7 +1,7 @@ package com.minelittlepony.unicopia.entity.behaviour; import com.minelittlepony.unicopia.ability.magic.Caster; -import com.minelittlepony.unicopia.ability.magic.Spell; +import com.minelittlepony.unicopia.ability.magic.spell.DisguiseSpell; import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.mixin.MixinShulkerEntity; @@ -16,38 +16,14 @@ import net.minecraft.util.math.Vec3d; public class ShulkerBehaviour extends EntityBehaviour { @Override - public void update(Caster source, ShulkerEntity shulker, Spell spell) { + public void update(Caster source, ShulkerEntity shulker, DisguiseSpell spell) { shulker.yaw = 0; shulker.prevBodyYaw = 0; shulker.bodyYaw = 0; shulker.setAttachedBlock(null); - if (source instanceof Pony) { - Pony player = (Pony)source; - - float peekAmount = 30; - - double speed = !source.getEntity().isSneaking() ? 0.29 : 0; - speed += Math.sqrt(Entity.squaredHorizontalLength(source.getEntity().getVelocity())) * 2; - - peekAmount = (float)MathHelper.clamp(speed, 0, 1); - peekAmount = ((Pony)source).getInterpolator().interpolate("peek", peekAmount, 5); - - MixinShulkerEntity mx = (MixinShulkerEntity)shulker; - - mx.setPrevOpenProgress(mx.getOpenProgress()); - mx.setOpenProgress(peekAmount); - - if (player.sneakingChanged()) { - shulker.setPeekAmount((int)(peekAmount / 0.01F)); - } else if (peekAmount > 0.2 && shulker.getPeekAmount() == 0) { - if (shulker.isAlive() && shulker.world.random.nextInt(1000) < shulker.ambientSoundChance++) { - shulker.ambientSoundChance = -shulker.getMinAmbientSoundDelay(); - shulker.playSound(SoundEvents.ENTITY_SHULKER_AMBIENT, 1, 1); - } - } - } + super.update(source, shulker, spell); Direction attachmentFace = shulker.getAttachedFace(); BlockPos pos = shulker.getBlockPos().offset(attachmentFace); @@ -63,4 +39,29 @@ public class ShulkerBehaviour extends EntityBehaviour { } } } + + @Override + protected void update(Pony player, ShulkerEntity shulker, DisguiseSpell spell) { + float peekAmount = 30; + + double speed = !player.getEntity().isSneaking() ? 0.29 : 0; + speed += Math.sqrt(Entity.squaredHorizontalLength(player.getEntity().getVelocity())) * 2; + + peekAmount = (float)MathHelper.clamp(speed, 0, 1); + peekAmount = player.getInterpolator().interpolate("peek", peekAmount, 5); + + MixinShulkerEntity mx = (MixinShulkerEntity)shulker; + + mx.setPrevOpenProgress(mx.getOpenProgress()); + mx.setOpenProgress(peekAmount); + + if (player.sneakingChanged()) { + shulker.setPeekAmount((int)(peekAmount / 0.01F)); + } else if (peekAmount > 0.2 && shulker.getPeekAmount() == 0) { + if (shulker.isAlive() && shulker.world.random.nextInt(1000) < shulker.ambientSoundChance++) { + shulker.ambientSoundChance = -shulker.getMinAmbientSoundDelay(); + shulker.playSound(SoundEvents.ENTITY_SHULKER_AMBIENT, 1, 1); + } + } + } } diff --git a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/SilverfishBehaviour.java b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/SilverfishBehaviour.java index 62cf7b40..6ea77d19 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/SilverfishBehaviour.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/SilverfishBehaviour.java @@ -1,7 +1,6 @@ package com.minelittlepony.unicopia.entity.behaviour; -import com.minelittlepony.unicopia.ability.magic.Caster; -import com.minelittlepony.unicopia.ability.magic.Spell; +import com.minelittlepony.unicopia.ability.magic.spell.DisguiseSpell; import com.minelittlepony.unicopia.block.state.StateMaps; import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.util.WorldEvent; @@ -12,19 +11,15 @@ import net.minecraft.util.math.BlockPos; public class SilverfishBehaviour extends EntityBehaviour { @Override - public void update(Caster source, SilverfishEntity entity, Spell spell) { - if (source instanceof Pony && !source.isClient()) { - Pony player = (Pony)source; + public void update(Pony player, SilverfishEntity entity, DisguiseSpell spell) { + if (!player.isClient() && player.sneakingChanged() && player.getOwner().isSneaking()) { + BlockPos pos = entity.getBlockPos().down(); + BlockState state = entity.world.getBlockState(pos); - if (player.sneakingChanged() && player.getOwner().isSneaking()) { - BlockPos pos = entity.getBlockPos().down(); - BlockState state = entity.world.getBlockState(pos); + if (StateMaps.SILVERFISH_AFFECTED.canConvert(state)) { - if (StateMaps.SILVERFISH_AFFECTED.canConvert(state)) { - - entity.world.setBlockState(pos, StateMaps.SILVERFISH_AFFECTED.getConverted(state)); - WorldEvent.play(WorldEvent.DESTROY_BLOCK, entity.world, pos, state); - } + entity.world.setBlockState(pos, StateMaps.SILVERFISH_AFFECTED.getConverted(state)); + WorldEvent.play(WorldEvent.DESTROY_BLOCK, entity.world, pos, state); } } } diff --git a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/SpellcastingIllagerBehaviour.java b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/SpellcastingIllagerBehaviour.java index a13579f4..dacc4188 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/SpellcastingIllagerBehaviour.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/SpellcastingIllagerBehaviour.java @@ -1,29 +1,23 @@ package com.minelittlepony.unicopia.entity.behaviour; -import com.minelittlepony.unicopia.ability.magic.Caster; -import com.minelittlepony.unicopia.ability.magic.Spell; +import com.minelittlepony.unicopia.ability.magic.spell.DisguiseSpell; import com.minelittlepony.unicopia.entity.player.Pony; import net.minecraft.entity.mob.SpellcastingIllagerEntity; public class SpellcastingIllagerBehaviour extends EntityBehaviour { @Override - public void update(Caster source, SpellcastingIllagerEntity entity, Spell s) { + public void update(Pony player, SpellcastingIllagerEntity entity, DisguiseSpell s) { + if (player.sneakingChanged()) { + if (player.getOwner().isSneaking()) { + SpellcastingIllagerEntity.Spell[] spells = SpellcastingIllagerEntity.Spell.values(); + SpellcastingIllagerEntity.Spell spell = spells[entity.world.random.nextInt(spells.length - 1) + 1]; - if (source instanceof Pony) { - Pony player = (Pony)source; - - if (player.sneakingChanged()) { - if (player.getOwner().isSneaking()) { - SpellcastingIllagerEntity.Spell[] spells = SpellcastingIllagerEntity.Spell.values(); - SpellcastingIllagerEntity.Spell spell = spells[entity.world.random.nextInt(spells.length - 1) + 1]; - - entity.setSpell(spell); - entity.setTarget(entity); - } else { - entity.setSpell(SpellcastingIllagerEntity.Spell.NONE); - entity.setTarget(null); - } + entity.setSpell(spell); + entity.setTarget(entity); + } else { + entity.setSpell(SpellcastingIllagerEntity.Spell.NONE); + entity.setTarget(null); } } } diff --git a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/TraderBehaviour.java b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/TraderBehaviour.java new file mode 100644 index 00000000..82c70805 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/TraderBehaviour.java @@ -0,0 +1,20 @@ +package com.minelittlepony.unicopia.entity.behaviour; + +import com.minelittlepony.unicopia.ability.magic.spell.DisguiseSpell; +import com.minelittlepony.unicopia.entity.player.Pony; + +import net.minecraft.entity.passive.AbstractTraderEntity; +import net.minecraft.sound.SoundEvents; + +public class TraderBehaviour extends EntityBehaviour { + @Override + public void update(Pony pony, AbstractTraderEntity entity, DisguiseSpell spell) { + if (pony.sneakingChanged() && pony.getOwner().isSneaking()) { + entity.setHeadRollingTimeLeft(40); + + if (!entity.world.isClient()) { + entity.playSound(SoundEvents.ENTITY_VILLAGER_NO, 1, 1); + } + } + } +} diff --git a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/VillagerBehaviour.java b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/VillagerBehaviour.java deleted file mode 100644 index f2878dc6..00000000 --- a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/VillagerBehaviour.java +++ /dev/null @@ -1,26 +0,0 @@ -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); - } - } - } - } -}