diff --git a/src/main/java/noppes/npcs/CustomNpcs.java b/src/main/java/noppes/npcs/CustomNpcs.java index 55fc31c23..cbb271971 100644 --- a/src/main/java/noppes/npcs/CustomNpcs.java +++ b/src/main/java/noppes/npcs/CustomNpcs.java @@ -69,7 +69,7 @@ public class CustomNpcs { private static int NewEntityStartId = 0; - @ConfigProp(info = "Navigation search range for NPCs. Not recommended to increase if you have a slow pc or on a server") + @ConfigProp(info = "Navigation search range for NPCs. Not recommended to increase if you have a slow pc or on a server. Minimum of 16, maximum of 96.") public static int NpcNavRange = 32; @ConfigProp(info = "Set to true if you want the dialog command option to be able to use op commands like tp etc") @@ -167,6 +167,10 @@ public class CustomNpcs { if (NpcNavRange < 16) { NpcNavRange = 16; } + if (NpcNavRange > 96) { + NpcNavRange = 96; + } + EnchantInterface.load(); CustomItems.load(); diff --git a/src/main/java/noppes/npcs/EventHooks.java b/src/main/java/noppes/npcs/EventHooks.java index 5b39a96f9..dcb421163 100644 --- a/src/main/java/noppes/npcs/EventHooks.java +++ b/src/main/java/noppes/npcs/EventHooks.java @@ -328,6 +328,11 @@ public class EventHooks { CustomGuiController.onSlotChange(event); } + public static void onCustomGuiUnfocused(ScriptPlayer player, ICustomGui gui, int textfieldId) { + CustomGuiEvent.UnfocusedEvent event = new CustomGuiEvent.UnfocusedEvent(player, gui, textfieldId); + CustomGuiController.onCustomGuiUnfocused(event); + } + public static void onCustomGuiScrollClick(ScriptPlayer player, ICustomGui gui, int scrollId, int scrollIndex, String[] selection, boolean doubleClick) { CustomGuiEvent.ScrollEvent event = new CustomGuiEvent.ScrollEvent(player, gui, scrollId, scrollIndex, selection, doubleClick); CustomGuiController.onScrollClick(event); diff --git a/src/main/java/noppes/npcs/NoppesUtilServer.java b/src/main/java/noppes/npcs/NoppesUtilServer.java index 4d0c7e8d9..6feca3dd1 100644 --- a/src/main/java/noppes/npcs/NoppesUtilServer.java +++ b/src/main/java/noppes/npcs/NoppesUtilServer.java @@ -319,7 +319,7 @@ public class NoppesUtilServer { float alpha1, float alpha2, float alphaRate, int alphaRateStart, int entityID ){ - Server.sendAssociatedData(entity, EnumPacketClient.SCRIPTED_PARTICLE, + Server.sendToAll(EnumPacketClient.SCRIPTED_PARTICLE, directory, HEXcolor, amount, maxAge, x, y, z, motionX, motionY, motionZ, gravity, diff --git a/src/main/java/noppes/npcs/PacketHandlerServer.java b/src/main/java/noppes/npcs/PacketHandlerServer.java index bae601c11..61816ea25 100644 --- a/src/main/java/noppes/npcs/PacketHandlerServer.java +++ b/src/main/java/noppes/npcs/PacketHandlerServer.java @@ -75,24 +75,25 @@ public class PacketHandlerServer{ if(type == EnumPacketServer.IsGuiOpen) { isGuiOpenPacket(buffer, player); return; - } else if (type == EnumPacketServer.CustomGuiButton) { - if (player.openContainer instanceof ContainerCustomGui) { - ((ContainerCustomGui)player.openContainer).customGui.fromNBT(Server.readNBT(buffer)); - EventHooks.onCustomGuiButton((ScriptPlayer)NpcAPI.Instance().getIEntity(player), ((ContainerCustomGui)player.openContainer).customGui, buffer.readInt()); - return; - } - } else if (type == EnumPacketServer.CustomGuiSlotChange) { - if (player.openContainer instanceof ContainerCustomGui) { - ((ContainerCustomGui)player.openContainer).customGui.fromNBT(Server.readNBT(buffer)); - EventHooks.onCustomGuiSlot((ScriptPlayer) NpcAPI.Instance().getIEntity(player), ((ContainerCustomGui)player.openContainer).customGui, buffer.readInt()); - return; - } + } else if (type == EnumPacketServer.CustomGuiButton && player.openContainer instanceof ContainerCustomGui) { + ((ContainerCustomGui)player.openContainer).customGui.fromNBT(Server.readNBT(buffer)); + EventHooks.onCustomGuiButton((ScriptPlayer)NpcAPI.Instance().getIEntity(player), ((ContainerCustomGui)player.openContainer).customGui, buffer.readInt()); + return; + } else if (type == EnumPacketServer.CustomGuiSlotChange && player.openContainer instanceof ContainerCustomGui) { + ((ContainerCustomGui)player.openContainer).customGui.fromNBT(Server.readNBT(buffer)); + EventHooks.onCustomGuiSlot((ScriptPlayer) NpcAPI.Instance().getIEntity(player), ((ContainerCustomGui)player.openContainer).customGui, buffer.readInt()); + return; + } else if(type == EnumPacketServer.CustomGuiUnfocused && player.openContainer instanceof ContainerCustomGui) { + ((ContainerCustomGui)player.openContainer).customGui.fromNBT(Server.readNBT(buffer)); + EventHooks.onCustomGuiUnfocused((ScriptPlayer) NpcAPI.Instance().getIEntity(player), ((ContainerCustomGui) player.openContainer).customGui, buffer.readInt()); + return; } else if (type == EnumPacketServer.CustomGuiScrollClick && player.openContainer instanceof ContainerCustomGui) { ((ContainerCustomGui) player.openContainer).customGui.fromNBT(Server.readNBT(buffer)); EventHooks.onCustomGuiScrollClick((ScriptPlayer) NpcAPI.Instance().getIEntity(player), ((ContainerCustomGui) player.openContainer).customGui, buffer.readInt(), buffer.readInt(), CustomGuiController.readScrollSelection(buffer), buffer.readBoolean()); return; } else if (type == EnumPacketServer.CustomGuiClose) { EventHooks.onCustomGuiClose((ScriptPlayer)NpcAPI.Instance().getIEntity(player), (new ScriptGui()).fromNBT(Server.readNBT(buffer))); + return; } if(type.needsNpc && npc == null){ diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiNpcDialogExtra.java b/src/main/java/noppes/npcs/client/gui/SubGuiNpcDialogExtra.java index df50d234c..27c22153b 100644 --- a/src/main/java/noppes/npcs/client/gui/SubGuiNpcDialogExtra.java +++ b/src/main/java/noppes/npcs/client/gui/SubGuiNpcDialogExtra.java @@ -55,6 +55,9 @@ public class SubGuiNpcDialogExtra extends SubGuiInterface implements ISubGuiList addButton(new GuiNpcButtonYesNo(15, guiLeft + 120, y += 22, dialog.disableEsc)); addLabel(new GuiNpcLabel(15, "dialog.disableEsc", guiLeft + 4, y + 5)); + + addButton(new GuiNpcButtonYesNo(16, guiLeft + 120, y += 22, dialog.darkenScreen)); + addLabel(new GuiNpcLabel(16, "Darken Screen", guiLeft + 4, y + 5)); this.addButton(new GuiNpcButton(66, guiLeft + 82, guiTop + 192,98, 20, "gui.done")); @@ -76,6 +79,9 @@ public class SubGuiNpcDialogExtra extends SubGuiInterface implements ISubGuiList if(button.id == 15){ dialog.disableEsc = button.getValue() == 1; } + if(button.id == 15){ + dialog.darkenScreen = button.getValue() == 1; + } if(button.id == 13){ setSubGui(new SubGuiMailmanSendSetup(dialog.mail, getParent())); } diff --git a/src/main/java/noppes/npcs/client/gui/custom/GuiCustom.java b/src/main/java/noppes/npcs/client/gui/custom/GuiCustom.java index 8f37fee33..7ad35397e 100644 --- a/src/main/java/noppes/npcs/client/gui/custom/GuiCustom.java +++ b/src/main/java/noppes/npcs/client/gui/custom/GuiCustom.java @@ -466,6 +466,10 @@ public class GuiCustom extends GuiScreen implements ICustomScrollListener, IGuiD } } + public void onTextFieldUnfocused(CustomGuiTextField textField){ + Client.sendData(EnumPacketServer.CustomGuiUnfocused, new Object[]{this.updateGui().toNBT(), textField.getID()}); + } + ScriptGui updateGui() { Iterator var1 = this.dataHolders.iterator(); @@ -537,11 +541,19 @@ public class GuiCustom extends GuiScreen implements ICustomScrollListener, IGuiD this.field_146995_H = false; if (mouseButton == 0 || mouseButton == 1 || flag) { - int i1 = guiLeft + ((ContainerCustomGui)this.inventorySlots).playerInvX; - int j1 = guiTop + ((ContainerCustomGui)this.inventorySlots).playerInvY; - boolean flag1 = mouseX < i1 || mouseY < j1 || mouseX >= i1 + this.xSize || mouseY >= j1 + this.ySize; + boolean flag1 = true; int k1 = -1; + for (int i = 0; i < this.inventorySlots.inventorySlots.size(); ++i) + { + Slot invSlot = (Slot)this.inventorySlots.inventorySlots.get(i); + + if (invSlot.equals(slot)) + { + flag1 = false; + } + } + if (slot != null) { k1 = slot.slotNumber; } diff --git a/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiTextField.java b/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiTextField.java index 879d15081..0e0c1eb73 100644 --- a/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiTextField.java +++ b/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiTextField.java @@ -8,10 +8,12 @@ package noppes.npcs.client.gui.custom.components; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiTextField; import net.minecraft.nbt.NBTTagCompound; +import noppes.npcs.client.Client; import noppes.npcs.client.gui.custom.GuiCustom; import noppes.npcs.client.gui.custom.interfaces.IClickListener; import noppes.npcs.client.gui.custom.interfaces.IDataHolder; import noppes.npcs.client.gui.custom.interfaces.IKeyListener; +import noppes.npcs.constants.EnumPacketServer; import noppes.npcs.scripted.gui.ScriptGuiTextField; import noppes.npcs.scripted.interfaces.ICustomGuiComponent; @@ -74,7 +76,14 @@ public class CustomGuiTextField extends GuiTextField implements IKeyListener, ID } public boolean mouseClicked(GuiCustom gui, int mouseX, int mouseY, int mouseButton) { + boolean flag = mouseX >= this.xPosition && mouseX < this.xPosition + this.width && mouseY >= this.yPosition && mouseY < this.yPosition + this.height; + + if (this.isFocused() && mouseButton == 0 && !flag){ + parent.onTextFieldUnfocused(this); + } + this.mouseClicked(mouseX, mouseY, mouseButton); + return true; } } diff --git a/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiTexturedRect.java b/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiTexturedRect.java index f8d749340..229e8e311 100644 --- a/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiTexturedRect.java +++ b/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiTexturedRect.java @@ -56,7 +56,7 @@ public class CustomGuiTexturedRect extends Gui implements IGuiComponent { boolean hovered = mouseX >= this.x && mouseY >= this.y && mouseX < this.x + this.width && mouseY < this.y + this.height; mc.getTextureManager().bindTexture(this.texture); - this.drawTexturedModalRect(this.textureX, this.textureY, 0, 0, (int)(this.width*this.scale), (int)(this.height*this.scale)); + this.drawTexturedModalRect(this.x + this.textureX, this.y + this.textureY, 0, 0, (int)(this.width*this.scale), (int)(this.height*this.scale)); if (hovered && this.hoverText != null && this.hoverText.length > 0) { this.parent.hoverText = this.hoverText; diff --git a/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java b/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java index b6864bb1d..20740533c 100644 --- a/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java +++ b/src/main/java/noppes/npcs/client/gui/player/GuiDialogInteract.java @@ -64,6 +64,7 @@ public class GuiDialogInteract extends GuiNPCInterface implements IGuiClose grabMouse(dialog.showWheel); guiTop = (height - ySize); calculateRowHeight(); + this.drawDefaultBackground = dialog.darkenScreen; } public void grabMouse(boolean grab){ diff --git a/src/main/java/noppes/npcs/client/gui/script/GuiScriptInterface.java b/src/main/java/noppes/npcs/client/gui/script/GuiScriptInterface.java index dc0e06c8e..dfe0f38d6 100644 --- a/src/main/java/noppes/npcs/client/gui/script/GuiScriptInterface.java +++ b/src/main/java/noppes/npcs/client/gui/script/GuiScriptInterface.java @@ -146,6 +146,7 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb hookList.add("customGuiButton"); hookList.add("customGuiSlot"); hookList.add("customGuiScroll"); + hookList.add("customGuiTextfield"); } else if(handler instanceof ForgeDataScript) { hooks.setSize(238, 198); diff --git a/src/main/java/noppes/npcs/constants/EnumPacketServer.java b/src/main/java/noppes/npcs/constants/EnumPacketServer.java index 595ccb08a..4591be8c4 100644 --- a/src/main/java/noppes/npcs/constants/EnumPacketServer.java +++ b/src/main/java/noppes/npcs/constants/EnumPacketServer.java @@ -78,7 +78,7 @@ public enum EnumPacketServer { NaturalSpawnGetAll, MailOpenSetup, DimensionsGet, DimensionTeleport, GetTileEntity, Gui, IsGuiOpen, - CustomGuiButton,CustomGuiSlotChange,CustomGuiScrollClick,CustomGuiClose; + CustomGuiButton,CustomGuiSlotChange,CustomGuiScrollClick,CustomGuiClose,CustomGuiUnfocused; public CustomNpcsPermissions.Permission permission = null; public boolean needsNpc = false; diff --git a/src/main/java/noppes/npcs/constants/EnumScriptType.java b/src/main/java/noppes/npcs/constants/EnumScriptType.java index 7ac39469d..a103ba293 100644 --- a/src/main/java/noppes/npcs/constants/EnumScriptType.java +++ b/src/main/java/noppes/npcs/constants/EnumScriptType.java @@ -57,6 +57,7 @@ public enum EnumScriptType { CUSTOM_GUI_BUTTON("customGuiButton"), CUSTOM_GUI_SLOT("customGuiSlot"), CUSTOM_GUI_SCROLL("customGuiScroll"), + CUSTOM_GUI_TEXTFIELD("customGuiTextfield"), PICKUP_XP("pickupXP"), MOUSE_CLICKED("mouseClicked"), START_USING_ITEM("startItem"), diff --git a/src/main/java/noppes/npcs/controllers/CustomGuiController.java b/src/main/java/noppes/npcs/controllers/CustomGuiController.java index 790a1b84a..edb1cf15c 100644 --- a/src/main/java/noppes/npcs/controllers/CustomGuiController.java +++ b/src/main/java/noppes/npcs/controllers/CustomGuiController.java @@ -83,6 +83,15 @@ public class CustomGuiController { WrapperNpcAPI.EVENT_BUS.post(event); } + public static void onCustomGuiUnfocused(CustomGuiEvent.UnfocusedEvent event) { + EntityPlayer player = (EntityPlayer) event.player.getMCEntity(); + if (checkGui(event) && getOpenGui(player).getScriptHandler() != null) { + getOpenGui(player).getScriptHandler().callScript(EnumScriptType.CUSTOM_GUI_TEXTFIELD, event); + } + + WrapperNpcAPI.EVENT_BUS.post(event); + } + public static void onScrollClick(CustomGuiEvent.ScrollEvent event) { EntityPlayer player = (EntityPlayer) event.player.getMCEntity(); if (checkGui(event) && getOpenGui(player).getScriptHandler() != null) { diff --git a/src/main/java/noppes/npcs/controllers/Dialog.java b/src/main/java/noppes/npcs/controllers/Dialog.java index 4b250ba13..730d36289 100644 --- a/src/main/java/noppes/npcs/controllers/Dialog.java +++ b/src/main/java/noppes/npcs/controllers/Dialog.java @@ -30,6 +30,7 @@ public class Dialog implements ICompatibilty, IDialog { public boolean hideNPC = false; public boolean showWheel = false; public boolean disableEsc = false; + public boolean darkenScreen = true; public boolean hasDialogs(EntityPlayer player) { for(DialogOption option: options.values()) diff --git a/src/main/java/noppes/npcs/scripted/event/CustomGuiEvent.java b/src/main/java/noppes/npcs/scripted/event/CustomGuiEvent.java index 5a96e3a5e..6c20658d0 100644 --- a/src/main/java/noppes/npcs/scripted/event/CustomGuiEvent.java +++ b/src/main/java/noppes/npcs/scripted/event/CustomGuiEvent.java @@ -23,6 +23,15 @@ public class CustomGuiEvent extends Event { } } + public static class UnfocusedEvent extends CustomGuiEvent { + public final int textfieldId; + + public UnfocusedEvent(IPlayer player, ICustomGui gui, int textfieldId) { + super(player, gui); + this.textfieldId = textfieldId; + } + } + public static class CloseEvent extends CustomGuiEvent { public CloseEvent(IPlayer player, ICustomGui gui) { super(player, gui); diff --git a/src/main/java/noppes/npcs/scripted/gui/ScriptGuiTexturedRect.java b/src/main/java/noppes/npcs/scripted/gui/ScriptGuiTexturedRect.java index 3ea0024db..a2b66012a 100644 --- a/src/main/java/noppes/npcs/scripted/gui/ScriptGuiTexturedRect.java +++ b/src/main/java/noppes/npcs/scripted/gui/ScriptGuiTexturedRect.java @@ -22,12 +22,12 @@ public class ScriptGuiTexturedRect extends ScriptGuiComponent implements ITextur this.scale = 1.0F; this.setID(id); this.setTexture(texture); - this.setPos(GuiCustom.guiLeft + x, GuiCustom.guiTop + y); + this.setPos(x, y); this.setSize(width, height); } public ScriptGuiTexturedRect(int id, String texture, int x, int y, int width, int height, int textureX, int textureY) { - this(id, texture, GuiCustom.guiLeft + x, GuiCustom.guiTop + y, width, height); + this(id, texture, x, y, width, height); this.setTextureOffset(textureX, textureY); }