From 79b3726c2cb7a4ac6f8d2648c28f221396efe5aa Mon Sep 17 00:00:00 2001 From: ix0rai Date: Sat, 1 Jun 2024 22:28:36 -0500 Subject: [PATCH] allow disabling dyeing - off by default --- .../rainglow/config/RainglowConfig.java | 2 ++ .../ix0rai/rainglow/mixin/DyeItemMixin.java | 26 ++++++++++--------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/main/java/io/ix0rai/rainglow/config/RainglowConfig.java b/src/main/java/io/ix0rai/rainglow/config/RainglowConfig.java index 2c4b228..c310d26 100644 --- a/src/main/java/io/ix0rai/rainglow/config/RainglowConfig.java +++ b/src/main/java/io/ix0rai/rainglow/config/RainglowConfig.java @@ -29,6 +29,8 @@ public class RainglowConfig extends ReflectiveConfig { public final TrackedValue> toggles = this.createMap(true); @Comment("The custom colours to use when the mode is set to custom.") public final TrackedValue> customColours = this.list("", RainglowMode.getDefaultCustom().stream().map(RainglowColour::getId).toArray(String[]::new)); + @Comment("Whether to allow recolouring entities via dyes.") + public final TrackedValue allowDyeing = this.value(false); public List getCustom() { return this.customColours.value().stream().map(RainglowColour::get).collect(Collectors.toList()); diff --git a/src/main/java/io/ix0rai/rainglow/mixin/DyeItemMixin.java b/src/main/java/io/ix0rai/rainglow/mixin/DyeItemMixin.java index abe992a..eb0f556 100644 --- a/src/main/java/io/ix0rai/rainglow/mixin/DyeItemMixin.java +++ b/src/main/java/io/ix0rai/rainglow/mixin/DyeItemMixin.java @@ -23,21 +23,23 @@ public class DyeItemMixin { @Inject(method = "useOnEntity", at = @At("TAIL"), cancellable = true) private void useOnEntity(ItemStack stack, PlayerEntity user, LivingEntity entity, Hand hand, CallbackInfoReturnable cir) { - String colour = getDye(stack); - RainglowEntity entityType = RainglowEntity.get(entity); + if (Rainglow.CONFIG.allowDyeing.value()) { + String colour = getDye(stack); + RainglowEntity entityType = RainglowEntity.get(entity); - if (entityType != null && !Rainglow.colourUnloaded(user.getWorld(), entityType, colour) - && Rainglow.CONFIG.isEntityEnabled(entityType) - && !Rainglow.getColour(user.getWorld(), entityType, entity.getDataTracker(), entity.getWorld().getRandom()).getId().equals(colour)) { - entity.getWorld().playSoundFromEntity(user, entity, SoundEvents.BLOCK_AMETHYST_CLUSTER_BREAK, SoundCategory.PLAYERS, 5.0f, 1.0f); - if (!user.getWorld().isClient()) { - stack.decrement(1); - } + if (entityType != null && !Rainglow.colourUnloaded(user.getWorld(), entityType, colour) + && Rainglow.CONFIG.isEntityEnabled(entityType) + && !Rainglow.getColour(user.getWorld(), entityType, entity.getDataTracker(), entity.getWorld().getRandom()).getId().equals(colour)) { + entity.getWorld().playSoundFromEntity(user, entity, SoundEvents.BLOCK_AMETHYST_CLUSTER_BREAK, SoundCategory.PLAYERS, 5.0f, 1.0f); + if (!user.getWorld().isClient()) { + stack.decrement(1); + } - DataTracker tracker = entity.getDataTracker(); - tracker.set(entityType.getTrackedData(), colour); + DataTracker tracker = entity.getDataTracker(); + tracker.set(entityType.getTrackedData(), colour); - cir.setReturnValue(ActionResult.success(user.getWorld().isClient())); + cir.setReturnValue(ActionResult.success(user.getWorld().isClient())); + } } }