From 5b83400b68edc1f419b9d8acd8f2634e0f327a1e Mon Sep 17 00:00:00 2001 From: ix0rai Date: Mon, 20 May 2024 23:45:02 -0500 Subject: [PATCH] misc fixes --- .../java/io/ix0rai/rainglow/Rainglow.java | 8 ++++-- .../ix0rai/rainglow/data/RainglowEntity.java | 14 +++++++--- .../ix0rai/rainglow/mixin/MobEntityMixin.java | 27 ++++++++++--------- .../client/AllayEntityRendererMixin.java | 1 - .../mixin/client/SlimeParticleMixin.java | 2 +- 5 files changed, 32 insertions(+), 20 deletions(-) diff --git a/src/main/java/io/ix0rai/rainglow/Rainglow.java b/src/main/java/io/ix0rai/rainglow/Rainglow.java index 4fc07ba..050fb4f 100644 --- a/src/main/java/io/ix0rai/rainglow/Rainglow.java +++ b/src/main/java/io/ix0rai/rainglow/Rainglow.java @@ -123,7 +123,11 @@ public static RainglowColour.RGB getPassiveParticleRGB(int index, RandomGenerato return random.nextBoolean() ? colour.getPassiveParticleRgb() : colour.getAltPassiveParticleRgb(); } - public static Item getItem(int index) { + public static Item getItem(RainglowEntity entity, int index) { + if (index == -1) { + return entity.getDefaultColour().getItem(); + } + return COLOURS.get(index).getItem(); } @@ -164,7 +168,7 @@ public static TrackedData getTrackedColourData(RainglowEntity entityType public static String getColour(RainglowEntity entityType, DataTracker tracker, RandomGenerator random) { // generate random colour if the squid's colour isn't currently loaded String colour = tracker.get(getTrackedColourData(entityType)); - if (colourUnloaded(colour)) { + if (colourUnloaded(colour) && !colour.equals(entityType.getDefaultColour().getId())) { // Use last generated colour if not null else generate a new colour tracker.set(getTrackedColourData(entityType), generateRandomColourId(random)); colour = tracker.get(getTrackedColourData(entityType)); diff --git a/src/main/java/io/ix0rai/rainglow/data/RainglowEntity.java b/src/main/java/io/ix0rai/rainglow/data/RainglowEntity.java index 76039b8..3f87647 100644 --- a/src/main/java/io/ix0rai/rainglow/data/RainglowEntity.java +++ b/src/main/java/io/ix0rai/rainglow/data/RainglowEntity.java @@ -7,9 +7,9 @@ import java.util.HashMap; public enum RainglowEntity { - GLOW_SQUID("glow_squid"), - ALLAY("allay"), - SLIME("slime"); + GLOW_SQUID("glow_squid", RainglowColour.BLUE), + ALLAY("allay", RainglowColour.BLUE), + SLIME("slime", RainglowColour.LIME); private static final HashMap BY_ID = new HashMap<>(); static { @@ -17,15 +17,21 @@ public enum RainglowEntity { } private final String id; + private final RainglowColour defaultColour; - RainglowEntity(String id) { + RainglowEntity(String id, RainglowColour defaultColour) { this.id = id; + this.defaultColour = defaultColour; } public String getId() { return this.id; } + public RainglowColour getDefaultColour() { + return this.defaultColour; + } + public static RainglowEntity read(PacketByteBuf buf) { return get(buf.readString()); } diff --git a/src/main/java/io/ix0rai/rainglow/mixin/MobEntityMixin.java b/src/main/java/io/ix0rai/rainglow/mixin/MobEntityMixin.java index 6ab5ea5..d41e488 100644 --- a/src/main/java/io/ix0rai/rainglow/mixin/MobEntityMixin.java +++ b/src/main/java/io/ix0rai/rainglow/mixin/MobEntityMixin.java @@ -17,7 +17,6 @@ import net.minecraft.entity.mob.SlimeEntity; import net.minecraft.entity.passive.AllayEntity; import net.minecraft.entity.passive.GlowSquidEntity; -import net.minecraft.util.random.RandomGenerator; import net.minecraft.world.LocalDifficulty; import net.minecraft.world.ServerWorldAccess; import net.minecraft.world.World; @@ -38,23 +37,27 @@ protected MobEntityMixin(EntityType entityType, World world @Inject(method = "initialize", at = @At("RETURN"), cancellable = true) public void initialize(ServerWorldAccess world, LocalDifficulty difficulty, SpawnReason spawnReason, @Nullable EntityData entityData, CallbackInfoReturnable cir) { if ((Object) this instanceof GlowSquidEntity glowSquid) { - String colour = Rainglow.generateRandomColourId(this.getRandom()); - ((GlowSquidVariantProvider) glowSquid).setVariant(getColourOrDefault(this.random, RainglowColour.BLUE, colour)); - cir.setReturnValue(new GlowSquidEntityData(getColourOrDefault(this.random, RainglowColour.BLUE, colour))); + RainglowColour colour = generateColour(); + ((GlowSquidVariantProvider) glowSquid).setVariant(colour); + cir.setReturnValue(new GlowSquidEntityData(colour)); } else if ((Object) this instanceof AllayEntity allay) { - String colour = Rainglow.generateRandomColourId(this.getRandom()); - ((AllayVariantProvider) allay).setVariant(getColourOrDefault(this.random, RainglowColour.BLUE, colour)); - cir.setReturnValue(new AllayEntityData(getColourOrDefault(this.random, RainglowColour.BLUE, colour))); + RainglowColour colour = generateColour(); + ((AllayVariantProvider) allay).setVariant(colour); + cir.setReturnValue(new AllayEntityData(colour)); } else if ((Object) this instanceof SlimeEntity slime) { - String colour = Rainglow.generateRandomColourId(this.getRandom()); - ((SlimeVariantProvider) slime).setVariant(getColourOrDefault(this.random, RainglowColour.LIME, colour)); - cir.setReturnValue(new SlimeEntityData(getColourOrDefault(this.random, RainglowColour.LIME, colour))); + RainglowColour colour = generateColour(); + ((SlimeVariantProvider) slime).setVariant(colour); + cir.setReturnValue(new SlimeEntityData(colour)); } } @Unique - private RainglowColour getColourOrDefault(RandomGenerator random, RainglowColour defaultColour, String randomColour) { - return random.nextInt(100) >= Rainglow.CONFIG.getRarity(this.getCurrentEntity()) ? defaultColour : RainglowColour.get(randomColour); + private RainglowColour generateColour() { + RainglowEntity entity = getCurrentEntity(); + int i = random.nextInt(100); + int rarity = Rainglow.CONFIG.getRarity(entity); + + return i >= rarity ? entity.getDefaultColour() : RainglowColour.get(Rainglow.generateRandomColourId(this.random)); } @Unique 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 7efc1f6..28cb0a1 100644 --- a/src/main/java/io/ix0rai/rainglow/mixin/client/AllayEntityRendererMixin.java +++ b/src/main/java/io/ix0rai/rainglow/mixin/client/AllayEntityRendererMixin.java @@ -13,7 +13,6 @@ @Mixin(AllayEntityRenderer.class) 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()); 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 6b6f56c..81de85d 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((int) g).getDefaultStack(); + ItemStack stack = Rainglow.getItem(RainglowEntity.SLIME, (int) g).getDefaultStack(); cir.setReturnValue(new ItemBreakParticle(clientWorld, d, e, f, stack)); } else { cir.setReturnValue(null);