summaryrefslogtreecommitdiff
path: root/src/main/java/gmail/Lance5057/gui
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/gmail/Lance5057/gui')
-rw-r--r--src/main/java/gmail/Lance5057/gui/Container_CrestMount.java88
-rw-r--r--src/main/java/gmail/Lance5057/gui/GuiHandler_CrestMount.java32
-rw-r--r--src/main/java/gmail/Lance5057/gui/Gui_CrestMount.java28
3 files changed, 148 insertions, 0 deletions
diff --git a/src/main/java/gmail/Lance5057/gui/Container_CrestMount.java b/src/main/java/gmail/Lance5057/gui/Container_CrestMount.java
new file mode 100644
index 0000000..8db0940
--- /dev/null
+++ b/src/main/java/gmail/Lance5057/gui/Container_CrestMount.java
@@ -0,0 +1,88 @@
+package gmail.Lance5057.gui;
+
+import gmail.Lance5057.blocks.TileEntity_CrestMount;
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.entity.player.InventoryPlayer;
+import net.minecraft.inventory.Container;
+import net.minecraft.inventory.Slot;
+import net.minecraft.item.ItemStack;
+
+public class Container_CrestMount extends Container
+{
+ protected TileEntity_CrestMount tileEntity;
+
+ public Container_CrestMount (InventoryPlayer inventoryPlayer, TileEntity_CrestMount te){
+ tileEntity = te;
+ te.openInventory();
+
+ //the Slot constructor takes the IInventory and the slot number in that it binds to
+ //and the x-y coordinates it resides on-screen
+ for (int i = 0; i < 4; i++) {
+ addSlotToContainer(new Slot(tileEntity, i, 62 + 18, 17 + i * 18));
+ }
+
+ //commonly used vanilla code that adds the player's inventory
+ bindPlayerInventory(inventoryPlayer);
+ }
+
+ protected void bindPlayerInventory(InventoryPlayer inventoryPlayer) {
+ for (int i = 0; i < 3; i++) {
+ for (int j = 0; j < 9; j++) {
+ addSlotToContainer(new Slot(inventoryPlayer, j + i * 9 + 9,
+ 8 + j * 18, 84 + i * 18));
+ }
+ }
+
+ for (int i = 0; i < 9; i++) {
+ addSlotToContainer(new Slot(inventoryPlayer, i, 8 + i * 18, 142));
+ }
+}
+
+ @Override
+ public boolean canInteractWith(EntityPlayer p_75145_1_) {
+ return tileEntity.isUseableByPlayer(p_75145_1_);
+ }
+
+ @Override
+ public ItemStack transferStackInSlot(EntityPlayer player, int slot) {
+ ItemStack stack = null;
+ Slot slotObject = (Slot) inventorySlots.get(slot);
+
+ //null checks and checks if the item can be stacked (maxStackSize > 1)
+ if (slotObject != null && slotObject.getHasStack()) {
+ ItemStack stackInSlot = slotObject.getStack();
+ stack = stackInSlot.copy();
+
+ //merges the item into player inventory since its in the tileEntity
+ if (slot < 4) {
+ if (!this.mergeItemStack(stackInSlot, 0, 35, true)) {
+ return null;
+ }
+ }
+ //places it into the tileEntity is possible since its in the player inventory
+ else if (!this.mergeItemStack(stackInSlot, 0, 4, false)) {
+ return null;
+ }
+
+ if (stackInSlot.stackSize == 0) {
+ slotObject.putStack(null);
+ } else {
+ slotObject.onSlotChanged();
+ }
+
+ if (stackInSlot.stackSize == stack.stackSize) {
+ return null;
+ }
+ slotObject.onPickupFromSlot(player, stackInSlot);
+ }
+ return stack;
+ }
+
+ @Override
+ public void onContainerClosed(EntityPlayer entityplayer)
+ {
+ super.onContainerClosed(entityplayer);
+ tileEntity.closeInventory();
+ }
+
+}
diff --git a/src/main/java/gmail/Lance5057/gui/GuiHandler_CrestMount.java b/src/main/java/gmail/Lance5057/gui/GuiHandler_CrestMount.java
new file mode 100644
index 0000000..604f088
--- /dev/null
+++ b/src/main/java/gmail/Lance5057/gui/GuiHandler_CrestMount.java
@@ -0,0 +1,32 @@
+package gmail.Lance5057.gui;
+
+import gmail.Lance5057.blocks.TileEntity_CrestMount;
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.tileentity.TileEntity;
+import net.minecraft.world.World;
+import cpw.mods.fml.common.network.IGuiHandler;
+
+public class GuiHandler_CrestMount implements IGuiHandler {
+ //returns an instance of the Container you made earlier
+ @Override
+ public Object getServerGuiElement(int id, EntityPlayer player, World world,
+ int x, int y, int z) {
+ TileEntity tileEntity = world.getTileEntity(x, y, z);
+ if(tileEntity instanceof TileEntity_CrestMount){
+ return new Container_CrestMount(player.inventory, (TileEntity_CrestMount) tileEntity);
+ }
+ return null;
+ }
+
+ //returns an instance of the Gui you made earlier
+ @Override
+ public Object getClientGuiElement(int id, EntityPlayer player, World world,
+ int x, int y, int z) {
+ TileEntity tileEntity = world.getTileEntity(x, y, z);
+ if(tileEntity instanceof TileEntity_CrestMount){
+ return new Gui_CrestMount((Container_CrestMount) new Container_CrestMount(player.inventory, new TileEntity_CrestMount()));
+ }
+ return null;
+
+ }
+}
diff --git a/src/main/java/gmail/Lance5057/gui/Gui_CrestMount.java b/src/main/java/gmail/Lance5057/gui/Gui_CrestMount.java
new file mode 100644
index 0000000..221f5c1
--- /dev/null
+++ b/src/main/java/gmail/Lance5057/gui/Gui_CrestMount.java
@@ -0,0 +1,28 @@
+package gmail.Lance5057.gui;
+
+import org.lwjgl.opengl.GL11;
+
+import gmail.Lance5057.blocks.TileEntity_CrestMount;
+import net.minecraft.client.gui.inventory.GuiContainer;
+import net.minecraft.entity.player.InventoryPlayer;
+import net.minecraft.util.ResourceLocation;
+
+public class Gui_CrestMount extends GuiContainer {
+
+ private ResourceLocation RL = new ResourceLocation("tinkersdefense", "textures/gui/inv_crestmount.png");
+
+ public Gui_CrestMount(Container_CrestMount container) {
+ super(container);
+ }
+
+ @Override
+ protected void drawGuiContainerBackgroundLayer(float p_146976_1_,
+ int p_146976_2_, int p_146976_3_) {
+ this.mc.renderEngine.bindTexture(RL);
+ int x = (width - xSize) / 2;
+ int y = (height - ySize) / 2;
+ this.drawTexturedModalRect(x, y, 0, 0, xSize, ySize);
+
+ }
+
+}