diff options
author | NopoTheGamer <40329022+NopoTheGamer@users.noreply.github.com> | 2023-03-12 02:05:14 +1100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-11 16:05:14 +0100 |
commit | fd063280c717e974bc9ac35f730e61b1be9de856 (patch) | |
tree | 1a9682ff3c573abc1e47a9f4bcec97128f37696a /src | |
parent | 95e17c191b8a0bdfa5af09a9cf658fe741ecaafc (diff) | |
download | NotEnoughUpdates-fd063280c717e974bc9ac35f730e61b1be9de856.tar.gz NotEnoughUpdates-fd063280c717e974bc9ac35f730e61b1be9de856.tar.bz2 NotEnoughUpdates-fd063280c717e974bc9ac35f730e61b1be9de856.zip |
Custom items in /neucustomize (#609)
* should work :tm:, probably breaks other mods, needs to be added to /neurename gui
* Improved compatibility with other mods probably
* Added a text box to /neurename
* Polish up everything
* Fix skulls have durability bar
* Should be everything finished
* add support for metadata and skulls rendering properly
* Made gui look nice
* fix leather not being coloured while moving it
* Fixed normal helmets not rendering
* fix pumpkin not showing overlay
* Fixed skulls showing as null by default on most other items
* added support to randomize the subitems with ":?"
* Add support for custom armour besides the head
* move custom armour function
* code dupe glitch
* A small sign in the permanent fight against duplication of code.
* clear cache on world unload
---------
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src')
11 files changed, 356 insertions, 12 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/ItemCustomizeManager.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/ItemCustomizeManager.java index dad801ec..ecab042c 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/ItemCustomizeManager.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/ItemCustomizeManager.java @@ -22,16 +22,23 @@ 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.NotEnoughUpdates; +import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe; import io.github.moulberry.notenoughupdates.core.ChromaColour; 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; @@ -46,9 +53,12 @@ import java.io.FileOutputStream; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.nio.charset.StandardCharsets; +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 @@ -81,6 +91,9 @@ public class ItemCustomizeManager { 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) { @@ -313,4 +326,104 @@ public class ItemCustomizeManager { } catch (Exception ignored) { } } + + public static Item getCustomItem(ItemStack stack) { + ItemData data = getDataForItem(stack); + if (data == null || data.customItem == null || data.customItem.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) { + Item newItem = Item.getByNameOrId(newItemString.split(":")[0]); + if (newItem == null) return stack.getItem(); + return newItem; + } + + static Random random = new Random(); + static HashMap<Integer, Long> lastUpdate = new HashMap<>(); + static HashMap<Integer, Integer> 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<ItemStack> 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)) 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) return stack; + ItemStack newStack = stack.copy(); + newStack.setItem(ItemCustomizeManager.getCustomItem(newStack)); + newStack.setItemDamage(ItemCustomizeManager.getCustomItemDamage(newStack)); + if (armorSlot != 4) { + if (newStack.getItem() instanceof ItemArmor) return newStack; + else 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 index eac58a1a..d9b24895 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiItemCustomize.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiItemCustomize.java @@ -53,8 +53,10 @@ 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; @@ -65,13 +67,15 @@ public class GuiItemCustomize extends GuiScreen { private String customGlintColour = null; private String customLeatherColour = null; - private final boolean supportCustomLeatherColour; + 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(); @@ -82,14 +86,20 @@ public class GuiItemCustomize extends GuiScreen { 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 = stack.getItem() instanceof ItemArmor && - ((ItemArmor) stack.getItem()).getArmorMaterial() == ItemArmor.ArmorMaterial.LEATHER; + 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) -> { @@ -105,7 +115,7 @@ public class GuiItemCustomize extends GuiScreen { } public String getChromaStrFromLeatherColour() { - return ChromaColour.special(0, 0xff, ((ItemArmor) stack.getItem()).getColor(stack)); + return ChromaColour.special(0, 0xff, ((ItemArmor) customItemStack.getItem()).getColor(customItemStack)); } public void updateData() { @@ -114,6 +124,9 @@ public class GuiItemCustomize extends GuiScreen { 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; @@ -127,8 +140,8 @@ public class GuiItemCustomize extends GuiScreen { data.customGlintColour = null; } - if (supportCustomLeatherColour && this.customLeatherColour != null && !this.customLeatherColour.equals( - getChromaStrFromLeatherColour())) { + if (this.customLeatherColour != null && (!(customItemStack.getItem() instanceof ItemArmor) || !this.customLeatherColour.equals( + getChromaStrFromLeatherColour()))) { data.customLeatherColour = this.customLeatherColour; } else { data.customLeatherColour = null; @@ -157,9 +170,22 @@ public class GuiItemCustomize extends GuiScreen { } } + 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) @@ -171,7 +197,7 @@ public class GuiItemCustomize extends GuiScreen { if (!supportCustomLeatherColour) return 0xff000000; int col = - customLeatherColour == null ? ((ItemArmor) stack.getItem()).getColor(stack) : ChromaColour.specialToChromaRGB( + customLeatherColour == null ? ((ItemArmor) customItemStack.getItem()).getColor(customItemStack) : ChromaColour.specialToChromaRGB( customLeatherColour); return 0xff000000 | col; } @@ -188,7 +214,7 @@ public class GuiItemCustomize extends GuiScreen { int yTopStart = (scaledResolution.getScaledHeight() - renderHeight) / 2; int yTop = yTopStart; - RenderUtils.drawFloatingRectDark(xCenter - 100, yTop - 9, 200, renderHeight + 11); + 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); @@ -211,6 +237,7 @@ public class GuiItemCustomize extends GuiScreen { } textFieldRename.render(xCenter - textFieldRename.getWidth() / 2 - 10, yTop); + int yTopText = yTop; Minecraft.getMinecraft().getTextureManager().bindTexture(GuiTextures.help); GlStateManager.color(1, 1, 1, 1); @@ -260,7 +287,8 @@ public class GuiItemCustomize extends GuiScreen { GlStateManager.pushMatrix(); GlStateManager.translate(xCenter - 48, yTop + 7, 0); GlStateManager.scale(6, 6, 1); - Utils.drawItemStack(stack, 0, 0); + this.customItemStack = copy(stack); + Utils.drawItemStack(customItemStack, 0, 0); GlStateManager.popMatrix(); yTop += 115; @@ -308,6 +336,9 @@ public class GuiItemCustomize extends GuiScreen { yTop += enchantGlintCustomColourAnimation.getValue() + 3; } + supportCustomLeatherColour = customItemStack.getItem() instanceof ItemArmor && + ((ItemArmor) customItemStack.getItem()).getArmorMaterial() == ItemArmor.ArmorMaterial.LEATHER; + if (supportCustomLeatherColour) { int leatherColour = getLeatherColour(); @@ -348,6 +379,32 @@ public class GuiItemCustomize extends GuiScreen { }*/ + 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) { @@ -389,6 +446,16 @@ public class GuiItemCustomize extends GuiScreen { } } + if (textFieldCustomItem.getFocus()) { + updateData(); + if (keyCode == Keyboard.KEY_ESCAPE) { + textFieldCustomItem.setFocus(false); + return; + } else { + textFieldCustomItem.keyTyped(typedChar, keyCode); + } + } + super.keyTyped(typedChar, keyCode); } @@ -417,6 +484,7 @@ public class GuiItemCustomize extends GuiScreen { @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 @@ -433,6 +501,18 @@ public class GuiItemCustomize extends GuiScreen { 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) { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiContainer.java b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiContainer.java index 2c7cf0ee..adae04f8 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiContainer.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiContainer.java @@ -31,6 +31,7 @@ import io.github.moulberry.notenoughupdates.miscfeatures.AuctionSortModeWarning; import io.github.moulberry.notenoughupdates.miscfeatures.BetterContainers; import io.github.moulberry.notenoughupdates.miscfeatures.DungeonNpcProfitOverlay; import io.github.moulberry.notenoughupdates.miscfeatures.EnchantingSolvers; +import io.github.moulberry.notenoughupdates.miscfeatures.ItemCustomizeManager; import io.github.moulberry.notenoughupdates.miscfeatures.PresetWarning; import io.github.moulberry.notenoughupdates.miscfeatures.SlotLocking; import io.github.moulberry.notenoughupdates.miscgui.GuiCustomEnchant; @@ -57,6 +58,7 @@ import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.ModifyArg; import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @@ -335,4 +337,14 @@ public abstract class MixinGuiContainer extends GuiScreen { private void drawBackground(int mouseX, int mouseY, float partialTicks, CallbackInfo ci) { new GuiContainerBackgroundDrawnEvent(((GuiContainer) (Object) this), partialTicks).post(); } + + @ModifyArg(method = "drawSlot", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/entity/RenderItem;renderItemAndEffectIntoGUI(Lnet/minecraft/item/ItemStack;II)V", ordinal = 0)) + public ItemStack drawSlot_renderItemAndEffectIntoGUI(ItemStack stack) { + return ItemCustomizeManager.useCustomItem(stack); + } + + @ModifyArg(method = "drawSlot", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/entity/RenderItem;renderItemOverlayIntoGUI(Lnet/minecraft/client/gui/FontRenderer;Lnet/minecraft/item/ItemStack;IILjava/lang/String;)V")) + public ItemStack drawSlot_renderItemOverlays(ItemStack stack) { + return ItemCustomizeManager.useCustomItem(stack); + } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiIngame.java b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiIngame.java index 381f5934..285163ab 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiIngame.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiIngame.java @@ -20,24 +20,36 @@ package io.github.moulberry.notenoughupdates.mixins; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; +import io.github.moulberry.notenoughupdates.miscfeatures.ItemCustomizeManager; import io.github.moulberry.notenoughupdates.miscfeatures.StreamerMode; import io.github.moulberry.notenoughupdates.miscgui.InventoryStorageSelector; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiIngame; import net.minecraft.client.gui.ScaledResolution; +import net.minecraft.client.renderer.entity.RenderItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; import net.minecraft.scoreboard.ScorePlayerTeam; import net.minecraft.scoreboard.Team; +import org.spongepowered.asm.lib.Opcodes; +import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.ModifyArg; import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin({GuiIngame.class}) public class MixinGuiIngame { + @Shadow + @Final + protected RenderItem itemRenderer; + @Shadow + @Final + protected Minecraft mc; private static final String TARGET = "Lnet/minecraft/scoreboard/ScorePlayerTeam;" + "formatPlayerName(Lnet/minecraft/scoreboard/Team;Ljava/lang/String;)Ljava/lang/String;"; @@ -80,4 +92,19 @@ public class MixinGuiIngame { } return inventory.getCurrentItem(); } + + @Redirect(method = "renderHotbarItem", at = @At(value = "FIELD", target = "Lnet/minecraft/item/ItemStack;animationsToGo:I", opcode = Opcodes.GETFIELD)) + public int renderHotbarItem_animationsToGo(ItemStack stack) { + return ItemCustomizeManager.useCustomItem(stack).animationsToGo; + } + + @ModifyArg(method = "renderHotbarItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/entity/RenderItem;renderItemAndEffectIntoGUI(Lnet/minecraft/item/ItemStack;II)V", ordinal = 0)) + public ItemStack renderHotbarItem_renderItemAndEffectIntoGUI(ItemStack stack) { + return ItemCustomizeManager.useCustomItem(stack); + } + + @ModifyArg(method = "renderHotbarItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/entity/RenderItem;renderItemOverlays(Lnet/minecraft/client/gui/FontRenderer;Lnet/minecraft/item/ItemStack;II)V", ordinal = 0)) + public ItemStack renderHotbarItem_renderItemOverlays(ItemStack stack) { + return ItemCustomizeManager.useCustomItem(stack); + } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiIngameForge.java b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiIngameForge.java new file mode 100644 index 00000000..b263cf31 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiIngameForge.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2023 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.mixins; + +import io.github.moulberry.notenoughupdates.miscfeatures.ItemCustomizeManager; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraftforge.client.GuiIngameForge; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Mixin(GuiIngameForge.class) +public class MixinGuiIngameForge { + + @Redirect(method = "renderHelmet", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;getItem()Lnet/minecraft/item/Item;", ordinal = 1)) + public Item renderHelmet(ItemStack stack) { + return ItemCustomizeManager.useCustomItem(stack).getItem(); + } +} diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinItemRenderer.java b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinItemRenderer.java index c2739ad8..eb32ed70 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinItemRenderer.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinItemRenderer.java @@ -19,16 +19,20 @@ package io.github.moulberry.notenoughupdates.mixins; +import io.github.moulberry.notenoughupdates.miscfeatures.ItemCustomizeManager; import io.github.moulberry.notenoughupdates.miscgui.InventoryStorageSelector; import net.minecraft.client.renderer.ItemRenderer; import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.ModifyArg; import org.spongepowered.asm.mixin.injection.Redirect; @Mixin(ItemRenderer.class) public abstract class MixinItemRenderer { + @Redirect(method = "updateEquippedItem", at = @At( value = "INVOKE", target = "Lnet/minecraft/entity/player/InventoryPlayer;getCurrentItem()Lnet/minecraft/item/ItemStack;" @@ -39,4 +43,19 @@ public abstract class MixinItemRenderer { } return player.getCurrentItem(); } + + @Redirect(method = "renderItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;getItem()Lnet/minecraft/item/Item;")) + public Item renderItem_getItem(ItemStack stack) { + return ItemCustomizeManager.useCustomItem(stack).getItem(); + } + + @ModifyArg(method = "renderItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/entity/RenderItem;shouldRenderItemIn3D(Lnet/minecraft/item/ItemStack;)Z")) + public ItemStack renderItem_shouldRenderItemIn3D(ItemStack stack) { + return ItemCustomizeManager.useCustomItem(stack); + } + + @ModifyArg(method = "renderItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/entity/RenderItem;renderItemModelForEntity(Lnet/minecraft/item/ItemStack;Lnet/minecraft/entity/EntityLivingBase;Lnet/minecraft/client/renderer/block/model/ItemCameraTransforms$TransformType;)V", ordinal = 0)) + public ItemStack renderItem_renderItemModelForEntity(ItemStack stack) { + return ItemCustomizeManager.useCustomItem(stack); + } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinItemStack.java b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinItemStack.java index 83379a18..127e4216 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinItemStack.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinItemStack.java @@ -19,6 +19,7 @@ package io.github.moulberry.notenoughupdates.mixins; +import io.github.moulberry.notenoughupdates.core.ChromaColour; import io.github.moulberry.notenoughupdates.miscfeatures.ItemCustomizeManager; import io.github.moulberry.notenoughupdates.util.Utils; import net.minecraft.item.ItemStack; @@ -27,8 +28,11 @@ import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import java.awt.*; + @Mixin({ItemStack.class}) public class MixinItemStack { @Inject(method = "hasEffect", at = @At("HEAD"), cancellable = true) @@ -66,4 +70,32 @@ public class MixinItemStack { } catch (Exception ignored) { } } + + @Redirect(method = "getTooltip", at = @At(value = "INVOKE", target = "Lnet/minecraft/nbt/NBTTagCompound;hasKey(Ljava/lang/String;I)Z", ordinal = 2)) + public boolean getTooltip_hasKey2(NBTTagCompound nbttagcompound, String key, int type) { + ItemStack stack = (ItemStack) (Object) this; + ItemCustomizeManager.ItemData data = ItemCustomizeManager.getDataForItem(stack); + if (data != null && data.customLeatherColour != null && ItemCustomizeManager.shouldRenderLeatherColour(stack)) { + return true; + } else if (data != null && !ItemCustomizeManager.shouldRenderLeatherColour(stack)) { + return false; + } + return nbttagcompound.hasKey("color", 3); + } + + @Redirect(method = "getTooltip", at = @At(value = "INVOKE", target = "Ljava/lang/Integer;toHexString(I)Ljava/lang/String;")) + public String getTooltip_toHexString(int colour) { + ItemStack stack = (ItemStack) (Object) this; + ItemCustomizeManager.ItemData data = ItemCustomizeManager.getDataForItem(stack); + if (data != null && data.customLeatherColour != null && ItemCustomizeManager.shouldRenderLeatherColour(stack)) { + int currentColour = ChromaColour.specialToChromaRGB(data.customLeatherColour); + Color c = new Color(currentColour, false); + String hex = Integer.toHexString(c.getRGB() & 0xFFFFFF); + if (hex.length() < 6) { + hex = hex + "000000".substring(0, 6 - hex.length()); + } + return hex.length() < 6 ? "0" + hex : hex; + } + return Integer.toHexString(colour); + } } 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 773e7ebe..0a5acedf 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinLayerArmorBase.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinLayerArmorBase.java @@ -76,10 +76,20 @@ public abstract class MixinLayerArmorBase<T extends ModelBase> { ) public int renderItem_getColor(ItemArmor item, ItemStack stack) { ItemCustomizeManager.ItemData data = ItemCustomizeManager.getDataForItem(stack); - if (data != null && data.customLeatherColour != null) { + if (data != null && data.customLeatherColour != null && ItemCustomizeManager.shouldRenderLeatherColour(stack)) { return ChromaColour.specialToChromaRGB(data.customLeatherColour); } return item.getColor(stack); } + + @Redirect(method = "renderLayer", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/client/renderer/entity/layers/LayerArmorBase;getCurrentArmor(Lnet/minecraft/entity/EntityLivingBase;I)Lnet/minecraft/item/ItemStack;" + ) + ) + public ItemStack renderItem_getCurrentArmor(LayerArmorBase<?> instance, EntityLivingBase entitylivingbaseIn, int armorSlot) { + return ItemCustomizeManager.useCustomArmour(instance, entitylivingbaseIn, armorSlot); + } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinLayerCustomHead.java b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinLayerCustomHead.java index 90101696..c3d92ab7 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinLayerCustomHead.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinLayerCustomHead.java @@ -53,6 +53,11 @@ public class MixinLayerCustomHead { } } + @Redirect(method = "doRenderLayer", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/EntityLivingBase;getCurrentArmor(I)Lnet/minecraft/item/ItemStack;")) + public ItemStack doRenderLayer_getCurrentArmor(EntityLivingBase instance, int i) { + return ItemCustomizeManager.setHeadArmour(instance, i); + } + @Redirect(method = "doRenderLayer", at = @At( value = "INVOKE", 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 7c2cfcbf..2173a3c8 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinRenderItem.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinRenderItem.java @@ -131,7 +131,7 @@ public abstract class MixinRenderItem { public int renderItem_renderByItem(Item item, ItemStack stack, int renderPass) { if (renderPass == 0) { ItemCustomizeManager.ItemData data = ItemCustomizeManager.getDataForItem(stack); - if (data != null && data.customLeatherColour != null) { + if (data != null && data.customLeatherColour != null && ItemCustomizeManager.shouldRenderLeatherColour(stack)) { return ChromaColour.specialToChromaRGB(data.customLeatherColour); } } @@ -301,4 +301,12 @@ public abstract class MixinRenderItem { GlStateManager.enableDepth(); } } + + @Redirect(method = "renderItemOverlayIntoGUI", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/Item;showDurabilityBar(Lnet/minecraft/item/ItemStack;)Z")) + public boolean renderItemOverlayIntoGUI_showDurabilityBar( + Item instance, ItemStack stack + ) { + if (ItemCustomizeManager.hasCustomItem(stack)) return false; + return stack.getItem().showDurabilityBar(stack); + } } diff --git a/src/main/resources/mixins.notenoughupdates.json b/src/main/resources/mixins.notenoughupdates.json index 8a8b10bc..eb04957b 100644 --- a/src/main/resources/mixins.notenoughupdates.json +++ b/src/main/resources/mixins.notenoughupdates.json @@ -22,6 +22,7 @@ "MixinGuiChest", "MixinGuiContainer", "MixinGuiIngame", + "MixinGuiIngameForge", "MixinGuiInventory", "MixinGuiScreen", "MixinGuiUtils", |