Add saturation and value to rainbowname + a preview in gui settings

This commit is contained in:
blackilykat 2024-11-04 19:07:36 +01:00
parent dcfbdfc544
commit 4dbf7925cc
4 changed files with 62 additions and 3 deletions

View file

@ -1,13 +1,19 @@
package land.chipmunk.chipmunkmod.modules; package land.chipmunk.chipmunkmod.modules;
import land.chipmunk.chipmunkmod.ChipmunkMod; import land.chipmunk.chipmunkmod.ChipmunkMod;
import land.chipmunk.chipmunkmod.testclient.modules.fun.RainbowNameModule;
import land.chipmunk.chipmunkmod.util.ColorUtilities; import land.chipmunk.chipmunkmod.util.ColorUtilities;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.TextColor; import net.kyori.adventure.text.format.TextColor;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.widget.TextFieldWidget;
import net.minecraft.client.gui.widget.TextWidget;
import net.minecraft.client.network.ClientPlayNetworkHandler; import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
import net.minecraft.text.TextContent;
import java.util.Random; import java.util.Random;
import java.util.Timer; import java.util.Timer;
@ -30,6 +36,8 @@ public class RainbowName {
private int startHue = 0; private int startHue = 0;
public double speed = 1; public double speed = 1;
public int saturation = 255;
public int value = 255;
public void init () { public void init () {
final TimerTask task = new TimerTask() { final TimerTask task = new TimerTask() {
@ -120,16 +128,21 @@ public class RainbowName {
Component component = Component.empty(); Component component = Component.empty();
StringBuilder essentialsNickname = new StringBuilder(); StringBuilder essentialsNickname = new StringBuilder();
MutableText preview = Text.empty();
for (char character : displayName.toCharArray()) { for (char character : displayName.toCharArray()) {
String color = String.format("%06x", ColorUtilities.hsvToRgb(hue, 100, 100)); int colorRaw = ColorUtilities.hsvToRgb(hue, saturation, value);
String color = String.format("%06x", colorRaw);
component = component.append(Component.text(character).color(TextColor.fromHexString("#" + color))); component = component.append(Component.text(character).color(TextColor.fromHexString("#" + color)));
essentialsNickname.append("\u00a7#").append(color).append(character != ' ' ? character : '_'); essentialsNickname.append("\u00a7#").append(color).append(character != ' ' ? character : '_');
preview.append(Text.of(character+"").copy().withColor(colorRaw));
hue = (hue + increment) % 360; hue = (hue + increment) % 360;
} }
CommandCore.INSTANCE.run("essentials:nick " + ChipmunkMod.CONFIG.defaultUsername + " " + essentialsNickname); CommandCore.INSTANCE.run("essentials:nick " + ChipmunkMod.CONFIG.defaultUsername + " " + essentialsNickname);
((RainbowNameModule.MutableTextWidget)RainbowNameModule.preview.widget).setText(preview);
startHue = (startHue + increment) % 360; startHue = (startHue + increment) % 360;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();

View file

@ -39,7 +39,7 @@ public class IntSliderOption extends Option<Integer> {
@Override @Override
public void setValueFromString(String string) { public void setValueFromString(String string) {
optionValue = Integer.valueOf(string); optionValue = Integer.valueOf(string);
sliderWidget.value = optionValue; sliderWidget.value = (double) (optionValue - minValue) / (maxValue - minValue);
sliderWidget.updateMessage(); sliderWidget.updateMessage();
} }

View file

@ -2,22 +2,67 @@ package land.chipmunk.chipmunkmod.testclient.modules.fun;
import land.chipmunk.chipmunkmod.modules.RainbowName; import land.chipmunk.chipmunkmod.modules.RainbowName;
import land.chipmunk.chipmunkmod.testclient.gui.components.Module; import land.chipmunk.chipmunkmod.testclient.gui.components.Module;
import land.chipmunk.chipmunkmod.testclient.gui.components.Option;
import land.chipmunk.chipmunkmod.testclient.gui.components.options.DoubleSliderOption; import land.chipmunk.chipmunkmod.testclient.gui.components.options.DoubleSliderOption;
import land.chipmunk.chipmunkmod.testclient.gui.components.options.IntSliderOption;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.widget.TextWidget;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
public class RainbowNameModule extends Module { public class RainbowNameModule extends Module {
public static RainbowNameModule instance = new RainbowNameModule(); public static RainbowNameModule instance = new RainbowNameModule();
public static DoubleSliderOption speedOption; public static DoubleSliderOption speedOption;
public static IntSliderOption saturationOption;
public static IntSliderOption valueOption;
public static Preview preview;
public RainbowNameModule() { public RainbowNameModule() {
super("Rainbow name"); super("Rainbow name");
speedOption = new DoubleSliderOption("Speed", 1, 0.1, 2, 2); speedOption = new DoubleSliderOption("Speed", 1, 0.1, 2, 2);
withOption(speedOption); withOption(speedOption);
saturationOption = new IntSliderOption("Saturation", 100, 0, 100);
withOption(saturationOption);
valueOption = new IntSliderOption("Value", 100, 0, 100);
withOption(valueOption);
preview = new Preview("Preview");
withOption(preview);
needsInWorld = true; needsInWorld = true;
// onActivate(RainbowName.INSTANCE::enable); // onActivate(RainbowName.INSTANCE::enable);
onDeactivate(RainbowName.INSTANCE::disable); onDeactivate(RainbowName.INSTANCE::disable);
atEndTick(() -> { atEndTick(() -> {
RainbowName.INSTANCE.enable(); RainbowName.INSTANCE.enable();
RainbowName.INSTANCE.speed = speedOption.optionValue; RainbowName.INSTANCE.speed = speedOption.optionValue;
RainbowName.INSTANCE.saturation = saturationOption.optionValue;
RainbowName.INSTANCE.value = valueOption.optionValue;
}); });
} }
public static class Preview extends Option<Void> {
public Preview(String name) {
super(name, null);
widget = new MutableTextWidget(Text.empty(), MinecraftClient.getInstance().textRenderer);
}
@Override
public void setValueFromString(String string) { }
@Override
public String getValueAsString() {
return "null";
}
}
public static class MutableTextWidget extends TextWidget {
public MutableTextWidget(Text message, TextRenderer textRenderer) {
super(100, 20, message, textRenderer);
}
public void setText(Text text) {
this.message = text;
}
}
} }

View file

@ -2,4 +2,5 @@ accessWidener v2 named
accessible field net/minecraft/client/gui/screen/Screen drawables Ljava/util/List; accessible field net/minecraft/client/gui/screen/Screen drawables Ljava/util/List;
accessible field net/minecraft/client/gui/widget/CheckboxWidget checked Z accessible field net/minecraft/client/gui/widget/CheckboxWidget checked Z
accessible field net/minecraft/client/gui/widget/SliderWidget value D accessible field net/minecraft/client/gui/widget/SliderWidget value D
accessible method net/minecraft/client/gui/widget/SliderWidget updateMessage ()V accessible method net/minecraft/client/gui/widget/SliderWidget updateMessage ()V
accessible field net/minecraft/client/gui/widget/ClickableWidget message Lnet/minecraft/text/Text;