From 62e11d8caa5e06ea6e8f71433517c543226f5edc Mon Sep 17 00:00:00 2001 From: Kam Date: Wed, 9 Jul 2025 21:35:27 -0400 Subject: [PATCH] Show recipe banner with overlay --- src/main/java/noppes/npcs/EventHooks.java | 18 ++++++++++++++++-- .../npcs/client/gui/player/GuiNpcAnvil.java | 11 +++++++++++ .../gui/player/GuiNpcCarpentryBench.java | 11 +++++++++++ .../npcs/containers/ContainerAnvilRepair.java | 7 +++++++ .../containers/ContainerCarpentryBench.java | 7 +++++++ 5 files changed, 52 insertions(+), 2 deletions(-) diff --git a/src/main/java/noppes/npcs/EventHooks.java b/src/main/java/noppes/npcs/EventHooks.java index b12a60e48..8191ddc7f 100644 --- a/src/main/java/noppes/npcs/EventHooks.java +++ b/src/main/java/noppes/npcs/EventHooks.java @@ -35,12 +35,19 @@ import noppes.npcs.scripted.event.*; import noppes.npcs.scripted.event.player.*; import noppes.npcs.scripted.event.player.PlayerEvent.*; import noppes.npcs.scripted.item.ScriptItemStack; -import kamkeel.npcs.network.packets.data.AchievementPacket; +import kamkeel.npcs.network.PacketHandler; +import kamkeel.npcs.network.packets.data.script.ScriptOverlayClosePacket; +import noppes.npcs.NoppesUtilServer; +import noppes.npcs.scripted.overlay.ScriptOverlay; +import noppes.npcs.scripted.overlay.ScriptOverlayLabel; +import noppes.npcs.NoppesUtilServer; import org.apache.commons.lang3.StringUtils; import java.util.ArrayList; public class EventHooks { + // Overlay id used for recipe pre-event banner messages + public static final int RECIPE_OVERLAY_ID = 901; public EventHooks() { } @@ -181,7 +188,14 @@ public class EventHooks { if (!player.worldObj.isRemote) { String msg = event.getMessage(); if (msg == null) msg = ""; - AchievementPacket.sendAchievement((EntityPlayerMP) player, false, "", msg); + if (!msg.isEmpty()) { + ScriptOverlay overlay = new ScriptOverlay(RECIPE_OVERLAY_ID); + ScriptOverlayLabel lbl = (ScriptOverlayLabel) overlay.addLabel(0, msg, 0, 5, 200, 20); + lbl.setAlignment(1); + CustomGuiController.openOverlay(NoppesUtilServer.getIPlayer(player), overlay); + } else { + PacketHandler.Instance.sendToPlayer(new ScriptOverlayClosePacket(RECIPE_OVERLAY_ID), (EntityPlayerMP) player); + } } return event; } diff --git a/src/main/java/noppes/npcs/client/gui/player/GuiNpcAnvil.java b/src/main/java/noppes/npcs/client/gui/player/GuiNpcAnvil.java index 7ef23a9a1..e98b8d280 100644 --- a/src/main/java/noppes/npcs/client/gui/player/GuiNpcAnvil.java +++ b/src/main/java/noppes/npcs/client/gui/player/GuiNpcAnvil.java @@ -46,6 +46,9 @@ public class GuiNpcAnvil extends GuiContainerNPCInterface { int i1 = (height - ySize) / 2; drawTexturedModalRect(l, i1, 0, 0, xSize, ySize); super.drawGuiContainerBackgroundLayer(partialTicks, mouseX, mouseY); + if (!container.canPickupResult()) { + drawRedSlotOutline(guiLeft + 133, guiTop + 47); + } // Draw title and player's inventory label. fontRendererObj.drawString(StatCollector.translateToLocal("tile.anvil.name"), guiLeft + 4, guiTop + 4, CustomNpcResourceListener.DefaultTextColor); @@ -74,6 +77,14 @@ public class GuiNpcAnvil extends GuiContainerNPCInterface { fontRendererObj.drawString(status, guiLeft + 5, guiTop + 75, textColor); } + private void drawRedSlotOutline(int x, int y) { + int c = 0xFFFF0000; + drawRect(x - 1, y - 1, x + 17, y, c); + drawRect(x - 1, y + 16, x + 17, y + 17, c); + drawRect(x - 1, y, x, y + 16, c); + drawRect(x + 16, y, x + 17, y + 16, c); + } + @Override public void save() { // Nothing to save. diff --git a/src/main/java/noppes/npcs/client/gui/player/GuiNpcCarpentryBench.java b/src/main/java/noppes/npcs/client/gui/player/GuiNpcCarpentryBench.java index 6c59de3ca..9087b6b6f 100644 --- a/src/main/java/noppes/npcs/client/gui/player/GuiNpcCarpentryBench.java +++ b/src/main/java/noppes/npcs/client/gui/player/GuiNpcCarpentryBench.java @@ -46,10 +46,21 @@ public class GuiNpcCarpentryBench extends GuiContainerNPCInterface { title = StatCollector.translateToLocal("tile.anvil.name"); drawTexturedModalRect(l, i1, 0, 0, xSize, ySize); super.drawGuiContainerBackgroundLayer(f, i, j); + if (!container.canPickupResult()) { + drawRedSlotOutline(guiLeft + 133, guiTop + 41); + } fontRendererObj.drawString(title, guiLeft + 4, guiTop + 4, CustomNpcResourceListener.DefaultTextColor); fontRendererObj.drawString(StatCollector.translateToLocal("container.inventory"), guiLeft + 4, guiTop + 87, CustomNpcResourceListener.DefaultTextColor); } + private void drawRedSlotOutline(int x, int y) { + int c = 0xFFFF0000; + drawRect(x - 1, y - 1, x + 17, y, c); + drawRect(x - 1, y + 16, x + 17, y + 17, c); + drawRect(x - 1, y, x, y + 16, c); + drawRect(x + 16, y, x + 17, y + 16, c); + } + @Override public void save() { return; diff --git a/src/main/java/noppes/npcs/containers/ContainerAnvilRepair.java b/src/main/java/noppes/npcs/containers/ContainerAnvilRepair.java index 042f8d573..8685d8cda 100644 --- a/src/main/java/noppes/npcs/containers/ContainerAnvilRepair.java +++ b/src/main/java/noppes/npcs/containers/ContainerAnvilRepair.java @@ -11,6 +11,8 @@ import noppes.npcs.api.handler.data.IAnvilRecipe; import noppes.npcs.controllers.RecipeController; import noppes.npcs.controllers.data.RecipeAnvil; import noppes.npcs.scripted.event.RecipeScriptEvent; +import kamkeel.npcs.network.PacketHandler; +import kamkeel.npcs.network.packets.data.script.ScriptOverlayClosePacket; public class ContainerAnvilRepair extends Container { // A 2-slot crafting matrix: slot 0 = damaged item, slot 1 = repair material. @@ -212,6 +214,7 @@ public class ContainerAnvilRepair extends Container { public void onContainerClosed(EntityPlayer player) { super.onContainerClosed(player); if (!this.worldObj.isRemote) { + PacketHandler.Instance.sendToPlayer(new ScriptOverlayClosePacket(EventHooks.RECIPE_OVERLAY_ID), (EntityPlayerMP) player); for (int i = 0; i < this.anvilMatrix.getSizeInventory(); i++) { ItemStack stack = this.anvilMatrix.getStackInSlotOnClosing(i); if (stack != null) { @@ -228,6 +231,10 @@ public class ContainerAnvilRepair extends Container { (double) this.posZ + 0.5D) <= 64.0D; } + public boolean canPickupResult() { + return this.resultCanPickup; + } + @Override public ItemStack transferStackInSlot(EntityPlayer player, int index) { ItemStack copy = null; diff --git a/src/main/java/noppes/npcs/containers/ContainerCarpentryBench.java b/src/main/java/noppes/npcs/containers/ContainerCarpentryBench.java index 43511ae77..fd6a3ff50 100644 --- a/src/main/java/noppes/npcs/containers/ContainerCarpentryBench.java +++ b/src/main/java/noppes/npcs/containers/ContainerCarpentryBench.java @@ -9,6 +9,8 @@ import net.minecraft.network.play.server.S2FPacketSetSlot; import net.minecraft.world.World; import noppes.npcs.CustomItems; import noppes.npcs.EventHooks; +import kamkeel.npcs.network.PacketHandler; +import kamkeel.npcs.network.packets.data.script.ScriptOverlayClosePacket; import noppes.npcs.scripted.event.RecipeScriptEvent; import noppes.npcs.controllers.RecipeController; import noppes.npcs.controllers.data.RecipeCarpentry; @@ -102,6 +104,7 @@ public class ContainerCarpentryBench extends Container { super.onContainerClosed(par1EntityPlayer); if (!this.worldObj.isRemote) { + PacketHandler.Instance.sendToPlayer(new ScriptOverlayClosePacket(EventHooks.RECIPE_OVERLAY_ID), (EntityPlayerMP) par1EntityPlayer); for (int var2 = 0; var2 < 16; ++var2) { ItemStack var3 = this.craftMatrix.getStackInSlotOnClosing(var2); @@ -117,6 +120,10 @@ public class ContainerCarpentryBench extends Container { return this.worldObj.getBlock(this.posX, this.posY, this.posZ) != CustomItems.carpentyBench ? false : par1EntityPlayer.getDistanceSq((double) this.posX + 0.5D, (double) this.posY + 0.5D, (double) this.posZ + 0.5D) <= 64.0D; } + public boolean canPickupResult() { + return this.resultCanPickup; + } + /** * Called to transfer a stack from one inventory to the other eg. when shift clicking. */