Consolodate asWorld() implementations

This commit is contained in:
Sollace 2022-12-19 19:50:15 +01:00
parent a239d30cab
commit a3163d431f
5 changed files with 17 additions and 24 deletions

View file

@ -3,6 +3,7 @@ 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.BlockPos;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
/** /**
* Interface for things that can be owned by an entity. * Interface for things that can be owned by an entity.
@ -11,7 +12,7 @@ import net.minecraft.util.math.Vec3d;
* *
* @param <E> The type of object that owns us. * @param <E> The type of object that owns us.
*/ */
public interface EntityConvertable<E extends Entity> { public interface EntityConvertable<E extends Entity> extends WorldConvertable {
E asEntity(); E asEntity();
/** /**
@ -26,4 +27,9 @@ public interface EntityConvertable<E extends Entity> {
default Vec3d getOriginVector() { default Vec3d getOriginVector() {
return asEntity().getPos(); return asEntity().getPos();
} }
@Override
default World asWorld() {
return asEntity().world;
}
} }

View file

@ -7,4 +7,11 @@ public interface WorldConvertable {
* Gets the minecraft world * Gets the minecraft world
*/ */
World asWorld(); World asWorld();
/**
* Returns true if we're executing on the client.
*/
default boolean isClient() {
return asWorld().isClient();
}
} }

View file

@ -21,7 +21,6 @@ import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
import net.minecraft.world.GameRules; import net.minecraft.world.GameRules;
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.
@ -31,8 +30,7 @@ public interface Caster<E extends Entity> extends Owned<LivingEntity>,
Affine, Affine,
ParticleSource<E>, ParticleSource<E>,
SoundEmitter<E>, SoundEmitter<E>,
EntityConvertable<E>, EntityConvertable<E> {
WorldConvertable {
Physics getPhysics(); Physics getPhysics();
@ -45,18 +43,6 @@ public interface Caster<E extends Entity> extends Owned<LivingEntity>,
*/ */
boolean subtractEnergyCost(double amount); 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) { default boolean canModifyAt(BlockPos pos) {
return canModifyAt(pos, ModificationType.EITHER); return canModifyAt(pos, ModificationType.EITHER);
} }

View file

@ -32,7 +32,6 @@ import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtElement; import net.minecraft.nbt.NbtElement;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World;
public class Creature extends Living<LivingEntity> implements WeaklyOwned<LivingEntity> { public class Creature extends Living<LivingEntity> implements WeaklyOwned<LivingEntity> {
private static final TrackedData<NbtCompound> EFFECT = DataTracker.registerData(LivingEntity.class, TrackedDataHandlerRegistry.NBT_COMPOUND); private static final TrackedData<NbtCompound> EFFECT = DataTracker.registerData(LivingEntity.class, TrackedDataHandlerRegistry.NBT_COMPOUND);
@ -75,11 +74,6 @@ public class Creature extends Living<LivingEntity> implements WeaklyOwned<Living
return owner.getId().isPresent(); return owner.getId().isPresent();
} }
@Override
public World asWorld() {
return super.asWorld();
}
@Override @Override
@NotNull @NotNull
public LivingEntity getMaster() { public LivingEntity getMaster() {

View file

@ -20,11 +20,11 @@ public interface ParticleSource<E extends Entity> extends ParticleSpawner, Entit
} }
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, asEntity().world.random).forEach(particleSpawner); area.translate(pos).randomPoints(count, asWorld().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(asEntity().world, effect, position, velocity); ParticleUtils.spawnParticle(asWorld(), effect, position, velocity);
} }
} }