diff --git a/src/main/java/com/minelittlepony/unicopia/EntityConvertable.java b/src/main/java/com/minelittlepony/unicopia/EntityConvertable.java index 9b0f4037..dcf4373e 100644 --- a/src/main/java/com/minelittlepony/unicopia/EntityConvertable.java +++ b/src/main/java/com/minelittlepony/unicopia/EntityConvertable.java @@ -1,6 +1,8 @@ package com.minelittlepony.unicopia; import net.minecraft.entity.Entity; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Vec3d; /** * Interface for things that can be owned by an entity. @@ -11,4 +13,17 @@ import net.minecraft.entity.Entity; */ public interface EntityConvertable { E asEntity(); + + /** + * Gets the center position where this caster is located. + */ + default BlockPos getOrigin() { + return asEntity().getBlockPos(); + } + /** + * Gets the center position where this caster is located. + */ + default Vec3d getOriginVector() { + return asEntity().getPos(); + } } diff --git a/src/main/java/com/minelittlepony/unicopia/WeaklyOwned.java b/src/main/java/com/minelittlepony/unicopia/WeaklyOwned.java index e6aa0aef..09c3c632 100644 --- a/src/main/java/com/minelittlepony/unicopia/WeaklyOwned.java +++ b/src/main/java/com/minelittlepony/unicopia/WeaklyOwned.java @@ -8,7 +8,6 @@ import org.jetbrains.annotations.Nullable; import com.minelittlepony.unicopia.entity.EntityReference; import net.minecraft.entity.Entity; -import net.minecraft.world.World; /** * Interface for things that can be weakly owned (by an entity). @@ -16,7 +15,7 @@ import net.minecraft.world.World; * * @param The type of object that owns us. */ -public interface WeaklyOwned extends Owned { +public interface WeaklyOwned extends Owned, WorldConvertable { EntityReference getMasterReference(); @@ -40,14 +39,10 @@ public interface WeaklyOwned extends Owned { getMasterReference().set(master); } - default World getReferenceWorld() { - return ((Entity)this).getEntityWorld(); - } - @Nullable @Override default E getMaster() { - return getMasterReference().get(getReferenceWorld()); + return getMasterReference().get(asWorld()); } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/WorldConvertable.java b/src/main/java/com/minelittlepony/unicopia/WorldConvertable.java new file mode 100644 index 00000000..fafe7662 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/WorldConvertable.java @@ -0,0 +1,10 @@ +package com.minelittlepony.unicopia; + +import net.minecraft.world.World; + +public interface WorldConvertable { + /** + * Gets the minecraft world + */ + World asWorld(); +} diff --git a/src/main/java/com/minelittlepony/unicopia/ability/AbilityDispatcher.java b/src/main/java/com/minelittlepony/unicopia/ability/AbilityDispatcher.java index 12228c17..a368250b 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/AbilityDispatcher.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/AbilityDispatcher.java @@ -202,7 +202,7 @@ public class AbilityDispatcher implements Tickable, NbtSerialisable { return; } - if (ability.canActivate(player.getReferenceWorld(), player)) { + if (ability.canActivate(player.asWorld(), player)) { triggered = true; setCooldown(ability.getCooldownTime(player)); diff --git a/src/main/java/com/minelittlepony/unicopia/ability/BatEeeeAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/BatEeeeAbility.java index b4f8a1f6..bc598e9d 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/BatEeeeAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/BatEeeeAbility.java @@ -54,18 +54,18 @@ public class BatEeeeAbility implements Ability { @Override public void apply(Pony player, Hit data) { - Random rng = player.getReferenceWorld().random; + Random rng = player.asWorld().random; int count = 1 + rng.nextInt(10); for (int i = 0; i < count; i++) { - player.getReferenceWorld().playSound(null, player.getOrigin(), USounds.ENTITY_PLAYER_BATPONY_SCREECH, SoundCategory.PLAYERS, + player.asWorld().playSound(null, player.getOrigin(), USounds.ENTITY_PLAYER_BATPONY_SCREECH, SoundCategory.PLAYERS, 0.9F + (rng.nextFloat() - 0.5F) / 2F, 1.6F + (rng.nextFloat() - 0.5F) ); } - AwaitTickQueue.scheduleTask(player.getReferenceWorld(), w -> { + AwaitTickQueue.scheduleTask(player.asWorld(), w -> { for (int i = 0; i < count; i++) { - player.getReferenceWorld().playSound(null, player.getOrigin(), USounds.ENTITY_PLAYER_BATPONY_SCREECH, SoundCategory.PLAYERS, + player.asWorld().playSound(null, player.getOrigin(), USounds.ENTITY_PLAYER_BATPONY_SCREECH, SoundCategory.PLAYERS, 0.9F + (rng.nextFloat() - 0.5F) / 2F, 1.6F + (rng.nextFloat() - 0.5F) ); diff --git a/src/main/java/com/minelittlepony/unicopia/ability/CarryAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/CarryAbility.java index 0e33751a..14f5e74a 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/CarryAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/CarryAbility.java @@ -55,7 +55,7 @@ public class CarryAbility implements Ability { public boolean onQuickAction(Pony player, ActivationType type) { if (type == ActivationType.TAP && player.getPhysics().isFlying()) { - player.getPhysics().dashForward((float)player.getReferenceWorld().random.nextTriangular(1, 0.3F)); + player.getPhysics().dashForward((float)player.asWorld().random.nextTriangular(1, 0.3F)); return true; } @@ -65,7 +65,7 @@ public class CarryAbility implements Ability { @Override public void apply(Pony iplayer, Hit data) { PlayerEntity player = iplayer.asEntity(); - LivingEntity rider = findRider(player, iplayer.getReferenceWorld()); + LivingEntity rider = findRider(player, iplayer.asWorld()); if (player.hasPassengers()) { player.removeAllPassengers(); diff --git a/src/main/java/com/minelittlepony/unicopia/ability/ChangelingDisguiseAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/ChangelingDisguiseAbility.java index 1e5364ee..2ebaa7e7 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/ChangelingDisguiseAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/ChangelingDisguiseAbility.java @@ -42,8 +42,8 @@ public class ChangelingDisguiseAbility extends ChangelingFeedAbility { Trace trace = Trace.create(player, 10, 1, EquinePredicates.VALID_FOR_DISGUISE); Entity looked = trace.getEntity().map(AbstractDisguiseSpell::getAppearance).orElseGet(() -> trace.getBlockPos().map(pos -> { - if (!iplayer.getReferenceWorld().isAir(pos)) { - return MixinFallingBlockEntity.createInstance(player.getEntityWorld(), 0, 0, 0, iplayer.getReferenceWorld().getBlockState(pos)); + if (!iplayer.asWorld().isAir(pos)) { + return MixinFallingBlockEntity.createInstance(player.getEntityWorld(), 0, 0, 0, iplayer.asWorld().getBlockState(pos)); } return null; }).orElse(null)); diff --git a/src/main/java/com/minelittlepony/unicopia/ability/ChangelingFeedAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/ChangelingFeedAbility.java index 0ed15c06..43e9462b 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/ChangelingFeedAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/ChangelingFeedAbility.java @@ -80,7 +80,7 @@ public class ChangelingFeedAbility implements Ability { } protected List getTargets(Pony player) { - List list = VecHelper.findInRange(player.asEntity(), player.getReferenceWorld(), player.getOriginVector(), 3, this::canDrain); + List list = VecHelper.findInRange(player.asEntity(), player.asWorld(), player.getOriginVector(), 3, this::canDrain); TraceHelper.findEntity(player.asEntity(), 17, 1, looked -> looked instanceof LivingEntity && !list.contains(looked) && canDrain(looked)) @@ -162,7 +162,7 @@ public class ChangelingFeedAbility implements Ability { @Override public void postApply(Pony player, AbilitySlot slot) { - if (player.getReferenceWorld().random.nextInt(10) == 0) { + if (player.asWorld().random.nextInt(10) == 0) { player.spawnParticles(ParticleTypes.HEART, 1); } } diff --git a/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyGrowAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyGrowAbility.java index 52797ba5..d1ba7ee9 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyGrowAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyGrowAbility.java @@ -56,7 +56,7 @@ public class EarthPonyGrowAbility implements Ability { for (BlockPos pos : BlockPos.iterate( data.pos().add(-2, -2, -2), data.pos().add( 2, 2, 2))) { - count += applySingle(player.getReferenceWorld(), player.getReferenceWorld().getBlockState(pos), pos); + count += applySingle(player.asWorld(), player.asWorld().getBlockState(pos), pos); } if (count > 0) { @@ -80,7 +80,7 @@ public class EarthPonyGrowAbility implements Ability { public void preApply(Pony player, AbilitySlot slot) { player.getMagicalReserves().getExertion().add(30); - if (player.getReferenceWorld().isClient()) { + if (player.asWorld().isClient()) { player.spawnParticles(MagicParticleEffect.UNICORN, 1); } } diff --git a/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyKickAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyKickAbility.java index 467c0eea..d080b61f 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyKickAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyKickAbility.java @@ -61,7 +61,7 @@ public class EarthPonyKickAbility implements Ability { double distance = MineLPDelegate.getInstance().getPlayerPonyRace(player.asEntity()).isDefault() ? 6 : -6; return TraceHelper.findBlock(player.asEntity(), distance, 1) - .filter(pos -> TreeType.at(pos, player.getReferenceWorld()) != TreeType.NONE) + .filter(pos -> TreeType.at(pos, player.asWorld()) != TreeType.NONE) .isPresent() ? 3 : 1; } @@ -77,12 +77,12 @@ public class EarthPonyKickAbility implements Ability { if (!player.isClient()) { data.ifPresent(kickLocation -> { Vec3d origin = player.getOriginVector(); - World w = player.getReferenceWorld(); + World w = player.asWorld(); 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); + entity.damage(MagicalDamageSource.KICK, player.asWorld().random.nextBetween(2, 10) + calculatedStrength); entity.takeKnockback(calculatedStrength, origin.x - entity.getX(), origin.z - entity.getZ()); Living.updateVelocity(entity); player.subtractEnergyCost(3); @@ -107,7 +107,7 @@ public class EarthPonyKickAbility implements Ability { @Override public Pos tryActivate(Pony player) { return TraceHelper.findBlock(player.asEntity(), 6 * getKickDirection(player), 1) - .filter(pos -> TreeType.at(pos, player.getReferenceWorld()) != TreeType.NONE) + .filter(pos -> TreeType.at(pos, player.asWorld()) != TreeType.NONE) .map(Pos::new) .orElseGet(() -> getDefaultKickLocation(player)); } @@ -128,10 +128,10 @@ public class EarthPonyKickAbility implements Ability { @Override public boolean canApply(Pony player, Pos data) { BlockPos pos = data.pos(); - TreeType tree = TreeType.at(pos, player.getReferenceWorld()); + TreeType tree = TreeType.at(pos, player.asWorld()); - return tree == TreeType.NONE || tree.findBase(player.getReferenceWorld(), pos) - .map(base -> tree.countBlocks(player.getReferenceWorld(), pos) > 0) + return tree == TreeType.NONE || tree.findBase(player.asWorld(), pos) + .map(base -> tree.countBlocks(player.asWorld(), pos) > 0) .orElse(false); } @@ -143,7 +143,7 @@ public class EarthPonyKickAbility implements Ability { @Override public void apply(Pony iplayer, Pos data) { BlockPos pos = data.pos(); - TreeType tree = TreeType.at(pos, iplayer.getReferenceWorld()); + TreeType tree = TreeType.at(pos, iplayer.asWorld()); iplayer.setAnimation(Animation.KICK); iplayer.subtractEnergyCost(tree == TreeType.NONE ? 1 : 3); @@ -151,7 +151,7 @@ public class EarthPonyKickAbility implements Ability { if (tree == TreeType.NONE) { return; } else { - ParticleUtils.spawnParticle(iplayer.getReferenceWorld(), UParticles.GROUND_POUND, data.vec(), Vec3d.ZERO); + ParticleUtils.spawnParticle(iplayer.asWorld(), UParticles.GROUND_POUND, data.vec(), Vec3d.ZERO); } PlayerEntity player = iplayer.asEntity(); diff --git a/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyStompAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyStompAbility.java index 99429729..62f28443 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyStompAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyStompAbility.java @@ -84,7 +84,7 @@ public class EarthPonyStompAbility implements Ability { private void thrustDownwards(Pony player) { BlockPos ppos = player.getOrigin(); - BlockPos pos = PosHelper.findSolidGroundAt(player.getReferenceWorld(), ppos, player.getPhysics().getGravitySignum()); + BlockPos pos = PosHelper.findSolidGroundAt(player.asWorld(), ppos, player.getPhysics().getGravitySignum()); double downV = Math.sqrt(ppos.getSquaredDistance(pos)) * player.getPhysics().getGravitySignum(); player.asEntity().addVelocity(0, -downV, 0); @@ -104,7 +104,7 @@ public class EarthPonyStompAbility implements Ability { float heavyness = 1 + EnchantmentHelper.getEquipmentLevel(UEnchantments.HEAVY, player); - iplayer.getReferenceWorld().getOtherEntities(player, areaOfEffect.offset(iplayer.getOriginVector())).forEach(i -> { + iplayer.asWorld().getOtherEntities(player, areaOfEffect.offset(iplayer.getOriginVector())).forEach(i -> { double dist = Math.sqrt(center.getSquaredDistance(i.getBlockPos())); if (dist <= rad + 3) { diff --git a/src/main/java/com/minelittlepony/unicopia/ability/PegasusCaptureStormAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/PegasusCaptureStormAbility.java index c5b7b2da..a1eb5a64 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/PegasusCaptureStormAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/PegasusCaptureStormAbility.java @@ -60,7 +60,7 @@ public class PegasusCaptureStormAbility implements Ability { @Override public void apply(Pony player, Hit data) { - World w = player.getReferenceWorld(); + World w = player.asWorld(); ItemStack stack = player.asEntity().getStackInHand(Hand.MAIN_HAND); boolean thundering = w.isThundering(); diff --git a/src/main/java/com/minelittlepony/unicopia/ability/PegasusRainboomAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/PegasusRainboomAbility.java index e1e6eb2a..e50fbbc6 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/PegasusRainboomAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/PegasusRainboomAbility.java @@ -61,7 +61,7 @@ public class PegasusRainboomAbility implements Ability { public boolean onQuickAction(Pony player, ActivationType type) { if (type == ActivationType.TAP && player.getPhysics().isFlying() && player.getMagicalReserves().getMana().get() > 40) { - player.getPhysics().dashForward((float)player.getReferenceWorld().random.nextTriangular(2.5F, 0.3F)); + player.getPhysics().dashForward((float)player.asWorld().random.nextTriangular(2.5F, 0.3F)); player.subtractEnergyCost(4); return true; } diff --git a/src/main/java/com/minelittlepony/unicopia/ability/UnicornCastingAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/UnicornCastingAbility.java index c8b0b7b3..354476d0 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.asEntity(), USounds.ITEM_AMULET_RECHARGE, SoundCategory.PLAYERS, 1, 1); + player.asWorld().playSoundFromEntity(null, player.asEntity(), USounds.ITEM_AMULET_RECHARGE, SoundCategory.PLAYERS, 1, 1); } } } else { @@ -152,7 +152,7 @@ public class UnicornCastingAbility implements Ability { float i = player.getAbilities().getStat(slot).getFillProgress(); - Random rng = player.getReferenceWorld().random; + Random rng = player.asWorld().random; player.addParticle(i > 0.5F ? ParticleTypes.LARGE_SMOKE : ParticleTypes.CLOUD, eyes, VecHelper.supply(() -> (rng.nextGaussian() - 0.5) / 10)); player.playSound(USounds.ITEM_AMULET_CHARGING, 1, i / 20); } else { diff --git a/src/main/java/com/minelittlepony/unicopia/ability/UnicornDispellAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/UnicornDispellAbility.java index abd73db5..315a9916 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/UnicornDispellAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/UnicornDispellAbility.java @@ -85,7 +85,7 @@ public class UnicornDispellAbility implements Ability { @Override public void apply(Pony player, Pos data) { player.setAnimation(Animation.WOLOLO); - Caster.stream(VecHelper.findInRange(player.asEntity(), player.getReferenceWorld(), data.vec(), 3, EquinePredicates.IS_PLACED_SPELL).stream()).forEach(target -> { + Caster.stream(VecHelper.findInRange(player.asEntity(), player.asWorld(), data.vec(), 3, EquinePredicates.IS_PLACED_SPELL).stream()).forEach(target -> { target.getSpellSlot().clear(); }); } diff --git a/src/main/java/com/minelittlepony/unicopia/ability/UnicornTeleportAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/UnicornTeleportAbility.java index 2c162bfc..7b339a8d 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/UnicornTeleportAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/UnicornTeleportAbility.java @@ -71,7 +71,7 @@ public class UnicornTeleportAbility implements Ability { int maxDistance = player.asEntity().isCreative() ? 1000 : 100; - World w = player.getReferenceWorld(); + World w = player.asWorld(); Trace trace = Trace.create(player.asEntity(), maxDistance, 1, EntityPredicates.EXCEPT_SPECTATOR); return trace.getBlockOrEntityPos().map(pos -> { @@ -133,7 +133,7 @@ public class UnicornTeleportAbility implements Ability { return; } - teleportee.getReferenceWorld().playSound(null, teleportee.getOrigin(), USounds.ENTITY_PLAYER_UNICORN_TELEPORT, SoundCategory.PLAYERS, 1, 1); + teleportee.asWorld().playSound(null, teleportee.getOrigin(), USounds.ENTITY_PLAYER_UNICORN_TELEPORT, SoundCategory.PLAYERS, 1, 1); double distance = destination.distanceTo(teleportee) / 10; diff --git a/src/main/java/com/minelittlepony/unicopia/ability/data/Pos.java b/src/main/java/com/minelittlepony/unicopia/ability/data/Pos.java index 15b082d8..628a6910 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/data/Pos.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/data/Pos.java @@ -47,6 +47,6 @@ public class Pos extends Hit { } public double distanceTo(Caster caster) { - return Math.sqrt(caster.getEntity().squaredDistanceTo(x, y, z)); + return Math.sqrt(caster.asEntity().squaredDistanceTo(x, y, z)); } } \ No newline at end of file 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 b4ac4170..57b5a60e 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/Caster.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/Caster.java @@ -6,8 +6,7 @@ import java.util.stream.Stream; import org.jetbrains.annotations.Nullable; -import com.minelittlepony.unicopia.EquinePredicates; -import com.minelittlepony.unicopia.Owned; +import com.minelittlepony.unicopia.*; import com.minelittlepony.unicopia.ability.magic.spell.effect.SpellType; import com.minelittlepony.unicopia.block.data.ModificationType; import com.minelittlepony.unicopia.entity.Physics; @@ -27,38 +26,35 @@ 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, + EntityConvertable, + WorldConvertable { Physics getPhysics(); SpellContainer getSpellSlot(); /** - * Gets the entity directly responsible for casting. + * Removes the desired amount of mana or health from this caster in exchange for a spell's benefits. + *

+ * @return False if the transaction has depleted the caster's reserves. */ - @Override - Entity getEntity(); + boolean subtractEnergyCost(double amount); - /** - * Gets the minecraft world - */ @Override - default World getReferenceWorld() { - return getEntity().getEntityWorld(); + default World asWorld() { + return asEntity().world; } /** * Returns true if we're executing on the client. */ default boolean isClient() { - return getReferenceWorld().isClient(); - } - - /** - * Gets the center position where this caster is located. - */ - default BlockPos getOrigin() { - return getEntity().getBlockPos(); + return asWorld().isClient(); } default boolean canModifyAt(BlockPos pos) { @@ -69,11 +65,11 @@ public interface Caster extends Owned, Lev if (mod.checkPhysical()) { if (getMaster() instanceof PlayerEntity player) { - if (!getReferenceWorld().canPlayerModifyAt(player, pos)) { + if (!asWorld().canPlayerModifyAt(player, pos)) { return false; } } else { - if (!getReferenceWorld().getGameRules().getBoolean(GameRules.DO_MOB_GRIEFING)) { + if (!asWorld().getGameRules().getBoolean(GameRules.DO_MOB_GRIEFING)) { return false; } } @@ -82,13 +78,6 @@ public interface Caster extends Owned, Lev return !mod.checkMagical() || canCastAt(Vec3d.ofCenter(pos)); } - /** - * Removes the desired amount of mana or health from this caster in exchange for a spell's benefits. - *

- * @return False if the transaction has depleted the caster's reserves. - */ - boolean subtractEnergyCost(double amount); - default Stream> findAllSpellsInRange(double radius) { return findAllSpellsInRange(radius, null); } @@ -98,7 +87,7 @@ public interface Caster extends Owned, Lev } default Stream findAllEntitiesInRange(double radius, @Nullable Predicate test) { - return VecHelper.findInRange(getEntity(), getReferenceWorld(), getOriginVector(), radius, test).stream(); + return VecHelper.findInRange(asEntity(), asWorld(), getOriginVector(), radius, test).stream(); } default Stream findAllEntitiesInRange(double radius) { diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/AbstractDisguiseSpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/AbstractDisguiseSpell.java index 55541abd..36bd300b 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/AbstractDisguiseSpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/AbstractDisguiseSpell.java @@ -28,8 +28,8 @@ public abstract class AbstractDisguiseSpell extends AbstractSpell implements Dis @Override public void onDestroyed(Caster caster) { - caster.getEntity().calculateDimensions(); - caster.getEntity().setInvisible(false); + caster.asEntity().calculateDimensions(); + caster.asEntity().setInvisible(false); if (caster instanceof Pony) { ((Pony) caster).setInvisible(false); } diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/DispersableDisguiseSpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/DispersableDisguiseSpell.java index 85a12121..650867b6 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/DispersableDisguiseSpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/DispersableDisguiseSpell.java @@ -50,7 +50,7 @@ public class DispersableDisguiseSpell extends AbstractDisguiseSpell implements I if (isSuppressed()) { source.spawnParticles(MagicParticleEffect.UNICORN, 5); source.spawnParticles(UParticles.CHANGELING_MAGIC, 5); - } else if (source.getReferenceWorld().random.nextInt(30) == 0) { + } else if (source.asWorld().random.nextInt(30) == 0) { source.spawnParticles(UParticles.CHANGELING_MAGIC, 2); } } diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/PlaceableSpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/PlaceableSpell.java index efe47a8e..5b94fac7 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/PlaceableSpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/PlaceableSpell.java @@ -79,7 +79,7 @@ public class PlaceableSpell extends AbstractDelegatingSpell implements OrientedS if (!source.isClient()) { if (dimension == null) { - dimension = source.getReferenceWorld().getRegistryKey(); + dimension = source.asWorld().getRegistryKey(); setDirty(); } @@ -93,7 +93,7 @@ public class PlaceableSpell extends AbstractDelegatingSpell implements OrientedS } if (situation == Situation.GROUND_ENTITY) { - if (!source.isClient() && Ether.get(source.getReferenceWorld()).getEntry(getType(), source).isEmpty()) { + if (!source.isClient() && Ether.get(source.asWorld()).getEntry(getType(), source).isEmpty()) { setDead(); return false; } @@ -119,9 +119,9 @@ public class PlaceableSpell extends AbstractDelegatingSpell implements OrientedS } private void spawnPlacedEntity(Caster source) { - CastSpellEntity entity = UEntities.CAST_SPELL.create(source.getReferenceWorld()); + CastSpellEntity entity = UEntities.CAST_SPELL.create(source.asWorld()); Vec3d pos = castEntity.getPosition().orElse(source.getOriginVector()); - entity.updatePositionAndAngles(pos.x, pos.y, pos.z, source.getEntity().getYaw(), source.getEntity().getPitch()); + entity.updatePositionAndAngles(pos.x, pos.y, pos.z, source.asEntity().getYaw(), source.asEntity().getPitch()); PlaceableSpell copy = spell.toPlaceable(); if (spell instanceof PlacementDelegate delegate) { delegate.onPlaced(source, copy, entity); @@ -157,8 +157,8 @@ public class PlaceableSpell extends AbstractDelegatingSpell implements OrientedS castEntity.set(null); }); - if (source.getEntity() instanceof CastSpellEntity spellcast) { - Ether.get(source.getReferenceWorld()).remove(getType(), source); + if (source.asEntity() instanceof CastSpellEntity spellcast) { + Ether.get(source.asWorld()).remove(getType(), source); } } super.onDestroyed(source); @@ -180,7 +180,7 @@ public class PlaceableSpell extends AbstractDelegatingSpell implements OrientedS protected Optional getWorld(Caster source) { return Optional.ofNullable(dimension) - .map(dim -> source.getReferenceWorld().getServer().getWorld(dim)); + .map(dim -> source.asWorld().getServer().getWorld(dim)); } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/RainboomAbilitySpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/RainboomAbilitySpell.java index 7a9a878e..f4b6ce0f 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/RainboomAbilitySpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/RainboomAbilitySpell.java @@ -65,25 +65,25 @@ public class RainboomAbilitySpell extends AbstractSpell { e.damage(MagicalDamageSource.create("rainboom", source).setBreakSunglasses(), 6); }); EFFECT_RANGE.translate(source.getOrigin()).getBlockPositions().forEach(pos -> { - BlockState state = source.getReferenceWorld().getBlockState(pos); + BlockState state = source.asWorld().getBlockState(pos); if (state.isIn(UTags.FRAGILE) && source.canModifyAt(pos, ModificationType.PHYSICAL)) { owner.world.breakBlock(pos, true); } }); - Vec3d motion = source.getEntity().getRotationVec(1).multiply(1.5); - Vec3d velocity = source.getEntity().getVelocity().add(motion); + Vec3d motion = source.asEntity().getRotationVec(1).multiply(1.5); + Vec3d velocity = source.asEntity().getVelocity().add(motion); while (velocity.length() > 3) { velocity = velocity.multiply(0.6); } - source.getEntity().setVelocity(velocity); + source.asEntity().setVelocity(velocity); if (source instanceof Pony pony) { pony.getMagicalReserves().getExhaustion().multiply(0.2F); } - return !source.getEntity().isRemoved() && age++ < 90 + 7 * source.getLevel().getScaled(9); + return !source.asEntity().isRemoved() && age++ < 90 + 7 * source.getLevel().getScaled(9); } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/ThrowableSpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/ThrowableSpell.java index ec0eb75c..b891c994 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/ThrowableSpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/ThrowableSpell.java @@ -49,7 +49,7 @@ public final class ThrowableSpell extends AbstractDelegatingSpell { * Returns the resulting projectile entity for customization (or null if on the client). */ public Optional throwProjectile(Caster caster, float divergance) { - World world = caster.getReferenceWorld(); + World world = caster.asWorld(); LivingEntity entity = caster.getMaster(); 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 b6a5a8c2..16ebfaee 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 @@ -38,14 +38,14 @@ public class AreaProtectionSpell extends AbstractAreaEffectSpell { Vec3d origin = source.getOriginVector(); source.spawnParticles(origin, new Sphere(true, radius), (int)(radius * 6), pos -> { - if (!source.getReferenceWorld().isAir(new BlockPos(pos))) { + if (!source.asWorld().isAir(new BlockPos(pos))) { source.addParticle(new MagicParticleEffect(getType().getColor()), pos, Vec3d.ZERO); } }); } source.findAllSpellsInRange(radius, e -> isValidTarget(source, e)).filter(caster -> !caster.hasCommonOwner(source)).forEach(caster -> { - caster.getEntity().kill(); + caster.asEntity().kill(); }); return !isDead(); @@ -65,7 +65,7 @@ public class AreaProtectionSpell extends AbstractAreaEffectSpell { } public boolean blocksMagicFor(Caster source, Caster other, Vec3d position) { - return !FriendshipBraceletItem.isComrade(other, other.getEntity()) + return !FriendshipBraceletItem.isComrade(other, other.asEntity()) && source.getOriginVector().distanceTo(position) <= getDrawDropOffRange(source); } diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/AttractiveSpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/AttractiveSpell.java index bdc9de01..c84dcb65 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/AttractiveSpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/AttractiveSpell.java @@ -47,8 +47,8 @@ public class AttractiveSpell extends ShieldSpell implements HomingSpell, TimedSp setDirty(); Vec3d pos = caster.getOriginVector(); - if (target.isPresent(caster.getReferenceWorld()) && target.get(caster.getReferenceWorld()).distanceTo(caster.getEntity()) > getDrawDropOffRange(caster)) { - target.get(caster.getReferenceWorld()).requestTeleport(pos.x, pos.y, pos.z); + if (target.isPresent(caster.asWorld()) && target.get(caster.asWorld()).distanceTo(caster.asEntity()) > getDrawDropOffRange(caster)) { + target.get(caster.asWorld()).requestTeleport(pos.x, pos.y, pos.z); } return super.tick(caster, situation); @@ -60,7 +60,7 @@ public class AttractiveSpell extends ShieldSpell implements HomingSpell, TimedSp source.spawnParticles(getOrigin(source), new Sphere(false, range), 7, p -> { source.addParticle( - new FollowingParticleEffect(UParticles.HEALTH_DRAIN, source.getEntity(), 0.4F) + new FollowingParticleEffect(UParticles.HEALTH_DRAIN, source.asEntity(), 0.4F) .withChild(new MagicParticleEffect(getType().getColor())), p, Vec3d.ZERO @@ -92,8 +92,8 @@ public class AttractiveSpell extends ShieldSpell implements HomingSpell, TimedSp force *= AttractionUtils.getForceAdjustment(target); } - if (!isGood && source.getReferenceWorld().random.nextInt(4500) == 0) { - source.getEntity().damage(MagicalDamageSource.create("vortex"), 4); + if (!isGood && source.asWorld().random.nextInt(4500) == 0) { + source.asEntity().damage(MagicalDamageSource.create("vortex"), 4); } AttractionUtils.applyForce(getOrigin(source), target, -force, 0, false); @@ -138,7 +138,7 @@ public class AttractiveSpell extends ShieldSpell implements HomingSpell, TimedSp @Override public void onDestroyed(Caster caster) { - target.getOrEmpty(caster.getReferenceWorld()).ifPresent(target -> target.setGlowing(false)); + target.getOrEmpty(caster.asWorld()).ifPresent(target -> target.setGlowing(false)); } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/AwkwardSpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/AwkwardSpell.java index 884980dd..964fe1d4 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/AwkwardSpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/AwkwardSpell.java @@ -49,7 +49,7 @@ public class AwkwardSpell extends AbstractSpell implements TimedSpell { List names = new ArrayList<>(Registries.PARTICLE_TYPE.getIds()); - int index = (int)MathHelper.nextDouble(source.getReferenceWorld().random, 0, names.size()); + int index = (int)MathHelper.nextDouble(source.asWorld().random, 0, names.size()); Identifier id = names.get(index); ParticleType type = Registries.PARTICLE_TYPE.get(id); diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/CatapultSpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/CatapultSpell.java index 8def7d01..d964cf44 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/CatapultSpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/CatapultSpell.java @@ -65,14 +65,14 @@ public class CatapultSpell extends AbstractSpell implements ProjectileDelegate.B } protected void apply(Caster caster, Entity e) { - Vec3d vel = caster.getEntity().getVelocity(); + Vec3d vel = caster.asEntity().getVelocity(); if (Math.abs(e.getVelocity().y) > 0.5) { - e.setVelocity(caster.getEntity().getVelocity()); + e.setVelocity(caster.asEntity().getVelocity()); } else { e.addVelocity( - ((caster.getReferenceWorld().random.nextFloat() * HORIZONTAL_VARIANCE) - HORIZONTAL_VARIANCE + vel.x * 0.8F) * 0.1F, + ((caster.asWorld().random.nextFloat() * HORIZONTAL_VARIANCE) - HORIZONTAL_VARIANCE + vel.x * 0.8F) * 0.1F, 0.1F + (getTraits().get(Trait.STRENGTH, -MAX_STRENGTH, MAX_STRENGTH) - 40) / 16D, - ((caster.getReferenceWorld().random.nextFloat() * HORIZONTAL_VARIANCE) - HORIZONTAL_VARIANCE + vel.z * 0.8F) * 0.1F + ((caster.asWorld().random.nextFloat() * HORIZONTAL_VARIANCE) - HORIZONTAL_VARIANCE + vel.z * 0.8F) * 0.1F ); } } @@ -84,11 +84,11 @@ public class CatapultSpell extends AbstractSpell implements ProjectileDelegate.B double maxDistance = 2 + (getTraits().get(Trait.FOCUS) - 50) * 8; - Trace trace = Trace.create(caster.getEntity(), maxDistance, 1, EntityPredicates.EXCEPT_SPECTATOR); + Trace trace = Trace.create(caster.asEntity(), maxDistance, 1, EntityPredicates.EXCEPT_SPECTATOR); trace.getEntity().ifPresentOrElse(apply, () -> { trace.ifBlock(pos -> { if (caster.canModifyAt(pos)) { - createBlockEntity(caster.getReferenceWorld(), pos, apply); + createBlockEntity(caster.asWorld(), pos, apply); } }); }); diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/DarkVortexSpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/DarkVortexSpell.java index ba46a4bd..9f2cbaf2 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/DarkVortexSpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/DarkVortexSpell.java @@ -86,13 +86,13 @@ public class DarkVortexSpell extends AttractiveSpell implements ProjectileDelega setDirty(); if (age % 20 == 0) { - source.getReferenceWorld().playSound(null, source.getOrigin(), USounds.AMBIENT_DARK_VORTEX_ADDITIONS, SoundCategory.AMBIENT, 1, 1); + source.asWorld().playSound(null, source.getOrigin(), USounds.AMBIENT_DARK_VORTEX_ADDITIONS, SoundCategory.AMBIENT, 1, 1); } source.subtractEnergyCost(-accumulatedMass); - if (!source.isClient() && source.getReferenceWorld().random.nextInt(300) == 0) { - ParticleUtils.spawnParticle(source.getReferenceWorld(), UParticles.LIGHTNING_BOLT, getOrigin(source), Vec3d.ZERO); + if (!source.isClient() && source.asWorld().random.nextInt(300) == 0) { + ParticleUtils.spawnParticle(source.asWorld(), UParticles.LIGHTNING_BOLT, getOrigin(source), Vec3d.ZERO); } return super.tick(source, situation); @@ -161,9 +161,9 @@ public class DarkVortexSpell extends AttractiveSpell implements ProjectileDelega return; } if (source.getOrigin().isWithinDistance(i, getEventHorizonRadius() / 2)) { - source.getReferenceWorld().breakBlock(i, false); + source.asWorld().breakBlock(i, false); } else { - CatapultSpell.createBlockEntity(source.getReferenceWorld(), i, e -> { + CatapultSpell.createBlockEntity(source.asWorld(), i, e -> { applyRadialEffect(source, e, e.getPos().distanceTo(origin), radius); }); } @@ -177,8 +177,8 @@ public class DarkVortexSpell extends AttractiveSpell implements ProjectileDelega protected boolean canAffect(Caster source, BlockPos pos) { return source.canModifyAt(pos) - && source.getReferenceWorld().getFluidState(pos).isEmpty() - && source.getReferenceWorld().getBlockState(pos).getHardness(source.getReferenceWorld(), pos) >= 0; + && source.asWorld().getFluidState(pos).isEmpty() + && source.asWorld().getBlockState(pos).getHardness(source.asWorld(), pos) >= 0; } // 1. force decreases with distance: distance scale 1 -> 0 @@ -234,7 +234,7 @@ public class DarkVortexSpell extends AttractiveSpell implements ProjectileDelega } source.subtractEnergyCost(-massOfTarget * 10); - source.getReferenceWorld().playSound(null, source.getOrigin(), USounds.AMBIENT_DARK_VORTEX_MOOD, SoundCategory.AMBIENT, 2, 0.02F); + source.asWorld().playSound(null, source.getOrigin(), USounds.AMBIENT_DARK_VORTEX_MOOD, SoundCategory.AMBIENT, 2, 0.02F); } else { double force = getAttractiveForce(source, target); diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/DisplacementSpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/DisplacementSpell.java index 8713214e..36e3c29e 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/DisplacementSpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/DisplacementSpell.java @@ -39,7 +39,7 @@ public class DisplacementSpell extends AbstractSpell implements HomingSpell, Pla } if (ticks == 0) { - target.ifPresent(source.getReferenceWorld(), target -> { + target.ifPresent(source.asWorld(), target -> { Vec3d destinationPos = target.getPos(); Vec3d destinationVel = target.getVelocity(); @@ -95,7 +95,7 @@ public class DisplacementSpell extends AbstractSpell implements HomingSpell, Pla @Override public void onDestroyed(Caster caster) { caster.getMaster().setGlowing(false); - target.ifPresent(caster.getReferenceWorld(), e -> e.setGlowing(false)); + target.ifPresent(caster.asWorld(), e -> e.setGlowing(false)); } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/FeatherFallSpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/FeatherFallSpell.java index 72b4dac4..40fd8413 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/FeatherFallSpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/FeatherFallSpell.java @@ -67,8 +67,8 @@ public class FeatherFallSpell extends AbstractSpell implements TimedSpell { final float strength = 1F / (getTraits().get(Trait.STRENGTH, 2, 9) / targets.size()); final float generosity = getTraits().get(Trait.GENEROSITY, 1, MAX_GENEROSITY_FACTOR) / MAX_GENEROSITY_FACTOR; - Entity entity = caster.getEntity(); - Vec3d masterVelocity = caster.getEntity().getVelocity().multiply(0.1); + Entity entity = caster.asEntity(); + Vec3d masterVelocity = entity.getVelocity().multiply(0.1); targets.forEach(target -> { if (target.getVelocity().y < 0) { @@ -84,7 +84,7 @@ public class FeatherFallSpell extends AbstractSpell implements TimedSpell { ((PlayerEntity)target).getAbilities().flying = false; } target.setVelocity(target.getVelocity().multiply(1, delta, 1)); - if (situation == Situation.PROJECTILE && target != caster.getEntity()) { + if (situation == Situation.PROJECTILE && target != entity) { target.addVelocity(masterVelocity.x, 0, masterVelocity.z); } } @@ -114,8 +114,7 @@ public class FeatherFallSpell extends AbstractSpell implements TimedSpell { } protected Stream getTargets(Caster caster) { - Entity owner = caster.getEntity();// , EquinePredicates.IS_PLAYER - return Stream.concat(Stream.of(owner), caster.findAllEntitiesInRange(getEffectRange()).sorted((a, b) -> { + return Stream.concat(Stream.of(caster.asEntity()), caster.findAllEntitiesInRange(getEffectRange()).sorted((a, b) -> { return Integer.compare( FriendshipBraceletItem.isComrade(caster, a) ? 1 : 0, FriendshipBraceletItem.isComrade(caster, b) ? 1 : 0 diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/FireBoltSpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/FireBoltSpell.java index e57d31c7..8a5ea3cd 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/FireBoltSpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/FireBoltSpell.java @@ -57,7 +57,7 @@ public class FireBoltSpell extends AbstractSpell implements HomingSpell, return true; } - if (getTraits().get(Trait.FOCUS) >= 50 && !target.isPresent(caster.getReferenceWorld())) { + if (getTraits().get(Trait.FOCUS) >= 50 && !target.isPresent(caster.asWorld())) { target.set(caster.findAllEntitiesInRange( getTraits().get(Trait.FOCUS) - 49, EntityPredicates.VALID_LIVING_ENTITY.and(TargetSelecter.notOwnerOrFriend(this, caster)) @@ -66,10 +66,10 @@ public class FireBoltSpell extends AbstractSpell implements HomingSpell, for (int i = 0; i < getNumberOfBalls(caster); i++) { getTypeAndTraits().create().toThrowable().throwProjectile(caster, 2).ifPresent(c -> { - target.ifPresent(caster.getReferenceWorld(), c::setHomingTarget); + target.ifPresent(caster.asWorld(), c::setHomingTarget); }); - caster.playSound(USounds.SPELL_FIRE_BOLT_SHOOT, 0.7F, 0.4F / (caster.getReferenceWorld().random.nextFloat() * 0.4F + 0.8F)); + caster.playSound(USounds.SPELL_FIRE_BOLT_SHOOT, 0.7F, 0.4F / (caster.asWorld().random.nextFloat() * 0.4F + 0.8F)); } return false; } @@ -83,7 +83,7 @@ public class FireBoltSpell extends AbstractSpell implements HomingSpell, } protected int getNumberOfBalls(Caster caster) { - return 1 + caster.getReferenceWorld().random.nextInt(3) + (int)getTraits().get(Trait.EARTH) * 3; + return 1 + caster.asWorld().random.nextInt(3) + (int)getTraits().get(Trait.EARTH) * 3; } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/FireSpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/FireSpell.java index 3dbeb0c1..21c352c0 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/FireSpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/FireSpell.java @@ -52,7 +52,7 @@ public class FireSpell extends AbstractAreaEffectSpell implements ProjectileDele public void onImpact(MagicProjectileEntity projectile, BlockHitResult hit) { if (!projectile.isClient()) { Vec3d pos = hit.getPos(); - projectile.getReferenceWorld().createExplosion(projectile.getOwner(), pos.getX(), pos.getY(), pos.getZ(), 2, ExplosionSourceType.MOB); + projectile.asWorld().createExplosion(projectile.getOwner(), pos.getX(), pos.getY(), pos.getZ(), 2, ExplosionSourceType.MOB); } } @@ -60,7 +60,7 @@ public class FireSpell extends AbstractAreaEffectSpell implements ProjectileDele public void onImpact(MagicProjectileEntity projectile, EntityHitResult hit) { if (!projectile.isClient()) { Entity entity = hit.getEntity(); - projectile.getReferenceWorld().createExplosion(projectile.getOwner(), entity.getX(), entity.getY(), entity.getZ(), 2, ExplosionSourceType.MOB); + projectile.asWorld().createExplosion(projectile.getOwner(), entity.getX(), entity.getY(), entity.getZ(), 2, ExplosionSourceType.MOB); } } @@ -71,9 +71,9 @@ public class FireSpell extends AbstractAreaEffectSpell implements ProjectileDele } return new Sphere(false, Math.max(0, 4 + getTraits().get(Trait.POWER))).translate(source.getOrigin()).getBlockPositions().reduce(false, - (r, i) -> source.canModifyAt(i) && applyBlocks(source.getReferenceWorld(), i), + (r, i) -> source.canModifyAt(i) && applyBlocks(source.asWorld(), i), (a, b) -> a || b) - || applyEntities(null, source.getReferenceWorld(), source.getOriginVector()); + || applyEntities(null, source.asWorld(), source.getOriginVector()); } protected void generateParticles(Caster source) { diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/HydrophobicSpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/HydrophobicSpell.java index 2d7891f5..f9f74437 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/HydrophobicSpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/HydrophobicSpell.java @@ -50,7 +50,7 @@ public class HydrophobicSpell extends AbstractSpell { public boolean tick(Caster source, Situation situation) { if (!source.isClient()) { - World world = source.getReferenceWorld(); + World world = source.asWorld(); Shape area = new Sphere(false, getRange(source)).translate(source.getOriginVector()); @@ -83,12 +83,12 @@ public class HydrophobicSpell extends AbstractSpell { source.subtractEnergyCost(storedFluidPositions.isEmpty() ? 0.001F : 0.02F); source.spawnParticles(new Sphere(true, getRange(source)), 10, pos -> { BlockPos bp = new BlockPos(pos); - if (source.getReferenceWorld().getFluidState(bp.up()).isIn(affectedFluid)) { + if (source.asWorld().getFluidState(bp.up()).isIn(affectedFluid)) { source.addParticle(UParticles.RAIN_DROPS, pos, Vec3d.ZERO); } }); - if (source.getEntity().age % 200 == 0) { + if (source.asEntity().age % 200 == 0) { source.playSound(USounds.SPELL_AMBIENT, 0.5F); } } @@ -99,7 +99,7 @@ public class HydrophobicSpell extends AbstractSpell { @Override public void onDestroyed(Caster caster) { storedFluidPositions.removeIf(entry -> { - entry.restore(caster.getReferenceWorld()); + entry.restore(caster.asWorld()); return true; }); } diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/IceSpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/IceSpell.java index 09bad564..c08f4dcc 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/IceSpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/IceSpell.java @@ -40,24 +40,24 @@ public class IceSpell extends AbstractSpell { @Override public boolean tick(Caster source, Situation situation) { - boolean submerged = source.getEntity().isSubmergedInWater() || source.getEntity().isSubmergedIn(FluidTags.LAVA); + boolean submerged = source.asEntity().isSubmergedInWater() || source.asEntity().isSubmergedIn(FluidTags.LAVA); long blocksAffected = OUTER_RANGE.translate(source.getOrigin()).getBlockPositions().filter(i -> { - if (source.canModifyAt(i) && applyBlockSingle(source.getEntity(), source.getReferenceWorld(), i, situation)) { + if (source.canModifyAt(i) && applyBlockSingle(source.asEntity(), source.asWorld(), i, situation)) { if (submerged & source.getOrigin().isWithinDistance(i, RADIUS - 1)) { - BlockState state = source.getReferenceWorld().getBlockState(i); + BlockState state = source.asWorld().getBlockState(i); if (state.isIn(BlockTags.ICE) || state.isOf(Blocks.OBSIDIAN)) { - source.getReferenceWorld().setBlockState(i, Blocks.AIR.getDefaultState(), Block.NOTIFY_NEIGHBORS); + source.asWorld().setBlockState(i, Blocks.AIR.getDefaultState(), Block.NOTIFY_NEIGHBORS); } else if (!state.getFluidState().isEmpty()) { - source.getReferenceWorld().setBlockState(i, state.with(Properties.WATERLOGGED, false), Block.NOTIFY_NEIGHBORS); + source.asWorld().setBlockState(i, state.with(Properties.WATERLOGGED, false), Block.NOTIFY_NEIGHBORS); } } - ParticleUtils.spawnParticle(source.getReferenceWorld(), ParticleTypes.SPLASH, new Vec3d( - i.getX() + source.getReferenceWorld().random.nextFloat(), + ParticleUtils.spawnParticle(source.asWorld(), ParticleTypes.SPLASH, new Vec3d( + i.getX() + source.asWorld().random.nextFloat(), i.getY() + 1, - i.getZ() + source.getReferenceWorld().random.nextFloat()), Vec3d.ZERO); + i.getZ() + source.asWorld().random.nextFloat()), Vec3d.ZERO); return true; } @@ -67,7 +67,7 @@ public class IceSpell extends AbstractSpell { source.subtractEnergyCost(Math.min(10, blocksAffected)); - return applyEntities(source.getMaster(), source.getReferenceWorld(), source.getOriginVector()) && situation == Situation.PROJECTILE; + return applyEntities(source.getMaster(), source.asWorld(), source.getOriginVector()) && situation == Situation.PROJECTILE; } protected boolean applyEntities(LivingEntity owner, World world, Vec3d pos) { diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/InfernoSpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/InfernoSpell.java index 41c24c57..bb7ae5d2 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/InfernoSpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/InfernoSpell.java @@ -30,7 +30,7 @@ public class InfernoSpell extends FireSpell { generateParticles(source); } - World w = source.getReferenceWorld(); + World w = source.asWorld(); if (!w.isClient) { float radius = 4 + (source.getLevel().getScaled(4) * 4); diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/LightSpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/LightSpell.java index 641891bf..a2a36430 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/LightSpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/LightSpell.java @@ -56,17 +56,17 @@ public class LightSpell extends AbstractSpell implements TimedSpell { if (!caster.isClient()) { if (lights.isEmpty()) { - int size = 2 + caster.getReferenceWorld().random.nextInt(2) + (int)(getTraits().get(Trait.LIFE, 10, 20) - 10)/10; + int size = 2 + caster.asWorld().random.nextInt(2) + (int)(getTraits().get(Trait.LIFE, 10, 20) - 10)/10; while (lights.size() < size) { lights.add(new EntityReference()); } } lights.forEach(ref -> { - if (!ref.isPresent(caster.getReferenceWorld())) { - FairyEntity entity = UEntities.TWITTERMITE.create(caster.getReferenceWorld()); + if (!ref.isPresent(caster.asWorld())) { + FairyEntity entity = UEntities.TWITTERMITE.create(caster.asWorld()); entity.setPosition(ref.getPosition().orElseGet(() -> { - return caster.getOriginVector().add(VecHelper.supply(() -> caster.getReferenceWorld().random.nextInt(3) - 1)); + return caster.getOriginVector().add(VecHelper.supply(() -> caster.asWorld().random.nextInt(3) - 1)); })); entity.setMaster(caster); entity.world.spawnEntity(entity); @@ -86,7 +86,7 @@ public class LightSpell extends AbstractSpell implements TimedSpell { return; } lights.forEach(ref -> { - ref.ifPresent(caster.getReferenceWorld(), e -> { + ref.ifPresent(caster.asWorld(), e -> { e.world.sendEntityStatus(e, (byte)60); e.discard(); }); diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/MindSwapSpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/MindSwapSpell.java index 073db3b9..afdafbb5 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/MindSwapSpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/MindSwapSpell.java @@ -33,7 +33,7 @@ public class MindSwapSpell extends MimicSpell { public void onDestroyed(Caster caster) { super.onDestroyed(caster); if (initialized && !caster.isClient()) { - counterpart.ifPresent(caster.getReferenceWorld(), e -> { + counterpart.ifPresent(caster.asWorld(), e -> { EntitySwap.ALL.accept(e, caster.getMaster()); Inventory.swapInventories( e, myStoredInventory.or(() -> Inventory.of(e)), @@ -59,7 +59,7 @@ public class MindSwapSpell extends MimicSpell { if (!initialized) { initialized = true; setDirty(); - counterpart.ifPresent(caster.getReferenceWorld(), e -> { + counterpart.ifPresent(caster.asWorld(), e -> { setDisguise(e); Caster other = Caster.of(e).get(); SpellType.MIMIC.withTraits().apply(other).setDisguise(caster.getMaster()); @@ -77,14 +77,14 @@ public class MindSwapSpell extends MimicSpell { }); } - if (counterpart.getId().isPresent() && counterpart.get(caster.getReferenceWorld()) == null) { + if (counterpart.getId().isPresent() && counterpart.get(caster.asWorld()) == null) { caster.getMaster().damage(DamageSource.MAGIC, Float.MAX_VALUE); setDead(); return false; } - if (!caster.getEntity().isAlive()) { - counterpart.ifPresent(caster.getReferenceWorld(), e -> { + if (!caster.asEntity().isAlive()) { + counterpart.ifPresent(caster.asWorld(), e -> { e.damage(DamageSource.MAGIC, Float.MAX_VALUE); }); onDestroyed(caster); diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/NecromancySpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/NecromancySpell.java index 9036ac0a..e69f960e 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/NecromancySpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/NecromancySpell.java @@ -56,24 +56,24 @@ public class NecromancySpell extends AbstractAreaEffectSpell { return false; } - boolean rainy = source.getReferenceWorld().hasRain(source.getOrigin()); + boolean rainy = source.asWorld().hasRain(source.getOrigin()); if (source.isClient()) { source.spawnParticles(new Sphere(true, radius * 2), rainy ? 98 : 125, pos -> { BlockPos bpos = new BlockPos(pos); - if (!source.getReferenceWorld().isAir(bpos.down())) { - source.addParticle(source.getReferenceWorld().hasRain(bpos) ? ParticleTypes.SMOKE : ParticleTypes.FLAME, pos, Vec3d.ZERO); + if (!source.asWorld().isAir(bpos.down())) { + source.addParticle(source.asWorld().hasRain(bpos) ? ParticleTypes.SMOKE : ParticleTypes.FLAME, pos, Vec3d.ZERO); } }); return true; } - if (source.getReferenceWorld().getDifficulty() == Difficulty.PEACEFUL) { + if (source.asWorld().getDifficulty() == Difficulty.PEACEFUL) { return true; } - summonedEntities.removeIf(ref -> ref.getOrEmpty(source.getReferenceWorld()).filter(e -> { + summonedEntities.removeIf(ref -> ref.getOrEmpty(source.asWorld()).filter(e -> { if (e.getPos().distanceTo(source.getOriginVector()) > radius * 2) { e.world.sendEntityStatus(e, (byte)60); e.discard(); @@ -82,13 +82,13 @@ public class NecromancySpell extends AbstractAreaEffectSpell { return true; }).isEmpty()); - float additional = source.getReferenceWorld().getLocalDifficulty(source.getOrigin()).getLocalDifficulty() + getTraits().get(Trait.CHAOS, 0, 10); + float additional = source.asWorld().getLocalDifficulty(source.getOrigin()).getLocalDifficulty() + getTraits().get(Trait.CHAOS, 0, 10); setDirty(); if (--spawnCountdown > 0 && !summonedEntities.isEmpty()) { return true; } - spawnCountdown = 1200 + source.getReferenceWorld().random.nextInt(rainy ? 2000 : 1000); + spawnCountdown = 1200 + source.asWorld().random.nextInt(rainy ? 2000 : 1000); if (summonedEntities.size() > 10 + additional) { return true; @@ -97,11 +97,11 @@ public class NecromancySpell extends AbstractAreaEffectSpell { Shape affectRegion = new Sphere(false, radius); for (int i = 0; i < 10; i++) { - Vec3d pos = affectRegion.computePoint(source.getReferenceWorld().random).add(source.getOriginVector()); + Vec3d pos = affectRegion.computePoint(source.asWorld().random).add(source.getOriginVector()); BlockPos loc = new BlockPos(pos); - if (source.getReferenceWorld().isAir(loc.up()) && !source.getReferenceWorld().isAir(loc)) { + if (source.asWorld().isAir(loc.up()) && !source.asWorld().isAir(loc)) { spawnPool.get().ifPresent(type -> { spawnMonster(source, pos, type); }); @@ -118,7 +118,7 @@ public class NecromancySpell extends AbstractAreaEffectSpell { } LivingEntity master = caster.getMaster(); summonedEntities.forEach(ref -> { - ref.ifPresent(caster.getReferenceWorld(), e -> { + ref.ifPresent(caster.asWorld(), e -> { if (master != null) { master.applyDamageEffects(master, e); } @@ -129,14 +129,14 @@ public class NecromancySpell extends AbstractAreaEffectSpell { } protected void spawnMonster(Caster source, Vec3d pos, EntityType type) { - LivingEntity minion = type.create(source.getReferenceWorld()); + LivingEntity minion = type.create(source.asWorld()); source.subtractEnergyCost(3); minion.updatePositionAndAngles(pos.x, pos.y, pos.z, 0, 0); minion.setVelocity(0, 0.3, 0); - source.getReferenceWorld().syncWorldEvent(WorldEvents.DRAGON_BREATH_CLOUD_SPAWNS, minion.getBlockPos(), 0); + source.asWorld().syncWorldEvent(WorldEvents.DRAGON_BREATH_CLOUD_SPAWNS, minion.getBlockPos(), 0); source.playSound(SoundEvents.BLOCK_BELL_USE, 1, 0.3F); source.spawnParticles(ParticleTypes.LARGE_SMOKE, 10); minion.equipStack(EquipmentSlot.HEAD, Items.IRON_HELMET.getDefaultStack()); @@ -145,7 +145,7 @@ public class NecromancySpell extends AbstractAreaEffectSpell { ((Creature)eq).setMaster(source); }); - source.getReferenceWorld().spawnEntity(minion); + source.asWorld().spawnEntity(minion); summonedEntities.add(new EntityReference<>(minion)); setDirty(); } diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/PortalSpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/PortalSpell.java index 68608771..4cca6f3e 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/PortalSpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/PortalSpell.java @@ -51,7 +51,7 @@ public class PortalSpell extends AbstractSpell implements PlaceableSpell.Placeme @Override public boolean apply(Caster caster) { - setOrientation(caster.getEntity().getPitch(), caster.getEntity().getYaw()); + setOrientation(caster.asEntity().getPitch(), caster.asEntity().getYaw()); return toPlaceable().apply(caster); } @@ -82,11 +82,11 @@ public class PortalSpell extends AbstractSpell implements PlaceableSpell.Placeme }); } else { teleportationTarget.getId().ifPresent(id -> { - if (Ether.get(source.getReferenceWorld()).getEntry(getType(), id).isEmpty()) { + if (Ether.get(source.asWorld()).getEntry(getType(), id).isEmpty()) { Unicopia.LOGGER.debug("Lost sibling, breaking connection to " + id); teleportationTarget.set(null); setDirty(); - source.getReferenceWorld().syncWorldEvent(WorldEvents.BLOCK_BROKEN, source.getOrigin(), Block.getRawIdFromState(Blocks.GLASS.getDefaultState())); + source.asWorld().syncWorldEvent(WorldEvents.BLOCK_BROKEN, source.getOrigin(), Block.getRawIdFromState(Blocks.GLASS.getDefaultState())); } }); @@ -98,7 +98,7 @@ public class PortalSpell extends AbstractSpell implements PlaceableSpell.Placeme if (!publishedPosition) { publishedPosition = true; - Ether.Entry entry = Ether.get(source.getReferenceWorld()).put(getType(), source); + Ether.Entry entry = Ether.get(source.asWorld()).put(getType(), source); entry.pitch = pitch; entry.yaw = yaw; } @@ -140,10 +140,10 @@ public class PortalSpell extends AbstractSpell implements PlaceableSpell.Placeme return; } - Ether ether = Ether.get(source.getReferenceWorld()); + Ether ether = Ether.get(source.asWorld()); ether.getEntries(getType()) .stream() - .filter(entry -> entry.isAvailable() && !entry.entity.referenceEquals(source.getEntity()) && entry.entity.getId().isPresent()) + .filter(entry -> entry.isAvailable() && !entry.entity.referenceEquals(source.asEntity()) && entry.entity.getId().isPresent()) .findAny() .ifPresent(entry -> { entry.setTaken(true); @@ -153,7 +153,7 @@ public class PortalSpell extends AbstractSpell implements PlaceableSpell.Placeme } private Optional getTarget(Caster source) { - return teleportationTarget.getId().flatMap(id -> Ether.get(source.getReferenceWorld()).getEntry(getType(), id)); + return teleportationTarget.getId().flatMap(id -> Ether.get(source.asWorld()).getEntry(getType(), id)); } @Override @@ -185,8 +185,8 @@ public class PortalSpell extends AbstractSpell implements PlaceableSpell.Placeme @Override public void onDestroyed(Caster caster) { - Ether ether = Ether.get(caster.getReferenceWorld()); - ether.remove(getType(), caster.getEntity().getUuid()); + Ether ether = Ether.get(caster.asWorld()); + ether.remove(getType(), caster.asEntity().getUuid()); getTarget(caster).ifPresent(e -> e.setTaken(false)); } diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/ScorchSpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/ScorchSpell.java index 8c21b334..59ec591b 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/ScorchSpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/ScorchSpell.java @@ -31,9 +31,9 @@ public class ScorchSpell extends FireSpell implements ProjectileDelegate.Configu @Override public boolean tick(Caster source, Situation situation) { - BlockPos pos = PosHelper.findSolidGroundAt(source.getReferenceWorld(), source.getOrigin(), source.getPhysics().getGravitySignum()); + BlockPos pos = PosHelper.findSolidGroundAt(source.asWorld(), source.getOrigin(), source.getPhysics().getGravitySignum()); - if (source.canModifyAt(pos) && StateMaps.FIRE_AFFECTED.convert(source.getReferenceWorld(), pos)) { + if (source.canModifyAt(pos) && StateMaps.FIRE_AFFECTED.convert(source.asWorld(), pos)) { source.spawnParticles(new Sphere(false, Math.max(1, getTraits().get(Trait.POWER))), 5, p -> { source.addParticle(ParticleTypes.SMOKE, PosHelper.offset(p, pos), Vec3d.ZERO); }); diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/SiphoningSpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/SiphoningSpell.java index efc3ada5..3d112c64 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/SiphoningSpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/SiphoningSpell.java @@ -55,7 +55,7 @@ public class SiphoningSpell extends AbstractAreaEffectSpell { int direction = isFriendlyTogether(source) ? 1 : -1; source.spawnParticles(new Sphere(true, radius, 1, 0, 1), 1, pos -> { - if (!source.getReferenceWorld().isAir(new BlockPos(pos).down())) { + if (!source.asWorld().isAir(new BlockPos(pos).down())) { double dist = pos.distanceTo(source.getOriginVector()); Vec3d velocity = pos.subtract(source.getOriginVector()).normalize().multiply(direction * dist); @@ -64,7 +64,7 @@ public class SiphoningSpell extends AbstractAreaEffectSpell { } }); } else { - if (source.getReferenceWorld().getTime() % 10 != 0) { + if (source.asWorld().getTime() % 10 != 0) { return true; } @@ -78,7 +78,7 @@ public class SiphoningSpell extends AbstractAreaEffectSpell { } private Stream getTargets(Caster source) { - return VecHelper.findInRange(null, source.getReferenceWorld(), source.getOriginVector(), 4 + source.getLevel().getScaled(6), EntityPredicates.EXCEPT_CREATIVE_OR_SPECTATOR.and(e -> e instanceof LivingEntity)) + return VecHelper.findInRange(null, source.asWorld(), source.getOriginVector(), 4 + source.getLevel().getScaled(6), EntityPredicates.EXCEPT_CREATIVE_OR_SPECTATOR.and(e -> e instanceof LivingEntity)) .stream() .map(e -> (LivingEntity)e); } @@ -92,7 +92,7 @@ public class SiphoningSpell extends AbstractAreaEffectSpell { source.subtractEnergyCost(0.2F); if (ticksUpset > 0 || maxHealthGain <= 0) { - if (source.getReferenceWorld().random.nextInt(3000) == 0) { + if (source.asWorld().random.nextInt(3000) == 0) { setDead(); } else { e.damage(damage, e.getHealth() / 4); 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 ab67d3b6..19de23fd 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 @@ -75,7 +75,7 @@ public class TraitDiscovery implements NbtSerialisable { }); unreadTraits.addAll(newTraits); pony.setDirty(); - if (!newTraits.isEmpty() && !pony.getReferenceWorld().isClient) { + if (!newTraits.isEmpty() && !pony.asWorld().isClient) { Channel.UNLOCK_TRAITS.send((ServerPlayerEntity)pony.asEntity(), new MsgUnlockTraits(newTraits)); } } diff --git a/src/main/java/com/minelittlepony/unicopia/block/data/Ether.java b/src/main/java/com/minelittlepony/unicopia/block/data/Ether.java index 391c89e9..8df42fe1 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/data/Ether.java +++ b/src/main/java/com/minelittlepony/unicopia/block/data/Ether.java @@ -87,7 +87,7 @@ public class Ether extends PersistentState implements CasterView { } public void remove(SpellType spellType, Caster caster) { - remove(spellType, caster.getEntity().getUuid()); + remove(spellType, caster.asEntity().getUuid()); } public Set getEntries(SpellType spellType) { @@ -109,7 +109,7 @@ public class Ether extends PersistentState implements CasterView { public Optional getEntry(SpellType spellType, Caster caster) { synchronized (locker) { - return getEntries(spellType).stream().filter(e -> e.entity.referenceEquals(caster.getEntity())).findFirst(); + return getEntries(spellType).stream().filter(e -> e.entity.referenceEquals(caster.asEntity())).findFirst(); } } @@ -137,7 +137,7 @@ public class Ether extends PersistentState implements CasterView { } public Entry(Caster caster) { - entity = new EntityReference<>(caster.getEntity()); + entity = new EntityReference<>(caster.asEntity()); } boolean isAlive() { diff --git a/src/main/java/com/minelittlepony/unicopia/client/particle/RunesParticle.java b/src/main/java/com/minelittlepony/unicopia/client/particle/RunesParticle.java index b40679cf..eefe4950 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/particle/RunesParticle.java +++ b/src/main/java/com/minelittlepony/unicopia/client/particle/RunesParticle.java @@ -166,7 +166,7 @@ public class RunesParticle extends OrientedBillboardParticle implements Attachme public void tick() { super.tick(); - link.flatMap(Link::get).map(Caster::getEntity).ifPresentOrElse(e -> { + link.flatMap(Link::get).map(Caster::asEntity).ifPresentOrElse(e -> { if (getAlphaScale() >= 0.9F) { if (stasisAge < 0) { stasisAge = age; diff --git a/src/main/java/com/minelittlepony/unicopia/client/particle/SphereParticle.java b/src/main/java/com/minelittlepony/unicopia/client/particle/SphereParticle.java index 74c36019..44e026f5 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/particle/SphereParticle.java +++ b/src/main/java/com/minelittlepony/unicopia/client/particle/SphereParticle.java @@ -101,7 +101,7 @@ public class SphereParticle extends Particle implements Attachment { super.tick(); if (link.isPresent()) { - link.flatMap(Link::get).map(Caster::getEntity).ifPresentOrElse(e -> { + link.flatMap(Link::get).map(Caster::asEntity).ifPresentOrElse(e -> { Vec3d offset = parameters.getOffset(); setPos(e.getX() + offset.getX(), e.getY() + offset.getY(), e.getZ() + offset.getZ()); diff --git a/src/main/java/com/minelittlepony/unicopia/entity/CastSpellEntity.java b/src/main/java/com/minelittlepony/unicopia/entity/CastSpellEntity.java index d2f5df90..9416da08 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/CastSpellEntity.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/CastSpellEntity.java @@ -23,7 +23,7 @@ import net.minecraft.network.listener.ClientPlayPacketListener; import net.minecraft.text.Text; import net.minecraft.world.World; -public class CastSpellEntity extends LightEmittingEntity implements Caster, WeaklyOwned { +public class CastSpellEntity extends LightEmittingEntity implements Caster, WeaklyOwned { private static final TrackedData GRAVITY = DataTracker.registerData(CastSpellEntity.class, TrackedDataHandlerRegistry.FLOAT); private static final TrackedData EFFECT = DataTracker.registerData(CastSpellEntity.class, TrackedDataHandlerRegistry.NBT_COMPOUND); @@ -78,12 +78,7 @@ public class CastSpellEntity extends LightEmittingEntity implements Caster implements WeaklyOwned implements WeaklyOwned implements WeaklyOwned implements WeaklyOwned { if (!(living instanceof Pony)) { foundStacks.forEach(stack -> { if (getTicks((Trackable)stack.getItem()) == 1) { - stack.inventoryTick(living.getReferenceWorld(), living.asEntity(), 0, false); + stack.inventoryTick(living.asWorld(), living.asEntity(), 0, false); } }); } diff --git a/src/main/java/com/minelittlepony/unicopia/entity/Living.java b/src/main/java/com/minelittlepony/unicopia/entity/Living.java index b1e32795..46ff7071 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/Living.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/Living.java @@ -98,15 +98,6 @@ public abstract class Living implements Equine, Caste return armour; } - /** - * @deprecated use asEntity() - */ - @Deprecated(forRemoval = true) - @Override - public final Entity getEntity() { - return asEntity(); - } - @Override public final T asEntity() { return entity; diff --git a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/AxolotlBehaviour.java b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/AxolotlBehaviour.java index 8fb0b43f..c7bfe8ff 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/AxolotlBehaviour.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/AxolotlBehaviour.java @@ -2,20 +2,20 @@ package com.minelittlepony.unicopia.entity.behaviour; import org.joml.Vector3f; -import com.minelittlepony.unicopia.ability.magic.Caster; +import com.minelittlepony.unicopia.entity.Living; import net.minecraft.entity.passive.AxolotlEntity; public class AxolotlBehaviour extends EntityBehaviour { private static final float toRad = 0.017453292F; @Override - public void update(Caster source, AxolotlEntity entity, Disguise spell) { + public void update(Living source, AxolotlEntity entity, Disguise spell) { if (entity.getModelAngles().isEmpty()) { return; } Vector3f current = entity.getModelAngles().get("body"); entity.getModelAngles().put("body", new Vector3f( - source.getEntity().isSubmergedInWater() ? source.getEntity().getPitch() * toRad : 0, + source.asEntity().isSubmergedInWater() ? source.asEntity().getPitch() * toRad : 0, 0, current == null ? 0 : current.z )); diff --git a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/BeeBehaviour.java b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/BeeBehaviour.java index 77ba854f..1252fd52 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/BeeBehaviour.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/BeeBehaviour.java @@ -1,7 +1,7 @@ package com.minelittlepony.unicopia.entity.behaviour; import com.minelittlepony.unicopia.InteractionManager; -import com.minelittlepony.unicopia.ability.magic.Caster; +import com.minelittlepony.unicopia.entity.Living; import net.minecraft.entity.passive.BeeEntity; @@ -16,8 +16,8 @@ public class BeeBehaviour extends EntityBehaviour { } @Override - public void update(Caster source, BeeEntity entity, Disguise spell) { - if (source.getMaster().isSneaking()) { + public void update(Living source, BeeEntity entity, Disguise spell) { + if (source.asEntity().isSneaking()) { entity.setAngerTime(10); } else { entity.setAngerTime(0); 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 744e25fd..f7e81bef 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/BlazeBehaviour.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/BlazeBehaviour.java @@ -1,6 +1,6 @@ package com.minelittlepony.unicopia.entity.behaviour; -import com.minelittlepony.unicopia.ability.magic.Caster; +import com.minelittlepony.unicopia.entity.Living; import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.mixin.MixinBlazeEntity; @@ -14,10 +14,10 @@ import net.minecraft.world.WorldEvents; public class BlazeBehaviour extends EntityBehaviour { @Override - public void update(Caster source, BlazeEntity entity, Disguise spell) { + public void update(Living source, BlazeEntity entity, Disguise spell) { super.update(source, entity, spell); - Entity src = source.getEntity(); + Entity src = source.asEntity(); if (src.isOnGround() || src instanceof PlayerEntity player && player.getAbilities().flying) { return; 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 7bc885af..f31f2904 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/ChickenBehaviour.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/ChickenBehaviour.java @@ -1,6 +1,6 @@ package com.minelittlepony.unicopia.entity.behaviour; -import com.minelittlepony.unicopia.ability.magic.Caster; +import com.minelittlepony.unicopia.entity.Living; import com.minelittlepony.unicopia.entity.player.Pony; import net.minecraft.entity.Entity; @@ -20,7 +20,7 @@ public class ChickenBehaviour extends EntityBehaviour { } @Override - public void update(Caster source, ChickenEntity entity, Disguise spell) { + public void update(Living source, ChickenEntity entity, Disguise spell) { entity.eggLayTime = Integer.MAX_VALUE; if (source instanceof Pony player) { @@ -48,7 +48,7 @@ public class ChickenBehaviour extends EntityBehaviour { } } - Entity src = source.getEntity(); + Entity src = source.asEntity(); if (src.isOnGround() || src instanceof PlayerEntity player && player.getAbilities().flying) { return; diff --git a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/CreeperBehaviour.java b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/CreeperBehaviour.java index 5901b3bf..5767cb3c 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/CreeperBehaviour.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/CreeperBehaviour.java @@ -1,13 +1,13 @@ package com.minelittlepony.unicopia.entity.behaviour; -import com.minelittlepony.unicopia.ability.magic.Caster; +import com.minelittlepony.unicopia.entity.Living; import net.minecraft.entity.mob.CreeperEntity; import net.minecraft.util.math.MathHelper; public class CreeperBehaviour extends EntityBehaviour { @Override - public void update(Caster source, CreeperEntity entity, Disguise spell) { + public void update(Living source, CreeperEntity entity, Disguise spell) { int fuseCountDown = spell.getDisguise().getOrCreateTag().getInt("fuseCountdown"); boolean trigger = isSneakingOnGround(source); diff --git a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/Disguise.java b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/Disguise.java index 08f5e53c..987af210 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/Disguise.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/Disguise.java @@ -7,6 +7,7 @@ import org.jetbrains.annotations.Nullable; import com.minelittlepony.unicopia.FlightType; import com.minelittlepony.unicopia.Owned; import com.minelittlepony.unicopia.ability.magic.Caster; +import com.minelittlepony.unicopia.entity.Living; import com.minelittlepony.unicopia.entity.duck.LivingEntityDuck; import com.minelittlepony.unicopia.entity.player.PlayerDimensions; import com.minelittlepony.unicopia.entity.player.Pony; @@ -56,9 +57,14 @@ public interface Disguise extends FlightType.Provider, PlayerDimensions.Provider } @SuppressWarnings("unchecked") - default boolean update(Caster source, boolean tick) { + default boolean update(Caster caster, boolean tick) { - LivingEntity owner = source.getMaster(); + if (!(caster instanceof Living)) { + return false; + } + + Living source = (Living)caster; + LivingEntity owner = source.asEntity(); if (owner == null) { return true; diff --git a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/EndermanBehaviour.java b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/EndermanBehaviour.java index 2ba3157b..87314b92 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/EndermanBehaviour.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/EndermanBehaviour.java @@ -1,6 +1,6 @@ package com.minelittlepony.unicopia.entity.behaviour; -import com.minelittlepony.unicopia.ability.magic.Caster; +import com.minelittlepony.unicopia.entity.Living; import net.minecraft.entity.mob.EndermanEntity; import net.minecraft.item.BlockItem; @@ -9,8 +9,8 @@ import net.minecraft.util.Hand; public class EndermanBehaviour extends EntityBehaviour { @Override - public void update(Caster source, EndermanEntity entity, Disguise spell) { - if (source.getMaster().isSneaking() || source.getMaster().isSprinting()) { + public void update(Living source, EndermanEntity entity, Disguise spell) { + if (source.asEntity().isSneaking() || source.asEntity().isSprinting()) { entity.setTarget(entity); } else { entity.setTarget(null); diff --git a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/EntityAppearance.java b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/EntityAppearance.java index 0fd3de46..3ea7a29f 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/EntityAppearance.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/EntityAppearance.java @@ -133,7 +133,7 @@ public class EntityAppearance implements NbtSerialisable, PlayerDimensions.Provi private synchronized void createPlayer(NbtCompound nbt, GameProfile profile, Caster source) { remove(); - entity = InteractionManager.instance().createPlayer(source.getEntity(), profile); + entity = InteractionManager.instance().createPlayer(source.asEntity(), profile); entity.setCustomName(source.getMaster().getName()); ((PlayerEntity)entity).readNbt(nbt.getCompound("playerNbt")); if (nbt.contains("playerVisibleParts", NbtElement.BYTE_TYPE)) { @@ -164,7 +164,7 @@ public class EntityAppearance implements NbtSerialisable, PlayerDimensions.Provi ), p -> createPlayer(nbt, p, source)); } else { if (source.isClient()) { - entity = EntityType.fromNbt(nbt).map(type -> type.create(source.getReferenceWorld())).orElse(null); + entity = EntityType.fromNbt(nbt).map(type -> type.create(source.asWorld())).orElse(null); if (entity != null) { try { entity.readNbt(nbt); @@ -174,7 +174,7 @@ public class EntityAppearance implements NbtSerialisable, PlayerDimensions.Provi entity = EntityBehaviour.forEntity(entity).onCreate(entity, this, true); } } else { - entity = EntityType.loadEntityWithPassengers(nbt, source.getReferenceWorld(), e -> { + entity = EntityType.loadEntityWithPassengers(nbt, source.asWorld(), e -> { return EntityBehaviour.forEntity(e).onCreate(e, this, true); }); } @@ -191,7 +191,7 @@ public class EntityAppearance implements NbtSerialisable, PlayerDimensions.Provi } private void onEntityLoaded(Caster source) { - source.getEntity().calculateDimensions(); + source.asEntity().calculateDimensions(); if (entity == null) { return; @@ -202,7 +202,7 @@ public class EntityAppearance implements NbtSerialisable, PlayerDimensions.Provi } if (source.isClient()) { - source.getReferenceWorld().spawnEntity(entity); + source.asWorld().spawnEntity(entity); } } diff --git a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/EntityBehaviour.java b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/EntityBehaviour.java index 457eec1e..ca1ef0b9 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/EntityBehaviour.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/EntityBehaviour.java @@ -8,6 +8,7 @@ import org.jetbrains.annotations.Nullable; import com.minelittlepony.unicopia.Unicopia; import com.minelittlepony.unicopia.ability.magic.Caster; import com.minelittlepony.unicopia.entity.duck.LivingEntityDuck; +import com.minelittlepony.unicopia.entity.Living; import com.minelittlepony.unicopia.entity.duck.EntityDuck; import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.util.RegistryUtils; @@ -45,7 +46,7 @@ public class EntityBehaviour { *
* We use this to add entity-specific behaviours. */ - public void update(Caster source, T entity, Disguise spell) { + public void update(Living source, T entity, Disguise spell) { if (source instanceof Pony) { update((Pony)source, entity, spell); } @@ -249,7 +250,7 @@ public class EntityBehaviour { } protected boolean isSneakingOnGround(Caster source) { - Entity e = source.getEntity(); + Entity e = source.asEntity(); return e.isSneaking() && (e.isOnGround() && !(e instanceof PlayerEntity player && player.getAbilities().flying)); } diff --git a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/FallingBlockBehaviour.java b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/FallingBlockBehaviour.java index 6ec22c28..e70103b9 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/FallingBlockBehaviour.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/FallingBlockBehaviour.java @@ -4,6 +4,7 @@ import java.util.List; import java.util.Optional; import com.minelittlepony.unicopia.ability.magic.Caster; +import com.minelittlepony.unicopia.entity.Living; import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.mixin.MixinFallingBlock; import com.minelittlepony.unicopia.mixin.MixinFallingBlockEntity; @@ -41,8 +42,8 @@ public class FallingBlockBehaviour extends EntityBehaviour { @Override public void onImpact(Caster source, FallingBlockEntity entity, float distance, float damageMultiplier, DamageSource cause) { - if (source.getEntity().fallDistance > 3) { - entity.fallDistance = source.getEntity().fallDistance; + if (source.asEntity().fallDistance > 3) { + entity.fallDistance = source.asEntity().fallDistance; entity.handleFallDamage(distance, damageMultiplier, cause); BlockState state = entity.getBlockState(); @@ -85,7 +86,7 @@ public class FallingBlockBehaviour extends EntityBehaviour { } @Override - public void update(Caster source, FallingBlockEntity entity, Disguise spell) { + public void update(Living source, FallingBlockEntity entity, Disguise spell) { BlockState state = entity.getBlockState(); if (state.contains(Properties.WATERLOGGED)) { @@ -101,7 +102,7 @@ public class FallingBlockBehaviour extends EntityBehaviour { EntityAppearance disguise = spell.getDisguise(); List attachments = disguise.getAttachments(); if (attachments.size() > 0) { - copyBaseAttributes(source.getMaster(), attachments.get(0), UP); + copyBaseAttributes(source.asEntity(), attachments.get(0), UP); } BlockEntity be = disguise.getBlockEntity(); diff --git a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/MinecartBehaviour.java b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/MinecartBehaviour.java index 5d69f1ac..9a1366e0 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/MinecartBehaviour.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/MinecartBehaviour.java @@ -1,7 +1,7 @@ package com.minelittlepony.unicopia.entity.behaviour; import com.minelittlepony.unicopia.InteractionManager; -import com.minelittlepony.unicopia.ability.magic.Caster; +import com.minelittlepony.unicopia.entity.Living; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.vehicle.AbstractMinecartEntity; @@ -18,19 +18,18 @@ public class MinecartBehaviour extends EntityBehaviour { } @Override - public void update(Caster source, AbstractMinecartEntity entity, Disguise spell) { + public void update(Living source, AbstractMinecartEntity entity, Disguise spell) { entity.setYaw(entity.getYaw() - 90); entity.prevYaw -= 90; entity.setPitch(0); entity.prevPitch = 0; - if (source.getEntity() instanceof LivingEntity living) { - if (living.hurtTime > 0) { - entity.setDamageWobbleTicks(living.hurtTime); - entity.setDamageWobbleStrength(1); - entity.setDamageWobbleSide(20 + (int)source.getEntity().fallDistance / 10); - } + LivingEntity living = source.asEntity(); + if (living.hurtTime > 0) { + entity.setDamageWobbleTicks(living.hurtTime); + entity.setDamageWobbleStrength(1); + entity.setDamageWobbleSide(20 + (int)source.asEntity().fallDistance / 10); } } } 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 66628a94..612153bc 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/PlayerBehaviour.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/PlayerBehaviour.java @@ -1,6 +1,6 @@ package com.minelittlepony.unicopia.entity.behaviour; -import com.minelittlepony.unicopia.ability.magic.Caster; +import com.minelittlepony.unicopia.entity.Living; import com.minelittlepony.unicopia.entity.duck.*; import com.minelittlepony.unicopia.entity.player.Pony; @@ -8,7 +8,7 @@ import net.minecraft.entity.player.PlayerEntity; public class PlayerBehaviour extends EntityBehaviour { @Override - public void update(Caster source, PlayerEntity entity, Disguise spell) { + public void update(Living source, PlayerEntity entity, Disguise spell) { if (source instanceof Pony pony) { PlayerEntity pFrom = pony.asEntity(); @@ -22,14 +22,15 @@ public class PlayerBehaviour extends EntityBehaviour { ((PlayerEntityDuck)entity).callUpdateCapeAngles(); } - if (source.getEntity().getPose() != entity.getPose()) { - entity.setPose(source.getEntity().getPose()); + if (source.asEntity().getPose() != entity.getPose()) { + entity.setPose(source.asEntity().getPose()); } - if (source.getEntity().isSwimming() != entity.isSwimming()) { - entity.setSwimming(source.getEntity().isSwimming()); + if (source.asEntity().isSwimming() != entity.isSwimming()) { + entity.setSwimming(source.asEntity().isSwimming()); } - if (source.getEntity() instanceof LivingEntityDuck duck) { - duck.copyLeaningAnglesFrom(((LivingEntityDuck)source.getEntity())); + if (source.asEntity() instanceof LivingEntityDuck duck) { + // TODO: CopyAngles + duck.copyLeaningAnglesFrom(((LivingEntityDuck)entity)); } } } 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 e2e8045a..47c76ea1 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/ShulkerBehaviour.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/ShulkerBehaviour.java @@ -1,6 +1,6 @@ package com.minelittlepony.unicopia.entity.behaviour; -import com.minelittlepony.unicopia.ability.magic.Caster; +import com.minelittlepony.unicopia.entity.Living; import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.mixin.MixinShulkerEntity; @@ -14,7 +14,7 @@ import net.minecraft.util.math.Vec3d; public class ShulkerBehaviour extends EntityBehaviour { @Override - public void update(Caster source, ShulkerEntity shulker, Disguise spell) { + public void update(Living source, ShulkerEntity shulker, Disguise spell) { shulker.setYaw(0); shulker.prevBodyYaw = 0; shulker.bodyYaw = 0; @@ -27,11 +27,11 @@ public class ShulkerBehaviour extends EntityBehaviour { boolean noGravity = !shulker.isOnGround() && !shulker.world.isAir(pos) && (attachmentFace == Direction.UP || attachmentFace.getAxis() != Axis.Y); - source.getEntity().setNoGravity(noGravity); - if (noGravity && source.getEntity().isSneaking()) { - Vec3d vel = source.getEntity().getVelocity(); + source.asEntity().setNoGravity(noGravity); + if (noGravity && source.asEntity().isSneaking()) { + Vec3d vel = source.asEntity().getVelocity(); if (vel.y > 0) { - source.getEntity().setVelocity(vel.multiply(1, 0.8, 1)); + source.asEntity().setVelocity(vel.multiply(1, 0.8, 1)); } } } diff --git a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/WaterCreatureBehaviour.java b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/WaterCreatureBehaviour.java index 63408f6a..3ea4aced 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/behaviour/WaterCreatureBehaviour.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/behaviour/WaterCreatureBehaviour.java @@ -1,22 +1,22 @@ package com.minelittlepony.unicopia.entity.behaviour; -import com.minelittlepony.unicopia.ability.magic.Caster; +import com.minelittlepony.unicopia.entity.Living; import net.minecraft.entity.damage.DamageSource; import net.minecraft.entity.mob.WaterCreatureEntity; public class WaterCreatureBehaviour extends EntityBehaviour { @Override - public void update(Caster source, WaterCreatureEntity entity, Disguise spell) { + public void update(Living source, WaterCreatureEntity entity, Disguise spell) { - if (source.getEntity().isInsideWaterOrBubbleColumn()) { - source.getEntity().setAir(source.getEntity().getAir() - 1); - if (source.getEntity().getAir() == -20) { - source.getEntity().setAir(0); - source.getEntity().damage(DamageSource.DRYOUT, 2); + if (source.asEntity().isInsideWaterOrBubbleColumn()) { + source.asEntity().setAir(source.asEntity().getAir() - 1); + if (source.asEntity().getAir() == -20) { + source.asEntity().setAir(0); + source.asEntity().damage(DamageSource.DRYOUT, 2); } } else { - source.getEntity().setAir(300); + source.asEntity().setAir(300); } } 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 3100a27f..bd070bd7 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerCamera.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerCamera.java @@ -68,7 +68,7 @@ public class PlayerCamera extends MotionCompositor { return 0; } - float energyAddition = (player.getReferenceWorld().random.nextInt(maxE) - maxE/2) / 100F; + float energyAddition = (player.asWorld().random.nextInt(maxE) - maxE/2) / 100F; if (Math.abs(energyAddition) <= 0.001) { return 0; 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 f4df2616..6bd3e982 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerLevelStore.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerLevelStore.java @@ -30,7 +30,7 @@ class PlayerLevelStore implements Levelled.LevelStore { if (upgradeMana) { pony.getMagicalReserves().getMana().add(pony.getMagicalReserves().getMana().getMax() / 2); } - pony.getReferenceWorld().playSound(null, pony.getOrigin(), levelUpSound, SoundCategory.PLAYERS, 1, 2); + pony.asWorld().playSound(null, pony.getOrigin(), levelUpSound, SoundCategory.PLAYERS, 1, 2); } Levelled.LevelStore.super.add(levels); } 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 939f2a81..69aa8c41 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/Pony.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/Pony.java @@ -136,7 +136,7 @@ public class Pony extends Living implements Copyable, Update this.animationMaxDuration = animationDuration; if (!isClient()) { - Channel.SERVER_PLAYER_ANIMATION_CHANGE.send(getReferenceWorld(), new MsgPlayerAnimationChange(this, animation, animationDuration)); + Channel.SERVER_PLAYER_ANIMATION_CHANGE.send(asWorld(), new MsgPlayerAnimationChange(this, animation, animationDuration)); } animation.getSound().ifPresent(sound -> { @@ -369,14 +369,14 @@ public class Pony extends Living implements Copyable, Update } public boolean canHangAt(BlockPos pos) { - if (!getReferenceWorld().isAir(pos) || !getReferenceWorld().isAir(pos.down())) { + if (!asWorld().isAir(pos) || !asWorld().isAir(pos.down())) { return false; } pos = pos.up(); - BlockState state = getReferenceWorld().getBlockState(pos); + BlockState state = asWorld().getBlockState(pos); - return state.isSolidSurface(getReferenceWorld(), pos, entity, Direction.DOWN); + return state.isSolidSurface(asWorld(), pos, entity, Direction.DOWN); } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/item/AlicornAmuletItem.java b/src/main/java/com/minelittlepony/unicopia/item/AlicornAmuletItem.java index 915618fb..c31aa964 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/AlicornAmuletItem.java +++ b/src/main/java/com/minelittlepony/unicopia/item/AlicornAmuletItem.java @@ -122,7 +122,7 @@ public class AlicornAmuletItem extends AmuletItem implements ItemTracker.Trackab float attachedTime = timeWorn / 100F; - LocalDifficulty difficulty = wearer.getReferenceWorld().getLocalDifficulty(wearer.getOrigin()); + LocalDifficulty difficulty = wearer.asWorld().getLocalDifficulty(wearer.getOrigin()); float amount = attachedTime * (1 + difficulty.getClampedLocalDifficulty()); amount = Math.min(amount, wearer.getMaster().getMaxHealth()); diff --git a/src/main/java/com/minelittlepony/unicopia/item/ZapAppleItem.java b/src/main/java/com/minelittlepony/unicopia/item/ZapAppleItem.java index bf349032..e087e58a 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/ZapAppleItem.java +++ b/src/main/java/com/minelittlepony/unicopia/item/ZapAppleItem.java @@ -101,7 +101,7 @@ public class ZapAppleItem extends Item implements ChameleonItem, ToxicHolder, Mu @Override public List getDefaultStacks() { - return Unicopia.SIDE.getPony().map(Pony::getReferenceWorld) + return Unicopia.SIDE.getPony().map(Pony::asWorld) .stream() .flatMap(world -> RegistryUtils.valuesForTag(world, UTags.APPLES)) .filter(a -> a != this).map(item -> { diff --git a/src/main/java/com/minelittlepony/unicopia/item/enchantment/GemFindingEnchantment.java b/src/main/java/com/minelittlepony/unicopia/item/enchantment/GemFindingEnchantment.java index 4b934ff6..5e4ef687 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/enchantment/GemFindingEnchantment.java +++ b/src/main/java/com/minelittlepony/unicopia/item/enchantment/GemFindingEnchantment.java @@ -23,7 +23,7 @@ public class GemFindingEnchantment extends SimpleEnchantment { BlockPos origin = user.getOrigin(); - double volume = BlockPos.findClosest(origin, radius, radius, pos -> user.getReferenceWorld().getBlockState(pos).isIn(UTags.INTERESTING)) + double volume = BlockPos.findClosest(origin, radius, radius, pos -> user.asWorld().getBlockState(pos).isIn(UTags.INTERESTING)) .map(p -> user.getOriginVector().squaredDistanceTo(p.getX(), p.getY(), p.getZ())) .map(find -> (1 - (Math.sqrt(find) / radius))) .orElse(-1D); @@ -37,7 +37,7 @@ public class GemFindingEnchantment extends SimpleEnchantment { @Override public void onEquipped(Living user) { if (user.isClient()) { - MinecraftClient.getInstance().getSoundManager().play(new MagicAuraSoundInstance(user.asEntity().getSoundCategory(), user, user.getReferenceWorld().getRandom())); + MinecraftClient.getInstance().getSoundManager().play(new MagicAuraSoundInstance(user.asEntity().getSoundCategory(), user, user.asWorld().getRandom())); } } diff --git a/src/main/java/com/minelittlepony/unicopia/item/enchantment/PoisonedJokeEnchantment.java b/src/main/java/com/minelittlepony/unicopia/item/enchantment/PoisonedJokeEnchantment.java index 6fc9c05b..0d0e5cfe 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/enchantment/PoisonedJokeEnchantment.java +++ b/src/main/java/com/minelittlepony/unicopia/item/enchantment/PoisonedJokeEnchantment.java @@ -36,19 +36,19 @@ public class PoisonedJokeEnchantment extends SimpleEnchantment implements Identi @Override public void onUserTick(Living user, int level) { - if (sounds.isEmpty() || user.getReferenceWorld().isClient) { + if (sounds.isEmpty() || user.asWorld().isClient) { return; } - int light = user.getReferenceWorld().getLightLevel(user.asEntity().getRootVehicle().getBlockPos()); - Random rng = user.getReferenceWorld().random; + int light = user.asWorld().getLightLevel(user.asEntity().getRootVehicle().getBlockPos()); + Random rng = user.asWorld().random; Data data = user.getEnchants().computeIfAbsent(this, Data::new); data.level -= rng.nextFloat() * 0.8F; if (rng.nextInt(Math.max(1, (light * 9) + (int)data.level)) == 0) { data.level = rng.nextInt(5000); - user.getReferenceWorld().playSoundFromEntity( + user.asWorld().playSoundFromEntity( null, user.asEntity(), sounds.get(rng.nextInt(sounds.size())), SoundCategory.HOSTILE, diff --git a/src/main/java/com/minelittlepony/unicopia/item/enchantment/WantItNeedItEnchantment.java b/src/main/java/com/minelittlepony/unicopia/item/enchantment/WantItNeedItEnchantment.java index 71688e6c..d181a4d7 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/enchantment/WantItNeedItEnchantment.java +++ b/src/main/java/com/minelittlepony/unicopia/item/enchantment/WantItNeedItEnchantment.java @@ -16,7 +16,7 @@ public class WantItNeedItEnchantment extends SimpleEnchantment { @Override public void onUserTick(Living user, int level) { - if (user instanceof Creature && user.getReferenceWorld().random.nextInt(10) == 0) { + if (user instanceof Creature && user.asWorld().random.nextInt(10) == 0) { ParticleUtils.spawnParticles(new FollowingParticleEffect(UParticles.HEALTH_DRAIN, user.asEntity(), 0.2F), user.asEntity(), 1); } } diff --git a/src/main/java/com/minelittlepony/unicopia/network/MsgRequestSpeciesChange.java b/src/main/java/com/minelittlepony/unicopia/network/MsgRequestSpeciesChange.java index add53d72..b9cec5f8 100644 --- a/src/main/java/com/minelittlepony/unicopia/network/MsgRequestSpeciesChange.java +++ b/src/main/java/com/minelittlepony/unicopia/network/MsgRequestSpeciesChange.java @@ -43,7 +43,7 @@ public class MsgRequestSpeciesChange implements Packet { public void handle(ServerPlayerEntity sender) { Pony player = Pony.of(sender); - Race worldDefaultRace = WorldTribeManager.forWorld((ServerWorld)player.getReferenceWorld()).getDefaultRace(); + Race worldDefaultRace = WorldTribeManager.forWorld((ServerWorld)player.asWorld()).getDefaultRace(); if (force || player.getActualSpecies().isDefault() || (player.getActualSpecies() == worldDefaultRace && !player.isSpeciesPersisted())) { player.setSpecies(newRace.isPermitted(sender) ? newRace : worldDefaultRace); diff --git a/src/main/java/com/minelittlepony/unicopia/network/datasync/EffectSync.java b/src/main/java/com/minelittlepony/unicopia/network/datasync/EffectSync.java index 6b224cd4..e79dfa7e 100644 --- a/src/main/java/com/minelittlepony/unicopia/network/datasync/EffectSync.java +++ b/src/main/java/com/minelittlepony/unicopia/network/datasync/EffectSync.java @@ -113,8 +113,8 @@ public class EffectSync implements SpellContainer, NbtSerialisable { @SuppressWarnings("unchecked") private Stream read(@Nullable SpellPredicate type, boolean synchronize, boolean sendUpdate) { - if (synchronize && spells.fromNbt(owner.getEntity().getDataTracker().get(param)) && sendUpdate) { - owner.getEntity().getDataTracker().set(param, spells.toNbt()); + if (synchronize && spells.fromNbt(owner.asEntity().getDataTracker().get(param)) && sendUpdate) { + owner.asEntity().getDataTracker().set(param, spells.toNbt()); } if (type == null) { @@ -135,7 +135,7 @@ public class EffectSync implements SpellContainer, NbtSerialisable { private void write() { if (spells.isDirty()) { - owner.getEntity().getDataTracker().set(param, spells.toNbt()); + owner.asEntity().getDataTracker().set(param, spells.toNbt()); } } diff --git a/src/main/java/com/minelittlepony/unicopia/particle/ParticleHandle.java b/src/main/java/com/minelittlepony/unicopia/particle/ParticleHandle.java index f10f3174..000bd705 100644 --- a/src/main/java/com/minelittlepony/unicopia/particle/ParticleHandle.java +++ b/src/main/java/com/minelittlepony/unicopia/particle/ParticleHandle.java @@ -22,13 +22,13 @@ import net.minecraft.world.World; public class ParticleHandle { private final Map loadedEffects = new WeakHashMap<>(); - public Optional update(UUID id, ParticleSource source, Consumer constructor) { + public Optional update(UUID id, ParticleSource source, Consumer constructor) { return update(id, "prime", source, constructor); } - public Optional update(UUID id, String partName, ParticleSource source, Consumer constructor) { + public Optional update(UUID id, String partName, ParticleSource source, Consumer constructor) { return get(partName).or(() -> { - if (source.getReferenceWorld().isClient) { + if (source.asEntity().world.isClient) { new ClientHandle().addParticle(id, partName, source, constructor); } return get(partName); @@ -50,7 +50,7 @@ public class ParticleHandle { private Particle pp; @Environment(EnvType.CLIENT) - private void addParticle(UUID id, String partName, ParticleSource source, Consumer constructor) { + private void addParticle(UUID id, String partName, ParticleSource source, Consumer constructor) { SPAWNED_PARTICLES.values().removeIf(set -> { set.values().removeIf(particle -> particle.get() == null); return set.isEmpty(); @@ -110,7 +110,7 @@ public class ParticleHandle { } public Optional> get() { - caster = caster.filter(r -> r.get() != null && r.get().getSpellSlot().contains(effect) && r.get().getEntity().isAlive()); + caster = caster.filter(r -> r.get() != null && r.get().getSpellSlot().contains(effect) && r.get().asEntity().isAlive()); return caster.map(WeakReference::get); } } diff --git a/src/main/java/com/minelittlepony/unicopia/particle/ParticleSource.java b/src/main/java/com/minelittlepony/unicopia/particle/ParticleSource.java index 19c4ad51..3e280cf8 100644 --- a/src/main/java/com/minelittlepony/unicopia/particle/ParticleSource.java +++ b/src/main/java/com/minelittlepony/unicopia/particle/ParticleSource.java @@ -2,31 +2,17 @@ package com.minelittlepony.unicopia.particle; import java.util.function.Consumer; +import com.minelittlepony.unicopia.EntityConvertable; import com.minelittlepony.unicopia.util.shape.PointGenerator; import net.minecraft.entity.Entity; import net.minecraft.particle.ParticleEffect; import net.minecraft.util.math.Vec3d; -import net.minecraft.world.World; -public interface ParticleSource extends ParticleSpawner { - - /** - * gets the minecraft world - */ - World getReferenceWorld(); - - Entity getEntity(); - - /** - * Gets the center position where this caster is located. - */ - default Vec3d getOriginVector() { - return getEntity().getPos(); - } +public interface ParticleSource extends ParticleSpawner, EntityConvertable { default void spawnParticles(ParticleEffect particleId, int count) { - ParticleUtils.spawnParticles(particleId, getEntity(), count); + ParticleUtils.spawnParticles(particleId, asEntity(), count); } default void spawnParticles(PointGenerator area, int count, Consumer particleSpawner) { @@ -34,11 +20,11 @@ public interface ParticleSource extends ParticleSpawner { } default void spawnParticles(Vec3d pos, PointGenerator area, int count, Consumer particleSpawner) { - area.translate(pos).randomPoints(count, getReferenceWorld().random).forEach(particleSpawner); + area.translate(pos).randomPoints(count, asEntity().world.random).forEach(particleSpawner); } @Override default void addParticle(ParticleEffect effect, Vec3d position, Vec3d velocity) { - ParticleUtils.spawnParticle(getReferenceWorld(), effect, position, velocity); + ParticleUtils.spawnParticle(asEntity().world, effect, position, velocity); } } diff --git a/src/main/java/com/minelittlepony/unicopia/projectile/MagicProjectileEntity.java b/src/main/java/com/minelittlepony/unicopia/projectile/MagicProjectileEntity.java index 19d5b988..7bef8477 100644 --- a/src/main/java/com/minelittlepony/unicopia/projectile/MagicProjectileEntity.java +++ b/src/main/java/com/minelittlepony/unicopia/projectile/MagicProjectileEntity.java @@ -7,7 +7,6 @@ import java.util.function.Function; import org.jetbrains.annotations.Nullable; import com.minelittlepony.unicopia.Affinity; -import com.minelittlepony.unicopia.Owned; import com.minelittlepony.unicopia.ability.magic.Affine; import com.minelittlepony.unicopia.ability.magic.Caster; import com.minelittlepony.unicopia.ability.magic.Levelled; @@ -53,7 +52,7 @@ import net.minecraft.world.World; * * Can also carry a spell if needed. */ -public class MagicProjectileEntity extends ThrownItemEntity implements Caster, Owned { +public class MagicProjectileEntity extends ThrownItemEntity implements Caster { private static final TrackedData DAMAGE = DataTracker.registerData(MagicProjectileEntity.class, TrackedDataHandlerRegistry.FLOAT); private static final TrackedData GRAVITY = DataTracker.registerData(MagicProjectileEntity.class, TrackedDataHandlerRegistry.FLOAT); private static final TrackedData HYDROPHOBIC = DataTracker.registerData(MagicProjectileEntity.class, TrackedDataHandlerRegistry.BOOLEAN); @@ -98,7 +97,7 @@ public class MagicProjectileEntity extends ThrownItemEntity implements Caster

  • caster) { - return new MagicalDamageSource(type, caster.getMaster(), caster.getEntity(), false, false); + return new MagicalDamageSource(type, caster.getMaster(), caster.asEntity(), false, false); } private Entity spell; diff --git a/src/main/java/com/minelittlepony/unicopia/util/SoundEmitter.java b/src/main/java/com/minelittlepony/unicopia/util/SoundEmitter.java index b6a2725f..b9cd1b0e 100644 --- a/src/main/java/com/minelittlepony/unicopia/util/SoundEmitter.java +++ b/src/main/java/com/minelittlepony/unicopia/util/SoundEmitter.java @@ -1,20 +1,16 @@ package com.minelittlepony.unicopia.util; +import com.minelittlepony.unicopia.EntityConvertable; + import net.minecraft.entity.Entity; import net.minecraft.sound.SoundCategory; import net.minecraft.sound.SoundEvent; import net.minecraft.util.math.random.Random; -import net.minecraft.world.World; - -public interface SoundEmitter { - - World getReferenceWorld(); - - Entity getEntity(); +public interface SoundEmitter extends EntityConvertable { default void playSound(SoundEvent sound, float volume, float pitch) { - playSoundAt(getEntity(), sound, volume, pitch); + playSoundAt(asEntity(), sound, volume, pitch); } default void playSound(SoundEvent sound, float volume) { @@ -22,7 +18,7 @@ public interface SoundEmitter { } default float getRandomPitch() { - return getRandomPitch(getReferenceWorld().getRandom()); + return getRandomPitch(asEntity().world.getRandom()); } static void playSoundAt(Entity entity, SoundEvent sound, float volume, float pitch) {