forked from ChomeNS/chipmunkmod
Add saturation and value to rainbowname + a preview in gui settings
This commit is contained in:
parent
dcfbdfc544
commit
4dbf7925cc
4 changed files with 62 additions and 3 deletions
|
@ -1,13 +1,19 @@
|
|||
package land.chipmunk.chipmunkmod.modules;
|
||||
|
||||
import land.chipmunk.chipmunkmod.ChipmunkMod;
|
||||
import land.chipmunk.chipmunkmod.testclient.modules.fun.RainbowNameModule;
|
||||
import land.chipmunk.chipmunkmod.util.ColorUtilities;
|
||||
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
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.text.MutableText;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.text.TextContent;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.Timer;
|
||||
|
@ -30,6 +36,8 @@ public class RainbowName {
|
|||
|
||||
private int startHue = 0;
|
||||
public double speed = 1;
|
||||
public int saturation = 255;
|
||||
public int value = 255;
|
||||
|
||||
public void init () {
|
||||
final TimerTask task = new TimerTask() {
|
||||
|
@ -120,16 +128,21 @@ public class RainbowName {
|
|||
|
||||
Component component = Component.empty();
|
||||
StringBuilder essentialsNickname = new StringBuilder();
|
||||
MutableText preview = Text.empty();
|
||||
|
||||
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)));
|
||||
essentialsNickname.append("\u00a7#").append(color).append(character != ' ' ? character : '_');
|
||||
preview.append(Text.of(character+"").copy().withColor(colorRaw));
|
||||
hue = (hue + increment) % 360;
|
||||
}
|
||||
|
||||
CommandCore.INSTANCE.run("essentials:nick " + ChipmunkMod.CONFIG.defaultUsername + " " + essentialsNickname);
|
||||
|
||||
((RainbowNameModule.MutableTextWidget)RainbowNameModule.preview.widget).setText(preview);
|
||||
|
||||
startHue = (startHue + increment) % 360;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
|
|
@ -39,7 +39,7 @@ public class IntSliderOption extends Option<Integer> {
|
|||
@Override
|
||||
public void setValueFromString(String string) {
|
||||
optionValue = Integer.valueOf(string);
|
||||
sliderWidget.value = optionValue;
|
||||
sliderWidget.value = (double) (optionValue - minValue) / (maxValue - minValue);
|
||||
sliderWidget.updateMessage();
|
||||
}
|
||||
|
||||
|
|
|
@ -2,22 +2,67 @@ package land.chipmunk.chipmunkmod.testclient.modules.fun;
|
|||
|
||||
import land.chipmunk.chipmunkmod.modules.RainbowName;
|
||||
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.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 static RainbowNameModule instance = new RainbowNameModule();
|
||||
public static DoubleSliderOption speedOption;
|
||||
public static IntSliderOption saturationOption;
|
||||
public static IntSliderOption valueOption;
|
||||
public static Preview preview;
|
||||
public RainbowNameModule() {
|
||||
super("Rainbow name");
|
||||
speedOption = new DoubleSliderOption("Speed", 1, 0.1, 2, 2);
|
||||
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;
|
||||
// onActivate(RainbowName.INSTANCE::enable);
|
||||
onDeactivate(RainbowName.INSTANCE::disable);
|
||||
atEndTick(() -> {
|
||||
RainbowName.INSTANCE.enable();
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,3 +3,4 @@ accessible field net/minecraft/client/gui/screen/Screen drawables Ljava/util/Lis
|
|||
accessible field net/minecraft/client/gui/widget/CheckboxWidget checked Z
|
||||
accessible field net/minecraft/client/gui/widget/SliderWidget value D
|
||||
accessible method net/minecraft/client/gui/widget/SliderWidget updateMessage ()V
|
||||
accessible field net/minecraft/client/gui/widget/ClickableWidget message Lnet/minecraft/text/Text;
|
Loading…
Reference in a new issue