diff --git a/src/main/java/io/ix0rai/rainglow/Rainglow.java b/src/main/java/io/ix0rai/rainglow/Rainglow.java index ad52844..d701768 100644 --- a/src/main/java/io/ix0rai/rainglow/Rainglow.java +++ b/src/main/java/io/ix0rai/rainglow/Rainglow.java @@ -11,12 +11,6 @@ import net.fabricmc.fabric.api.resource.ResourceManagerHelper; import net.fabricmc.loader.api.FabricLoader; import net.minecraft.entity.data.DataTracker; -import net.minecraft.entity.data.TrackedData; -import net.minecraft.entity.data.TrackedDataHandlerRegistry; -import net.minecraft.entity.mob.SlimeEntity; -import net.minecraft.entity.passive.AllayEntity; -import net.minecraft.entity.passive.GlowSquidEntity; -import net.minecraft.item.Item; import net.minecraft.resource.ResourceType; import net.minecraft.text.Text; import net.minecraft.util.Identifier; @@ -95,41 +89,17 @@ private static void addColour(RainglowColour colour) { } public static Identifier getTexture(RainglowEntity entityType, String colour) { - if (entityType == RainglowEntity.GLOW_SQUID) return GLOW_SQUID_TEXTURES.get(colour); - else if (entityType == RainglowEntity.ALLAY) return ALLAY_TEXTURES.get(colour); - else return SLIME_TEXTURES.get(colour); - } - - public static int getColourIndex(String colour) { - return COLOURS.indexOf(RainglowColour.get(colour)); - } - - public static RainglowColour.RGB getInkRgb(int index) { - return COLOURS.get(index).getInkRgb(); - } - - public static RainglowColour.RGB getPassiveParticleRGB(int index, RandomGenerator random) { - RainglowColour colour = COLOURS.get(index); - return random.nextBoolean() ? colour.getPassiveParticleRgb() : colour.getAltPassiveParticleRgb(); - } - - public static Item getItem(RainglowEntity entity, int index) { - if (index == -1) { - return entity.getDefaultColour().getItem(); - } - - return COLOURS.get(index).getItem(); + return switch (entityType) { + case ALLAY -> ALLAY_TEXTURES.get(colour); + case SLIME -> SLIME_TEXTURES.get(colour); + case GLOW_SQUID -> GLOW_SQUID_TEXTURES.get(colour); + }; } public static String generateRandomColourId(RandomGenerator random) { return COLOURS.get(random.nextInt(COLOURS.size())).getId(); } - public static Identifier getDefaultTexture(RainglowEntity entityType) { - if (entityType == RainglowEntity.SLIME) return RainglowColour.LIME.getTexture(entityType); - else return RainglowColour.BLUE.getTexture(entityType); - } - public static boolean colourUnloaded(RainglowEntity entityType, String colour) { return !COLOURS.contains(RainglowColour.get(colour)) && !colour.equals(entityType.getDefaultColour().getId()); } @@ -147,7 +117,7 @@ public static Text translatableText(String key) { return Text.translatable(translatableTextKey(key)); } - public static String getColour(RainglowEntity entityType, DataTracker tracker, RandomGenerator random) { + public static RainglowColour getColour(RainglowEntity entityType, DataTracker tracker, RandomGenerator random) { // generate random colour if the squid's colour isn't currently loaded String colour = tracker.get(entityType.getTrackedData()); if (colourUnloaded(entityType, colour)) { @@ -156,6 +126,6 @@ public static String getColour(RainglowEntity entityType, DataTracker tracker, R colour = tracker.get(entityType.getTrackedData()); } - return colour; + return RainglowColour.get(colour); } } diff --git a/src/main/java/io/ix0rai/rainglow/data/RainglowColour.java b/src/main/java/io/ix0rai/rainglow/data/RainglowColour.java index d570ab1..25a88c5 100644 --- a/src/main/java/io/ix0rai/rainglow/data/RainglowColour.java +++ b/src/main/java/io/ix0rai/rainglow/data/RainglowColour.java @@ -4,6 +4,7 @@ import net.minecraft.item.Items; import net.minecraft.network.PacketByteBuf; import net.minecraft.util.Identifier; +import net.minecraft.util.random.RandomGenerator; import org.jetbrains.annotations.Nullable; import java.util.Arrays; @@ -95,6 +96,15 @@ public static RainglowColour get(String id) { return BY_ID.get(id); } + public static RainglowColour.RGB getInkRgb(int index) { + return RainglowColour.values()[index].getInkRgb(); + } + + public static RainglowColour.RGB getPassiveParticleRGB(int index, RandomGenerator random) { + RainglowColour colour = RainglowColour.values()[index]; + return random.nextBoolean() ? colour.getPassiveParticleRgb() : colour.getAltPassiveParticleRgb(); + } + public record RGB(float r, float g, float b) { } diff --git a/src/main/java/io/ix0rai/rainglow/data/RainglowEntity.java b/src/main/java/io/ix0rai/rainglow/data/RainglowEntity.java index 8b75d39..a23eb22 100644 --- a/src/main/java/io/ix0rai/rainglow/data/RainglowEntity.java +++ b/src/main/java/io/ix0rai/rainglow/data/RainglowEntity.java @@ -1,12 +1,17 @@ package io.ix0rai.rainglow.data; +import io.ix0rai.rainglow.Rainglow; import net.minecraft.entity.data.DataTracker; import net.minecraft.entity.data.TrackedData; import net.minecraft.entity.data.TrackedDataHandlerRegistry; import net.minecraft.entity.mob.SlimeEntity; import net.minecraft.entity.passive.AllayEntity; import net.minecraft.entity.passive.GlowSquidEntity; +import net.minecraft.item.Item; +import net.minecraft.nbt.NbtCompound; import net.minecraft.network.PacketByteBuf; +import net.minecraft.util.Identifier; +import net.minecraft.util.random.RandomGenerator; import org.jetbrains.annotations.Nullable; import java.util.Arrays; @@ -44,6 +49,28 @@ public TrackedData getTrackedData() { return this.trackedData; } + public Identifier getDefaultTexture() { + return this.defaultColour.getTexture(this); + } + + public Item getItem(int index) { + if (index == -1) { + return this.getDefaultColour().getItem(); + } + + return RainglowColour.values()[index].getItem(); + } + + public RainglowColour readNbt(NbtCompound nbt, RandomGenerator random) { + String colour = nbt.getString(Rainglow.CUSTOM_NBT_KEY); + + if (Rainglow.colourUnloaded(this, colour)) { + colour = Rainglow.generateRandomColourId(random); + } + + return RainglowColour.get(colour); + } + public static RainglowEntity read(PacketByteBuf buf) { return get(buf.readString()); } diff --git a/src/main/java/io/ix0rai/rainglow/mixin/AllayEntityMixin.java b/src/main/java/io/ix0rai/rainglow/mixin/AllayEntityMixin.java index c67f5ee..1a6a57d 100644 --- a/src/main/java/io/ix0rai/rainglow/mixin/AllayEntityMixin.java +++ b/src/main/java/io/ix0rai/rainglow/mixin/AllayEntityMixin.java @@ -20,6 +20,9 @@ @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(); @@ -27,37 +30,31 @@ protected AllayEntityMixin(EntityType entityType, World w @Inject(method = "initDataTracker", at = @At("TAIL")) protected void initDataTracker(Builder builder, CallbackInfo ci) { - builder.add(RainglowEntity.ALLAY.getTrackedData(), RainglowEntity.ALLAY.getDefaultColour().getId()); + builder.add(THIS.getTrackedData(), THIS.getDefaultColour().getId()); } @Inject(method = "writeCustomDataToNbt", at = @At("TAIL")) public void writeCustomDataToNbt(NbtCompound nbt, CallbackInfo ci) { - String colour = Rainglow.getColour(RainglowEntity.ALLAY, this.getDataTracker(), this.getRandom()); - nbt.putString(Rainglow.CUSTOM_NBT_KEY, colour); + RainglowColour colour = Rainglow.getColour(THIS, 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) { - String colour = nbt.getString(Rainglow.CUSTOM_NBT_KEY); - - if (Rainglow.colourUnloaded(RainglowEntity.ALLAY, colour)) { - colour = Rainglow.generateRandomColourId(this.getRandom()); - } - - this.setVariant(RainglowColour.get(colour)); + this.setVariant(THIS.readNbt(nbt, this.getRandom())); } // 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 = RainglowColour.get(Rainglow.getColour(RainglowEntity.ALLAY, this.getDataTracker(), this.getRandom())); + RainglowColour colour = Rainglow.getColour(THIS, this.getDataTracker(), this.getRandom()); entity.getDataTracker().set(RainglowEntity.ALLAY.getTrackedData(), colour.getId()); return this.getWorld().spawnEntity(entity); } @Override public RainglowColour getVariant() { - return RainglowColour.get(Rainglow.getColour(RainglowEntity.ALLAY, this.getDataTracker(), this.getRandom())); + return Rainglow.getColour(RainglowEntity.ALLAY, this.getDataTracker(), this.getRandom()); } @Override diff --git a/src/main/java/io/ix0rai/rainglow/mixin/GlowSquidEntityMixin.java b/src/main/java/io/ix0rai/rainglow/mixin/GlowSquidEntityMixin.java index e4e4b40..98a82a0 100644 --- a/src/main/java/io/ix0rai/rainglow/mixin/GlowSquidEntityMixin.java +++ b/src/main/java/io/ix0rai/rainglow/mixin/GlowSquidEntityMixin.java @@ -15,6 +15,7 @@ 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; @@ -22,6 +23,9 @@ @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(); @@ -29,25 +33,18 @@ protected GlowSquidEntityMixin(EntityType entityType, Wor @Inject(method = "initDataTracker", at = @At("TAIL")) protected void initDataTracker(Builder builder, CallbackInfo ci) { - builder.add(RainglowEntity.GLOW_SQUID.getTrackedData(), RainglowColour.BLUE.getId()); + builder.add(THIS.getTrackedData(), THIS.getDefaultColour().getId()); } @Inject(method = "writeCustomDataToNbt", at = @At("TAIL")) public void writeCustomDataToNbt(NbtCompound nbt, CallbackInfo ci) { - String colour = Rainglow.getColour(RainglowEntity.GLOW_SQUID, this.getDataTracker(), this.getRandom()); - nbt.putString(Rainglow.CUSTOM_NBT_KEY, colour); + RainglowColour colour = Rainglow.getColour(THIS, 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) { - String colour = nbt.getString(Rainglow.CUSTOM_NBT_KEY); - - // if read colour does not exist in the colour map, generate the squid a new one - if (Rainglow.colourUnloaded(RainglowEntity.GLOW_SQUID, colour)) { - colour = Rainglow.generateRandomColourId(this.getRandom()); - } - - this.setVariant(RainglowColour.get(colour)); + this.setVariant(THIS.readNbt(nbt, this.getRandom())); } /** @@ -56,22 +53,23 @@ 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) { - String colour = Rainglow.getColour(RainglowEntity.GLOW_SQUID, this.getDataTracker(), this.getRandom()); - if (!colour.equals(RainglowColour.BLUE.getId())) { + RainglowColour colour = Rainglow.getColour(THIS, 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 - this.getWorld().addParticle(ParticleTypes.GLOW, this.getParticleX(0.6), this.getRandomBodyY(), this.getParticleZ(0.6), Rainglow.getColourIndex(colour) + 100, 0, 0); + this.getWorld().addParticle(ParticleTypes.GLOW, this.getParticleX(0.6), this.getRandomBodyY(), this.getParticleZ(0.6), colour.ordinal() + 100, 0, 0); ci.cancel(); } } @Override public RainglowColour getVariant() { - return RainglowColour.get(Rainglow.getColour(RainglowEntity.GLOW_SQUID, this.getDataTracker(), this.getRandom())); + return Rainglow.getColour(THIS, this.getDataTracker(), this.getRandom()); } @Override public void setVariant(RainglowColour colour) { - this.getDataTracker().set(RainglowEntity.GLOW_SQUID.getTrackedData(), colour.getId()); + this.getDataTracker().set(THIS.getTrackedData(), colour.getId()); } @Mixin(SquidEntity.class) @@ -91,8 +89,8 @@ 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 - String colour = Rainglow.getColour(RainglowEntity.GLOW_SQUID, this.getDataTracker(), this.getRandom()); - int index = Rainglow.getColourIndex(colour); + RainglowColour colour = Rainglow.getColour(THIS, 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); } else { diff --git a/src/main/java/io/ix0rai/rainglow/mixin/SlimeEntityMixin.java b/src/main/java/io/ix0rai/rainglow/mixin/SlimeEntityMixin.java index e026234..97f2415 100644 --- a/src/main/java/io/ix0rai/rainglow/mixin/SlimeEntityMixin.java +++ b/src/main/java/io/ix0rai/rainglow/mixin/SlimeEntityMixin.java @@ -14,6 +14,7 @@ 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; @@ -22,11 +23,11 @@ @Mixin(SlimeEntity.class) public abstract class SlimeEntityMixin extends Entity implements SlimeVariantProvider { - @Shadow - protected abstract ParticleEffect getParticles(); + @Unique + private static final RainglowEntity THIS = RainglowEntity.SLIME; @Shadow - public abstract int getSize(); + protected abstract ParticleEffect getParticles(); protected SlimeEntityMixin(EntityType entityType, World world) { super(entityType, world); @@ -35,24 +36,18 @@ protected SlimeEntityMixin(EntityType entityType, World w @Inject(method = "initDataTracker", at = @At("TAIL")) protected void initDataTracker(DataTracker.Builder builder, CallbackInfo ci) { - builder.add(RainglowEntity.SLIME.getTrackedData(), RainglowColour.LIME.getId()); + builder.add(THIS.getTrackedData(), THIS.getDefaultColour().getId()); } @Inject(method = "writeCustomDataToNbt", at = @At("TAIL")) public void writeCustomDataToNbt(NbtCompound nbt, CallbackInfo ci) { - String colour = Rainglow.getColour(RainglowEntity.SLIME, this.getDataTracker(), this.random); - nbt.putString(Rainglow.CUSTOM_NBT_KEY, colour); + RainglowColour colour = Rainglow.getColour(THIS, 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) { - String colour = nbt.getString(Rainglow.CUSTOM_NBT_KEY); - - if (Rainglow.colourUnloaded(RainglowEntity.SLIME, colour)) { - colour = Rainglow.generateRandomColourId(this.random); - } - - this.setVariant(RainglowColour.get(colour)); + this.setVariant(THIS.readNbt(nbt, this.random)); } /** @@ -60,8 +55,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 = RainglowColour.get(Rainglow.getColour(RainglowEntity.SLIME, this.getDataTracker(), this.random)); - entity.getDataTracker().set(RainglowEntity.SLIME.getTrackedData(), colour.getId()); + RainglowColour colour = Rainglow.getColour(THIS, this.getDataTracker(), this.random); + entity.getDataTracker().set(THIS.getTrackedData(), colour.getId()); return this.getWorld().spawnEntity(entity); } @@ -77,8 +72,8 @@ public boolean spawnWithParentColour(World instance, Entity entity) { ) public void tick(CallbackInfo ci) { float size = this.getDimensions(this.getPose()).width(); - String colour = RainglowColour.get(Rainglow.getColour(RainglowEntity.SLIME, this.getDataTracker(), this.random)).getId(); - int index = Rainglow.getColourIndex(colour); + RainglowColour colour = Rainglow.getColour(THIS, this.getDataTracker(), this.random); + int index = colour.ordinal(); for (int j = 0; j < size / 2; j ++) { float f = this.random.nextFloat() * 6.2831855F; @@ -92,11 +87,11 @@ public void tick(CallbackInfo ci) { @Override public RainglowColour getVariant() { - return RainglowColour.get(Rainglow.getColour(RainglowEntity.SLIME, this.getDataTracker(), this.random)); + return Rainglow.getColour(THIS, this.getDataTracker(), this.random); } @Override public void setVariant(RainglowColour colour) { - this.getDataTracker().set(RainglowEntity.SLIME.getTrackedData(), colour.getId()); + this.getDataTracker().set(THIS.getTrackedData(), colour.getId()); } } diff --git a/src/main/java/io/ix0rai/rainglow/mixin/client/AllayEntityRendererMixin.java b/src/main/java/io/ix0rai/rainglow/mixin/client/AllayEntityRendererMixin.java index 28cb0a1..ec778f9 100644 --- a/src/main/java/io/ix0rai/rainglow/mixin/client/AllayEntityRendererMixin.java +++ b/src/main/java/io/ix0rai/rainglow/mixin/client/AllayEntityRendererMixin.java @@ -15,13 +15,13 @@ public class AllayEntityRendererMixin { @Inject(method = "getTexture*", at = @At("HEAD"), cancellable = true) public void getTexture(AllayEntity allayEntity, CallbackInfoReturnable cir) { - String colour = Rainglow.getColour(RainglowEntity.ALLAY, allayEntity.getDataTracker(), allayEntity.getRandom()); + RainglowColour colour = Rainglow.getColour(RainglowEntity.ALLAY, allayEntity.getDataTracker(), allayEntity.getRandom()); // if the colour is blue we don't need to override the method // this optimises a tiny bit - if (Rainglow.CONFIG.isEntityEnabled(RainglowEntity.ALLAY) && !colour.equals(RainglowColour.BLUE.getId())) { - Identifier texture = Rainglow.getTexture(RainglowEntity.ALLAY, colour); - cir.setReturnValue(texture != null ? texture : Rainglow.getDefaultTexture(RainglowEntity.ALLAY)); + if (Rainglow.CONFIG.isEntityEnabled(RainglowEntity.ALLAY) && colour != RainglowEntity.ALLAY.getDefaultColour()) { + Identifier texture = Rainglow.getTexture(RainglowEntity.ALLAY, colour.getId()); + cir.setReturnValue(texture != null ? texture : RainglowEntity.ALLAY.getDefaultTexture()); } } } diff --git a/src/main/java/io/ix0rai/rainglow/mixin/client/GlowParticleMixin.java b/src/main/java/io/ix0rai/rainglow/mixin/client/GlowParticleMixin.java index df4dea5..60e163e 100644 --- a/src/main/java/io/ix0rai/rainglow/mixin/client/GlowParticleMixin.java +++ b/src/main/java/io/ix0rai/rainglow/mixin/client/GlowParticleMixin.java @@ -32,7 +32,7 @@ public void createParticle(DefaultParticleType defaultParticleType, ClientWorld GlowParticle glowParticle = new GlowParticle(clientWorld, d, e, f, 0.5 - GlowParticle.RANDOM.nextDouble(), h, 0.5 - GlowParticle.RANDOM.nextDouble(), this.spriteProvider); // we check the g value to see what the colour is - RainglowColour.RGB rgb = Rainglow.getPassiveParticleRGB((int) g, GlowParticle.RANDOM); + RainglowColour.RGB rgb = RainglowColour.getPassiveParticleRGB((int) g, GlowParticle.RANDOM); glowParticle.setColor(rgb.r(), rgb.g(), rgb.b()); // set velocities - I don't entirely understand why this is necessary, it's copied from vanilla code diff --git a/src/main/java/io/ix0rai/rainglow/mixin/client/GlowSquidEntityRendererMixin.java b/src/main/java/io/ix0rai/rainglow/mixin/client/GlowSquidEntityRendererMixin.java index 53627a5..aba3c90 100644 --- a/src/main/java/io/ix0rai/rainglow/mixin/client/GlowSquidEntityRendererMixin.java +++ b/src/main/java/io/ix0rai/rainglow/mixin/client/GlowSquidEntityRendererMixin.java @@ -19,13 +19,13 @@ public class GlowSquidEntityRendererMixin { */ @Inject(method = "getTexture*", at = @At("HEAD"), cancellable = true) public void getTexture(GlowSquidEntity glowSquidEntity, CallbackInfoReturnable cir) { - String colour = Rainglow.getColour(RainglowEntity.GLOW_SQUID, glowSquidEntity.getDataTracker(), glowSquidEntity.getRandom()); + RainglowColour colour = Rainglow.getColour(RainglowEntity.GLOW_SQUID, glowSquidEntity.getDataTracker(), glowSquidEntity.getRandom()); // if the colour is blue we don't need to override the method // this optimises a tiny bit - if (Rainglow.CONFIG.isEntityEnabled(RainglowEntity.GLOW_SQUID) && !colour.equals(RainglowColour.BLUE.getId())) { - Identifier texture = Rainglow.getTexture(RainglowEntity.GLOW_SQUID, colour); - cir.setReturnValue(texture != null ? texture : Rainglow.getDefaultTexture(RainglowEntity.GLOW_SQUID)); + if (Rainglow.CONFIG.isEntityEnabled(RainglowEntity.GLOW_SQUID) && colour != RainglowEntity.GLOW_SQUID.getDefaultColour()) { + Identifier texture = Rainglow.getTexture(RainglowEntity.GLOW_SQUID, colour.getId()); + cir.setReturnValue(texture != null ? texture : RainglowEntity.GLOW_SQUID.getDefaultTexture()); } } } diff --git a/src/main/java/io/ix0rai/rainglow/mixin/client/SlimeEntityRendererMixin.java b/src/main/java/io/ix0rai/rainglow/mixin/client/SlimeEntityRendererMixin.java index d93ede4..5800752 100644 --- a/src/main/java/io/ix0rai/rainglow/mixin/client/SlimeEntityRendererMixin.java +++ b/src/main/java/io/ix0rai/rainglow/mixin/client/SlimeEntityRendererMixin.java @@ -3,7 +3,6 @@ import io.ix0rai.rainglow.Rainglow; import io.ix0rai.rainglow.data.RainglowColour; import io.ix0rai.rainglow.data.RainglowEntity; -import io.ix0rai.rainglow.data.RainglowMode; import net.minecraft.client.render.entity.SlimeEntityRenderer; import net.minecraft.entity.mob.SlimeEntity; import net.minecraft.util.Identifier; @@ -16,12 +15,12 @@ public class SlimeEntityRendererMixin { @Inject(method = "getTexture*", at = @At("HEAD"), cancellable = true) public void getTexture(SlimeEntity entity, CallbackInfoReturnable cir) { - String colour = Rainglow.getColour(RainglowEntity.SLIME, entity.getDataTracker(), entity.getRandom()); + RainglowColour colour = Rainglow.getColour(RainglowEntity.SLIME, entity.getDataTracker(), entity.getRandom()); // don't override if the colour is lime, use the default texture - if (Rainglow.CONFIG.isEntityEnabled(RainglowEntity.SLIME) && !colour.equals(RainglowColour.LIME.getId()) || Rainglow.CONFIG.getMode().equals(RainglowMode.get("vanilla"))) { - Identifier texture = Rainglow.getTexture(RainglowEntity.SLIME, colour); - cir.setReturnValue(texture != null ? texture : Rainglow.getDefaultTexture(RainglowEntity.SLIME)); + if (Rainglow.CONFIG.isEntityEnabled(RainglowEntity.SLIME) && colour != RainglowEntity.SLIME.getDefaultColour()) { + Identifier texture = Rainglow.getTexture(RainglowEntity.SLIME, colour.getId()); + cir.setReturnValue(texture != null ? texture : RainglowEntity.SLIME.getDefaultTexture()); } } } diff --git a/src/main/java/io/ix0rai/rainglow/mixin/client/SlimeParticleMixin.java b/src/main/java/io/ix0rai/rainglow/mixin/client/SlimeParticleMixin.java index 81de85d..83327e6 100644 --- a/src/main/java/io/ix0rai/rainglow/mixin/client/SlimeParticleMixin.java +++ b/src/main/java/io/ix0rai/rainglow/mixin/client/SlimeParticleMixin.java @@ -25,7 +25,7 @@ public void createParticle(DefaultParticleType defaultParticleType, ClientWorld cir.setReturnValue(new ItemBreakParticle(clientWorld, d, e, f, new ItemStack(Items.SLIME_BALL))); // 99.9d and 100.1d are used to account for floating point errors } else if (h >= 99.9d && h <= 100.1d) { - ItemStack stack = Rainglow.getItem(RainglowEntity.SLIME, (int) g).getDefaultStack(); + ItemStack stack = RainglowEntity.SLIME.getItem((int) g).getDefaultStack(); cir.setReturnValue(new ItemBreakParticle(clientWorld, d, e, f, stack)); } else { cir.setReturnValue(null); diff --git a/src/main/java/io/ix0rai/rainglow/mixin/client/SquidInkParticleMixin.java b/src/main/java/io/ix0rai/rainglow/mixin/client/SquidInkParticleMixin.java index 797c136..a6ae80b 100644 --- a/src/main/java/io/ix0rai/rainglow/mixin/client/SquidInkParticleMixin.java +++ b/src/main/java/io/ix0rai/rainglow/mixin/client/SquidInkParticleMixin.java @@ -45,7 +45,7 @@ public void createParticle(DefaultParticleType defaultParticleType, ClientWorld // when we catch an exception we use white as it looks the most normal RainglowColour.RGB rgb; try { - rgb = Rainglow.getInkRgb(colourIndex); + rgb = RainglowColour.getInkRgb(colourIndex); } catch (IndexOutOfBoundsException ignored) { rgb = RainglowColour.WHITE.getInkRgb(); }