From 688a288804cc355390561e48332c99e25c207f5d Mon Sep 17 00:00:00 2001 From: NopoTheGamer <40329022+NopoTheGamer@users.noreply.github.com> Date: Tue, 9 Jul 2024 01:25:51 +1000 Subject: Add Improvements to /neucustomize (#1200) --- .../moulberry/notenoughupdates/NEUOverlay.java | 8 + .../notenoughupdates/NotEnoughUpdates.java | 2 +- .../listener/NEUEventListener.java | 2 +- .../miscfeatures/ItemCustomizeManager.java | 418 -------- .../notenoughupdates/miscgui/GuiItemCustomize.java | 558 ---------- .../miscgui/itemcustomization/DyeType.java | 59 ++ .../itemcustomization/GuiItemCustomize.java | 1065 ++++++++++++++++++++ .../miscgui/itemcustomization/GuiType.kt | 25 + .../itemcustomization/ItemCustomizationUtils.java | 346 +++++++ .../itemcustomization/ItemCustomizeManager.java | 472 +++++++++ .../notenoughupdates/mixins/MixinGuiContainer.java | 2 +- .../notenoughupdates/mixins/MixinGuiIngame.java | 2 +- .../mixins/MixinGuiIngameForge.java | 2 +- .../notenoughupdates/mixins/MixinItemRenderer.java | 2 +- .../notenoughupdates/mixins/MixinItemStack.java | 2 +- .../mixins/MixinLayerArmorBase.java | 7 +- .../mixins/MixinLayerCustomHead.java | 2 +- .../notenoughupdates/mixins/MixinRenderItem.java | 7 +- .../mixins/MixinTextureManager.java | 4 +- .../options/separatesections/Misc.java | 8 + .../moulberry/notenoughupdates/util/Constants.java | 2 + .../notenoughupdates/commands/misc/MiscCommands.kt | 8 +- .../notenoughupdates/itemcustomize/cross.png | Bin 0 -> 123 bytes .../assets/notenoughupdates/itemcustomize/plus.png | Bin 0 -> 187 bytes 24 files changed, 2010 insertions(+), 993 deletions(-) delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/ItemCustomizeManager.java delete mode 100644 src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiItemCustomize.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/miscgui/itemcustomization/DyeType.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/miscgui/itemcustomization/GuiItemCustomize.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/miscgui/itemcustomization/GuiType.kt create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/miscgui/itemcustomization/ItemCustomizationUtils.java create mode 100644 src/main/java/io/github/moulberry/notenoughupdates/miscgui/itemcustomization/ItemCustomizeManager.java create mode 100644 src/main/resources/assets/notenoughupdates/itemcustomize/cross.png create mode 100644 src/main/resources/assets/notenoughupdates/itemcustomize/plus.png diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java index 087365e0..d5ffc790 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java @@ -38,6 +38,7 @@ import io.github.moulberry.notenoughupdates.miscfeatures.CookieWarning; import io.github.moulberry.notenoughupdates.miscfeatures.EnchantingSolvers; import io.github.moulberry.notenoughupdates.miscfeatures.SunTzu; import io.github.moulberry.notenoughupdates.miscgui.NeuSearchCalculator; +import io.github.moulberry.notenoughupdates.miscgui.itemcustomization.GuiItemCustomize; import io.github.moulberry.notenoughupdates.miscgui.pricegraph.GuiPriceGraph; import io.github.moulberry.notenoughupdates.recipes.CraftingRecipe; import io.github.moulberry.notenoughupdates.util.Calculator; @@ -1249,6 +1250,13 @@ public class NEUOverlay extends Gui { .replace("[Lvl {LVL}]", "") .trim()); NotEnoughUpdates.INSTANCE.trySendCommand("/recipe " + displayName); + } else if (keyPressed == NotEnoughUpdates.INSTANCE.config.misc.neuCustomizeKeybind && itemstack.get() != null) { + String uuid = NEUManager.getUUIDFromNBT(itemstack.get().getTagCompound()); + if (uuid != null) { + NotEnoughUpdates.INSTANCE.openGui = new GuiItemCustomize(itemstack.get(), uuid); + } else { + Utils.addChatMessage("§cThis item does not have an UUID, so it cannot be customized."); + } } } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java index b34150d7..0c6cc55b 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NotEnoughUpdates.java @@ -38,7 +38,6 @@ import io.github.moulberry.notenoughupdates.listener.RenderListener; import io.github.moulberry.notenoughupdates.listener.WorldListener; import io.github.moulberry.notenoughupdates.miscfeatures.CustomSkulls; import io.github.moulberry.notenoughupdates.miscfeatures.FairySouls; -import io.github.moulberry.notenoughupdates.miscfeatures.ItemCustomizeManager; import io.github.moulberry.notenoughupdates.miscfeatures.NPCRetexturing; import io.github.moulberry.notenoughupdates.miscfeatures.Navigation; import io.github.moulberry.notenoughupdates.miscfeatures.PetInfoOverlay; @@ -47,6 +46,7 @@ import io.github.moulberry.notenoughupdates.miscfeatures.StorageManager; import io.github.moulberry.notenoughupdates.miscfeatures.customblockzones.CustomBlockSounds; import io.github.moulberry.notenoughupdates.miscfeatures.inventory.MuseumCheapestItemOverlay; import io.github.moulberry.notenoughupdates.miscfeatures.inventory.MuseumItemHighlighter; +import io.github.moulberry.notenoughupdates.miscgui.itemcustomization.ItemCustomizeManager; import io.github.moulberry.notenoughupdates.mixins.AccessorMinecraft; import io.github.moulberry.notenoughupdates.oneconfig.IOneConfigCompat; import io.github.moulberry.notenoughupdates.options.NEUConfig; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/listener/NEUEventListener.java b/src/main/java/io/github/moulberry/notenoughupdates/listener/NEUEventListener.java index 2480b57e..c92fca74 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/listener/NEUEventListener.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/listener/NEUEventListener.java @@ -32,13 +32,13 @@ import io.github.moulberry.notenoughupdates.miscfeatures.CookieWarning; import io.github.moulberry.notenoughupdates.miscfeatures.CrystalMetalDetectorSolver; import io.github.moulberry.notenoughupdates.miscfeatures.CrystalOverlay; import io.github.moulberry.notenoughupdates.miscfeatures.FairySouls; -import io.github.moulberry.notenoughupdates.miscfeatures.ItemCustomizeManager; import io.github.moulberry.notenoughupdates.miscfeatures.NPCRetexturing; import io.github.moulberry.notenoughupdates.miscgui.AccessoryBagOverlay; import io.github.moulberry.notenoughupdates.miscgui.GuiCustomEnchant; import io.github.moulberry.notenoughupdates.miscgui.GuiItemRecipe; import io.github.moulberry.notenoughupdates.miscgui.StorageOverlay; import io.github.moulberry.notenoughupdates.miscgui.hex.GuiCustomHex; +import io.github.moulberry.notenoughupdates.miscgui.itemcustomization.ItemCustomizeManager; import io.github.moulberry.notenoughupdates.overlays.OverlayManager; import io.github.moulberry.notenoughupdates.overlays.TextOverlay; import io.github.moulberry.notenoughupdates.overlays.TextTabOverlay; diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/ItemCustomizeManager.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/ItemCustomizeManager.java deleted file mode 100644 index 59e5a610..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/ItemCustomizeManager.java +++ /dev/null @@ -1,418 +0,0 @@ -/* - * 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 . - */ - -package io.github.moulberry.notenoughupdates.miscfeatures; - -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import io.github.moulberry.notenoughupdates.NEUManager; -import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe; -import io.github.moulberry.notenoughupdates.core.ChromaColour; -import io.github.moulberry.notenoughupdates.core.config.ConfigUtil; -import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.client.renderer.entity.layers.LayerArmorBase; -import net.minecraft.client.renderer.texture.DynamicTexture; -import net.minecraft.client.renderer.texture.TextureMap; -import net.minecraft.client.resources.IResourceManager; -import net.minecraft.client.resources.IResourceManagerReloadListener; -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.init.Items; -import net.minecraft.item.Item; -import net.minecraft.item.ItemArmor; -import net.minecraft.item.ItemStack; -import net.minecraft.util.ResourceLocation; -import net.minecraftforge.event.world.WorldEvent; -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; -import org.lwjgl.opengl.GL11; -import org.lwjgl.opengl.GL14; - -import javax.imageio.ImageIO; -import java.awt.*; -import java.awt.image.BufferedImage; -import java.io.File; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Random; -import java.util.function.Consumer; - -@NEUAutoSubscribe -public class ItemCustomizeManager { - public static class ReloadListener implements IResourceManagerReloadListener { - @Override - public void onResourceManagerReload(IResourceManager resourceManager) { - ItemCustomizeManager.loadedCustomGlintTexture = false; - } - } - - public static boolean disableTextureBinding = false; - - private static ResourceLocation CUSTOM_GLINT_TEXTURE = new ResourceLocation( - "notenoughupdates:dynamic/custom_glint_texture"); - private static boolean loadedCustomGlintTexture = false; - - public static final String DEFAULT_GLINT_COLOR = ChromaColour.special(0, 0xcc, 0x6419FF); - //A050FF 0x8040cc 100,25,255 64,19 - - private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create(); - private static ItemDataMap itemDataMap = new ItemDataMap(); - - public static class ItemDataMap { - public HashMap itemData = new HashMap<>(); - } - - public static class ItemData { - public String customName = null; - public String customNamePrefix = ""; - public boolean overrideEnchantGlint = false; - public boolean enchantGlintValue; - - public String customGlintColour = DEFAULT_GLINT_COLOR; - - public String customLeatherColour = null; - - public String defaultItem = null; - public String customItem = null; - } - - public static void putItemData(String uuid, ItemData data) { - itemDataMap.itemData.put(uuid, data); - } - - public static void setCustomBlendFunc(String colour) { - - /*int argb = ChromaColour.specialToChromaRGB(colour); - float[] hsv = Color.RGBtoHSB((argb >> 16) & 0xff, (argb >> 8) & 0xff, argb & 0xff, null); - GL14.glBlendColor(1, 1, 1, hsv[2]);*/ - - GL14.glBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_CONSTANT_ALPHA, GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA); - //GL14.glBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE, GL11.GL_ONE); - } - - private static void renderEffect(Consumer renderModelCallback, int color) { - GL11.glPushMatrix(); - - GlStateManager.enableBlend(); - GlStateManager.depthMask(false); - GlStateManager.depthFunc(GL11.GL_EQUAL); - GlStateManager.disableLighting(); - Minecraft.getMinecraft().getTextureManager().bindTexture(getCustomGlintTexture()); - GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); - GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); - - GlStateManager.matrixMode(5890); - GlStateManager.pushMatrix(); - GlStateManager.scale(8.0F, 8.0F, 8.0F); - float f = (float) (Minecraft.getSystemTime() % 3000L) / 3000.0F / 8.0F; - GlStateManager.translate(f, 0.0F, 0.0F); - GlStateManager.rotate(-50.0F, 0.0F, 0.0F, 1.0F); - renderModelCallback.accept(color); - GlStateManager.matrixMode(5890); - GlStateManager.popMatrix(); - - GlStateManager.pushMatrix(); - GlStateManager.scale(8.0F, 8.0F, 8.0F); - float f1 = (float) (Minecraft.getSystemTime() % 4873L) / 4873.0F / 8.0F; - GlStateManager.translate(-f1, 0.0F, 0.0F); - GlStateManager.rotate(10.0F, 0.0F, 0.0F, 1.0F); - renderModelCallback.accept(color); - GlStateManager.matrixMode(5890); - GlStateManager.popMatrix(); - - GlStateManager.matrixMode(5888); - GlStateManager.blendFunc(770, 771); - GlStateManager.enableLighting(); - GlStateManager.depthFunc(515); - GlStateManager.depthMask(true); - Minecraft.getMinecraft().getTextureManager().bindTexture(TextureMap.locationBlocksTexture); - - GL11.glPopMatrix(); - } - - private static void renderArmorGlint(Runnable renderModelCallback, float existed, int color) { - Minecraft.getMinecraft().getTextureManager().bindTexture(getCustomGlintTexture()); - GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); - GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); - GlStateManager.enableBlend(); - GlStateManager.depthFunc(514); - GlStateManager.depthMask(false); - float f1 = 0.5F; - GlStateManager.color(f1, f1, f1, 1.0F); - - for (int i = 0; i < 2; ++i) { - GlStateManager.disableLighting(); - - float red = ((color >> 16) & 0xFF) / 255f; - float green = ((color >> 8) & 0xFF) / 255f; - float blue = (color & 0xFF) / 255f; - float alpha = ((color >> 24) & 0xFF) / 255f; - - GlStateManager.color(red, green, blue, alpha); - GlStateManager.matrixMode(5890); - GlStateManager.loadIdentity(); - float f3 = 0.33333334F; - GlStateManager.scale(f3, f3, f3); - GlStateManager.rotate(30.0F - (float) i * 60.0F, 0.0F, 0.0F, 1.0F); - GlStateManager.translate(0.0F, existed * (0.001F + (float) i * 0.003F) * 20.0F, 0.0F); - GlStateManager.matrixMode(5888); - renderModelCallback.run(); - } - - GlStateManager.matrixMode(5890); - GlStateManager.loadIdentity(); - GlStateManager.matrixMode(5888); - GlStateManager.enableLighting(); - GlStateManager.depthMask(true); - GlStateManager.depthFunc(515); - GlStateManager.disableBlend(); - } - - public static void pre() { - GlStateManager.matrixMode(GL11.GL_MODELVIEW); - } - - public static boolean render3DGlint(String customEnchantGlint, float existed, Runnable renderModelCallback) { - if (customEnchantGlint != null) { - int colour = ChromaColour.specialToChromaRGB(customEnchantGlint); - - float[] hsv = Color.RGBtoHSB((colour >> 16) & 0xff, (colour >> 8) & 0xff, colour & 0xff, null); - GL14.glBlendColor(1, 1, 1, hsv[2]); - - GlStateManager.tryBlendFuncSeparate( - GL11.GL_ZERO, - GL11.GL_ONE_MINUS_SRC_ALPHA, - GL11.GL_ZERO, - GL11.GL_ONE_MINUS_SRC_ALPHA - ); - int alphaValue = (int) ((1 - hsv[2] * hsv[2]) * 0xff) * ((colour >> 24) & 0xff) / 0xff; - renderArmorGlint(renderModelCallback, existed, alphaValue << 24); - GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE, GL11.GL_ONE); - renderArmorGlint(renderModelCallback, existed, colour); - - return true; - } - return false; - } - - public static boolean renderEffectHook(String customEnchantGlint, Consumer renderModelCallback) { - if (customEnchantGlint != null) { - int colour = ChromaColour.specialToChromaRGB(customEnchantGlint); - - float[] hsv = Color.RGBtoHSB((colour >> 16) & 0xff, (colour >> 8) & 0xff, colour & 0xff, null); - GL14.glBlendColor(1, 1, 1, hsv[2]); - - GL11.glPushMatrix(); - - GlStateManager.tryBlendFuncSeparate( - GL11.GL_ZERO, - GL11.GL_ONE_MINUS_SRC_ALPHA, - GL11.GL_ZERO, - GL11.GL_ONE_MINUS_SRC_ALPHA - ); - int alphaValue = (int) ((1 - hsv[2] * hsv[2]) * 0xff) * ((colour >> 24) & 0xff) / 0xff; - renderEffect(renderModelCallback, alphaValue << 24); - GlStateManager.tryBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE, GL11.GL_ONE); - renderEffect(renderModelCallback, colour); - - GL11.glPopMatrix(); - - return true; - } - return false; - } - - public static ResourceLocation getCustomGlintTexture() { - if (!loadedCustomGlintTexture) { - loadedCustomGlintTexture = true; - - final ResourceLocation RES_ITEM_GLINT = new ResourceLocation("textures/misc/enchanted_item_glint.png"); - - try { - BufferedImage originalGlint = ImageIO.read(Minecraft - .getMinecraft() - .getResourceManager() - .getResource(RES_ITEM_GLINT) - .getInputStream()); - BufferedImage newGlint = new BufferedImage( - originalGlint.getWidth(), - originalGlint.getHeight(), - BufferedImage.TYPE_INT_ARGB - ); - - for (int x = 0; x < originalGlint.getWidth(); x++) { - for (int y = 0; y < originalGlint.getHeight(); y++) { - int argb = originalGlint.getRGB(x, y); - - int avgRGB = ((((argb >> 16) & 0xff) + ((argb >> 8) & 0xff) + (argb & 0xff)) / 3) & 0xff; - - int newArgb = (avgRGB << 24) | (avgRGB << 16) | (avgRGB << 8) | avgRGB; - - newGlint.setRGB(x, y, newArgb); - } - } - - Minecraft.getMinecraft().getTextureManager().loadTexture(CUSTOM_GLINT_TEXTURE, new DynamicTexture(newGlint)); - } catch (Exception e) { - e.printStackTrace(); - CUSTOM_GLINT_TEXTURE = RES_ITEM_GLINT; - } - } - return CUSTOM_GLINT_TEXTURE; - } - - public static ItemData getDataForItem(ItemStack stack) { - if (stack == null) return null; - - String uuid = NEUManager.getUUIDForItem(stack); - - if (uuid == null) { - return null; - } else { - return itemDataMap.itemData.get(uuid); - } - } - - public static void tick() { - disableTextureBinding = false; - } - - public static void loadCustomization(File file) { - itemDataMap = ConfigUtil.loadConfig(ItemDataMap.class, file, GSON); - if (itemDataMap == null) { - itemDataMap = new ItemDataMap(); - } - } - - public static void saveCustomization(File file) { - ConfigUtil.saveConfig(itemDataMap, file, GSON); - } - - public static Item getCustomItem(ItemStack stack) { - ItemData data = getDataForItem(stack); - if (data == null || data.customItem == null || data.customItem.length() == 0 || - data.customItem.split(":").length == 0) return stack.getItem(); - Item newItem = Item.getByNameOrId(data.customItem.split(":")[0]); - if (newItem == null) return stack.getItem(); - return newItem; - } - - public static Item getCustomItem(ItemStack stack, String newItemString) { - if (newItemString.split(":").length == 0) return stack.getItem(); - Item newItem = Item.getByNameOrId(newItemString.split(":")[0]); - if (newItem == null) return stack.getItem(); - return newItem; - } - - static Random random = new Random(); - static HashMap lastUpdate = new HashMap<>(); - static HashMap damageMap = new HashMap<>(); - - public static int getCustomItemDamage(ItemStack stack) { - ItemData data = getDataForItem(stack); - if (data == null || data.customItem == null || data.customItem.length() == 0) return stack.getMetadata(); - try { - String damageString = data.customItem.split(":")[1]; - if (damageString.equals("?")) { - ArrayList list = new ArrayList<>(); - getCustomItem(stack).getSubItems(getCustomItem(stack), null, list); - if (damageMap.get(stack.getTagCompound().hashCode()) == null || System.currentTimeMillis() - lastUpdate.get( - stack.getTagCompound().hashCode()) > 250) { - damageMap.put(stack.getTagCompound().hashCode(), random.nextInt(list.size())); - - lastUpdate.put(stack.getTagCompound().hashCode(), System.currentTimeMillis()); - } - return damageMap.get(stack.getTagCompound().hashCode()); - } - return Integer.parseInt(data.customItem.split(":")[1]); - } catch (Exception e) { - if (Item.getByNameOrId(data.defaultItem) == Items.skull && getCustomItem(stack) != Items.skull) return 0; - return stack.getMetadata(); - } - } - - @SubscribeEvent - public void onWorldUnload(WorldEvent.Unload event) { - damageMap.clear(); - lastUpdate.clear(); - } - - public static boolean shouldRenderLeatherColour(ItemStack stack) { - ItemData data = getDataForItem(stack); - if (data == null || data.customItem == null || data.customItem.length() == 0) - return stack.getItem() instanceof ItemArmor && - ((ItemArmor) stack.getItem()).getArmorMaterial() == ItemArmor.ArmorMaterial.LEATHER; - Item item = Item.getByNameOrId(data.customItem); - if (item == null) return stack.getItem() instanceof ItemArmor && - ((ItemArmor) stack.getItem()).getArmorMaterial() == ItemArmor.ArmorMaterial.LEATHER; - return item instanceof ItemArmor && - ((ItemArmor) item).getArmorMaterial() == ItemArmor.ArmorMaterial.LEATHER; - } - - public static boolean hasCustomItem(ItemStack stack) { - ItemData data = getDataForItem(stack); - if (data == null || data.customItem == null || data.customItem.length() == 0 || data.defaultItem == null || - data.customItem.equals(data.defaultItem) || data.customItem.split(":").length == 0) return false; - Item item = Item.getByNameOrId(data.customItem.split(":")[0]); - Item defaultItem = Item.getByNameOrId(data.defaultItem); - if (item == null) { - data.customItem = null; - return false; - } - return defaultItem != item; - } - - public static ItemStack useCustomArmour( - LayerArmorBase instance, - EntityLivingBase entitylivingbaseIn, - int armorSlot - ) { - ItemStack stack = instance.getCurrentArmor(entitylivingbaseIn, armorSlot); - if (stack == null || getDataForItem(stack) == null) return stack; - ItemStack newStack = stack.copy(); - newStack.setItem(ItemCustomizeManager.getCustomItem(newStack)); - newStack.setItemDamage(ItemCustomizeManager.getCustomItemDamage(newStack)); - - if (armorSlot != 4 && newStack.getItem() instanceof ItemArmor) - // Remove non armor from any slot except heads - newStack = stack; - - if (newStack.getItem() == stack.getItem() - && newStack.getItemDamage() == stack.getItemDamage()) - return stack; - return newStack; - } - - public static ItemStack useCustomItem(ItemStack stack) { - if (stack == null) return stack; - if (!ItemCustomizeManager.hasCustomItem(stack)) return stack; - ItemStack newStack = stack.copy(); - newStack.setItem(ItemCustomizeManager.getCustomItem(newStack)); - newStack.setItemDamage(ItemCustomizeManager.getCustomItemDamage(newStack)); - return newStack; - } - - public static ItemStack setHeadArmour(EntityLivingBase instance, int i) { - if (instance.getCurrentArmor(3) == null) return null; - ItemStack stack = instance.getCurrentArmor(3).copy(); - stack.setItem(ItemCustomizeManager.getCustomItem(stack)); - stack.setItemDamage(ItemCustomizeManager.getCustomItemDamage(stack)); - return stack; - } - -} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiItemCustomize.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiItemCustomize.java deleted file mode 100644 index d9b24895..00000000 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiItemCustomize.java +++ /dev/null @@ -1,558 +0,0 @@ -/* - * 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 . - */ - -package io.github.moulberry.notenoughupdates.miscgui; - -import com.google.common.collect.Lists; -import io.github.moulberry.notenoughupdates.core.ChromaColour; -import io.github.moulberry.notenoughupdates.core.GlScissorStack; -import io.github.moulberry.notenoughupdates.core.GuiElement; -import io.github.moulberry.notenoughupdates.core.GuiElementBoolean; -import io.github.moulberry.notenoughupdates.core.GuiElementColour; -import io.github.moulberry.notenoughupdates.core.GuiElementTextField; -import io.github.moulberry.notenoughupdates.core.util.lerp.LerpingFloat; -import io.github.moulberry.notenoughupdates.core.util.render.RenderUtils; -import io.github.moulberry.notenoughupdates.miscfeatures.ItemCustomizeManager; -import io.github.moulberry.notenoughupdates.util.GuiTextures; -import io.github.moulberry.notenoughupdates.util.Utils; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.Gui; -import net.minecraft.client.gui.GuiScreen; -import net.minecraft.client.gui.ScaledResolution; -import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.client.resources.model.IBakedModel; -import net.minecraft.item.ItemArmor; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.EnumChatFormatting; -import net.minecraft.util.ResourceLocation; -import org.lwjgl.input.Keyboard; -import org.lwjgl.input.Mouse; -import org.lwjgl.opengl.GL11; - -import java.io.IOException; -import java.util.List; - -public class GuiItemCustomize extends GuiScreen { - private static final ResourceLocation RESET = new ResourceLocation("notenoughupdates:itemcustomize/reset.png"); - - private final ItemStack stack; - private ItemStack customItemStack; - private final String itemUUID; - private final GuiElementTextField textFieldRename = new GuiElementTextField("", 158, 20, GuiElementTextField.COLOUR); - private final GuiElementTextField textFieldCustomItem = new GuiElementTextField("", 180, 20, GuiElementTextField.COLOUR); - private final GuiElementBoolean enchantGlintButton; - - private int renderHeight = 0; - - private final LerpingFloat enchantGlintCustomColourAnimation = new LerpingFloat(0, 200); - - private boolean enchantGlint; - private String customGlintColour = null; - - private String customLeatherColour = null; - private boolean supportCustomLeatherColour; - private String lastCustomItem = ""; - - private GuiElement editor = null; - - public GuiItemCustomize(ItemStack stack, String itemUUID) { - this.stack = stack; - this.itemUUID = itemUUID; - this.customItemStack = copy(stack); - - IBakedModel model = Minecraft.getMinecraft().getRenderItem().getItemModelMesher().getItemModel(stack); - boolean stackHasEffect = stack.hasEffect() && !model.isBuiltInRenderer(); - - ItemCustomizeManager.ItemData data = ItemCustomizeManager.getDataForItem(stack); - if (data != null) { - this.enchantGlint = data.overrideEnchantGlint ? data.enchantGlintValue : stackHasEffect; - if (data.customName != null) { - textFieldRename.setText(data.customName); - } - if (data.customItem != null && data.customItem.length() > 0) { - textFieldCustomItem.setText(data.customItem); - } else { - textFieldCustomItem.setText(stack.getItem().getRegistryName().replace("minecraft:", "")); - } - this.customGlintColour = data.customGlintColour; - this.customLeatherColour = data.customLeatherColour; - } else { - this.enchantGlint = stackHasEffect; - textFieldCustomItem.setText(stack.getItem().getRegistryName().replace("minecraft:", "")); - } - - supportCustomLeatherColour = customItemStack.getItem() instanceof ItemArmor && - ((ItemArmor) customItemStack.getItem()).getArmorMaterial() == ItemArmor.ArmorMaterial.LEATHER; - - enchantGlintCustomColourAnimation.setValue(enchantGlint ? 17 : 0); - this.enchantGlintButton = new GuiElementBoolean(0, 0, () -> enchantGlint, (bool) -> { - enchantGlint = bool; - updateData(); - }); - - } - - @Override - public void onGuiClosed() { - updateData(); - } - - public String getChromaStrFromLeatherColour() { - return ChromaColour.special(0, 0xff, ((ItemArmor) customItemStack.getItem()).getColor(customItemStack)); - } - - public void updateData() { - ItemCustomizeManager.ItemData data = new ItemCustomizeManager.ItemData(); - - IBakedModel model = Minecraft.getMinecraft().getRenderItem().getItemModelMesher().getItemModel(stack); - boolean stackHasEffect = stack.hasEffect() && !model.isBuiltInRenderer(); - - this.customItemStack = copy(stack); - data.defaultItem = stack.getItem().getRegistryName(); - - if (this.enchantGlint != stackHasEffect) { - data.overrideEnchantGlint = true; - data.enchantGlintValue = this.enchantGlint; - } - - if (this.customGlintColour != null && !this.customGlintColour.equals(ItemCustomizeManager.DEFAULT_GLINT_COLOR)) { - data.customGlintColour = this.customGlintColour; - } else if (model.isBuiltInRenderer() && data.overrideEnchantGlint && data.enchantGlintValue) { - data.customGlintColour = ItemCustomizeManager.DEFAULT_GLINT_COLOR; - } else { - data.customGlintColour = null; - } - - if (this.customLeatherColour != null && (!(customItemStack.getItem() instanceof ItemArmor) || !this.customLeatherColour.equals( - getChromaStrFromLeatherColour()))) { - data.customLeatherColour = this.customLeatherColour; - } else { - data.customLeatherColour = null; - } - - if (!this.textFieldRename.getText().isEmpty()) { - data.customName = this.textFieldRename.getText(); - - NBTTagCompound stackTagCompound = stack.getTagCompound(); - if (stackTagCompound != null && stackTagCompound.hasKey("display", 10)) { - NBTTagCompound nbttagcompound = stackTagCompound.getCompoundTag("display"); - - if (nbttagcompound.hasKey("Name", 8)) { - String name = nbttagcompound.getString("Name"); - char[] chars = name.toCharArray(); - - int i; - for (i = 0; i < chars.length; i += 2) { - if (chars[i] != '\u00a7') { - break; - } - } - - data.customNamePrefix = name.substring(0, i); - } - } - } - - if (!this.textFieldCustomItem.getText().isEmpty()) { - data.customItem = this.textFieldCustomItem.getText(); - } - - ItemCustomizeManager.putItemData(itemUUID, data); - } - - private ItemStack copy(ItemStack stack) { - ItemStack customStack = stack.copy(); - if (!this.textFieldCustomItem.getText().isEmpty()) { - customStack.setItem(ItemCustomizeManager.getCustomItem(stack, this.textFieldCustomItem.getText().trim())); - customStack.setItemDamage(ItemCustomizeManager.getCustomItemDamage(stack)); - } - return customStack; - } - - private int getGlintColour() { - int col = customGlintColour == null - ? ChromaColour.specialToChromaRGB(ItemCustomizeManager.DEFAULT_GLINT_COLOR) - : ChromaColour.specialToChromaRGB(customGlintColour); - return 0xff000000 | col; - } - - private int getLeatherColour() { - if (!supportCustomLeatherColour) return 0xff000000; - - int col = - customLeatherColour == null ? ((ItemArmor) customItemStack.getItem()).getColor(customItemStack) : ChromaColour.specialToChromaRGB( - customLeatherColour); - return 0xff000000 | col; - } - - @Override - public void drawScreen(int mouseX, int mouseY, float partialTicks) { - drawDefaultBackground(); - - List tooltipToDisplay = null; - - ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); - - int xCenter = scaledResolution.getScaledWidth() / 2; - int yTopStart = (scaledResolution.getScaledHeight() - renderHeight) / 2; - int yTop = yTopStart; - - RenderUtils.drawFloatingRectDark(xCenter - 100, yTop - 9, 200, renderHeight + 33); - - RenderUtils.drawFloatingRectDark(xCenter - 90, yTop - 5, 180, 14); - Utils.renderShadowedString("\u00a75\u00a7lNEU Item Customizer", xCenter, yTop - 1, 180); - - yTop += 14; - - if (!textFieldRename.getFocus() && textFieldRename.getText().isEmpty()) { - textFieldRename.setOptions(GuiElementTextField.SCISSOR_TEXT); - textFieldRename.setPrependText("\u00a77Enter Custom Name..."); - } else { - textFieldRename.setOptions(GuiElementTextField.COLOUR | GuiElementTextField.SCISSOR_TEXT); - textFieldRename.setPrependText(""); - } - - if (!textFieldRename.getFocus()) { - textFieldRename.setSize(158, 20); - } else { - int textSize = fontRendererObj.getStringWidth(textFieldRename.getTextDisplay()) + 10; - textFieldRename.setSize(Math.max(textSize, 158), 20); - } - - textFieldRename.render(xCenter - textFieldRename.getWidth() / 2 - 10, yTop); - int yTopText = yTop; - - Minecraft.getMinecraft().getTextureManager().bindTexture(GuiTextures.help); - GlStateManager.color(1, 1, 1, 1); - int helpX = xCenter + textFieldRename.getWidth() / 2 - 5; - Utils.drawTexturedRect(helpX, yTop, 20, 20, GL11.GL_LINEAR); - - if (mouseX >= helpX && mouseX <= helpX + 20 && mouseY >= yTop && mouseY <= yTop + 20) { - tooltipToDisplay = Lists.newArrayList( - EnumChatFormatting.AQUA + "Set a custom name for the item", - EnumChatFormatting.GREEN + "", - EnumChatFormatting.GREEN + "Type \"&&\" for \u00B6", - EnumChatFormatting.GREEN + "Type \"**\" for \u272A", - EnumChatFormatting.GREEN + "Type \"*1-9\" for \u278A-\u2792", - EnumChatFormatting.GREEN + "", - EnumChatFormatting.GREEN + "Available colour codes:", - Utils.chromaString("\u00B6z = Chroma"), - EnumChatFormatting.DARK_BLUE + "\u00B61 = Dark Blue", - EnumChatFormatting.DARK_GREEN + "\u00B62 = Dark Green", - EnumChatFormatting.DARK_AQUA + "\u00B63 = Dark Aqua", - EnumChatFormatting.DARK_RED + "\u00B64 = Dark Red", - EnumChatFormatting.DARK_PURPLE + "\u00B65 = Dark Purple", - EnumChatFormatting.GOLD + "\u00B66 = Gold", - EnumChatFormatting.GRAY + "\u00B67 = Gray", - EnumChatFormatting.DARK_GRAY + "\u00B68 = Dark Gray", - EnumChatFormatting.BLUE + "\u00B69 = Blue", - EnumChatFormatting.GREEN + "\u00B6a = Green", - EnumChatFormatting.AQUA + "\u00B6b = Aqua", - EnumChatFormatting.RED + "\u00B6c = Red", - EnumChatFormatting.LIGHT_PURPLE + "\u00B6d = Purple", - EnumChatFormatting.YELLOW + "\u00B6e = Yellow", - EnumChatFormatting.WHITE + "\u00B6f = White", - "\u00A7Z\u00B6Z = SBA Chroma" + EnumChatFormatting.RESET + EnumChatFormatting.GRAY + " (Requires SBA)", - "", - EnumChatFormatting.GREEN + "Available formatting codes:", - EnumChatFormatting.GRAY + "\u00B6k = " + EnumChatFormatting.OBFUSCATED + "Obfuscated", - EnumChatFormatting.GRAY + "\u00B6l = " + EnumChatFormatting.BOLD + "Bold", - EnumChatFormatting.GRAY + "\u00B6m = " + EnumChatFormatting.STRIKETHROUGH + "Strikethrough", - EnumChatFormatting.GRAY + "\u00B6n = " + EnumChatFormatting.UNDERLINE + "Underline", - EnumChatFormatting.GRAY + "\u00B6o = " + EnumChatFormatting.ITALIC + "Italic" - ); - } - - yTop += 25; - - RenderUtils.drawFloatingRectDark(xCenter - 90, yTop, 180, 110); - GlStateManager.enableDepth(); - GlStateManager.pushMatrix(); - GlStateManager.translate(xCenter - 48, yTop + 7, 0); - GlStateManager.scale(6, 6, 1); - this.customItemStack = copy(stack); - Utils.drawItemStack(customItemStack, 0, 0); - GlStateManager.popMatrix(); - - yTop += 115; - - RenderUtils.drawFloatingRectDark(xCenter - 90, yTop, 180, 20); - - Minecraft.getMinecraft().fontRendererObj.drawString("Enchant Glint", - xCenter - 85, yTop + 6, 0xff8040cc - ); - - enchantGlintButton.x = xCenter + 90 - 5 - 48; - enchantGlintButton.y = yTop + 3; - enchantGlintButton.render(); - - yTop += 25; - - enchantGlintCustomColourAnimation.tick(); - if (enchantGlintCustomColourAnimation.getValue() > 0) { - yTop -= 5; - - int glintColour = getGlintColour(); - - GlScissorStack.push( - 0, - yTop, - scaledResolution.getScaledWidth(), - scaledResolution.getScaledHeight(), - scaledResolution - ); - GlStateManager.translate(0, enchantGlintCustomColourAnimation.getValue() - 17, 0); - - Gui.drawRect(xCenter - 90, yTop, xCenter + 92, yTop + 17, 0x70000000); - Gui.drawRect(xCenter - 90, yTop, xCenter + 90, yTop + 15, 0xff101016); - Gui.drawRect(xCenter - 89, yTop + 1, xCenter + 89, yTop + 14, 0xff000000 | glintColour); - - Utils.renderShadowedString("\u00a7a\u00a7lCustom Glint Colour", xCenter, yTop + 4, 180); - - Minecraft.getMinecraft().getTextureManager().bindTexture(RESET); - GlStateManager.color(1, 1, 1, 1); - RenderUtils.drawTexturedRect(xCenter + 90 - 12, yTop + 2, 10, 11, GL11.GL_NEAREST); - - GlStateManager.translate(0, -enchantGlintCustomColourAnimation.getValue() + 17, 0); - GlScissorStack.pop(scaledResolution); - - yTop += enchantGlintCustomColourAnimation.getValue() + 3; - } - - supportCustomLeatherColour = customItemStack.getItem() instanceof ItemArmor && - ((ItemArmor) customItemStack.getItem()).getArmorMaterial() == ItemArmor.ArmorMaterial.LEATHER; - - if (supportCustomLeatherColour) { - int leatherColour = getLeatherColour(); - - Gui.drawRect(xCenter - 90, yTop, xCenter + 92, yTop + 17, 0x70000000); - Gui.drawRect(xCenter - 90, yTop, xCenter + 90, yTop + 15, 0xff101016); - Gui.drawRect(xCenter - 89, yTop + 1, xCenter + 89, yTop + 14, 0xff000000 | leatherColour); - - Utils.renderShadowedString("\u00a7b\u00a7lCustom Leather Colour", xCenter, yTop + 4, 180); - - Minecraft.getMinecraft().getTextureManager().bindTexture(RESET); - GlStateManager.color(1, 1, 1, 1); - RenderUtils.drawTexturedRect(xCenter + 90 - 12, yTop + 2, 10, 11, GL11.GL_NEAREST); - - yTop += 20; - } - - /*if(true) { - yTop += 20; - - String titleStr = "\u00a76\u00a7lWant other players to see your customized item?"; - String buttonStr = "\u00a76Purchase Item Customize Tag"; - if(true) { - buttonStr = "\u00a76Use item customize tag (3 remaining)"; - } - - int w = Minecraft.getMinecraft().fontRendererObj.getStringWidth(titleStr)+8; - if(w > scaledResolution.getScaledWidth()/2) w= scaledResolution.getScaledWidth()/2; - - RenderUtils.drawFloatingRectDark(xCenter-w/2, yTop, w, 50); - Utils.renderShadowedString(titleStr, xCenter, yTop+8, scaledResolution.getScaledWidth()/2); - - int ctw = Minecraft.getMinecraft().fontRendererObj.getStringWidth(buttonStr)+8; - - RenderUtils.drawFloatingRectDark(xCenter-ctw/2, yTop+25, ctw, 15); - Utils.renderShadowedString(buttonStr, xCenter, yTop+28, w); - - - - }*/ - - if (!lastCustomItem.equals(textFieldCustomItem.getText())) { - updateData(); - } - lastCustomItem = textFieldCustomItem.getText(); - - if (!textFieldCustomItem.getFocus() && textFieldCustomItem.getText().isEmpty()) { - textFieldCustomItem.setOptions(GuiElementTextField.SCISSOR_TEXT); - textFieldCustomItem.setPrependText("\u00a77Enter Custom Item ID..."); - } else { - textFieldCustomItem.setOptions(GuiElementTextField.COLOUR | GuiElementTextField.SCISSOR_TEXT); - textFieldCustomItem.setPrependText(""); - } - - if (!textFieldCustomItem.getFocus()) { - textFieldCustomItem.setSize(180, 20); - } else { - int textSize = fontRendererObj.getStringWidth(textFieldCustomItem.getTextDisplay()) + 10; - textFieldCustomItem.setSize(Math.max(textSize, 180), 20); - } - - int offset = 200; - if (!supportCustomLeatherColour) offset -= 20; - if (!enchantGlint) offset -= 16; - - textFieldCustomItem.render(xCenter - textFieldCustomItem.getWidth() / 2 - 10 + 11, yTopText + offset); - - renderHeight = yTop - yTopStart; - - if (editor != null) { - editor.render(); - } - - if (tooltipToDisplay != null) { - Utils.drawHoveringText(tooltipToDisplay, mouseX, mouseY, width, height, -1); - } - - super.drawScreen(mouseX, mouseY, partialTicks); - } - - @Override - public void updateScreen() { - if (enchantGlint) { - if (enchantGlintCustomColourAnimation.getTarget() != 17) { - enchantGlintCustomColourAnimation.setTarget(17); - enchantGlintCustomColourAnimation.resetTimer(); - } - } else { - if (enchantGlintCustomColourAnimation.getTarget() != 0) { - enchantGlintCustomColourAnimation.setTarget(0); - enchantGlintCustomColourAnimation.resetTimer(); - } - } - - super.updateScreen(); - } - - @Override - protected void keyTyped(char typedChar, int keyCode) throws IOException { - if (textFieldRename.getFocus()) { - if (keyCode == Keyboard.KEY_ESCAPE) { - textFieldRename.setFocus(false); - return; - } else { - textFieldRename.keyTyped(typedChar, keyCode); - } - } - - if (textFieldCustomItem.getFocus()) { - updateData(); - if (keyCode == Keyboard.KEY_ESCAPE) { - textFieldCustomItem.setFocus(false); - return; - } else { - textFieldCustomItem.keyTyped(typedChar, keyCode); - } - } - - super.keyTyped(typedChar, keyCode); - } - - @Override - public void handleKeyboardInput() throws IOException { - if (editor == null || !editor.keyboardInput()) { - if (editor != null && Keyboard.getEventKeyState() && Keyboard.getEventKey() == Keyboard.KEY_ESCAPE) { - editor = null; - } else { - super.handleKeyboardInput(); - } - } - } - - @Override - public void handleMouseInput() throws IOException { - int mouseX = Mouse.getEventX() * this.width / this.mc.displayWidth; - int mouseY = this.height - Mouse.getEventY() * this.height / this.mc.displayHeight - 1; - - if (editor == null || !editor.mouseInput(mouseX, mouseY)) { - super.handleMouseInput(); - enchantGlintButton.mouseInput(mouseX, mouseY); - } - } - - @Override - protected void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick) { - textFieldRename.mouseClickMove(mouseX, mouseY, clickedMouseButton, timeSinceLastClick); - textFieldCustomItem.mouseClickMove(mouseX, mouseY, clickedMouseButton, timeSinceLastClick); - } - - @Override - protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException { - ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); - int xCenter = scaledResolution.getScaledWidth() / 2; - int yTop = (scaledResolution.getScaledHeight() - renderHeight) / 2; - - if (mouseX >= xCenter - textFieldRename.getWidth() / 2 - 10 && - mouseX <= xCenter + textFieldRename.getWidth() / 2 - 10 && - mouseY >= yTop + 14 && mouseY <= yTop + 14 + textFieldRename.getHeight()) { - textFieldRename.mouseClicked(mouseX, mouseY, mouseButton); - } else { - textFieldRename.unfocus(); - } - - int offset = 200; - if (!supportCustomLeatherColour) offset -= 20; - if (!enchantGlint) offset -= 18; - - if (mouseX >= xCenter - textFieldCustomItem.getWidth() / 2 - 10 + 11 && - mouseX <= xCenter + textFieldCustomItem.getWidth() / 2 - 10 + 11 && - mouseY >= yTop + offset + 14 && mouseY <= yTop + offset + 14 + textFieldCustomItem.getHeight()) { - textFieldCustomItem.mouseClicked(mouseX, mouseY, mouseButton); - } else { - textFieldCustomItem.unfocus(); - } - - if (enchantGlint && mouseX >= xCenter - 90 && mouseX <= xCenter + 90 && - mouseY >= yTop + 174 && mouseY <= yTop + 174 + enchantGlintCustomColourAnimation.getValue()) { - if (mouseX >= xCenter + 90 - 12) { - editor = null; - customGlintColour = ItemCustomizeManager.DEFAULT_GLINT_COLOR; - updateData(); - } else { - editor = new GuiElementColour( - mouseX, - mouseY, - () -> customGlintColour == null ? ItemCustomizeManager.DEFAULT_GLINT_COLOR : customGlintColour, - (colour) -> { - customGlintColour = colour; - updateData(); - }, - () -> editor = null - ); - } - } - - float belowEnchGlint = yTop + 174 + enchantGlintCustomColourAnimation.getValue() + 5; - - if (supportCustomLeatherColour && mouseX >= xCenter - 90 && mouseX <= xCenter + 90 && - mouseY >= belowEnchGlint && - mouseY <= belowEnchGlint + 15) { - if (mouseX >= xCenter + 90 - 12) { - editor = null; - customLeatherColour = null; - updateData(); - } else { - editor = new GuiElementColour(mouseX, mouseY, - () -> customLeatherColour == null ? getChromaStrFromLeatherColour() : customLeatherColour, - (colour) -> { - customLeatherColour = colour; - updateData(); - }, () -> editor = null, false, true - ); - } - } - - super.mouseClicked(mouseX, mouseY, mouseButton); - } -} 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 new file mode 100644 index 00000000..1e26c759 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/itemcustomization/DyeType.java @@ -0,0 +1,59 @@ +/* + * 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 . + */ + +package io.github.moulberry.notenoughupdates.miscgui.itemcustomization; + +import com.google.gson.JsonArray; + +public class DyeType { + + String itemId; + String colour = null; + JsonArray colours = null; + String[] coloursArray = null; + int ticks = 2; + + public DyeType(String displayName) { + this.itemId = displayName; + + } + + public DyeType(String itemID, String colour) { + this.itemId = itemID; + this.colour = colour; + } + + public DyeType(String itemID, JsonArray colours) { + this.itemId = itemID; + this.colours = colours; + } + + public DyeType(String[] coloursArray, int ticks) { + this.ticks = ticks; + this.coloursArray = coloursArray; + } + + public boolean hasStaticColour() { + return colour != null; + } + + public boolean hasAnimatedColour() { + return colours != null; + } +} 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 new file mode 100644 index 00000000..f97d7e41 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/itemcustomization/GuiItemCustomize.java @@ -0,0 +1,1065 @@ +/* + * Copyright (C) 2022-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 . + */ + +package io.github.moulberry.notenoughupdates.miscgui.itemcustomization; + +import com.google.gson.Gson; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import io.github.moulberry.notenoughupdates.NotEnoughUpdates; +import io.github.moulberry.notenoughupdates.core.GlScissorStack; +import io.github.moulberry.notenoughupdates.core.GuiElement; +import io.github.moulberry.notenoughupdates.core.GuiElementBoolean; +import io.github.moulberry.notenoughupdates.core.GuiElementColour; +import io.github.moulberry.notenoughupdates.core.GuiElementTextField; +import io.github.moulberry.notenoughupdates.core.util.lerp.LerpingFloat; +import io.github.moulberry.notenoughupdates.core.util.render.RenderUtils; +import io.github.moulberry.notenoughupdates.util.Constants; +import io.github.moulberry.notenoughupdates.util.GuiTextures; +import io.github.moulberry.notenoughupdates.util.SpecialColour; +import io.github.moulberry.notenoughupdates.util.Utils; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Gui; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.gui.ScaledResolution; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.resources.model.IBakedModel; +import net.minecraft.item.ItemArmor; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.MathHelper; +import net.minecraft.util.ResourceLocation; +import org.lwjgl.input.Keyboard; +import org.lwjgl.input.Mouse; +import org.lwjgl.opengl.GL11; + +import java.awt.*; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Objects; + +public class GuiItemCustomize extends GuiScreen { + private static final ResourceLocation PLUS = new ResourceLocation("notenoughupdates:itemcustomize/plus.png"); + + private final ItemStack stack; + ItemStack customItemStack; + private final String itemUUID; + private final GuiElementTextField textFieldRename = new GuiElementTextField("", 138, 20, GuiElementTextField.COLOUR); + final GuiElementTextField textFieldCustomItem = new GuiElementTextField("", 180, 20, GuiElementTextField.COLOUR); + final GuiElementTextField textFieldTickSpeed = new GuiElementTextField("", 180, 45, GuiElementTextField.COLOUR | GuiElementTextField.NUM_ONLY); + private final GuiElementBoolean enchantGlintButton; + + private int renderHeight = 0; + + private final LerpingFloat enchantGlintCustomColourAnimation = new LerpingFloat(0, 200); + + private boolean enchantGlint; + String customGlintColour = null; + + String customLeatherColour = null; + ArrayList animatedLeatherColours = new ArrayList<>(); + int animatedDyeTicks = 2; + private int lastTicks = 2; + boolean supportCustomLeatherColour; + private String lastCustomItem = ""; + + JsonObject animatedDyes = null; + JsonObject staticDyes = null; + ArrayList dyes = new ArrayList<>(); + boolean repoError = false; + + private GuiElement editor = null; + + private GuiType guiType = GuiType.DEFAULT; + + public GuiItemCustomize(ItemStack stack, String itemUUID) { + this.stack = stack; + this.itemUUID = itemUUID; + this.customItemStack = ItemCustomizationUtils.copy(stack, this); + + IBakedModel model = Minecraft.getMinecraft().getRenderItem().getItemModelMesher().getItemModel(stack); + boolean stackHasEffect = stack.hasEffect() && !model.isBuiltInRenderer(); + + ItemCustomizeManager.ItemData data = ItemCustomizeManager.getDataForItem(stack); + if (data != null) { + this.enchantGlint = data.overrideEnchantGlint ? data.enchantGlintValue : stackHasEffect; + if (data.customName != null) { + textFieldRename.setText(data.customName); + } + if (data.customItem != null && data.customItem.length() > 0) { + textFieldCustomItem.setText(data.customItem); + } else { + textFieldCustomItem.setText(stack.getItem().getRegistryName().replace("minecraft:", "")); + } + this.customGlintColour = data.customGlintColour; + this.customLeatherColour = data.customLeatherColour; + if (data.animatedLeatherColours != null) { + this.animatedLeatherColours = new ArrayList<>(Arrays.asList(data.animatedLeatherColours)); + if (data.animatedDyeTicks < 1) { + this.animatedDyeTicks = 1; + data.animatedDyeTicks = 1; + } else { + this.animatedDyeTicks = data.animatedDyeTicks; + } + this.textFieldTickSpeed.setText("" + this.animatedDyeTicks); + } else { + this.animatedLeatherColours = new ArrayList<>(); + this.textFieldTickSpeed.setText("2"); + + } + } else { + this.enchantGlint = stackHasEffect; + textFieldCustomItem.setText(stack.getItem().getRegistryName().replace("minecraft:", "")); + } + + supportCustomLeatherColour = customItemStack.getItem() instanceof ItemArmor && + ((ItemArmor) customItemStack.getItem()).getArmorMaterial() == ItemArmor.ArmorMaterial.LEATHER; + + enchantGlintCustomColourAnimation.setValue(enchantGlint ? 17 : 0); + this.enchantGlintButton = new GuiElementBoolean(0, 0, () -> enchantGlint, (bool) -> { + enchantGlint = bool; + updateData(); + }); + + JsonObject dyesConst = Constants.DYES; + + if (dyesConst == null) { + Utils.showOutdatedRepoNotification("dyes.json"); + repoError = true; + return; + } else { + repoError = false; + } + + if (dyesConst.has("animated")) { + 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(); + DyeType dyeType = new DyeType(key, value); + dyes.add(dyeType); + }); + } + + if (dyesConst.has("static")) { + staticDyes = dyesConst.get("static").getAsJsonObject(); + DyeType staticHeader = new DyeType("Static Dyes"); + dyes.add(staticHeader); + + staticDyes.entrySet().forEach(entry -> { + String key = entry.getKey(); + String value = entry.getValue().getAsString(); + DyeType dyeType = new DyeType(key, value); + dyes.add(dyeType); + }); + } + } + + @Override + public void onGuiClosed() { + updateData(); + } + + public void updateData() { + ItemCustomizeManager.ItemData data = new ItemCustomizeManager.ItemData(); + + IBakedModel model = Minecraft.getMinecraft().getRenderItem().getItemModelMesher().getItemModel(stack); + boolean stackHasEffect = stack.hasEffect() && !model.isBuiltInRenderer(); + + this.customItemStack = ItemCustomizationUtils.copy(stack, this); + data.defaultItem = stack.getItem().getRegistryName(); + + if (this.enchantGlint != stackHasEffect) { + data.overrideEnchantGlint = true; + data.enchantGlintValue = this.enchantGlint; + } + + if (this.customGlintColour != null && !this.customGlintColour.equals(ItemCustomizeManager.DEFAULT_GLINT_COLOR)) { + data.customGlintColour = this.customGlintColour; + } else if (model.isBuiltInRenderer() && data.overrideEnchantGlint && data.enchantGlintValue) { + data.customGlintColour = ItemCustomizeManager.DEFAULT_GLINT_COLOR; + } else { + data.customGlintColour = null; + } + + if (this.customLeatherColour != null && (!(customItemStack.getItem() instanceof ItemArmor) || + !this.customLeatherColour.equals(ItemCustomizationUtils.getChromaStrFromLeatherColour(this)))) { + data.customLeatherColour = this.customLeatherColour; + } else { + data.customLeatherColour = null; + } + + if (!this.animatedLeatherColours.isEmpty()) { + data.animatedLeatherColours = new String[animatedLeatherColours.size()]; + data.animatedLeatherColours = animatedLeatherColours.toArray(data.animatedLeatherColours); + if (textFieldTickSpeed.getText().isEmpty()) { + data.animatedDyeTicks = 2; + } else { + try { + int dyeTicks = Integer.parseInt(textFieldTickSpeed.getText()); + data.animatedDyeTicks = Math.max(dyeTicks, 1); + } catch (NumberFormatException e) { + data.animatedDyeTicks = 2; + } + } + } + + if (!this.textFieldRename.getText().isEmpty()) { + data.customName = this.textFieldRename.getText(); + + NBTTagCompound stackTagCompound = stack.getTagCompound(); + if (stackTagCompound != null && stackTagCompound.hasKey("display", 10)) { + NBTTagCompound nbttagcompound = stackTagCompound.getCompoundTag("display"); + + if (nbttagcompound.hasKey("Name", 8)) { + String name = nbttagcompound.getString("Name"); + char[] chars = name.toCharArray(); + + int i; + for (i = 0; i < chars.length; i += 2) { + if (chars[i] != '\u00a7') { + break; + } + } + + data.customNamePrefix = name.substring(0, i); + } + } + } + + if (!this.textFieldCustomItem.getText().isEmpty()) { + data.customItem = this.textFieldCustomItem.getText(); + } + + ItemCustomizeManager.putItemData(itemUUID, data); + } + + @Override + public void drawScreen(int mouseX, int mouseY, float partialTicks) { + if (!supportCustomLeatherColour) guiType = GuiType.DEFAULT; + drawScreenType(mouseX, mouseY, partialTicks, guiType); + } + + private void drawScreenType(int mouseX, int mouseY, float partialTicks, GuiType type) { + if (type == GuiType.DEFAULT) { + drawScreenDefault(mouseX, mouseY, partialTicks); + } else if (type == GuiType.ANIMATED) { + drawScreenAnimatedDyes(mouseX, mouseY, partialTicks); + } else if (type == GuiType.HYPIXEL) { + drawScreenHypixel(mouseX, mouseY, partialTicks); + } + } + + private void drawScreenDefault(int mouseX, int mouseY, float partialTicks) { + drawDefaultBackground(); + + List tooltipToDisplay = null; + + ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); + + int xCenter = scaledResolution.getScaledWidth() / 2; + int yTopStart = (scaledResolution.getScaledHeight() - renderHeight) / 2; + int yTop = yTopStart; + + renderHeader(xCenter, yTop); + + yTop += 14; + + ItemCustomizationUtils.renderTextBox(textFieldRename, "§7Enter Custom Name...", xCenter - textFieldRename.getWidth() / 2 - 20, yTop, 138); + + int yTopText = yTop; + + Minecraft.getMinecraft().getTextureManager().bindTexture(GuiTextures.help); + GlStateManager.color(1, 1, 1, 1); + int helpX = xCenter + textFieldRename.getWidth() / 2 - 5 + 10; + Utils.drawTexturedRect(helpX, yTop, 20, 20, GL11.GL_LINEAR); + + if (mouseX >= helpX && mouseX <= helpX + 20 && mouseY >= yTop && mouseY <= yTop + 20) { + ItemCustomizationUtils.customizeColourGuide.set(7, Utils.chromaString("¶z = Chroma")); + tooltipToDisplay = ItemCustomizationUtils.customizeColourGuide; + } + + Minecraft.getMinecraft().getTextureManager().bindTexture(ItemCustomizationUtils.RESET); + GlStateManager.color(1, 1, 1, 1); + int resetX = xCenter + textFieldRename.getWidth() / 2 - 15; + Utils.drawTexturedRect(resetX, yTop + 5, 10, 11, GL11.GL_LINEAR); + + if (mouseX >= resetX && mouseX <= resetX + 10 && mouseY >= yTop && mouseY <= yTop + 20) { + tooltipToDisplay = ItemCustomizationUtils.resetGuide; + } + + ItemCustomizationUtils.renderPresetButtons(xCenter, + yTop, + ItemCustomizationUtils.validShareContents("NEUCUSTOMIZE"), + true, + "preset" + ); + + yTop += 25; + + renderBigStack(xCenter, yTop); + + yTop += 115; + + RenderUtils.drawFloatingRectDark(xCenter - 90, yTop, 180, 20); + + Minecraft.getMinecraft().fontRendererObj.drawString("Enchant Glint", xCenter - 85, yTop + 6, 0xff8040cc); + + enchantGlintButton.x = xCenter + 90 - 5 - 48; + enchantGlintButton.y = yTop + 3; + enchantGlintButton.render(); + + yTop += 25; + + enchantGlintCustomColourAnimation.tick(); + if (enchantGlintCustomColourAnimation.getValue() > 0) { + yTop -= 5; + + int glintColour = ItemCustomizationUtils.getGlintColour(this); + + GlScissorStack.push(0, + yTop, + scaledResolution.getScaledWidth(), + scaledResolution.getScaledHeight(), + scaledResolution + ); + GlStateManager.translate(0, enchantGlintCustomColourAnimation.getValue() - 17, 0); + + ItemCustomizationUtils.renderColourBlob(xCenter, yTop, glintColour, "§a§lCustom Glint Colour", true, false); + + GlStateManager.translate(0, -enchantGlintCustomColourAnimation.getValue() + 17, 0); + GlScissorStack.pop(scaledResolution); + + yTop += enchantGlintCustomColourAnimation.getValue() + 3; + } + + supportCustomLeatherColour = customItemStack.getItem() instanceof ItemArmor && + ((ItemArmor) customItemStack.getItem()).getArmorMaterial() == ItemArmor.ArmorMaterial.LEATHER; + + if (supportCustomLeatherColour) { + int leatherColour = ItemCustomizationUtils.getLeatherColour(this); + + String text = "§b§lCustom Leather Colour"; + boolean reset = true; + + if (!animatedLeatherColours.isEmpty()) { + text = "§b§lOverridden by Animated"; + reset = false; + } + + ItemCustomizationUtils.renderColourBlob(xCenter, yTop, leatherColour, text, reset, false); + + yTop += 20; + } + + if (!lastCustomItem.equals(textFieldCustomItem.getText())) { + updateData(); + } + lastCustomItem = textFieldCustomItem.getText(); + + int offset = 200; + if (!supportCustomLeatherColour) offset -= 20; + if (!enchantGlint) offset -= 16; + + ItemCustomizationUtils.renderTextBox(textFieldCustomItem, "§7Enter Custom Item ID...", xCenter - textFieldCustomItem.getWidth() / 2 - 10 + 11, yTopText + offset, 180); + + if (supportCustomLeatherColour) { + yTop += 25; + ItemCustomizationUtils.renderFooter(xCenter, yTop, guiType); + } + + renderHeight = yTop - yTopStart; + + if (editor != null) { + editor.render(); + } + + if (tooltipToDisplay != null) { + Utils.drawHoveringText(tooltipToDisplay, mouseX, mouseY, width, height, -1); + } + + super.drawScreen(mouseX, mouseY, partialTicks); + } + + private void drawScreenAnimatedDyes(int mouseX, int mouseY, float partialTicks) { + drawDefaultBackground(); + + List tooltipToDisplay = null; + + ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); + + int xCenter = scaledResolution.getScaledWidth() / 2; + int yTopStart = (scaledResolution.getScaledHeight() - renderHeight) / 2; + int yTop = yTopStart; + + renderHeader(xCenter, yTop); + + ItemCustomizationUtils.renderPresetButtons(xCenter, + yTop, + ItemCustomizationUtils.validShareContents("NEUCUSTOMIZE"), + true, + "preset" + ); + ItemCustomizationUtils.renderPresetButtons(xCenter, + yTop + 50, + ItemCustomizationUtils.validShareContents("NEUANIMATED"), + !this.animatedLeatherColours.isEmpty(), + "animated" + ); + + yTop += 14; + + renderBigStack(xCenter, yTop); + + yTop += 115; + + int adjustedY = yTop + pageScroll + 20; + + for (int i = 0; i < animatedLeatherColours.size(); i++) { + if (adjustedY + 20 * i < yTopStart + 130 || adjustedY + 20 * i >= yTopStart + guiScaleOffset() + 150) { + continue; + } + + int leatherColour = ItemCustomizationUtils.getLeatherColour(animatedLeatherColours.get(i)); + ItemCustomizationUtils.renderColourBlob(xCenter, yTop, leatherColour, "§b§lDye Colour " + (i + 1), false, true); + + yTop += 20; + } + + Minecraft.getMinecraft().getTextureManager().bindTexture(PLUS); + GlStateManager.color(1, 1, 1, 1); + RenderUtils.drawTexturedRect(xCenter + 90 - 12, yTop + 4, 10, 10, GL11.GL_NEAREST); + + int xOffset = xCenter - textFieldCustomItem.getWidth() / 2 - 10 + 11; + ItemCustomizationUtils.renderTextBox(textFieldTickSpeed, + "§7Speed...", + xOffset, + yTop, + 45 + ); + + if (mouseX >= xOffset && mouseX <= xOffset + textFieldTickSpeed.getWidth() && mouseY >= yTop && mouseY <= yTop + 20) { + tooltipToDisplay = ItemCustomizationUtils.speedGuide; + } + + // Button background + Gui.drawRect(xCenter - 40, yTop + 2, xCenter - 2, yTop + 19, 0x70000000); + Gui.drawRect(xCenter - 40, yTop + 2, xCenter - 2, yTop + 16, 0xff101016); + Gui.drawRect(xCenter - 39, yTop + 3, xCenter - 3, yTop + 16, 0xff000000 | 0xff6955); + Utils.renderShadowedString("§c§lClear", xCenter - 20, yTop + 6, xCenter * 2); + + yTop += 25; + + enchantGlintCustomColourAnimation.tick(); + + ItemCustomizationUtils.renderFooter(xCenter, yTop, guiType); + + try { + if (lastTicks != (Integer.parseInt(textFieldTickSpeed.getText()))) { + updateData(); + } + lastTicks = Integer.parseInt(textFieldTickSpeed.getText()); + } catch (NumberFormatException ignored) { + } + + renderHeight = yTop - yTopStart; + + if (editor != null) { + editor.render(); + } + + if (tooltipToDisplay != null) { + Utils.drawHoveringText(tooltipToDisplay, mouseX, mouseY, width, height, -1); + } + + scrollScreen(animatedLeatherColours.size()); + + super.drawScreen(mouseX, mouseY, partialTicks); + } + + private void drawScreenHypixel(int mouseX, int mouseY, float partialTicks) { + drawDefaultBackground(); + + List tooltipToDisplay = null; + + ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft()); + + int xCenter = scaledResolution.g