Skip to content

Commit

Permalink
allow disabling dyeing - off by default
Browse files Browse the repository at this point in the history
  • Loading branch information
ix0rai committed Jun 2, 2024
1 parent 6e03486 commit 79b3726
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
2 changes: 2 additions & 0 deletions src/main/java/io/ix0rai/rainglow/config/RainglowConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public class RainglowConfig extends ReflectiveConfig {
public final TrackedValue<ValueMap<Boolean>> toggles = this.createMap(true);
@Comment("The custom colours to use when the mode is set to custom.")
public final TrackedValue<ValueList<String>> customColours = this.list("", RainglowMode.getDefaultCustom().stream().map(RainglowColour::getId).toArray(String[]::new));
@Comment("Whether to allow recolouring entities via dyes.")
public final TrackedValue<Boolean> allowDyeing = this.value(false);

public List<RainglowColour> getCustom() {
return this.customColours.value().stream().map(RainglowColour::get).collect(Collectors.toList());
Expand Down
26 changes: 14 additions & 12 deletions src/main/java/io/ix0rai/rainglow/mixin/DyeItemMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<ActionResult> 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()));
}
}
}

Expand Down

0 comments on commit 79b3726

Please sign in to comment.