From a3163d431f61619dae1698da2c57fc225a088db9 Mon Sep 17 00:00:00 2001 From: Sollace Date: Mon, 19 Dec 2022 19:50:15 +0100 Subject: [PATCH] Consolodate asWorld() implementations --- .../unicopia/EntityConvertable.java | 8 +++++++- .../unicopia/WorldConvertable.java | 7 +++++++ .../unicopia/ability/magic/Caster.java | 16 +--------------- .../minelittlepony/unicopia/entity/Creature.java | 6 ------ .../unicopia/particle/ParticleSource.java | 4 ++-- 5 files changed, 17 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/minelittlepony/unicopia/EntityConvertable.java b/src/main/java/com/minelittlepony/unicopia/EntityConvertable.java index dcf4373e..ab37c15c 100644 --- a/src/main/java/com/minelittlepony/unicopia/EntityConvertable.java +++ b/src/main/java/com/minelittlepony/unicopia/EntityConvertable.java @@ -3,6 +3,7 @@ package com.minelittlepony.unicopia; import net.minecraft.entity.Entity; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; +import net.minecraft.world.World; /** * Interface for things that can be owned by an entity. @@ -11,7 +12,7 @@ import net.minecraft.util.math.Vec3d; * * @param The type of object that owns us. */ -public interface EntityConvertable { +public interface EntityConvertable extends WorldConvertable { E asEntity(); /** @@ -26,4 +27,9 @@ public interface EntityConvertable { default Vec3d getOriginVector() { return asEntity().getPos(); } + + @Override + default World asWorld() { + return asEntity().world; + } } diff --git a/src/main/java/com/minelittlepony/unicopia/WorldConvertable.java b/src/main/java/com/minelittlepony/unicopia/WorldConvertable.java index fafe7662..2fada4bd 100644 --- a/src/main/java/com/minelittlepony/unicopia/WorldConvertable.java +++ b/src/main/java/com/minelittlepony/unicopia/WorldConvertable.java @@ -7,4 +7,11 @@ public interface WorldConvertable { * Gets the minecraft world */ World asWorld(); + + /** + * Returns true if we're executing on the client. + */ + default boolean isClient() { + return asWorld().isClient(); + } } diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/Caster.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/Caster.java index 57b5a60e..a5e753c4 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/Caster.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/Caster.java @@ -21,7 +21,6 @@ import net.minecraft.entity.player.PlayerEntity; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; import net.minecraft.world.GameRules; -import net.minecraft.world.World; /** * Interface for any magically capable entities that can cast or persist spells. @@ -31,8 +30,7 @@ public interface Caster extends Owned, Affine, ParticleSource, SoundEmitter, - EntityConvertable, - WorldConvertable { + EntityConvertable { Physics getPhysics(); @@ -45,18 +43,6 @@ public interface Caster extends Owned, */ boolean subtractEnergyCost(double amount); - @Override - default World asWorld() { - return asEntity().world; - } - - /** - * Returns true if we're executing on the client. - */ - default boolean isClient() { - return asWorld().isClient(); - } - default boolean canModifyAt(BlockPos pos) { return canModifyAt(pos, ModificationType.EITHER); } diff --git a/src/main/java/com/minelittlepony/unicopia/entity/Creature.java b/src/main/java/com/minelittlepony/unicopia/entity/Creature.java index 85e71459..a94ac4c4 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/Creature.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/Creature.java @@ -32,7 +32,6 @@ import net.minecraft.entity.player.PlayerEntity; import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtElement; import net.minecraft.util.math.MathHelper; -import net.minecraft.world.World; public class Creature extends Living implements WeaklyOwned { private static final TrackedData EFFECT = DataTracker.registerData(LivingEntity.class, TrackedDataHandlerRegistry.NBT_COMPOUND); @@ -75,11 +74,6 @@ public class Creature extends Living implements WeaklyOwned extends ParticleSpawner, Entit } default void spawnParticles(Vec3d pos, PointGenerator area, int count, Consumer particleSpawner) { - area.translate(pos).randomPoints(count, asEntity().world.random).forEach(particleSpawner); + area.translate(pos).randomPoints(count, asWorld().random).forEach(particleSpawner); } @Override default void addParticle(ParticleEffect effect, Vec3d position, Vec3d velocity) { - ParticleUtils.spawnParticle(asEntity().world, effect, position, velocity); + ParticleUtils.spawnParticle(asWorld(), effect, position, velocity); } }