Replace getEntity() with asEntity() and getReferenceWorld() with asWorld()

This commit is contained in:
Sollace 2022-12-19 18:13:15 +01:00
parent daa508ba73
commit a239d30cab
79 changed files with 307 additions and 319 deletions

View file

@ -1,6 +1,8 @@
package com.minelittlepony.unicopia; package com.minelittlepony.unicopia;
import net.minecraft.entity.Entity; 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. * Interface for things that can be owned by an entity.
@ -11,4 +13,17 @@ import net.minecraft.entity.Entity;
*/ */
public interface EntityConvertable<E extends Entity> { public interface EntityConvertable<E extends Entity> {
E asEntity(); 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();
}
} }

View file

@ -8,7 +8,6 @@ import org.jetbrains.annotations.Nullable;
import com.minelittlepony.unicopia.entity.EntityReference; import com.minelittlepony.unicopia.entity.EntityReference;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.world.World;
/** /**
* Interface for things that can be weakly owned (by an entity). * Interface for things that can be weakly owned (by an entity).
@ -16,7 +15,7 @@ import net.minecraft.world.World;
* *
* @param <E> The type of object that owns us. * @param <E> The type of object that owns us.
*/ */
public interface WeaklyOwned<E extends Entity> extends Owned<E> { public interface WeaklyOwned<E extends Entity> extends Owned<E>, WorldConvertable {
EntityReference<E> getMasterReference(); EntityReference<E> getMasterReference();
@ -40,14 +39,10 @@ public interface WeaklyOwned<E extends Entity> extends Owned<E> {
getMasterReference().set(master); getMasterReference().set(master);
} }
default World getReferenceWorld() {
return ((Entity)this).getEntityWorld();
}
@Nullable @Nullable
@Override @Override
default E getMaster() { default E getMaster() {
return getMasterReference().get(getReferenceWorld()); return getMasterReference().get(asWorld());
} }
@Override @Override

View file

@ -0,0 +1,10 @@
package com.minelittlepony.unicopia;
import net.minecraft.world.World;
public interface WorldConvertable {
/**
* Gets the minecraft world
*/
World asWorld();
}

View file

@ -202,7 +202,7 @@ public class AbilityDispatcher implements Tickable, NbtSerialisable {
return; return;
} }
if (ability.canActivate(player.getReferenceWorld(), player)) { if (ability.canActivate(player.asWorld(), player)) {
triggered = true; triggered = true;
setCooldown(ability.getCooldownTime(player)); setCooldown(ability.getCooldownTime(player));

View file

@ -54,18 +54,18 @@ public class BatEeeeAbility implements Ability<Hit> {
@Override @Override
public void apply(Pony player, Hit data) { public void apply(Pony player, Hit data) {
Random rng = player.getReferenceWorld().random; Random rng = player.asWorld().random;
int count = 1 + rng.nextInt(10); int count = 1 + rng.nextInt(10);
for (int i = 0; i < count; i++) { 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, 0.9F + (rng.nextFloat() - 0.5F) / 2F,
1.6F + (rng.nextFloat() - 0.5F) 1.6F + (rng.nextFloat() - 0.5F)
); );
} }
AwaitTickQueue.scheduleTask(player.getReferenceWorld(), w -> { AwaitTickQueue.scheduleTask(player.asWorld(), w -> {
for (int i = 0; i < count; i++) { 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, 0.9F + (rng.nextFloat() - 0.5F) / 2F,
1.6F + (rng.nextFloat() - 0.5F) 1.6F + (rng.nextFloat() - 0.5F)
); );

View file

@ -55,7 +55,7 @@ public class CarryAbility implements Ability<Hit> {
public boolean onQuickAction(Pony player, ActivationType type) { public boolean onQuickAction(Pony player, ActivationType type) {
if (type == ActivationType.TAP && player.getPhysics().isFlying()) { 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; return true;
} }
@ -65,7 +65,7 @@ public class CarryAbility implements Ability<Hit> {
@Override @Override
public void apply(Pony iplayer, Hit data) { public void apply(Pony iplayer, Hit data) {
PlayerEntity player = iplayer.asEntity(); PlayerEntity player = iplayer.asEntity();
LivingEntity rider = findRider(player, iplayer.getReferenceWorld()); LivingEntity rider = findRider(player, iplayer.asWorld());
if (player.hasPassengers()) { if (player.hasPassengers()) {
player.removeAllPassengers(); player.removeAllPassengers();

View file

@ -42,8 +42,8 @@ public class ChangelingDisguiseAbility extends ChangelingFeedAbility {
Trace trace = Trace.create(player, 10, 1, EquinePredicates.VALID_FOR_DISGUISE); Trace trace = Trace.create(player, 10, 1, EquinePredicates.VALID_FOR_DISGUISE);
Entity looked = trace.getEntity().map(AbstractDisguiseSpell::getAppearance).orElseGet(() -> trace.getBlockPos().map(pos -> { Entity looked = trace.getEntity().map(AbstractDisguiseSpell::getAppearance).orElseGet(() -> trace.getBlockPos().map(pos -> {
if (!iplayer.getReferenceWorld().isAir(pos)) { if (!iplayer.asWorld().isAir(pos)) {
return MixinFallingBlockEntity.createInstance(player.getEntityWorld(), 0, 0, 0, iplayer.getReferenceWorld().getBlockState(pos)); return MixinFallingBlockEntity.createInstance(player.getEntityWorld(), 0, 0, 0, iplayer.asWorld().getBlockState(pos));
} }
return null; return null;
}).orElse(null)); }).orElse(null));

View file

@ -80,7 +80,7 @@ public class ChangelingFeedAbility implements Ability<Hit> {
} }
protected List<LivingEntity> getTargets(Pony player) { protected List<LivingEntity> getTargets(Pony player) {
List<Entity> list = VecHelper.findInRange(player.asEntity(), player.getReferenceWorld(), player.getOriginVector(), 3, this::canDrain); List<Entity> list = VecHelper.findInRange(player.asEntity(), player.asWorld(), player.getOriginVector(), 3, this::canDrain);
TraceHelper.<LivingEntity>findEntity(player.asEntity(), 17, 1, TraceHelper.<LivingEntity>findEntity(player.asEntity(), 17, 1,
looked -> looked instanceof LivingEntity && !list.contains(looked) && canDrain(looked)) looked -> looked instanceof LivingEntity && !list.contains(looked) && canDrain(looked))
@ -162,7 +162,7 @@ public class ChangelingFeedAbility implements Ability<Hit> {
@Override @Override
public void postApply(Pony player, AbilitySlot slot) { 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); player.spawnParticles(ParticleTypes.HEART, 1);
} }
} }

View file

@ -56,7 +56,7 @@ public class EarthPonyGrowAbility implements Ability<Pos> {
for (BlockPos pos : BlockPos.iterate( for (BlockPos pos : BlockPos.iterate(
data.pos().add(-2, -2, -2), data.pos().add(-2, -2, -2),
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) { if (count > 0) {
@ -80,7 +80,7 @@ public class EarthPonyGrowAbility implements Ability<Pos> {
public void preApply(Pony player, AbilitySlot slot) { public void preApply(Pony player, AbilitySlot slot) {
player.getMagicalReserves().getExertion().add(30); player.getMagicalReserves().getExertion().add(30);
if (player.getReferenceWorld().isClient()) { if (player.asWorld().isClient()) {
player.spawnParticles(MagicParticleEffect.UNICORN, 1); player.spawnParticles(MagicParticleEffect.UNICORN, 1);
} }
} }

View file

@ -61,7 +61,7 @@ public class EarthPonyKickAbility implements Ability<Pos> {
double distance = MineLPDelegate.getInstance().getPlayerPonyRace(player.asEntity()).isDefault() ? 6 : -6; double distance = MineLPDelegate.getInstance().getPlayerPonyRace(player.asEntity()).isDefault() ? 6 : -6;
return TraceHelper.findBlock(player.asEntity(), distance, 1) 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; .isPresent() ? 3 : 1;
} }
@ -77,12 +77,12 @@ public class EarthPonyKickAbility implements Ability<Pos> {
if (!player.isClient()) { if (!player.isClient()) {
data.ifPresent(kickLocation -> { data.ifPresent(kickLocation -> {
Vec3d origin = player.getOriginVector(); 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)) { for (var e : VecHelper.findInRange(player.asEntity(), w, kickLocation.vec(), 2, EntityPredicates.EXCEPT_CREATIVE_OR_SPECTATOR)) {
if (e instanceof LivingEntity entity) { if (e instanceof LivingEntity entity) {
float calculatedStrength = 0.5F * (1 + player.getLevel().getScaled(9)); float calculatedStrength = 0.5F * (1 + player.getLevel().getScaled(9));
entity.damage(MagicalDamageSource.KICK, player.getReferenceWorld().random.nextBetween(2, 10) + calculatedStrength); entity.damage(MagicalDamageSource.KICK, player.asWorld().random.nextBetween(2, 10) + calculatedStrength);
entity.takeKnockback(calculatedStrength, origin.x - entity.getX(), origin.z - entity.getZ()); entity.takeKnockback(calculatedStrength, origin.x - entity.getX(), origin.z - entity.getZ());
Living.updateVelocity(entity); Living.updateVelocity(entity);
player.subtractEnergyCost(3); player.subtractEnergyCost(3);
@ -107,7 +107,7 @@ public class EarthPonyKickAbility implements Ability<Pos> {
@Override @Override
public Pos tryActivate(Pony player) { public Pos tryActivate(Pony player) {
return TraceHelper.findBlock(player.asEntity(), 6 * getKickDirection(player), 1) return TraceHelper.findBlock(player.asEntity(), 6 * getKickDirection(player), 1)
.filter(pos -> TreeType.at(pos, player.getReferenceWorld()) != TreeType.NONE) .filter(pos -> TreeType.at(pos, player.asWorld()) != TreeType.NONE)
.map(Pos::new) .map(Pos::new)
.orElseGet(() -> getDefaultKickLocation(player)); .orElseGet(() -> getDefaultKickLocation(player));
} }
@ -128,10 +128,10 @@ public class EarthPonyKickAbility implements Ability<Pos> {
@Override @Override
public boolean canApply(Pony player, Pos data) { public boolean canApply(Pony player, Pos data) {
BlockPos pos = data.pos(); 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) return tree == TreeType.NONE || tree.findBase(player.asWorld(), pos)
.map(base -> tree.countBlocks(player.getReferenceWorld(), pos) > 0) .map(base -> tree.countBlocks(player.asWorld(), pos) > 0)
.orElse(false); .orElse(false);
} }
@ -143,7 +143,7 @@ public class EarthPonyKickAbility implements Ability<Pos> {
@Override @Override
public void apply(Pony iplayer, Pos data) { public void apply(Pony iplayer, Pos data) {
BlockPos pos = data.pos(); BlockPos pos = data.pos();
TreeType tree = TreeType.at(pos, iplayer.getReferenceWorld()); TreeType tree = TreeType.at(pos, iplayer.asWorld());
iplayer.setAnimation(Animation.KICK); iplayer.setAnimation(Animation.KICK);
iplayer.subtractEnergyCost(tree == TreeType.NONE ? 1 : 3); iplayer.subtractEnergyCost(tree == TreeType.NONE ? 1 : 3);
@ -151,7 +151,7 @@ public class EarthPonyKickAbility implements Ability<Pos> {
if (tree == TreeType.NONE) { if (tree == TreeType.NONE) {
return; return;
} else { } 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(); PlayerEntity player = iplayer.asEntity();

View file

@ -84,7 +84,7 @@ public class EarthPonyStompAbility implements Ability<Hit> {
private void thrustDownwards(Pony player) { private void thrustDownwards(Pony player) {
BlockPos ppos = player.getOrigin(); 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(); double downV = Math.sqrt(ppos.getSquaredDistance(pos)) * player.getPhysics().getGravitySignum();
player.asEntity().addVelocity(0, -downV, 0); player.asEntity().addVelocity(0, -downV, 0);
@ -104,7 +104,7 @@ public class EarthPonyStompAbility implements Ability<Hit> {
float heavyness = 1 + EnchantmentHelper.getEquipmentLevel(UEnchantments.HEAVY, player); 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())); double dist = Math.sqrt(center.getSquaredDistance(i.getBlockPos()));
if (dist <= rad + 3) { if (dist <= rad + 3) {

View file

@ -60,7 +60,7 @@ public class PegasusCaptureStormAbility implements Ability<Hit> {
@Override @Override
public void apply(Pony player, Hit data) { public void apply(Pony player, Hit data) {
World w = player.getReferenceWorld(); World w = player.asWorld();
ItemStack stack = player.asEntity().getStackInHand(Hand.MAIN_HAND); ItemStack stack = player.asEntity().getStackInHand(Hand.MAIN_HAND);
boolean thundering = w.isThundering(); boolean thundering = w.isThundering();

View file

@ -61,7 +61,7 @@ public class PegasusRainboomAbility implements Ability<Hit> {
public boolean onQuickAction(Pony player, ActivationType type) { public boolean onQuickAction(Pony player, ActivationType type) {
if (type == ActivationType.TAP && player.getPhysics().isFlying() && player.getMagicalReserves().getMana().get() > 40) { 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); player.subtractEnergyCost(4);
return true; return true;
} }

View file

@ -96,7 +96,7 @@ public class UnicornCastingAbility implements Ability<Hit> {
if (amount < 0) { if (amount < 0) {
AmuletItem.consumeEnergy(stack, amount); AmuletItem.consumeEnergy(stack, amount);
player.getMagicalReserves().getMana().add(amount * player.getMagicalReserves().getMana().getMax()); player.getMagicalReserves().getMana().add(amount * player.getMagicalReserves().getMana().getMax());
player.getReferenceWorld().playSoundFromEntity(null, player.asEntity(), USounds.ITEM_AMULET_RECHARGE, SoundCategory.PLAYERS, 1, 1); player.asWorld().playSoundFromEntity(null, player.asEntity(), USounds.ITEM_AMULET_RECHARGE, SoundCategory.PLAYERS, 1, 1);
} }
} }
} else { } else {
@ -152,7 +152,7 @@ public class UnicornCastingAbility implements Ability<Hit> {
float i = player.getAbilities().getStat(slot).getFillProgress(); 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.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); player.playSound(USounds.ITEM_AMULET_CHARGING, 1, i / 20);
} else { } else {

View file

@ -85,7 +85,7 @@ public class UnicornDispellAbility implements Ability<Pos> {
@Override @Override
public void apply(Pony player, Pos data) { public void apply(Pony player, Pos data) {
player.setAnimation(Animation.WOLOLO); player.setAnimation(Animation.WOLOLO);
Caster.stream(VecHelper.findInRange(player.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(); target.getSpellSlot().clear();
}); });
} }

View file

@ -71,7 +71,7 @@ public class UnicornTeleportAbility implements Ability<Pos> {
int maxDistance = player.asEntity().isCreative() ? 1000 : 100; 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); Trace trace = Trace.create(player.asEntity(), maxDistance, 1, EntityPredicates.EXCEPT_SPECTATOR);
return trace.getBlockOrEntityPos().map(pos -> { return trace.getBlockOrEntityPos().map(pos -> {
@ -133,7 +133,7 @@ public class UnicornTeleportAbility implements Ability<Pos> {
return; 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; double distance = destination.distanceTo(teleportee) / 10;

View file

@ -47,6 +47,6 @@ public class Pos extends Hit {
} }
public double distanceTo(Caster<?> caster) { public double distanceTo(Caster<?> caster) {
return Math.sqrt(caster.getEntity().squaredDistanceTo(x, y, z)); return Math.sqrt(caster.asEntity().squaredDistanceTo(x, y, z));
} }
} }

View file

@ -6,8 +6,7 @@ import java.util.stream.Stream;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import com.minelittlepony.unicopia.EquinePredicates; import com.minelittlepony.unicopia.*;
import com.minelittlepony.unicopia.Owned;
import com.minelittlepony.unicopia.ability.magic.spell.effect.SpellType; import com.minelittlepony.unicopia.ability.magic.spell.effect.SpellType;
import com.minelittlepony.unicopia.block.data.ModificationType; import com.minelittlepony.unicopia.block.data.ModificationType;
import com.minelittlepony.unicopia.entity.Physics; 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. * Interface for any magically capable entities that can cast or persist spells.
*/ */
public interface Caster<E extends LivingEntity> extends Owned<LivingEntity>, Levelled, Affine, ParticleSource, SoundEmitter { public interface Caster<E extends Entity> extends Owned<LivingEntity>,
Levelled,
Affine,
ParticleSource<E>,
SoundEmitter<E>,
EntityConvertable<E>,
WorldConvertable {
Physics getPhysics(); Physics getPhysics();
SpellContainer getSpellSlot(); 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.
* <p>
* @return False if the transaction has depleted the caster's reserves.
*/ */
@Override boolean subtractEnergyCost(double amount);
Entity getEntity();
/**
* Gets the minecraft world
*/
@Override @Override
default World getReferenceWorld() { default World asWorld() {
return getEntity().getEntityWorld(); return asEntity().world;
} }
/** /**
* Returns true if we're executing on the client. * Returns true if we're executing on the client.
*/ */
default boolean isClient() { default boolean isClient() {
return getReferenceWorld().isClient(); return asWorld().isClient();
}
/**
* Gets the center position where this caster is located.
*/
default BlockPos getOrigin() {
return getEntity().getBlockPos();
} }
default boolean canModifyAt(BlockPos pos) { default boolean canModifyAt(BlockPos pos) {
@ -69,11 +65,11 @@ public interface Caster<E extends LivingEntity> extends Owned<LivingEntity>, Lev
if (mod.checkPhysical()) { if (mod.checkPhysical()) {
if (getMaster() instanceof PlayerEntity player) { if (getMaster() instanceof PlayerEntity player) {
if (!getReferenceWorld().canPlayerModifyAt(player, pos)) { if (!asWorld().canPlayerModifyAt(player, pos)) {
return false; return false;
} }
} else { } else {
if (!getReferenceWorld().getGameRules().getBoolean(GameRules.DO_MOB_GRIEFING)) { if (!asWorld().getGameRules().getBoolean(GameRules.DO_MOB_GRIEFING)) {
return false; return false;
} }
} }
@ -82,13 +78,6 @@ public interface Caster<E extends LivingEntity> extends Owned<LivingEntity>, Lev
return !mod.checkMagical() || canCastAt(Vec3d.ofCenter(pos)); 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.
* <p>
* @return False if the transaction has depleted the caster's reserves.
*/
boolean subtractEnergyCost(double amount);
default Stream<Caster<?>> findAllSpellsInRange(double radius) { default Stream<Caster<?>> findAllSpellsInRange(double radius) {
return findAllSpellsInRange(radius, null); return findAllSpellsInRange(radius, null);
} }
@ -98,7 +87,7 @@ public interface Caster<E extends LivingEntity> extends Owned<LivingEntity>, Lev
} }
default Stream<Entity> findAllEntitiesInRange(double radius, @Nullable Predicate<Entity> test) { default Stream<Entity> findAllEntitiesInRange(double radius, @Nullable Predicate<Entity> test) {
return VecHelper.findInRange(getEntity(), getReferenceWorld(), getOriginVector(), radius, test).stream(); return VecHelper.findInRange(asEntity(), asWorld(), getOriginVector(), radius, test).stream();
} }
default Stream<Entity> findAllEntitiesInRange(double radius) { default Stream<Entity> findAllEntitiesInRange(double radius) {

View file

@ -28,8 +28,8 @@ public abstract class AbstractDisguiseSpell extends AbstractSpell implements Dis
@Override @Override
public void onDestroyed(Caster<?> caster) { public void onDestroyed(Caster<?> caster) {
caster.getEntity().calculateDimensions(); caster.asEntity().calculateDimensions();
caster.getEntity().setInvisible(false); caster.asEntity().setInvisible(false);
if (caster instanceof Pony) { if (caster instanceof Pony) {
((Pony) caster).setInvisible(false); ((Pony) caster).setInvisible(false);
} }

View file

@ -50,7 +50,7 @@ public class DispersableDisguiseSpell extends AbstractDisguiseSpell implements I
if (isSuppressed()) { if (isSuppressed()) {
source.spawnParticles(MagicParticleEffect.UNICORN, 5); source.spawnParticles(MagicParticleEffect.UNICORN, 5);
source.spawnParticles(UParticles.CHANGELING_MAGIC, 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); source.spawnParticles(UParticles.CHANGELING_MAGIC, 2);
} }
} }

View file

@ -79,7 +79,7 @@ public class PlaceableSpell extends AbstractDelegatingSpell implements OrientedS
if (!source.isClient()) { if (!source.isClient()) {
if (dimension == null) { if (dimension == null) {
dimension = source.getReferenceWorld().getRegistryKey(); dimension = source.asWorld().getRegistryKey();
setDirty(); setDirty();
} }
@ -93,7 +93,7 @@ public class PlaceableSpell extends AbstractDelegatingSpell implements OrientedS
} }
if (situation == Situation.GROUND_ENTITY) { 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(); setDead();
return false; return false;
} }
@ -119,9 +119,9 @@ public class PlaceableSpell extends AbstractDelegatingSpell implements OrientedS
} }
private void spawnPlacedEntity(Caster<?> source) { 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()); 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(); PlaceableSpell copy = spell.toPlaceable();
if (spell instanceof PlacementDelegate delegate) { if (spell instanceof PlacementDelegate delegate) {
delegate.onPlaced(source, copy, entity); delegate.onPlaced(source, copy, entity);
@ -157,8 +157,8 @@ public class PlaceableSpell extends AbstractDelegatingSpell implements OrientedS
castEntity.set(null); castEntity.set(null);
}); });
if (source.getEntity() instanceof CastSpellEntity spellcast) { if (source.asEntity() instanceof CastSpellEntity spellcast) {
Ether.get(source.getReferenceWorld()).remove(getType(), source); Ether.get(source.asWorld()).remove(getType(), source);
} }
} }
super.onDestroyed(source); super.onDestroyed(source);
@ -180,7 +180,7 @@ public class PlaceableSpell extends AbstractDelegatingSpell implements OrientedS
protected Optional<World> getWorld(Caster<?> source) { protected Optional<World> getWorld(Caster<?> source) {
return Optional.ofNullable(dimension) return Optional.ofNullable(dimension)
.map(dim -> source.getReferenceWorld().getServer().getWorld(dim)); .map(dim -> source.asWorld().getServer().getWorld(dim));
} }
@Override @Override

View file

@ -65,25 +65,25 @@ public class RainboomAbilitySpell extends AbstractSpell {
e.damage(MagicalDamageSource.create("rainboom", source).setBreakSunglasses(), 6); e.damage(MagicalDamageSource.create("rainboom", source).setBreakSunglasses(), 6);
}); });
EFFECT_RANGE.translate(source.getOrigin()).getBlockPositions().forEach(pos -> { 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)) { if (state.isIn(UTags.FRAGILE) && source.canModifyAt(pos, ModificationType.PHYSICAL)) {
owner.world.breakBlock(pos, true); owner.world.breakBlock(pos, true);
} }
}); });
Vec3d motion = source.getEntity().getRotationVec(1).multiply(1.5); Vec3d motion = source.asEntity().getRotationVec(1).multiply(1.5);
Vec3d velocity = source.getEntity().getVelocity().add(motion); Vec3d velocity = source.asEntity().getVelocity().add(motion);
while (velocity.length() > 3) { while (velocity.length() > 3) {
velocity = velocity.multiply(0.6); velocity = velocity.multiply(0.6);
} }
source.getEntity().setVelocity(velocity); source.asEntity().setVelocity(velocity);
if (source instanceof Pony pony) { if (source instanceof Pony pony) {
pony.getMagicalReserves().getExhaustion().multiply(0.2F); 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 @Override

View file

@ -49,7 +49,7 @@ public final class ThrowableSpell extends AbstractDelegatingSpell {
* Returns the resulting projectile entity for customization (or null if on the client). * Returns the resulting projectile entity for customization (or null if on the client).
*/ */
public Optional<MagicProjectileEntity> throwProjectile(Caster<?> caster, float divergance) { public Optional<MagicProjectileEntity> throwProjectile(Caster<?> caster, float divergance) {
World world = caster.getReferenceWorld(); World world = caster.asWorld();
LivingEntity entity = caster.getMaster(); LivingEntity entity = caster.getMaster();

View file

@ -38,14 +38,14 @@ public class AreaProtectionSpell extends AbstractAreaEffectSpell {
Vec3d origin = source.getOriginVector(); Vec3d origin = source.getOriginVector();
source.spawnParticles(origin, new Sphere(true, radius), (int)(radius * 6), pos -> { 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.addParticle(new MagicParticleEffect(getType().getColor()), pos, Vec3d.ZERO);
} }
}); });
} }
source.findAllSpellsInRange(radius, e -> isValidTarget(source, e)).filter(caster -> !caster.hasCommonOwner(source)).forEach(caster -> { source.findAllSpellsInRange(radius, e -> isValidTarget(source, e)).filter(caster -> !caster.hasCommonOwner(source)).forEach(caster -> {
caster.getEntity().kill(); caster.asEntity().kill();
}); });
return !isDead(); return !isDead();
@ -65,7 +65,7 @@ public class AreaProtectionSpell extends AbstractAreaEffectSpell {
} }
public boolean blocksMagicFor(Caster<?> source, Caster<?> other, Vec3d position) { 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); && source.getOriginVector().distanceTo(position) <= getDrawDropOffRange(source);
} }

View file

@ -47,8 +47,8 @@ public class AttractiveSpell extends ShieldSpell implements HomingSpell, TimedSp
setDirty(); setDirty();
Vec3d pos = caster.getOriginVector(); Vec3d pos = caster.getOriginVector();
if (target.isPresent(caster.getReferenceWorld()) && target.get(caster.getReferenceWorld()).distanceTo(caster.getEntity()) > getDrawDropOffRange(caster)) { if (target.isPresent(caster.asWorld()) && target.get(caster.asWorld()).distanceTo(caster.asEntity()) > getDrawDropOffRange(caster)) {
target.get(caster.getReferenceWorld()).requestTeleport(pos.x, pos.y, pos.z); target.get(caster.asWorld()).requestTeleport(pos.x, pos.y, pos.z);
} }
return super.tick(caster, situation); 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.spawnParticles(getOrigin(source), new Sphere(false, range), 7, p -> {
source.addParticle( 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())), .withChild(new MagicParticleEffect(getType().getColor())),
p, p,
Vec3d.ZERO Vec3d.ZERO
@ -92,8 +92,8 @@ public class AttractiveSpell extends ShieldSpell implements HomingSpell, TimedSp
force *= AttractionUtils.getForceAdjustment(target); force *= AttractionUtils.getForceAdjustment(target);
} }
if (!isGood && source.getReferenceWorld().random.nextInt(4500) == 0) { if (!isGood && source.asWorld().random.nextInt(4500) == 0) {
source.getEntity().damage(MagicalDamageSource.create("vortex"), 4); source.asEntity().damage(MagicalDamageSource.create("vortex"), 4);
} }
AttractionUtils.applyForce(getOrigin(source), target, -force, 0, false); AttractionUtils.applyForce(getOrigin(source), target, -force, 0, false);
@ -138,7 +138,7 @@ public class AttractiveSpell extends ShieldSpell implements HomingSpell, TimedSp
@Override @Override
public void onDestroyed(Caster<?> caster) { public void onDestroyed(Caster<?> caster) {
target.getOrEmpty(caster.getReferenceWorld()).ifPresent(target -> target.setGlowing(false)); target.getOrEmpty(caster.asWorld()).ifPresent(target -> target.setGlowing(false));
} }
@Override @Override

View file

@ -49,7 +49,7 @@ public class AwkwardSpell extends AbstractSpell implements TimedSpell {
List<Identifier> names = new ArrayList<>(Registries.PARTICLE_TYPE.getIds()); List<Identifier> 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); Identifier id = names.get(index);
ParticleType<?> type = Registries.PARTICLE_TYPE.get(id); ParticleType<?> type = Registries.PARTICLE_TYPE.get(id);

View file

@ -65,14 +65,14 @@ public class CatapultSpell extends AbstractSpell implements ProjectileDelegate.B
} }
protected void apply(Caster<?> caster, Entity e) { 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) { if (Math.abs(e.getVelocity().y) > 0.5) {
e.setVelocity(caster.getEntity().getVelocity()); e.setVelocity(caster.asEntity().getVelocity());
} else { } else {
e.addVelocity( 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, 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; 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.getEntity().ifPresentOrElse(apply, () -> {
trace.ifBlock(pos -> { trace.ifBlock(pos -> {
if (caster.canModifyAt(pos)) { if (caster.canModifyAt(pos)) {
createBlockEntity(caster.getReferenceWorld(), pos, apply); createBlockEntity(caster.asWorld(), pos, apply);
} }
}); });
}); });

View file

@ -86,13 +86,13 @@ public class DarkVortexSpell extends AttractiveSpell implements ProjectileDelega
setDirty(); setDirty();
if (age % 20 == 0) { 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); source.subtractEnergyCost(-accumulatedMass);
if (!source.isClient() && source.getReferenceWorld().random.nextInt(300) == 0) { if (!source.isClient() && source.asWorld().random.nextInt(300) == 0) {
ParticleUtils.spawnParticle(source.getReferenceWorld(), UParticles.LIGHTNING_BOLT, getOrigin(source), Vec3d.ZERO); ParticleUtils.spawnParticle(source.asWorld(), UParticles.LIGHTNING_BOLT, getOrigin(source), Vec3d.ZERO);
} }
return super.tick(source, situation); return super.tick(source, situation);
@ -161,9 +161,9 @@ public class DarkVortexSpell extends AttractiveSpell implements ProjectileDelega
return; return;
} }
if (source.getOrigin().isWithinDistance(i, getEventHorizonRadius() / 2)) { if (source.getOrigin().isWithinDistance(i, getEventHorizonRadius() / 2)) {
source.getReferenceWorld().breakBlock(i, false); source.asWorld().breakBlock(i, false);
} else { } else {
CatapultSpell.createBlockEntity(source.getReferenceWorld(), i, e -> { CatapultSpell.createBlockEntity(source.asWorld(), i, e -> {
applyRadialEffect(source, e, e.getPos().distanceTo(origin), radius); 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) { protected boolean canAffect(Caster<?> source, BlockPos pos) {
return source.canModifyAt(pos) return source.canModifyAt(pos)
&& source.getReferenceWorld().getFluidState(pos).isEmpty() && source.asWorld().getFluidState(pos).isEmpty()
&& source.getReferenceWorld().getBlockState(pos).getHardness(source.getReferenceWorld(), pos) >= 0; && source.asWorld().getBlockState(pos).getHardness(source.asWorld(), pos) >= 0;
} }
// 1. force decreases with distance: distance scale 1 -> 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.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 { } else {
double force = getAttractiveForce(source, target); double force = getAttractiveForce(source, target);

View file

@ -39,7 +39,7 @@ public class DisplacementSpell extends AbstractSpell implements HomingSpell, Pla
} }
if (ticks == 0) { if (ticks == 0) {
target.ifPresent(source.getReferenceWorld(), target -> { target.ifPresent(source.asWorld(), target -> {
Vec3d destinationPos = target.getPos(); Vec3d destinationPos = target.getPos();
Vec3d destinationVel = target.getVelocity(); Vec3d destinationVel = target.getVelocity();
@ -95,7 +95,7 @@ public class DisplacementSpell extends AbstractSpell implements HomingSpell, Pla
@Override @Override
public void onDestroyed(Caster<?> caster) { public void onDestroyed(Caster<?> caster) {
caster.getMaster().setGlowing(false); caster.getMaster().setGlowing(false);
target.ifPresent(caster.getReferenceWorld(), e -> e.setGlowing(false)); target.ifPresent(caster.asWorld(), e -> e.setGlowing(false));
} }
@Override @Override

View file

@ -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 strength = 1F / (getTraits().get(Trait.STRENGTH, 2, 9) / targets.size());
final float generosity = getTraits().get(Trait.GENEROSITY, 1, MAX_GENEROSITY_FACTOR) / MAX_GENEROSITY_FACTOR; final float generosity = getTraits().get(Trait.GENEROSITY, 1, MAX_GENEROSITY_FACTOR) / MAX_GENEROSITY_FACTOR;
Entity entity = caster.getEntity(); Entity entity = caster.asEntity();
Vec3d masterVelocity = caster.getEntity().getVelocity().multiply(0.1); Vec3d masterVelocity = entity.getVelocity().multiply(0.1);
targets.forEach(target -> { targets.forEach(target -> {
if (target.getVelocity().y < 0) { if (target.getVelocity().y < 0) {
@ -84,7 +84,7 @@ public class FeatherFallSpell extends AbstractSpell implements TimedSpell {
((PlayerEntity)target).getAbilities().flying = false; ((PlayerEntity)target).getAbilities().flying = false;
} }
target.setVelocity(target.getVelocity().multiply(1, delta, 1)); 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); target.addVelocity(masterVelocity.x, 0, masterVelocity.z);
} }
} }
@ -114,8 +114,7 @@ public class FeatherFallSpell extends AbstractSpell implements TimedSpell {
} }
protected Stream<Entity> getTargets(Caster<?> caster) { protected Stream<Entity> getTargets(Caster<?> caster) {
Entity owner = caster.getEntity();// , EquinePredicates.IS_PLAYER return Stream.concat(Stream.of(caster.asEntity()), caster.findAllEntitiesInRange(getEffectRange()).sorted((a, b) -> {
return Stream.concat(Stream.of(owner), caster.findAllEntitiesInRange(getEffectRange()).sorted((a, b) -> {
return Integer.compare( return Integer.compare(
FriendshipBraceletItem.isComrade(caster, a) ? 1 : 0, FriendshipBraceletItem.isComrade(caster, a) ? 1 : 0,
FriendshipBraceletItem.isComrade(caster, b) ? 1 : 0 FriendshipBraceletItem.isComrade(caster, b) ? 1 : 0

View file

@ -57,7 +57,7 @@ public class FireBoltSpell extends AbstractSpell implements HomingSpell,
return true; 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( target.set(caster.findAllEntitiesInRange(
getTraits().get(Trait.FOCUS) - 49, getTraits().get(Trait.FOCUS) - 49,
EntityPredicates.VALID_LIVING_ENTITY.and(TargetSelecter.notOwnerOrFriend(this, caster)) 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++) { for (int i = 0; i < getNumberOfBalls(caster); i++) {
getTypeAndTraits().create().toThrowable().throwProjectile(caster, 2).ifPresent(c -> { 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; return false;
} }
@ -83,7 +83,7 @@ public class FireBoltSpell extends AbstractSpell implements HomingSpell,
} }
protected int getNumberOfBalls(Caster<?> caster) { 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 @Override

View file

@ -52,7 +52,7 @@ public class FireSpell extends AbstractAreaEffectSpell implements ProjectileDele
public void onImpact(MagicProjectileEntity projectile, BlockHitResult hit) { public void onImpact(MagicProjectileEntity projectile, BlockHitResult hit) {
if (!projectile.isClient()) { if (!projectile.isClient()) {
Vec3d pos = hit.getPos(); 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) { public void onImpact(MagicProjectileEntity projectile, EntityHitResult hit) {
if (!projectile.isClient()) { if (!projectile.isClient()) {
Entity entity = hit.getEntity(); 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, 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) (a, b) -> a || b)
|| applyEntities(null, source.getReferenceWorld(), source.getOriginVector()); || applyEntities(null, source.asWorld(), source.getOriginVector());
} }
protected void generateParticles(Caster<?> source) { protected void generateParticles(Caster<?> source) {

View file

@ -50,7 +50,7 @@ public class HydrophobicSpell extends AbstractSpell {
public boolean tick(Caster<?> source, Situation situation) { public boolean tick(Caster<?> source, Situation situation) {
if (!source.isClient()) { if (!source.isClient()) {
World world = source.getReferenceWorld(); World world = source.asWorld();
Shape area = new Sphere(false, getRange(source)).translate(source.getOriginVector()); 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.subtractEnergyCost(storedFluidPositions.isEmpty() ? 0.001F : 0.02F);
source.spawnParticles(new Sphere(true, getRange(source)), 10, pos -> { source.spawnParticles(new Sphere(true, getRange(source)), 10, pos -> {
BlockPos bp = new BlockPos(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); 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); source.playSound(USounds.SPELL_AMBIENT, 0.5F);
} }
} }
@ -99,7 +99,7 @@ public class HydrophobicSpell extends AbstractSpell {
@Override @Override
public void onDestroyed(Caster<?> caster) { public void onDestroyed(Caster<?> caster) {
storedFluidPositions.removeIf(entry -> { storedFluidPositions.removeIf(entry -> {
entry.restore(caster.getReferenceWorld()); entry.restore(caster.asWorld());
return true; return true;
}); });
} }

View file

@ -40,24 +40,24 @@ public class IceSpell extends AbstractSpell {
@Override @Override
public boolean tick(Caster<?> source, Situation situation) { 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 -> { 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)) { 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)) { 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()) { } 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( ParticleUtils.spawnParticle(source.asWorld(), ParticleTypes.SPLASH, new Vec3d(
i.getX() + source.getReferenceWorld().random.nextFloat(), i.getX() + source.asWorld().random.nextFloat(),
i.getY() + 1, i.getY() + 1,
i.getZ() + source.getReferenceWorld().random.nextFloat()), Vec3d.ZERO); i.getZ() + source.asWorld().random.nextFloat()), Vec3d.ZERO);
return true; return true;
} }
@ -67,7 +67,7 @@ public class IceSpell extends AbstractSpell {
source.subtractEnergyCost(Math.min(10, blocksAffected)); 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) { protected boolean applyEntities(LivingEntity owner, World world, Vec3d pos) {

View file

@ -30,7 +30,7 @@ public class InfernoSpell extends FireSpell {
generateParticles(source); generateParticles(source);
} }
World w = source.getReferenceWorld(); World w = source.asWorld();
if (!w.isClient) { if (!w.isClient) {
float radius = 4 + (source.getLevel().getScaled(4) * 4); float radius = 4 + (source.getLevel().getScaled(4) * 4);

View file

@ -56,17 +56,17 @@ public class LightSpell extends AbstractSpell implements TimedSpell {
if (!caster.isClient()) { if (!caster.isClient()) {
if (lights.isEmpty()) { 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) { while (lights.size() < size) {
lights.add(new EntityReference<FairyEntity>()); lights.add(new EntityReference<FairyEntity>());
} }
} }
lights.forEach(ref -> { lights.forEach(ref -> {
if (!ref.isPresent(caster.getReferenceWorld())) { if (!ref.isPresent(caster.asWorld())) {
FairyEntity entity = UEntities.TWITTERMITE.create(caster.getReferenceWorld()); FairyEntity entity = UEntities.TWITTERMITE.create(caster.asWorld());
entity.setPosition(ref.getPosition().orElseGet(() -> { 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.setMaster(caster);
entity.world.spawnEntity(entity); entity.world.spawnEntity(entity);
@ -86,7 +86,7 @@ public class LightSpell extends AbstractSpell implements TimedSpell {
return; return;
} }
lights.forEach(ref -> { lights.forEach(ref -> {
ref.ifPresent(caster.getReferenceWorld(), e -> { ref.ifPresent(caster.asWorld(), e -> {
e.world.sendEntityStatus(e, (byte)60); e.world.sendEntityStatus(e, (byte)60);
e.discard(); e.discard();
}); });

View file

@ -33,7 +33,7 @@ public class MindSwapSpell extends MimicSpell {
public void onDestroyed(Caster<?> caster) { public void onDestroyed(Caster<?> caster) {
super.onDestroyed(caster); super.onDestroyed(caster);
if (initialized && !caster.isClient()) { if (initialized && !caster.isClient()) {
counterpart.ifPresent(caster.getReferenceWorld(), e -> { counterpart.ifPresent(caster.asWorld(), e -> {
EntitySwap.ALL.accept(e, caster.getMaster()); EntitySwap.ALL.accept(e, caster.getMaster());
Inventory.swapInventories( Inventory.swapInventories(
e, myStoredInventory.or(() -> Inventory.of(e)), e, myStoredInventory.or(() -> Inventory.of(e)),
@ -59,7 +59,7 @@ public class MindSwapSpell extends MimicSpell {
if (!initialized) { if (!initialized) {
initialized = true; initialized = true;
setDirty(); setDirty();
counterpart.ifPresent(caster.getReferenceWorld(), e -> { counterpart.ifPresent(caster.asWorld(), e -> {
setDisguise(e); setDisguise(e);
Caster<?> other = Caster.of(e).get(); Caster<?> other = Caster.of(e).get();
SpellType.MIMIC.withTraits().apply(other).setDisguise(caster.getMaster()); 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); caster.getMaster().damage(DamageSource.MAGIC, Float.MAX_VALUE);
setDead(); setDead();
return false; return false;
} }
if (!caster.getEntity().isAlive()) { if (!caster.asEntity().isAlive()) {
counterpart.ifPresent(caster.getReferenceWorld(), e -> { counterpart.ifPresent(caster.asWorld(), e -> {
e.damage(DamageSource.MAGIC, Float.MAX_VALUE); e.damage(DamageSource.MAGIC, Float.MAX_VALUE);
}); });
onDestroyed(caster); onDestroyed(caster);

View file

@ -56,24 +56,24 @@ public class NecromancySpell extends AbstractAreaEffectSpell {
return false; return false;
} }
boolean rainy = source.getReferenceWorld().hasRain(source.getOrigin()); boolean rainy = source.asWorld().hasRain(source.getOrigin());
if (source.isClient()) { if (source.isClient()) {
source.spawnParticles(new Sphere(true, radius * 2), rainy ? 98 : 125, pos -> { source.spawnParticles(new Sphere(true, radius * 2), rainy ? 98 : 125, pos -> {
BlockPos bpos = new BlockPos(pos); BlockPos bpos = new BlockPos(pos);
if (!source.getReferenceWorld().isAir(bpos.down())) { if (!source.asWorld().isAir(bpos.down())) {
source.addParticle(source.getReferenceWorld().hasRain(bpos) ? ParticleTypes.SMOKE : ParticleTypes.FLAME, pos, Vec3d.ZERO); source.addParticle(source.asWorld().hasRain(bpos) ? ParticleTypes.SMOKE : ParticleTypes.FLAME, pos, Vec3d.ZERO);
} }
}); });
return true; return true;
} }
if (source.getReferenceWorld().getDifficulty() == Difficulty.PEACEFUL) { if (source.asWorld().getDifficulty() == Difficulty.PEACEFUL) {
return true; 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) { if (e.getPos().distanceTo(source.getOriginVector()) > radius * 2) {
e.world.sendEntityStatus(e, (byte)60); e.world.sendEntityStatus(e, (byte)60);
e.discard(); e.discard();
@ -82,13 +82,13 @@ public class NecromancySpell extends AbstractAreaEffectSpell {
return true; return true;
}).isEmpty()); }).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(); setDirty();
if (--spawnCountdown > 0 && !summonedEntities.isEmpty()) { if (--spawnCountdown > 0 && !summonedEntities.isEmpty()) {
return true; 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) { if (summonedEntities.size() > 10 + additional) {
return true; return true;
@ -97,11 +97,11 @@ public class NecromancySpell extends AbstractAreaEffectSpell {
Shape affectRegion = new Sphere(false, radius); Shape affectRegion = new Sphere(false, radius);
for (int i = 0; i < 10; i++) { 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); 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 -> { spawnPool.get().ifPresent(type -> {
spawnMonster(source, pos, type); spawnMonster(source, pos, type);
}); });
@ -118,7 +118,7 @@ public class NecromancySpell extends AbstractAreaEffectSpell {
} }
LivingEntity master = caster.getMaster(); LivingEntity master = caster.getMaster();
summonedEntities.forEach(ref -> { summonedEntities.forEach(ref -> {
ref.ifPresent(caster.getReferenceWorld(), e -> { ref.ifPresent(caster.asWorld(), e -> {
if (master != null) { if (master != null) {
master.applyDamageEffects(master, e); master.applyDamageEffects(master, e);
} }
@ -129,14 +129,14 @@ public class NecromancySpell extends AbstractAreaEffectSpell {
} }
protected void spawnMonster(Caster<?> source, Vec3d pos, EntityType<? extends LivingEntity> type) { protected void spawnMonster(Caster<?> source, Vec3d pos, EntityType<? extends LivingEntity> type) {
LivingEntity minion = type.create(source.getReferenceWorld()); LivingEntity minion = type.create(source.asWorld());
source.subtractEnergyCost(3); source.subtractEnergyCost(3);
minion.updatePositionAndAngles(pos.x, pos.y, pos.z, 0, 0); minion.updatePositionAndAngles(pos.x, pos.y, pos.z, 0, 0);
minion.setVelocity(0, 0.3, 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.playSound(SoundEvents.BLOCK_BELL_USE, 1, 0.3F);
source.spawnParticles(ParticleTypes.LARGE_SMOKE, 10); source.spawnParticles(ParticleTypes.LARGE_SMOKE, 10);
minion.equipStack(EquipmentSlot.HEAD, Items.IRON_HELMET.getDefaultStack()); minion.equipStack(EquipmentSlot.HEAD, Items.IRON_HELMET.getDefaultStack());
@ -145,7 +145,7 @@ public class NecromancySpell extends AbstractAreaEffectSpell {
((Creature)eq).setMaster(source); ((Creature)eq).setMaster(source);
}); });
source.getReferenceWorld().spawnEntity(minion); source.asWorld().spawnEntity(minion);
summonedEntities.add(new EntityReference<>(minion)); summonedEntities.add(new EntityReference<>(minion));
setDirty(); setDirty();
} }

View file

@ -51,7 +51,7 @@ public class PortalSpell extends AbstractSpell implements PlaceableSpell.Placeme
@Override @Override
public boolean apply(Caster<?> caster) { public boolean apply(Caster<?> caster) {
setOrientation(caster.getEntity().getPitch(), caster.getEntity().getYaw()); setOrientation(caster.asEntity().getPitch(), caster.asEntity().getYaw());
return toPlaceable().apply(caster); return toPlaceable().apply(caster);
} }
@ -82,11 +82,11 @@ public class PortalSpell extends AbstractSpell implements PlaceableSpell.Placeme
}); });
} else { } else {
teleportationTarget.getId().ifPresent(id -> { 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); Unicopia.LOGGER.debug("Lost sibling, breaking connection to " + id);
teleportationTarget.set(null); teleportationTarget.set(null);
setDirty(); 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) { if (!publishedPosition) {
publishedPosition = true; 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.pitch = pitch;
entry.yaw = yaw; entry.yaw = yaw;
} }
@ -140,10 +140,10 @@ public class PortalSpell extends AbstractSpell implements PlaceableSpell.Placeme
return; return;
} }
Ether ether = Ether.get(source.getReferenceWorld()); Ether ether = Ether.get(source.asWorld());
ether.getEntries(getType()) ether.getEntries(getType())
.stream() .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() .findAny()
.ifPresent(entry -> { .ifPresent(entry -> {
entry.setTaken(true); entry.setTaken(true);
@ -153,7 +153,7 @@ public class PortalSpell extends AbstractSpell implements PlaceableSpell.Placeme
} }
private Optional<Ether.Entry> getTarget(Caster<?> source) { private Optional<Ether.Entry> 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 @Override
@ -185,8 +185,8 @@ public class PortalSpell extends AbstractSpell implements PlaceableSpell.Placeme
@Override @Override
public void onDestroyed(Caster<?> caster) { public void onDestroyed(Caster<?> caster) {
Ether ether = Ether.get(caster.getReferenceWorld()); Ether ether = Ether.get(caster.asWorld());
ether.remove(getType(), caster.getEntity().getUuid()); ether.remove(getType(), caster.asEntity().getUuid());
getTarget(caster).ifPresent(e -> e.setTaken(false)); getTarget(caster).ifPresent(e -> e.setTaken(false));
} }

View file

@ -31,9 +31,9 @@ public class ScorchSpell extends FireSpell implements ProjectileDelegate.Configu
@Override @Override
public boolean tick(Caster<?> source, Situation situation) { 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.spawnParticles(new Sphere(false, Math.max(1, getTraits().get(Trait.POWER))), 5, p -> {
source.addParticle(ParticleTypes.SMOKE, PosHelper.offset(p, pos), Vec3d.ZERO); source.addParticle(ParticleTypes.SMOKE, PosHelper.offset(p, pos), Vec3d.ZERO);
}); });

View file

@ -55,7 +55,7 @@ public class SiphoningSpell extends AbstractAreaEffectSpell {
int direction = isFriendlyTogether(source) ? 1 : -1; int direction = isFriendlyTogether(source) ? 1 : -1;
source.spawnParticles(new Sphere(true, radius, 1, 0, 1), 1, pos -> { 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()); double dist = pos.distanceTo(source.getOriginVector());
Vec3d velocity = pos.subtract(source.getOriginVector()).normalize().multiply(direction * dist); Vec3d velocity = pos.subtract(source.getOriginVector()).normalize().multiply(direction * dist);
@ -64,7 +64,7 @@ public class SiphoningSpell extends AbstractAreaEffectSpell {
} }
}); });
} else { } else {
if (source.getReferenceWorld().getTime() % 10 != 0) { if (source.asWorld().getTime() % 10 != 0) {
return true; return true;
} }
@ -78,7 +78,7 @@ public class SiphoningSpell extends AbstractAreaEffectSpell {
} }
private Stream<LivingEntity> getTargets(Caster<?> source) { private Stream<LivingEntity> 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() .stream()
.map(e -> (LivingEntity)e); .map(e -> (LivingEntity)e);
} }
@ -92,7 +92,7 @@ public class SiphoningSpell extends AbstractAreaEffectSpell {
source.subtractEnergyCost(0.2F); source.subtractEnergyCost(0.2F);
if (ticksUpset > 0 || maxHealthGain <= 0) { if (ticksUpset > 0 || maxHealthGain <= 0) {
if (source.getReferenceWorld().random.nextInt(3000) == 0) { if (source.asWorld().random.nextInt(3000) == 0) {
setDead(); setDead();
} else { } else {
e.damage(damage, e.getHealth() / 4); e.damage(damage, e.getHealth() / 4);

View file

@ -75,7 +75,7 @@ public class TraitDiscovery implements NbtSerialisable {
}); });
unreadTraits.addAll(newTraits); unreadTraits.addAll(newTraits);
pony.setDirty(); pony.setDirty();
if (!newTraits.isEmpty() && !pony.getReferenceWorld().isClient) { if (!newTraits.isEmpty() && !pony.asWorld().isClient) {
Channel.UNLOCK_TRAITS.send((ServerPlayerEntity)pony.asEntity(), new MsgUnlockTraits(newTraits)); Channel.UNLOCK_TRAITS.send((ServerPlayerEntity)pony.asEntity(), new MsgUnlockTraits(newTraits));
} }
} }

View file

@ -87,7 +87,7 @@ public class Ether extends PersistentState implements CasterView {
} }
public void remove(SpellType<?> spellType, Caster<?> caster) { public void remove(SpellType<?> spellType, Caster<?> caster) {
remove(spellType, caster.getEntity().getUuid()); remove(spellType, caster.asEntity().getUuid());
} }
public Set<Entry> getEntries(SpellType<?> spellType) { public Set<Entry> getEntries(SpellType<?> spellType) {
@ -109,7 +109,7 @@ public class Ether extends PersistentState implements CasterView {
public Optional<Entry> getEntry(SpellType<?> spellType, Caster<?> caster) { public Optional<Entry> getEntry(SpellType<?> spellType, Caster<?> caster) {
synchronized (locker) { 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) { public Entry(Caster<?> caster) {
entity = new EntityReference<>(caster.getEntity()); entity = new EntityReference<>(caster.asEntity());
} }
boolean isAlive() { boolean isAlive() {

View file

@ -166,7 +166,7 @@ public class RunesParticle extends OrientedBillboardParticle implements Attachme
public void tick() { public void tick() {
super.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 (getAlphaScale() >= 0.9F) {
if (stasisAge < 0) { if (stasisAge < 0) {
stasisAge = age; stasisAge = age;

View file

@ -101,7 +101,7 @@ public class SphereParticle extends Particle implements Attachment {
super.tick(); super.tick();
if (link.isPresent()) { 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(); Vec3d offset = parameters.getOffset();
setPos(e.getX() + offset.getX(), e.getY() + offset.getY(), e.getZ() + offset.getZ()); setPos(e.getX() + offset.getX(), e.getY() + offset.getY(), e.getZ() + offset.getZ());

View file

@ -23,7 +23,7 @@ import net.minecraft.network.listener.ClientPlayPacketListener;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.world.World; import net.minecraft.world.World;
public class CastSpellEntity extends LightEmittingEntity implements Caster<LivingEntity>, WeaklyOwned<LivingEntity> { public class CastSpellEntity extends LightEmittingEntity implements Caster<CastSpellEntity>, WeaklyOwned<LivingEntity> {
private static final TrackedData<Float> GRAVITY = DataTracker.registerData(CastSpellEntity.class, TrackedDataHandlerRegistry.FLOAT); private static final TrackedData<Float> GRAVITY = DataTracker.registerData(CastSpellEntity.class, TrackedDataHandlerRegistry.FLOAT);
private static final TrackedData<NbtCompound> EFFECT = DataTracker.registerData(CastSpellEntity.class, TrackedDataHandlerRegistry.NBT_COMPOUND); private static final TrackedData<NbtCompound> EFFECT = DataTracker.registerData(CastSpellEntity.class, TrackedDataHandlerRegistry.NBT_COMPOUND);
@ -78,12 +78,7 @@ public class CastSpellEntity extends LightEmittingEntity implements Caster<Livin
} }
@Override @Override
public World getReferenceWorld() { public CastSpellEntity asEntity() {
return WeaklyOwned.super.getReferenceWorld();
}
@Override
public Entity getEntity() {
return this; return this;
} }

View file

@ -76,8 +76,8 @@ public class Creature extends Living<LivingEntity> implements WeaklyOwned<Living
} }
@Override @Override
public World getReferenceWorld() { public World asWorld() {
return super.getReferenceWorld(); return super.asWorld();
} }
@Override @Override
@ -85,7 +85,7 @@ public class Creature extends Living<LivingEntity> implements WeaklyOwned<Living
public LivingEntity getMaster() { public LivingEntity getMaster() {
NbtCompound data = entity.getDataTracker().get(MASTER); NbtCompound data = entity.getDataTracker().get(MASTER);
owner.fromNBT(data); owner.fromNBT(data);
return owner.getOrEmpty(getReferenceWorld()).orElse(entity); return owner.getOrEmpty(asWorld()).orElse(entity);
} }
@Override @Override
@ -116,7 +116,7 @@ public class Creature extends Living<LivingEntity> implements WeaklyOwned<Living
goals.add(3, eatMuffinGoal); goals.add(3, eatMuffinGoal);
} }
if (owner.isPresent(getReferenceWorld())) { if (owner.isPresent(asWorld())) {
initMinionAi(); initMinionAi();
} }
@ -241,7 +241,7 @@ public class Creature extends Living<LivingEntity> implements WeaklyOwned<Living
} }
if (compound.contains("master", NbtElement.COMPOUND_TYPE)) { if (compound.contains("master", NbtElement.COMPOUND_TYPE)) {
owner.fromNBT(compound.getCompound("master")); owner.fromNBT(compound.getCompound("master"));
if (owner.isPresent(getReferenceWorld()) && targets != null) { if (owner.isPresent(asWorld()) && targets != null) {
initMinionAi(); initMinionAi();
} }
} }

View file

@ -104,6 +104,11 @@ public class FairyEntity extends PathAwareEntity implements DynamicLightSource,
return owner; return owner;
} }
@Override
public World asWorld() {
return world;
}
@Override @Override
public boolean handleFallDamage(float fallDistance, float damageMultiplier, DamageSource damageSource) { public boolean handleFallDamage(float fallDistance, float damageMultiplier, DamageSource damageSource) {
return false; return false;

View file

@ -75,7 +75,7 @@ public class ItemTracker implements NbtSerialisable, Copyable<ItemTracker> {
if (!(living instanceof Pony)) { if (!(living instanceof Pony)) {
foundStacks.forEach(stack -> { foundStacks.forEach(stack -> {
if (getTicks((Trackable)stack.getItem()) == 1) { if (getTicks((Trackable)stack.getItem()) == 1) {
stack.inventoryTick(living.getReferenceWorld(), living.asEntity(), 0, false); stack.inventoryTick(living.asWorld(), living.asEntity(), 0, false);
} }
}); });
} }

View file

@ -98,15 +98,6 @@ public abstract class Living<T extends LivingEntity> implements Equine<T>, Caste
return armour; return armour;
} }
/**
* @deprecated use asEntity()
*/
@Deprecated(forRemoval = true)
@Override
public final Entity getEntity() {
return asEntity();
}
@Override @Override
public final T asEntity() { public final T asEntity() {
return entity; return entity;

View file

@ -2,20 +2,20 @@ package com.minelittlepony.unicopia.entity.behaviour;
import org.joml.Vector3f; import org.joml.Vector3f;
import com.minelittlepony.unicopia.ability.magic.Caster; import com.minelittlepony.unicopia.entity.Living;
import net.minecraft.entity.passive.AxolotlEntity; import net.minecraft.entity.passive.AxolotlEntity;
public class AxolotlBehaviour extends EntityBehaviour<AxolotlEntity> { public class AxolotlBehaviour extends EntityBehaviour<AxolotlEntity> {
private static final float toRad = 0.017453292F; private static final float toRad = 0.017453292F;
@Override @Override
public void update(Caster<?> source, AxolotlEntity entity, Disguise spell) { public void update(Living<?> source, AxolotlEntity entity, Disguise spell) {
if (entity.getModelAngles().isEmpty()) { if (entity.getModelAngles().isEmpty()) {
return; return;
} }
Vector3f current = entity.getModelAngles().get("body"); Vector3f current = entity.getModelAngles().get("body");
entity.getModelAngles().put("body", new Vector3f( entity.getModelAngles().put("body", new Vector3f(
source.getEntity().isSubmergedInWater() ? source.getEntity().getPitch() * toRad : 0, source.asEntity().isSubmergedInWater() ? source.asEntity().getPitch() * toRad : 0,
0, 0,
current == null ? 0 : current.z current == null ? 0 : current.z
)); ));

View file

@ -1,7 +1,7 @@
package com.minelittlepony.unicopia.entity.behaviour; package com.minelittlepony.unicopia.entity.behaviour;
import com.minelittlepony.unicopia.InteractionManager; import com.minelittlepony.unicopia.InteractionManager;
import com.minelittlepony.unicopia.ability.magic.Caster; import com.minelittlepony.unicopia.entity.Living;
import net.minecraft.entity.passive.BeeEntity; import net.minecraft.entity.passive.BeeEntity;
@ -16,8 +16,8 @@ public class BeeBehaviour extends EntityBehaviour<BeeEntity> {
} }
@Override @Override
public void update(Caster<?> source, BeeEntity entity, Disguise spell) { public void update(Living<?> source, BeeEntity entity, Disguise spell) {
if (source.getMaster().isSneaking()) { if (source.asEntity().isSneaking()) {
entity.setAngerTime(10); entity.setAngerTime(10);
} else { } else {
entity.setAngerTime(0); entity.setAngerTime(0);

View file

@ -1,6 +1,6 @@
package com.minelittlepony.unicopia.entity.behaviour; 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.entity.player.Pony;
import com.minelittlepony.unicopia.mixin.MixinBlazeEntity; import com.minelittlepony.unicopia.mixin.MixinBlazeEntity;
@ -14,10 +14,10 @@ import net.minecraft.world.WorldEvents;
public class BlazeBehaviour extends EntityBehaviour<BlazeEntity> { public class BlazeBehaviour extends EntityBehaviour<BlazeEntity> {
@Override @Override
public void update(Caster<?> source, BlazeEntity entity, Disguise spell) { public void update(Living<?> source, BlazeEntity entity, Disguise spell) {
super.update(source, entity, spell); super.update(source, entity, spell);
Entity src = source.getEntity(); Entity src = source.asEntity();
if (src.isOnGround() || src instanceof PlayerEntity player && player.getAbilities().flying) { if (src.isOnGround() || src instanceof PlayerEntity player && player.getAbilities().flying) {
return; return;

View file

@ -1,6 +1,6 @@
package com.minelittlepony.unicopia.entity.behaviour; 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.entity.player.Pony;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
@ -20,7 +20,7 @@ public class ChickenBehaviour extends EntityBehaviour<ChickenEntity> {
} }
@Override @Override
public void update(Caster<?> source, ChickenEntity entity, Disguise spell) { public void update(Living<?> source, ChickenEntity entity, Disguise spell) {
entity.eggLayTime = Integer.MAX_VALUE; entity.eggLayTime = Integer.MAX_VALUE;
if (source instanceof Pony player) { if (source instanceof Pony player) {
@ -48,7 +48,7 @@ public class ChickenBehaviour extends EntityBehaviour<ChickenEntity> {
} }
} }
Entity src = source.getEntity(); Entity src = source.asEntity();
if (src.isOnGround() || src instanceof PlayerEntity player && player.getAbilities().flying) { if (src.isOnGround() || src instanceof PlayerEntity player && player.getAbilities().flying) {
return; return;

View file

@ -1,13 +1,13 @@
package com.minelittlepony.unicopia.entity.behaviour; 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.entity.mob.CreeperEntity;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.MathHelper;
public class CreeperBehaviour extends EntityBehaviour<CreeperEntity> { public class CreeperBehaviour extends EntityBehaviour<CreeperEntity> {
@Override @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"); int fuseCountDown = spell.getDisguise().getOrCreateTag().getInt("fuseCountdown");
boolean trigger = isSneakingOnGround(source); boolean trigger = isSneakingOnGround(source);

View file

@ -7,6 +7,7 @@ import org.jetbrains.annotations.Nullable;
import com.minelittlepony.unicopia.FlightType; import com.minelittlepony.unicopia.FlightType;
import com.minelittlepony.unicopia.Owned; import com.minelittlepony.unicopia.Owned;
import com.minelittlepony.unicopia.ability.magic.Caster; 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.duck.LivingEntityDuck;
import com.minelittlepony.unicopia.entity.player.PlayerDimensions; import com.minelittlepony.unicopia.entity.player.PlayerDimensions;
import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.entity.player.Pony;
@ -56,9 +57,14 @@ public interface Disguise extends FlightType.Provider, PlayerDimensions.Provider
} }
@SuppressWarnings("unchecked") @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) { if (owner == null) {
return true; return true;

View file

@ -1,6 +1,6 @@
package com.minelittlepony.unicopia.entity.behaviour; 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.entity.mob.EndermanEntity;
import net.minecraft.item.BlockItem; import net.minecraft.item.BlockItem;
@ -9,8 +9,8 @@ import net.minecraft.util.Hand;
public class EndermanBehaviour extends EntityBehaviour<EndermanEntity> { public class EndermanBehaviour extends EntityBehaviour<EndermanEntity> {
@Override @Override
public void update(Caster<?> source, EndermanEntity entity, Disguise spell) { public void update(Living<?> source, EndermanEntity entity, Disguise spell) {
if (source.getMaster().isSneaking() || source.getMaster().isSprinting()) { if (source.asEntity().isSneaking() || source.asEntity().isSprinting()) {
entity.setTarget(entity); entity.setTarget(entity);
} else { } else {
entity.setTarget(null); entity.setTarget(null);

View file

@ -133,7 +133,7 @@ public class EntityAppearance implements NbtSerialisable, PlayerDimensions.Provi
private synchronized void createPlayer(NbtCompound nbt, GameProfile profile, Caster<?> source) { private synchronized void createPlayer(NbtCompound nbt, GameProfile profile, Caster<?> source) {
remove(); remove();
entity = InteractionManager.instance().createPlayer(source.getEntity(), profile); entity = InteractionManager.instance().createPlayer(source.asEntity(), profile);
entity.setCustomName(source.getMaster().getName()); entity.setCustomName(source.getMaster().getName());
((PlayerEntity)entity).readNbt(nbt.getCompound("playerNbt")); ((PlayerEntity)entity).readNbt(nbt.getCompound("playerNbt"));
if (nbt.contains("playerVisibleParts", NbtElement.BYTE_TYPE)) { if (nbt.contains("playerVisibleParts", NbtElement.BYTE_TYPE)) {
@ -164,7 +164,7 @@ public class EntityAppearance implements NbtSerialisable, PlayerDimensions.Provi
), p -> createPlayer(nbt, p, source)); ), p -> createPlayer(nbt, p, source));
} else { } else {
if (source.isClient()) { 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) { if (entity != null) {
try { try {
entity.readNbt(nbt); entity.readNbt(nbt);
@ -174,7 +174,7 @@ public class EntityAppearance implements NbtSerialisable, PlayerDimensions.Provi
entity = EntityBehaviour.forEntity(entity).onCreate(entity, this, true); entity = EntityBehaviour.forEntity(entity).onCreate(entity, this, true);
} }
} else { } else {
entity = EntityType.loadEntityWithPassengers(nbt, source.getReferenceWorld(), e -> { entity = EntityType.loadEntityWithPassengers(nbt, source.asWorld(), e -> {
return EntityBehaviour.forEntity(e).onCreate(e, this, true); return EntityBehaviour.forEntity(e).onCreate(e, this, true);
}); });
} }
@ -191,7 +191,7 @@ public class EntityAppearance implements NbtSerialisable, PlayerDimensions.Provi
} }
private void onEntityLoaded(Caster<?> source) { private void onEntityLoaded(Caster<?> source) {
source.getEntity().calculateDimensions(); source.asEntity().calculateDimensions();
if (entity == null) { if (entity == null) {
return; return;
@ -202,7 +202,7 @@ public class EntityAppearance implements NbtSerialisable, PlayerDimensions.Provi
} }
if (source.isClient()) { if (source.isClient()) {
source.getReferenceWorld().spawnEntity(entity); source.asWorld().spawnEntity(entity);
} }
} }

View file

@ -8,6 +8,7 @@ import org.jetbrains.annotations.Nullable;
import com.minelittlepony.unicopia.Unicopia; import com.minelittlepony.unicopia.Unicopia;
import com.minelittlepony.unicopia.ability.magic.Caster; import com.minelittlepony.unicopia.ability.magic.Caster;
import com.minelittlepony.unicopia.entity.duck.LivingEntityDuck; 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.duck.EntityDuck;
import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.entity.player.Pony;
import com.minelittlepony.unicopia.util.RegistryUtils; import com.minelittlepony.unicopia.util.RegistryUtils;
@ -45,7 +46,7 @@ public class EntityBehaviour<T extends Entity> {
* <br> * <br>
* We use this to add entity-specific behaviours. * 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) { if (source instanceof Pony) {
update((Pony)source, entity, spell); update((Pony)source, entity, spell);
} }
@ -249,7 +250,7 @@ public class EntityBehaviour<T extends Entity> {
} }
protected boolean isSneakingOnGround(Caster<?> source) { 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)); return e.isSneaking() && (e.isOnGround() && !(e instanceof PlayerEntity player && player.getAbilities().flying));
} }

View file

@ -4,6 +4,7 @@ import java.util.List;
import java.util.Optional; import java.util.Optional;
import com.minelittlepony.unicopia.ability.magic.Caster; import com.minelittlepony.unicopia.ability.magic.Caster;
import com.minelittlepony.unicopia.entity.Living;
import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.entity.player.Pony;
import com.minelittlepony.unicopia.mixin.MixinFallingBlock; import com.minelittlepony.unicopia.mixin.MixinFallingBlock;
import com.minelittlepony.unicopia.mixin.MixinFallingBlockEntity; import com.minelittlepony.unicopia.mixin.MixinFallingBlockEntity;
@ -41,8 +42,8 @@ public class FallingBlockBehaviour extends EntityBehaviour<FallingBlockEntity> {
@Override @Override
public void onImpact(Caster<?> source, FallingBlockEntity entity, float distance, float damageMultiplier, DamageSource cause) { public void onImpact(Caster<?> source, FallingBlockEntity entity, float distance, float damageMultiplier, DamageSource cause) {
if (source.getEntity().fallDistance > 3) { if (source.asEntity().fallDistance > 3) {
entity.fallDistance = source.getEntity().fallDistance; entity.fallDistance = source.asEntity().fallDistance;
entity.handleFallDamage(distance, damageMultiplier, cause); entity.handleFallDamage(distance, damageMultiplier, cause);
BlockState state = entity.getBlockState(); BlockState state = entity.getBlockState();
@ -85,7 +86,7 @@ public class FallingBlockBehaviour extends EntityBehaviour<FallingBlockEntity> {
} }
@Override @Override
public void update(Caster<?> source, FallingBlockEntity entity, Disguise spell) { public void update(Living<?> source, FallingBlockEntity entity, Disguise spell) {
BlockState state = entity.getBlockState(); BlockState state = entity.getBlockState();
if (state.contains(Properties.WATERLOGGED)) { if (state.contains(Properties.WATERLOGGED)) {
@ -101,7 +102,7 @@ public class FallingBlockBehaviour extends EntityBehaviour<FallingBlockEntity> {
EntityAppearance disguise = spell.getDisguise(); EntityAppearance disguise = spell.getDisguise();
List<Entity> attachments = disguise.getAttachments(); List<Entity> attachments = disguise.getAttachments();
if (attachments.size() > 0) { if (attachments.size() > 0) {
copyBaseAttributes(source.getMaster(), attachments.get(0), UP); copyBaseAttributes(source.asEntity(), attachments.get(0), UP);
} }
BlockEntity be = disguise.getBlockEntity(); BlockEntity be = disguise.getBlockEntity();

View file

@ -1,7 +1,7 @@
package com.minelittlepony.unicopia.entity.behaviour; package com.minelittlepony.unicopia.entity.behaviour;
import com.minelittlepony.unicopia.InteractionManager; 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.LivingEntity;
import net.minecraft.entity.vehicle.AbstractMinecartEntity; import net.minecraft.entity.vehicle.AbstractMinecartEntity;
@ -18,19 +18,18 @@ public class MinecartBehaviour extends EntityBehaviour<AbstractMinecartEntity> {
} }
@Override @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.setYaw(entity.getYaw() - 90);
entity.prevYaw -= 90; entity.prevYaw -= 90;
entity.setPitch(0); entity.setPitch(0);
entity.prevPitch = 0; entity.prevPitch = 0;
if (source.getEntity() instanceof LivingEntity living) { LivingEntity living = source.asEntity();
if (living.hurtTime > 0) { if (living.hurtTime > 0) {
entity.setDamageWobbleTicks(living.hurtTime); entity.setDamageWobbleTicks(living.hurtTime);
entity.setDamageWobbleStrength(1); entity.setDamageWobbleStrength(1);
entity.setDamageWobbleSide(20 + (int)source.getEntity().fallDistance / 10); entity.setDamageWobbleSide(20 + (int)source.asEntity().fallDistance / 10);
}
} }
} }
} }

View file

@ -1,6 +1,6 @@
package com.minelittlepony.unicopia.entity.behaviour; 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.duck.*;
import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.entity.player.Pony;
@ -8,7 +8,7 @@ import net.minecraft.entity.player.PlayerEntity;
public class PlayerBehaviour extends EntityBehaviour<PlayerEntity> { public class PlayerBehaviour extends EntityBehaviour<PlayerEntity> {
@Override @Override
public void update(Caster<?> source, PlayerEntity entity, Disguise spell) { public void update(Living<?> source, PlayerEntity entity, Disguise spell) {
if (source instanceof Pony pony) { if (source instanceof Pony pony) {
PlayerEntity pFrom = pony.asEntity(); PlayerEntity pFrom = pony.asEntity();
@ -22,14 +22,15 @@ public class PlayerBehaviour extends EntityBehaviour<PlayerEntity> {
((PlayerEntityDuck)entity).callUpdateCapeAngles(); ((PlayerEntityDuck)entity).callUpdateCapeAngles();
} }
if (source.getEntity().getPose() != entity.getPose()) { if (source.asEntity().getPose() != entity.getPose()) {
entity.setPose(source.getEntity().getPose()); entity.setPose(source.asEntity().getPose());
} }
if (source.getEntity().isSwimming() != entity.isSwimming()) { if (source.asEntity().isSwimming() != entity.isSwimming()) {
entity.setSwimming(source.getEntity().isSwimming()); entity.setSwimming(source.asEntity().isSwimming());
} }
if (source.getEntity() instanceof LivingEntityDuck duck) { if (source.asEntity() instanceof LivingEntityDuck duck) {
duck.copyLeaningAnglesFrom(((LivingEntityDuck)source.getEntity())); // TODO: CopyAngles
duck.copyLeaningAnglesFrom(((LivingEntityDuck)entity));
} }
} }
} }

View file

@ -1,6 +1,6 @@
package com.minelittlepony.unicopia.entity.behaviour; 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.entity.player.Pony;
import com.minelittlepony.unicopia.mixin.MixinShulkerEntity; import com.minelittlepony.unicopia.mixin.MixinShulkerEntity;
@ -14,7 +14,7 @@ import net.minecraft.util.math.Vec3d;
public class ShulkerBehaviour extends EntityBehaviour<ShulkerEntity> { public class ShulkerBehaviour extends EntityBehaviour<ShulkerEntity> {
@Override @Override
public void update(Caster<?> source, ShulkerEntity shulker, Disguise spell) { public void update(Living<?> source, ShulkerEntity shulker, Disguise spell) {
shulker.setYaw(0); shulker.setYaw(0);
shulker.prevBodyYaw = 0; shulker.prevBodyYaw = 0;
shulker.bodyYaw = 0; shulker.bodyYaw = 0;
@ -27,11 +27,11 @@ public class ShulkerBehaviour extends EntityBehaviour<ShulkerEntity> {
boolean noGravity = !shulker.isOnGround() && !shulker.world.isAir(pos) boolean noGravity = !shulker.isOnGround() && !shulker.world.isAir(pos)
&& (attachmentFace == Direction.UP || attachmentFace.getAxis() != Axis.Y); && (attachmentFace == Direction.UP || attachmentFace.getAxis() != Axis.Y);
source.getEntity().setNoGravity(noGravity); source.asEntity().setNoGravity(noGravity);
if (noGravity && source.getEntity().isSneaking()) { if (noGravity && source.asEntity().isSneaking()) {
Vec3d vel = source.getEntity().getVelocity(); Vec3d vel = source.asEntity().getVelocity();
if (vel.y > 0) { if (vel.y > 0) {
source.getEntity().setVelocity(vel.multiply(1, 0.8, 1)); source.asEntity().setVelocity(vel.multiply(1, 0.8, 1));
} }
} }
} }

View file

@ -1,22 +1,22 @@
package com.minelittlepony.unicopia.entity.behaviour; 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.damage.DamageSource;
import net.minecraft.entity.mob.WaterCreatureEntity; import net.minecraft.entity.mob.WaterCreatureEntity;
public class WaterCreatureBehaviour extends EntityBehaviour<WaterCreatureEntity> { public class WaterCreatureBehaviour extends EntityBehaviour<WaterCreatureEntity> {
@Override @Override
public void update(Caster<?> source, WaterCreatureEntity entity, Disguise spell) { public void update(Living<?> source, WaterCreatureEntity entity, Disguise spell) {
if (source.getEntity().isInsideWaterOrBubbleColumn()) { if (source.asEntity().isInsideWaterOrBubbleColumn()) {
source.getEntity().setAir(source.getEntity().getAir() - 1); source.asEntity().setAir(source.asEntity().getAir() - 1);
if (source.getEntity().getAir() == -20) { if (source.asEntity().getAir() == -20) {
source.getEntity().setAir(0); source.asEntity().setAir(0);
source.getEntity().damage(DamageSource.DRYOUT, 2); source.asEntity().damage(DamageSource.DRYOUT, 2);
} }
} else { } else {
source.getEntity().setAir(300); source.asEntity().setAir(300);
} }
} }

View file

@ -68,7 +68,7 @@ public class PlayerCamera extends MotionCompositor {
return 0; 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) { if (Math.abs(energyAddition) <= 0.001) {
return 0; return 0;

View file

@ -30,7 +30,7 @@ class PlayerLevelStore implements Levelled.LevelStore {
if (upgradeMana) { if (upgradeMana) {
pony.getMagicalReserves().getMana().add(pony.getMagicalReserves().getMana().getMax() / 2); 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); Levelled.LevelStore.super.add(levels);
} }

View file

@ -136,7 +136,7 @@ public class Pony extends Living<PlayerEntity> implements Copyable<Pony>, Update
this.animationMaxDuration = animationDuration; this.animationMaxDuration = animationDuration;
if (!isClient()) { 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 -> { animation.getSound().ifPresent(sound -> {
@ -369,14 +369,14 @@ public class Pony extends Living<PlayerEntity> implements Copyable<Pony>, Update
} }
public boolean canHangAt(BlockPos pos) { public boolean canHangAt(BlockPos pos) {
if (!getReferenceWorld().isAir(pos) || !getReferenceWorld().isAir(pos.down())) { if (!asWorld().isAir(pos) || !asWorld().isAir(pos.down())) {
return false; return false;
} }
pos = pos.up(); 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 @Override

View file

@ -122,7 +122,7 @@ public class AlicornAmuletItem extends AmuletItem implements ItemTracker.Trackab
float attachedTime = timeWorn / 100F; float attachedTime = timeWorn / 100F;
LocalDifficulty difficulty = wearer.getReferenceWorld().getLocalDifficulty(wearer.getOrigin()); LocalDifficulty difficulty = wearer.asWorld().getLocalDifficulty(wearer.getOrigin());
float amount = attachedTime * (1 + difficulty.getClampedLocalDifficulty()); float amount = attachedTime * (1 + difficulty.getClampedLocalDifficulty());
amount = Math.min(amount, wearer.getMaster().getMaxHealth()); amount = Math.min(amount, wearer.getMaster().getMaxHealth());

View file

@ -101,7 +101,7 @@ public class ZapAppleItem extends Item implements ChameleonItem, ToxicHolder, Mu
@Override @Override
public List<ItemStack> getDefaultStacks() { public List<ItemStack> getDefaultStacks() {
return Unicopia.SIDE.getPony().map(Pony::getReferenceWorld) return Unicopia.SIDE.getPony().map(Pony::asWorld)
.stream() .stream()
.flatMap(world -> RegistryUtils.valuesForTag(world, UTags.APPLES)) .flatMap(world -> RegistryUtils.valuesForTag(world, UTags.APPLES))
.filter(a -> a != this).map(item -> { .filter(a -> a != this).map(item -> {

View file

@ -23,7 +23,7 @@ public class GemFindingEnchantment extends SimpleEnchantment {
BlockPos origin = user.getOrigin(); 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(p -> user.getOriginVector().squaredDistanceTo(p.getX(), p.getY(), p.getZ()))
.map(find -> (1 - (Math.sqrt(find) / radius))) .map(find -> (1 - (Math.sqrt(find) / radius)))
.orElse(-1D); .orElse(-1D);
@ -37,7 +37,7 @@ public class GemFindingEnchantment extends SimpleEnchantment {
@Override @Override
public void onEquipped(Living<?> user) { public void onEquipped(Living<?> user) {
if (user.isClient()) { 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()));
} }
} }

View file

@ -36,19 +36,19 @@ public class PoisonedJokeEnchantment extends SimpleEnchantment implements Identi
@Override @Override
public void onUserTick(Living<?> user, int level) { public void onUserTick(Living<?> user, int level) {
if (sounds.isEmpty() || user.getReferenceWorld().isClient) { if (sounds.isEmpty() || user.asWorld().isClient) {
return; return;
} }
int light = user.getReferenceWorld().getLightLevel(user.asEntity().getRootVehicle().getBlockPos()); int light = user.asWorld().getLightLevel(user.asEntity().getRootVehicle().getBlockPos());
Random rng = user.getReferenceWorld().random; Random rng = user.asWorld().random;
Data data = user.getEnchants().computeIfAbsent(this, Data::new); Data data = user.getEnchants().computeIfAbsent(this, Data::new);
data.level -= rng.nextFloat() * 0.8F; data.level -= rng.nextFloat() * 0.8F;
if (rng.nextInt(Math.max(1, (light * 9) + (int)data.level)) == 0) { if (rng.nextInt(Math.max(1, (light * 9) + (int)data.level)) == 0) {
data.level = rng.nextInt(5000); data.level = rng.nextInt(5000);
user.getReferenceWorld().playSoundFromEntity( user.asWorld().playSoundFromEntity(
null, null,
user.asEntity(), user.asEntity(),
sounds.get(rng.nextInt(sounds.size())), SoundCategory.HOSTILE, sounds.get(rng.nextInt(sounds.size())), SoundCategory.HOSTILE,

View file

@ -16,7 +16,7 @@ public class WantItNeedItEnchantment extends SimpleEnchantment {
@Override @Override
public void onUserTick(Living<?> user, int level) { 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); ParticleUtils.spawnParticles(new FollowingParticleEffect(UParticles.HEALTH_DRAIN, user.asEntity(), 0.2F), user.asEntity(), 1);
} }
} }

View file

@ -43,7 +43,7 @@ public class MsgRequestSpeciesChange implements Packet<ServerPlayerEntity> {
public void handle(ServerPlayerEntity sender) { public void handle(ServerPlayerEntity sender) {
Pony player = Pony.of(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())) { if (force || player.getActualSpecies().isDefault() || (player.getActualSpecies() == worldDefaultRace && !player.isSpeciesPersisted())) {
player.setSpecies(newRace.isPermitted(sender) ? newRace : worldDefaultRace); player.setSpecies(newRace.isPermitted(sender) ? newRace : worldDefaultRace);

View file

@ -113,8 +113,8 @@ public class EffectSync implements SpellContainer, NbtSerialisable {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private <T extends Spell> Stream<T> read(@Nullable SpellPredicate<T> type, boolean synchronize, boolean sendUpdate) { private <T extends Spell> Stream<T> read(@Nullable SpellPredicate<T> type, boolean synchronize, boolean sendUpdate) {
if (synchronize && spells.fromNbt(owner.getEntity().getDataTracker().get(param)) && sendUpdate) { if (synchronize && spells.fromNbt(owner.asEntity().getDataTracker().get(param)) && sendUpdate) {
owner.getEntity().getDataTracker().set(param, spells.toNbt()); owner.asEntity().getDataTracker().set(param, spells.toNbt());
} }
if (type == null) { if (type == null) {
@ -135,7 +135,7 @@ public class EffectSync implements SpellContainer, NbtSerialisable {
private void write() { private void write() {
if (spells.isDirty()) { if (spells.isDirty()) {
owner.getEntity().getDataTracker().set(param, spells.toNbt()); owner.asEntity().getDataTracker().set(param, spells.toNbt());
} }
} }

View file

@ -22,13 +22,13 @@ import net.minecraft.world.World;
public class ParticleHandle { public class ParticleHandle {
private final Map<String, Attachment> loadedEffects = new WeakHashMap<>(); private final Map<String, Attachment> loadedEffects = new WeakHashMap<>();
public Optional<Attachment> update(UUID id, ParticleSource source, Consumer<ParticleSpawner> constructor) { public Optional<Attachment> update(UUID id, ParticleSource<?> source, Consumer<ParticleSpawner> constructor) {
return update(id, "prime", source, constructor); return update(id, "prime", source, constructor);
} }
public Optional<Attachment> update(UUID id, String partName, ParticleSource source, Consumer<ParticleSpawner> constructor) { public Optional<Attachment> update(UUID id, String partName, ParticleSource<?> source, Consumer<ParticleSpawner> constructor) {
return get(partName).or(() -> { return get(partName).or(() -> {
if (source.getReferenceWorld().isClient) { if (source.asEntity().world.isClient) {
new ClientHandle().addParticle(id, partName, source, constructor); new ClientHandle().addParticle(id, partName, source, constructor);
} }
return get(partName); return get(partName);
@ -50,7 +50,7 @@ public class ParticleHandle {
private Particle pp; private Particle pp;
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
private void addParticle(UUID id, String partName, ParticleSource source, Consumer<ParticleSpawner> constructor) { private void addParticle(UUID id, String partName, ParticleSource<?> source, Consumer<ParticleSpawner> constructor) {
SPAWNED_PARTICLES.values().removeIf(set -> { SPAWNED_PARTICLES.values().removeIf(set -> {
set.values().removeIf(particle -> particle.get() == null); set.values().removeIf(particle -> particle.get() == null);
return set.isEmpty(); return set.isEmpty();
@ -110,7 +110,7 @@ public class ParticleHandle {
} }
public Optional<Caster<?>> get() { public Optional<Caster<?>> 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); return caster.map(WeakReference::get);
} }
} }

View file

@ -2,31 +2,17 @@ package com.minelittlepony.unicopia.particle;
import java.util.function.Consumer; import java.util.function.Consumer;
import com.minelittlepony.unicopia.EntityConvertable;
import com.minelittlepony.unicopia.util.shape.PointGenerator; import com.minelittlepony.unicopia.util.shape.PointGenerator;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.particle.ParticleEffect; import net.minecraft.particle.ParticleEffect;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
public interface ParticleSource extends ParticleSpawner { public interface ParticleSource<E extends Entity> extends ParticleSpawner, EntityConvertable<E> {
/**
* gets the minecraft world
*/
World getReferenceWorld();
Entity getEntity();
/**
* Gets the center position where this caster is located.
*/
default Vec3d getOriginVector() {
return getEntity().getPos();
}
default void spawnParticles(ParticleEffect particleId, int count) { 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<Vec3d> particleSpawner) { default void spawnParticles(PointGenerator area, int count, Consumer<Vec3d> particleSpawner) {
@ -34,11 +20,11 @@ public interface ParticleSource extends ParticleSpawner {
} }
default void spawnParticles(Vec3d pos, PointGenerator area, int count, Consumer<Vec3d> particleSpawner) { default void spawnParticles(Vec3d pos, PointGenerator area, int count, Consumer<Vec3d> particleSpawner) {
area.translate(pos).randomPoints(count, getReferenceWorld().random).forEach(particleSpawner); area.translate(pos).randomPoints(count, asEntity().world.random).forEach(particleSpawner);
} }
@Override @Override
default void addParticle(ParticleEffect effect, Vec3d position, Vec3d velocity) { default void addParticle(ParticleEffect effect, Vec3d position, Vec3d velocity) {
ParticleUtils.spawnParticle(getReferenceWorld(), effect, position, velocity); ParticleUtils.spawnParticle(asEntity().world, effect, position, velocity);
} }
} }

View file

@ -7,7 +7,6 @@ import java.util.function.Function;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import com.minelittlepony.unicopia.Affinity; import com.minelittlepony.unicopia.Affinity;
import com.minelittlepony.unicopia.Owned;
import com.minelittlepony.unicopia.ability.magic.Affine; import com.minelittlepony.unicopia.ability.magic.Affine;
import com.minelittlepony.unicopia.ability.magic.Caster; import com.minelittlepony.unicopia.ability.magic.Caster;
import com.minelittlepony.unicopia.ability.magic.Levelled; import com.minelittlepony.unicopia.ability.magic.Levelled;
@ -53,7 +52,7 @@ import net.minecraft.world.World;
* *
* Can also carry a spell if needed. * Can also carry a spell if needed.
*/ */
public class MagicProjectileEntity extends ThrownItemEntity implements Caster<LivingEntity>, Owned<LivingEntity> { public class MagicProjectileEntity extends ThrownItemEntity implements Caster<MagicProjectileEntity> {
private static final TrackedData<Float> DAMAGE = DataTracker.registerData(MagicProjectileEntity.class, TrackedDataHandlerRegistry.FLOAT); private static final TrackedData<Float> DAMAGE = DataTracker.registerData(MagicProjectileEntity.class, TrackedDataHandlerRegistry.FLOAT);
private static final TrackedData<Float> GRAVITY = DataTracker.registerData(MagicProjectileEntity.class, TrackedDataHandlerRegistry.FLOAT); private static final TrackedData<Float> GRAVITY = DataTracker.registerData(MagicProjectileEntity.class, TrackedDataHandlerRegistry.FLOAT);
private static final TrackedData<Boolean> HYDROPHOBIC = DataTracker.registerData(MagicProjectileEntity.class, TrackedDataHandlerRegistry.BOOLEAN); private static final TrackedData<Boolean> HYDROPHOBIC = DataTracker.registerData(MagicProjectileEntity.class, TrackedDataHandlerRegistry.BOOLEAN);
@ -98,7 +97,7 @@ public class MagicProjectileEntity extends ThrownItemEntity implements Caster<Li
} }
@Override @Override
public Entity getEntity() { public MagicProjectileEntity asEntity() {
return this; return this;
} }

View file

@ -36,7 +36,7 @@ public class MagicalDamageSource extends EntityDamageSource {
} }
public static MagicalDamageSource create(String type, Caster<?> caster) { public static MagicalDamageSource create(String type, 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; private Entity spell;

View file

@ -1,20 +1,16 @@
package com.minelittlepony.unicopia.util; package com.minelittlepony.unicopia.util;
import com.minelittlepony.unicopia.EntityConvertable;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.sound.SoundCategory; import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvent; import net.minecraft.sound.SoundEvent;
import net.minecraft.util.math.random.Random; import net.minecraft.util.math.random.Random;
import net.minecraft.world.World;
public interface SoundEmitter {
World getReferenceWorld();
Entity getEntity();
public interface SoundEmitter<E extends Entity> extends EntityConvertable<E> {
default void playSound(SoundEvent sound, float volume, float pitch) { 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) { default void playSound(SoundEvent sound, float volume) {
@ -22,7 +18,7 @@ public interface SoundEmitter {
} }
default float getRandomPitch() { default float getRandomPitch() {
return getRandomPitch(getReferenceWorld().getRandom()); return getRandomPitch(asEntity().world.getRandom());
} }
static void playSoundAt(Entity entity, SoundEvent sound, float volume, float pitch) { static void playSoundAt(Entity entity, SoundEvent sound, float volume, float pitch) {