From 0ffa55a20c7cd07f9685690285a675c2d61f36d8 Mon Sep 17 00:00:00 2001 From: Sollace Date: Sun, 11 Sep 2022 17:06:05 +0200 Subject: [PATCH] More cleanup! Haza! --- .../unicopia/entity/behaviour/BlazeBehaviour.java | 4 ++-- .../entity/behaviour/ChickenBehaviour.java | 7 ++----- .../entity/behaviour/EndermanBehaviour.java | 4 ++-- .../entity/behaviour/FallingBlockBehaviour.java | 13 +++++-------- .../unicopia/entity/behaviour/GhastBehaviour.java | 5 +++-- .../entity/behaviour/HoppingBehaviour.java | 14 ++++++++------ .../entity/behaviour/MinecartBehaviour.java | 8 +++----- .../unicopia/entity/player/PlayerPhysics.java | 6 +++--- 8 files changed, 28 insertions(+), 33 deletions(-) diff --git a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/BlazeBehaviour.java b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/BlazeBehaviour.java index 95786ecf..bd897f62 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/BlazeBehaviour.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/BlazeBehaviour.java @@ -19,7 +19,7 @@ public class BlazeBehaviour extends EntityBehaviour { Entity src = source.getEntity(); - if (src.isOnGround() || src instanceof PlayerEntity && ((PlayerEntity)src).getAbilities().flying) { + if (src.isOnGround() || src instanceof PlayerEntity player && player.getAbilities().flying) { return; } @@ -67,7 +67,7 @@ public class BlazeBehaviour extends EntityBehaviour { if (fireballsFired > 0) { if (!entity.isSilent()) { - entity.world.syncWorldEvent((PlayerEntity)null, WorldEvents.BLAZE_SHOOTS, entity.getBlockPos(), 0); + entity.world.syncWorldEvent(null, WorldEvents.BLAZE_SHOOTS, entity.getBlockPos(), 0); } Vec3d rot = player.getEntity().getRotationVec(1); 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 f484b762..ae773a95 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/ChickenBehaviour.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/ChickenBehaviour.java @@ -23,10 +23,7 @@ public class ChickenBehaviour extends EntityBehaviour { public void update(Caster source, ChickenEntity entity, Disguise spell) { entity.eggLayTime = Integer.MAX_VALUE; - if (source instanceof Pony) { - Pony player = (Pony)source; - - + if (source instanceof Pony player) { if (player.sneakingChanged()) { ItemStack egg = entity.getEquippedStack(EquipmentSlot.OFFHAND); @@ -53,7 +50,7 @@ public class ChickenBehaviour extends EntityBehaviour { Entity src = source.getEntity(); - if (src.isOnGround() || src instanceof PlayerEntity && ((PlayerEntity)src).getAbilities().flying) { + if (src.isOnGround() || src instanceof PlayerEntity player && player.getAbilities().flying) { return; } 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 159bf793..2ba3157b 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/EndermanBehaviour.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/EndermanBehaviour.java @@ -17,8 +17,8 @@ public class EndermanBehaviour extends EntityBehaviour { } ItemStack stack = source.getMaster().getStackInHand(Hand.MAIN_HAND); - if (stack.getItem() instanceof BlockItem) { - entity.setCarriedBlock(((BlockItem)stack.getItem()).getBlock().getDefaultState()); + if (stack.getItem() instanceof BlockItem bi) { + entity.setCarriedBlock(bi.getBlock().getDefaultState()); } else { entity.setCarriedBlock(null); } 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 626a7714..6444daa3 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/FallingBlockBehaviour.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/FallingBlockBehaviour.java @@ -46,8 +46,8 @@ public class FallingBlockBehaviour extends EntityBehaviour { entity.handleFallDamage(distance, damageMultiplier, cause); BlockState state = entity.getBlockState(); - if (state.getBlock() instanceof FallingBlock) { - ((FallingBlock)state.getBlock()).onLanding(entity.world, entity.getBlockPos(), state, state, entity); + if (state.getBlock() instanceof FallingBlock fb) { + fb.onLanding(entity.world, entity.getBlockPos(), state, state, entity); } } } @@ -77,8 +77,8 @@ public class FallingBlockBehaviour extends EntityBehaviour { return configure(MixinFallingBlockEntity.createInstance(entity.world, entity.getX(), entity.getY() + 1, entity.getZ(), lowerState), block); } - if (block instanceof BlockEntityProvider) { - context.addBlockEntity(((BlockEntityProvider)block).createBlockEntity(entity.getBlockPos(), state)); + if (block instanceof BlockEntityProvider bep) { + context.addBlockEntity(bep.createBlockEntity(entity.getBlockPos(), state)); } return configure(entity, block); @@ -106,10 +106,7 @@ public class FallingBlockBehaviour extends EntityBehaviour { BlockEntity be = disguise.getBlockEntity(); - if (source instanceof Pony && be instanceof Tickable && (be instanceof ChestBlockEntity || be instanceof EnderChestBlockEntity)) { - Pony player = (Pony)source; - Tickable ceb = (Tickable)disguise.getBlockEntity(); - + if (source instanceof Pony player && be instanceof Tickable ceb && (be instanceof ChestBlockEntity || be instanceof EnderChestBlockEntity)) { if (player.sneakingChanged()) { be.onSyncedBlockEvent(1, isSneakingOnGround(source) ? 1 : 0); } diff --git a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/GhastBehaviour.java b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/GhastBehaviour.java index 9094247f..19b4c9a5 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/GhastBehaviour.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/GhastBehaviour.java @@ -5,6 +5,7 @@ import com.minelittlepony.unicopia.entity.player.Pony; import net.minecraft.entity.mob.GhastEntity; import net.minecraft.entity.projectile.FireballEntity; import net.minecraft.util.math.Vec3d; +import net.minecraft.world.WorldEvents; public class GhastBehaviour extends MobBehaviour { @@ -18,11 +19,11 @@ public class GhastBehaviour extends MobBehaviour { if (sneaking) { if (!entity.isSilent()) { - entity.world.syncWorldEvent(null, 1015, entity.getBlockPos(), 0); + entity.world.syncWorldEvent(null, WorldEvents.GHAST_WARNS, entity.getBlockPos(), 0); } } else { if (!entity.isSilent()) { - entity.world.syncWorldEvent(null, 1016, entity.getBlockPos(), 0); + entity.world.syncWorldEvent(null, WorldEvents.GHAST_SHOOTS, entity.getBlockPos(), 0); } Vec3d rot = player.getEntity().getRotationVec(1); diff --git a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/HoppingBehaviour.java b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/HoppingBehaviour.java index 26c9ed0a..894855fe 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/HoppingBehaviour.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/HoppingBehaviour.java @@ -12,14 +12,16 @@ public class HoppingBehaviour extends EntityBehaviour { if (player.getEntity().isOnGround()) { if (player.getEntity().getVelocity().horizontalLengthSquared() > 0.01) { player.getMaster().jump(); - if (entity instanceof RabbitEntity) { - ((RabbitEntity)entity).startJump(); - } + startJump(entity); } } else if (player.landedChanged()) { - if (entity instanceof RabbitEntity) { - ((RabbitEntity)entity).startJump(); - } + startJump(entity); + } + } + + private void startJump(LivingEntity entity) { + if (entity instanceof RabbitEntity rabbit) { + rabbit.startJump(); } } } 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 0f563e07..5d69f1ac 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/MinecartBehaviour.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/MinecartBehaviour.java @@ -25,11 +25,9 @@ public class MinecartBehaviour extends EntityBehaviour { entity.setPitch(0); entity.prevPitch = 0; - if (source.getEntity() instanceof LivingEntity) { - int hurt = ((LivingEntity)source.getEntity()).hurtTime; - - if (hurt > 0) { - entity.setDamageWobbleTicks(hurt); + if (source.getEntity() instanceof LivingEntity living) { + if (living.hurtTime > 0) { + entity.setDamageWobbleTicks(living.hurtTime); entity.setDamageWobbleStrength(1); entity.setDamageWobbleSide(20 + (int)source.getEntity().fallDistance / 10); } diff --git a/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerPhysics.java b/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerPhysics.java index 56dbc577..fd80dee6 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerPhysics.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerPhysics.java @@ -297,17 +297,17 @@ public class PlayerPhysics extends EntityPhysics implements Tickab if (isFlying() && !entity.isFallFlying()) { - float pitch = ((Leaner)entity).getLeaningPitch(); + float pitch = ((LivingEntityDuck)entity).getLeaningPitch(); if (pitch < 1) { if (pitch < 0.9F) { pitch += 0.1F; } pitch += 0.09F; - ((Leaner)entity).setLeaningPitch(Math.max(0, pitch)); + ((LivingEntityDuck)entity).setLeaningPitch(Math.max(0, pitch)); } entity.limbAngle = 20 + (float)Math.cos(entity.age / 7F) - 0.5F; - entity.limbDistance = this.thrustScale; + entity.limbDistance = thrustScale; } }