diff options
Diffstat (limited to 'src/main/java')
18 files changed, 172 insertions, 132 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/BuildFlags.java b/src/main/java/io/github/moulberry/notenoughupdates/BuildFlags.java index d997d980..2091496d 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/BuildFlags.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/BuildFlags.java @@ -50,6 +50,7 @@ public class BuildFlags { } public static final boolean ENABLE_PRONOUNS_IN_PV_BY_DEFAULT = getBuildFlag("pronouns"); + public static final boolean ENABLE_ONECONFIG_COMPAT_LAYER = getBuildFlag("oneconfig"); private static class Holder { static Map<String, Boolean> ALL_FLAGS = new HashMap<>(); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java index f10db528..d6ae6219 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java @@ -79,6 +79,7 @@ import io.github.moulberry.notenoughupdates.miscgui.SignCalculator; import io.github.moulberry.notenoughupdates.miscgui.TrophyRewardOverlay; import io.github.moulberry.notenoughupdates.miscgui.minionhelper.MinionHelperManager; import io.github.moulberry.notenoughupdates.mixins.AccessorMinecraft; +import io.github.moulberry.notenoughupdates.oneconfig.IOneConfigCompat; import io.github.moulberry.notenoughupdates.options.NEUConfig; import io.github.moulberry.notenoughupdates.overlays.EquipmentOverlay; import io.github.moulberry.notenoughupdates.overlays.FuelBar; @@ -294,6 +295,8 @@ public class NotEnoughUpdates { if (config.mining.powderGrindingTrackerResetMode == 2) OverlayManager.powderGrindingOverlay.load(); + IOneConfigCompat.getInstance().ifPresent(it -> it.initConfig(config, this::saveConfig)); + MinecraftForge.EVENT_BUS.register(this); MinecraftForge.EVENT_BUS.register(new NEUEventListener(this)); MinecraftForge.EVENT_BUS.register(new RecipeGenerator(this)); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/ChromaColour.java b/src/main/java/io/github/moulberry/notenoughupdates/core/ChromaColour.java index 05a9a65e..fb7b2abe 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/core/ChromaColour.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/ChromaColour.java @@ -38,7 +38,8 @@ public class ChromaColour { return sb.toString(); } - private static int[] decompose(String csv) { + @Deprecated + public static int[] decompose(String csv) { String[] split = csv.split(":"); int[] arr = new int[split.length]; @@ -68,6 +69,10 @@ public class ChromaColour { return (255 - speed) / 254f * (MAX_CHROMA_SECS - MIN_CHROMA_SECS) + MIN_CHROMA_SECS; } + public static int getSpeedForSeconds(float seconds) { + return (int) (255 - (seconds - MIN_CHROMA_SECS) * 254f / (MAX_CHROMA_SECS - MIN_CHROMA_SECS)); + } + private static final int MIN_CHROMA_SECS = 1; private static final int MAX_CHROMA_SECS = 60; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/GuiElementBoolean.java b/src/main/java/io/github/moulberry/notenoughupdates/core/GuiElementBoolean.java index 11547aaa..ab176933 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/core/GuiElementBoolean.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/GuiElementBoolean.java @@ -28,11 +28,12 @@ import net.minecraft.util.ResourceLocation; import org.lwjgl.input.Mouse; import java.util.function.Consumer; +import java.util.function.Supplier; public class GuiElementBoolean extends GuiElement { public int x; public int y; - private boolean value; + private Supplier<Boolean> value; private final int clickRadius; private final Consumer<Boolean> toggleCallback; @@ -43,20 +44,20 @@ public class GuiElementBoolean extends GuiElement { private static final int xSize = 48; private static final int ySize = 14; - public GuiElementBoolean(int x, int y, boolean value, Consumer<Boolean> toggleCallback) { + public GuiElementBoolean(int x, int y, Supplier<Boolean> value, Consumer<Boolean> toggleCallback) { this(x, y, value, 0, toggleCallback); } - public GuiElementBoolean(int x, int y, boolean value, int clickRadius, Consumer<Boolean> toggleCallback) { + public GuiElementBoolean(int x, int y, Supplier<Boolean> value, int clickRadius, Consumer<Boolean> toggleCallback) { this.x = x; this.y = y; this.value = value; - this.previewValue = value; + this.previewValue = value.get(); this.clickRadius = clickRadius; this.toggleCallback = toggleCallback; this.lastMillis = System.currentTimeMillis(); - if (value) animation = 36; + if (previewValue) animation = 36; } @Override @@ -70,7 +71,7 @@ public class GuiElementBoolean extends GuiElement { long deltaMillis = currentMillis - lastMillis; lastMillis = currentMillis; boolean passedLimit = false; - if (previewValue != value) { + if (previewValue != value.get()) { if ((previewValue && animation > 12) || (!previewValue && animation < 24)) { passedLimit = true; @@ -83,7 +84,7 @@ public class GuiElementBoolean extends GuiElement { } lastMillis -= deltaMillis % 10; - if (previewValue == value) { + if (previewValue == value.get()) { animation = Math.max(0, Math.min(36, animation)); } else if (!passedLimit) { if (previewValue) { @@ -120,14 +121,13 @@ public class GuiElementBoolean extends GuiElement { mouseY > y - clickRadius && mouseY < y + ySize + clickRadius) { if (Mouse.getEventButton() == 0) { if (Mouse.getEventButtonState()) { - previewValue = !value; - } else if (previewValue == !value) { - value = !value; - toggleCallback.accept(value); + previewValue = !value.get(); + } else if (previewValue == !value.get()) { + toggleCallback.accept(!value.get()); } } } else { - previewValue = value; + previewValue = value.get(); } return false; } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/GuiElementColour.java b/src/main/java/io/github/moulberry/notenoughupdates/core/GuiElementColour.java index 1f655aaf..1802a1a4 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/core/GuiElementColour.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/GuiElementColour.java @@ -35,6 +35,7 @@ import org.lwjgl.opengl.GL11; import java.awt.*; import java.awt.image.BufferedImage; import java.util.function.Consumer; +import java.util.function.Supplier; public class GuiElementColour extends GuiElement { public static final ResourceLocation colour_selector_dot = new ResourceLocation( @@ -68,20 +69,20 @@ public class GuiElementColour extends GuiElement { private final Consumer<String> colourChangedCallback; private final Runnable closeCallback; - private String colour; + private Supplier<String> colour; private final boolean opacitySlider; private final boolean valueSlider; public GuiElementColour( - int x, int y, String initialColour, Consumer<String> colourChangedCallback, + int x, int y, Supplier<String> colour, Consumer<String> colourChangedCallback, Runnable closeCallback ) { - this(x, y, initialColour, colourChangedCallback, closeCallback, true, true); + this(x, y, colour, colourChangedCallback, closeCallback, true, true); } public GuiElementColour( - int x, int y, String initialColour, Consumer<String> colourChangedCallback, + int x, int y, Supplier<String> colour, Consumer<String> colourChangedCallback, Runnable closeCallback, boolean opacitySlider, boolean valueSlider ) { final ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); @@ -89,12 +90,12 @@ public class GuiElementColour extends GuiElement { this.y = Math.max(10, Math.min(scaledResolution.getScaledHeight() - ySize - 10, y)); this.x = Math.max(10, Math.min(scaledResolution.getScaledWidth() - xSize - 10, x)); - this.colour = initialColour; + this.colour = colour; this.colourChangedCallback = colourChangedCallback; this.closeCallback = closeCallback; - int colour = ChromaColour.specialToSimpleRGB(initialColour); - Color c = new Color(colour); + int icolour = ChromaColour.specialToSimpleRGB(colour.get()); + Color c = new Color(icolour); float[] hsv = Color.RGBtoHSB(c.getRed(), c.getGreen(), c.getBlue(), null); updateAngleAndRadius(hsv); @@ -113,7 +114,7 @@ public class GuiElementColour extends GuiElement { public void render() { RenderUtils.drawFloatingRectDark(x, y, xSize, ySize); - int currentColour = ChromaColour.specialToSimpleRGB(colour); + int currentColour = ChromaColour.specialToSimpleRGB(colour.get()); Color c = new Color(currentColour, true); float[] hsv = Color.RGBtoHSB(c.getRed(), c.getGreen(), c.getBlue(), null); @@ -200,8 +201,8 @@ public class GuiElementColour extends GuiElement { RenderUtils.drawTexturedRect(x + 5 + 64 + 5 + valueOffset, y + 5, 10, 64, GL11.GL_NEAREST); } - int chromaSpeed = ChromaColour.getSpeed(colour); - int currentColourChroma = ChromaColour.specialToChromaRGB(colour); + int chromaSpeed = ChromaColour.getSpeed(colour.get()); + int currentColourChroma = ChromaColour.specialToChromaRGB(colour.get()); Color cChroma = new Color(currentColourChroma, true); float[] hsvChroma = Color.RGBtoHSB(cChroma.getRed(), cChroma.getGreen(), cChroma.getBlue(), null); @@ -343,7 +344,7 @@ public class GuiElementColour extends GuiElement { } } - int chromaSpeed = ChromaColour.getSpeed(colour); + int chromaSpeed = ChromaColour.getSpeed(colour.get()); int xChroma = mouseX - (x + 5 + 64 + valueOffset + opacityOffset + 5); if (xChroma > 0 && xChroma < 10) { if (chromaSpeed > 0) { @@ -351,10 +352,9 @@ public class GuiElementColour extends GuiElement { clickedComponent = 3; } } else if (mouseY > this.y + 5 + 27 && mouseY < this.y + 5 + 37) { - int currentColour = ChromaColour.specialToSimpleRGB(colour); + int currentColour = ChromaColour.specialToSimpleRGB(colour.get()); Color c = new Color(currentColour, true); - colour = ChromaColour.special(200, c.getAlpha(), currentColour); - colourChangedCallback.accept(colour); + colourChangedCallback.accept(ChromaColour.special(200, c.getAlpha(), currentColour)); } } } else { @@ -364,7 +364,7 @@ public class GuiElementColour extends GuiElement { } } if (Mouse.isButtonDown(0) && clickedComponent >= 0) { - int currentColour = ChromaColour.specialToSimpleRGB(colour); + int currentColour = ChromaColour.specialToSimpleRGB(colour.get()); Color c = new Color(currentColour, true); float[] hsv = Color.RGBtoHSB(c.getRed(), c.getGreen(), c.getBlue(), null); @@ -381,8 +381,7 @@ public class GuiElementColour extends GuiElement { this.wheelAngle = angle; this.wheelRadius = (float) Math.pow(Math.min(1, radius), 1.5f); int rgb = Color.getHSBColor(angle / 360f, wheelRadius, hsv[2]).getRGB(); - colour = ChromaColour.special(ChromaColour.getSpeed(colour), c.getAlpha(), rgb); - colourChangedCallback.accept(colour); + colourChangedCallback.accept(ChromaColour.special(ChromaColour.getSpeed(colour.get()), c.getAlpha(), rgb)); return true; } @@ -392,22 +391,19 @@ public class GuiElementColour extends GuiElement { if (clickedComponent == 1) { int rgb = Color.getHSBColor(wheelAngle / 360, wheelRadius, 1 - y / 64f).getRGB(); - colour = ChromaColour.special(ChromaColour.getSpeed(colour), c.getAlpha(), rgb); - colourChangedCallback.accept(colour); + colourChangedCallback.accept(ChromaColour.special(ChromaColour.getSpeed(colour.get()), c.getAlpha(), rgb)); return true; } if (clickedComponent == 2) { - colour = ChromaColour.special(ChromaColour.getSpeed(colour), + colourChangedCallback.accept(ChromaColour.special(ChromaColour.getSpeed(colour.get()), 255 - Math.round(y / 64f * 255), currentColour - ); - colourChangedCallback.accept(colour); + )); return true; } if (clickedComponent == 3) { - colour = ChromaColour.special(255 - Math.round(y / 64f * 255), c.getAlpha(), currentColour); - colourChangedCallback.accept(colour); + colourChangedCallback.accept(ChromaColour.special(255 - Math.round(y / 64f * 255), c.getAlpha(), currentColour)); } return true; } @@ -431,9 +427,8 @@ public class GuiElementColour extends GuiElement { String text = hexField.getText().toLowerCase(); int rgb = Integer.parseInt(text, 16); - int alpha = (ChromaColour.specialToSimpleRGB(colour) >> 24) & 0xFF; - colour = ChromaColour.special(ChromaColour.getSpeed(colour), alpha, rgb); - colourChangedCallback.accept(colour); + int alpha = (ChromaColour.specialToSimpleRGB(colour.get()) >> 24) & 0xFF; + colourChangedCallback.accept(ChromaColour.special(ChromaColour.getSpeed(colour.get()), alpha, rgb)); Color c = new Color(rgb); float[] hsv = Color.RGBtoHSB(c.getRed(), c.getGreen(), c.getBlue(), null); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorAccordion.java b/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorAccordion.java index dc1173ef..91515259 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorAccordion.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorAccordion.java @@ -32,11 +32,9 @@ import org.lwjgl.opengl.GL11; public class GuiOptionEditorAccordion extends GuiOptionEditor { private final int accordionId; - private boolean accordionToggled; public GuiOptionEditorAccordion(ConfigProcessor.ProcessedOption option, int accordionId) { super(option); - this.accordionToggled = (boolean) option.get(); this.accordionId = accordionId; } @@ -50,7 +48,7 @@ public class GuiOptionEditorAccordion extends GuiOptionEditor { } public boolean getToggled() { - return accordionToggled; + return (boolean) option.get(); } @Override @@ -65,7 +63,7 @@ public class GuiOptionEditorAccordion extends GuiOptionEditor { GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); GlStateManager.color(1, 1, 1, 1); worldrenderer.begin(GL11.GL_TRIANGLES, DefaultVertexFormats.POSITION); - if (accordionToggled) { + if (getToggled()) { worldrenderer.pos((double) x + 6, (double) y + 6, 0.0D).endVertex(); worldrenderer.pos((double) x + 9.75f, (double) y + 13.5f, 0.0D).endVertex(); worldrenderer.pos((double) x + 13.5f, (double) y + 6, 0.0D).endVertex(); @@ -87,7 +85,7 @@ public class GuiOptionEditorAccordion extends GuiOptionEditor { public boolean mouseInput(int x, int y, int width, int mouseX, int mouseY) { if (Mouse.getEventButtonState() && mouseX > x && mouseX < x + width && mouseY > y && mouseY < y + getHeight()) { - accordionToggled = !accordionToggled; + option.set(!getToggled()); return true; } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorBoolean.java b/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorBoolean.java index d12ec8e7..00907e9e 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorBoolean.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorBoolean.java @@ -37,7 +37,7 @@ public class GuiOptionEditorBoolean extends GuiOptionEditor { super(option); this.config = config; this.runnableId = runnableId; - bool = new GuiElementBoolean(0, 0, (boolean) option.get(), 10, (value) -> onUpdate(option, value)); + bool = new GuiElementBoolean(0, 0, () -> (boolean) option.get(), 10, (value) -> onUpdate(option, value)); } @Override diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorColour.java b/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorColour.java index ca4087b5..359a3e27 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorColour.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorColour.java @@ -30,13 +30,14 @@ import org.lwjgl.input.Mouse; import static io.github.moulberry.notenoughupdates.util.GuiTextures.button_white; public class GuiOptionEditorColour extends GuiOptionEditor { - private String chromaColour; private GuiElementColour colourElement = null; public GuiOptionEditorColour(ConfigProcessor.ProcessedOption option) { super(option); + } - this.chromaColour = (String) option.get(); + public String getChromaString() { + return (String) option.get(); } @Override @@ -44,7 +45,7 @@ public class GuiOptionEditorColour extends GuiOptionEditor { super.render(x, y, width); int height = getHeight(); - int argb = ChromaColour.specialToChromaRGB(chromaColour); + int argb = ChromaColour.specialToChromaRGB(getChromaString()); int r = (argb >> 16) & 0xFF; int g = (argb >> 8) & 0xFF; int b = argb & 0xFF; @@ -72,10 +73,8 @@ public class GuiOptionEditorColour extends GuiOptionEditor { if (Mouse.getEventButtonState() && Mouse.getEventButton() == 0 && mouseX > x + width / 6 - 24 && mouseX < x + width / 6 + 24 && mouseY > y + height - 7 - 14 && mouseY < y + height - 7 + 2) { - colourElement = new GuiElementColour(mouseX, mouseY, (String) option.get(), (val) -> { - option.set(val); - chromaColour = val; - }, () -> colourElement = null); + colourElement = new GuiElementColour(mouseX, mouseY, () -> (String) option.get(), + option::set, () -> colourElement = null); } return false; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorKeybind.java b/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorKeybind.java index 6eb71d1e..b7d70db8 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorKeybind.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorKeybind.java @@ -35,16 +35,18 @@ import static io.github.moulberry.notenoughupdates.util.GuiTextures.button_tex; public class GuiOptionEditorKeybind extends GuiOptionEditor { private static final ResourceLocation RESET = new ResourceLocation("notenoughupdates:itemcustomize/reset.png"); - private int keyCode; private final int defaultKeyCode; private boolean editingKeycode; - public GuiOptionEditorKeybind(ConfigProcessor.ProcessedOption option, int keyCode, int defaultKeyCode) { + public GuiOptionEditorKeybind(ConfigProcessor.ProcessedOption option, int defaultKeyCode) { super(option); - this.keyCode = keyCode; this.defaultKeyCode = defaultKeyCode; } + public int getKeyCode() { + return (int) option.get(); + } + @Override public void render(int x, int y, int width) { super.render(x, y, width); @@ -55,7 +57,7 @@ public class GuiOptionEditorKeybind extends GuiOptionEditor { Minecraft.getMinecraft().getTextureManager().bindTexture(button_tex); RenderUtils.drawTexturedRect(x + width / 6 - 24, y + height - 7 - 14, 48, 16); - String keyName = KeybindHelper.getKeyName(keyCode); + String keyName = KeybindHelper.getKeyName(getKeyCode()); String text = editingKeycode ? "> " + keyName + " <" : keyName; TextRenderUtils.drawStringCenteredScaledMaxWidth(text, Minecraft.getMinecraft().fontRendererObj, @@ -72,8 +74,7 @@ public class GuiOptionEditorKeybind extends GuiOptionEditor { public boolean mouseInput(int x, int y, int width, int mouseX, int mouseY) { if (Mouse.getEventButtonState() && Mouse.getEventButton() != -1 && editingKeycode) { editingKeycode = false; - keyCode = Mouse.getEventButton() - 100; - option.set(keyCode); + option.set(Mouse.getEventButton() - 100); return true; } @@ -86,8 +87,7 @@ public class GuiOptionEditorKeybind extends GuiOptionEditor { } if (mouseX > x + width / 6 - 24 + 48 + 3 && mouseX < x + width / 6 - 24 + 48 + 13 && mouseY > y + height - 7 - 14 + 3 && mouseY < y + height - 7 - 14 + 3 + 11) { - keyCode = defaultKeyCode; - option.set(keyCode); + option.set(defaultKeyCode); return true; } } @@ -99,13 +99,15 @@ public class GuiOptionEditorKeybind extends GuiOptionEditor { public boolean keyboardInput() { if (editingKeycode) { editingKeycode = false; + int keyCode = -1; if (Keyboard.getEventKey() == Keyboard.KEY_ESCAPE) { keyCode = 0; } else if (Keyboard.getEventKey() != 0) { keyCode = Keyboard.getEventKey(); } if (keyCode > 256) keyCode = 0; - option.set(keyCode); + if (keyCode != -1) + option.set(keyCode); return true; } return false; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorSlider.java b/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorSlider.java index 7fceb92d..175dcdc0 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorSlider.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorSlider.java @@ -34,35 +34,35 @@ public class GuiOptionEditorSlider extends GuiOptionEditor { super(option); if (minStep < 0) minStep = 0.01f; - float floatVal = ((Number) option.get()).floatValue(); - { - String strVal; - if (floatVal % 1 == 0) { - strVal = Integer.toString((int) floatVal); - } else { - strVal = Float.toString(floatVal); - } - textField = new GuiElementTextField( - strVal, - GuiElementTextField.NO_SPACE | GuiElementTextField.NUM_ONLY | GuiElementTextField.SCALE_TEXT - ); - } + float floatVal = getFloatValue(); + textField = new GuiElementTextField( + getStringifiedFloatValue(), + GuiElementTextField.NO_SPACE | GuiElementTextField.NUM_ONLY | GuiElementTextField.SCALE_TEXT + ); slider = new GuiElementSlider(0, 0, 80, minValue, maxValue, minStep, floatVal, (val) -> { option.set(val); - - String strVal; - if (val % 1 == 0) { - strVal = Integer.toString(val.intValue()); - } else { - strVal = Float.toString(val); - strVal = strVal.replaceAll("(\\.\\d\\d\\d)(?:\\d)+", "$1"); - strVal = strVal.replaceAll("0+$", ""); - } - textField.setText(strVal); + textField.setText(getStringifiedFloatValue()); }); } + public String getStringifiedFloatValue() { + float floatVal = getFloatValue(); + String strVal; + if (floatVal % 1 == 0) { + strVal = Integer.toString((int) floatVal); + } else { + strVal = Float.toString(floatVal); + strVal = strVal.replaceAll("(\\.\\d\\d\\d)\\d+", "$1"); + strVal = strVal.replaceAll("0+$", ""); + } + return strVal; + } + + public float getFloatValue() { + return ((Number) option.get()).floatValue(); + } + @Override public void render(int x, int y, int width) { super.render(x, y, width); @@ -72,6 +72,9 @@ public class GuiOptionEditorSlider extends GuiOptionEditor { int sliderWidth = (fullWidth - 5) * 3 / 4; int textFieldWidth = (fullWidth - 5) / 4; + if (!Mouse.isButtonDown(0)) { + slider.setValue(getFloatValue()); + } slider.x = x + width / 6 - fullWidth / 2; slider.y = y + height - 7 - 14; slider.width = sliderWidth; @@ -84,6 +87,7 @@ public class GuiOptionEditorSlider extends GuiOptionEditor { 16 ); } else { + textField.setText(getStringifiedFloatValue()); textField.setSize(textFieldWidth, 16); textField.setOptions( GuiElementTextField.NO_SPACE | GuiElementTextField.NUM_ONLY | GuiElementTextField.SCALE_TEXT); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorText.java b/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorText.java index ad2fa4db..48072fbe 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorText.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/config/gui/GuiOptionEditorText.java @@ -47,6 +47,8 @@ public class GuiOptionEditorText extends GuiOptionEditor { fullWidth, Minecraft.getMinecraft().fontRendererObj.getStringWidth(textField.getText()) + 10 ); + } else { + textField.setText((String) option.get()); } textField.setSize(fullWidth, 16); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/core/config/struct/ConfigProcessor.java b/src/main/java/io/github/moulberry/notenoughupdates/core/config/struct/ConfigProcessor.java index efdeab01..9a75ec19 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/core/config/struct/ConfigProcessor.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/core/config/struct/ConfigProcessor.java @@ -152,7 +152,7 @@ public class ConfigProcessor { if (optionType.isAssignableFrom(int.class) && optionField.isAnnotationPresent(ConfigEditorKeybind.class)) { ConfigEditorKeybind configEditorAnnotation = optionField.getAnnotation(ConfigEditorKeybind.class); - editor = new GuiOptionEditorKeybind(option, (int) option.get(), configEditorAnnotation.defaultKey()); + editor = new GuiOptionEditorKeybind(option, configEditorAnnotation.defaultKey()); } if (optionField.isAnnotationPresent(ConfigEditorButton.class)) { ConfigEditorButton configEditorAnnotation = optionField.getAnnotation(ConfigEditorButton.class); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/dungeons/GuiDungeonMapEditor.java b/src/main/java/io/github/moulberry/notenoughupdates/dungeons/GuiDungeonMapEditor.java index 98d36f2b..025e11b2 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/dungeons/GuiDungeonMapEditor.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/dungeons/GuiDungeonMapEditor.java @@ -744,7 +744,7 @@ public class GuiDungeonMapEditor extends GuiScreen { ScaledResolution realRes = new ScaledResolution(Minecraft.getMinecraft()); mouseX = Mouse.getEventX() * realRes.getScaledWidth() / this.mc.displayWidth; mouseY = realRes.getScaledHeight() - Mouse.getEventY() * realRes.getScaledHeight() / this.mc.displayHeight - 1; - activeColourEditor = new GuiElementColour(mouseX, mouseY, options.dmBackgroundColour, + activeColourEditor = new GuiElementColour(mouseX, mouseY, () -> options.dmBackgroundColour, (col) -> options.dmBackgroundColour = col, () -> activeColourEditor = null ); } @@ -753,7 +753,7 @@ public class GuiDungeonMapEditor extends GuiScreen { ScaledResolution realRes = new ScaledResolution(Minecraft.getMinecraft()); mouseX = Mouse.getEventX() * realRes.getScaledWidth() / this.mc.displayWidth; mouseY = realRes.getScaledHeight() - Mouse.getEventY() * realRes.getScaledHeight() / this.mc.displayHeight - 1; - activeColourEditor = new GuiElementColour(mouseX, mouseY, options.dmBorderColour, + activeColourEditor = new GuiElementColour(mouseX, mouseY, () -> options.dmBorderColour, (col) -> options.dmBorderColour = col, () -> activeColourEditor = null ); } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/loader/NEUDelegatingTweaker.java b/src/main/java/io/github/moulberry/notenoughupdates/loader/NEUDelegatingTweaker.java index 1d91ca76..d7759c9a 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/loader/NEUDelegatingTweaker.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/loader/NEUDelegatingTweaker.java @@ -19,14 +19,15 @@ package io.github.moulberry.notenoughupdates.loader; +import io.github.moulberry.notenoughupdates.BuildFlags; import io.github.moulberry.notenoughupdates.envcheck.EnvironmentScan; import net.minecraft.launchwrapper.ITweaker; +import net.minecraft.launchwrapper.Launch; import net.minecraft.launchwrapper.LaunchClassLoader; import org.spongepowered.asm.launch.MixinTweaker; import java.io.File; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; /** @@ -48,7 +49,7 @@ public class NEUDelegatingTweaker implements ITweaker { EnvironmentScan.checkEnvironmentOnce(); } - List<ITweaker> delegates = new ArrayList<>(); + List<String> delegates = new ArrayList<>(); public NEUDelegatingTweaker() { discoverTweakers(); @@ -56,45 +57,32 @@ public class NEUDelegatingTweaker implements ITweaker { } private void discoverTweakers() { - delegates.add(new MixinTweaker()); - delegates.add(new ModLoadingTweaker()); - delegates.add(new KotlinLoadingTweaker()); + if (BuildFlags.ENABLE_ONECONFIG_COMPAT_LAYER) { + delegates.add("cc.polyfrost.oneconfigwrapper.OneConfigWrapper"); + } + delegates.add(MixinTweaker.class.getName()); + delegates.add(ModLoadingTweaker.class.getName()); + delegates.add(KotlinLoadingTweaker.class.getName()); } @Override public void acceptOptions(List<String> args, File gameDir, File assetsDir, String profile) { - for (ITweaker delegate : delegates) { - delegate.acceptOptions(args, gameDir, assetsDir, profile); - } + List<String> tweakClasses = (List<String>) Launch.blackboard.get("TweakClasses"); + tweakClasses.addAll(delegates); } @Override public void injectIntoClassLoader(LaunchClassLoader classLoader) { - for (ITweaker delegate : delegates) { - delegate.injectIntoClassLoader(classLoader); - } } @Override public String getLaunchTarget() { - String target = null; - for (ITweaker delegate : delegates) { - String launchTarget = delegate.getLaunchTarget(); - if (launchTarget != null) - target = launchTarget; - } - return target; + return null; } @Override public String[] getLaunchArguments() { - List<String> launchArguments = new ArrayList<>(); - for (ITweaker delegate : delegates) { - String[] delegateLaunchArguments = delegate.getLaunchArguments(); - if (delegateLaunchArguments != null) - launchArguments.addAll(Arrays.asList(delegateLaunchArguments)); - } - return launchArguments.toArray(new String[0]); + return new String[0]; } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiItemCustomize.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiItemCustomize.java index 674e4068..129699da 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiItemCustomize.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiItemCustomize.java @@ -92,7 +92,7 @@ public class GuiItemCustomize extends GuiScreen { ((ItemArmor) stack.getItem()).getArmorMaterial() == ItemArmor.ArmorMaterial.LEATHER; enchantGlintCustomColourAnimation.setValue(enchantGlint ? 17 : 0); - this.enchantGlintButton = new GuiElementBoolean(0, 0, enchantGlint, (bool) -> { + this.enchantGlintButton = new GuiElementBoolean(0, 0, () -> enchantGlint, (bool) -> { enchantGlint = bool; updateData(); }); @@ -443,7 +443,7 @@ public class GuiItemCustomize extends GuiScreen { editor = new GuiElementColour( mouseX, mouseY, - customGlintColour == null ? ItemCustomizeManager.DEFAULT_GLINT_COLOR : customGlintColour, + () -> customGlintColour == null ? ItemCustomizeManager.DEFAULT_GLINT_COLOR : customGlintColour, (colour) -> { customGlintColour = colour; updateData(); @@ -464,7 +464,7 @@ public class GuiItemCustomize extends GuiScreen { updateData(); } else { editor = new GuiElementColour(mouseX, mouseY, - customLeatherColour == null ? getChromaStrFromLeatherColour() : customLeatherColour, + () -> customLeatherColour == null ? getChromaStrFromLeatherColour() : customLeatherColour, (colour) -> { customLeatherColour = colour; updateData(); @@ -473,19 +473,6 @@ public class GuiItemCustomize extends GuiScreen { } } - /*if(mouseX >= xCenter-90 && mouseX <= xCenter+90 && - mouseY >= belowEnchGlint+65 && mouseY <= belowEnchGlint+80) { - if(true) { - String userName = Minecraft.getMinecraft().thePlayer.getName(); - String serverId = "1872398172739"; - try { - Desktop.getDesktop().browse(new URL("https://moulberry.codes/purchaseitemtag?uniqueId="+serverId+"&username="+userName).toURI()); - } catch(Exception ignored) {} - } else { - - } - }*/ - super.mouseClicked(mouseX, mouseY, mouseButton); } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/oneconfig/IOneConfigCompat.java b/src/main/java/io/github/moulberry/notenoughupdates/oneconfig/IOneConfigCompat.java new file mode 100644 index 00000000..7afceab9 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/oneconfig/IOneConfigCompat.java @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2022 NotEnoughUpdates contributors + * + * This file is part of NotEnoughUpdates. + * + * NotEnoughUpdates is free software: you can redistribute it + * and/or modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * NotEnoughUpdates is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>. + */ + +package io.github.moulberry.notenoughupdates.oneconfig; + +import io.github.moulberry.notenoughupdates.core.config.Config; +import net.minecraftforge.fml.common.Loader; + +import java.util.Optional; + +public abstract class IOneConfigCompat { + private static final Object sentinelFailure = new Object(); + private static final Object lock = new Object(); + private static Object INSTANCE = null; + + public static Optional<IOneConfigCompat> getInstance() { + if (INSTANCE == null && Loader.isModLoaded("oneconfig")) { + synchronized (lock) { + if (INSTANCE == null) + try { + Class<?> aClass = Class.forName("io.github.moulberry.notenoughupdates.compat.oneconfig.OneConfigCompat"); + INSTANCE = aClass.newInstance(); + } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { + System.err.println("Critical failure in OneConfigCompat initialization"); + e.printStackTrace(); + INSTANCE = sentinelFailure; + } + } + } + if (INSTANCE == sentinelFailure) return Optional.empty(); + return Optional.ofNullable((IOneConfigCompat) INSTANCE); + } + + public abstract void initConfig(Config moulConfig, Runnable saveCallback); + +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java b/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java index 129f973b..371d657e 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java @@ -73,6 +73,8 @@ import io.github.moulberry.notenoughupdates.overlays.TextOverlay; import io.github.moulberry.notenoughupdates.util.NotificationHandler; import io.github.moulberry.notenoughupdates.util.SBInfo; import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Gui; +import net.minecraft.client.gui.GuiScreen; import net.minecraftforge.client.ClientCommandHandler; import java.util.ArrayList; @@ -88,10 +90,11 @@ public class NEUConfig extends Config { for (TextOverlay overlay : OverlayManager.textOverlays) { overlayPositions.put(overlay, overlay.getPosition()); } + GuiScreen savedGui = Minecraft.getMinecraft().currentScreen; Minecraft.getMinecraft().displayGuiScreen(new GuiPositionEditor(overlayPositions, () -> { }, () -> { }, () -> { - NotEnoughUpdates.INSTANCE.openGui = new GuiScreenElementWrapper(NEUConfigEditor.editor); + NotEnoughUpdates.INSTANCE.openGui = savedGui; })); } @@ -109,8 +112,9 @@ public class NEUConfig extends Config { case -1: return; case 0: + GuiScreen savedGui = Minecraft.getMinecraft().currentScreen; NotEnoughUpdates.INSTANCE.openGui = new GuiDungeonMapEditor(() -> { - NotEnoughUpdates.INSTANCE.openGui = new GuiScreenElementWrapper(NEUConfigEditor.editor); + NotEnoughUpdates.INSTANCE.openGui = savedGui; }); return; case 1: diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ExtraPage.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ExtraPage.java index a1b15b82..59c78dda 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ExtraPage.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ExtraPage.java @@ -51,7 +51,7 @@ import java.util.TimeZone; import java.util.TreeMap; public class ExtraPage extends GuiProfileViewerPage { - +// Hehe private static final ResourceLocation pv_extra = new ResourceLocation("notenoughupdates:pv_extra.png"); private TreeMap<Integer, Set<String>> topKills = null; private TreeMap<Integer, Set<String>> topDeaths = null; |