mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-12 22:27:32 +00:00
Show recipe banner with overlay
This commit is contained in:
1 parent
1585aa8e55
commit
62e11d8caa
5 files changed
+52
-2
No files matched your search
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user