Add a method specifically for getting the wrapped entity and move away from using getMaster() for everything

This commit is contained in:
Sollace 2022-12-19 16:03:35 +01:00
parent 6fd0e79d5a
commit 34b9a54487
53 changed files with 188 additions and 146 deletions

View file

@ -0,0 +1,14 @@
package com.minelittlepony.unicopia;
import net.minecraft.entity.Entity;
/**
* Interface for things that can be owned by an entity.
* <p>
* Ownership is retained so long as the owner is still active. If the owner leaves or dies, the link is broken.
*
* @param <E> The type of object that owns us.
*/
public interface EntityConvertable<E extends Entity> {
E asEntity();
}

View file

@ -212,7 +212,7 @@ public class AbilityDispatcher implements Tickable, NbtSerialisable {
if (data.isPresent()) { if (data.isPresent()) {
Channel.CLIENT_PLAYER_ABILITY.send(new MsgPlayerAbility<>(ability, data, ActivationType.NONE)); Channel.CLIENT_PLAYER_ABILITY.send(new MsgPlayerAbility<>(ability, data, ActivationType.NONE));
} else { } else {
player.getEntity().playSound(USounds.GUI_ABILITY_FAIL, 1, 1); player.asEntity().playSound(USounds.GUI_ABILITY_FAIL, 1, 1);
setCooldown(0); setCooldown(0);
} }
} }

View file

@ -75,8 +75,8 @@ public class BatEeeeAbility implements Ability<Hit> {
Vec3d origin = player.getOriginVector(); Vec3d origin = player.getOriginVector();
if (rng.nextInt(20000) == 0) { if (rng.nextInt(20000) == 0) {
player.getMaster().damage(MagicalDamageSource.create("eeee", player).setBreakSunglasses(), 0.1F); player.asEntity().damage(MagicalDamageSource.create("eeee", player).setBreakSunglasses(), 0.1F);
UCriteria.SCREECH_SELF.trigger(player.getMaster()); UCriteria.SCREECH_SELF.trigger(player.asEntity());
} }
int total = player.findAllEntitiesInRange(5).mapToInt(e -> { int total = player.findAllEntitiesInRange(5).mapToInt(e -> {
@ -95,7 +95,7 @@ public class BatEeeeAbility implements Ability<Hit> {
}).sum(); }).sum();
if (total >= 20) { if (total >= 20) {
UCriteria.SCREECH_TWENTY_MOBS.trigger(player.getMaster()); UCriteria.SCREECH_TWENTY_MOBS.trigger(player.asEntity());
} }
} }

View file

@ -40,7 +40,7 @@ public class BatPonyHangAbility implements Ability<Multi> {
return new Multi(BlockPos.ZERO, 0); return new Multi(BlockPos.ZERO, 0);
} }
return TraceHelper.findBlock(player.getMaster(), 5, 1) return TraceHelper.findBlock(player.asEntity(), 5, 1)
.map(BlockPos::down) .map(BlockPos::down)
.filter(player::canHangAt) .filter(player::canHangAt)
.map(pos -> new Multi(pos, 1)) .map(pos -> new Multi(pos, 1))

View file

