diff --git a/src/main/java/com/minelittlepony/unicopia/EntityConvertable.java b/src/main/java/com/minelittlepony/unicopia/EntityConvertable.java new file mode 100644 index 00000000..9b0f4037 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/EntityConvertable.java @@ -0,0 +1,14 @@ +package com.minelittlepony.unicopia; + +import net.minecraft.entity.Entity; + +/** + * Interface for things that can be owned by an entity. + *

+ * Ownership is retained so long as the owner is still active. If the owner leaves or dies, the link is broken. + * + * @param The type of object that owns us. + */ +public interface EntityConvertable { + E asEntity(); +} diff --git a/src/main/java/com/minelittlepony/unicopia/ability/AbilityDispatcher.java b/src/main/java/com/minelittlepony/unicopia/ability/AbilityDispatcher.java index a6260430..12228c17 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/AbilityDispatcher.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/AbilityDispatcher.java @@ -212,7 +212,7 @@ public class AbilityDispatcher implements Tickable, NbtSerialisable { if (data.isPresent()) { Channel.CLIENT_PLAYER_ABILITY.send(new MsgPlayerAbility<>(ability, data, ActivationType.NONE)); } else { - player.getEntity().playSound(USounds.GUI_ABILITY_FAIL, 1, 1); + player.asEntity().playSound(USounds.GUI_ABILITY_FAIL, 1, 1); setCooldown(0); } } diff --git a/src/main/java/com/minelittlepony/unicopia/ability/BatEeeeAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/BatEeeeAbility.java index ce4d4bce..b4f8a1f6 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/BatEeeeAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/BatEeeeAbility.java @@ -75,8 +75,8 @@ public class BatEeeeAbility implements Ability { Vec3d origin = player.getOriginVector(); if (rng.nextInt(20000) == 0) { - player.getMaster().damage(MagicalDamageSource.create("eeee", player).setBreakSunglasses(), 0.1F); - UCriteria.SCREECH_SELF.trigger(player.getMaster()); + player.asEntity().damage(MagicalDamageSource.create("eeee", player).setBreakSunglasses(), 0.1F); + UCriteria.SCREECH_SELF.trigger(player.asEntity()); } int total = player.findAllEntitiesInRange(5).mapToInt(e -> { @@ -95,7 +95,7 @@ public class BatEeeeAbility implements Ability { }).sum(); if (total >= 20) { - UCriteria.SCREECH_TWENTY_MOBS.trigger(player.getMaster()); + UCriteria.SCREECH_TWENTY_MOBS.trigger(player.asEntity()); } } diff --git a/src/main/java/com/minelittlepony/unicopia/ability/BatPonyHangAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/BatPonyHangAbility.java index f5441b76..7ca555bb 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/BatPonyHangAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/BatPonyHangAbility.java @@ -40,7 +40,7 @@ public class BatPonyHangAbility implements Ability { return new Multi(BlockPos.ZERO, 0); } - return TraceHelper.findBlock(player.getMaster(), 5, 1) + return TraceHelper.findBlock(player.asEntity(), 5, 1) .map(BlockPos::down) .filter(player::canHangAt) .map(pos -> new Multi(pos, 1)) diff --git a/src/main/java/com/minelittlepony/unicopia/ability/CarryAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/CarryAbility.java index 0bf4a551..0e33751a 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/CarryAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/CarryAbility.java @@ -64,7 +64,7 @@ public class CarryAbility implements Ability { @Override public void apply(Pony iplayer, Hit data) { - PlayerEntity player = iplayer.getMaster(); + PlayerEntity player = iplayer.asEntity(); LivingEntity rider = findRider(player, iplayer.getReferenceWorld()); if (player.hasPassengers()) { diff --git a/src/main/java/com/minelittlepony/unicopia/ability/ChangelingDisguiseAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/ChangelingDisguiseAbility.java index d9d4893f..1e5364ee 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/ChangelingDisguiseAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/ChangelingDisguiseAbility.java @@ -25,7 +25,7 @@ public class ChangelingDisguiseAbility extends ChangelingFeedAbility { @Nullable @Override public Hit tryActivate(Pony player) { - if (player.getMaster().isCreative() || player.getMagicalReserves().getMana().getPercentFill() >= 0.9F) { + if (player.asEntity().isCreative() || player.getMagicalReserves().getMana().getPercentFill() >= 0.9F) { return Hit.INSTANCE; } return null; @@ -33,7 +33,7 @@ public class ChangelingDisguiseAbility extends ChangelingFeedAbility { @Override public void apply(Pony iplayer, Hit data) { - PlayerEntity player = iplayer.getMaster(); + PlayerEntity player = iplayer.asEntity(); if (!player.isCreative() && iplayer.getMagicalReserves().getMana().getPercentFill() < 0.9F) { return; diff --git a/src/main/java/com/minelittlepony/unicopia/ability/ChangelingFeedAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/ChangelingFeedAbility.java index 75b96e78..0ed15c06 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/ChangelingFeedAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/ChangelingFeedAbility.java @@ -61,7 +61,7 @@ public class ChangelingFeedAbility implements Ability { } private boolean canFeed(Pony player) { - return player.getMaster().getHealth() < player.getMaster().getMaxHealth() || player.getMaster().canConsume(false); + return player.asEntity().getHealth() < player.asEntity().getMaxHealth() || player.asEntity().canConsume(false); } private boolean canDrain(Entity e) { @@ -80,9 +80,9 @@ public class ChangelingFeedAbility implements Ability { } protected List getTargets(Pony player) { - List list = VecHelper.findInRange(player.getMaster(), player.getReferenceWorld(), player.getOriginVector(), 3, this::canDrain); + List list = VecHelper.findInRange(player.asEntity(), player.getReferenceWorld(), player.getOriginVector(), 3, this::canDrain); - TraceHelper.findEntity(player.getMaster(), 17, 1, + TraceHelper.findEntity(player.asEntity(), 17, 1, looked -> looked instanceof LivingEntity && !list.contains(looked) && canDrain(looked)) .ifPresent(list::add); @@ -96,7 +96,7 @@ public class ChangelingFeedAbility implements Ability { @Override public void apply(Pony iplayer, Hit data) { - PlayerEntity player = iplayer.getMaster(); + PlayerEntity player = iplayer.asEntity(); float maximumHealthGain = player.getMaxHealth() - player.getHealth(); int maximumFoodGain = player.canConsume(false) ? (20 - player.getHungerManager().getFoodLevel()) : 0; diff --git a/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyGrowAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyGrowAbility.java index 1ae34e1c..52797ba5 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyGrowAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyGrowAbility.java @@ -36,7 +36,7 @@ public class EarthPonyGrowAbility implements Ability { @Override public Pos tryActivate(Pony player) { - return TraceHelper.findBlock(player.getMaster(), 3, 1).map(Pos::new).orElse(null); + return TraceHelper.findBlock(player.asEntity(), 3, 1).map(Pos::new).orElse(null); } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyKickAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyKickAbility.java index 7bf3b5ab..467c0eea 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyKickAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyKickAbility.java @@ -58,9 +58,9 @@ public class EarthPonyKickAbility implements Ability { @Override public double getCostEstimate(Pony player) { - double distance = MineLPDelegate.getInstance().getPlayerPonyRace(player.getMaster()).isDefault() ? 6 : -6; + double distance = MineLPDelegate.getInstance().getPlayerPonyRace(player.asEntity()).isDefault() ? 6 : -6; - return TraceHelper.findBlock(player.getMaster(), distance, 1) + return TraceHelper.findBlock(player.asEntity(), distance, 1) .filter(pos -> TreeType.at(pos, player.getReferenceWorld()) != TreeType.NONE) .isPresent() ? 3 : 1; } @@ -79,7 +79,7 @@ public class EarthPonyKickAbility implements Ability { Vec3d origin = player.getOriginVector(); World w = player.getReferenceWorld(); - for (var e : VecHelper.findInRange(player.getEntity(), w, kickLocation.vec(), 2, EntityPredicates.EXCEPT_CREATIVE_OR_SPECTATOR)) { + for (var e : VecHelper.findInRange(player.asEntity(), w, kickLocation.vec(), 2, EntityPredicates.EXCEPT_CREATIVE_OR_SPECTATOR)) { if (e instanceof LivingEntity entity) { float calculatedStrength = 0.5F * (1 + player.getLevel().getScaled(9)); entity.damage(MagicalDamageSource.KICK, player.getReferenceWorld().random.nextBetween(2, 10) + calculatedStrength); @@ -92,7 +92,7 @@ public class EarthPonyKickAbility implements Ability { } BlockPos pos = kickLocation.pos(); - EarthPonyStompAbility.stompBlock(w, pos, 10 * (1 + player.getLevel().getScaled(5)) * w.getBlockState(pos).calcBlockBreakingDelta(player.getMaster(), w, pos)); + EarthPonyStompAbility.stompBlock(w, pos, 10 * (1 + player.getLevel().getScaled(5)) * w.getBlockState(pos).calcBlockBreakingDelta(player.asEntity(), w, pos)); player.setAnimation(Animation.KICK); }); } @@ -106,20 +106,20 @@ public class EarthPonyKickAbility implements Ability { @Nullable @Override public Pos tryActivate(Pony player) { - return TraceHelper.findBlock(player.getMaster(), 6 * getKickDirection(player), 1) + return TraceHelper.findBlock(player.asEntity(), 6 * getKickDirection(player), 1) .filter(pos -> TreeType.at(pos, player.getReferenceWorld()) != TreeType.NONE) .map(Pos::new) .orElseGet(() -> getDefaultKickLocation(player)); } private int getKickDirection(Pony player) { - return MineLPDelegate.getInstance().getPlayerPonyRace(player.getMaster()).isDefault() ? 1 : -1; + return MineLPDelegate.getInstance().getPlayerPonyRace(player.asEntity()).isDefault() ? 1 : -1; } private Pos getDefaultKickLocation(Pony player) { - Vec3d kickVector = player.getMaster().getRotationVector().multiply(1, 0, 1); - player.getMaster(); - if (!MineLPDelegate.getInstance().getPlayerPonyRace(player.getMaster()).isDefault()) { + Vec3d kickVector = player.asEntity().getRotationVector().multiply(1, 0, 1); + + if (!MineLPDelegate.getInstance().getPlayerPonyRace(player.asEntity()).isDefault()) { kickVector = kickVector.rotateY((float)Math.PI); } return new Pos(new BlockPos(player.getOriginVector().add(kickVector))); @@ -154,7 +154,7 @@ public class EarthPonyKickAbility implements Ability { ParticleUtils.spawnParticle(iplayer.getReferenceWorld(), UParticles.GROUND_POUND, data.vec(), Vec3d.ZERO); } - PlayerEntity player = iplayer.getMaster(); + PlayerEntity player = iplayer.asEntity(); if (BlockDestructionManager.of(player.world).getBlockDestruction(pos) + 4 >= BlockDestructionManager.MAX_DAMAGE) { if (player.world.random.nextInt(30) == 0) { diff --git a/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyStompAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyStompAbility.java index e52a8d86..99429729 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyStompAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyStompAbility.java @@ -67,7 +67,9 @@ public class EarthPonyStompAbility implements Ability { @Nullable @Override public Hit tryActivate(Pony player) { - if (!player.getMaster().isOnGround() && player.getMaster().getVelocity().y * player.getPhysics().getGravitySignum() < 0 && !player.getMaster().getAbilities().flying) { + if (!player.asEntity().isOnGround() + && player.asEntity().getVelocity().y * player.getPhysics().getGravitySignum() < 0 + && !player.asEntity().getAbilities().flying) { thrustDownwards(player); return Hit.INSTANCE; } @@ -85,13 +87,13 @@ public class EarthPonyStompAbility implements Ability { BlockPos pos = PosHelper.findSolidGroundAt(player.getReferenceWorld(), ppos, player.getPhysics().getGravitySignum()); double downV = Math.sqrt(ppos.getSquaredDistance(pos)) * player.getPhysics().getGravitySignum(); - player.getMaster().addVelocity(0, -downV, 0); + player.asEntity().addVelocity(0, -downV, 0); player.updateVelocity(); } @Override public void apply(Pony iplayer, Hit data) { - PlayerEntity player = iplayer.getMaster(); + PlayerEntity player = iplayer.asEntity(); iplayer.setAnimation(Animation.STOMP, 10); diff --git a/src/main/java/com/minelittlepony/unicopia/ability/PegasusCaptureStormAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/PegasusCaptureStormAbility.java index 1fb893eb..c5b7b2da 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/PegasusCaptureStormAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/PegasusCaptureStormAbility.java @@ -40,7 +40,7 @@ public class PegasusCaptureStormAbility implements Ability { @Override public Hit tryActivate(Pony player) { - if (!player.getMaster().isCreative() && player.getMagicalReserves().getMana().getPercentFill() < 0.2F) { + if (!player.asEntity().isCreative() && player.getMagicalReserves().getMana().getPercentFill() < 0.2F) { return null; } @@ -61,7 +61,7 @@ public class PegasusCaptureStormAbility implements Ability { public void apply(Pony player, Hit data) { World w = player.getReferenceWorld(); - ItemStack stack = player.getMaster().getStackInHand(Hand.MAIN_HAND); + ItemStack stack = player.asEntity().getStackInHand(Hand.MAIN_HAND); boolean thundering = w.isThundering(); if (stack.getItem() != UItems.EMPTY_JAR) { @@ -73,12 +73,12 @@ public class PegasusCaptureStormAbility implements Ability { } else if (player.getOrigin().getY() < 120) { tell(player, "ability.unicopia.too_low"); } else { - if (!player.getMaster().getAbilities().creativeMode) { + if (!player.asEntity().getAbilities().creativeMode) { stack.decrement(1); } if (thundering && w.random.nextBoolean()) { - player.getMaster().giveItemStack(UItems.STORM_CLOUD_JAR.getDefaultStack()); + player.asEntity().giveItemStack(UItems.STORM_CLOUD_JAR.getDefaultStack()); if (w instanceof ServerWorld) { ServerWorldProperties props = (ServerWorldProperties)w.getLevelProperties(); @@ -91,7 +91,7 @@ public class PegasusCaptureStormAbility implements Ability { ((ServerWorld)w).getServer().getPlayerManager().sendToDimension(new GameStateChangeS2CPacket(GameStateChangeS2CPacket.THUNDER_GRADIENT_CHANGED, w.getRainGradient(1)), w.getRegistryKey()); } } else { - player.getMaster().giveItemStack(UItems.RAIN_CLOUD_JAR.getDefaultStack()); + player.asEntity().giveItemStack(UItems.RAIN_CLOUD_JAR.getDefaultStack()); if (w instanceof ServerWorld) { ServerWorldProperties props = (ServerWorldProperties)w.getLevelProperties(); @@ -109,7 +109,7 @@ public class PegasusCaptureStormAbility implements Ability { } private void tell(Pony player, String translation) { - player.getMaster().sendMessage(Text.translatable(translation), true); + player.asEntity().sendMessage(Text.translatable(translation), true); } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/ability/PegasusFlightToggleAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/PegasusFlightToggleAbility.java index 152b081d..e8643062 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/PegasusFlightToggleAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/PegasusFlightToggleAbility.java @@ -30,7 +30,7 @@ public class PegasusFlightToggleAbility implements Ability { @Nullable @Override public Hit tryActivate(Pony player) { - return player.getMaster().isCreative() ? null : Hit.INSTANCE; + return player.asEntity().isCreative() ? null : Hit.INSTANCE; } @Override @@ -54,15 +54,15 @@ public class PegasusFlightToggleAbility implements Ability { @Override public void apply(Pony player, Hit data) { - if (player.getMaster().isCreative()) { + if (player.asEntity().isCreative()) { return; } player.subtractEnergyCost(1); if (!player.getPhysics().isFlying()) { - player.getEntity().addVelocity(0, player.getPhysics().getGravitySignum() * 0.7F, 0); - Living.updateVelocity(player.getEntity()); + player.asEntity().addVelocity(0, player.getPhysics().getGravitySignum() * 0.7F, 0); + Living.updateVelocity(player.asEntity()); player.getPhysics().startFlying(true); } else { player.getPhysics().cancelFlight(true); diff --git a/src/main/java/com/minelittlepony/unicopia/ability/PegasusRainboomAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/PegasusRainboomAbility.java index 91aef117..e1e6eb2a 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/PegasusRainboomAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/PegasusRainboomAbility.java @@ -36,7 +36,7 @@ public class PegasusRainboomAbility implements Ability { @Override public Hit tryActivate(Pony player) { - if (!player.getMaster().isCreative() && player.getMagicalReserves().getMana().getPercentFill() < 0.2F) { + if (!player.asEntity().isCreative() && player.getMagicalReserves().getMana().getPercentFill() < 0.2F) { return null; } diff --git a/src/main/java/com/minelittlepony/unicopia/ability/UnicornCastingAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/UnicornCastingAbility.java index d3cea2f5..c8b0b7b3 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/UnicornCastingAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/UnicornCastingAbility.java @@ -96,7 +96,7 @@ public class UnicornCastingAbility implements Ability { if (amount < 0) { AmuletItem.consumeEnergy(stack, amount); player.getMagicalReserves().getMana().add(amount * player.getMagicalReserves().getMana().getMax()); - player.getReferenceWorld().playSoundFromEntity(null, player.getMaster(), USounds.ITEM_AMULET_RECHARGE, SoundCategory.PLAYERS, 1, 1); + player.getReferenceWorld().playSoundFromEntity(null, player.asEntity(), USounds.ITEM_AMULET_RECHARGE, SoundCategory.PLAYERS, 1, 1); } } } else { @@ -117,7 +117,7 @@ public class UnicornCastingAbility implements Ability { } else { player.setAnimation(Animation.ARMS_UP); if (s instanceof HomingSpell homer) { - TraceHelper.findEntity(player.getMaster(), homer.getRange(player), 1, EntityPredicates.VALID_ENTITY).ifPresent(homer::setTarget); + TraceHelper.findEntity(player.asEntity(), homer.getRange(player), 1, EntityPredicates.VALID_ENTITY).ifPresent(homer::setTarget); } player.playSound(USounds.SPELL_CAST_SUCCESS, 0.05F, 2.2F); } @@ -130,7 +130,7 @@ public class UnicornCastingAbility implements Ability { private TypedActionResult getAmulet(Pony player) { - ItemStack stack = player.getMaster().getStackInHand(Hand.MAIN_HAND); + ItemStack stack = player.asEntity().getStackInHand(Hand.MAIN_HAND); if (stack.getItem() instanceof AmuletItem) { if (((AmuletItem)stack.getItem()).isChargable()) { @@ -148,7 +148,7 @@ public class UnicornCastingAbility implements Ability { player.getMagicalReserves().getExhaustion().multiply(3.3F); if (getAmulet(player).getResult() == ActionResult.CONSUME) { - Vec3d eyes = player.getMaster().getCameraPosVec(1); + Vec3d eyes = player.asEntity().getCameraPosVec(1); float i = player.getAbilities().getStat(slot).getFillProgress(); diff --git a/src/main/java/com/minelittlepony/unicopia/ability/UnicornDispellAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/UnicornDispellAbility.java index 310cd92d..abd73db5 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/UnicornDispellAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/UnicornDispellAbility.java @@ -54,9 +54,9 @@ public class UnicornDispellAbility implements Ability { if (type.getTapCount() > 1) { player.setAnimation(Animation.WOLOLO, 10); if (player.getSpellSlot().clear()) { - player.getMaster().sendMessage(Text.translatable("gui.unicopia.action.spells_cleared"), true); + player.asEntity().sendMessage(Text.translatable("gui.unicopia.action.spells_cleared"), true); } else { - player.getMaster().sendMessage(Text.translatable("gui.unicopia.action.no_spells_cleared"), true); + player.asEntity().sendMessage(Text.translatable("gui.unicopia.action.no_spells_cleared"), true); } return true; } @@ -85,14 +85,14 @@ public class UnicornDispellAbility implements Ability { @Override public void apply(Pony player, Pos data) { player.setAnimation(Animation.WOLOLO); - Caster.stream(VecHelper.findInRange(player.getEntity(), player.getReferenceWorld(), data.vec(), 3, EquinePredicates.IS_PLACED_SPELL).stream()).forEach(target -> { + Caster.stream(VecHelper.findInRange(player.asEntity(), player.getReferenceWorld(), data.vec(), 3, EquinePredicates.IS_PLACED_SPELL).stream()).forEach(target -> { target.getSpellSlot().clear(); }); } private Optional> getTarget(Pony player) { - int maxDistance = player.getMaster().isCreative() ? 1000 : 100; - return TraceHelper.findEntity(player.getMaster(), maxDistance, 1, EquinePredicates.IS_PLACED_SPELL).flatMap(Caster::of); + int maxDistance = player.asEntity().isCreative() ? 1000 : 100; + return TraceHelper.findEntity(player.asEntity(), maxDistance, 1, EquinePredicates.IS_PLACED_SPELL).flatMap(Caster::of); } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/ability/UnicornProjectileAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/UnicornProjectileAbility.java index 6df17350..019b9f18 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/UnicornProjectileAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/UnicornProjectileAbility.java @@ -93,7 +93,7 @@ public class UnicornProjectileAbility implements Ability { projectile.setHydrophobic(); if (spell instanceof HomingSpell) { - TraceHelper.findEntity(player.getMaster(), 600, 1).filter(((HomingSpell)spell)::setTarget).ifPresent(projectile::setHomingTarget); + TraceHelper.findEntity(player.asEntity(), 600, 1).filter(((HomingSpell)spell)::setTarget).ifPresent(projectile::setHomingTarget); } }); } diff --git a/src/main/java/com/minelittlepony/unicopia/ability/UnicornTeleportAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/UnicornTeleportAbility.java index a5780406..2c162bfc 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/UnicornTeleportAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/UnicornTeleportAbility.java @@ -68,21 +68,21 @@ public class UnicornTeleportAbility implements Ability { return null; } - int maxDistance = player.getMaster().isCreative() ? 1000 : 100; + int maxDistance = player.asEntity().isCreative() ? 1000 : 100; World w = player.getReferenceWorld(); - Trace trace = Trace.create(player.getMaster(), maxDistance, 1, EntityPredicates.EXCEPT_SPECTATOR); + Trace trace = Trace.create(player.asEntity(), maxDistance, 1, EntityPredicates.EXCEPT_SPECTATOR); return trace.getBlockOrEntityPos().map(pos -> { final BlockPos originalPos = pos; boolean airAbove = enterable(w, pos.up()) && enterable(w, pos.up(2)); - if (exception(w, pos, player.getMaster())) { + if (exception(w, pos, player.asEntity())) { final BlockPos p = pos; pos = trace.getSide().map(sideHit -> { - if (player.getMaster().isSneaking()) { + if (player.asEntity().isSneaking()) { sideHit = sideHit.getOpposite(); } @@ -102,8 +102,8 @@ public class UnicornTeleportAbility implements Ability { } } - if ((!enterable(w, pos) && exception(w, pos, player.getMaster())) - || (!enterable(w, pos.up()) && exception(w, pos.up(), player.getMaster()))) { + if ((!enterable(w, pos) && exception(w, pos, player.asEntity())) + || (!enterable(w, pos.up()) && exception(w, pos.up(), player.asEntity()))) { return null; } diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/Caster.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/Caster.java index c04e5059..b4ac4170 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/Caster.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/Caster.java @@ -27,7 +27,7 @@ import net.minecraft.world.World; /** * Interface for any magically capable entities that can cast or persist spells. */ -public interface Caster extends Owned, Levelled, Affine, ParticleSource, SoundEmitter { +public interface Caster extends Owned, Levelled, Affine, ParticleSource, SoundEmitter { Physics getPhysics(); @@ -37,9 +37,7 @@ public interface Caster extends Owned, Levelled, Affi * Gets the entity directly responsible for casting. */ @Override - default Entity getEntity() { - return getMaster(); - } + Entity getEntity(); /** * Gets the minecraft world diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/AreaProtectionSpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/AreaProtectionSpell.java index 0bca6ed5..b6a5a8c2 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/AreaProtectionSpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/AreaProtectionSpell.java @@ -55,7 +55,7 @@ public class AreaProtectionSpell extends AbstractAreaEffectSpell { * Calculates the maximum radius of the shield. aka The area of effect. */ public double getDrawDropOffRange(Caster source) { - float multiplier = source instanceof Pony pony && pony.getMaster().isSneaking() ? 1 : 2; + float multiplier = source instanceof Pony pony && pony.asEntity().isSneaking() ? 1 : 2; float min = 4 + getTraits().get(Trait.POWER); double range = (min + (source.getLevel().getScaled(4) * 2)) / multiplier; if (source instanceof Pony && range > 2) { diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/AttractionUtils.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/AttractionUtils.java index edb5e78b..ad7487f1 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/AttractionUtils.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/AttractionUtils.java @@ -51,7 +51,7 @@ public interface AttractionUtils { if (pony.getSpecies().canUseEarth()) { force /= 2; - if (pony.getMaster().isSneaking()) { + if (pony.asEntity().isSneaking()) { force /= 6; } } else if (pony.getSpecies().canFly()) { diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/ShieldSpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/ShieldSpell.java index 90234441..6ff5e50b 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/ShieldSpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/ShieldSpell.java @@ -117,7 +117,7 @@ public class ShieldSpell extends AbstractSpell { * Calculates the maximum radius of the shield. aka The area of effect. */ public double getDrawDropOffRange(Caster source) { - float multiplier = source instanceof Pony pony && pony.getMaster().isSneaking() ? 1 : 2; + float multiplier = source instanceof Pony pony && pony.asEntity().isSneaking() ? 1 : 2; float min = (source instanceof Pony ? 4 : 6) + getTraits().get(Trait.POWER); double range = (min + (source.getLevel().getScaled(source instanceof Pony ? 4 : 40) * (source instanceof Pony ? 2 : 10))) / multiplier; diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/trait/TraitDiscovery.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/trait/TraitDiscovery.java index 7f8720e6..ab67d3b6 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/trait/TraitDiscovery.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/trait/TraitDiscovery.java @@ -76,7 +76,7 @@ public class TraitDiscovery implements NbtSerialisable { unreadTraits.addAll(newTraits); pony.setDirty(); if (!newTraits.isEmpty() && !pony.getReferenceWorld().isClient) { - Channel.UNLOCK_TRAITS.send((ServerPlayerEntity)pony.getMaster(), new MsgUnlockTraits(newTraits)); + Channel.UNLOCK_TRAITS.send((ServerPlayerEntity)pony.asEntity(), new MsgUnlockTraits(newTraits)); } } diff --git a/src/main/java/com/minelittlepony/unicopia/client/gui/DismissSpellScreen.java b/src/main/java/com/minelittlepony/unicopia/client/gui/DismissSpellScreen.java index 5cb7f874..e8b10f63 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/gui/DismissSpellScreen.java +++ b/src/main/java/com/minelittlepony/unicopia/client/gui/DismissSpellScreen.java @@ -65,7 +65,7 @@ public class DismissSpellScreen extends GameGui { Vec3d cartesian = relativePos .normalize() .multiply(minimalDistance + relativePos.length()) - .rotateY((pony.getEntity().getYaw() - 180) * MathHelper.RADIANS_PER_DEGREE); + .rotateY((pony.asEntity().getYaw() - 180) * MathHelper.RADIANS_PER_DEGREE); addDrawableChild(new Entry(placeable).ofCartesian(cartesian)); }); }); diff --git a/src/main/java/com/minelittlepony/unicopia/client/gui/UHud.java b/src/main/java/com/minelittlepony/unicopia/client/gui/UHud.java index ef55fa69..8e528b94 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/gui/UHud.java +++ b/src/main/java/com/minelittlepony/unicopia/client/gui/UHud.java @@ -125,7 +125,7 @@ public class UHud extends DrawableHelper { matrices.pop(); - if (pony.getActualSpecies().canCast() || AmuletSelectors.ALICORN_AMULET.test(pony.getMaster())) { + if (pony.getActualSpecies().canCast() || AmuletSelectors.ALICORN_AMULET.test(pony.asEntity())) { renderSpell(pony.getCharms().getEquippedSpell(Hand.MAIN_HAND), hudX + 15 - xDirection * 13, hudY + 3); renderSpell(pony.getCharms().getEquippedSpell(Hand.OFF_HAND), hudX + 15 - xDirection * 2, hudY - 3); } diff --git a/src/main/java/com/minelittlepony/unicopia/client/gui/spellbook/SpellbookProfilePageContent.java b/src/main/java/com/minelittlepony/unicopia/client/gui/spellbook/SpellbookProfilePageContent.java index a3e75028..4089aa29 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/gui/spellbook/SpellbookProfilePageContent.java +++ b/src/main/java/com/minelittlepony/unicopia/client/gui/spellbook/SpellbookProfilePageContent.java @@ -67,10 +67,10 @@ public class SpellbookProfilePageContent extends DrawableHelper implements Spell int y = SpellbookScreen.TITLE_Y; - float delta = pony.getEntity().age + client.getTickDelta(); + float delta = pony.asEntity().age + client.getTickDelta(); int currentLevel = pony.getLevel().get(); - DrawableUtil.drawScaledText(matrices, pony.getEntity().getName(), SpellbookScreen.TITLE_X, y, 1.3F, SpellbookScreen.TITLE_COLOR); + DrawableUtil.drawScaledText(matrices, pony.asEntity().getName(), SpellbookScreen.TITLE_X, y, 1.3F, SpellbookScreen.TITLE_COLOR); DrawableUtil.drawScaledText(matrices, ExperienceGroup.forLevel(currentLevel, pony.getCorruption().get()), SpellbookScreen.TITLE_X, y + 13, 0.8F, 0xAA0040FF); MagicReserves reserves = pony.getMagicalReserves(); diff --git a/src/main/java/com/minelittlepony/unicopia/entity/Equine.java b/src/main/java/com/minelittlepony/unicopia/entity/Equine.java index e7deea55..62a68e5f 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/Equine.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/Equine.java @@ -4,6 +4,7 @@ import java.util.Optional; import org.jetbrains.annotations.Nullable; +import com.minelittlepony.unicopia.EntityConvertable; import com.minelittlepony.unicopia.Race; import com.minelittlepony.unicopia.projectile.ProjectileImpactListener; import com.minelittlepony.unicopia.util.NbtSerialisable; @@ -13,7 +14,7 @@ import net.minecraft.entity.Entity; import net.minecraft.entity.damage.DamageSource; import net.minecraft.entity.projectile.ProjectileEntity; -public interface Equine extends NbtSerialisable, Tickable, ProjectileImpactListener { +public interface Equine extends NbtSerialisable, Tickable, ProjectileImpactListener, EntityConvertable { Race getSpecies(); Physics getPhysics(); diff --git a/src/main/java/com/minelittlepony/unicopia/entity/ItemImpl.java b/src/main/java/com/minelittlepony/unicopia/entity/ItemImpl.java index 3933c83a..f0f9e4ef 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/ItemImpl.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/ItemImpl.java @@ -32,14 +32,14 @@ public class ItemImpl implements Equine, Owned { private static final TrackedData ITEM_RACE = DataTracker.registerData(ItemEntity.class, TrackedDataHandlerRegistry.STRING); static final TrackedData ITEM_GRAVITY = DataTracker.registerData(ItemEntity.class, TrackedDataHandlerRegistry.FLOAT); - private final ItemEntity owner; + private final ItemEntity entity; private final ItemPhysics physics; private Race serverRace; public ItemImpl(ItemEntity owner) { - this.owner = owner; + this.entity = owner; this.physics = new ItemPhysics(owner); owner.getDataTracker().startTracking(ITEM_GRAVITY, 1F); owner.getDataTracker().startTracking(ITEM_RACE, Race.REGISTRY.getId(Race.HUMAN).toString()); @@ -53,7 +53,7 @@ public class ItemImpl implements Equine, Owned { @Override public boolean beforeUpdate() { - if (!owner.world.isClient) { + if (!entity.world.isClient) { Race race = getSpecies(); if (race != serverRace) { serverRace = race; @@ -62,8 +62,8 @@ public class ItemImpl implements Equine, Owned { } } - ItemStack stack = owner.getStack(); - IItemEntity i = (IItemEntity)owner; + ItemStack stack = entity.getStack(); + IItemEntity i = (IItemEntity)entity; if (!stack.isEmpty()) { @@ -71,26 +71,26 @@ public class ItemImpl implements Equine, Owned { ClingyItem clingy = item instanceof ClingyItem ? (ClingyItem)item : ClingyItem.DEFAULT; if (clingy.isClingy(stack)) { - Random rng = owner.world.random; + Random rng = entity.world.random; - owner.world.addParticle(clingy.getParticleEffect((IItemEntity)owner), - owner.getX() + rng.nextFloat() - 0.5, - owner.getY() + rng.nextFloat() - 0.5, - owner.getZ() + rng.nextFloat() - 0.5, + entity.world.addParticle(clingy.getParticleEffect((IItemEntity)entity), + entity.getX() + rng.nextFloat() - 0.5, + entity.getY() + rng.nextFloat() - 0.5, + entity.getZ() + rng.nextFloat() - 0.5, 0, 0, 0 ); - Vec3d position = owner.getPos(); - VecHelper.findInRange(owner, owner.world, owner.getPos(), clingy.getFollowDistance(i), e -> e instanceof PlayerEntity) + Vec3d position = entity.getPos(); + VecHelper.findInRange(entity, entity.world, entity.getPos(), clingy.getFollowDistance(i), e -> e instanceof PlayerEntity) .stream() .sorted((a, b) -> (int)(a.getPos().distanceTo(position) - b.getPos().distanceTo(position))) .findFirst() .ifPresent(player -> { - double distance = player.getPos().distanceTo(owner.getPos()); + double distance = player.getPos().distanceTo(entity.getPos()); - owner.move(MovementType.SELF, player.getPos().subtract(owner.getPos()).multiply(distance < 0.3 ? 1 : clingy.getFollowSpeed(i))); - if (owner.horizontalCollision) { - owner.move(MovementType.SELF, new Vec3d(0, owner.verticalCollision ? -0.3 : 0.3, 0)); + entity.move(MovementType.SELF, player.getPos().subtract(entity.getPos()).multiply(distance < 0.3 ? 1 : clingy.getFollowSpeed(i))); + if (entity.horizontalCollision) { + entity.move(MovementType.SELF, new Vec3d(0, entity.verticalCollision ? -0.3 : 0.3, 0)); } clingy.interactWithPlayer(i, (PlayerEntity)player); @@ -98,19 +98,19 @@ public class ItemImpl implements Equine, Owned { } if (stack.isIn(UTags.FALLS_SLOWLY)) { - if (!owner.isOnGround() && Math.signum(owner.getVelocity().y) != getPhysics().getGravitySignum()) { - double ticks = ((Entity)owner).age; + if (!entity.isOnGround() && Math.signum(entity.getVelocity().y) != getPhysics().getGravitySignum()) { + double ticks = ((Entity)entity).age; double shift = Math.sin(ticks / 9D) / 9D; double rise = -Math.cos(ticks / 9D) * getPhysics().getGravitySignum(); - owner.prevYaw = owner.prevYaw; - owner.setYaw(owner.getYaw() + 0.3F); + entity.prevYaw = entity.prevYaw; + entity.setYaw(entity.getYaw() + 0.3F); - owner.setVelocity( - owner.getVelocity() + entity.setVelocity( + entity.getVelocity() .multiply(0.25, 0, 0.25) .add(0, rise, 0) - .add(owner.getRotationVec(1)).normalize().multiply(shift) + .add(entity.getRotationVec(1)).normalize().multiply(shift) ); } } @@ -136,12 +136,12 @@ public class ItemImpl implements Equine, Owned { @Override public Race getSpecies() { - return Race.fromName(owner.getDataTracker().get(ITEM_RACE), Race.HUMAN); + return Race.fromName(entity.getDataTracker().get(ITEM_RACE), Race.HUMAN); } @Override public void setSpecies(Race race) { - owner.getDataTracker().set(ITEM_RACE, Race.REGISTRY.getId(race).toString()); + entity.getDataTracker().set(ITEM_RACE, Race.REGISTRY.getId(race).toString()); } @Override @@ -166,7 +166,12 @@ public class ItemImpl implements Equine, Owned { @Override @NotNull public ItemEntity getMaster() { - return owner; + return asEntity(); + } + + @Override + public ItemEntity asEntity() { + return entity; } public static T registerTickCallback(T item, GroundTickCallback callback) { diff --git a/src/main/java/com/minelittlepony/unicopia/entity/Living.java b/src/main/java/com/minelittlepony/unicopia/entity/Living.java index 1a3b87c0..1e4346f0 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/Living.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/Living.java @@ -100,12 +100,17 @@ public abstract class Living implements Equine, Caste } @Override - public void setMaster(T owner) { + public void setMaster(LivingEntity owner) { } @Override @NotNull - public T getMaster() { + public LivingEntity getMaster() { + return asEntity(); + } + + @Override + public final T asEntity() { return entity; } 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 bd897f62..744e25fd 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/BlazeBehaviour.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/BlazeBehaviour.java @@ -40,7 +40,7 @@ public class BlazeBehaviour extends EntityBehaviour { int fireballsFired = tag.getInt("fireballsFired"); if (player.sneakingChanged()) { - boolean sneaking = player.getMaster().isSneaking(); + boolean sneaking = player.asEntity().isSneaking(); if (sneaking) { firing = true; @@ -70,10 +70,10 @@ public class BlazeBehaviour extends EntityBehaviour { entity.world.syncWorldEvent(null, WorldEvents.BLAZE_SHOOTS, entity.getBlockPos(), 0); } - Vec3d rot = player.getEntity().getRotationVec(1); + Vec3d rot = player.asEntity().getRotationVec(1); for (int i = 0; i < 1; ++i) { - SmallFireballEntity proj = new SmallFireballEntity(entity.world, player.getMaster(), + SmallFireballEntity proj = new SmallFireballEntity(entity.world, player.asEntity(), rot.getX() + entity.getRandom().nextGaussian(), rot.getY(), rot.getZ() + entity.getRandom().nextGaussian() 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 ae773a95..7bc885af 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/ChickenBehaviour.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/ChickenBehaviour.java @@ -27,13 +27,13 @@ public class ChickenBehaviour extends EntityBehaviour { if (player.sneakingChanged()) { ItemStack egg = entity.getEquippedStack(EquipmentSlot.OFFHAND); - if (player.getMaster().isSneaking()) { + if (player.asEntity().isSneaking()) { if (egg.isEmpty()) { egg = new ItemStack(Items.EGG); - int slot = player.getMaster().getInventory().indexOf(egg); + int slot = player.asEntity().getInventory().indexOf(egg); if (slot > -1) { - player.getMaster().getInventory().removeStack(slot, 1); + player.asEntity().getInventory().removeStack(slot, 1); entity.playSound(SoundEvents.ENTITY_CHICKEN_EGG, 1, (entity.world.random.nextFloat() - entity.world.random.nextFloat()) * 0.2F + 4 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 19b4c9a5..352852aa 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/GhastBehaviour.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/GhastBehaviour.java @@ -13,7 +13,7 @@ public class GhastBehaviour extends MobBehaviour { public void update(Pony player, GhastEntity entity, Disguise spell) { if (player.sneakingChanged()) { - boolean sneaking = player.getMaster().isSneaking(); + boolean sneaking = player.asEntity().isSneaking(); entity.setShooting(sneaking); entity.setTarget(sneaking ? findTarget(player, entity) : null); @@ -26,9 +26,9 @@ public class GhastBehaviour extends MobBehaviour { entity.world.syncWorldEvent(null, WorldEvents.GHAST_SHOOTS, entity.getBlockPos(), 0); } - Vec3d rot = player.getEntity().getRotationVec(1); + Vec3d rot = player.asEntity().getRotationVec(1); - FireballEntity proj = new FireballEntity(entity.world, player.getMaster(), + FireballEntity proj = new FireballEntity(entity.world, player.asEntity(), rot.getX(), rot.getY(), rot.getZ(), 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 894855fe..33eb2dfa 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/HoppingBehaviour.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/HoppingBehaviour.java @@ -9,9 +9,9 @@ public class HoppingBehaviour extends EntityBehaviour { @Override public void update(Pony player, LivingEntity entity, Disguise spell) { - if (player.getEntity().isOnGround()) { - if (player.getEntity().getVelocity().horizontalLengthSquared() > 0.01) { - player.getMaster().jump(); + if (player.asEntity().isOnGround()) { + if (player.asEntity().getVelocity().horizontalLengthSquared() > 0.01) { + player.asEntity().jump(); startJump(entity); } } else if (player.landedChanged()) { 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 82b1fce5..bdf69f65 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/MobBehaviour.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/MobBehaviour.java @@ -21,12 +21,12 @@ public class MobBehaviour extends EntityBehaviour { if (player.sneakingChanged() && isSneakingOnGround(player)) { LivingEntity target = findTarget(player, entity); entity.tryAttack(target); - target.setAttacker(player.getMaster()); + target.setAttacker(player.asEntity()); } } protected LivingEntity findTarget(Pony player, T entity) { - return TraceHelper.findEntity(player.getEntity(), 6, 1, + return TraceHelper.findEntity(player.asEntity(), 6, 1, e -> e instanceof LivingEntity && e != entity && !player.isOwnedBy(e)) .orElseGet(() -> getDummy(entity)); } diff --git a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/PlayerBehaviour.java b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/PlayerBehaviour.java index 907d704a..66628a94 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/PlayerBehaviour.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/PlayerBehaviour.java @@ -10,7 +10,7 @@ public class PlayerBehaviour extends EntityBehaviour { @Override public void update(Caster source, PlayerEntity entity, Disguise spell) { if (source instanceof Pony pony) { - PlayerEntity pFrom = pony.getMaster(); + PlayerEntity pFrom = pony.asEntity(); entity.capeX = pFrom.capeX; entity.capeY = pFrom.capeY; 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 9fa24feb..86d780d7 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/RangedAttackBehaviour.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/RangedAttackBehaviour.java @@ -30,10 +30,10 @@ public class RangedAttackBehaviour extends E ProjectileEntity spit = projectileSupplier.apply(entity.world, entity); - Vec3d rot = player.getEntity().getRotationVec(1); + Vec3d rot = player.asEntity().getRotationVec(1); spit.setVelocity(rot.getX(), rot.getY(), rot.getZ(), 1.5F, 3); - spit.setOwner(player.getMaster()); + spit.setOwner(player.asEntity()); if (!entity.isSilent()) { SoundEmitter.playSoundAt(entity, sound, 1, 1 + (entity.world.random.nextFloat() - entity.world.random.nextFloat()) * 0.2F); 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 5d67e1ef..aa027cd7 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/SheepBehaviour.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/SheepBehaviour.java @@ -25,7 +25,7 @@ public class SheepBehaviour extends EntityBehaviour { BlockState state = entity.world.getBlockState(pos); boolean grass = state.isOf(Blocks.GRASS_BLOCK); - if (player.getMaster().isSneaking()) { + if (player.asEntity().isSneaking()) { if (grass && entity.world.isClient && entity.isSheared()) { entity.handleStatus((byte)10); } @@ -38,11 +38,11 @@ public class SheepBehaviour extends EntityBehaviour { } else if (!entity.isSheared()) { ItemStack dropType = new ItemStack(MixinSheepEntity.getDrops().get(entity.getColor()).asItem()); - player.getMaster().playSound(SoundEvents.ENTITY_SHEEP_SHEAR, 1, 1); + player.asEntity().playSound(SoundEvents.ENTITY_SHEEP_SHEAR, 1, 1); entity.setSheared(true); Random rng = entity.world.random; - PlayerInventory inv = player.getMaster().getInventory(); + PlayerInventory inv = player.asEntity().getInventory(); int dropAmount = rng.nextInt(3); int slot; 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 c0e14f7f..e2e8045a 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/ShulkerBehaviour.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/ShulkerBehaviour.java @@ -40,8 +40,8 @@ public class ShulkerBehaviour extends EntityBehaviour { protected void update(Pony player, ShulkerEntity shulker, Disguise spell) { float peekAmount = 30; - double speed = !player.getEntity().isSneaking() ? 0.29 : 0; - speed += Math.sqrt(player.getEntity().getVelocity().horizontalLengthSquared()) * 2; + double speed = !player.asEntity().isSneaking() ? 0.29 : 0; + speed += Math.sqrt(player.asEntity().getVelocity().horizontalLengthSquared()) * 2; peekAmount = (float)MathHelper.clamp(speed, 0, 1); peekAmount = player.getInterpolator().interpolate("peek", peekAmount, 5); 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 eb5c4a06..14709927 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/SilverfishBehaviour.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/SilverfishBehaviour.java @@ -12,7 +12,7 @@ import net.minecraft.world.WorldEvents; public class SilverfishBehaviour extends EntityBehaviour { @Override public void update(Pony player, SilverfishEntity entity, Disguise spell) { - if (!player.isClient() && player.sneakingChanged() && player.getMaster().isSneaking()) { + if (!player.isClient() && player.sneakingChanged() && player.asEntity().isSneaking()) { BlockPos pos = entity.getBlockPos().down(); BlockState state = entity.world.getBlockState(pos); 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 b3acfc67..f7720aae 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/SpellcastingIllagerBehaviour.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/SpellcastingIllagerBehaviour.java @@ -16,7 +16,7 @@ public class SpellcastingIllagerBehaviour extends EntityBehaviour extends EntityBehavio @Override public void update(Pony player, T horse, Disguise spell) { - boolean angry = !player.getEntity().isOnGround() && player.getMaster().isSprinting(); + boolean angry = !player.asEntity().isOnGround() && player.asEntity().isSprinting(); boolean sneaking = isSneakingOnGround(player); angry |= sneaking; diff --git a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/TraderBehaviour.java b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/TraderBehaviour.java index 46af39a9..ddd61b53 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/TraderBehaviour.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/TraderBehaviour.java @@ -8,7 +8,7 @@ import net.minecraft.sound.SoundEvents; public class TraderBehaviour extends EntityBehaviour { @Override public void update(Pony pony, MerchantEntity entity, Disguise spell) { - if (pony.sneakingChanged() && pony.getMaster().isSneaking()) { + if (pony.sneakingChanged() && pony.asEntity().isSneaking()) { entity.setHeadRollingTimeLeft(40); if (!entity.world.isClient()) { diff --git a/src/main/java/com/minelittlepony/unicopia/entity/player/ManaContainer.java b/src/main/java/com/minelittlepony/unicopia/entity/player/ManaContainer.java index 40d49331..c753514f 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/ManaContainer.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/ManaContainer.java @@ -137,12 +137,12 @@ public class ManaContainer implements MagicReserves, Tickable, NbtSerialisable { BarInst(TrackedData marker, float max, float initial) { this.marker = marker; this.max = max; - pony.getMaster().getDataTracker().startTracking(marker, initial); + pony.asEntity().getDataTracker().startTracking(marker, initial); } @Override public float get() { - return pony.getMaster().getDataTracker().get(marker); + return pony.asEntity().getDataTracker().get(marker); } @Override @@ -156,7 +156,7 @@ public class ManaContainer implements MagicReserves, Tickable, NbtSerialisable { } private void load(float value) { - pony.getMaster().getDataTracker().set(marker, value); + pony.asEntity().getDataTracker().set(marker, value); } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerAttributes.java b/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerAttributes.java index 896a0906..0536d71d 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerAttributes.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerAttributes.java @@ -43,7 +43,7 @@ public class PlayerAttributes implements Tickable { @Override public void tick() { - PlayerEntity entity = pony.getMaster(); + PlayerEntity entity = pony.asEntity(); Race race = pony.getSpecies(); toggleAttribute(entity, EntityAttributes.GENERIC_ATTACK_DAMAGE, EARTH_PONY_STRENGTH, race.canUseEarth()); diff --git a/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerCamera.java b/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerCamera.java index 750e9b73..3100a27f 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerCamera.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerCamera.java @@ -21,9 +21,9 @@ public class PlayerCamera extends MotionCompositor { double roll = 0; if (player.getMotion().isFlying()) { - Vec3d vel = player.getMaster().getVelocity(); + Vec3d vel = player.asEntity().getVelocity(); - roll -= calculateRoll(player.getMaster(), vel.x, vel.y, vel.z); + roll -= calculateRoll(player.asEntity(), vel.x, vel.y, vel.z); } if (player.getPhysics().isGravityNegative()) { @@ -31,7 +31,7 @@ public class PlayerCamera extends MotionCompositor { roll += 180; } - if (player.getEntity().age > 10) { + if (player.asEntity().age > 10) { roll = player.getInterpolator().interpolate("roll", (float)roll, 15); } diff --git a/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerCharmTracker.java b/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerCharmTracker.java index a77a6f88..d53a20ed 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerCharmTracker.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerCharmTracker.java @@ -35,16 +35,16 @@ public class PlayerCharmTracker implements NbtSerialisable { } public TypedActionResult> getSpellInHand(Hand hand) { - return Streams.stream(pony.getMaster().getHandItems()) + return Streams.stream(pony.asEntity().getHandItems()) .filter(GemstoneItem::isEnchanted) - .map(stack -> GemstoneItem.consumeSpell(stack, pony.getMaster(), null)) + .map(stack -> GemstoneItem.consumeSpell(stack, pony.asEntity(), null)) .findFirst() .orElse(getEquippedSpell(hand).toAction()); } public void equipSpell(Hand hand, CustomisedSpellType spell) { handSpells[hand.ordinal()] = spell; - pony.getMaster().playSound(SoundEvents.UI_BUTTON_CLICK.value(), 0.25F, 1.75F); + pony.asEntity().playSound(SoundEvents.UI_BUTTON_CLICK.value(), 0.25F, 1.75F); pony.setDirty(); } diff --git a/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerDimensions.java b/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerDimensions.java index 9e53ee4f..70eee553 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerDimensions.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerDimensions.java @@ -25,7 +25,7 @@ public final class PlayerDimensions { .or(() -> physics.isFlyingSurvival ? FLYING_EYE_HEIGHT : physics.isGravityNegative() ? Optional.of(dimensions.height) : Optional.empty()) .map(h -> { if (physics.isGravityNegative()) { - if (pony.getMaster().isSneaking()) { + if (pony.asEntity().isSneaking()) { h += 0.2F; } diff --git a/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerLevelStore.java b/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerLevelStore.java index 9738813d..f4df2616 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerLevelStore.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerLevelStore.java @@ -21,7 +21,7 @@ class PlayerLevelStore implements Levelled.LevelStore { this.dataEntry = dataEntry; this.upgradeMana = upgradeMana; this.levelUpSound = levelUpSound; - pony.getEntity().getDataTracker().startTracking(dataEntry, 0); + pony.asEntity().getDataTracker().startTracking(dataEntry, 0); } @Override @@ -42,11 +42,11 @@ class PlayerLevelStore implements Levelled.LevelStore { @Override public int get() { - return pony.getEntity().getDataTracker().get(dataEntry); + return pony.asEntity().getDataTracker().get(dataEntry); } @Override public void set(int level) { - pony.getEntity().getDataTracker().set(dataEntry, MathHelper.clamp(level, 0, getMax())); + pony.asEntity().getDataTracker().set(dataEntry, MathHelper.clamp(level, 0, getMax())); } } 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 c42fb0db..c7c3f460 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerPhysics.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerPhysics.java @@ -68,7 +68,7 @@ public class PlayerPhysics extends EntityPhysics implements Tickab private final Pony pony; public PlayerPhysics(Pony pony) { - super(pony.getMaster(), Creature.GRAVITY); + super(pony.asEntity(), Creature.GRAVITY); this.pony = pony; dimensions = new PlayerDimensions(pony, this); } @@ -104,7 +104,7 @@ public class PlayerPhysics extends EntityPhysics implements Tickab if (isFlying()) { if (getFlightType() == FlightType.INSECTOID) { - spreadAmount += Math.sin(pony.getEntity().age * 4F) * 8; + spreadAmount += Math.sin(pony.asEntity().age * 4F) * 8; } else { if (isGliding()) { spreadAmount += 2.5F; 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 0f01ccda..72290752 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/Pony.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/Pony.java @@ -38,8 +38,7 @@ import com.minelittlepony.common.util.animation.Interpolator; import com.mojang.authlib.GameProfile; import net.minecraft.block.BlockState; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EquipmentSlot; +import net.minecraft.entity.*; import net.minecraft.entity.attribute.DefaultAttributeContainer; import net.minecraft.entity.attribute.EntityAttributeInstance; import net.minecraft.entity.damage.DamageSource; @@ -289,6 +288,24 @@ public class Pony extends Living implements Copyable, Update return interpolator; } + /** + * @deprecated use asEntity() + */ + @Deprecated(forRemoval = true) + @Override + public final Entity getEntity() { + return asEntity(); + } + + /** + * @deprecated use asEntity() + */ + @Override + @Deprecated(forRemoval = true) + public final LivingEntity getMaster() { + return asEntity(); + } + public void onSpawn() { if (entity.world instanceof ServerWorld sw && getObservedSpecies() == Race.BAT @@ -360,7 +377,7 @@ public class Pony extends Living implements Copyable, Update pos = pos.up(); BlockState state = getReferenceWorld().getBlockState(pos); - return state.isSolidSurface(getReferenceWorld(), pos, getEntity(), Direction.DOWN); + return state.isSolidSurface(getReferenceWorld(), pos, entity, Direction.DOWN); } @Override @@ -393,7 +410,7 @@ public class Pony extends Living implements Copyable, Update entity.addStatusEffect(new StatusEffectInstance(UEffects.SUN_BLINDNESS, SunBlindnessStatusEffect.MAX_DURATION, 1, true, false)); UCriteria.LOOK_INTO_SUN.trigger(entity); } else if (isClientPlayer()) { - InteractionManager.instance().playLoopingSound(entity, InteractionManager.SOUND_EARS_RINGING, getEntity().getId()); + InteractionManager.instance().playLoopingSound(entity, InteractionManager.SOUND_EARS_RINGING, entity.getId()); } } } else if (ticksInSun > 0) { @@ -599,7 +616,7 @@ public class Pony extends Living implements Copyable, Update @Override public void copyFrom(Pony oldPlayer) { speciesPersisted = true; - if (!oldPlayer.getEntity().isRemoved()) { + if (!oldPlayer.asEntity().isRemoved()) { oldPlayer.getSpellSlot().stream(true).forEach(getSpellSlot()::put); } else { oldPlayer.getSpellSlot().stream(true).filter(SpellPredicate.IS_PLACED).forEach(getSpellSlot()::put); @@ -630,7 +647,7 @@ public class Pony extends Living implements Copyable, Update } public boolean isClientPlayer() { - return InteractionManager.instance().isClientPlayer(getMaster()); + return InteractionManager.instance().isClientPlayer(asEntity()); } @SuppressWarnings("unchecked") diff --git a/src/main/java/com/minelittlepony/unicopia/item/AlicornAmuletItem.java b/src/main/java/com/minelittlepony/unicopia/item/AlicornAmuletItem.java index daaf2314..b304a2c8 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/AlicornAmuletItem.java +++ b/src/main/java/com/minelittlepony/unicopia/item/AlicornAmuletItem.java @@ -193,7 +193,7 @@ public class AlicornAmuletItem extends AmuletItem implements ItemTracker.Trackab reserves.getExertion().add(2); } - if (fullSecond && world.random.nextInt(12) == 0 && !pony.getMaster().isCreative()) { + if (fullSecond && world.random.nextInt(12) == 0 && !pony.asEntity().isCreative()) { reserves.getEnergy().add(reserves.getEnergy().getMax() / 10F); pony.getCorruption().add((int)MathHelper.clamp(attachedTicks / ItemTracker.HOURS, 1, pony.getCorruption().getMax())); } diff --git a/src/main/java/com/minelittlepony/unicopia/mixin/client/MixinKeyboardInput.java b/src/main/java/com/minelittlepony/unicopia/mixin/client/MixinKeyboardInput.java index f67de81c..9afd4557 100644 --- a/src/main/java/com/minelittlepony/unicopia/mixin/client/MixinKeyboardInput.java +++ b/src/main/java/com/minelittlepony/unicopia/mixin/client/MixinKeyboardInput.java @@ -25,7 +25,7 @@ abstract class MixinKeyboardInput extends Input { movementSideways = -movementSideways; - if (player.getMaster().getAbilities().flying && !player.getPhysics().isFlying()) { + if (player.asEntity().getAbilities().flying && !player.getPhysics().isFlying()) { tmp = jumping; jumping = sneaking; sneaking = tmp; diff --git a/src/main/java/com/minelittlepony/unicopia/network/MsgPlayerAnimationChange.java b/src/main/java/com/minelittlepony/unicopia/network/MsgPlayerAnimationChange.java index 8c7c3cf8..af2170e8 100644 --- a/src/main/java/com/minelittlepony/unicopia/network/MsgPlayerAnimationChange.java +++ b/src/main/java/com/minelittlepony/unicopia/network/MsgPlayerAnimationChange.java @@ -25,7 +25,7 @@ public class MsgPlayerAnimationChange implements Packet { } public MsgPlayerAnimationChange(Pony player, Animation animation, int duration) { - this.playerId = player.getEntity().getUuid(); + this.playerId = player.asEntity().getUuid(); this.animation = animation; this.duration = duration; } diff --git a/src/main/java/com/minelittlepony/unicopia/network/MsgPlayerCapabilities.java b/src/main/java/com/minelittlepony/unicopia/network/MsgPlayerCapabilities.java index 555c9832..a7573c02 100644 --- a/src/main/java/com/minelittlepony/unicopia/network/MsgPlayerCapabilities.java +++ b/src/main/java/com/minelittlepony/unicopia/network/MsgPlayerCapabilities.java @@ -37,7 +37,7 @@ public class MsgPlayerCapabilities implements Packet { } public MsgPlayerCapabilities(Pony player) { - playerId = player.getEntity().getUuid(); + playerId = player.asEntity().getUuid(); compoundTag = new NbtCompound(); player.toSyncronisedNbt(compoundTag); }