aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNopoTheGamer <40329022+NopoTheGamer@users.noreply.github.com>2024-08-14 07:01:45 +1000
committerGitHub <noreply@github.com>2024-08-13 23:01:45 +0200
commitf829161159ed9d6aead2c47336bd34bb26863df6 (patch)
treec38bb57f8ceb7fb41d97dcea8e8a2fd12c545ba0
parentc8e10f2daebc745509757ee0e25ca3354417cd0f (diff)
downloadnotenoughupdates-f829161159ed9d6aead2c47336bd34bb26863df6.tar.gz
notenoughupdates-f829161159ed9d6aead2c47336bd34bb26863df6.tar.bz2
notenoughupdates-f829161159ed9d6aead2c47336bd34bb26863df6.zip
meta: fix recipe stack overriding wrong thing (#1301)
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java37
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/BetterContainers.java19
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiContainer.java112
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/overlays/RecipeSearchOverlay.java20
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewerButton.java104
5 files changed, 124 insertions, 168 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java b/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java
index a0c8473a..45111f66 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/listener/RenderListener.java
@@ -46,10 +46,8 @@ import io.github.moulberry.notenoughupdates.miscgui.hex.GuiCustomHex;
import io.github.moulberry.notenoughupdates.mixins.AccessorGuiContainer;
import io.github.moulberry.notenoughupdates.options.NEUConfig;
import io.github.moulberry.notenoughupdates.overlays.OverlayManager;
-import io.github.moulberry.notenoughupdates.overlays.RecipeSearchOverlay;
import io.github.moulberry.notenoughupdates.overlays.TextOverlay;
import io.github.moulberry.notenoughupdates.profileviewer.GuiProfileViewer;
-import io.github.moulberry.notenoughupdates.profileviewer.ProfileViewerUtils;
import io.github.moulberry.notenoughupdates.util.ItemUtils;
import io.github.moulberry.notenoughupdates.util.NotificationHandler;
import io.github.moulberry.notenoughupdates.util.Rectangle;
@@ -930,41 +928,6 @@ public class RenderListener {
GuiChest eventGui = (GuiChest) guiScreen;
ContainerChest cc = (ContainerChest) eventGui.inventorySlots;
containerName = cc.getLowerChestInventory().getDisplayName().getUnformattedText();
- if (containerName.contains(" Profile") && BetterContainers.profileViewerStackIndex != -1 &&
- ((AccessorGuiContainer) eventGui).doIsMouseOverSlot(
- cc.inventorySlots.get(BetterContainers.profileViewerStackIndex),
- mouseX,
- mouseY
- ) &&
- Mouse.getEventButton() >= 0) {
- event.setCanceled(true);
- if (Mouse.getEventButtonState() && eventGui.inventorySlots.inventorySlots.get(22).getStack() != null &&
- eventGui.inventorySlots.inventorySlots.get(22).getStack().getTagCompound() != null) {
- NBTTagCompound tag = eventGui.inventorySlots.inventorySlots.get(22).getStack().getTagCompound();
- if (tag.hasKey("SkullOwner") && tag.getCompoundTag("SkullOwner").hasKey("Name")) {
- String username = tag.getCompoundTag("SkullOwner").getString("Name");
- Utils.playPressSound();
- NotEnoughUpdates.profileViewer.loadPlayerByName(username, profile -> {
- if (profile == null) {
- Utils.addChatMessage("${RED}Invalid player name. Maybe the API is down?");
- } else {
- profile.resetCache();
- ProfileViewerUtils.saveSearch(username);
- NotEnoughUpdates.INSTANCE.openGui = new GuiProfileViewer(profile);
- }
- });
- }
- }
- } else if (containerName.equals("Craft Item") && BetterContainers.recipeSearchStackIndex != -1 &&
- ((AccessorGuiContainer) eventGui).doIsMouseOverSlot(
- cc.inventorySlots.get(BetterContainers.recipeSearchStackIndex),
- mouseX,
- mouseY
- ) &&
- Mouse.getEventButton() >= 0) {
- event.setCanceled(true);
- NotEnoughUpdates.INSTANCE.openGui = new RecipeSearchOverlay();
- }
}
if (GuiCustomHex.getInstance().shouldOverride(containerName) &&
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/BetterContainers.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/BetterContainers.java
index 431a029a..4d3b7fb1 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/BetterContainers.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/BetterContainers.java
@@ -74,9 +74,6 @@ public class BetterContainers {
private static int lastInvHashcode = 0;
private static final int lastHashcodeCheck = 0;
- public static int profileViewerStackIndex = -1;
- public static int recipeSearchStackIndex = -1;
-
public static void clickSlot(int slot) {
clickedSlotMillis = System.currentTimeMillis();
clickedSlot = slot;
@@ -138,14 +135,6 @@ public class BetterContainers {
}
public static boolean isBlankStack(int index, ItemStack stack) {
- if (index != -1 && index == profileViewerStackIndex) {
- return false;
- }
-
- if (index != -1 && index == recipeSearchStackIndex) {
- return false;
- }
-
return stack != null && stack.getItem() == Item.getItemFromBlock(Blocks.stained_glass_pane) &&
stack.getItemDamage() == 15 &&
stack.getDisplayName() != null && stack.getDisplayName().trim().isEmpty();
@@ -156,14 +145,6 @@ public class BetterContainers {
}
public static boolean isButtonStack(int index, ItemStack stack) {
- if (index == profileViewerStackIndex) {
- return true;
- }
-
- if (index == recipeSearchStackIndex) {
- return true;
- }
-
return stack != null && stack.getItem() != Item.getItemFromBlock(Blocks.stained_glass_pane)
&& NotEnoughUpdates.INSTANCE.manager.getInternalNameForItem(stack) == null && !isToggleOn(stack) && !isToggleOff(
stack);
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 6d8992fc..ebbfc025 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiContainer.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/mixins/MixinGuiContainer.java
@@ -37,23 +37,15 @@ import io.github.moulberry.notenoughupdates.miscgui.GuiCustomEnchant;
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.util.Utils;
import lombok.var;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiScreen;
-import net.minecraft.client.gui.inventory.GuiChest;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.RenderHelper;
-import net.minecraft.init.Blocks;
-import net.minecraft.init.Items;
-import net.minecraft.inventory.ContainerChest;
import net.minecraft.inventory.Slot;
-import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
-import net.minecraft.nbt.NBTTagCompound;
-import net.minecraft.util.EnumChatFormatting;
import net.minecraftforge.common.MinecraftForge;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
@@ -69,18 +61,6 @@ import java.util.Set;
@Mixin(value = GuiContainer.class, priority = 500)
public abstract class MixinGuiContainer extends GuiScreen {
- private static boolean hasProfileViewerStack = false;
- private static boolean hasRecipeSearchStack = false;
- private static final ItemStack profileViewerStack = Utils.createItemStack(
- Item.getItemFromBlock(Blocks.command_block),
- EnumChatFormatting.GREEN + "Profile Viewer",
- EnumChatFormatting.YELLOW + "Click to open NEU profile viewer!"
- );
- private static final ItemStack recipeSearchStack = Utils.createItemStack(
- Items.golden_pickaxe,
- EnumChatFormatting.GREEN + "Recipe Search",
- EnumChatFormatting.YELLOW + "Click to open Recipe Search!"
- );
@Inject(method = "drawSlot", at = @At("RETURN"))
public void drawSlotRet(Slot slotIn, CallbackInfo ci) {
@@ -92,87 +72,6 @@ public abstract class MixinGuiContainer extends GuiScreen {
public void drawSlot(Slot slot, CallbackInfo ci) {
if (slot == null) return;
- GuiContainer $this = (GuiContainer) (Object) this;
-
- if (!hasProfileViewerStack && $this instanceof GuiChest && slot.getSlotIndex() > 9 &&
- (slot.getSlotIndex() % 9 == 6 || slot.getSlotIndex() % 9 == 7) &&
- BetterContainers.isBlankStack(-1, slot.getStack())) {
- BetterContainers.profileViewerStackIndex = -1;
- hasProfileViewerStack = true;
-
- GuiChest eventGui = (GuiChest) $this;
- ContainerChest cc = (ContainerChest) eventGui.inventorySlots;
- String containerName = cc.getLowerChestInventory().getDisplayName().getUnformattedText();
- if (containerName.contains(" Profile") && cc.inventorySlots.size() >= 54) {
- if (cc.inventorySlots.get(22).getStack() != null &&
- cc.inventorySlots.get(22).getStack().getTagCompound() != null) {
- NBTTagCompound tag = eventGui.inventorySlots.inventorySlots.get(22).getStack().getTagCompound();
- if (tag.hasKey("SkullOwner") && tag.getCompoundTag("SkullOwner").hasKey("Name")) {
- String tagName = tag.getCompoundTag("SkullOwner").getString("Name");
- String displayName = Utils.cleanColour(cc.inventorySlots.get(22).getStack().getDisplayName());
- if (displayName.length() - tagName.length() >= 0 && tagName.equals(displayName.substring(
- displayName.length() - tagName.length()))) {
- ci.cancel();
-
- this.zLevel = 100.0F;
- this.itemRender.zLevel = 100.0F;
-
- GlStateManager.enableDepth();
- this.itemRender.renderItemAndEffectIntoGUI(
- profileViewerStack,
- slot.xDisplayPosition,
- slot.yDisplayPosition
- );
- this.itemRender.renderItemOverlayIntoGUI(this.fontRendererObj, profileViewerStack,
- slot.xDisplayPosition, slot.yDisplayPosition, ""
- );
-
- this.itemRender.zLevel = 0.0F;
- this.zLevel = 0.0F;
-
- BetterContainers.profileViewerStackIndex = slot.getSlotIndex();
- }
- }
- }
- }
- } else if (!hasRecipeSearchStack && $this instanceof GuiChest && slot.getSlotIndex() == 32 &&
- BetterContainers.isBlankStack(-1, slot.getStack())) {
- BetterContainers.recipeSearchStackIndex = -1;
- hasRecipeSearchStack = true;
-
- GuiChest eventGui = (GuiChest) $this;
- ContainerChest cc = (ContainerChest) eventGui.inventorySlots;
- String containerName = cc.getLowerChestInventory().getDisplayName().getUnformattedText();
- if (containerName.equals("Craft Item") && cc.inventorySlots.size() >= 54) {
- ci.cancel();
-
- this.zLevel = 100.0F;
- this.itemRender.zLevel = 100.0F;
-
- GlStateManager.enableDepth();
- this.itemRender.renderItemAndEffectIntoGUI(
- recipeSearchStack,
- slot.xDisplayPosition,
- slot.yDisplayPosition
- );
- this.itemRender.renderItemOverlayIntoGUI(this.fontRendererObj, recipeSearchStack,
- slot.xDisplayPosition, slot.yDisplayPosition, ""
- );
-
- this.itemRender.zLevel = 0.0F;
- this.zLevel = 0.0F;
- BetterContainers.recipeSearchStackIndex = slot.getSlotIndex();
- } else {
- BetterContainers.recipeSearchStackIndex = -1;
- }
- } else if (slot.getSlotIndex() == 0) {
- hasProfileViewerStack = false;
- hasRecipeSearchStack = false;
- } else if (!($this instanceof GuiChest)) {
- BetterContainers.recipeSearchStackIndex = -1;
- BetterContainers.profileViewerStackIndex = -1;
- }
-
if (slot.getStack() == null && NotEnoughUpdates.INSTANCE.overlay.searchMode && RenderListener.drawingGuiScreen &&
NotEnoughUpdates.INSTANCE.isOnSkyblock()) {
GlStateManager.pushMatrix();
@@ -211,17 +110,6 @@ public abstract class MixinGuiContainer extends GuiScreen {
}
}
- @ModifyArg(method = "drawScreen", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/inventory/GuiContainer;renderToolTip(Lnet/minecraft/item/ItemStack;II)V"), index = 0)
- public ItemStack adjustItemStack(ItemStack itemStack) {
- if (theSlot.slotNumber == BetterContainers.profileViewerStackIndex) {
- return profileViewerStack;
- } else if (theSlot.slotNumber == BetterContainers.recipeSearchStackIndex) {
- return recipeSearchStack;
- } else {
- return itemStack;
- }
- }
-
@Inject(method = "drawScreen",
at = @At(
value = "INVOKE",
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/overlays/RecipeSearchOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/overlays/RecipeSearchOverlay.java
index 00c67fb8..7f145940 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/overlays/RecipeSearchOverlay.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/overlays/RecipeSearchOverlay.java
@@ -21,11 +21,14 @@ package io.github.moulberry.notenoughupdates.overlays;
import io.github.moulberry.notenoughupdates.NotEnoughUpdates;
import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe;
+import io.github.moulberry.notenoughupdates.events.ReplaceItemEvent;
import io.github.moulberry.notenoughupdates.events.SlotClickEvent;
+import io.github.moulberry.notenoughupdates.util.Utils;
import net.minecraft.client.Minecraft;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntitySign;
+import net.minecraft.util.EnumChatFormatting;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import java.util.ArrayList;
@@ -50,6 +53,22 @@ public class RecipeSearchOverlay extends SearchOverlayScreen {
event.setCanceled(true);
NotEnoughUpdates.INSTANCE.openGui = new RecipeSearchOverlay();
}
+ if (event.slot.slotNumber == 32 && Utils.getOpenChestName().equals("Craft Item")) {
+ event.setCanceled(true);
+ NotEnoughUpdates.INSTANCE.openGui = new RecipeSearchOverlay();
+ }
+ }
+
+ private static final ItemStack recipeSearchStack = Utils.createItemStack(
+ Items.golden_pickaxe,
+ EnumChatFormatting.GREEN + "Recipe Search",
+ EnumChatFormatting.YELLOW + "Click to open Recipe Search!"
+ );
+
+ @SubscribeEvent
+ public void slotReplace(ReplaceItemEvent event) {
+ if (event.getSlotNumber() != 32 || !Utils.getOpenChestName().equals("Craft Item")) return;
+ event.replaceWith(recipeSearchStack);
}
@@ -87,4 +106,5 @@ public class RecipeSearchOverlay extends SearchOverlayScreen {
public GuiType currentGuiType() {
return GuiType.RECIPE;
}
+
}
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewerButton.java b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewerButton.java
new file mode 100644
index 00000000..f4a6504c
--- /dev/null
+++ b/src/main/java/io/github/moulberry/notenoughupdates/profileviewer/ProfileViewerButton.java
@@ -0,0 +1,104 @@
+/*
+ * Copyright (C) 2024 NotEnoughUpdates contributors
+ *
+ * This file is part of NotEnoughUpdates.
+ *
+ * NotEnoughUpdates is free software: you can redistribute it
+ * and/or modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation, either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * NotEnoughUpdates is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package io.github.moulberry.notenoughupdates.profileviewer;
+
+import io.github.moulberry.notenoughupdates.NotEnoughUpdates;
+import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe;
+import io.github.moulberry.notenoughupdates.events.ReplaceItemEvent;
+import io.github.moulberry.notenoughupdates.events.SlotClickEvent;
+import io.github.moulberry.notenoughupdates.miscfeatures.BetterContainers;
+import io.github.moulberry.notenoughupdates.util.Utils;
+import net.minecraft.init.Blocks;
+import net.minecraft.item.Item;
+import net.minecraft.item.ItemStack;
+import net.minecraft.nbt.NBTTagCompound;
+import net.minecraft.util.EnumChatFormatting;
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
+
+@NEUAutoSubscribe
+public class ProfileViewerButton {
+
+ private static final ItemStack profileViewerStack = Utils.createItemStack(
+ Item.getItemFromBlock(Blocks.command_block),
+ EnumChatFormatting.GREEN + "Profile Viewer",
+ EnumChatFormatting.YELLOW + "Click to open NEU profile viewer!"
+ );
+
+
+ String username = "";
+ int replaceSlot = -1;
+
+ @SubscribeEvent
+ public void onSlotClick(SlotClickEvent event) {
+ if (!Utils.getOpenChestName().contains(" Profile") || event.guiContainer.inventorySlots.inventorySlots.size() < 54) {
+ username = "";
+ replaceSlot = -1;
+ return;
+ }
+ if (!username.isEmpty() && event.slot.slotNumber == replaceSlot &&
+ isReplacedStack(event.slot.getStack())) {
+ Utils.playPressSound();
+ event.setCanceled(true);
+ NotEnoughUpdates.profileViewer.loadPlayerByName(username, profile -> {
+ if (profile == null) {
+ Utils.addChatMessage(EnumChatFormatting.RED + "Invalid player name. Maybe the API is down?");
+ } else {
+ profile.resetCache();
+ ProfileViewerUtils.saveSearch(username);
+ NotEnoughUpdates.INSTANCE.openGui = new GuiProfileViewer(profile);
+ }
+ });
+ }
+ //username = "";
+ }
+
+ @SubscribeEvent
+ public void itemReplace(ReplaceItemEvent event) {
+ if (!Utils.getOpenChestName().contains(" Profile")) {
+ username = "";
+ replaceSlot = -1;
+ return;
+ }
+ if (replaceSlot == event.getSlotNumber()) {
+ event.replaceWith(profileViewerStack);
+ } else if (replaceSlot == -1 && event.getSlotNumber() > 9 &&
+ (event.getSlotNumber() % 9 == 6 || event.getSlotNumber() % 9 == 7) &&
+ BetterContainers.isBlankStack(-1, event.getOriginal())) {
+ event.replaceWith(profileViewerStack);
+ replaceSlot = event.getSlotNumber();
+ } else if (event.getSlotNumber() == 22) {
+ ItemStack stack = event.getOriginal();
+ if (stack != null && stack.getTagCompound() != null) {
+ NBTTagCompound tag = stack.getTagCompound();
+ String tagName = tag.getCompoundTag("SkullOwner").getString("Name");
+ String displayName = Utils.cleanColour(stack.getDisplayName());
+ if (displayName.length() - tagName.length() >= 0 && tagName.equals(displayName.substring(
+ displayName.length() - tagName.length()))) {
+ username = tagName;
+ }
+ }
+ }
+ //username = "";
+ }
+
+ private static boolean isReplacedStack(ItemStack stack) {
+ return stack != null && stack.getItem() == Item.getItemFromBlock(Blocks.command_block);
+ }
+}