diff options
| author | NopoTheGamer <40329022+NopoTheGamer@users.noreply.github.com> | 2024-08-04 23:55:53 +1000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-04 15:55:53 +0200 |
| commit | d2ea5ba43970e4beef98d6ba2b1bfb49ba73ab1d (patch) | |
| tree | 42361e9f78b9e872f12d97a72853813e152f26ba | |
| parent | 2b2f59ef37e93f11a70a44bc83d81ac8d9b64381 (diff) | |
| download | notenoughupdates-d2ea5ba43970e4beef98d6ba2b1bfb49ba73ab1d.tar.gz notenoughupdates-d2ea5ba43970e4beef98d6ba2b1bfb49ba73ab1d.tar.bz2 notenoughupdates-d2ea5ba43970e4beef98d6ba2b1bfb49ba73ab1d.zip | |
Add gradient mode for animated dyes (#1260)
Co-authored-by: Linnea Gräf <nea@nea.moe>
7 files changed, 108 insertions, 7 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/itemcustomization/DyeMode.kt b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/itemcustomization/DyeMode.kt new file mode 100644 index 00000000..3aa87219 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/itemcustomization/DyeMode.kt @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2024 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.miscgui.itemcustomization + +enum class DyeMode { + CYCLING, + GRADIENT, +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/itemcustomization/DyeType.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/itemcustomization/DyeType.java index 1e26c759..b40f2966 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/itemcustomization/DyeType.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/itemcustomization/DyeType.java @@ -28,6 +28,7 @@ public class DyeType { JsonArray colours = null; String[] coloursArray = null; int ticks = 2; + DyeMode dyeMode = DyeMode.CYCLING; public DyeType(String displayName) { this.itemId = displayName; @@ -44,9 +45,10 @@ public class DyeType { this.colours = colours; } - public DyeType(String[] coloursArray, int ticks) { + public DyeType(String[] coloursArray, int ticks, DyeMode dyeMode) { this.ticks = ticks; this.coloursArray = coloursArray; + this.dyeMode = dyeMode; } public boolean hasStaticColour() { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/itemcustomization/GuiItemCustomize.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/itemcustomization/GuiItemCustomize.java index f97d7e41..8fd1f2be 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/itemcustomization/GuiItemCustomize.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/itemcustomization/GuiItemCustomize.java @@ -79,12 +79,14 @@ public class GuiItemCustomize extends GuiScreen { String customLeatherColour = null; ArrayList<String> animatedLeatherColours = new ArrayList<>(); int animatedDyeTicks = 2; + DyeMode dyeMode = DyeMode.CYCLING; private int lastTicks = 2; boolean supportCustomLeatherColour; private String lastCustomItem = ""; JsonObject animatedDyes = null; JsonObject staticDyes = null; + JsonObject vanillaDyes = null; ArrayList<DyeType> dyes = new ArrayList<>(); boolean repoError = false; @@ -122,6 +124,7 @@ public class GuiItemCustomize extends GuiScreen { this.animatedDyeTicks = data.animatedDyeTicks; } this.textFieldTickSpeed.setText("" + this.animatedDyeTicks); + this.dyeMode = data.dyeMode; } else { this.animatedLeatherColours = new ArrayList<>(); this.textFieldTickSpeed.setText("2"); @@ -155,6 +158,7 @@ public class GuiItemCustomize extends GuiScreen { animatedDyes = dyesConst.get("animated").getAsJsonObject(); DyeType animatedHeader = new DyeType("Animated Dyes"); dyes.add(animatedHeader); + animatedDyes.entrySet().forEach(entry -> { String key = entry.getKey(); JsonArray value = entry.getValue().getAsJsonArray(); @@ -175,6 +179,19 @@ public class GuiItemCustomize extends GuiScreen { dyes.add(dyeType); }); } + + if (dyesConst.has("vanilla")) { + vanillaDyes = dyesConst.get("vanilla").getAsJsonObject(); + DyeType staticHeader = new DyeType("Vanilla Dyes"); + dyes.add(staticHeader); + + vanillaDyes.entrySet().forEach(entry -> { + String key = entry.getKey(); + String value = entry.getValue().getAsString(); + DyeType dyeType = new DyeType(key, value); + dyes.add(dyeType); + }); + } } @Override @@ -226,6 +243,8 @@ public class GuiItemCustomize extends GuiScreen { } } + data.dyeMode = dyeMode; + if (!this.textFieldRename.getText().isEmpty()) { data.customName = this.textFieldRename.getText(); @@ -470,6 +489,13 @@ public class GuiItemCustomize extends GuiScreen { Gui.drawRect(xCenter - 39, yTop + 3, xCenter - 3, yTop + 16, 0xff000000 | 0xff6955); Utils.renderShadowedString("§c§lClear", xCenter - 20, yTop + 6, xCenter * 2); + String dyeModeText = dyeMode == DyeMode.CYCLING ? "§a§lCycling" : "§d§lGradient"; + int backgroundColour = dyeMode == DyeMode.CYCLING ? 0x0aff00 : 0xff00ef; + Gui.drawRect(xCenter + 10, yTop + 2, xCenter + 68, yTop + 19, 0x70000000); + Gui.drawRect(xCenter + 10, yTop + 2, xCenter + 68, yTop + 16, 0xff101016); + Gui.drawRect(xCenter + 11, yTop + 3, xCenter + 67, yTop + 16, 0xff000000 | backgroundColour); + Utils.renderShadowedString(dyeModeText, xCenter + 39, yTop + 6, xCenter * 2); + yTop += 25; enchantGlintCustomColourAnimation.tick(); @@ -557,7 +583,7 @@ public class GuiItemCustomize extends GuiScreen { //Utils.drawItemStack(itemStack, xCenter - 90, yTop); GlStateManager.enableDepth(); GlStateManager.pushMatrix(); - GlStateManager.translate(xCenter - 90, yTop, 0); + GlStateManager.translate(xCenter - 89, yTop, 0); GlStateManager.scale(.9, .9, 1); Utils.drawItemStack(itemStack, 0, 0); GlStateManager.popMatrix(); @@ -934,6 +960,13 @@ public class GuiItemCustomize extends GuiScreen { this.animatedLeatherColours = new ArrayList<>(Arrays.asList(dyeType.coloursArray)); dataForItem.animatedLeatherColours = Arrays.stream(dataForItem.animatedLeatherColours).filter(Objects::nonNull).toArray(String[]::new); + if (dyeType.dyeMode != null) { + this.dyeMode = dyeType.dyeMode; + dataForItem.dyeMode = dyeType.dyeMode; + } else { + this.dyeMode = DyeMode.CYCLING; + dataForItem.dyeMode = DyeMode.CYCLING; + } ItemCustomizeManager.putItemData(itemUUID, dataForItem); NotEnoughUpdates.INSTANCE.openGui = new GuiItemCustomize(stack, itemUUID); } @@ -941,7 +974,7 @@ public class GuiItemCustomize extends GuiScreen { } else if (mouseY >= yTop + 72 && mouseY <= yTop + 72 + 20) { ItemCustomizationUtils.shareContents( "NEUANIMATED", - gson.toJson(new DyeType(dataForItem.animatedLeatherColours, dataForItem.animatedDyeTicks)) + gson.toJson(new DyeType(dataForItem.animatedLeatherColours, dataForItem.animatedDyeTicks, dataForItem.dyeMode)) ); } } @@ -978,6 +1011,12 @@ public class GuiItemCustomize extends GuiScreen { updateData(); } + if (mouseX >= xCenter - 23 - 15 + 50 && mouseX <= xCenter + 23 / 2 - 15 + 70 && + mouseY >= topOffset && mouseY <= topOffset + 20) { + dyeMode = dyeMode == DyeMode.CYCLING ? DyeMode.GRADIENT : DyeMode.CYCLING; + updateData(); + } + GuiType buttonClicked = ItemCustomizationUtils.getButtonClicked(mouseX, mouseY, guiType, bottomOffset); if (buttonClicked != null) { guiType = buttonClicked; @@ -1004,6 +1043,7 @@ public class GuiItemCustomize extends GuiScreen { mouseY <= topOffset + 15) { if (dyes.get(i).hasAnimatedColour()) { animatedLeatherColours.clear(); + dyeMode = DyeMode.CYCLING; for (JsonElement colour : dyes.get(i).colours) { String string = colour.getAsString(); Color colourFromHex = ItemCustomizationUtils.getColourFromHex(string); @@ -1011,6 +1051,7 @@ public class GuiItemCustomize extends GuiScreen { animatedLeatherColours.add(special); } } else if ((dyes.get(i).hasStaticColour())) { + dyeMode = DyeMode.CYCLING; animatedLeatherColours.clear(); Color colourFromHex = ItemCustomizationUtils.getColourFromHex(dyes.get(i).colour); String special = SpecialColour.special(0, 0, colourFromHex.getRGB()); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/itemcustomization/ItemCustomizationUtils.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/itemcustomization/ItemCustomizationUtils.java index 9f31fddc..ec8b3af2 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/itemcustomization/ItemCustomizationUtils.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/itemcustomization/ItemCustomizationUtils.java @@ -86,7 +86,10 @@ public class ItemCustomizationUtils { public static List<String> speedGuide = Lists.newArrayList( EnumChatFormatting.AQUA + "This is how fast the dyes will cycle, in ticks", - EnumChatFormatting.GRAY + "Hypixel dyes cycle every 2 ticks" + EnumChatFormatting.GRAY + "§6Hypixel §7dyes cycle every 2 ticks", + EnumChatFormatting.GRAY + "", + EnumChatFormatting.GRAY + "In the §dgradient mode §7this decides the amount of intermediary colours", + EnumChatFormatting.GRAY + "This means if speed is set to 1 it's the same as §aCycling mode" ); public static ItemStack copy(ItemStack stack, GuiItemCustomize instance) { @@ -197,7 +200,18 @@ public class ItemCustomizationUtils { return null; } - public static int getAnimatedDyeColour(String[] dyeColours, int ticks) { + public static int getAnimatedDyeColour(String[] dyeColours, int ticks, DyeMode dyeMode) { + if (dyeMode == DyeMode.GRADIENT) { + int i = (Minecraft.getMinecraft().thePlayer.ticksExisted / ticks) % dyeColours.length; + int dyeColour1 = ChromaColour.specialToChromaRGB(dyeColours[i]); + if (i == dyeColours.length - 1) { + i = 0; + } else { + i++; + } + int dyeColour2 = ChromaColour.specialToChromaRGB(dyeColours[i]); + return blendColors(dyeColour1, dyeColour2, (float) (Minecraft.getMinecraft().thePlayer.ticksExisted % ticks) / ticks); + } return ChromaColour.specialToChromaRGB( dyeColours[(Minecraft.getMinecraft().thePlayer.ticksExisted / ticks) % dyeColours.length]); } @@ -343,4 +357,22 @@ public class ItemCustomizationUtils { return jsonString; } + + public static int blendColors(int startColorInt, int endColorInt, float ratio) { + Color startColour = new Color(startColorInt); + Color endColour = new Color(endColorInt); + int redStart = startColour.getRed(); + int greenStart = startColour.getGreen(); + int blueStart = startColour.getBlue(); + + int redEnd = endColour.getRed(); + int greenEnd = endColour.getGreen(); + int blueEnd = endColour.getBlue(); + + int red = (int) (redStart + (redEnd - redStart) * ratio); + int green = (int) (greenStart + (greenEnd - greenStart) * ratio); + int blue = (int) (blueStart + (blueEnd - blueStart) * ratio); + + return (red << 16) | (green << 8) | blue; + } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/itemcustomization/ItemCustomizeManager.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/itemcustomization/ItemCustomizeManager.java index 9466b280..3dad7d24 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/itemcustomization/ItemCustomizeManager.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/itemcustomization/ItemCustomizeManager.java @@ -91,6 +91,7 @@ public class ItemCustomizeManager { public String customLeatherColour = null; public String[] animatedLeatherColours = null; public int animatedDyeTicks = 2; + public DyeMode dyeMode = DyeMode.CYCLING; public String defaultItem = null; public String customItem = null; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinLayerArmorBase.java b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinLayerArmorBase.java index 8f4e74d5..8a71d205 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinLayerArmorBase.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinLayerArmorBase.java @@ -84,7 +84,7 @@ public abstract class MixinLayerArmorBase<T extends ModelBase> { ItemCustomizeManager.ItemData data = ItemCustomizeManager.getDataForItem(stack); if (data != null && data.animatedLeatherColours != null && data.animatedDyeTicks > 0 && ItemCustomizeManager.shouldRenderLeatherColour(stack)) { - return ItemCustomizationUtils.getAnimatedDyeColour(data.animatedLeatherColours, data.animatedDyeTicks); + return ItemCustomizationUtils.getAnimatedDyeColour(data.animatedLeatherColours, data.animatedDyeTicks, data.dyeMode); } else if (data != null && data.customLeatherColour != null && ItemCustomizeManager.shouldRenderLeatherColour(stack)) { return ChromaColour.specialToChromaRGB(data.customLeatherColour); } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinRenderItem.java b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinRenderItem.java index 5c856d9d..96f8220a 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinRenderItem.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinRenderItem.java @@ -135,7 +135,7 @@ public abstract class MixinRenderItem { if (renderPass == 0) { ItemCustomizeManager.ItemData data = ItemCustomizeManager.getDataForItem(stack); if (data != null && data.animatedLeatherColours != null && data.animatedDyeTicks > 0 && ItemCustomizeManager.shouldRenderLeatherColour(stack)) { - return ItemCustomizationUtils.getAnimatedDyeColour(data.animatedLeatherColours, data.animatedDyeTicks); + return ItemCustomizationUtils.getAnimatedDyeColour(data.animatedLeatherColours, data.animatedDyeTicks, data.dyeMode); } else if (data != null && data.customLeatherColour != null && ItemCustomizeManager.shouldRenderLeatherColour(stack)) { return ChromaColour.specialToChromaRGB(data.customLeatherColour); } |
