From 6b9cfb9d253ac75ad82054e96b727212717e5b8a Mon Sep 17 00:00:00 2001 From: luisc Date: Wed, 12 Jan 2022 04:44:08 -0600 Subject: [PATCH] Implemented custom GUIs. --- src/main/java/noppes/npcs/CommonProxy.java | 25 +- src/main/java/noppes/npcs/EventHooks.java | 24 + .../java/noppes/npcs/PacketHandlerServer.java | 86 +- .../java/noppes/npcs/client/ClientProxy.java | 22 +- .../npcs/client/gui/custom/GuiCustom.java | 885 ++++++++++++++++++ .../custom/components/CustomGuiButton.java | 155 +++ .../gui/custom/components/CustomGuiLabel.java | 100 ++ .../components/CustomGuiScrollComponent.java | 111 +++ .../gui/custom/components/CustomGuiSlot.java | 30 + .../custom/components/CustomGuiTextField.java | 80 ++ .../components/CustomGuiTexturedRect.java | 88 ++ .../gui/custom/interfaces/IClickListener.java | 12 + .../gui/custom/interfaces/IDataHolder.java | 12 + .../gui/custom/interfaces/IGuiComponent.java | 17 + .../gui/custom/interfaces/IKeyListener.java | 10 + .../client/gui/script/GuiScriptInterface.java | 4 + .../npcs/client/gui/util/GuiCustomScroll.java | 2 +- .../noppes/npcs/constants/EnumGuiType.java | 2 +- .../npcs/constants/EnumPacketServer.java | 4 +- .../npcs/containers/ContainerCustomGui.java | 103 ++ .../npcs/controllers/CustomGuiController.java | 122 +++ .../npcs/scripted/entity/ScriptPlayer.java | 31 +- .../npcs/scripted/event/CustomGuiEvent.java | 57 ++ .../noppes/npcs/scripted/gui/ScriptGui.java | 298 ++++++ .../npcs/scripted/gui/ScriptGuiButton.java | 149 +++ .../npcs/scripted/gui/ScriptGuiComponent.java | 119 +++ .../npcs/scripted/gui/ScriptGuiItemSlot.java | 63 ++ .../npcs/scripted/gui/ScriptGuiLabel.java | 94 ++ .../npcs/scripted/gui/ScriptGuiScroll.java | 109 +++ .../npcs/scripted/gui/ScriptGuiTextField.java | 66 ++ .../scripted/gui/ScriptGuiTexturedRect.java | 107 +++ .../npcs/scripted/interfaces/IButton.java | 30 + .../npcs/scripted/interfaces/ICustomGui.java | 60 ++ .../interfaces/ICustomGuiComponent.java | 26 + .../npcs/scripted/interfaces/IItemSlot.java | 18 + .../npcs/scripted/interfaces/ILabel.java | 26 + .../npcs/scripted/interfaces/IScroll.java | 26 + .../npcs/scripted/interfaces/ITextField.java | 18 + .../scripted/interfaces/ITexturedRect.java | 28 + .../npcs/scripted/wrapper/WrapperNpcAPI.java | 9 +- 40 files changed, 3136 insertions(+), 92 deletions(-) create mode 100644 src/main/java/noppes/npcs/client/gui/custom/GuiCustom.java create mode 100644 src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiButton.java create mode 100644 src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiLabel.java create mode 100644 src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiScrollComponent.java create mode 100644 src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiSlot.java create mode 100644 src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiTextField.java create mode 100644 src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiTexturedRect.java create mode 100644 src/main/java/noppes/npcs/client/gui/custom/interfaces/IClickListener.java create mode 100644 src/main/java/noppes/npcs/client/gui/custom/interfaces/IDataHolder.java create mode 100644 src/main/java/noppes/npcs/client/gui/custom/interfaces/IGuiComponent.java create mode 100644 src/main/java/noppes/npcs/client/gui/custom/interfaces/IKeyListener.java create mode 100644 src/main/java/noppes/npcs/containers/ContainerCustomGui.java create mode 100644 src/main/java/noppes/npcs/controllers/CustomGuiController.java create mode 100644 src/main/java/noppes/npcs/scripted/event/CustomGuiEvent.java create mode 100644 src/main/java/noppes/npcs/scripted/gui/ScriptGui.java create mode 100644 src/main/java/noppes/npcs/scripted/gui/ScriptGuiButton.java create mode 100644 src/main/java/noppes/npcs/scripted/gui/ScriptGuiComponent.java create mode 100644 src/main/java/noppes/npcs/scripted/gui/ScriptGuiItemSlot.java create mode 100644 src/main/java/noppes/npcs/scripted/gui/ScriptGuiLabel.java create mode 100644 src/main/java/noppes/npcs/scripted/gui/ScriptGuiScroll.java create mode 100644 src/main/java/noppes/npcs/scripted/gui/ScriptGuiTextField.java create mode 100644 src/main/java/noppes/npcs/scripted/gui/ScriptGuiTexturedRect.java create mode 100644 src/main/java/noppes/npcs/scripted/interfaces/IButton.java create mode 100644 src/main/java/noppes/npcs/scripted/interfaces/ICustomGui.java create mode 100644 src/main/java/noppes/npcs/scripted/interfaces/ICustomGuiComponent.java create mode 100644 src/main/java/noppes/npcs/scripted/interfaces/IItemSlot.java create mode 100644 src/main/java/noppes/npcs/scripted/interfaces/ILabel.java create mode 100644 src/main/java/noppes/npcs/scripted/interfaces/IScroll.java create mode 100644 src/main/java/noppes/npcs/scripted/interfaces/ITextField.java create mode 100644 src/main/java/noppes/npcs/scripted/interfaces/ITexturedRect.java diff --git a/src/main/java/noppes/npcs/CommonProxy.java b/src/main/java/noppes/npcs/CommonProxy.java index b5075fec4..47e99d01d 100644 --- a/src/main/java/noppes/npcs/CommonProxy.java +++ b/src/main/java/noppes/npcs/CommonProxy.java @@ -4,32 +4,14 @@ import net.minecraft.client.model.ModelBiped; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; +import net.minecraft.inventory.InventoryBasic; import net.minecraft.item.Item; import net.minecraft.stats.Achievement; import net.minecraft.world.World; import net.minecraftforge.common.util.FakePlayer; import noppes.npcs.blocks.tiles.TileNpcContainer; import noppes.npcs.constants.EnumGuiType; -import noppes.npcs.containers.ContainerCarpentryBench; -import noppes.npcs.containers.ContainerCrate; -import noppes.npcs.containers.ContainerMail; -import noppes.npcs.containers.ContainerManageBanks; -import noppes.npcs.containers.ContainerManageRecipes; -import noppes.npcs.containers.ContainerMerchantAdd; -import noppes.npcs.containers.ContainerNPCBankLarge; -import noppes.npcs.containers.ContainerNPCBankSmall; -import noppes.npcs.containers.ContainerNPCBankUnlock; -import noppes.npcs.containers.ContainerNPCBankUpgrade; -import noppes.npcs.containers.ContainerNPCCompanion; -import noppes.npcs.containers.ContainerNPCFollower; -import noppes.npcs.containers.ContainerNPCFollowerHire; -import noppes.npcs.containers.ContainerNPCFollowerSetup; -import noppes.npcs.containers.ContainerNPCInv; -import noppes.npcs.containers.ContainerNPCTrader; -import noppes.npcs.containers.ContainerNPCTraderSetup; -import noppes.npcs.containers.ContainerNpcItemGiver; -import noppes.npcs.containers.ContainerNpcQuestReward; -import noppes.npcs.containers.ContainerNpcQuestTypeItem; +import noppes.npcs.containers.*; import noppes.npcs.controllers.PlayerData; import noppes.npcs.entity.EntityCustomNpc; import noppes.npcs.entity.EntityNPCInterface; @@ -59,6 +41,9 @@ public class CommonProxy implements IGuiHandler { return getContainer(gui, player, x, y, z, npc); } public Container getContainer(EnumGuiType gui,EntityPlayer player, int x, int y, int z,EntityNPCInterface npc){ + if(gui == EnumGuiType.CustomGui) + return new ContainerCustomGui(new InventoryBasic("", false, x)); + if(gui == EnumGuiType.MainMenuInv) return new ContainerNPCInv(npc, player); diff --git a/src/main/java/noppes/npcs/EventHooks.java b/src/main/java/noppes/npcs/EventHooks.java index f1367a235..18366fadd 100644 --- a/src/main/java/noppes/npcs/EventHooks.java +++ b/src/main/java/noppes/npcs/EventHooks.java @@ -18,6 +18,7 @@ import net.minecraft.world.World; import net.minecraft.world.WorldServer; import net.minecraftforge.event.entity.EntityEvent; import net.minecraftforge.event.world.WorldEvent; +import noppes.npcs.controllers.CustomGuiController; import noppes.npcs.controllers.ScriptController; import noppes.npcs.controllers.data.ForgeDataScript; import noppes.npcs.controllers.data.PlayerDataScript; @@ -33,6 +34,7 @@ import noppes.npcs.scripted.event.PlayerEvent.LoginEvent; import noppes.npcs.scripted.event.PlayerEvent.LogoutEvent; import noppes.npcs.scripted.event.PlayerEvent.PickUpEvent; import noppes.npcs.scripted.event.PlayerEvent.DropEvent; +import noppes.npcs.scripted.interfaces.ICustomGui; import noppes.npcs.scripted.interfaces.IEntity; import noppes.npcs.scripted.interfaces.IItemStack; import noppes.npcs.scripted.interfaces.IWorld; @@ -47,6 +49,8 @@ public class EventHooks { public EventHooks() { } + + public static void onNPCTimer(EntityNPCInterface npc, int id) { NpcEvent.TimerEvent event = new NpcEvent.TimerEvent(npc.wrappedNPC, id); ScriptEventTimer scriptEvent = new ScriptEventTimer(id); @@ -311,4 +315,24 @@ public class EventHooks { } } + + public static void onCustomGuiButton(ScriptPlayer player, ICustomGui gui, int buttonId) { + CustomGuiEvent.ButtonEvent event = new CustomGuiEvent.ButtonEvent(player, gui, buttonId); + CustomGuiController.onButton(event); + } + + public static void onCustomGuiSlot(ScriptPlayer player, ICustomGui gui, int slotId) { + CustomGuiEvent.SlotEvent event = new CustomGuiEvent.SlotEvent(player, gui, slotId, player.getOpenContainer().getSlot(slotId)); + CustomGuiController.onSlotChange(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); + } + + public static void onCustomGuiClose(ScriptPlayer player, ICustomGui gui) { + noppes.npcs.scripted.event.CustomGuiEvent.CloseEvent event = new noppes.npcs.scripted.event.CustomGuiEvent.CloseEvent(player, gui); + CustomGuiController.onClose(event); + } } \ No newline at end of file diff --git a/src/main/java/noppes/npcs/PacketHandlerServer.java b/src/main/java/noppes/npcs/PacketHandlerServer.java index 050dd76bc..bae601c11 100644 --- a/src/main/java/noppes/npcs/PacketHandlerServer.java +++ b/src/main/java/noppes/npcs/PacketHandlerServer.java @@ -36,31 +36,10 @@ import noppes.npcs.constants.EnumPacketClient; import noppes.npcs.constants.EnumPacketServer; import noppes.npcs.constants.EnumPlayerData; import noppes.npcs.constants.EnumRoleType; +import noppes.npcs.containers.ContainerCustomGui; import noppes.npcs.containers.ContainerMail; -import noppes.npcs.controllers.Bank; -import noppes.npcs.controllers.BankController; -import noppes.npcs.controllers.Dialog; -import noppes.npcs.controllers.DialogCategory; -import noppes.npcs.controllers.DialogController; -import noppes.npcs.controllers.DialogOption; -import noppes.npcs.controllers.Faction; -import noppes.npcs.controllers.FactionController; -import noppes.npcs.controllers.LinkedNpcController; +import noppes.npcs.controllers.*; import noppes.npcs.controllers.LinkedNpcController.LinkedData; -import noppes.npcs.controllers.PlayerData; -import noppes.npcs.controllers.PlayerDataController; -import noppes.npcs.controllers.PlayerMail; -import noppes.npcs.controllers.Quest; -import noppes.npcs.controllers.QuestCategory; -import noppes.npcs.controllers.QuestController; -import noppes.npcs.controllers.RecipeCarpentry; -import noppes.npcs.controllers.RecipeController; -import noppes.npcs.controllers.ScriptController; -import noppes.npcs.controllers.ServerCloneController; -import noppes.npcs.controllers.SpawnController; -import noppes.npcs.controllers.SpawnData; -import noppes.npcs.controllers.TransportController; -import noppes.npcs.controllers.TransportLocation; import noppes.npcs.controllers.data.ForgeDataScript; import noppes.npcs.controllers.data.PlayerDataScript; import noppes.npcs.entity.EntityCustomNpc; @@ -71,6 +50,9 @@ import noppes.npcs.roles.RoleTrader; import noppes.npcs.roles.RoleTransporter; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.common.network.FMLNetworkEvent.ServerCustomPacketEvent; +import noppes.npcs.scripted.NpcAPI; +import noppes.npcs.scripted.entity.ScriptPlayer; +import noppes.npcs.scripted.gui.ScriptGui; public class PacketHandlerServer{ @@ -93,6 +75,24 @@ 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.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))); } if(type.needsNpc && npc == null){ @@ -103,24 +103,28 @@ public class PacketHandlerServer{ } else if(item == null && (type == EnumPacketServer.ScriptPlayerGet || type == EnumPacketServer.ScriptPlayerSave || type == EnumPacketServer.ScriptForgeGet || type == EnumPacketServer.ScriptForgeSave)) warn(player, "tried to use custom npcs without a tool in hand, probably a hacker"); - else if(item.getItem() == CustomItems.wand) - wandPackets(type, buffer, player, npc); - else if(item.getItem() == CustomItems.moving) - movingPackets(type, buffer, player, npc); - else if(item.getItem() == CustomItems.mount) - mountPackets(type, buffer, player); - else if(item.getItem() == CustomItems.cloner) - clonePackets(type, buffer, player); - else if(item.getItem() == CustomItems.teleporter) - featherPackets(type, buffer, player); - else if(type == EnumPacketServer.ScriptPlayerGet || type == EnumPacketServer.ScriptPlayerSave) - playerScriptPackets(type, buffer, player); - else if(type == EnumPacketServer.ScriptForgeGet || type == EnumPacketServer.ScriptForgeSave) - forgeScriptPackets(type, buffer, player); - else if(item.getItem() == CustomItems.scripter) - scriptPackets(type, buffer, player, npc); - else if(item.getItem() == Item.getItemFromBlock(CustomItems.waypoint) || item.getItem() == Item.getItemFromBlock(CustomItems.border) || item.getItem() == Item.getItemFromBlock(CustomItems.redstoneBlock)) - blockPackets(type, buffer, player); + else { + if (item != null) { + if (item.getItem() == CustomItems.wand) + wandPackets(type, buffer, player, npc); + else if (item.getItem() == CustomItems.moving) + movingPackets(type, buffer, player, npc); + else if (item.getItem() == CustomItems.mount) + mountPackets(type, buffer, player); + else if (item.getItem() == CustomItems.cloner) + clonePackets(type, buffer, player); + else if (item.getItem() == CustomItems.teleporter) + featherPackets(type, buffer, player); + else if (type == EnumPacketServer.ScriptPlayerGet || type == EnumPacketServer.ScriptPlayerSave) + playerScriptPackets(type, buffer, player); + else if (type == EnumPacketServer.ScriptForgeGet || type == EnumPacketServer.ScriptForgeSave) + forgeScriptPackets(type, buffer, player); + else if (item.getItem() == CustomItems.scripter) + scriptPackets(type, buffer, player, npc); + else if (item.getItem() == Item.getItemFromBlock(CustomItems.waypoint) || item.getItem() == Item.getItemFromBlock(CustomItems.border) || item.getItem() == Item.getItemFromBlock(CustomItems.redstoneBlock)) + blockPackets(type, buffer, player); + } + } } catch (Exception e) { LogWriter.error("Error with EnumPacketServer." + type, e); } diff --git a/src/main/java/noppes/npcs/client/ClientProxy.java b/src/main/java/noppes/npcs/client/ClientProxy.java index b96e82b61..ec1779fc4 100644 --- a/src/main/java/noppes/npcs/client/ClientProxy.java +++ b/src/main/java/noppes/npcs/client/ClientProxy.java @@ -65,6 +65,7 @@ import noppes.npcs.client.fx.EntityElementalStaffFX; import noppes.npcs.client.fx.EntityEnderFX; import noppes.npcs.client.fx.EntityRainbowFX; import noppes.npcs.client.gui.*; +import noppes.npcs.client.gui.custom.GuiCustom; import noppes.npcs.client.gui.global.GuiNPCManageBanks; import noppes.npcs.client.gui.global.GuiNPCManageDialogs; import noppes.npcs.client.gui.global.GuiNPCManageFactions; @@ -128,22 +129,7 @@ import noppes.npcs.client.renderer.blocks.BlockWallBannerRenderer; import noppes.npcs.client.renderer.blocks.BlockWeaponRackRenderer; import noppes.npcs.config.StringCache; import noppes.npcs.constants.EnumGuiType; -import noppes.npcs.containers.ContainerCarpentryBench; -import noppes.npcs.containers.ContainerCrate; -import noppes.npcs.containers.ContainerMail; -import noppes.npcs.containers.ContainerManageBanks; -import noppes.npcs.containers.ContainerManageRecipes; -import noppes.npcs.containers.ContainerNPCBankInterface; -import noppes.npcs.containers.ContainerNPCCompanion; -import noppes.npcs.containers.ContainerNPCFollower; -import noppes.npcs.containers.ContainerNPCFollowerHire; -import noppes.npcs.containers.ContainerNPCFollowerSetup; -import noppes.npcs.containers.ContainerNPCInv; -import noppes.npcs.containers.ContainerNPCTrader; -import noppes.npcs.containers.ContainerNPCTraderSetup; -import noppes.npcs.containers.ContainerNpcItemGiver; -import noppes.npcs.containers.ContainerNpcQuestReward; -import noppes.npcs.containers.ContainerNpcQuestTypeItem; +import noppes.npcs.containers.*; import noppes.npcs.controllers.PlayerData; import noppes.npcs.entity.*; @@ -437,6 +423,10 @@ public class ClientProxy extends CommonProxy { else if (gui == EnumGuiType.CompanionInv) return new GuiNpcCompanionInv(npc, (ContainerNPCCompanion) container); + + else if (gui == EnumGuiType.CustomGui) + return new GuiCustom((ContainerCustomGui)container); + return null; } diff --git a/src/main/java/noppes/npcs/client/gui/custom/GuiCustom.java b/src/main/java/noppes/npcs/client/gui/custom/GuiCustom.java new file mode 100644 index 000000000..8f37fee33 --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/custom/GuiCustom.java @@ -0,0 +1,885 @@ +package noppes.npcs.client.gui.custom; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.gui.GuiTextField; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.client.renderer.OpenGlHelper; +import net.minecraft.client.renderer.RenderHelper; +import net.minecraft.client.renderer.texture.TextureMap; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.Container; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.nbt.NBTTagString; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.IIcon; +import net.minecraft.util.MathHelper; +import net.minecraft.util.ResourceLocation; +import noppes.npcs.client.Client; +import noppes.npcs.client.gui.custom.components.*; +import noppes.npcs.client.gui.custom.interfaces.IClickListener; +import noppes.npcs.client.gui.custom.interfaces.IDataHolder; +import noppes.npcs.client.gui.custom.interfaces.IGuiComponent; +import noppes.npcs.client.gui.util.GuiCustomScroll; +import noppes.npcs.client.gui.util.ICustomScrollListener; +import noppes.npcs.client.gui.util.IGuiData; +import noppes.npcs.constants.EnumPacketServer; +import noppes.npcs.containers.ContainerCustomGui; +import noppes.npcs.scripted.gui.*; +import noppes.npcs.scripted.interfaces.ICustomGuiComponent; +import org.lwjgl.input.Keyboard; +import org.lwjgl.input.Mouse; +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL12; + +import java.util.*; + +public class GuiCustom extends GuiScreen implements ICustomScrollListener, IGuiData { + ScriptGui gui; + int xSize; + int ySize; + public static int guiLeft; + public static int guiTop; + ResourceLocation background; + public String[] hoverText; + Map components = new HashMap(); + List clickListeners = new ArrayList(); + List keyListeners = new ArrayList(); + List dataHolders = new ArrayList(); + + public Container inventorySlots; + private Slot theSlot; + private Slot clickedSlot; + private boolean isRightMouseClick; + private ItemStack draggedStack; + private int field_147011_y; + private int field_147010_z; + private Slot returningStackDestSlot; + private long returningStackTime; + private ItemStack returningStack; + private Slot field_146985_D; + private long field_146986_E; + protected final Set field_147008_s = new HashSet(); + protected boolean field_147007_t; + private int field_146987_F; + private int field_146988_G; + private boolean field_146995_H; + private int field_146996_I; + private long field_146997_J; + private Slot field_146998_K; + private int field_146992_L; + private boolean field_146993_M; + private ItemStack field_146994_N; + + public GuiCustom(ContainerCustomGui container) { + this.inventorySlots = container; + this.field_146995_H = true; + this.allowUserInput = true; + } + + public void initGui() { + super.initGui(); + this.mc.thePlayer.openContainer = this.inventorySlots; + if (this.gui != null) { + guiLeft = (this.width - this.xSize)/2; + guiTop = (this.height - this.ySize)/2; + this.components.clear(); + this.clickListeners.clear(); + this.keyListeners.clear(); + this.dataHolders.clear(); + Iterator var1 = this.gui.getComponents().iterator(); + + while(var1.hasNext()) { + ICustomGuiComponent c = (ICustomGuiComponent)var1.next(); + this.addComponent(c); + } + } + + } + + public void updateScreen() { + super.updateScreen(); + + Iterator var1 = this.dataHolders.iterator(); + + while(var1.hasNext()) { + IDataHolder component = (IDataHolder)var1.next(); + if (component instanceof GuiTextField) { + ((GuiTextField)component).updateCursorCounter(); + } + } + + if (!this.mc.thePlayer.isEntityAlive() || this.mc.thePlayer.isDead) + { + this.mc.thePlayer.closeScreen(); + } + } + + public void drawScreen(int mouseX, int mouseY, float partialTicks) { + this.hoverText = null; + //this.drawDefaultBackground(); + if (this.background != null) { + this.drawBackgroundTexture(); + } + + Iterator var4 = this.components.values().iterator(); + + while(var4.hasNext()) { + IGuiComponent component = (IGuiComponent)var4.next(); + component.onRender(this.mc, mouseX, mouseY, Mouse.getDWheel(), partialTicks); + } + + if (this.hoverText != null) { + this.func_146283_a(Arrays.asList(this.hoverText), mouseX, mouseY); + } + + drawScreenSuper(mouseX, mouseY, partialTicks); + } + + public void drawScreenSuper(int mouseX, int mouseY, float partialTicks) + { + //this.drawDefaultBackground(); + int k = this.guiLeft; + int l = this.guiTop; + //this.drawGuiContainerBackgroundLayer(partialTicks, mouseX, mouseY); + GL11.glDisable(GL12.GL_RESCALE_NORMAL); + RenderHelper.disableStandardItemLighting(); + GL11.glDisable(GL11.GL_LIGHTING); + GL11.glDisable(GL11.GL_DEPTH_TEST); + super.drawScreen(mouseX, mouseY, partialTicks); + RenderHelper.enableGUIStandardItemLighting(); + GL11.glPushMatrix(); + GL11.glTranslatef((float)k, (float)l, 0.0F); + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + GL11.glEnable(GL12.GL_RESCALE_NORMAL); + this.theSlot = null; + short short1 = 240; + short short2 = 240; + OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, (float)short1 / 1.0F, (float)short2 / 1.0F); + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + int k1; + + for (int i1 = 0; i1 < this.inventorySlots.inventorySlots.size(); ++i1) + { + Slot slot = (Slot)this.inventorySlots.inventorySlots.get(i1); + this.drawSlot(slot); + + if (this.isMouseOverSlot(slot, mouseX, mouseY) && slot.func_111238_b()) + { + this.theSlot = slot; + GL11.glDisable(GL11.GL_LIGHTING); + GL11.glDisable(GL11.GL_DEPTH_TEST); + int j1 = slot.xDisplayPosition; + k1 = slot.yDisplayPosition; + GL11.glColorMask(true, true, true, false); + this.drawGradientRect(j1, k1, j1 + 16, k1 + 16, -2130706433, -2130706433); + GL11.glColorMask(true, true, true, true); + GL11.glEnable(GL11.GL_LIGHTING); + GL11.glEnable(GL11.GL_DEPTH_TEST); + } + } + + //Forge: Force lighting to be disabled as there are some issue where lighting would + //incorrectly be applied based on items that are in the inventory. + GL11.glDisable(GL11.GL_LIGHTING); + //this.drawGuiContainerForegroundLayer(mouseX, mouseY); + GL11.glEnable(GL11.GL_LIGHTING); + InventoryPlayer inventoryplayer = this.mc.thePlayer.inventory; + ItemStack itemstack = this.draggedStack == null ? inventoryplayer.getItemStack() : this.draggedStack; + + if (itemstack != null) + { + byte b0 = 8; + k1 = this.draggedStack == null ? 8 : 16; + String s = null; + + if (this.draggedStack != null && this.isRightMouseClick) + { + itemstack = itemstack.copy(); + itemstack.stackSize = MathHelper.ceiling_float_int((float)itemstack.stackSize / 2.0F); + } + else if (this.field_147007_t && this.field_147008_s.size() > 1) + { + itemstack = itemstack.copy(); + itemstack.stackSize = this.field_146996_I; + + if (itemstack.stackSize == 0) + { + s = "" + EnumChatFormatting.YELLOW + "0"; + } + } + + this.drawItemStack(itemstack, mouseX - k - b0, mouseY - l - k1, s); + } + + if (this.returningStack != null) + { + float f1 = (float)(Minecraft.getSystemTime() - this.returningStackTime) / 100.0F; + + if (f1 >= 1.0F) + { + f1 = 1.0F; + this.returningStack = null; + } + + k1 = this.returningStackDestSlot.xDisplayPosition - this.field_147011_y; + int j2 = this.returningStackDestSlot.yDisplayPosition - this.field_147010_z; + int l1 = this.field_147011_y + (int)((float)k1 * f1); + int i2 = this.field_147010_z + (int)((float)j2 * f1); + this.drawItemStack(this.returningStack, l1, i2, (String)null); + } + + GL11.glPopMatrix(); + + if (inventoryplayer.getItemStack() == null && this.theSlot != null && this.theSlot.getHasStack()) + { + ItemStack itemstack1 = this.theSlot.getStack(); + this.renderToolTip(itemstack1, mouseX, mouseY); + } + + GL11.glEnable(GL11.GL_LIGHTING); + GL11.glEnable(GL11.GL_DEPTH_TEST); + RenderHelper.enableStandardItemLighting(); + } + + private void drawItemStack(ItemStack p_146982_1_, int p_146982_2_, int p_146982_3_, String p_146982_4_) + { + GL11.glTranslatef(0.0F, 0.0F, 32.0F); + this.zLevel = 200.0F; + itemRender.zLevel = 200.0F; + FontRenderer font = null; + if (p_146982_1_ != null) font = p_146982_1_.getItem().getFontRenderer(p_146982_1_); + if (font == null) font = fontRendererObj; + itemRender.renderItemAndEffectIntoGUI(font, this.mc.getTextureManager(), p_146982_1_, p_146982_2_, p_146982_3_); + itemRender.renderItemOverlayIntoGUI(font, this.mc.getTextureManager(), p_146982_1_, p_146982_2_, p_146982_3_ - (this.draggedStack == null ? 0 : 8), p_146982_4_); + this.zLevel = 0.0F; + itemRender.zLevel = 0.0F; + } + + private boolean isMouseOverSlot(Slot slot, int posX, int posY) + { + return this.isPointInRegion(slot.xDisplayPosition, slot.yDisplayPosition, 16, 16, posX, posY); + } + + protected boolean isPointInRegion(int slotDisplayX, int slotDisplayY, int slotSizeX, int slotSizeY, int posX, int posY) + { + int k1 = this.guiLeft; + int l1 = this.guiTop; + posX -= k1; + posY -= l1; + return posX >= slotDisplayX - 1 && posX < slotDisplayX + slotSizeX + 1 && posY >= slotDisplayY - 1 && posY < slotDisplayY + slotSizeY + 1; + } + + private void drawSlot(Slot p_146977_1_) + { + int i = p_146977_1_.xDisplayPosition; + int j = p_146977_1_.yDisplayPosition; + ItemStack itemstack = p_146977_1_.getStack(); + boolean flag = false; + boolean flag1 = p_146977_1_ == this.clickedSlot && this.draggedStack != null && !this.isRightMouseClick; + ItemStack itemstack1 = this.mc.thePlayer.inventory.getItemStack(); + String s = null; + + if (p_146977_1_ == this.clickedSlot && this.draggedStack != null && this.isRightMouseClick && itemstack != null) + { + itemstack = itemstack.copy(); + itemstack.stackSize /= 2; + } + else if (this.field_147007_t && this.field_147008_s.contains(p_146977_1_) && itemstack1 != null) + { + if (this.field_147008_s.size() == 1) + { + return; + } + + if (Container.func_94527_a(p_146977_1_, itemstack1, true) && this.inventorySlots.canDragIntoSlot(p_146977_1_)) + { + itemstack = itemstack1.copy(); + flag = true; + Container.func_94525_a(this.field_147008_s, this.field_146987_F, itemstack, p_146977_1_.getStack() == null ? 0 : p_146977_1_.getStack().stackSize); + + if (itemstack.stackSize > itemstack.getMaxStackSize()) + { + s = EnumChatFormatting.YELLOW + "" + itemstack.getMaxStackSize(); + itemstack.stackSize = itemstack.getMaxStackSize(); + } + + if (itemstack.stackSize > p_146977_1_.getSlotStackLimit()) + { + s = EnumChatFormatting.YELLOW + "" + p_146977_1_.getSlotStackLimit(); + itemstack.stackSize = p_146977_1_.getSlotStackLimit(); + } + } + else + { + this.field_147008_s.remove(p_146977_1_); + this.func_146980_g(); + } + } + + this.zLevel = 100.0F; + itemRender.zLevel = 100.0F; + + if (itemstack == null) + { + IIcon iicon = p_146977_1_.getBackgroundIconIndex(); + + if (iicon != null) + { + GL11.glDisable(GL11.GL_LIGHTING); + GL11.glEnable(GL11.GL_BLEND); // Forge: Blending needs to be enabled for this. + this.mc.getTextureManager().bindTexture(TextureMap.locationItemsTexture); + this.drawTexturedModelRectFromIcon(i, j, iicon, 16, 16); + GL11.glDisable(GL11.GL_BLEND); // Forge: And clean that up + GL11.glEnable(GL11.GL_LIGHTING); + flag1 = true; + } + } + + if (!flag1) + { + if (flag) + { + drawRect(i, j, i + 16, j + 16, -2130706433); + } + + GL11.glEnable(GL11.GL_DEPTH_TEST); + itemRender.renderItemAndEffectIntoGUI(this.fontRendererObj, this.mc.getTextureManager(), itemstack, i, j); + itemRender.renderItemOverlayIntoGUI(this.fontRendererObj, this.mc.getTextureManager(), itemstack, i, j, s); + } + + itemRender.zLevel = 0.0F; + this.zLevel = 0.0F; + } + + private void func_146980_g() + { + ItemStack itemstack = this.mc.thePlayer.inventory.getItemStack(); + + if (itemstack != null && this.field_147007_t) + { + this.field_146996_I = itemstack.stackSize; + ItemStack itemstack1; + int i; + + for (Iterator iterator = this.field_147008_s.iterator(); iterator.hasNext(); this.field_146996_I -= itemstack1.stackSize - i) + { + Slot slot = (Slot)iterator.next(); + itemstack1 = itemstack.copy(); + i = slot.getStack() == null ? 0 : slot.getStack().stackSize; + Container.func_94525_a(this.field_147008_s, this.field_146987_F, itemstack1, i); + + if (itemstack1.stackSize > itemstack1.getMaxStackSize()) + { + itemstack1.stackSize = itemstack1.getMaxStackSize(); + } + + if (itemstack1.stackSize > slot.getSlotStackLimit()) + { + itemstack1.stackSize = slot.getSlotStackLimit(); + } + } + } + } + + protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) { + } + + void drawBackgroundTexture() { + this.mc.getTextureManager().bindTexture(this.background); + this.drawTexturedModalRect(guiLeft, guiTop, 0, 0, this.xSize, this.ySize); + } + + private void addComponent(ICustomGuiComponent component) { + ScriptGuiComponent c = (ScriptGuiComponent)component; + switch(c.getType()) { + case 0: + CustomGuiButton button = CustomGuiButton.fromComponent((ScriptGuiButton)component); + button.setParent(this); + this.components.put(button.getID(), button); + this.addClickListener(button); + break; + case 1: + CustomGuiLabel lbl = CustomGuiLabel.fromComponent((ScriptGuiLabel)component); + lbl.setParent(this); + this.components.put(lbl.getID(), lbl); + break; + case 2: + CustomGuiTexturedRect rect = CustomGuiTexturedRect.fromComponent((ScriptGuiTexturedRect)component); + rect.setParent(this); + this.components.put(rect.getID(), rect); + break; + case 3: + CustomGuiTextField textField = CustomGuiTextField.fromComponent((ScriptGuiTextField)component); + textField.setParent(this); + this.components.put(textField.getID(), textField); + this.addDataHolder(textField); + this.addClickListener(textField); + this.addKeyListener(textField); + break; + case 4: + CustomGuiScrollComponent scroll = new CustomGuiScrollComponent(this.mc, this, component.getID(), ((ScriptGuiScroll)component).isMultiSelect()); + scroll.fromComponent((ScriptGuiScroll)component); + scroll.setParent(this); + this.components.put(scroll.getID(), scroll); + this.addDataHolder(scroll); + this.addClickListener(scroll); + } + + } + + protected void actionPerformed(GuiButton button) { + super.actionPerformed(button); + Client.sendData(EnumPacketServer.CustomGuiButton, new Object[]{this.updateGui().toNBT(), button.id}); + } + + public void buttonClick(CustomGuiButton button) { + Client.sendData(EnumPacketServer.CustomGuiButton, new Object[]{this.updateGui().toNBT(), button.id}); + } + + public void slotChange(CustomGuiSlot slot) { + Client.sendData(EnumPacketServer.CustomGuiSlotChange, new Object[]{this.updateGui().toNBT(), slot.slotNumber}); + } + + public String prevScrollClicked = null; + public void customScrollClicked(int i, int j, int k, GuiCustomScroll scroll) { + Client.sendData(EnumPacketServer.CustomGuiScrollClick, new Object[]{this.updateGui().toNBT(), scroll.id, scroll.selected, this.getScrollSelection((CustomGuiScrollComponent)scroll), false}); + if(Integer.toString(scroll.selected).equals(prevScrollClicked)){ + Client.sendData(EnumPacketServer.CustomGuiScrollClick, new Object[]{this.updateGui().toNBT(), scroll.id, scroll.selected, this.getScrollSelection((CustomGuiScrollComponent)scroll), true}); + } + prevScrollClicked = Integer.toString(scroll.selected); + } + + public void onGuiClosed() { + if (this.gui != null) { + Client.sendData(EnumPacketServer.CustomGuiClose, new Object[]{this.updateGui().toNBT()}); + } + + if (this.mc.thePlayer != null) + { + this.inventorySlots.onContainerClosed(this.mc.thePlayer); + } + } + + ScriptGui updateGui() { + Iterator var1 = this.dataHolders.iterator(); + + while(var1.hasNext()) { + IDataHolder component = (IDataHolder)var1.next(); + this.gui.updateComponent(component.toComponent()); + } + + return this.gui; + } + + NBTTagCompound getScrollSelection(CustomGuiScrollComponent scroll) { + NBTTagList list = new NBTTagList(); + if (scroll.multiSelect) { + Iterator var3 = scroll.getSelectedList().iterator(); + + while(var3.hasNext()) { + String s = (String)var3.next(); + list.appendTag(new NBTTagString(s)); + } + } else { + list.appendTag(new NBTTagString(scroll.getSelected())); + } + + NBTTagCompound selection = new NBTTagCompound(); + selection.setTag("selection", list); + return selection; + } + + protected void keyTyped(char typedChar, int keyCode) { + if (keyCode == 1 || keyCode == this.mc.gameSettings.keyBindInventory.getKeyCode()) + { + this.mc.thePlayer.closeScreen(); + } + + this.checkHotbarKeys(keyCode); + + if (this.theSlot != null && this.theSlot.getHasStack()) + { + if (keyCode == this.mc.gameSettings.keyBindPickBlock.getKeyCode()) + { + this.handleMouseClick(this.theSlot, this.theSlot.slotNumber, 0, 3); + } + else if (keyCode == this.mc.gameSettings.keyBindDrop.getKeyCode()) + { + this.handleMouseClick(this.theSlot, this.theSlot.slotNumber, isCtrlKeyDown() ? 1 : 0, 4); + } + } + + Iterator var3 = this.keyListeners.iterator(); + + while(var3.hasNext()) { + CustomGuiTextField listener = (CustomGuiTextField) var3.next(); + listener.keyTyped(typedChar, keyCode); + } + + if (this.mc.gameSettings.keyBindInventory.getKeyCode() != keyCode && !this.mc.gameSettings.keyBindInventory.getIsKeyPressed()) { + super.keyTyped(typedChar, keyCode); + } + } + + public void mouseClicked(int mouseX, int mouseY, int mouseButton) { + super.mouseClicked(mouseX, mouseY, mouseButton); + + boolean flag = mouseButton == this.mc.gameSettings.keyBindPickBlock.getKeyCode() + 100; + Slot slot = this.getSlotAtPosition(mouseX, mouseY); + long l = Minecraft.getSystemTime(); + this.field_146993_M = this.field_146998_K == slot && l - this.field_146997_J < 250L && this.field_146992_L == mouseButton; + 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; + int k1 = -1; + + if (slot != null) { + k1 = slot.slotNumber; + } + + if (flag1) { + k1 = -999; + } + + if (this.mc.gameSettings.touchscreen && flag1 && this.mc.thePlayer.inventory.getItemStack() == null) { + this.mc.displayGuiScreen((GuiScreen) null); + return; + } + + if (k1 != -1) { + if (this.mc.gameSettings.touchscreen) { + if (slot != null && slot.getHasStack()) { + this.clickedSlot = slot; + this.draggedStack = null; + this.isRightMouseClick = mouseButton == 1; + } else { + this.clickedSlot = null; + } + } else if (!this.field_147007_t) { + if (this.mc.thePlayer.inventory.getItemStack() == null) { + if (mouseButton == this.mc.gameSettings.keyBindPickBlock.getKeyCode() + 100) { + this.handleMouseClick(slot, k1, mouseButton, 3); + } else { + boolean flag2 = k1 != -999 && (Keyboard.isKeyDown(42) || Keyboard.isKeyDown(54)); + byte b0 = 0; + + if (flag2) { + this.field_146994_N = slot != null && slot.getHasStack() ? slot.getStack() : null; + b0 = 1; + } else if (k1 == -999) { + b0 = 4; + } + + this.handleMouseClick(slot, k1, mouseButton, b0); + } + + this.field_146995_H = true; + } else { + this.field_147007_t = true; + this.field_146988_G = mouseButton; + this.field_147008_s.clear(); + + if (mouseButton == 0) { + this.field_146987_F = 0; + } else if (mouseButton == 1) { + this.field_146987_F = 1; + } + } + } + } + } + + this.field_146998_K = slot; + this.field_146997_J = l; + this.field_146992_L = mouseButton; + + Iterator var4 = this.clickListeners.iterator(); + + while(var4.hasNext()) { + IClickListener listener = (IClickListener)var4.next(); + listener.mouseClicked(this, mouseX, mouseY, mouseButton); + } + + } + + public boolean doesGuiPauseGame() { + return this.gui == null || this.gui.getDoesPauseGame(); + } + + public void addDataHolder(IDataHolder component) { + this.dataHolders.add(component); + } + + public void addKeyListener(CustomGuiTextField component) { + this.keyListeners.add(component); + } + + public void addClickListener(IClickListener component) { + this.clickListeners.add(component); + } + + public void setGuiData(NBTTagCompound compound) { + Minecraft mc = Minecraft.getMinecraft(); + ScriptGui gui = (ScriptGui)(new ScriptGui()).fromNBT(compound); + ((ContainerCustomGui)this.inventorySlots).setGui(gui, mc.thePlayer); + this.gui = gui; + this.xSize = gui.getWidth(); + this.ySize = gui.getHeight(); + if (!gui.getBackgroundTexture().isEmpty()) { + this.background = new ResourceLocation(gui.getBackgroundTexture()); + } + + this.initGui(); + } + + /** + * This function is what controls the hotbar shortcut check when you press a number key when hovering a stack. + */ + protected boolean checkHotbarKeys(int p_146983_1_) + { + if (this.mc.thePlayer.inventory.getItemStack() == null && this.theSlot != null) + { + for (int j = 0; j < 9; ++j) + { + if (p_146983_1_ == this.mc.gameSettings.keyBindsHotbar[j].getKeyCode()) + { + this.handleMouseClick(this.theSlot, this.theSlot.slotNumber, j, 2); + return true; + } + } + } + + return false; + } + + protected void handleMouseClick(Slot slot, int index, int p_146984_3_, int p_146984_4_) + { + if (slot != null) + { + index = slot.slotNumber; + } + + this.mc.playerController.windowClick(this.inventorySlots.windowId, index, p_146984_3_, p_146984_4_, this.mc.thePlayer); + } + + protected void mouseMovedOrUp(int p_146286_1_, int p_146286_2_, int p_146286_3_) + { + super.mouseMovedOrUp(p_146286_1_, p_146286_2_, p_146286_3_); //Forge, Call parent to release buttons + Slot slot = this.getSlotAtPosition(p_146286_1_, p_146286_2_); + int l = this.guiLeft; + int i1 = this.guiTop; + boolean flag = p_146286_1_ < l || p_146286_2_ < i1 || p_146286_1_ >= l + this.xSize || p_146286_2_ >= i1 + this.ySize; + int j1 = -1; + + if (slot != null) + { + j1 = slot.slotNumber; + } + + if (flag) + { + j1 = -999; + } + + Slot slot1; + Iterator iterator; + + if (this.field_146993_M && slot != null && p_146286_3_ == 0 && this.inventorySlots.func_94530_a((ItemStack)null, slot)) + { + if (isShiftKeyDown()) + { + if (slot != null && slot.inventory != null && this.field_146994_N != null) + { + iterator = this.inventorySlots.inventorySlots.iterator(); + + while (iterator.hasNext()) + { + slot1 = (Slot)iterator.next(); + + if (slot1 != null && slot1.canTakeStack(this.mc.thePlayer) && slot1.getHasStack() && slot1.inventory == slot.inventory && Container.func_94527_a(slot1, this.field_146994_N, true)) + { + this.handleMouseClick(slot1, slot1.slotNumber, p_146286_3_, 1); + } + } + } + } + else + { + this.handleMouseClick(slot, j1, p_146286_3_, 6); + } + + this.field_146993_M = false; + this.field_146997_J = 0L; + } + else + { + if (this.field_147007_t && this.field_146988_G != p_146286_3_) + { + this.field_147007_t = false; + this.field_147008_s.clear(); + this.field_146995_H = true; + return; + } + + if (this.field_146995_H) + { + this.field_146995_H = false; + return; + } + + boolean flag1; + + if (this.clickedSlot != null && this.mc.gameSettings.touchscreen) + { + if (p_146286_3_ == 0 || p_146286_3_ == 1) + { + if (this.draggedStack == null && slot != this.clickedSlot) + { + this.draggedStack = this.clickedSlot.getStack(); + } + + flag1 = Container.func_94527_a(slot, this.draggedStack, false); + + if (j1 != -1 && this.draggedStack != null && flag1) + { + this.handleMouseClick(this.clickedSlot, this.clickedSlot.slotNumber, p_146286_3_, 0); + this.handleMouseClick(slot, j1, 0, 0); + + if (this.mc.thePlayer.inventory.getItemStack() != null) + { + this.handleMouseClick(this.clickedSlot, this.clickedSlot.slotNumber, p_146286_3_, 0); + this.field_147011_y = p_146286_1_ - l; + this.field_147010_z = p_146286_2_ - i1; + this.returningStackDestSlot = this.clickedSlot; + this.returningStack = this.draggedStack; + this.returningStackTime = Minecraft.getSystemTime(); + } + else + { + this.returningStack = null; + } + } + else if (this.draggedStack != null) + { + this.field_147011_y = p_146286_1_ - l; + this.field_147010_z = p_146286_2_ - i1; + this.returningStackDestSlot = this.clickedSlot; + this.returningStack = this.draggedStack; + this.returningStackTime = Minecraft.getSystemTime(); + } + + this.draggedStack = null; + this.clickedSlot = null; + } + } + else if (this.field_147007_t && !this.field_147008_s.isEmpty()) + { + this.handleMouseClick((Slot)null, -999, Container.func_94534_d(0, this.field_146987_F), 5); + iterator = this.field_147008_s.iterator(); + + while (iterator.hasNext()) + { + slot1 = (Slot)iterator.next(); + this.handleMouseClick(slot1, slot1.slotNumber, Container.func_94534_d(1, this.field_146987_F), 5); + } + + this.handleMouseClick((Slot)null, -999, Container.func_94534_d(2, this.field_146987_F), 5); + } + else if (this.mc.thePlayer.inventory.getItemStack() != null) + { + if (p_146286_3_ == this.mc.gameSettings.keyBindPickBlock.getKeyCode() + 100) + { + this.handleMouseClick(slot, j1, p_146286_3_, 3); + } + else + { + flag1 = j1 != -999 && (Keyboard.isKeyDown(42) || Keyboard.isKeyDown(54)); + + if (flag1) + { + this.field_146994_N = slot != null && slot.getHasStack() ? slot.getStack() : null; + } + + this.handleMouseClick(slot, j1, p_146286_3_, flag1 ? 1 : 0); + } + } + } + + if (this.mc.thePlayer.inventory.getItemStack() == null) + { + this.field_146997_J = 0L; + } + + this.field_147007_t = false; + } + + private Slot getSlotAtPosition(int posX, int posY) + { + for (int k = 0; k < this.inventorySlots.inventorySlots.size(); ++k) + { + Slot slot = (Slot)this.inventorySlots.inventorySlots.get(k); + + if (this.isMouseOverSlot(slot, posX, posY)) + { + return slot; + } + } + + return null; + } + + protected void mouseClickMove(int p_146273_1_, int p_146273_2_, int p_146273_3_, long p_146273_4_) + { + Slot slot = this.getSlotAtPosition(p_146273_1_, p_146273_2_); + ItemStack itemstack = this.mc.thePlayer.inventory.getItemStack(); + + if (this.clickedSlot != null && this.mc.gameSettings.touchscreen) + { + if (p_146273_3_ == 0 || p_146273_3_ == 1) + { + if (this.draggedStack == null) + { + if (slot != this.clickedSlot) + { + this.draggedStack = this.clickedSlot.getStack().copy(); + } + } + else if (this.draggedStack.stackSize > 1 && slot != null && Container.func_94527_a(slot, this.draggedStack, false)) + { + long i1 = Minecraft.getSystemTime(); + + if (this.field_146985_D == slot) + { + if (i1 - this.field_146986_E > 500L) + { + this.handleMouseClick(this.clickedSlot, this.clickedSlot.slotNumber, 0, 0); + this.handleMouseClick(slot, slot.slotNumber, 1, 0); + this.handleMouseClick(this.clickedSlot, this.clickedSlot.slotNumber, 0, 0); + this.field_146986_E = i1 + 750L; + --this.draggedStack.stackSize; + } + } + else + { + this.field_146985_D = slot; + this.field_146986_E = i1; + } + } + } + } + else if (this.field_147007_t && slot != null && itemstack != null && itemstack.stackSize > this.field_147008_s.size() && Container.func_94527_a(slot, itemstack, true) && slot.isItemValid(itemstack) && this.inventorySlots.canDragIntoSlot(slot)) + { + this.field_147008_s.add(slot); + this.func_146980_g(); + } + } +} diff --git a/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiButton.java b/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiButton.java new file mode 100644 index 000000000..57ad3bc66 --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiButton.java @@ -0,0 +1,155 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by FernFlower decompiler) +// + +package noppes.npcs.client.gui.custom.components; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.audio.PositionedSoundRecord; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.util.ResourceLocation; +import noppes.npcs.client.gui.custom.GuiCustom; +import noppes.npcs.client.gui.custom.interfaces.IClickListener; +import noppes.npcs.scripted.gui.ScriptGuiButton; +import noppes.npcs.scripted.interfaces.ICustomGuiComponent; +import org.lwjgl.opengl.GL11; + +public class CustomGuiButton extends GuiButton implements IClickListener { + GuiCustom parent; + ResourceLocation texture; + public int textureX; + public int textureY; + boolean field_146123_n; + String label; + int colour; + String[] hoverText; + + public CustomGuiButton(int id, String buttonText, int x, int y) { + super(id, GuiCustom.guiLeft + x, GuiCustom.guiTop + y, buttonText); + this.colour = 16777215; + } + + public CustomGuiButton(int id, String buttonText, int x, int y, int width, int height) { + super(id, GuiCustom.guiLeft + x, GuiCustom.guiTop + y, width, height, buttonText); + this.colour = 16777215; + } + + public CustomGuiButton(int buttonId, String buttonText, int x, int y, int width, int height, String texture) { + this(buttonId, buttonText, x, y, width, height, texture, 0, 0); + } + + public CustomGuiButton(int buttonId, String buttonText, int x, int y, int width, int height, String texture, int textureX, int textureY) { + this(buttonId, buttonText, x, y, width, height); + this.textureX = textureX; + this.textureY = textureY; + this.label = buttonText; + this.texture = new ResourceLocation(texture); + } + + public void setParent(GuiCustom parent) { + this.parent = parent; + } + + public static CustomGuiButton fromComponent(ScriptGuiButton component) { + CustomGuiButton btn; + if (component.hasTexture()) { + if (component.getTextureX() >= 0 && component.getTextureY() >= 0) { + btn = new CustomGuiButton(component.getID(), component.getLabel(), component.getPosX(), component.getPosY(), component.getWidth(), component.getHeight(), component.getTexture(), component.getTextureX(), component.getTextureY()); + } else { + btn = new CustomGuiButton(component.getID(), component.getLabel(), component.getPosX(), component.getPosY(), component.getWidth(), component.getHeight(), component.getTexture()); + } + } else if (component.getWidth() >= 0 && component.getHeight() >= 0) { + btn = new CustomGuiButton(component.getID(), component.getLabel(), component.getPosX(), component.getPosY(), component.getWidth(), component.getHeight()); + } else { + btn = new CustomGuiButton(component.getID(), component.getLabel(), component.getPosX(), component.getPosY()); + } + + if (component.hasHoverText()) { + btn.hoverText = component.getHoverText(); + } + + return btn; + } + + public int getID() { + return this.id; + } + + public void onRender(Minecraft mc, int mouseX, int mouseY, int mouseWheel, float partialTicks) { + //GL11.func_179094_E(); + //GL11.func_179109_b(0.0F, 0.0F, (float)this.id); + GL11.glPushMatrix(); + GL11.glTranslatef(0.0F, 0.0F, (float)this.id); + FontRenderer fontRenderer = mc.fontRenderer; + int i; + if (this.texture == null) { + mc.getTextureManager().bindTexture(buttonTextures); + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + this.field_146123_n = mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height; + i = this.getHoverState(this.field_146123_n); + GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + //GL11.func_187428_a(SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA, SourceFactor.ONE, DestFactor.ZERO); + //GL11.func_187401_a(SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA); + this.drawTexturedModalRect(this.xPosition, this.yPosition, 0, 46 + i * 20, this.width / 2, this.height); + this.drawTexturedModalRect(this.xPosition + this.width / 2, this.yPosition, 200 - this.width / 2, 46 + i * 20, this.width / 2, this.height); + this.mouseDragged(mc, mouseX, mouseY); + int j = 14737632; + if (this.packedFGColour != 0) { + j = this.packedFGColour; + } else if (!this.enabled) { + j = 10526880; + } else if (this.field_146123_n) { + j = 16777120; + } + + GL11.glTranslated(0.0D, 0.0D, 0.1D); + this.drawCenteredString(fontRenderer, this.displayString, this.xPosition + this.width / 2, this.yPosition + (this.height - 8) / 2, j); + } else { + mc.getTextureManager().bindTexture(this.texture); + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + this.field_146123_n = mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height; + i = this.hoverState(this.field_146123_n); + GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + //GL11.func_187428_a(SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA, SourceFactor.ONE, DestFactor.ZERO); + //GL11.func_187401_a(SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA); + this.drawTexturedModalRect(this.xPosition, this.yPosition, this.textureX, this.textureY + i * this.height, this.width, this.height); + this.drawCenteredString(fontRenderer, this.label, this.xPosition + this.width / 2, this.yPosition + (this.height - 8) / 2, this.colour); + if (this.field_146123_n && this.hoverText != null && this.hoverText.length > 0) { + this.parent.hoverText = this.hoverText; + } + } + + GL11.glPopMatrix(); + } + + public ICustomGuiComponent toComponent() { + ScriptGuiButton component = new ScriptGuiButton(this.id, this.label, this.xPosition, this.yPosition, this.width, this.height, this.texture.toString(), this.textureX, this.textureY); + component.setHoverText(this.hoverText); + return component; + } + + public void setColour(int colour) { + this.colour = colour; + } + + protected int hoverState(boolean mouseOver) { + int i = 0; + if (mouseOver) { + i = 1; + } + + return i; + } + + public boolean mouseClicked(GuiCustom gui, int mouseX, int mouseY, int mouseButton) { + if (mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height) { + //Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.func_147673_a(SoundEvents.field_187909_gi, 1.0F)); + gui.buttonClick(this); + return true; + } else { + return false; + } + } +} diff --git a/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiLabel.java b/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiLabel.java new file mode 100644 index 000000000..d55254fba --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiLabel.java @@ -0,0 +1,100 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by FernFlower decompiler) +// + +package noppes.npcs.client.gui.custom.components; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiLabel; +import net.minecraft.client.renderer.OpenGlHelper; +import noppes.npcs.client.gui.custom.GuiCustom; +import noppes.npcs.client.gui.custom.interfaces.IGuiComponent; +import noppes.npcs.scripted.gui.ScriptGuiLabel; +import noppes.npcs.scripted.interfaces.ICustomGuiComponent; +import org.lwjgl.opengl.GL11; + +public class CustomGuiLabel extends GuiLabel implements IGuiComponent { + int x, y, width, height; + GuiCustom parent; + String fullLabel; + int color; + String[] hoverText; + float scale; + int id; + int border = 2; + boolean labelBgEnabled = true; + + public void setParent(GuiCustom parent) { + this.parent = parent; + } + + public void onRender(Minecraft mc, int mouseX, int mouseY, int mouseWheel, float partialTicks) { + boolean hovered = mouseX >= this.field_146162_g && mouseY >= this.field_146174_h && mouseX < this.field_146162_g + this.field_146167_a && mouseY < this.field_146174_h + this.field_146161_f; + this.drawLabel(); + if (hovered && this.hoverText != null && this.hoverText.length > 0) { + this.parent.hoverText = this.hoverText; + } + } + + public int getID() { + return this.id; + } + + public void setScale(float scale) { + this.scale = scale; + } + + public static CustomGuiLabel fromComponent(ScriptGuiLabel component) { + CustomGuiLabel lbl = new CustomGuiLabel(); + lbl.scale = 1.0F; + lbl.fullLabel = component.getText(); + lbl.color = component.getColor(); + lbl.field_146172_j = true; + lbl.id = component.getID(); + lbl.x = GuiCustom.guiLeft + component.getPosX(); + lbl.y = GuiCustom.guiTop + component.getPosY(); + lbl.width = component.getWidth(); + lbl.height = component.getHeight(); + lbl.setScale(component.getScale()); + if (component.hasHoverText()) { + lbl.hoverText = component.getHoverText(); + } + + return lbl; + } + + public ICustomGuiComponent toComponent() { + ScriptGuiLabel component = new ScriptGuiLabel(this.id, this.fullLabel, this.field_146162_g, this.field_146174_h, this.field_146167_a, this.field_146161_f, this.color); + component.setHoverText(this.hoverText); + return component; + } + + public void drawLabel() + { + if (this.field_146172_j) + { + GL11.glEnable(GL11.GL_BLEND); + OpenGlHelper.glBlendFunc(770, 771, 1, 0); + GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + this.drawLabelBackground(); + this.drawString(Minecraft.getMinecraft().fontRenderer, fullLabel, this.x, this.y, this.color); + } + } + + protected void drawLabelBackground() + { + if (this.labelBgEnabled) + { + int k = this.width + this.border * 2; + int l = this.height + this.border * 2; + int i1 = this.x - this.border; + int j1 = this.y - this.border; + drawRect(i1, j1, i1 + k, j1 + l, this.color);//backColor + this.drawHorizontalLine(i1, i1 + k, j1, this.color);//ulColor + this.drawHorizontalLine(i1, i1 + k, j1 + l, this.color);//brColor + this.drawVerticalLine(i1, j1, j1 + l, this.color);//ulColor + this.drawVerticalLine(i1 + k, j1, j1 + l, this.color);//brColor + } + } +} diff --git a/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiScrollComponent.java b/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiScrollComponent.java new file mode 100644 index 000000000..eba41ba2c --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiScrollComponent.java @@ -0,0 +1,111 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by FernFlower decompiler) +// + +package noppes.npcs.client.gui.custom.components; + +import java.util.Arrays; +import java.util.Iterator; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.nbt.NBTTagString; +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.util.GuiCustomScroll; +import noppes.npcs.scripted.gui.ScriptGuiScroll; +import noppes.npcs.scripted.interfaces.ICustomGuiComponent; +import org.lwjgl.opengl.GL11; + +public class CustomGuiScrollComponent extends GuiCustomScroll implements IDataHolder, IClickListener { + GuiCustom parent; + String[] hoverText; + public boolean multiSelect = false; + + public CustomGuiScrollComponent(Minecraft mc, GuiScreen parent, int id) { + super(parent, id); + this.mc = mc; + this.fontRendererObj = mc.fontRenderer; + } + + public CustomGuiScrollComponent(Minecraft mc, GuiScreen parent, int id, boolean multiSelect) { + super(parent, id, multiSelect); + this.mc = mc; + this.fontRendererObj = mc.fontRenderer; + this.multiSelect = multiSelect; + } + + public void setParent(GuiCustom parent) { + this.parent = parent; + } + + public int getID() { + return this.id; + } + + public void onRender(Minecraft mc, int mouseX, int mouseY, int mouseWheel, float partialTicks) { + GL11.glPushMatrix(); + GL11.glTranslatef(0.0F, 0.0F, (float)this.id); + boolean hovered = mouseX >= this.guiLeft && mouseY >= this.guiTop && mouseX < this.guiLeft + this.xSize && mouseY < this.guiTop + this.ySize; + super.drawScreen(mouseX, mouseY, partialTicks, mouseWheel); + if (hovered && this.hoverText != null && this.hoverText.length > 0) { + this.parent.hoverText = this.hoverText; + } + + GL11.glPopMatrix(); + } + + public boolean mouseClicked(GuiCustom gui, int mouseX, int mouseY, int mouseButton) { + super.mouseClicked(mouseX, mouseY, mouseButton); + return this.isMouseOver(mouseX, mouseY); + } + + public void fromComponent(ScriptGuiScroll component) { + this.guiLeft = GuiCustom.guiLeft + component.getPosX(); + this.guiTop = GuiCustom.guiTop + component.getPosY(); + this.setSize(component.getWidth(), component.getHeight()); + this.setUnsortedList(Arrays.asList(component.getList())); + if (component.getDefaultSelection() >= 0) { + int defaultSelect = component.getDefaultSelection(); + if (defaultSelect < this.getList().size()) { + this.selected = defaultSelect; + } + } + + if (component.hasHoverText()) { + this.hoverText = component.getHoverText(); + } + + } + + public ICustomGuiComponent toComponent() { + ScriptGuiScroll component = new ScriptGuiScroll(this.id, this.guiLeft - GuiCustom.guiLeft, this.guiTop - GuiCustom.guiTop, this.width, this.height, (String[])this.getList().toArray(new String[0])); + component.setHoverText(this.hoverText); + return component; + } + + public NBTTagCompound toNBT() { + NBTTagCompound nbt = new NBTTagCompound(); + nbt.setInteger("id", this.id); + if (!this.getSelectedList().isEmpty()) { + NBTTagList tagList = new NBTTagList(); + Iterator var3 = this.getSelectedList().iterator(); + + while(var3.hasNext()) { + String s = (String)var3.next(); + tagList.appendTag(new NBTTagString(s)); + } + + nbt.setTag("selectedList", tagList); + } else if (this.getSelected() != null && !this.getSelected().isEmpty()) { + nbt.setString("selected", this.getSelected()); + } else { + nbt.setString("selected", "Null"); + } + + return nbt; + } +} diff --git a/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiSlot.java b/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiSlot.java new file mode 100644 index 000000000..61c31ce4c --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiSlot.java @@ -0,0 +1,30 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by FernFlower decompiler) +// + +package noppes.npcs.client.gui.custom.components; + +import net.minecraft.client.Minecraft; +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.Slot; +import noppes.npcs.client.gui.custom.GuiCustom; + +public class CustomGuiSlot extends Slot { + public boolean clientSide; + public int slotNumber; + + public CustomGuiSlot(IInventory inventoryIn, int index, int xPosition, int yPosition, boolean clientSide) { + super(inventoryIn, index, xPosition, yPosition); + this.clientSide = clientSide; + this.slotNumber = index; + } + + public void onSlotChanged() { + if (this.clientSide) { + ((GuiCustom)Minecraft.getMinecraft().currentScreen).slotChange(this); + } + + super.onSlotChanged(); + } +} 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 new file mode 100644 index 000000000..879d15081 --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiTextField.java @@ -0,0 +1,80 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by FernFlower decompiler) +// + +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.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.scripted.gui.ScriptGuiTextField; +import noppes.npcs.scripted.interfaces.ICustomGuiComponent; + +public class CustomGuiTextField extends GuiTextField implements IKeyListener, IDataHolder, IClickListener { + GuiCustom parent; + String[] hoverText; + int id; + + public CustomGuiTextField(int id, int x, int y, int width, int height) { + super(Minecraft.getMinecraft().fontRenderer, GuiCustom.guiLeft + x, GuiCustom.guiTop + y, width, height); + this.id = id; + this.setMaxStringLength(500); + } + + public void keyTyped(char typedChar, int keyCode) { + this.textboxKeyTyped(typedChar, keyCode); + } + + public void onRender(Minecraft mc, int mouseX, int mouseY, int mouseWheel, float partialTicks) { + boolean hovered = mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height; + this.drawTextBox(); + if (hovered && this.hoverText != null && this.hoverText.length > 0) { + this.parent.hoverText = this.hoverText; + } + } + + public void setParent(GuiCustom parent) { + this.parent = parent; + } + + public int getID() { + return this.id; + } + + public NBTTagCompound toNBT() { + NBTTagCompound tag = new NBTTagCompound(); + tag.setInteger("id", this.id); + tag.setString("text", this.getText()); + return tag; + } + + public ICustomGuiComponent toComponent() { + ScriptGuiTextField component = new ScriptGuiTextField(this.id, this.xPosition - GuiCustom.guiLeft, this.yPosition - GuiCustom.guiTop, this.width, this.height); + component.setText(this.getText()); + component.setHoverText(this.hoverText); + return component; + } + + public static CustomGuiTextField fromComponent(ScriptGuiTextField component) { + CustomGuiTextField txt = new CustomGuiTextField(component.getID(), component.getPosX(), component.getPosY(), component.getWidth(), component.getHeight()); + if (component.hasHoverText()) { + txt.hoverText = component.getHoverText(); + } + + if (component.getText() != null && !component.getText().isEmpty()) { + txt.setText(component.getText()); + } + + return txt; + } + + public boolean mouseClicked(GuiCustom gui, int mouseX, int mouseY, int mouseButton) { + 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 new file mode 100644 index 000000000..f8d749340 --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiTexturedRect.java @@ -0,0 +1,88 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by FernFlower decompiler) +// + +package noppes.npcs.client.gui.custom.components; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Gui; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.util.ResourceLocation; +import noppes.npcs.client.gui.custom.GuiCustom; +import noppes.npcs.client.gui.custom.interfaces.IGuiComponent; +import noppes.npcs.scripted.gui.ScriptGuiTexturedRect; +import noppes.npcs.scripted.interfaces.ICustomGuiComponent; +import org.lwjgl.opengl.GL11; + +public class CustomGuiTexturedRect extends Gui implements IGuiComponent { + GuiCustom parent; + ResourceLocation texture; + int id; + int x; + int y; + int width; + int height; + int textureX; + int textureY; + float scale; + String[] hoverText; + + public CustomGuiTexturedRect(int id, String texture, int x, int y, int width, int height) { + this(id, texture, x, y, width, height, 0, 0); + } + + public CustomGuiTexturedRect(int id, String texture, int x, int y, int width, int height, int textureX, int textureY) { + this.scale = 1.0F; + this.id = id; + this.texture = new ResourceLocation(texture); + this.x = GuiCustom.guiLeft + x; + this.y = GuiCustom.guiTop + y; + this.width = width; + this.height = height; + this.textureX = textureX; + this.textureY = textureY; + } + + public void setParent(GuiCustom parent) { + this.parent = parent; + } + + public int getID() { + return this.id; + } + + public void onRender(Minecraft mc, int mouseX, int mouseY, int mouseWheel, float partialTicks) { + 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)); + + if (hovered && this.hoverText != null && this.hoverText.length > 0) { + this.parent.hoverText = this.hoverText; + } + } + + public ICustomGuiComponent toComponent() { + ScriptGuiTexturedRect component = new ScriptGuiTexturedRect(this.id, this.texture.toString(), this.x, this.y, this.width, this.height, this.textureX, this.textureY); + component.setHoverText(this.hoverText); + component.setScale(this.scale); + return component; + } + + public static CustomGuiTexturedRect fromComponent(ScriptGuiTexturedRect component) { + CustomGuiTexturedRect rect; + if (component.getTextureX() >= 0 && component.getTextureY() >= 0) { + rect = new CustomGuiTexturedRect(component.getID(), component.getTexture(), component.getPosX(), component.getPosY(), component.getWidth(), component.getHeight(), component.getTextureX(), component.getTextureY()); + } else { + rect = new CustomGuiTexturedRect(component.getID(), component.getTexture(), component.getPosX(), component.getPosY(), component.getWidth(), component.getHeight()); + } + + rect.scale = component.getScale(); + if (component.hasHoverText()) { + rect.hoverText = component.getHoverText(); + } + + return rect; + } +} diff --git a/src/main/java/noppes/npcs/client/gui/custom/interfaces/IClickListener.java b/src/main/java/noppes/npcs/client/gui/custom/interfaces/IClickListener.java new file mode 100644 index 000000000..4130d438c --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/custom/interfaces/IClickListener.java @@ -0,0 +1,12 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by FernFlower decompiler) +// + +package noppes.npcs.client.gui.custom.interfaces; + +import noppes.npcs.client.gui.custom.GuiCustom; + +public interface IClickListener extends IGuiComponent { + boolean mouseClicked(GuiCustom var1, int var2, int var3, int var4); +} diff --git a/src/main/java/noppes/npcs/client/gui/custom/interfaces/IDataHolder.java b/src/main/java/noppes/npcs/client/gui/custom/interfaces/IDataHolder.java new file mode 100644 index 000000000..a49821f51 --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/custom/interfaces/IDataHolder.java @@ -0,0 +1,12 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by FernFlower decompiler) +// + +package noppes.npcs.client.gui.custom.interfaces; + +import net.minecraft.nbt.NBTTagCompound; + +public interface IDataHolder extends IGuiComponent { + NBTTagCompound toNBT(); +} diff --git a/src/main/java/noppes/npcs/client/gui/custom/interfaces/IGuiComponent.java b/src/main/java/noppes/npcs/client/gui/custom/interfaces/IGuiComponent.java new file mode 100644 index 000000000..af8f1d248 --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/custom/interfaces/IGuiComponent.java @@ -0,0 +1,17 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by FernFlower decompiler) +// + +package noppes.npcs.client.gui.custom.interfaces; + +import net.minecraft.client.Minecraft; +import noppes.npcs.scripted.interfaces.ICustomGuiComponent; + +public interface IGuiComponent { + int getID(); + + void onRender(Minecraft var1, int var2, int var3, int var4, float var5); + + ICustomGuiComponent toComponent(); +} diff --git a/src/main/java/noppes/npcs/client/gui/custom/interfaces/IKeyListener.java b/src/main/java/noppes/npcs/client/gui/custom/interfaces/IKeyListener.java new file mode 100644 index 000000000..c0d5968f2 --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/custom/interfaces/IKeyListener.java @@ -0,0 +1,10 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by FernFlower decompiler) +// + +package noppes.npcs.client.gui.custom.interfaces; + +public interface IKeyListener extends IGuiComponent { + void keyTyped(char var1, int var2); +} 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 e6328ab6b..20b2e21f6 100644 --- a/src/main/java/noppes/npcs/client/gui/script/GuiScriptInterface.java +++ b/src/main/java/noppes/npcs/client/gui/script/GuiScriptInterface.java @@ -135,6 +135,10 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb hookList.add("playSound"); hookList.add("lightning"); hookList.add("changedDim"); + hookList.add("customGuiClosed"); + hookList.add("customGuiButton"); + hookList.add("customGuiSlot"); + hookList.add("customGuiScroll"); } else if(handler instanceof ForgeDataScript) { hooks.setSize(238, 198); diff --git a/src/main/java/noppes/npcs/client/gui/util/GuiCustomScroll.java b/src/main/java/noppes/npcs/client/gui/util/GuiCustomScroll.java index 362400803..f29428838 100644 --- a/src/main/java/noppes/npcs/client/gui/util/GuiCustomScroll.java +++ b/src/main/java/noppes/npcs/client/gui/util/GuiCustomScroll.java @@ -20,7 +20,7 @@ public class GuiCustomScroll extends GuiScreen public int id; public int guiLeft = 0; public int guiTop = 0; - private int xSize, ySize; + public int xSize, ySize; public int selected; private HashSet selectedList; private int hover; diff --git a/src/main/java/noppes/npcs/constants/EnumGuiType.java b/src/main/java/noppes/npcs/constants/EnumGuiType.java index 39e728518..eb58809b6 100644 --- a/src/main/java/noppes/npcs/constants/EnumGuiType.java +++ b/src/main/java/noppes/npcs/constants/EnumGuiType.java @@ -1,5 +1,5 @@ package noppes.npcs.constants; public enum EnumGuiType { - MainMenuDisplay, MainMenuInv, MainMenuStats, ManageFactions, MainMenuAdvanced, MainMenuGlobal, PlayerBankSmall, PlayerFollowerHire, PlayerFollower, SetupItemGiver, SetupTrader, SetupFollower, PlayerTrader, PlayerTransporter, RedstoneBlock, SetupTransporter, ManageTransport, ManageBanks, MobSpawner, SetupBank, ManageDialogs, ManageQuests, PlayerAnvil, QuestReward, ManageRecipes, QuestItem, NpcRemote, ScriptEvent, MoneyBag, MainMenuAI, MovingPath, PlayerBankUnlock, PlayerBankUprade, PlayerBankLarge, MobSpawnerAdd, PlayerMailbox, PlayerMailman, Waypoint, MerchantAdd, MobSpawnerMounter, Crate, NpcDimensions, Border, BigSign, Script, Companion, CompanionInv, CompanionTalent, CompanionTrader, ManageLinked + MainMenuDisplay, MainMenuInv, MainMenuStats, ManageFactions, MainMenuAdvanced, MainMenuGlobal, PlayerBankSmall, PlayerFollowerHire, PlayerFollower, SetupItemGiver, SetupTrader, SetupFollower, PlayerTrader, PlayerTransporter, RedstoneBlock, SetupTransporter, ManageTransport, ManageBanks, MobSpawner, SetupBank, ManageDialogs, ManageQuests, PlayerAnvil, QuestReward, ManageRecipes, QuestItem, NpcRemote, ScriptEvent, MoneyBag, MainMenuAI, MovingPath, PlayerBankUnlock, PlayerBankUprade, PlayerBankLarge, MobSpawnerAdd, PlayerMailbox, PlayerMailman, Waypoint, MerchantAdd, MobSpawnerMounter, Crate, NpcDimensions, Border, BigSign, Script, Companion, CompanionInv, CompanionTalent, CompanionTrader, ManageLinked, CustomGui; } diff --git a/src/main/java/noppes/npcs/constants/EnumPacketServer.java b/src/main/java/noppes/npcs/constants/EnumPacketServer.java index 54b7bbcbf..595ccb08a 100644 --- a/src/main/java/noppes/npcs/constants/EnumPacketServer.java +++ b/src/main/java/noppes/npcs/constants/EnumPacketServer.java @@ -76,7 +76,9 @@ public enum EnumPacketServer { RemoteTpToNpc,QuestGet, QuestCategoryGet, SaveTileEntity, NaturalSpawnGetAll, MailOpenSetup, - DimensionsGet, DimensionTeleport, GetTileEntity, Gui, IsGuiOpen; + DimensionsGet, DimensionTeleport, GetTileEntity, Gui, IsGuiOpen, + + CustomGuiButton,CustomGuiSlotChange,CustomGuiScrollClick,CustomGuiClose; public CustomNpcsPermissions.Permission permission = null; public boolean needsNpc = false; diff --git a/src/main/java/noppes/npcs/containers/ContainerCustomGui.java b/src/main/java/noppes/npcs/containers/ContainerCustomGui.java new file mode 100644 index 000000000..c16a4cc91 --- /dev/null +++ b/src/main/java/noppes/npcs/containers/ContainerCustomGui.java @@ -0,0 +1,103 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by FernFlower decompiler) +// + +package noppes.npcs.containers; + +import java.util.Iterator; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.Container; +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; +import noppes.npcs.scripted.interfaces.IItemSlot; +import noppes.npcs.scripted.gui.ScriptGui; +import noppes.npcs.client.gui.custom.components.CustomGuiSlot; + +public class ContainerCustomGui extends Container { + public ScriptGui customGui; + public IInventory guiInventory; + int slotCount = 0; + + public int playerInvX; + public int playerInvY; + + public ContainerCustomGui(IInventory inventory) { + this.guiInventory = inventory; + } + + public void setGui(ScriptGui gui, EntityPlayer player) { + this.customGui = gui; + + if (this.customGui.getShowPlayerInv()) { + this.addPlayerInventory(player, this.customGui.getPlayerInvX(), this.customGui.getPlayerInvY()); + } + + Iterator var3 = this.customGui.getSlots().iterator(); + + while(var3.hasNext()) { + IItemSlot slot = (IItemSlot)var3.next(); + if (slot.hasStack()) { + this.addSlot(slot.getPosX(), slot.getPosY(), slot.getStack().getMCItemStack(), player.worldObj.isRemote); + } else { + this.addSlot(slot.getPosX(), slot.getPosY(), player.worldObj.isRemote); + } + } + } + + public ItemStack transferStackInSlot(EntityPlayer playerIn, int index) { + ItemStack itemstack = null; + Slot slot = (Slot)this.inventorySlots.get(index); + if (slot != null && slot.getHasStack()) { + ItemStack itemstack1 = slot.getStack(); + itemstack = itemstack1.copy(); + if (index < this.guiInventory.getSizeInventory()) { + if (!this.mergeItemStack(itemstack1, this.guiInventory.getSizeInventory(), this.inventorySlots.size(), true)) { + return null; + } + } else if (!this.mergeItemStack(itemstack1, 0, this.guiInventory.getSizeInventory(), false)) { + return null; + } + + if (itemstack1.stackSize <= 0) { + slot.putStack(null); + } else { + slot.onSlotChanged(); + } + } + + return itemstack; + } + + void addSlot(int x, int y, boolean clientSide) { + this.addSlotToContainer(new CustomGuiSlot(this.guiInventory, this.slotCount++, x, y, clientSide)); + } + + void addSlot(int x, int y, ItemStack itemStack, boolean clientSide) { + this.guiInventory.setInventorySlotContents(this.slotCount, itemStack); + this.addSlotToContainer(new CustomGuiSlot(this.guiInventory, this.slotCount++, x, y, clientSide)); + } + + void addPlayerInventory(EntityPlayer player, int x, int y) { + this.playerInvX = x; + this.playerInvY = y; + + int row; + for(row = 0; row < 3; ++row) { + for(int col = 0; col < 9; ++col) { + this.addSlotToContainer(new Slot(player.inventory, col + row * 9 + 9, x + col * 18, y + row * 18)); + } + } + + for(row = 0; row < 9; ++row) { + this.addSlotToContainer(new Slot(player.inventory, row, x + row * 18, y + 58)); + } + } + + public boolean canInteractWith(EntityPlayer p_75145_1_) { + return true; + } + + public boolean canDragIntoSlot(Slot p_94531_1_) { return true; } +} diff --git a/src/main/java/noppes/npcs/controllers/CustomGuiController.java b/src/main/java/noppes/npcs/controllers/CustomGuiController.java new file mode 100644 index 000000000..790a1b84a --- /dev/null +++ b/src/main/java/noppes/npcs/controllers/CustomGuiController.java @@ -0,0 +1,122 @@ +package noppes.npcs.controllers; + +import io.netty.buffer.ByteBuf; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.Container; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.nbt.NBTTagString; +import noppes.npcs.CustomNpcs; +import noppes.npcs.Server; +import noppes.npcs.constants.EnumGuiType; +import noppes.npcs.constants.EnumPacketClient; +import noppes.npcs.constants.EnumScriptType; +import noppes.npcs.containers.ContainerCustomGui; +import noppes.npcs.scripted.NpcAPI; +import noppes.npcs.scripted.entity.ScriptPlayer; +import noppes.npcs.scripted.event.CustomGuiEvent; +import noppes.npcs.scripted.gui.ScriptGui; +import noppes.npcs.scripted.interfaces.IItemStack; +import noppes.npcs.scripted.wrapper.WrapperNpcAPI; + +import java.io.IOException; + +public class CustomGuiController { + public CustomGuiController() { + } + + public static void openGui(ScriptPlayer player, ScriptGui gui) { + EntityPlayerMP entityPlayerMP = (EntityPlayerMP) player.getMCEntity(); + entityPlayerMP.openGui(CustomNpcs.instance, EnumGuiType.CustomGui.ordinal(), player.getWorld().getMCWorld(), gui.getSlots().size(), 0, 0); + ((ContainerCustomGui)((EntityPlayerMP)player.getMCEntity()).openContainer).setGui(gui, (EntityPlayer)player.getMCEntity()); + Server.sendData((EntityPlayerMP)player.getMCEntity(), EnumPacketClient.GUI_DATA, new Object[]{gui.toNBT()}); + } + + public static boolean updateGui(ScriptPlayer player, ScriptGui gui) { + if (((EntityPlayerMP)player.getMCEntity()).openContainer instanceof ContainerCustomGui) { + Server.sendData((EntityPlayerMP)player.getMCEntity(), EnumPacketClient.GUI_DATA, new Object[]{gui.toNBT()}); + return true; + } else { + return false; + } + } + + static boolean checkGui(CustomGuiEvent event) { + EntityPlayer player = (EntityPlayer) event.player.getMCEntity(); + if (!(player.openContainer instanceof ContainerCustomGui)) { + return false; + } else { + return ((ContainerCustomGui)player.openContainer).customGui.getID() == event.gui.getID(); + } + } + + public static IItemStack[] getSlotContents(EntityPlayer player) { + IItemStack[] slotContents = new IItemStack[0]; + if (player.openContainer instanceof ContainerCustomGui) { + ContainerCustomGui container = (ContainerCustomGui)player.openContainer; + slotContents = new IItemStack[container.guiInventory.getSizeInventory()]; + + for(int i = 0; i < container.guiInventory.getSizeInventory(); ++i) { + slotContents[i] = NpcAPI.Instance().getIItemStack(container.guiInventory.getStackInSlot(i)); + } + } + + return slotContents; + } + + public static void onButton(CustomGuiEvent.ButtonEvent event) { + EntityPlayer player = (EntityPlayer) event.player.getMCEntity(); + if (checkGui(event) && getOpenGui(player).getScriptHandler() != null) { + getOpenGui(player).getScriptHandler().callScript(EnumScriptType.CUSTOM_GUI_BUTTON, event); + } + + WrapperNpcAPI.EVENT_BUS.post(event); + } + + public static void onSlotChange(CustomGuiEvent.SlotEvent event) { + EntityPlayer player = (EntityPlayer) event.player.getMCEntity(); + if (checkGui(event) && getOpenGui(player).getScriptHandler() != null) { + getOpenGui(player).getScriptHandler().callScript(EnumScriptType.CUSTOM_GUI_SLOT, 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) { + getOpenGui(player).getScriptHandler().callScript(EnumScriptType.CUSTOM_GUI_SCROLL, event); + } + + WrapperNpcAPI.EVENT_BUS.post(event); + } + + public static void onClose(CustomGuiEvent.CloseEvent event) { + if (ScriptController.Instance.playerScripts != null) { + ScriptController.Instance.playerScripts.callScript(EnumScriptType.CUSTOM_GUI_CLOSED, event); + } + + WrapperNpcAPI.EVENT_BUS.post(event); + } + + public static ScriptGui getOpenGui(EntityPlayer player) { + return player.openContainer instanceof ContainerCustomGui ? ((ContainerCustomGui)player.openContainer).customGui : null; + } + + public static String[] readScrollSelection(ByteBuf buffer) { + try { + NBTTagList list = Server.readNBT(buffer).getTagList("selection", 8); + String[] selection = new String[list.tagCount()]; + + for(int i = 0; i < list.tagCount(); ++i) { + selection[i] = list.getStringTagAt(i); + } + + return selection; + } catch (IOException var4) { + var4.printStackTrace(); + return null; + } + } +} diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java b/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java index b828a11ab..74530f13a 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java @@ -4,6 +4,7 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.stats.Achievement; import net.minecraft.stats.StatBase; import net.minecraft.stats.StatList; @@ -16,20 +17,17 @@ import noppes.npcs.NoppesUtilPlayer; import noppes.npcs.Server; import noppes.npcs.constants.EnumPacketClient; import noppes.npcs.constants.EnumQuestType; -import noppes.npcs.controllers.PixelmonHelper; -import noppes.npcs.controllers.PlayerData; -import noppes.npcs.controllers.PlayerDataController; -import noppes.npcs.controllers.PlayerDialogData; -import noppes.npcs.controllers.PlayerQuestData; -import noppes.npcs.controllers.Quest; -import noppes.npcs.controllers.QuestController; -import noppes.npcs.controllers.QuestData; +import noppes.npcs.containers.ContainerCustomGui; +import noppes.npcs.controllers.*; import noppes.npcs.scripted.CustomNPCsException; import noppes.npcs.scripted.NpcAPI; import noppes.npcs.scripted.ScriptItemStack; import noppes.npcs.scripted.ScriptPixelmonPlayerData; import noppes.npcs.scripted.constants.EntityType; +import noppes.npcs.scripted.gui.ScriptGui; import noppes.npcs.scripted.handler.data.IQuest; +import noppes.npcs.scripted.interfaces.IContainer; +import noppes.npcs.scripted.interfaces.ICustomGui; import noppes.npcs.scripted.interfaces.IPlayer; import noppes.npcs.scripted.interfaces.ITimers; import noppes.npcs.util.ValueUtil; @@ -440,6 +438,23 @@ public class ScriptPlayer extends ScriptLivingBase return (IQuest[])quests.toArray(new IQuest[quests.size()]); } + public IContainer getOpenContainer() { + return NpcAPI.Instance().getIContainer(((EntityPlayerMP)this.entity).openContainer); + } + + public void showCustomGui(ICustomGui gui) { + CustomGuiController.openGui(this, (ScriptGui) gui); + } + + public ICustomGui getCustomGui() { + return ((EntityPlayerMP)this.entity).openContainer instanceof ContainerCustomGui ? ((ContainerCustomGui)((EntityPlayerMP)this.entity).openContainer).customGui : null; + } + + public void closeGui() { + ((EntityPlayerMP)this.entity).closeContainer(); + Server.sendData((EntityPlayerMP)this.entity, EnumPacketClient.GUI_CLOSE, new Object[]{-1, new NBTTagCompound()}); + } + public IQuest[] getFinishedQuests() { PlayerQuestData data = this.getData().questData; List quests = new ArrayList(); diff --git a/src/main/java/noppes/npcs/scripted/event/CustomGuiEvent.java b/src/main/java/noppes/npcs/scripted/event/CustomGuiEvent.java new file mode 100644 index 000000000..5a96e3a5e --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/event/CustomGuiEvent.java @@ -0,0 +1,57 @@ +package noppes.npcs.scripted.event; + +import cpw.mods.fml.common.eventhandler.Event; +import noppes.npcs.scripted.interfaces.ICustomGui; +import noppes.npcs.scripted.interfaces.IItemStack; +import noppes.npcs.scripted.interfaces.IPlayer; + +public class CustomGuiEvent extends Event { + public final IPlayer player; + public final ICustomGui gui; + + public CustomGuiEvent(IPlayer player, ICustomGui gui) { + this.player = player; + this.gui = gui; + } + + public static class ButtonEvent extends CustomGuiEvent { + public final int buttonId; + + public ButtonEvent(IPlayer player, ICustomGui gui, int buttonId) { + super(player, gui); + this.buttonId = buttonId; + } + } + + public static class CloseEvent extends CustomGuiEvent { + public CloseEvent(IPlayer player, ICustomGui gui) { + super(player, gui); + } + } + + public static class ScrollEvent extends CustomGuiEvent { + public final int scrollId; + public final String[] selection; + public final boolean doubleClick; + public final int scrollIndex; + + public ScrollEvent(IPlayer player, ICustomGui gui, int scrollId, int scrollIndex, String[] selection, boolean doubleClick) { + super(player, gui); + this.scrollId = scrollId; + this.selection = selection; + this.doubleClick = doubleClick; + this.scrollIndex = scrollIndex; + } + } + + public static class SlotEvent extends CustomGuiEvent { + public final int slotId; + public final IItemStack stack; + + public SlotEvent(IPlayer player, ICustomGui gui, int slotId, IItemStack stack) { + super(player, gui); + this.slotId = slotId; + this.stack = stack; + } + } +} diff --git a/src/main/java/noppes/npcs/scripted/gui/ScriptGui.java b/src/main/java/noppes/npcs/scripted/gui/ScriptGui.java new file mode 100644 index 000000000..378bf3f82 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/gui/ScriptGui.java @@ -0,0 +1,298 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by FernFlower decompiler) +// + +package noppes.npcs.scripted.gui; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import net.minecraft.nbt.NBTBase; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import noppes.npcs.controllers.ScriptController; +import noppes.npcs.controllers.data.PlayerDataScript; +import noppes.npcs.scripted.interfaces.ICustomGuiComponent; +import noppes.npcs.scripted.interfaces.IPlayer; +import noppes.npcs.scripted.interfaces.IButton; +import noppes.npcs.scripted.interfaces.ICustomGui; +import noppes.npcs.scripted.interfaces.ICustomGuiComponent; +import noppes.npcs.scripted.interfaces.IItemSlot; +import noppes.npcs.scripted.interfaces.ILabel; +import noppes.npcs.scripted.interfaces.IScroll; +import noppes.npcs.scripted.interfaces.ITextField; +import noppes.npcs.scripted.interfaces.ITexturedRect; +import noppes.npcs.scripted.interfaces.IItemStack; +import noppes.npcs.scripted.entity.ScriptPlayer; +import noppes.npcs.controllers.CustomGuiController; +import noppes.npcs.controllers.ScriptContainer; +import noppes.npcs.scripted.interfaces.ICustomGui; + +public class ScriptGui implements ICustomGui { + int id; + int width; + int height; + int playerInvX; + int playerInvY; + boolean pauseGame; + boolean showPlayerInv; + String backgroundTexture = ""; + //ScriptContainer scriptHandler; + List components = new ArrayList(); + List slots = new ArrayList(); + + public ScriptGui() { + } + + public ScriptGui(int id, int width, int height, boolean pauseGame) { + this.id = id; + this.width = width; + this.height = height; + this.pauseGame = pauseGame; + //this.scriptHandler = ScriptContainer.Current; + } + + public int getID() { + return this.id; + } + + public int getWidth() { + return this.width; + } + + public int getHeight() { + return this.height; + } + + public List getComponents() { + return this.components; + } + + public List getSlots() { + return this.slots; + } + + public PlayerDataScript getScriptHandler() { + return ScriptController.Instance.playerScripts;//this.scriptHandler; + } + + public void setSize(int width, int height) { + this.width = width; + this.height = height; + } + + public void setDoesPauseGame(boolean pauseGame) { + this.pauseGame = pauseGame; + } + + public boolean getDoesPauseGame() { + return this.pauseGame; + } + + public void setBackgroundTexture(String resourceLocation) { + this.backgroundTexture = resourceLocation; + } + + public String getBackgroundTexture() { + return this.backgroundTexture; + } + + public IButton addButton(int id, String label, int x, int y) { + ScriptGuiButton component = new ScriptGuiButton(id, label, x, y); + this.components.add(component); + return (IButton)this.components.get(this.components.size() - 1); + } + + public IButton addButton(int id, String label, int x, int y, int width, int height) { + ScriptGuiButton component = new ScriptGuiButton(id, label, x, y, width, height); + this.components.add(component); + return (IButton)this.components.get(this.components.size() - 1); + } + + public IButton addTexturedButton(int id, String label, int x, int y, int width, int height, String texture) { + ScriptGuiButton component = new ScriptGuiButton(id, label, x, y, width, height, texture); + this.components.add(component); + return (IButton)this.components.get(this.components.size() - 1); + } + + public IButton addTexturedButton(int id, String label, int x, int y, int width, int height, String texture, int textureX, int textureY) { + ScriptGuiButton component = new ScriptGuiButton(id, label, x, y, width, height, texture, textureX, textureY); + this.components.add(component); + return (IButton)this.components.get(this.components.size() - 1); + } + + public ILabel addLabel(int id, String label, int x, int y, int width, int height) { + ScriptGuiLabel component = new ScriptGuiLabel(id, label, x, y, width, height); + this.components.add(component); + return (ILabel)this.components.get(this.components.size() - 1); + } + + public ILabel addLabel(int id, String label, int x, int y, int width, int height, int color) { + ScriptGuiLabel component = new ScriptGuiLabel(id, label, x, y, width, height, color); + this.components.add(component); + return (ILabel)this.components.get(this.components.size() - 1); + } + + public ITextField addTextField(int id, int x, int y, int width, int height) { + ScriptGuiTextField component = new ScriptGuiTextField(id, x, y, width, height); + this.components.add(component); + return (ITextField)this.components.get(this.components.size() - 1); + } + + public ITexturedRect addTexturedRect(int id, String texture, int x, int y, int width, int height) { + ScriptGuiTexturedRect component = new ScriptGuiTexturedRect(id, texture, x, y, width, height); + this.components.add(component); + return (ITexturedRect)this.components.get(this.components.size() - 1); + } + + public ITexturedRect addTexturedRect(int id, String texture, int x, int y, int width, int height, int textureX, int textureY) { + ScriptGuiTexturedRect component = new ScriptGuiTexturedRect(id, texture, x, y, width, height, textureX, textureY); + this.components.add(component); + return (ITexturedRect)this.components.get(this.components.size() - 1); + } + + public IItemSlot addItemSlot(int x, int y) { + ScriptGuiItemSlot slot = new ScriptGuiItemSlot(x, y); + this.slots.add(slot); + return (IItemSlot)this.slots.get(this.slots.size() - 1); + } + + public IItemSlot addItemSlot(int x, int y, IItemStack stack) { + ScriptGuiItemSlot slot = new ScriptGuiItemSlot(x, y, stack); + this.slots.add(slot); + return (IItemSlot)this.slots.get(this.slots.size() - 1); + } + + public IScroll addScroll(int id, int x, int y, int width, int height, String[] list) { + ScriptGuiScroll component = new ScriptGuiScroll(id, x, y, width, height, list); + this.components.add(component); + return (IScroll)this.components.get(this.components.size() - 1); + } + + public void showPlayerInventory(int x, int y) { + this.showPlayerInv = true; + this.playerInvX = x; + this.playerInvY = y; + } + + public ICustomGuiComponent getComponent(int componentID) { + Iterator var2 = this.components.iterator(); + + ICustomGuiComponent component; + do { + if (!var2.hasNext()) { + return null; + } + + component = (ICustomGuiComponent)var2.next(); + } while(component.getID() != componentID); + + return component; + } + + public void removeComponent(int componentID) { + for(int i = 0; i < this.components.size(); ++i) { + if (((ICustomGuiComponent)this.components.get(i)).getID() == componentID) { + this.components.remove(i); + return; + } + } + + } + + public void updateComponent(ICustomGuiComponent component) { + for(int i = 0; i < this.components.size(); ++i) { + ICustomGuiComponent c = (ICustomGuiComponent)this.components.get(i); + if (c.getID() == component.getID()) { + this.components.set(i, component); + return; + } + } + + } + + public void update(IPlayer player) { + CustomGuiController.updateGui((ScriptPlayer)player, this); + } + + public boolean getShowPlayerInv() { + return this.showPlayerInv; + } + + public int getPlayerInvX() { + return this.playerInvX; + } + + public int getPlayerInvY() { + return this.playerInvY; + } + + public ICustomGui fromNBT(NBTTagCompound tag) { + this.id = tag.getInteger("id"); + this.width = tag.getIntArray("size")[0]; + this.height = tag.getIntArray("size")[1]; + this.pauseGame = tag.getBoolean("pause"); + this.backgroundTexture = tag.getString("bgTexture"); + List components = new ArrayList(); + + NBTTagList list = tag.getTagList("components", 10); + for(int i = 0; i < list.tagCount(); i++){ + NBTBase b = list.getCompoundTagAt(i); + ScriptGuiComponent component = ScriptGuiComponent.createFromNBT((NBTTagCompound)b); + components.add(component); + } + + this.components = components; + List slots = new ArrayList(); + list = tag.getTagList("slots", 10); + + for(int i = 0; i < list.tagCount(); i++){ + NBTBase b = list.getCompoundTagAt(i); + ScriptGuiItemSlot component = (ScriptGuiItemSlot)ScriptGuiComponent.createFromNBT((NBTTagCompound)b); + slots.add(component); + } + + this.slots = slots; + this.showPlayerInv = tag.getBoolean("showPlayerInv"); + if (this.showPlayerInv) { + this.playerInvX = tag.getIntArray("pInvPos")[0]; + this.playerInvY = tag.getIntArray("pInvPos")[1]; + } + + return this; + } + + public NBTTagCompound toNBT() { + NBTTagCompound tag = new NBTTagCompound(); + tag.setInteger("id", this.id); + tag.setIntArray("size", new int[]{this.width, this.height}); + tag.setBoolean("pause", this.pauseGame); + tag.setString("bgTexture", this.backgroundTexture); + NBTTagList list = new NBTTagList(); + Iterator var3 = this.components.iterator(); + + ICustomGuiComponent c; + while(var3.hasNext()) { + c = (ICustomGuiComponent)var3.next(); + list.appendTag(((ScriptGuiComponent)c).toNBT(new NBTTagCompound())); + } + + tag.setTag("components", list); + list = new NBTTagList(); + var3 = this.slots.iterator(); + + while(var3.hasNext()) { + c = (ICustomGuiComponent)var3.next(); + list.appendTag(((ScriptGuiComponent)c).toNBT(new NBTTagCompound())); + } + + tag.setTag("slots", list); + tag.setBoolean("showPlayerInv", this.showPlayerInv); + if (this.showPlayerInv) { + tag.setIntArray("pInvPos", new int[]{this.playerInvX, this.playerInvY}); + } + + return tag; + } +} diff --git a/src/main/java/noppes/npcs/scripted/gui/ScriptGuiButton.java b/src/main/java/noppes/npcs/scripted/gui/ScriptGuiButton.java new file mode 100644 index 000000000..1ac8418ab --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/gui/ScriptGuiButton.java @@ -0,0 +1,149 @@ +package noppes.npcs.scripted.gui; + +import net.minecraft.nbt.NBTTagCompound; +import noppes.npcs.scripted.interfaces.IButton; +import noppes.npcs.scripted.interfaces.ICustomGuiComponent; + +public class ScriptGuiButton extends ScriptGuiComponent implements IButton { + int width; + int height; + String label; + String texture; + int textureX; + int textureY; + + public ScriptGuiButton() { + this.height = -1; + this.textureY = -1; + } + + public ScriptGuiButton(int id, String label, int x, int y) { + this.height = -1; + this.textureY = -1; + this.setID(id); + this.setLabel(label); + this.setPos(x, y); + } + + public ScriptGuiButton(int id, String label, int x, int y, int width, int height) { + this(id, label, x, y); + this.setSize(width, height); + } + + public ScriptGuiButton(int id, String label, int x, int y, int width, int height, String texture) { + this(id, label, x, y, width, height); + this.setTexture(texture); + } + + public ScriptGuiButton(int id, String label, int x, int y, int width, int height, String texture, int textureX, int textureY) { + this(id, label, x, y, width, height, texture); + this.setTextureOffset(textureX, textureY); + } + + public int getWidth() { + return this.width; + } + + public int getHeight() { + return this.height; + } + + public IButton setSize(int width, int height) { + this.width = width; + this.height = height; + return this; + } + + public String getLabel() { + return this.label; + } + + public IButton setLabel(String label) { + this.label = label; + return this; + } + + public String getTexture() { + return this.texture; + } + + public boolean hasTexture() { + return this.texture != null; + } + + public IButton setTexture(String texture) { + this.texture = texture; + return this; + } + + public int getTextureX() { + return this.textureX; + } + + public int getTextureY() { + return this.textureY; + } + + public IButton setTextureOffset(int textureX, int textureY) { + this.textureX = textureX; + this.textureY = textureY; + return this; + } + + public int getID() { + return this.id; + } + + public ICustomGuiComponent setID(int id) { + this.id = id; + return this; + } + + public int getPosX() { + return this.posX; + } + + public int getPosY() { + return this.posY; + } + + public int getType() { + return 0; + } + + public NBTTagCompound toNBT(NBTTagCompound nbt) { + super.toNBT(nbt); + if (this.width > 0 && this.height > 0) { + nbt.setIntArray("size", new int[]{this.width, this.height}); + } + + nbt.setString("label", this.label); + if (this.hasTexture()) { + nbt.setString("texture", this.texture); + } + + if (this.textureX >= 0 && this.textureY >= 0) { + nbt.setIntArray("texPos", new int[]{this.textureX, this.textureY}); + } + + return nbt; + } + + public ScriptGuiComponent fromNBT(NBTTagCompound nbt) { + super.fromNBT(nbt); + if (nbt.hasKey("size")) { + this.setSize(nbt.getIntArray("size")[0], nbt.getIntArray("size")[1]); + } + + this.setLabel(nbt.getString("label")); + if (nbt.hasKey("texture")) { + this.setTexture(nbt.getString("texture")); + } + + if (nbt.hasKey("texPos")) { + this.setTextureOffset(nbt.getIntArray("texPos")[0], nbt.getIntArray("texPos")[1]); + } + + return this; + } +} diff --git a/src/main/java/noppes/npcs/scripted/gui/ScriptGuiComponent.java b/src/main/java/noppes/npcs/scripted/gui/ScriptGuiComponent.java new file mode 100644 index 000000000..4d218b0db --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/gui/ScriptGuiComponent.java @@ -0,0 +1,119 @@ +package noppes.npcs.scripted.gui; + +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.nbt.NBTTagString; +import noppes.npcs.scripted.interfaces.ICustomGuiComponent; + +public abstract class ScriptGuiComponent implements ICustomGuiComponent { + int id; + int posX; + int posY; + String[] hoverText; + + public ScriptGuiComponent() { + } + + public int getID() { + return this.id; + } + + public ICustomGuiComponent setID(int id) { + this.id = id; + return this; + } + + public int getPosX() { + return this.posX; + } + + public int getPosY() { + return this.posY; + } + + public ICustomGuiComponent setPos(int x, int y) { + this.posX = x; + this.posY = y; + return this; + } + + public boolean hasHoverText() { + return this.hoverText != null && this.hoverText.length > 0; + } + + public String[] getHoverText() { + return this.hoverText; + } + + public ICustomGuiComponent setHoverText(String text) { + this.hoverText = new String[]{text}; + return this; + } + + public ICustomGuiComponent setHoverText(String[] text) { + this.hoverText = text; + return this; + } + + public abstract int getType(); + + public NBTTagCompound toNBT(NBTTagCompound nbt) { + nbt.setInteger("id", this.id); + nbt.setIntArray("pos", new int[]{this.posX, this.posY}); + if (this.hoverText != null) { + NBTTagList list = new NBTTagList(); + String[] var3 = this.hoverText; + int var4 = var3.length; + + for(int var5 = 0; var5 < var4; ++var5) { + String s = var3[var5]; + if (s != null && !s.isEmpty()) { + list.appendTag(new NBTTagString(s)); + } + } + + if (list.tagCount() > 0) { + nbt.setTag("hover", list); + } + } + + nbt.setInteger("type", this.getType()); + return nbt; + } + + public ScriptGuiComponent fromNBT(NBTTagCompound nbt) { + this.setID(nbt.getInteger("id")); + this.setPos(nbt.getIntArray("pos")[0], nbt.getIntArray("pos")[1]); + if (nbt.hasKey("hover")) { + NBTTagList list = nbt.getTagList("hover", 8); + String[] hoverText = new String[list.tagCount()]; + + for(int i = 0; i < list.tagCount(); ++i) { + hoverText[i] = list.getStringTagAt(i); + } + + this.setHoverText(hoverText); + } + + return this; + } + + public static ScriptGuiComponent createFromNBT(NBTTagCompound nbt) { + switch(nbt.getInteger("type")) { + case 0: + return (new ScriptGuiButton()).fromNBT(nbt); + case 1: + return (new ScriptGuiLabel()).fromNBT(nbt); + case 2: + return (new ScriptGuiTexturedRect()).fromNBT(nbt); + case 3: + return (new ScriptGuiTextField()).fromNBT(nbt); + case 4: + return (new ScriptGuiScroll()).fromNBT(nbt); + case 5: + return (new ScriptGuiItemSlot()).fromNBT(nbt); + default: + return null; + } + } +} diff --git a/src/main/java/noppes/npcs/scripted/gui/ScriptGuiItemSlot.java b/src/main/java/noppes/npcs/scripted/gui/ScriptGuiItemSlot.java new file mode 100644 index 000000000..68c81abdf --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/gui/ScriptGuiItemSlot.java @@ -0,0 +1,63 @@ +package noppes.npcs.scripted.gui; + +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import noppes.npcs.scripted.NpcAPI; +import noppes.npcs.scripted.interfaces.IItemSlot; +import noppes.npcs.scripted.interfaces.IItemStack; + +public class ScriptGuiItemSlot extends ScriptGuiComponent implements IItemSlot { + IItemStack stack; + + public ScriptGuiItemSlot() { + } + + public ScriptGuiItemSlot(int x, int y) { + this.setPos(x, y); + } + + public ScriptGuiItemSlot(int x, int y, IItemStack stack) { + this(x, y); + this.setStack(stack); + } + + public boolean hasStack() { + return this.stack != null && this.stack.getStackSize() > 0; + } + + public IItemStack getStack() { + return this.stack; + } + + public IItemSlot setStack(IItemStack itemStack) { + this.stack = itemStack; + return this; + } + + public Slot getMCSlot() { + return null; + } + + public int getType() { + return 5; + } + + public NBTTagCompound toNBT(NBTTagCompound nbt) { + super.toNBT(nbt); + if (this.hasStack()) { + nbt.setTag("stack", this.stack.getItemNbt().getMCNBT()); + } + + return nbt; + } + + public ScriptGuiComponent fromNBT(NBTTagCompound nbt) { + super.fromNBT(nbt); + if (nbt.hasKey("stack")) { + this.setStack(NpcAPI.Instance().getIItemStack(ItemStack.loadItemStackFromNBT(nbt.getCompoundTag("stack")))); + } + + return this; + } +} diff --git a/src/main/java/noppes/npcs/scripted/gui/ScriptGuiLabel.java b/src/main/java/noppes/npcs/scripted/gui/ScriptGuiLabel.java new file mode 100644 index 000000000..fb2d22609 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/gui/ScriptGuiLabel.java @@ -0,0 +1,94 @@ +package noppes.npcs.scripted.gui; + +import net.minecraft.nbt.NBTTagCompound; +import noppes.npcs.scripted.interfaces.ILabel; + +public class ScriptGuiLabel extends ScriptGuiComponent implements ILabel { + String label; + int width; + int height; + int color; + float scale; + + public ScriptGuiLabel() { + this.color = 16777215; + this.scale = 1.0F; + } + + public ScriptGuiLabel(int id, String label, int x, int y, int width, int height) { + this.color = 16777215; + this.scale = 1.0F; + this.setID(id); + this.setText(label); + this.setPos(x, y); + this.setSize(width, height); + } + + public ScriptGuiLabel(int id, String label, int x, int y, int width, int height, int color) { + this(id, label, x, y, width, height); + this.setColor(color); + } + + public String getText() { + return this.label; + } + + public ILabel setText(String label) { + this.label = label; + return this; + } + + public int getWidth() { + return this.width; + } + + public int getHeight() { + return this.height; + } + + public ILabel setSize(int width, int height) { + this.width = width; + this.height = height; + return this; + } + + public int getColor() { + return this.color; + } + + public ILabel setColor(int color) { + this.color = color; + return this; + } + + public float getScale() { + return this.scale; + } + + public ILabel setScale(float scale) { + this.scale = scale; + return this; + } + + public int getType() { + return 1; + } + + public NBTTagCompound toNBT(NBTTagCompound nbt) { + super.toNBT(nbt); + nbt.setString("label", this.label); + nbt.setIntArray("size", new int[]{this.width, this.height}); + nbt.setInteger("color", this.color); + nbt.setFloat("scale", this.scale); + return nbt; + } + + public ScriptGuiComponent fromNBT(NBTTagCompound nbt) { + super.fromNBT(nbt); + this.setText(nbt.getString("label")); + this.setSize(nbt.getIntArray("size")[0], nbt.getIntArray("size")[1]); + this.setColor(nbt.getInteger("color")); + this.setScale(nbt.getFloat("scale")); + return this; + } +} diff --git a/src/main/java/noppes/npcs/scripted/gui/ScriptGuiScroll.java b/src/main/java/noppes/npcs/scripted/gui/ScriptGuiScroll.java new file mode 100644 index 000000000..d06b0bcae --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/gui/ScriptGuiScroll.java @@ -0,0 +1,109 @@ +package noppes.npcs.scripted.gui; + +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.nbt.NBTTagString; +import noppes.npcs.scripted.interfaces.IScroll; + +public class ScriptGuiScroll extends ScriptGuiComponent implements IScroll { + int width; + int height; + int defaultSelection = -1; + String[] list; + boolean multiSelect = false; + + public ScriptGuiScroll() { + } + + public ScriptGuiScroll(int id, int x, int y, int width, int height, String[] list) { + this.setID(id); + this.setPos(x, y); + this.setSize(width, height); + this.setList(list); + } + + public int getWidth() { + return this.width; + } + + public int getHeight() { + return this.height; + } + + public IScroll setSize(int width, int height) { + this.width = width; + this.height = height; + return this; + } + + public String[] getList() { + return this.list; + } + + public IScroll setList(String[] list) { + this.list = list; + return this; + } + + public int getDefaultSelection() { + return this.defaultSelection; + } + + public IScroll setDefaultSelection(int defaultSelection) { + this.defaultSelection = defaultSelection; + return this; + } + + public boolean isMultiSelect() { + return this.multiSelect; + } + + public IScroll setMultiSelect(boolean multiSelect) { + this.multiSelect = multiSelect; + return this; + } + + public int getType() { + return 4; + } + + public NBTTagCompound toNBT(NBTTagCompound nbt) { + super.toNBT(nbt); + nbt.setIntArray("size", new int[]{this.width, this.height}); + if (this.defaultSelection >= 0) { + nbt.setInteger("default", this.defaultSelection); + } + + NBTTagList list = new NBTTagList(); + String[] var3 = this.list; + int var4 = var3.length; + + for(int var5 = 0; var5 < var4; ++var5) { + String s = var3[var5]; + list.appendTag(new NBTTagString(s)); + } + + nbt.setTag("list", list); + nbt.setBoolean("multiSelect", this.multiSelect); + return nbt; + } + + public ScriptGuiComponent fromNBT(NBTTagCompound nbt) { + super.fromNBT(nbt); + this.setSize(nbt.getIntArray("size")[0], nbt.getIntArray("size")[1]); + if (nbt.hasKey("default")) { + this.setDefaultSelection(nbt.getInteger("default")); + } + + NBTTagList tagList = nbt.getTagList("list", 8); + String[] list = new String[tagList.tagCount()]; + + for(int i = 0; i < tagList.tagCount(); ++i) { + list[i] = tagList.getStringTagAt(i); + } + + this.setList(list); + this.setMultiSelect(nbt.getBoolean("multiSelect")); + return this; + } +} diff --git a/src/main/java/noppes/npcs/scripted/gui/ScriptGuiTextField.java b/src/main/java/noppes/npcs/scripted/gui/ScriptGuiTextField.java new file mode 100644 index 000000000..a492047cc --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/gui/ScriptGuiTextField.java @@ -0,0 +1,66 @@ +package noppes.npcs.scripted.gui; + +import net.minecraft.nbt.NBTTagCompound; +import noppes.npcs.scripted.interfaces.ITextField; + +public class ScriptGuiTextField extends ScriptGuiComponent implements ITextField { + int width; + int height; + String defaultText; + + public ScriptGuiTextField() { + } + + public ScriptGuiTextField(int id, int x, int y, int width, int height) { + this.setID(id); + this.setPos(x, y); + this.setSize(width, height); + } + + public int getWidth() { + return this.width; + } + + public int getHeight() { + return this.height; + } + + public ITextField setSize(int width, int height) { + this.width = width; + this.height = height; + return this; + } + + public String getText() { + return this.defaultText; + } + + public ITextField setText(String defaultText) { + this.defaultText = defaultText; + return this; + } + + public int getType() { + return 3; + } + + public NBTTagCompound toNBT(NBTTagCompound nbt) { + super.toNBT(nbt); + nbt.setIntArray("size", new int[]{this.width, this.height}); + if (this.defaultText != null && !this.defaultText.isEmpty()) { + nbt.setString("default", this.defaultText); + } + + return nbt; + } + + public ScriptGuiComponent fromNBT(NBTTagCompound nbt) { + super.fromNBT(nbt); + this.setSize(nbt.getIntArray("size")[0], nbt.getIntArray("size")[1]); + if (nbt.hasKey("default")) { + this.setText(nbt.getString("default")); + } + + return this; + } +} diff --git a/src/main/java/noppes/npcs/scripted/gui/ScriptGuiTexturedRect.java b/src/main/java/noppes/npcs/scripted/gui/ScriptGuiTexturedRect.java new file mode 100644 index 000000000..3ea0024db --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/gui/ScriptGuiTexturedRect.java @@ -0,0 +1,107 @@ +package noppes.npcs.scripted.gui; + +import net.minecraft.nbt.NBTTagCompound; +import noppes.npcs.client.gui.custom.GuiCustom; +import noppes.npcs.scripted.interfaces.ITexturedRect; + +public class ScriptGuiTexturedRect extends ScriptGuiComponent implements ITexturedRect { + int width; + int height; + int textureX; + int textureY; + float scale; + String texture; + + public ScriptGuiTexturedRect() { + this.textureY = -1; + this.scale = 1.0F; + } + + public ScriptGuiTexturedRect(int id, String texture, int x, int y, int width, int height) { + this.textureY = -1; + this.scale = 1.0F; + this.setID(id); + this.setTexture(texture); + this.setPos(GuiCustom.guiLeft + x, GuiCustom.guiTop + 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.setTextureOffset(textureX, textureY); + } + + public String getTexture() { + return this.texture; + } + + public ITexturedRect setTexture(String texture) { + this.texture = texture; + return this; + } + + public int getWidth() { + return this.width; + } + + public int getHeight() { + return this.height; + } + + public ITexturedRect setSize(int width, int height) { + this.width = width; + this.height = height; + return this; + } + + public float getScale() { + return this.scale; + } + + public ITexturedRect setScale(float scale) { + this.scale = scale; + return this; + } + + public int getTextureX() { + return this.textureX; + } + + public int getTextureY() { + return this.textureY; + } + + public ITexturedRect setTextureOffset(int offsetX, int offsetY) { + this.textureX = offsetX; + this.textureY = offsetY; + return this; + } + + public int getType() { + return 2; + } + + public NBTTagCompound toNBT(NBTTagCompound nbt) { + super.toNBT(nbt); + nbt.setIntArray("size", new int[]{this.width, this.height}); + nbt.setFloat("scale", this.scale); + nbt.setString("texture", this.texture); + if (this.textureX >= 0 && this.textureY >= 0) { + nbt.setIntArray("texPos", new int[]{this.textureX, this.textureY}); + } + + return nbt; + } + + public ScriptGuiComponent fromNBT(NBTTagCompound nbt) { + super.fromNBT(nbt); + this.setSize(nbt.getIntArray("size")[0], nbt.getIntArray("size")[1]); + this.setScale(nbt.getFloat("scale")); + this.setTexture(nbt.getString("texture")); + if (nbt.hasKey("texPos")) { + this.setTextureOffset(nbt.getIntArray("texPos")[0], nbt.getIntArray("texPos")[1]); + } + + return this; + } +} diff --git a/src/main/java/noppes/npcs/scripted/interfaces/IButton.java b/src/main/java/noppes/npcs/scripted/interfaces/IButton.java new file mode 100644 index 000000000..06252a0a8 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/interfaces/IButton.java @@ -0,0 +1,30 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by FernFlower decompiler) +// + +package noppes.npcs.scripted.interfaces; + +public interface IButton extends ICustomGuiComponent { + int getWidth(); + + int getHeight(); + + IButton setSize(int var1, int var2); + + String getLabel(); + + IButton setLabel(String var1); + + String getTexture(); + + boolean hasTexture(); + + IButton setTexture(String var1); + + int getTextureX(); + + int getTextureY(); + + IButton setTextureOffset(int var1, int var2); +} diff --git a/src/main/java/noppes/npcs/scripted/interfaces/ICustomGui.java b/src/main/java/noppes/npcs/scripted/interfaces/ICustomGui.java new file mode 100644 index 000000000..02f6a958e --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/interfaces/ICustomGui.java @@ -0,0 +1,60 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by FernFlower decompiler) +// + +package noppes.npcs.scripted.interfaces; + +import java.util.List; + +public interface ICustomGui { + int getID(); + + int getWidth(); + + int getHeight(); + + List getComponents(); + + List getSlots(); + + void setSize(int var1, int var2); + + void setDoesPauseGame(boolean var1); + + void setBackgroundTexture(String var1); + + IButton addButton(int var1, String var2, int var3, int var4); + + IButton addButton(int var1, String var2, int var3, int var4, int var5, int var6); + + IButton addTexturedButton(int var1, String var2, int var3, int var4, int var5, int var6, String var7); + + IButton addTexturedButton(int var1, String var2, int var3, int var4, int var5, int var6, String var7, int var8, int var9); + + ILabel addLabel(int var1, String var2, int var3, int var4, int var5, int var6); + + ILabel addLabel(int var1, String var2, int var3, int var4, int var5, int var6, int var7); + + ITextField addTextField(int var1, int var2, int var3, int var4, int var5); + + ITexturedRect addTexturedRect(int var1, String var2, int var3, int var4, int var5, int var6); + + ITexturedRect addTexturedRect(int var1, String var2, int var3, int var4, int var5, int var6, int var7, int var8); + + IScroll addScroll(int var1, int var2, int var3, int var4, int var5, String[] var6); + + IItemSlot addItemSlot(int var1, int var2); + + IItemSlot addItemSlot(int var1, int var2, IItemStack var3); + + void showPlayerInventory(int var1, int var2); + + ICustomGuiComponent getComponent(int var1); + + void removeComponent(int var1); + + void updateComponent(ICustomGuiComponent var1); + + void update(IPlayer var1); +} diff --git a/src/main/java/noppes/npcs/scripted/interfaces/ICustomGuiComponent.java b/src/main/java/noppes/npcs/scripted/interfaces/ICustomGuiComponent.java new file mode 100644 index 000000000..b7f6474c9 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/interfaces/ICustomGuiComponent.java @@ -0,0 +1,26 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by FernFlower decompiler) +// + +package noppes.npcs.scripted.interfaces; + +public interface ICustomGuiComponent { + int getID(); + + ICustomGuiComponent setID(int var1); + + int getPosX(); + + int getPosY(); + + ICustomGuiComponent setPos(int var1, int var2); + + boolean hasHoverText(); + + String[] getHoverText(); + + ICustomGuiComponent setHoverText(String var1); + + ICustomGuiComponent setHoverText(String[] var1); +} diff --git a/src/main/java/noppes/npcs/scripted/interfaces/IItemSlot.java b/src/main/java/noppes/npcs/scripted/interfaces/IItemSlot.java new file mode 100644 index 000000000..8fbca6779 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/interfaces/IItemSlot.java @@ -0,0 +1,18 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by FernFlower decompiler) +// + +package noppes.npcs.scripted.interfaces; + +import net.minecraft.inventory.Slot; + +public interface IItemSlot extends ICustomGuiComponent { + boolean hasStack(); + + IItemStack getStack(); + + IItemSlot setStack(IItemStack var1); + + Slot getMCSlot(); +} diff --git a/src/main/java/noppes/npcs/scripted/interfaces/ILabel.java b/src/main/java/noppes/npcs/scripted/interfaces/ILabel.java new file mode 100644 index 000000000..6e3b00e99 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/interfaces/ILabel.java @@ -0,0 +1,26 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by FernFlower decompiler) +// + +package noppes.npcs.scripted.interfaces; + +public interface ILabel extends ICustomGuiComponent { + String getText(); + + ILabel setText(String var1); + + int getWidth(); + + int getHeight(); + + ILabel setSize(int var1, int var2); + + int getColor(); + + ILabel setColor(int var1); + + float getScale(); + + ILabel setScale(float var1); +} diff --git a/src/main/java/noppes/npcs/scripted/interfaces/IScroll.java b/src/main/java/noppes/npcs/scripted/interfaces/IScroll.java new file mode 100644 index 000000000..3f1a76fd2 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/interfaces/IScroll.java @@ -0,0 +1,26 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by FernFlower decompiler) +// + +package noppes.npcs.scripted.interfaces; + +public interface IScroll extends ICustomGuiComponent { + int getWidth(); + + int getHeight(); + + IScroll setSize(int var1, int var2); + + String[] getList(); + + IScroll setList(String[] var1); + + int getDefaultSelection(); + + IScroll setDefaultSelection(int var1); + + boolean isMultiSelect(); + + IScroll setMultiSelect(boolean var1); +} diff --git a/src/main/java/noppes/npcs/scripted/interfaces/ITextField.java b/src/main/java/noppes/npcs/scripted/interfaces/ITextField.java new file mode 100644 index 000000000..88c3cca63 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/interfaces/ITextField.java @@ -0,0 +1,18 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by FernFlower decompiler) +// + +package noppes.npcs.scripted.interfaces; + +public interface ITextField extends ICustomGuiComponent { + int getWidth(); + + int getHeight(); + + ITextField setSize(int var1, int var2); + + String getText(); + + ITextField setText(String var1); +} diff --git a/src/main/java/noppes/npcs/scripted/interfaces/ITexturedRect.java b/src/main/java/noppes/npcs/scripted/interfaces/ITexturedRect.java new file mode 100644 index 000000000..2d4c88cba --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/interfaces/ITexturedRect.java @@ -0,0 +1,28 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by FernFlower decompiler) +// + +package noppes.npcs.scripted.interfaces; + +public interface ITexturedRect extends ICustomGuiComponent { + String getTexture(); + + ITexturedRect setTexture(String var1); + + int getWidth(); + + int getHeight(); + + ITexturedRect setSize(int var1, int var2); + + float getScale(); + + ITexturedRect setScale(float var1); + + int getTextureX(); + + int getTextureY(); + + ITexturedRect setTextureOffset(int var1, int var2); +} diff --git a/src/main/java/noppes/npcs/scripted/wrapper/WrapperNpcAPI.java b/src/main/java/noppes/npcs/scripted/wrapper/WrapperNpcAPI.java index 16493fd11..df967b3d4 100644 --- a/src/main/java/noppes/npcs/scripted/wrapper/WrapperNpcAPI.java +++ b/src/main/java/noppes/npcs/scripted/wrapper/WrapperNpcAPI.java @@ -8,9 +8,7 @@ package noppes.npcs.scripted.wrapper; import java.io.File; import java.util.List; import java.util.Map; -import java.util.UUID; -import com.mojang.authlib.GameProfile; import cpw.mods.fml.common.eventhandler.EventBus; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLiving; @@ -31,10 +29,8 @@ import net.minecraft.util.EntityDamageSource; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraft.world.WorldServer; -import net.minecraftforge.common.util.FakePlayer; import noppes.npcs.CustomNpcs; import noppes.npcs.NoppesUtilServer; -import noppes.npcs.client.EntityUtil; import noppes.npcs.controllers.*; import noppes.npcs.scripted.*; import noppes.npcs.containers.ContainerNpcInterface; @@ -42,6 +38,7 @@ import noppes.npcs.entity.EntityCustomNpc; import noppes.npcs.entity.EntityNPCInterface; import noppes.npcs.scripted.ScriptContainer; import noppes.npcs.scripted.entity.*; +import noppes.npcs.scripted.gui.ScriptGui; import noppes.npcs.scripted.handler.*; import noppes.npcs.scripted.interfaces.*; import noppes.npcs.util.JsonException; @@ -271,4 +268,8 @@ public class WrapperNpcAPI extends NpcAPI { public int getServerTime() { return MinecraftServer.getServer().getTickCounter(); } + + public ICustomGui createCustomGui(int id, int width, int height, boolean pauseGame) { + return new ScriptGui(id, width, height, pauseGame); + } }