diff --git a/src/main/java/io/ix0rai/rainglow/mixin/AllayEntityMixin.java b/src/main/java/io/ix0rai/rainglow/mixin/AllayEntityMixin.java index 0890197..b63cc22 100644 --- a/src/main/java/io/ix0rai/rainglow/mixin/AllayEntityMixin.java +++ b/src/main/java/io/ix0rai/rainglow/mixin/AllayEntityMixin.java @@ -9,10 +9,8 @@ import net.minecraft.entity.data.DataTracker.Builder; import net.minecraft.entity.passive.AllayEntity; import net.minecraft.nbt.NbtCompound; -import net.minecraft.util.random.RandomGenerator; import net.minecraft.world.World; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Redirect; @@ -20,9 +18,6 @@ @Mixin(AllayEntity.class) public abstract class AllayEntityMixin extends Entity implements AllayVariantProvider { - @Unique - private static final RainglowEntity THIS = RainglowEntity.ALLAY; - protected AllayEntityMixin(EntityType entityType, World world) { super(entityType, world); throw new UnsupportedOperationException(); @@ -30,40 +25,35 @@ protected AllayEntityMixin(EntityType entityType, World w @Inject(method = "initDataTracker", at = @At("TAIL")) protected void initDataTracker(Builder builder, CallbackInfo ci) { - builder.add(THIS.getTrackedData(), THIS.getDefaultColour().getId()); + builder.add(RainglowEntity.ALLAY.getTrackedData(), RainglowEntity.ALLAY.getDefaultColour().getId()); } @Inject(method = "writeCustomDataToNbt", at = @At("TAIL")) public void writeCustomDataToNbt(NbtCompound nbt, CallbackInfo ci) { - RainglowColour colour = Rainglow.getColour(THIS, this.getDataTracker(), this.getRandom()); + RainglowColour colour = Rainglow.getColour(RainglowEntity.ALLAY, this.getDataTracker(), this.random); nbt.putString(Rainglow.CUSTOM_NBT_KEY, colour.getId()); } @Inject(method = "readCustomDataFromNbt", at = @At("TAIL")) public void readCustomDataFromNbt(NbtCompound nbt, CallbackInfo ci) { - this.setVariant(THIS.readNbt(nbt, this.getRandom())); + this.setVariant(RainglowEntity.ALLAY.readNbt(nbt, this.random)); } // triggered when an allay duplicates, to apply the same colour as parent @Redirect(method = "duplicate", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;spawnEntity(Lnet/minecraft/entity/Entity;)Z")) public boolean spawnWithColour(World instance, Entity entity) { - RainglowColour colour = Rainglow.getColour(THIS, this.getDataTracker(), this.getRandom()); - entity.getDataTracker().set(THIS.getTrackedData(), colour.getId()); + RainglowColour colour = Rainglow.getColour(RainglowEntity.ALLAY, this.getDataTracker(), this.random); + entity.getDataTracker().set(RainglowEntity.ALLAY.getTrackedData(), colour.getId()); return this.getWorld().spawnEntity(entity); } @Override public RainglowColour getVariant() { - return Rainglow.getColour(THIS, this.getDataTracker(), this.getRandom()); + return Rainglow.getColour(RainglowEntity.ALLAY, this.getDataTracker(), this.random); } @Override public void setVariant(RainglowColour colour) { - this.getDataTracker().set(THIS.getTrackedData(), colour.getId()); - } - - @Unique - public RandomGenerator getRandom() { - return this.random; + this.getDataTracker().set(RainglowEntity.ALLAY.getTrackedData(), colour.getId()); } } diff --git a/src/main/java/io/ix0rai/rainglow/mixin/GlowSquidEntityMixin.java b/src/main/java/io/ix0rai/rainglow/mixin/GlowSquidEntityMixin.java index 98a82a0..a74ff8b 100644 --- a/src/main/java/io/ix0rai/rainglow/mixin/GlowSquidEntityMixin.java +++ b/src/main/java/io/ix0rai/rainglow/mixin/GlowSquidEntityMixin.java @@ -15,7 +15,6 @@ import net.minecraft.server.world.ServerWorld; import net.minecraft.world.World; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Redirect; @@ -23,9 +22,6 @@ @Mixin(GlowSquidEntity.class) public abstract class GlowSquidEntityMixin extends SquidEntity implements GlowSquidVariantProvider { - @Unique - private static final RainglowEntity THIS = RainglowEntity.GLOW_SQUID; - protected GlowSquidEntityMixin(EntityType entityType, World world) { super(entityType, world); throw new UnsupportedOperationException(); @@ -33,18 +29,18 @@ protected GlowSquidEntityMixin(EntityType entityType, Wor @Inject(method = "initDataTracker", at = @At("TAIL")) protected void initDataTracker(Builder builder, CallbackInfo ci) { - builder.add(THIS.getTrackedData(), THIS.getDefaultColour().getId()); + builder.add(RainglowEntity.GLOW_SQUID.getTrackedData(), RainglowEntity.GLOW_SQUID.getDefaultColour().getId()); } @Inject(method = "writeCustomDataToNbt", at = @At("TAIL")) public void writeCustomDataToNbt(NbtCompound nbt, CallbackInfo ci) { - RainglowColour colour = Rainglow.getColour(THIS, this.getDataTracker(), this.getRandom()); + RainglowColour colour = Rainglow.getColour(RainglowEntity.GLOW_SQUID, this.getDataTracker(), this.getRandom()); nbt.putString(Rainglow.CUSTOM_NBT_KEY, colour.getId()); } @Inject(method = "readCustomDataFromNbt", at = @At("TAIL")) public void readCustomDataFromNbt(NbtCompound nbt, CallbackInfo ci) { - this.setVariant(THIS.readNbt(nbt, this.getRandom())); + this.setVariant(RainglowEntity.GLOW_SQUID.readNbt(nbt, this.getRandom())); } /** @@ -53,7 +49,7 @@ public void readCustomDataFromNbt(NbtCompound nbt, CallbackInfo ci) { */ @Inject(method = "tickMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;addParticle(Lnet/minecraft/particle/ParticleEffect;DDDDDD)V"), cancellable = true) public void tickMovement(CallbackInfo ci) { - RainglowColour colour = Rainglow.getColour(THIS, this.getDataTracker(), this.getRandom()); + RainglowColour colour = Rainglow.getColour(RainglowEntity.GLOW_SQUID, this.getDataTracker(), this.getRandom()); if (colour != RainglowColour.BLUE) { // we add 100 to g to let the mixin know that we want to override the method @@ -64,12 +60,12 @@ public void tickMovement(CallbackInfo ci) { @Override public RainglowColour getVariant() { - return Rainglow.getColour(THIS, this.getDataTracker(), this.getRandom()); + return Rainglow.getColour(RainglowEntity.GLOW_SQUID, this.getDataTracker(), this.getRandom()); } @Override public void setVariant(RainglowColour colour) { - this.getDataTracker().set(THIS.getTrackedData(), colour.getId()); + this.getDataTracker().set(RainglowEntity.GLOW_SQUID.getTrackedData(), colour.getId()); } @Mixin(SquidEntity.class) @@ -89,7 +85,7 @@ protected SquidEntityMixin(EntityType entityType, private int spawnParticles(ServerWorld instance, ParticleEffect particle, double x, double y, double z, int count, double deltaX, double deltaY, double deltaZ, double speed) { if (((Object) this) instanceof GlowSquidEntity) { // send in custom colour data - RainglowColour colour = Rainglow.getColour(THIS, this.getDataTracker(), this.getRandom()); + RainglowColour colour = Rainglow.getColour(RainglowEntity.GLOW_SQUID, this.getDataTracker(), this.getRandom()); int index = colour.ordinal(); // round x to 1 decimal place and append index data to the next two return ((ServerWorld) this.getWorld()).spawnParticles(particle, (Math.round(x * 10)) / 10D + index / 1000D, y + 0.5, z, 0, deltaX, deltaY, deltaZ, speed); diff --git a/src/main/java/io/ix0rai/rainglow/mixin/SlimeEntityMixin.java b/src/main/java/io/ix0rai/rainglow/mixin/SlimeEntityMixin.java index 97f2415..5cfa0f2 100644 --- a/src/main/java/io/ix0rai/rainglow/mixin/SlimeEntityMixin.java +++ b/src/main/java/io/ix0rai/rainglow/mixin/SlimeEntityMixin.java @@ -14,7 +14,6 @@ import net.minecraft.world.World; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Redirect; @@ -23,9 +22,6 @@ @Mixin(SlimeEntity.class) public abstract class SlimeEntityMixin extends Entity implements SlimeVariantProvider { - @Unique - private static final RainglowEntity THIS = RainglowEntity.SLIME; - @Shadow protected abstract ParticleEffect getParticles(); @@ -36,18 +32,18 @@ protected SlimeEntityMixin(EntityType entityType, World w @Inject(method = "initDataTracker", at = @At("TAIL")) protected void initDataTracker(DataTracker.Builder builder, CallbackInfo ci) { - builder.add(THIS.getTrackedData(), THIS.getDefaultColour().getId()); + builder.add(RainglowEntity.SLIME.getTrackedData(), RainglowEntity.SLIME.getDefaultColour().getId()); } @Inject(method = "writeCustomDataToNbt", at = @At("TAIL")) public void writeCustomDataToNbt(NbtCompound nbt, CallbackInfo ci) { - RainglowColour colour = Rainglow.getColour(THIS, this.getDataTracker(), this.random); + RainglowColour colour = Rainglow.getColour(RainglowEntity.SLIME, this.getDataTracker(), this.random); nbt.putString(Rainglow.CUSTOM_NBT_KEY, colour.getId()); } @Inject(method = "readCustomDataFromNbt", at = @At("TAIL")) public void readCustomDataFromNbt(NbtCompound nbt, CallbackInfo ci) { - this.setVariant(THIS.readNbt(nbt, this.random)); + this.setVariant(RainglowEntity.SLIME.readNbt(nbt, this.random)); } /** @@ -55,8 +51,8 @@ public void readCustomDataFromNbt(NbtCompound nbt, CallbackInfo ci) { */ @Redirect(method = "remove", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;spawnEntity(Lnet/minecraft/entity/Entity;)Z")) public boolean spawnWithParentColour(World instance, Entity entity) { - RainglowColour colour = Rainglow.getColour(THIS, this.getDataTracker(), this.random); - entity.getDataTracker().set(THIS.getTrackedData(), colour.getId()); + RainglowColour colour = Rainglow.getColour(RainglowEntity.SLIME, this.getDataTracker(), this.random); + entity.getDataTracker().set(RainglowEntity.SLIME.getTrackedData(), colour.getId()); return this.getWorld().spawnEntity(entity); } @@ -72,7 +68,7 @@ public boolean spawnWithParentColour(World instance, Entity entity) { ) public void tick(CallbackInfo ci) { float size = this.getDimensions(this.getPose()).width(); - RainglowColour colour = Rainglow.getColour(THIS, this.getDataTracker(), this.random); + RainglowColour colour = Rainglow.getColour(RainglowEntity.SLIME, this.getDataTracker(), this.random); int index = colour.ordinal(); for (int j = 0; j < size / 2; j ++) { @@ -87,11 +83,11 @@ public void tick(CallbackInfo ci) { @Override public RainglowColour getVariant() { - return Rainglow.getColour(THIS, this.getDataTracker(), this.random); + return Rainglow.getColour(RainglowEntity.SLIME, this.getDataTracker(), this.random); } @Override public void setVariant(RainglowColour colour) { - this.getDataTracker().set(THIS.getTrackedData(), colour.getId()); + this.getDataTracker().set(RainglowEntity.SLIME.getTrackedData(), colour.getId()); } }