@ -64,7 +64,7 @@ public class CarryAbility implements Ability<Hit> {
@Override @Override
public void apply(Pony iplayer, Hit data) { public void apply(Pony iplayer, Hit data) {
PlayerEntity player = iplayer.getMaster(); PlayerEntity player = iplayer.asEntity();
LivingEntity rider = findRider(player, iplayer.getReferenceWorld()); LivingEntity rider = findRider(player, iplayer.getReferenceWorld());
if (player.hasPassengers()) { if (player.hasPassengers()) {

View file

@ -25,7 +25,7 @@ public class ChangelingDisguiseAbility extends ChangelingFeedAbility {
@Nullable @Nullable
@Override @Override
public Hit tryActivate(Pony player) { 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 Hit.INSTANCE;
} }
return null; return null;
@ -33,7 +33,7 @@ public class ChangelingDisguiseAbility extends ChangelingFeedAbility {
@Override @Override
public void apply(Pony iplayer, Hit data) { public void apply(Pony iplayer, Hit data) {
PlayerEntity player = iplayer.getMaster(); PlayerEntity player = iplayer.asEntity();
if (!player.isCreative() && iplayer.getMagicalReserves().getMana().getPercentFill() < 0.9F) { if (!player.isCreative() && iplayer.getMagicalReserves().getMana().getPercentFill() < 0.9F) {
return; return;

View file

@ -61,7 +61,7 @@ public class ChangelingFeedAbility implements Ability<Hit> {
} }
private boolean canFeed(Pony player) { 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) { private boolean canDrain(Entity e) {
@ -80,9 +80,9 @@ public class ChangelingFeedAbility implements Ability<Hit> {
} }
protected List<LivingEntity> getTargets(Pony player) { protected List<LivingEntity> getTargets(Pony player) {
List<Entity> list = VecHelper.findInRange(player.getMaster(), player.getReferenceWorld(), player.getOriginVector(), 3, this::canDrain); List<Entity> list = VecHelper.findInRange(player.asEntity(), player.getReferenceWorld(), player.getOriginVector(), 3, this::canDrain);
TraceHelper.<LivingEntity>findEntity(player.getMaster(), 17, 1, TraceHelper.<LivingEntity>findEntity(player.asEntity(), 17, 1,
looked -> looked instanceof LivingEntity && !list.contains(looked) && canDrain(looked)) looked -> looked instanceof LivingEntity && !list.contains(looked) && canDrain(looked))
.ifPresent(list::add); .ifPresent(list::add);
@ -96,7 +96,7 @@ public class ChangelingFeedAbility implements Ability<Hit> {
@Override @Override
public void apply(Pony iplayer, Hit data) { public void apply(Pony iplayer, Hit data) {
PlayerEntity player = iplayer.getMaster(); PlayerEntity player = iplayer.asEntity();
float maximumHealthGain = player.getMaxHealth() - player.getHealth(); float maximumHealthGain = player.getMaxHealth() - player.getHealth();
int maximumFoodGain = player.canConsume(false) ? (20 - player.getHungerManager().getFoodLevel()) : 0; int maximumFoodGain = player.canConsume(false) ? (20 - player.getHungerManager().getFoodLevel()) : 0;

View file

@ -36,7 +36,7 @@ public class EarthPonyGrowAbility implements Ability<Pos> {
@Override @Override
public Pos tryActivate(Pony player) { 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 @Override

View file

@ -58,9 +58,9 @@ public class EarthPonyKickAbility implements Ability<Pos> {
@Override @Override
public double getCostEstimate(Pony player) { 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) .filter(pos -> TreeType.at(pos, player.getReferenceWorld()) != TreeType.NONE)
.isPresent() ? 3 : 1; .isPresent() ? 3 : 1;
} }
@ -79,7 +79,7 @@ public class EarthPonyKickAbility implements Ability<Pos> {
Vec3d origin = player.getOriginVector(); Vec3d origin = player.getOriginVector();
World w = player.getReferenceWorld(); 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) { if (e instanceof LivingEntity entity) {
float calculatedStrength = 0.5F * (1 + player.getLevel().getScaled(9)); float calculatedStrength = 0.5F * (1 + player.getLevel().getScaled(9));
entity.damage(MagicalDamageSource.KICK, player.getReferenceWorld().random.nextBetween(2, 10) + calculatedStrength); entity.damage(MagicalDamageSource.KICK, player.getReferenceWorld().random.nextBetween(2, 10) + calculatedStrength);
@ -92,7 +92,7 @@ public class EarthPonyKickAbility implements Ability<Pos> {
} }
BlockPos pos = kickLocation.pos(); 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); player.setAnimation(Animation.KICK);
}); });
} }
@ -106,20 +106,20 @@ public class EarthPonyKickAbility implements Ability<Pos> {
@Nullable @Nullable
@Override @Override
public Pos tryActivate(Pony player) { 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) .filter(pos -> TreeType.at(pos, player.getReferenceWorld()) != TreeType.NONE)
.map(Pos::new) .map(Pos::new)
.orElseGet(() -> getDefaultKickLocation(player)); .orElseGet(() -> getDefaultKickLocation(player));
} }
private int getKickDirection(Pony 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) { private Pos getDefaultKickLocation(Pony player) {
Vec3d kickVector = player.getMaster().getRotationVector().multiply(1, 0, 1); Vec3d kickVector = player.asEntity().getRotationVector().multiply(1, 0, 1);
player.getMaster();
if (!MineLPDelegate.getInstance().getPlayerPonyRace(player.getMaster()).isDefault()) { if (!MineLPDelegate.getInstance().getPlayerPonyRace(player.asEntity()).isDefault()) {
kickVector = kickVector.rotateY((float)Math.PI); kickVector = kickVector.rotateY((float)Math.PI);
} }
return new Pos(new BlockPos(player.getOriginVector().add(kickVector))); return new Pos(new BlockPos(player.getOriginVector().add(kickVector)));
@ -154,7 +154,7 @@ public class EarthPonyKickAbility implements Ability<Pos> {
ParticleUtils.spawnParticle(iplayer.getReferenceWorld(), UParticles.GROUND_POUND, data.vec(), Vec3d.ZERO); 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 (BlockDestructionManager.of(player.world).getBlockDestruction(pos) + 4 >= BlockDestructionManager.MAX_DAMAGE) {
if (player.world.random.nextInt(30) == 0) { if (player.world.random.nextInt(30) == 0) {

View file

@ -67,7 +67,9 @@ public class EarthPonyStompAbility implements Ability<Hit> {
@Nullable @Nullable
@Override @Override
public Hit tryActivate(Pony player) { 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); thrustDownwards(player);
return Hit.INSTANCE; return Hit.INSTANCE;
} }
@ -85,13 +87,13 @@ public class EarthPonyStompAbility implements Ability<Hit> {
BlockPos pos = PosHelper.findSolidGroundAt(player.getReferenceWorld(), ppos, player.getPhysics().getGravitySignum()); BlockPos pos = PosHelper.findSolidGroundAt(player.getReferenceWorld(), ppos, player.getPhysics().getGravitySignum());
double downV = Math.sqrt(ppos.getSquaredDistance(pos)) * 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(); player.updateVelocity();
} }
@Override @Override
public void apply(Pony iplayer, Hit data) { public void apply(Pony iplayer, Hit data) {
PlayerEntity player = iplayer.getMaster(); PlayerEntity player = iplayer.asEntity();
iplayer.setAnimation(Animation.STOMP, 10); iplayer.setAnimation(Animation.STOMP, 10);

View file

@ -40,7 +40,7 @@ public class PegasusCaptureStormAbility implements Ability<Hit> {
@Override @Override
public Hit tryActivate(Pony player) { 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; return null;
} }
@ -61,7 +61,7 @@ public class PegasusCaptureStormAbility implements Ability<Hit> {
public void apply(Pony player, Hit data) { public void apply(Pony player, Hit data) {
World w = player.getReferenceWorld(); World w = player.getReferenceWorld();
ItemStack stack = player.getMaster().getStackInHand(Hand.MAIN_HAND); ItemStack stack = player.asEntity().getStackInHand(Hand.MAIN_HAND);
boolean thundering = w.isThundering(); boolean thundering = w.isThundering();
if (stack.getItem() != UItems.EMPTY_JAR) { if (stack.getItem() != UItems.EMPTY_JAR) {
@ -73,12 +73,12 @@ public class PegasusCaptureStormAbility implements Ability<Hit> {
} else if (player.getOrigin().getY() < 120) { } else if (player.getOrigin().getY() < 120) {
tell(player, "ability.unicopia.too_low"); tell(player, "ability.unicopia.too_low");
} else { } else {
if (!player.getMaster().getAbilities().creativeMode) { if (!player.asEntity().getAbilities().creativeMode) {
stack.decrement(1); stack.decrement(1);
} }
if (thundering && w.random.nextBoolean()) { 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) { if (w instanceof ServerWorld) {
ServerWorldProperties props = (ServerWorldProperties)w.getLevelProperties(); ServerWorldProperties props = (ServerWorldProperties)w.getLevelProperties();
@ -91,7 +91,7 @@ public class PegasusCaptureStormAbility implements Ability<Hit> {
((ServerWorld)w).getServer().getPlayerManager().sendToDimension(new GameStateChangeS2CPacket(GameStateChangeS2CPacket.THUNDER_GRADIENT_CHANGED, w.getRainGradient(1)), w.getRegistryKey()); ((ServerWorld)w).getServer().getPlayerManager().sendToDimension(new GameStateChangeS2CPacket(GameStateChangeS2CPacket.THUNDER_GRADIENT_CHANGED, w.getRainGradient(1)), w.getRegistryKey());
} }
} else { } else {
player.getMaster().giveItemStack(UItems.RAIN_CLOUD_JAR.getDefaultStack()); player.asEntity().giveItemStack(UItems.RAIN_CLOUD_JAR.getDefaultStack());
if (w instanceof ServerWorld) { if (w instanceof ServerWorld) {
ServerWorldProperties props = (ServerWorldProperties)w.getLevelProperties(); ServerWorldProperties props = (ServerWorldProperties)w.getLevelProperties();
@ -109,7 +109,7 @@ public class PegasusCaptureStormAbility implements Ability<Hit> {
} }
private void tell(Pony player, String translation) { private void tell(Pony player, String translation) {
player.getMaster().sendMessage(Text.translatable(translation), true); player.asEntity().sendMessage(Text.translatable(translation), true);
} }
@Override @Override

View file

@ -30,7 +30,7 @@ public class PegasusFlightToggleAbility implements Ability<Hit> {
@Nullable @Nullable
@Override @Override
public Hit tryActivate(Pony player) { public Hit tryActivate(Pony player) {
return player.getMaster().isCreative() ? null : Hit.INSTANCE; return player.asEntity().isCreative() ? null : Hit.INSTANCE;
} }
@Override @Override
@ -54,15 +54,15 @@ public class PegasusFlightToggleAbility implements Ability<Hit> {
@Override @Override
public void apply(Pony player, Hit data) { public void apply(Pony player, Hit data) {
if (player.getMaster().isCreative()) { if (player.asEntity().isCreative()) {
return; return;
} }
player.subtractEnergyCost(1); player.subtractEnergyCost(1);
if (!player.getPhysics().isFlying()) { if (!player.getPhysics().isFlying()) {
player.getEntity().addVelocity(0, player.getPhysics().getGravitySignum() * 0.7F, 0); player.asEntity().addVelocity(0, player.getPhysics().getGravitySignum() * 0.7F, 0);
Living.updateVelocity(player.getEntity()); Living.updateVelocity(player.asEntity());
player.getPhysics().startFlying(true); player.getPhysics().startFlying(true);
} else { } else {
player.getPhysics().cancelFlight(true); player.getPhysics().cancelFlight(true);

View file

@ -36,7 +36,7 @@ public class PegasusRainboomAbility implements Ability<Hit> {
@Override @Override
public Hit tryActivate(Pony player) { 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; return null;
} }

View file

@ -96,7 +96,7 @@ public class UnicornCastingAbility implements Ability<Hit> {
if (amount < 0) { if (amount < 0) {
AmuletItem.consumeEnergy(stack, amount); AmuletItem.consumeEnergy(stack, amount);
player.getMagicalReserves().getMana().add(amount * player.getMagicalReserves().getMana().getMax()); 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 { } else {
@ -117,7 +117,7 @@ public class UnicornCastingAbility implements Ability<Hit> {
} else { } else {
player.setAnimation(Animation.ARMS_UP); player.setAnimation(Animation.ARMS_UP);
if (s instanceof HomingSpell homer) { 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); player.playSound(USounds.SPELL_CAST_SUCCESS, 0.05F, 2.2F);
} }
@ -130,7 +130,7 @@ public class UnicornCastingAbility implements Ability<Hit> {
private TypedActionResult<ItemStack> getAmulet(Pony player) { private TypedActionResult<ItemStack> 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 (stack.getItem() instanceof AmuletItem) {
if (((AmuletItem)stack.getItem()).isChargable()) { if (((AmuletItem)stack.getItem()).isChargable()) {
@ -148,7 +148,7 @@ public class UnicornCastingAbility implements Ability<Hit> {
player.getMagicalReserves().getExhaustion().multiply(3.3F); player.getMagicalReserves().getExhaustion().multiply(3.3F);
if (getAmulet(player).getResult() == ActionResult.CONSUME) { 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(); float i = player.getAbilities().getStat(slot).getFillProgress();

View file

@ -54,9 +54,9 @@ public class UnicornDispellAbility implements Ability<Pos> {
if (type.getTapCount() > 1) { if (type.getTapCount() > 1) {
player.setAnimation(Animation.WOLOLO, 10); player.setAnimation(Animation.WOLOLO, 10);
if (player.getSpellSlot().clear()) { 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 { } 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; return true;
} }
@ -85,14 +85,14 @@ public class UnicornDispellAbility implements Ability<Pos> {
@Override @Override
public void apply(Pony player, Pos data) { public void apply(Pony player, Pos data) {
player.setAnimation(Animation.WOLOLO); 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(); target.getSpellSlot().clear();
}); });
} }
private Optional<Caster<?>> getTarget(Pony player) { private Optional<Caster<?>> getTarget(Pony player) {
int maxDistance = player.getMaster().isCreative() ? 1000 : 100; int maxDistance = player.asEntity().isCreative() ? 1000 : 100;
return TraceHelper.findEntity(player.getMaster(), maxDistance, 1, EquinePredicates.IS_PLACED_SPELL).flatMap(Caster::of); return TraceHelper.findEntity(player.asEntity(), maxDistance, 1, EquinePredicates.IS_PLACED_SPELL).flatMap(Caster::of);
} }
@Override @Override

View file

@ -93,7 +93,7 @@ public class UnicornProjectileAbility implements Ability<Hit> {
projectile.setHydrophobic(); projectile.setHydrophobic();
if (spell instanceof HomingSpell) { 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);
} }
}); });
} }

View file

@ -68,21 +68,21 @@ public class UnicornTeleportAbility implements Ability<Pos> {
return null; return null;
} }
int maxDistance = player.getMaster().isCreative() ? 1000 : 100; int maxDistance = player.asEntity().isCreative() ? 1000 : 100;
World w = player.getReferenceWorld(); 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 -> { return trace.getBlockOrEntityPos().map(pos -> {
final BlockPos originalPos = pos; final BlockPos originalPos = pos;
boolean airAbove = enterable(w, pos.up()) && enterable(w, pos.up(2)); 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; final BlockPos p = pos;
pos = trace.getSide().map(sideHit -> { pos = trace.getSide().map(sideHit -> {
if (player.getMaster().isSneaking()) { if (player.asEntity().isSneaking()) {
sideHit = sideHit.getOpposite(); sideHit = sideHit.getOpposite();
} }
@ -102,8 +102,8 @@ public class UnicornTeleportAbility implements Ability<Pos> {
} }
} }
if ((!enterable(w, pos) && exception(w, pos, player.getMaster())) if ((!enterable(w, pos) && exception(w, pos, player.asEntity()))
|| (!enterable(w, pos.up()) && exception(w, pos.up(), player.getMaster()))) { || (!enterable(w, pos.up()) && exception(w, pos.up(), player.asEntity()))) {
return null; return null;
} }

View file

@ -27,7 +27,7 @@ import net.minecraft.world.World;
/** /**
* Interface for any magically capable entities that can cast or persist spells. * Interface for any magically capable entities that can cast or persist spells.
*/ */
public interface Caster<E extends LivingEntity> extends Owned<E>, Levelled, Affine, ParticleSource, SoundEmitter { public interface Caster<E extends LivingEntity> extends Owned<LivingEntity>, Levelled, Affine, ParticleSource, SoundEmitter {
Physics getPhysics(); Physics getPhysics();
@ -37,9 +37,7 @@ public interface Caster<E extends LivingEntity> extends Owned<E>, Levelled, Affi
* Gets the entity directly responsible for casting. * Gets the entity directly responsible for casting.
*/ */
@Override @Override
default Entity getEntity() { Entity getEntity();
return getMaster();
}
/** /**
* Gets the minecraft world * Gets the minecraft world

View file

@ -55,7 +55,7 @@ public class AreaProtectionSpell extends AbstractAreaEffectSpell {
* Calculates the maximum radius of the shield. aka The area of effect. * Calculates the maximum radius of the shield. aka The area of effect.
*/ */
public double getDrawDropOffRange(Caster<?> source) { 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); float min = 4 + getTraits().get(Trait.POWER);
double range = (min + (source.getLevel().getScaled(4) * 2)) / multiplier; double range = (min + (source.getLevel().getScaled(4) * 2)) / multiplier;
if (source instanceof Pony && range > 2) { if (source instanceof Pony && range > 2) {

View file

@ -51,7 +51,7 @@ public interface AttractionUtils {
if (pony.getSpecies().canUseEarth()) { if (pony.getSpecies().canUseEarth()) {
force /= 2; force /= 2;
if (pony.getMaster().isSneaking()) { if (pony.asEntity().isSneaking()) {
force /= 6; force /= 6;
} }
} else if (pony.getSpecies().canFly()) { } else if (pony.getSpecies().canFly()) {

View file

@ -117,7 +117,7 @@ public class ShieldSpell extends AbstractSpell {
* Calculates the maximum radius of the shield. aka The area of effect. * Calculates the maximum radius of the shield. aka The area of effect.
*/ */
public double getDrawDropOffRange(Caster<?> source) { 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); 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; double range = (min + (source.getLevel().getScaled(source instanceof Pony ? 4 : 40) * (source instanceof Pony ? 2 : 10))) / multiplier;

View file

@ -76,7 +76,7 @@ public class TraitDiscovery implements NbtSerialisable {
unreadTraits.addAll(newTraits); unreadTraits.addAll(newTraits);
pony.setDirty(); pony.setDirty();
if (!newTraits.isEmpty() && !pony.getReferenceWorld().isClient) { 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));
} }
} }

View file

@ -65,7 +65,7 @@ public class DismissSpellScreen extends GameGui {
Vec3d cartesian = relativePos Vec3d cartesian = relativePos
.normalize() .normalize()
.multiply(minimalDistance + relativePos.length()) .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)); addDrawableChild(new Entry(placeable).ofCartesian(cartesian));
}); });
}); });

View file

@ -125,7 +125,7 @@ public class UHud extends DrawableHelper {
matrices.pop(); 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.MAIN_HAND), hudX + 15 - xDirection * 13, hudY + 3);
renderSpell(pony.getCharms().getEquippedSpell(Hand.OFF_HAND), hudX + 15 - xDirection * 2, hudY - 3); renderSpell(pony.getCharms().getEquippedSpell(Hand.OFF_HAND), hudX + 15 - xDirection * 2, hudY - 3);
} }

View file

@ -67,10 +67,10 @@ public class SpellbookProfilePageContent extends DrawableHelper implements Spell
int y = SpellbookScreen.TITLE_Y; int y = SpellbookScreen.TITLE_Y;
float delta = pony.getEntity().age + client.getTickDelta(); float delta = pony.asEntity().age + client.getTickDelta();
int currentLevel = pony.getLevel().get(); 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); DrawableUtil.drawScaledText(matrices, ExperienceGroup.forLevel(currentLevel, pony.getCorruption().get()), SpellbookScreen.TITLE_X, y + 13, 0.8F, 0xAA0040FF);
MagicReserves reserves = pony.getMagicalReserves(); MagicReserves reserves = pony.getMagicalReserves();

View file

@ -4,6 +4,7 @@ import java.util.Optional;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import com.minelittlepony.unicopia.EntityConvertable;
import com.minelittlepony.unicopia.Race; import com.minelittlepony.unicopia.Race;
import com.minelittlepony.unicopia.projectile.ProjectileImpactListener; import com.minelittlepony.unicopia.projectile.ProjectileImpactListener;
import com.minelittlepony.unicopia.util.NbtSerialisable; 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.damage.DamageSource;
import net.minecraft.entity.projectile.ProjectileEntity; import net.minecraft.entity.projectile.ProjectileEntity;
public interface Equine<T extends Entity> extends NbtSerialisable, Tickable, ProjectileImpactListener { public interface Equine<T extends Entity> extends NbtSerialisable, Tickable, ProjectileImpactListener, EntityConvertable<T> {
Race getSpecies(); Race getSpecies();
Physics getPhysics(); Physics getPhysics();

View file

@ -32,14 +32,14 @@ public class ItemImpl implements Equine<ItemEntity>, Owned<ItemEntity> {
private static final TrackedData<String> ITEM_RACE = DataTracker.registerData(ItemEntity.class, TrackedDataHandlerRegistry.STRING); private static final TrackedData<String> ITEM_RACE = DataTracker.registerData(ItemEntity.class, TrackedDataHandlerRegistry.STRING);
static final TrackedData<Float> ITEM_GRAVITY = DataTracker.registerData(ItemEntity.class, TrackedDataHandlerRegistry.FLOAT); static final TrackedData<Float> ITEM_GRAVITY = DataTracker.registerData(ItemEntity.class, TrackedDataHandlerRegistry.FLOAT);
private final ItemEntity owner; private final ItemEntity entity;
private final ItemPhysics physics; private final ItemPhysics physics;
private Race serverRace; private Race serverRace;
public ItemImpl(ItemEntity owner) { public ItemImpl(ItemEntity owner) {
this.owner = owner; this.entity = owner;
this.physics = new ItemPhysics(owner); this.physics = new ItemPhysics(owner);
owner.getDataTracker().startTracking(ITEM_GRAVITY, 1F); owner.getDataTracker().startTracking(ITEM_GRAVITY, 1F);
owner.getDataTracker().startTracking(ITEM_RACE, Race.REGISTRY.getId(Race.HUMAN).toString()); owner.getDataTracker().startTracking(ITEM_RACE, Race.REGISTRY.getId(Race.HUMAN).toString());
@ -53,7 +53,7 @@ public class ItemImpl implements Equine<ItemEntity>, Owned<ItemEntity> {
@Override @Override
public boolean beforeUpdate() { public boolean beforeUpdate() {
if (!owner.world.isClient) { if (!entity.world.isClient) {
Race race = getSpecies(); Race race = getSpecies();
if (race != serverRace) { if (race != serverRace) {
serverRace = race; serverRace = race;
@ -62,8 +62,8 @@ public class ItemImpl implements Equine<ItemEntity>, Owned<ItemEntity> {
} }
} }
ItemStack stack = owner.getStack(); ItemStack stack = entity.getStack();
IItemEntity i = (IItemEntity)owner; IItemEntity i = (IItemEntity)entity;
if (!stack.isEmpty()) { if (!stack.isEmpty()) {
@ -71,26 +71,26 @@ public class ItemImpl implements Equine<ItemEntity>, Owned<ItemEntity> {
ClingyItem clingy = item instanceof ClingyItem ? (ClingyItem)item : ClingyItem.DEFAULT; ClingyItem clingy = item instanceof ClingyItem ? (ClingyItem)item : ClingyItem.DEFAULT;
if (clingy.isClingy(stack)) { if (clingy.isClingy(stack)) {
Random rng = owner.world.random; Random rng = entity.world.random;
owner.world.addParticle(clingy.getParticleEffect((IItemEntity)owner), entity.world.addParticle(clingy.getParticleEffect((IItemEntity)entity),
owner.getX() + rng.nextFloat() - 0.5, entity.getX() + rng.nextFloat() - 0.5,
owner.getY() + rng.nextFloat() - 0.5, entity.getY() + rng.nextFloat() - 0.5,
owner.getZ() + rng.nextFloat() - 0.5, entity.getZ() + rng.nextFloat() - 0.5,
0, 0, 0 0, 0, 0
); );
Vec3d position = owner.getPos(); Vec3d position = entity.getPos();
VecHelper.findInRange(owner, owner.world, owner.getPos(), clingy.getFollowDistance(i), e -> e instanceof PlayerEntity) VecHelper.findInRange(entity, entity.world, entity.getPos(), clingy.getFollowDistance(i), e -> e instanceof PlayerEntity)
.stream() .stream()
.sorted((a, b) -> (int)(a.getPos().distanceTo(position) - b.getPos().distanceTo(position))) .sorted((a, b) -> (int)(a.getPos().distanceTo(position) - b.getPos().distanceTo(position)))
.findFirst() .findFirst()
.ifPresent(player -> { .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))); entity.move(MovementType.SELF, player.getPos().subtract(entity.getPos()).multiply(distance < 0.3 ? 1 : clingy.getFollowSpeed(i)));
if (owner.horizontalCollision) { if (entity.horizontalCollision) {
owner.move(MovementType.SELF, new Vec3d(0, owner.verticalCollision ? -0.3 : 0.3, 0)); entity.move(MovementType.SELF, new Vec3d(0, entity.verticalCollision ? -0.3 : 0.3, 0));
} }
clingy.interactWithPlayer(i, (PlayerEntity)player); clingy.interactWithPlayer(i, (PlayerEntity)player);
@ -98,19 +98,19 @@ public class ItemImpl implements Equine<ItemEntity>, Owned<ItemEntity> {
} }
if (stack.isIn(UTags.FALLS_SLOWLY)) { if (stack.isIn(UTags.FALLS_SLOWLY)) {
if (!owner.isOnGround() && Math.signum(owner.getVelocity().y) != getPhysics().getGravitySignum()) { if (!entity.isOnGround() && Math.signum(entity.getVelocity().y) != getPhysics().getGravitySignum()) {
double ticks = ((Entity)owner).age; double ticks = ((Entity)entity).age;
double shift = Math.sin(ticks / 9D) / 9D; double shift = Math.sin(ticks / 9D) / 9D;
double rise = -Math.cos(ticks / 9D) * getPhysics().getGravitySignum(); double rise = -Math.cos(ticks / 9D) * getPhysics().getGravitySignum();
owner.prevYaw = owner.prevYaw; entity.prevYaw = entity.prevYaw;
owner.setYaw(owner.getYaw() + 0.3F); entity.setYaw(entity.getYaw() + 0.3F);
owner.setVelocity( entity.setVelocity(
owner.getVelocity() entity.getVelocity()
.multiply(0.25, 0, 0.25) .multiply(0.25, 0, 0.25)
.add(0, rise, 0) .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<ItemEntity>, Owned<ItemEntity> {
@Override @Override
public Race getSpecies() { public Race getSpecies() {
return Race.fromName(owner.getDataTracker().get(ITEM_RACE), Race.HUMAN); return Race.fromName(entity.getDataTracker().get(ITEM_RACE), Race.HUMAN);
} }
@Override @Override
public void setSpecies(Race race) { 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 @Override
@ -166,7 +166,12 @@ public class ItemImpl implements Equine<ItemEntity>, Owned<ItemEntity> {
@Override @Override
@NotNull @NotNull
public ItemEntity getMaster() { public ItemEntity getMaster() {
return owner; return asEntity();
}
@Override
public ItemEntity asEntity() {
return entity;
} }
public static <T extends Item> T registerTickCallback(T item, GroundTickCallback callback) { public static <T extends Item> T registerTickCallback(T item, GroundTickCallback callback) {

View file

@ -100,12 +100,17 @@ public abstract class Living<T extends LivingEntity> implements Equine<T>, Caste
} }
@Override @Override
public void setMaster(T owner) { public void setMaster(LivingEntity owner) {
} }
@Override @Override
@NotNull @NotNull
public T getMaster() { public LivingEntity getMaster() {
return asEntity();
}
@Override
public final T asEntity() {
return entity; return entity;
} }

View file

@ -40,7 +40,7 @@ public class BlazeBehaviour extends EntityBehaviour<BlazeEntity> {
int fireballsFired = tag.getInt("fireballsFired"); int fireballsFired = tag.getInt("fireballsFired");
if (player.sneakingChanged()) { if (player.sneakingChanged()) {
boolean sneaking = player.getMaster().isSneaking(); boolean sneaking = player.asEntity().isSneaking();
if (sneaking) { if (sneaking) {
firing = true; firing = true;
@ -70,10 +70,10 @@ public class BlazeBehaviour extends EntityBehaviour<BlazeEntity> {
entity.world.syncWorldEvent(null, WorldEvents.BLAZE_SHOOTS, entity.getBlockPos(), 0); 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) { 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.getX() + entity.getRandom().nextGaussian(),
rot.getY(), rot.getY(),
rot.getZ() + entity.getRandom().nextGaussian() rot.getZ() + entity.getRandom().nextGaussian()

View file

@ -27,13 +27,13 @@ public class ChickenBehaviour extends EntityBehaviour<ChickenEntity> {
if (player.sneakingChanged()) { if (player.sneakingChanged()) {
ItemStack egg = entity.getEquippedStack(EquipmentSlot.OFFHAND); ItemStack egg = entity.getEquippedStack(EquipmentSlot.OFFHAND);
if (player.getMaster().isSneaking()) { if (player.asEntity().isSneaking()) {
if (egg.isEmpty()) { if (egg.isEmpty()) {
egg = new ItemStack(Items.EGG); egg = new ItemStack(Items.EGG);
int slot = player.getMaster().getInventory().indexOf(egg); int slot = player.asEntity().getInventory().indexOf(egg);
if (slot > -1) { if (slot > -1) {
player.getMaster().getInventory().removeStack(slot, 1); player.asEntity().getInventory().removeStack(slot, 1);
entity.playSound(SoundEvents.ENTITY_CHICKEN_EGG, entity.playSound(SoundEvents.ENTITY_CHICKEN_EGG,
1, 1,
(entity.world.random.nextFloat() - entity.world.random.nextFloat()) * 0.2F + 4 (entity.world.random.nextFloat() - entity.world.random.nextFloat()) * 0.2F + 4

View file

@ -13,7 +13,7 @@ public class GhastBehaviour extends MobBehaviour<GhastEntity> {
public void update(Pony player, GhastEntity entity, Disguise spell) { public void update(Pony player, GhastEntity entity, Disguise spell) {
if (player.sneakingChanged()) { if (player.sneakingChanged()) {
boolean sneaking = player.getMaster().isSneaking(); boolean sneaking = player.asEntity().isSneaking();
entity.setShooting(sneaking); entity.setShooting(sneaking);
entity.setTarget(sneaking ? findTarget(player, entity) : null); entity.setTarget(sneaking ? findTarget(player, entity) : null);
@ -26,9 +26,9 @@ public class GhastBehaviour extends MobBehaviour<GhastEntity> {
entity.world.syncWorldEvent(null, WorldEvents.GHAST_SHOOTS, entity.getBlockPos(), 0); 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.getX(),
rot.getY(), rot.getY(),
rot.getZ(), rot.getZ(),

View file

@ -9,9 +9,9 @@ public class HoppingBehaviour extends EntityBehaviour<LivingEntity> {
@Override @Override
public void update(Pony player, LivingEntity entity, Disguise spell) { public void update(Pony player, LivingEntity entity, Disguise spell) {
if (player.getEntity().isOnGround()) { if (player.asEntity().isOnGround()) {
if (player.getEntity().getVelocity().horizontalLengthSquared() > 0.01) { if (player.asEntity().getVelocity().horizontalLengthSquared() > 0.01) {
player.getMaster().jump(); player.asEntity().jump();
startJump(entity); startJump(entity);
} }
} else if (player.landedChanged()) { } else if (player.landedChanged()) {

View file

@ -21,12 +21,12 @@ public class MobBehaviour<T extends MobEntity> extends EntityBehaviour<T> {
if (player.sneakingChanged() && isSneakingOnGround(player)) { if (player.sneakingChanged() && isSneakingOnGround(player)) {
LivingEntity target = findTarget(player, entity); LivingEntity target = findTarget(player, entity);
entity.tryAttack(target); entity.tryAttack(target);
target.setAttacker(player.getMaster()); target.setAttacker(player.asEntity());
} }
} }
protected LivingEntity findTarget(Pony player, T entity) { protected LivingEntity findTarget(Pony player, T entity) {
return TraceHelper.<LivingEntity>findEntity(player.getEntity(), 6, 1, return TraceHelper.<LivingEntity>findEntity(player.asEntity(), 6, 1,
e -> e instanceof LivingEntity && e != entity && !player.isOwnedBy(e)) e -> e instanceof LivingEntity && e != entity && !player.isOwnedBy(e))
.orElseGet(() -> getDummy(entity)); .orElseGet(() -> getDummy(entity));
} }

View file

@ -10,7 +10,7 @@ public class PlayerBehaviour extends EntityBehaviour<PlayerEntity> {
@Override @Override
public void update(Caster<?> source, PlayerEntity entity, Disguise spell) { public void update(Caster<?> source, PlayerEntity entity, Disguise spell) {
if (source instanceof Pony pony) { if (source instanceof Pony pony) {
PlayerEntity pFrom = pony.getMaster(); PlayerEntity pFrom = pony.asEntity();
entity.capeX = pFrom.capeX; entity.capeX = pFrom.capeX;
entity.capeY = pFrom.capeY; entity.capeY = pFrom.capeY;

View file

@ -30,10 +30,10 @@ public class RangedAttackBehaviour<T extends Entity & RangedAttackMob> extends E
ProjectileEntity spit = projectileSupplier.apply(entity.world, entity); 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.setVelocity(rot.getX(), rot.getY(), rot.getZ(), 1.5F, 3);
spit.setOwner(player.getMaster()); spit.setOwner(player.asEntity());
if (!entity.isSilent()) { if (!entity.isSilent()) {
SoundEmitter.playSoundAt(entity, sound, 1, 1 + (entity.world.random.nextFloat() - entity.world.random.nextFloat()) * 0.2F); SoundEmitter.playSoundAt(entity, sound, 1, 1 + (entity.world.random.nextFloat() - entity.world.random.nextFloat()) * 0.2F);

View file

@ -25,7 +25,7 @@ public class SheepBehaviour extends EntityBehaviour<SheepEntity> {
BlockState state = entity.world.getBlockState(pos); BlockState state = entity.world.getBlockState(pos);
boolean grass = state.isOf(Blocks.GRASS_BLOCK); boolean grass = state.isOf(Blocks.GRASS_BLOCK);
if (player.getMaster().isSneaking()) { if (player.asEntity().isSneaking()) {
if (grass && entity.world.isClient && entity.isSheared()) { if (grass && entity.world.isClient && entity.isSheared()) {
entity.handleStatus((byte)10); entity.handleStatus((byte)10);
} }
@ -38,11 +38,11 @@ public class SheepBehaviour extends EntityBehaviour<SheepEntity> {
} else if (!entity.isSheared()) { } else if (!entity.isSheared()) {
ItemStack dropType = new ItemStack(MixinSheepEntity.getDrops().get(entity.getColor()).asItem()); 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); entity.setSheared(true);
Random rng = entity.world.random; Random rng = entity.world.random;
PlayerInventory inv = player.getMaster().getInventory(); PlayerInventory inv = player.asEntity().getInventory();
int dropAmount = rng.nextInt(3); int dropAmount = rng.nextInt(3);
int slot; int slot;

View file

@ -40,8 +40,8 @@ public class ShulkerBehaviour extends EntityBehaviour<ShulkerEntity> {
protected void update(Pony player, ShulkerEntity shulker, Disguise spell) { protected void update(Pony player, ShulkerEntity shulker, Disguise spell) {
float peekAmount = 30; float peekAmount = 30;
double speed = !player.getEntity().isSneaking() ? 0.29 : 0; double speed = !player.asEntity().isSneaking() ? 0.29 : 0;
speed += Math.sqrt(player.getEntity().getVelocity().horizontalLengthSquared()) * 2; speed += Math.sqrt(player.asEntity().getVelocity().horizontalLengthSquared()) * 2;
peekAmount = (float)MathHelper.clamp(speed, 0, 1); peekAmount = (float)MathHelper.clamp(speed, 0, 1);
peekAmount = player.getInterpolator().interpolate("peek", peekAmount, 5); peekAmount = player.getInterpolator().interpolate("peek", peekAmount, 5);

View file

@ -12,7 +12,7 @@ import net.minecraft.world.WorldEvents;
public class SilverfishBehaviour extends EntityBehaviour<SilverfishEntity> { public class SilverfishBehaviour extends EntityBehaviour<SilverfishEntity> {
@Override @Override
public void update(Pony player, SilverfishEntity entity, Disguise spell) { 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(); BlockPos pos = entity.getBlockPos().down();
BlockState state = entity.world.getBlockState(pos); BlockState state = entity.world.getBlockState(pos);

View file

@ -16,7 +16,7 @@ public class SpellcastingIllagerBehaviour extends EntityBehaviour<SpellcastingIl
SpellCastAccess() {super(null, null);} SpellCastAccess() {super(null, null);}
static void setSpell(Pony player, SpellcastingIllagerEntity entity, Disguise s) { static void setSpell(Pony player, SpellcastingIllagerEntity entity, Disguise s) {
if (player.getMaster().isSneaking()) { if (player.asEntity().isSneaking()) {
SpellcastingIllagerEntity.Spell[] spells = SpellcastingIllagerEntity.Spell.values(); SpellcastingIllagerEntity.Spell[] spells = SpellcastingIllagerEntity.Spell.values();
SpellcastingIllagerEntity.Spell spell = spells[entity.world.random.nextInt(spells.length - 1) + 1]; SpellcastingIllagerEntity.Spell spell = spells[entity.world.random.nextInt(spells.length - 1) + 1];

View file

@ -8,7 +8,7 @@ public class SteedBehaviour<T extends AbstractHorseEntity> extends EntityBehavio
@Override @Override
public void update(Pony player, T horse, Disguise spell) { 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); boolean sneaking = isSneakingOnGround(player);
angry |= sneaking; angry |= sneaking;

View file

@ -8,7 +8,7 @@ import net.minecraft.sound.SoundEvents;
public class TraderBehaviour extends EntityBehaviour<MerchantEntity> { public class TraderBehaviour extends EntityBehaviour<MerchantEntity> {
@Override @Override
public void update(Pony pony, MerchantEntity entity, Disguise spell) { public void update(Pony pony, MerchantEntity entity, Disguise spell) {
if (pony.sneakingChanged() && pony.getMaster().isSneaking()) { if (pony.sneakingChanged() && pony.asEntity().isSneaking()) {
entity.setHeadRollingTimeLeft(40); entity.setHeadRollingTimeLeft(40);
if (!entity.world.isClient()) { if (!entity.world.isClient()) {

View file

@ -137,12 +137,12 @@ public class ManaContainer implements MagicReserves, Tickable, NbtSerialisable {
BarInst(TrackedData<Float> marker, float max, float initial) { BarInst(TrackedData<Float> marker, float max, float initial) {
this.marker = marker; this.marker = marker;
this.max = max; this.max = max;
pony.getMaster().getDataTracker().startTracking(marker, initial); pony.asEntity().getDataTracker().startTracking(marker, initial);
} }
@Override @Override
public float get() { public float get() {
return pony.getMaster().getDataTracker().get(marker); return pony.asEntity().getDataTracker().get(marker);
} }
@Override @Override
@ -156,7 +156,7 @@ public class ManaContainer implements MagicReserves, Tickable, NbtSerialisable {
} }
private void load(float value) { private void load(float value) {
pony.getMaster().getDataTracker().set(marker, value); pony.asEntity().getDataTracker().set(marker, value);
} }
@Override @Override

View file

@ -43,7 +43,7 @@ public class PlayerAttributes implements Tickable {
@Override @Override
public void tick() { public void tick() {
PlayerEntity entity = pony.getMaster(); PlayerEntity entity = pony.asEntity();
Race race = pony.getSpecies(); Race race = pony.getSpecies();
toggleAttribute(entity, EntityAttributes.GENERIC_ATTACK_DAMAGE, EARTH_PONY_STRENGTH, race.canUseEarth()); toggleAttribute(entity, EntityAttributes.GENERIC_ATTACK_DAMAGE, EARTH_PONY_STRENGTH, race.canUseEarth());

View file

@ -21,9 +21,9 @@ public class PlayerCamera extends MotionCompositor {
double roll = 0; double roll = 0;
if (player.getMotion().isFlying()) { 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()) { if (player.getPhysics().isGravityNegative()) {
@ -31,7 +31,7 @@ public class PlayerCamera extends MotionCompositor {
roll += 180; roll += 180;
} }
if (player.getEntity().age > 10) { if (player.asEntity().age > 10) {
roll = player.getInterpolator().interpolate("roll", (float)roll, 15); roll = player.getInterpolator().interpolate("roll", (float)roll, 15);
} }

View file

@ -35,16 +35,16 @@ public class PlayerCharmTracker implements NbtSerialisable {
} }
public TypedActionResult<CustomisedSpellType<?>> getSpellInHand(Hand hand) { public TypedActionResult<CustomisedSpellType<?>> getSpellInHand(Hand hand) {
return Streams.stream(pony.getMaster().getHandItems()) return Streams.stream(pony.asEntity().getHandItems())
.filter(GemstoneItem::isEnchanted) .filter(GemstoneItem::isEnchanted)
.map(stack -> GemstoneItem.consumeSpell(stack, pony.getMaster(), null)) .map(stack -> GemstoneItem.consumeSpell(stack, pony.asEntity(), null))
.findFirst() .findFirst()
.orElse(getEquippedSpell(hand).toAction()); .orElse(getEquippedSpell(hand).toAction());
} }
public void equipSpell(Hand hand, CustomisedSpellType<?> spell) { public void equipSpell(Hand hand, CustomisedSpellType<?> spell) {
handSpells[hand.ordinal()] = 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(); pony.setDirty();
} }

View file

@ -25,7 +25,7 @@ public final class PlayerDimensions {
.or(() -> physics.isFlyingSurvival ? FLYING_EYE_HEIGHT : physics.isGravityNegative() ? Optional.of(dimensions.height) : Optional.empty()) .or(() -> physics.isFlyingSurvival ? FLYING_EYE_HEIGHT : physics.isGravityNegative() ? Optional.of(dimensions.height) : Optional.empty())
.map(h -> { .map(h -> {
if (physics.isGravityNegative()) { if (physics.isGravityNegative()) {
if (pony.getMaster().isSneaking()) { if (pony.asEntity().isSneaking()) {
h += 0.2F; h += 0.2F;
} }

View file

@ -21,7 +21,7 @@ class PlayerLevelStore implements Levelled.LevelStore {
this.dataEntry = dataEntry; this.dataEntry = dataEntry;
this.upgradeMana = upgradeMana; this.upgradeMana = upgradeMana;
this.levelUpSound = levelUpSound; this.levelUpSound = levelUpSound;
pony.getEntity().getDataTracker().startTracking(dataEntry, 0); pony.asEntity().getDataTracker().startTracking(dataEntry, 0);
} }
@Override @Override
@ -42,11 +42,11 @@ class PlayerLevelStore implements Levelled.LevelStore {
@Override @Override
public int get() { public int get() {
return pony.getEntity().getDataTracker().get(dataEntry); return pony.asEntity().getDataTracker().get(dataEntry);
} }
@Override @Override
public void set(int level) { 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()));
} }
} }

View file

@ -68,7 +68,7 @@ public class PlayerPhysics extends EntityPhysics<PlayerEntity> implements Tickab
private final Pony pony; private final Pony pony;
public PlayerPhysics(Pony pony) { public PlayerPhysics(Pony pony) {
super(pony.getMaster(), Creature.GRAVITY); super(pony.asEntity(), Creature.GRAVITY);
this.pony = pony; this.pony = pony;
dimensions = new PlayerDimensions(pony, this); dimensions = new PlayerDimensions(pony, this);
} }
@ -104,7 +104,7 @@ public class PlayerPhysics extends EntityPhysics<PlayerEntity> implements Tickab
if (isFlying()) { if (isFlying()) {
if (getFlightType() == FlightType.INSECTOID) { if (getFlightType() == FlightType.INSECTOID) {
spreadAmount += Math.sin(pony.getEntity().age * 4F) * 8; spreadAmount += Math.sin(pony.asEntity().age * 4F) * 8;
} else { } else {
if (isGliding()) { if (isGliding()) {
spreadAmount += 2.5F; spreadAmount += 2.5F;

View file

@ -38,8 +38,7 @@ import com.minelittlepony.common.util.animation.Interpolator;
import com.mojang.authlib.GameProfile; import com.mojang.authlib.GameProfile;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.entity.Entity; import net.minecraft.entity.*;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.attribute.DefaultAttributeContainer; import net.minecraft.entity.attribute.DefaultAttributeContainer;
import net.minecraft.entity.attribute.EntityAttributeInstance; import net.minecraft.entity.attribute.EntityAttributeInstance;
import net.minecraft.entity.damage.DamageSource; import net.minecraft.entity.damage.DamageSource;
@ -289,6 +288,24 @@ public class Pony extends Living<PlayerEntity> implements Copyable<Pony>, Update
return interpolator; 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() { public void onSpawn() {
if (entity.world instanceof ServerWorld sw if (entity.world instanceof ServerWorld sw
&& getObservedSpecies() == Race.BAT && getObservedSpecies() == Race.BAT
@ -360,7 +377,7 @@ public class Pony extends Living<PlayerEntity> implements Copyable<Pony>, Update
pos = pos.up(); pos = pos.up();
BlockState state = getReferenceWorld().getBlockState(pos); BlockState state = getReferenceWorld().getBlockState(pos);
return state.isSolidSurface(getReferenceWorld(), pos, getEntity(), Direction.DOWN); return state.isSolidSurface(getReferenceWorld(), pos, entity, Direction.DOWN);
} }
@Override @Override
@ -393,7 +410,7 @@ public class Pony extends Living<PlayerEntity> implements Copyable<Pony>, Update
entity.addStatusEffect(new StatusEffectInstance(UEffects.SUN_BLINDNESS, SunBlindnessStatusEffect.MAX_DURATION, 1, true, false)); entity.addStatusEffect(new StatusEffectInstance(UEffects.SUN_BLINDNESS, SunBlindnessStatusEffect.MAX_DURATION, 1, true, false));
UCriteria.LOOK_INTO_SUN.trigger(entity); UCriteria.LOOK_INTO_SUN.trigger(entity);
} else if (isClientPlayer()) { } 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) { } else if (ticksInSun > 0) {
@ -599,7 +616,7 @@ public class Pony extends Living<PlayerEntity> implements Copyable<Pony>, Update
@Override @Override
public void copyFrom(Pony oldPlayer) { public void copyFrom(Pony oldPlayer) {
speciesPersisted = true; speciesPersisted = true;
if (!oldPlayer.getEntity().isRemoved()) { if (!oldPlayer.asEntity().isRemoved()) {
oldPlayer.getSpellSlot().stream(true).forEach(getSpellSlot()::put); oldPlayer.getSpellSlot().stream(true).forEach(getSpellSlot()::put);
} else { } else {
oldPlayer.getSpellSlot().stream(true).filter(SpellPredicate.IS_PLACED).forEach(getSpellSlot()::put); oldPlayer.getSpellSlot().stream(true).filter(SpellPredicate.IS_PLACED).forEach(getSpellSlot()::put);
@ -630,7 +647,7 @@ public class Pony extends Living<PlayerEntity> implements Copyable<Pony>, Update
} }
public boolean isClientPlayer() { public boolean isClientPlayer() {
return InteractionManager.instance().isClientPlayer(getMaster()); return InteractionManager.instance().isClientPlayer(asEntity());
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")

View file

@ -193,7 +193,7 @@ public class AlicornAmuletItem extends AmuletItem implements ItemTracker.Trackab
reserves.getExertion().add(2); 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); reserves.getEnergy().add(reserves.getEnergy().getMax() / 10F);
pony.getCorruption().add((int)MathHelper.clamp(attachedTicks / ItemTracker.HOURS, 1, pony.getCorruption().getMax())); pony.getCorruption().add((int)MathHelper.clamp(attachedTicks / ItemTracker.HOURS, 1, pony.getCorruption().getMax()));
} }

View file

@ -25,7 +25,7 @@ abstract class MixinKeyboardInput extends Input {
movementSideways = -movementSideways; movementSideways = -movementSideways;
if (player.getMaster().getAbilities().flying && !player.getPhysics().isFlying()) { if (player.asEntity().getAbilities().flying && !player.getPhysics().isFlying()) {
tmp = jumping; tmp = jumping;
jumping = sneaking; jumping = sneaking;
sneaking = tmp; sneaking = tmp;

View file

@ -25,7 +25,7 @@ public class MsgPlayerAnimationChange implements Packet<PlayerEntity> {
} }
public MsgPlayerAnimationChange(Pony player, Animation animation, int duration) { public MsgPlayerAnimationChange(Pony player, Animation animation, int duration) {
this.playerId = player.getEntity().getUuid(); this.playerId = player.asEntity().getUuid();
this.animation = animation; this.animation = animation;
this.duration = duration; this.duration = duration;
} }

View file

@ -37,7 +37,7 @@ public class MsgPlayerCapabilities implements Packet<PlayerEntity> {
} }
public MsgPlayerCapabilities(Pony player) { public MsgPlayerCapabilities(Pony player) {
playerId = player.getEntity().getUuid(); playerId = player.asEntity().getUuid();
compoundTag = new NbtCompound(); compoundTag = new NbtCompound();
player.toSyncronisedNbt(compoundTag); player.toSyncronisedNbt(compoundTag);
} }