From 311ab89f93558233a40079f7cb16605b141b5346 Mon Sep 17 00:00:00 2001 From: Johann Bernhardt Date: Sun, 12 Dec 2021 19:38:06 +0100 Subject: Move sources and resources --- .../core/container/Container_BackpackBase.java | 208 +++++++++++ .../container/Container_CircuitProgrammer.java | 190 ++++++++++ .../core/container/Container_DecayablesChest.java | 140 +++++++ .../core/container/Container_EggBox.java | 140 +++++++ .../core/container/Container_FishTrap.java | 142 +++++++ .../core/container/Container_Grindle.java | 160 ++++++++ .../core/container/Container_HeliumGenerator.java | 193 ++++++++++ .../core/container/Container_ModularityTable.java | 252 +++++++++++++ .../core/container/Container_PestKiller.java | 154 ++++++++ .../core/container/Container_ProjectTable.java | 242 ++++++++++++ .../core/container/Container_RoundRobinator.java | 246 ++++++++++++ .../core/container/Container_SuperJukebox.java | 251 +++++++++++++ .../core/container/Container_TradeTable.java | 223 +++++++++++ .../container/Container_VolumetricFlaskSetter.java | 185 +++++++++ .../core/container/Container_Workbench.java | 413 +++++++++++++++++++++ .../container/Container_WorkbenchAdvanced.java | 377 +++++++++++++++++++ .../core/container/box/LunchBoxContainer.java | 13 + .../core/container/box/MagicBagContainer.java | 13 + .../core/container/box/ToolBoxContainer.java | 15 + 19 files changed, 3557 insertions(+) create mode 100644 src/main/java/gtPlusPlus/core/container/Container_BackpackBase.java create mode 100644 src/main/java/gtPlusPlus/core/container/Container_CircuitProgrammer.java create mode 100644 src/main/java/gtPlusPlus/core/container/Container_DecayablesChest.java create mode 100644 src/main/java/gtPlusPlus/core/container/Container_EggBox.java create mode 100644 src/main/java/gtPlusPlus/core/container/Container_FishTrap.java create mode 100644 src/main/java/gtPlusPlus/core/container/Container_Grindle.java create mode 100644 src/main/java/gtPlusPlus/core/container/Container_HeliumGenerator.java create mode 100644 src/main/java/gtPlusPlus/core/container/Container_ModularityTable.java create mode 100644 src/main/java/gtPlusPlus/core/container/Container_PestKiller.java create mode 100644 src/main/java/gtPlusPlus/core/container/Container_ProjectTable.java create mode 100644 src/main/java/gtPlusPlus/core/container/Container_RoundRobinator.java create mode 100644 src/main/java/gtPlusPlus/core/container/Container_SuperJukebox.java create mode 100644 src/main/java/gtPlusPlus/core/container/Container_TradeTable.java create mode 100644 src/main/java/gtPlusPlus/core/container/Container_VolumetricFlaskSetter.java create mode 100644 src/main/java/gtPlusPlus/core/container/Container_Workbench.java create mode 100644 src/main/java/gtPlusPlus/core/container/Container_WorkbenchAdvanced.java create mode 100644 src/main/java/gtPlusPlus/core/container/box/LunchBoxContainer.java create mode 100644 src/main/java/gtPlusPlus/core/container/box/MagicBagContainer.java create mode 100644 src/main/java/gtPlusPlus/core/container/box/ToolBoxContainer.java (limited to 'src/main/java/gtPlusPlus/core/container') diff --git a/src/main/java/gtPlusPlus/core/container/Container_BackpackBase.java b/src/main/java/gtPlusPlus/core/container/Container_BackpackBase.java new file mode 100644 index 0000000000..ad76bebe81 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/container/Container_BackpackBase.java @@ -0,0 +1,208 @@ +package gtPlusPlus.core.container; + +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; + +import gtPlusPlus.core.inventories.BaseInventoryBackpack; +import gtPlusPlus.core.slots.SlotItemBackpackInv; + +public class Container_BackpackBase extends Container +{ + /** The Item Inventory for this Container, only needed if you want to reference isUseableByPlayer */ + public final BaseInventoryBackpack inventory; + + /** Using these will make transferStackInSlot easier to understand and implement + * INV_START is the index of the first slot in the Player's Inventory, so our + * BaseInventoryBackpack's number of slots (e.g. 5 slots is array indices 0-4, so start at 5) + * Notice how we don't have to remember how many slots we made? We can just use + * BaseInventoryBackpack.INV_SIZE and if we ever change it, the Container updates automatically. */ + private static final int INV_START = BaseInventoryBackpack.INV_SIZE, INV_END = INV_START+26, + HOTBAR_START = INV_END+1, HOTBAR_END = HOTBAR_START+8; + + // If you're planning to add armor slots, put those first like this: + // ARMOR_START = BaseInventoryBackpack.INV_SIZE, ARMOR_END = ARMOR_START+3, + // INV_START = ARMOR_END+1, and then carry on like above. + + public Container_BackpackBase(final EntityPlayer par1Player, final InventoryPlayer inventoryPlayer, final BaseInventoryBackpack inventoryItem) + { + this.inventory = inventoryItem; + + int i; + + // ITEM INVENTORY - you'll need to adjust the slot locations to match your texture file + // I have them set vertically in columns of 4 to the right of the player model + for (i = 0; i < BaseInventoryBackpack.INV_SIZE; ++i) + { + // You can make a custom Slot if you need different behavior, + // such as only certain item types can be put into this slot + // We made a custom slot to prevent our inventory-storing item + // from being stored within itself, but if you want to allow that and + // you followed my advice at the end of the above step, then you + // could get away with using the vanilla Slot class + this.addSlotToContainer(new SlotItemBackpackInv(this.inventory, i, 80 + (18 * (i/4)), 8 + (18*(i%4)))); + } + + // If you want, you can add ARMOR SLOTS here as well, but you need to + // make a public version of SlotArmor. I won't be doing that in this tutorial. + /* + for (i = 0; i < 4; ++i) + { + // These are the standard positions for survival inventory layout + this.addSlotToContainer(new SlotArmor(this.player, inventoryPlayer, inventoryPlayer.getSizeInventory() - 1 - i, 8, 8 + i * 18, i)); + } + */ + + // PLAYER INVENTORY - uses default locations for standard inventory texture file + for (i = 0; i < 3; ++i) + { + for (int j = 0; j < 9; ++j) + { + this.addSlotToContainer(new Slot(inventoryPlayer, j + (i * 9) + 9, 8 + (j * 18), 84 + (i * 18))); + } + } + + // PLAYER ACTION BAR - uses default locations for standard action bar texture file + for (i = 0; i < 9; ++i) + { + this.addSlotToContainer(new Slot(inventoryPlayer, i, 8 + (i * 18), 142)); + } + } + + @Override + public boolean canInteractWith(final EntityPlayer entityplayer) + { + // be sure to return the inventory's isUseableByPlayer method + // if you defined special behavior there: + return this.inventory.isUseableByPlayer(entityplayer); + } + + /** + * Called when a player shift-clicks on a slot. You must override this or you will crash when someone does that. + */ + @Override + public ItemStack transferStackInSlot(final EntityPlayer par1EntityPlayer, final int index) + { + ItemStack itemstack = null; + final Slot slot = (Slot) this.inventorySlots.get(index); + + if ((slot != null) && slot.getHasStack()) + { + final ItemStack itemstack1 = slot.getStack(); + itemstack = itemstack1.copy(); + + // If item is in our custom Inventory or armor slot + if (index < INV_START) + { + // try to place in player inventory / action bar + if (!this.mergeItemStack(itemstack1, INV_START, HOTBAR_END+1, true)) + { + return null; + } + + slot.onSlotChange(itemstack1, itemstack); + } + // Item is in inventory / hotbar, try to place in custom inventory or armor slots + else + { + /* + If your inventory only stores certain instances of Items, + you can implement shift-clicking to your inventory like this: + + // Check that the item is the right type + if (itemstack1.getItem() instanceof ItemCustom) + { + // Try to merge into your custom inventory slots + // We use 'BaseInventoryBackpack.INV_SIZE' instead of INV_START just in case + // you also add armor or other custom slots + if (!this.mergeItemStack(itemstack1, 0, BaseInventoryBackpack.INV_SIZE, false)) + { + return null; + } + } + // If you added armor slots, check them here as well: + // Item being shift-clicked is armor - try to put in armor slot + if (itemstack1.getItem() instanceof ItemArmor) + { + int type = ((ItemArmor) itemstack1.getItem()).armorType; + if (!this.mergeItemStack(itemstack1, ARMOR_START + type, ARMOR_START + type + 1, false)) + { + return null; + } + } + Otherwise, you have basically 2 choices: + 1. shift-clicking between player inventory and custom inventory + 2. shift-clicking between action bar and inventory + + Be sure to choose only ONE of the following implementations!!! + */ + /** + * Implementation number 1: Shift-click into your custom inventory + */ + if (index >= INV_START) + { + // place in custom inventory + if (!this.mergeItemStack(itemstack1, 0, INV_START, false)) + { + return null; + } + } + + /** + * Implementation number 2: Shift-click items between action bar and inventory + */ + // item is in player's inventory, but not in action bar + if ((index >= INV_START) && (index < HOTBAR_START)) + { + // place in action bar + if (!this.mergeItemStack(itemstack1, HOTBAR_START, HOTBAR_END+1, false)) + { + return null; + } + } + // item in action bar - place in player inventory + else if ((index >= HOTBAR_START) && (index < (HOTBAR_END+1))) + { + if (!this.mergeItemStack(itemstack1, INV_START, INV_END+1, false)) + { + return null; + } + } + } + + if (itemstack1.stackSize == 0) + { + slot.putStack((ItemStack) null); + } + else + { + slot.onSlotChanged(); + } + + if (itemstack1.stackSize == itemstack.stackSize) + { + return null; + } + + slot.onPickupFromSlot(par1EntityPlayer, itemstack1); + } + + return itemstack; + } + + /** + * You should override this method to prevent the player from moving the stack that + * opened the inventory, otherwise if the player moves it, the inventory will not + * be able to save properly + */ + @Override + public ItemStack slotClick(final int slot, final int button, final int flag, final EntityPlayer player) { + // this will prevent the player from interacting with the item that opened the inventory: + if ((slot >= 0) && (this.getSlot(slot) != null) && (this.getSlot(slot).getStack() == player.getHeldItem())) { + return null; + } + return super.slotClick(slot, button, flag, player); + } +} diff --git a/src/main/java/gtPlusPlus/core/container/Container_CircuitProgrammer.java b/src/main/java/gtPlusPlus/core/container/Container_CircuitProgrammer.java new file mode 100644 index 0000000000..d8ce521fb5 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/container/Container_CircuitProgrammer.java @@ -0,0 +1,190 @@ +package gtPlusPlus.core.container; + +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; +import net.minecraft.world.World; +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.inventories.InventoryCircuitProgrammer; +import gtPlusPlus.core.slots.SlotIntegratedCircuit; +import gtPlusPlus.core.slots.SlotNoInput; +import gtPlusPlus.core.tileentities.general.TileEntityCircuitProgrammer; + +public class Container_CircuitProgrammer extends Container { + + protected TileEntityCircuitProgrammer tile_entity; + public final InventoryCircuitProgrammer inventoryChest; + + private final World worldObj; + private final int posX; + private final int posY; + private final int posZ; + + public static final int SLOT_OUTPUT = 25; + + public static int StorageSlotNumber = 26; // Number of slots in storage area + public static int InventorySlotNumber = 36; // Inventory Slots (Inventory + // and Hotbar) + public static int FullSlotNumber = InventorySlotNumber + StorageSlotNumber; // All + // slots + + public Container_CircuitProgrammer(final InventoryPlayer inventory, final TileEntityCircuitProgrammer te) { + this.tile_entity = te; + this.inventoryChest = te.getInventory(); + + int var6; + int var7; + this.worldObj = te.getWorldObj(); + this.posX = te.xCoord; + this.posY = te.yCoord; + this.posZ = te.zCoord; + Logger.INFO("1"); + + int o = 0; + + // Storage Side + /*for (var6 = 0; var6 < 3; var6++) { + for (var7 = 0; var7 < 5; var7++) { + this.addSlotToContainer(new SlotIntegratedCircuit(o, this.inventoryChest, o, 44 + (var7 * 18), 15 + (var6 * 18))); + o++; + } + }*/ + + + int xStart = 8; + int yStart = 5; + + try { + //0 + this.addSlotToContainer(new SlotIntegratedCircuit(this.inventoryChest, o++, xStart, yStart)); + //1-10 + this.addSlotToContainer(new SlotIntegratedCircuit(this.inventoryChest, o++, xStart+18, yStart)); + this.addSlotToContainer(new SlotIntegratedCircuit(this.inventoryChest, o++, xStart+36, yStart)); + this.addSlotToContainer(new SlotIntegratedCircuit(this.inventoryChest, o++, xStart+54, yStart)); + this.addSlotToContainer(new SlotIntegratedCircuit(this.inventoryChest, o++, xStart+72, yStart)); + this.addSlotToContainer(new SlotIntegratedCircuit(this.inventoryChest, o++, xStart+90, yStart)); + this.addSlotToContainer(new SlotIntegratedCircuit(this.inventoryChest, o++, xStart+108, yStart)); + this.addSlotToContainer(new SlotIntegratedCircuit(this.inventoryChest, o++, xStart+18, yStart+18)); + this.addSlotToContainer(new SlotIntegratedCircuit(this.inventoryChest, o++, xStart+36, yStart+18)); + this.addSlotToContainer(new SlotIntegratedCircuit(this.inventoryChest, o++, xStart+54, yStart+18)); + this.addSlotToContainer(new SlotIntegratedCircuit(this.inventoryChest, o++, xStart+72, yStart+18)); + //11-20 + this.addSlotToContainer(new SlotIntegratedCircuit(this.inventoryChest, o++, xStart+90, yStart+18)); + this.addSlotToContainer(new SlotIntegratedCircuit(this.inventoryChest, o++, xStart+108, yStart+18)); + this.addSlotToContainer(new SlotIntegratedCircuit(this.inventoryChest, o++, xStart+18, yStart+36)); + this.addSlotToContainer(new SlotIntegratedCircuit(this.inventoryChest, o++, xStart+36, yStart+36)); + this.addSlotToContainer(new SlotIntegratedCircuit(this.inventoryChest, o++, xStart+54, yStart+36)); + this.addSlotToContainer(new SlotIntegratedCircuit(this.inventoryChest, o++, xStart+72, yStart+36)); + this.addSlotToContainer(new SlotIntegratedCircuit(this.inventoryChest, o++, xStart+90, yStart+36)); + this.addSlotToContainer(new SlotIntegratedCircuit(this.inventoryChest, o++, xStart+108, yStart+36)); + this.addSlotToContainer(new SlotIntegratedCircuit(this.inventoryChest, o++, xStart+18, yStart+54)); + this.addSlotToContainer(new SlotIntegratedCircuit(this.inventoryChest, o++, xStart+36, yStart+54)); + //21-24 + this.addSlotToContainer(new SlotIntegratedCircuit(this.inventoryChest, o++, xStart+54, yStart+54)); + this.addSlotToContainer(new SlotIntegratedCircuit(this.inventoryChest, o++, xStart+72, yStart+54)); + this.addSlotToContainer(new SlotIntegratedCircuit(this.inventoryChest, o++, xStart+90, yStart+54)); + this.addSlotToContainer(new SlotIntegratedCircuit(this.inventoryChest, o++, xStart+108, yStart+54)); + Logger.INFO("2"); + + //Add Output + this.addSlotToContainer(new SlotNoInput(this.inventoryChest, SLOT_OUTPUT, xStart+(8*18), yStart+54)); + o++; + Logger.INFO("3"); + + + + // Player Inventory + for (var6 = 0; var6 < 3; ++var6) { + for (var7 = 0; var7 < 9; ++var7) { + this.addSlotToContainer(new Slot(inventory, var7 + (var6 * 9) + 9, 8 + (var7 * 18), 84 + (var6 * 18))); + } + } + // Player Hotbar + for (var6 = 0; var6 < 9; ++var6) { + this.addSlotToContainer(new Slot(inventory, var6, 8 + (var6 * 18), 142)); + } + + + + Logger.INFO("4"); + } + catch (Throwable t) {} + + } + + @Override + public ItemStack slotClick(final int aSlotIndex, final int aMouseclick, final int aShifthold, + final EntityPlayer aPlayer) { + + if (!aPlayer.worldObj.isRemote) { + if ((aSlotIndex == 999) || (aSlotIndex == -999)) { + // Utils.LOG_WARNING("??? - "+aSlotIndex); + } + } + return super.slotClick(aSlotIndex, aMouseclick, aShifthold, aPlayer); + } + + @Override + public void onContainerClosed(final EntityPlayer par1EntityPlayer) { + super.onContainerClosed(par1EntityPlayer); + } + + @Override + public boolean canInteractWith(final EntityPlayer par1EntityPlayer) { + if (this.worldObj.getBlock(this.posX, this.posY, this.posZ) != ModBlocks.blockCircuitProgrammer) { + return false; + } + + return par1EntityPlayer.getDistanceSq(this.posX + 0.5D, this.posY + 0.5D, this.posZ + 0.5D) <= 64D; + } + + @Override + public ItemStack transferStackInSlot(final EntityPlayer par1EntityPlayer, final int par2) { + ItemStack var3 = null; + final Slot var4 = (Slot) this.inventorySlots.get(par2); + + if ((var4 != null) && var4.getHasStack()) { + final ItemStack var5 = var4.getStack(); + var3 = var5.copy(); + + /* + * if (par2 == 0) { if (!this.mergeItemStack(var5, + * InOutputSlotNumber, FullSlotNumber, true)) { return null; } + * + * var4.onSlotChange(var5, var3); } else if (par2 >= + * InOutputSlotNumber && par2 < InventoryOutSlotNumber) { if + * (!this.mergeItemStack(var5, InventoryOutSlotNumber, + * FullSlotNumber, false)) { return null; } } else if (par2 >= + * InventoryOutSlotNumber && par2 < FullSlotNumber) { if + * (!this.mergeItemStack(var5, InOutputSlotNumber, + * InventoryOutSlotNumber, false)) { return null; } } else if + * (!this.mergeItemStack(var5, InOutputSlotNumber, FullSlotNumber, + * false)) { return null; } + */ + + if (var5.stackSize == 0) { + var4.putStack((ItemStack) null); + } else { + var4.onSlotChanged(); + } + + if (var5.stackSize == var3.stackSize) { + return null; + } + + var4.onPickupFromSlot(par1EntityPlayer, var5); + } + + return var3; + } + + // Can merge Slot + @Override + public boolean func_94530_a(final ItemStack p_94530_1_, final Slot p_94530_2_) { + return super.func_94530_a(p_94530_1_, p_94530_2_); + } + +} \ No newline at end of file diff --git a/src/main/java/gtPlusPlus/core/container/Container_DecayablesChest.java b/src/main/java/gtPlusPlus/core/container/Container_DecayablesChest.java new file mode 100644 index 0000000000..5bc384cd29 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/container/Container_DecayablesChest.java @@ -0,0 +1,140 @@ +package gtPlusPlus.core.container; + +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.inventories.Inventory_DecayablesChest; +import gtPlusPlus.core.tileentities.general.TileEntityDecayablesChest; +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; +import net.minecraft.world.World; + +public class Container_DecayablesChest extends Container { + + protected TileEntityDecayablesChest tile_entity; + public final Inventory_DecayablesChest inventoryChest; + + private final World worldObj; + private final int posX; + private final int posY; + private final int posZ; + + public static int StorageSlotNumber = 15; // Number of slots in storage area + public static int InventorySlotNumber = 36; // Inventory Slots (Inventory + // and Hotbar) + public static int FullSlotNumber = InventorySlotNumber + StorageSlotNumber; // All + // slots + + private final int[] slotStorage = new int[15]; + + public Container_DecayablesChest(final InventoryPlayer inventory, final TileEntityDecayablesChest te) { + this.tile_entity = te; + this.inventoryChest = te.getInventory(); + te.openInventory(); + + int var6; + int var7; + this.worldObj = te.getWorldObj(); + this.posX = te.xCoord; + this.posY = te.yCoord; + this.posZ = te.zCoord; + + int o = 0; + + // Storage Side + for (var6 = 0; var6 < 3; var6++) { + for (var7 = 0; var7 < 5; var7++) { + this.slotStorage[o] = o; + this.addSlotToContainer(new Slot(this.inventoryChest, o++, 44 + (var7 * 18), 15 + (var6 * 18))); + } + } + + // Player Inventory + for (var6 = 0; var6 < 3; ++var6) { + for (var7 = 0; var7 < 9; ++var7) { + this.addSlotToContainer(new Slot(inventory, var7 + (var6 * 9) + 9, 8 + (var7 * 18), 84 + (var6 * 18))); + } + } + + // Player Hotbar + for (var6 = 0; var6 < 9; ++var6) { + this.addSlotToContainer(new Slot(inventory, var6, 8 + (var6 * 18), 142)); + } + + } + + @Override + public ItemStack slotClick(final int aSlotIndex, final int aMouseclick, final int aShifthold, + final EntityPlayer aPlayer) { + + if (!aPlayer.worldObj.isRemote) { + if ((aSlotIndex == 999) || (aSlotIndex == -999)) { + // Utils.LOG_WARNING("??? - "+aSlotIndex); + } + } + return super.slotClick(aSlotIndex, aMouseclick, aShifthold, aPlayer); + } + + @Override + public void onContainerClosed(final EntityPlayer par1EntityPlayer) { + super.onContainerClosed(par1EntityPlayer); + tile_entity.closeInventory(); + } + + @Override + public boolean canInteractWith(final EntityPlayer par1EntityPlayer) { + if (this.worldObj.getBlock(this.posX, this.posY, this.posZ) != ModBlocks.blockDecayablesChest) { + return false; + } + + return par1EntityPlayer.getDistanceSq(this.posX + 0.5D, this.posY + 0.5D, this.posZ + 0.5D) <= 64D; + } + + @Override + public ItemStack transferStackInSlot(final EntityPlayer par1EntityPlayer, final int par2) { + ItemStack var3 = null; + final Slot var4 = (Slot) this.inventorySlots.get(par2); + + if ((var4 != null) && var4.getHasStack()) { + final ItemStack var5 = var4.getStack(); + var3 = var5.copy(); + + /* + * if (par2 == 0) { if (!this.mergeItemStack(var5, + * InOutputSlotNumber, FullSlotNumber, true)) { return null; } + * + * var4.onSlotChange(var5, var3); } else if (par2 >= + * InOutputSlotNumber && par2 < InventoryOutSlotNumber) { if + * (!this.mergeItemStack(var5, InventoryOutSlotNumber, + * FullSlotNumber, false)) { return null; } } else if (par2 >= + * InventoryOutSlotNumber && par2 < FullSlotNumber) { if + * (!this.mergeItemStack(var5, InOutputSlotNumber, + * InventoryOutSlotNumber, false)) { return null; } } else if + * (!this.mergeItemStack(var5, InOutputSlotNumber, FullSlotNumber, + * false)) { return null; } + */ + + if (var5.stackSize == 0) { + var4.putStack((ItemStack) null); + } else { + var4.onSlotChanged(); + } + + if (var5.stackSize == var3.stackSize) { + return null; + } + + var4.onPickupFromSlot(par1EntityPlayer, var5); + } + + return var3; + } + + // Can merge Slot + @Override + public boolean func_94530_a(final ItemStack p_94530_1_, final Slot p_94530_2_) { + return super.func_94530_a(p_94530_1_, p_94530_2_); + } + +} \ No newline at end of file diff --git a/src/main/java/gtPlusPlus/core/container/Container_EggBox.java b/src/main/java/gtPlusPlus/core/container/Container_EggBox.java new file mode 100644 index 0000000000..c4396cca6f --- /dev/null +++ b/src/main/java/gtPlusPlus/core/container/Container_EggBox.java @@ -0,0 +1,140 @@ +package gtPlusPlus.core.container; + +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.inventories.Inventory_EggBox; +import gtPlusPlus.core.tileentities.general.TileEntityEggBox; +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; +import net.minecraft.world.World; + +public class Container_EggBox extends Container { + + protected TileEntityEggBox tile_entity; + public final Inventory_EggBox inventoryChest; + + private final World worldObj; + private final int posX; + private final int posY; + private final int posZ; + + public static int StorageSlotNumber = 15; // Number of slots in storage area + public static int InventorySlotNumber = 36; // Inventory Slots (Inventory + // and Hotbar) + public static int FullSlotNumber = InventorySlotNumber + StorageSlotNumber; // All + // slots + + private final int[] slotStorage = new int[15]; + + public Container_EggBox(final InventoryPlayer inventory, final TileEntityEggBox te) { + this.tile_entity = te; + this.inventoryChest = te.getInventory(); + te.openInventory(); + + int var6; + int var7; + this.worldObj = te.getWorldObj(); + this.posX = te.xCoord; + this.posY = te.yCoord; + this.posZ = te.zCoord; + + int o = 0; + + // Storage Side + for (var6 = 0; var6 < 3; var6++) { + for (var7 = 0; var7 < 5; var7++) { + this.slotStorage[o] = o; + this.addSlotToContainer(new Slot(this.inventoryChest, o++, 44 + (var7 * 18), 15 + (var6 * 18))); + } + } + + // Player Inventory + for (var6 = 0; var6 < 3; ++var6) { + for (var7 = 0; var7 < 9; ++var7) { + this.addSlotToContainer(new Slot(inventory, var7 + (var6 * 9) + 9, 8 + (var7 * 18), 84 + (var6 * 18))); + } + } + + // Player Hotbar + for (var6 = 0; var6 < 9; ++var6) { + this.addSlotToContainer(new Slot(inventory, var6, 8 + (var6 * 18), 142)); + } + + } + + @Override + public ItemStack slotClick(final int aSlotIndex, final int aMouseclick, final int aShifthold, + final EntityPlayer aPlayer) { + + if (!aPlayer.worldObj.isRemote) { + if ((aSlotIndex == 999) || (aSlotIndex == -999)) { + // Utils.LOG_WARNING("??? - "+aSlotIndex); + } + } + return super.slotClick(aSlotIndex, aMouseclick, aShifthold, aPlayer); + } + + @Override + public void onContainerClosed(final EntityPlayer par1EntityPlayer) { + super.onContainerClosed(par1EntityPlayer); + tile_entity.closeInventory(); + } + + @Override + public boolean canInteractWith(final EntityPlayer par1EntityPlayer) { + if (this.worldObj.getBlock(this.posX, this.posY, this.posZ) != ModBlocks.blockEggBox) { + return false; + } + + return par1EntityPlayer.getDistanceSq(this.posX + 0.5D, this.posY + 0.5D, this.posZ + 0.5D) <= 64D; + } + + @Override + public ItemStack transferStackInSlot(final EntityPlayer par1EntityPlayer, final int par2) { + ItemStack var3 = null; + final Slot var4 = (Slot) this.inventorySlots.get(par2); + + if ((var4 != null) && var4.getHasStack()) { + final ItemStack var5 = var4.getStack(); + var3 = var5.copy(); + + /* + * if (par2 == 0) { if (!this.mergeItemStack(var5, + * InOutputSlotNumber, FullSlotNumber, true)) { return null; } + * + * var4.onSlotChange(var5, var3); } else if (par2 >= + * InOutputSlotNumber && par2 < InventoryOutSlotNumber) { if + * (!this.mergeItemStack(var5, InventoryOutSlotNumber, + * FullSlotNumber, false)) { return null; } } else if (par2 >= + * InventoryOutSlotNumber && par2 < FullSlotNumber) { if + * (!this.mergeItemStack(var5, InOutputSlotNumber, + * InventoryOutSlotNumber, false)) { return null; } } else if + * (!this.mergeItemStack(var5, InOutputSlotNumber, FullSlotNumber, + * false)) { return null; } + */ + + if (var5.stackSize == 0) { + var4.putStack((ItemStack) null); + } else { + var4.onSlotChanged(); + } + + if (var5.stackSize == var3.stackSize) { + return null; + } + + var4.onPickupFromSlot(par1EntityPlayer, var5); + } + + return var3; + } + + // Can merge Slot + @Override + public boolean func_94530_a(final ItemStack p_94530_1_, final Slot p_94530_2_) { + return super.func_94530_a(p_94530_1_, p_94530_2_); + } + +} \ No newline at end of file diff --git a/src/main/java/gtPlusPlus/core/container/Container_FishTrap.java b/src/main/java/gtPlusPlus/core/container/Container_FishTrap.java new file mode 100644 index 0000000000..a2f44441d9 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/container/Container_FishTrap.java @@ -0,0 +1,142 @@ +package gtPlusPlus.core.container; + +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; +import net.minecraft.world.World; + +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.inventories.InventoryFishTrap; +import gtPlusPlus.core.slots.SlotNoInput; +import gtPlusPlus.core.tileentities.general.TileEntityFishTrap; + +public class Container_FishTrap extends Container { + + protected TileEntityFishTrap tile_entity; + public final InventoryFishTrap inventoryChest; + + private final World worldObj; + private final int posX; + private final int posY; + private final int posZ; + + public static int StorageSlotNumber = 15; // Number of slots in storage area + public static int InventorySlotNumber = 36; // Inventory Slots (Inventory + // and Hotbar) + public static int FullSlotNumber = InventorySlotNumber + StorageSlotNumber; // All + // slots + + private final int[] slotStorage = new int[15]; + + public Container_FishTrap(final InventoryPlayer inventory, final TileEntityFishTrap te) { + this.tile_entity = te; + this.inventoryChest = te.getInventory(); + + te.openInventory(); + int var6; + int var7; + this.worldObj = te.getWorldObj(); + this.posX = te.xCoord; + this.posY = te.yCoord; + this.posZ = te.zCoord; + + int o = 0; + + // Storage Side + for (var6 = 0; var6 < 3; var6++) { + for (var7 = 0; var7 < 5; var7++) { + this.slotStorage[o] = o; + this.addSlotToContainer(new SlotNoInput(this.inventoryChest, o++, 44 + (var7 * 18), 15 + (var6 * 18))); + } + } + + // Player Inventory + for (var6 = 0; var6 < 3; ++var6) { + for (var7 = 0; var7 < 9; ++var7) { + this.addSlotToContainer(new Slot(inventory, var7 + (var6 * 9) + 9, 8 + (var7 * 18), 84 + (var6 * 18))); + } + } + + // Player Hotbar + for (var6 = 0; var6 < 9; ++var6) { + this.addSlotToContainer(new Slot(inventory, var6, 8 + (var6 * 18), 142)); + } + + } + + @Override + public ItemStack slotClick(final int aSlotIndex, final int aMouseclick, final int aShifthold, + final EntityPlayer aPlayer) { + + if (!aPlayer.worldObj.isRemote) { + if ((aSlotIndex == 999) || (aSlotIndex == -999)) { + // Utils.LOG_WARNING("??? - "+aSlotIndex); + } + } + return super.slotClick(aSlotIndex, aMouseclick, aShifthold, aPlayer); + } + + @Override + public void onContainerClosed(final EntityPlayer par1EntityPlayer) { + super.onContainerClosed(par1EntityPlayer); + tile_entity.closeInventory(); + } + + @Override + public boolean canInteractWith(final EntityPlayer par1EntityPlayer) { + if (this.worldObj.getBlock(this.posX, this.posY, this.posZ) != ModBlocks.blockFishTrap) { + return false; + } + + return par1EntityPlayer.getDistanceSq(this.posX + 0.5D, this.posY + 0.5D, this.posZ + 0.5D) <= 64D; + } + + @Override + public ItemStack transferStackInSlot(final EntityPlayer par1EntityPlayer, final int par2) { + ItemStack var3 = null; + final Slot var4 = (Slot) this.inventorySlots.get(par2); + + if ((var4 != null) && var4.getHasStack()) { + final ItemStack var5 = var4.getStack(); + var3 = var5.copy(); + + /* + * if (par2 == 0) { if (!this.mergeItemStack(var5, + * InOutputSlotNumber, FullSlotNumber, true)) { return null; } + * + * var4.onSlotChange(var5, var3); } else if (par2 >= + * InOutputSlotNumber && par2 < InventoryOutSlotNumber) { if + * (!this.mergeItemStack(var5, InventoryOutSlotNumber, + * FullSlotNumber, false)) { return null; } } else if (par2 >= + * InventoryOutSlotNumber && par2 < FullSlotNumber) { if + * (!this.mergeItemStack(var5, InOutputSlotNumber, + * InventoryOutSlotNumber, false)) { return null; } } else if + * (!this.mergeItemStack(var5, InOutputSlotNumber, FullSlotNumber, + * false)) { return null; } + */ + + if (var5.stackSize == 0) { + var4.putStack((ItemStack) null); + } else { + var4.onSlotChanged(); + } + + if (var5.stackSize == var3.stackSize) { + return null; + } + + var4.onPickupFromSlot(par1EntityPlayer, var5); + } + + return var3; + } + + // Can merge Slot + @Override + public boolean func_94530_a(final ItemStack p_94530_1_, final Slot p_94530_2_) { + return super.func_94530_a(p_94530_1_, p_94530_2_); + } + +} \ No newline at end of file diff --git a/src/main/java/gtPlusPlus/core/container/Container_Grindle.java b/src/main/java/gtPlusPlus/core/container/Container_Grindle.java new file mode 100644 index 0000000000..4ab79322c9 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/container/Container_Grindle.java @@ -0,0 +1,160 @@ +package gtPlusPlus.core.container; + +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; + +import gtPlusPlus.core.inventories.BaseInventoryGrindle; +import gtPlusPlus.core.slots.SlotDataStick; + +public class Container_Grindle extends Container { + /** + * The Item Inventory for this Container, only needed if you want to reference + * isUseableByPlayer + */ + public final BaseInventoryGrindle inventory; + + /** + * Using these will make transferStackInSlot easier to understand and implement + * INV_START is the index of the first slot in the Player's Inventory, so our + * BaseInventoryBackpack's number of slots (e.g. 5 slots is array indices 0-4, + * so start at 5) Notice how we don't have to remember how many slots we made? + * We can just use BaseInventoryBackpack.INV_SIZE and if we ever change it, the + * Container updates automatically. + */ + private static final int + INV_START = BaseInventoryGrindle.INV_SIZE, + INV_END = INV_START + 0, + HOTBAR_START = INV_END, + HOTBAR_END = HOTBAR_START + 8; + + public Container_Grindle(final EntityPlayer par1Player, final InventoryPlayer inventoryPlayer, + final BaseInventoryGrindle inventoryItem) { + this.inventory = inventoryItem; + + int i; + + // Actual Scan Slot + this.addSlotToContainer(new SlotDataStick(this.inventory, 0, 152, 5)); + + for (i = 1; i < BaseInventoryGrindle.INV_SIZE; ++i) { + this.addSlotToContainer(new SlotDataStick(this.inventory, i, 153, 30 + (18 * i))); + } + + // PLAYER ACTION BAR - uses default locations for standard action bar texture + // file + for (i = 0; i < 9; ++i) { + this.addSlotToContainer(new Slot(inventoryPlayer, i, 8 + (i * 18), 142)); + } + } + + @Override + public boolean canInteractWith(final EntityPlayer entityplayer) { + return this.inventory.isUseableByPlayer(entityplayer); + } + + /** + * Called when a player shift-clicks on a slot. You must override this or you + * will crash when someone does that. + */ + @Override + public ItemStack transferStackInSlot(final EntityPlayer par1EntityPlayer, final int index) { + ItemStack itemstack = null; + final Slot slot = (Slot) this.inventorySlots.get(index); + + if ((slot != null) && slot.getHasStack()) { + final ItemStack itemstack1 = slot.getStack(); + itemstack = itemstack1.copy(); + + // If item is in our custom Inventory or armor slot + if (index < INV_START) { + // try to place in player inventory / action bar + if (!this.mergeItemStack(itemstack1, INV_START, HOTBAR_END + 1, true)) { + return null; + } + + slot.onSlotChange(itemstack1, itemstack); + } + // Item is in inventory / hotbar, try to place in custom inventory or armor + // slots + else {/* + + * If your inventory only stores certain instances of Items, you can implement + * shift-clicking to your inventory like this: + * + * // Check that the item is the right type if (itemstack1.getItem() instanceof + * ItemCustom) { // Try to merge into your custom inventory slots // We use + * 'BaseInventoryBackpack.INV_SIZE' instead of INV_START just in case // you + * also add armor or other custom slots if (!this.mergeItemStack(itemstack1, 0, + * BaseInventoryBackpack.INV_SIZE, false)) { return null; } } // If you added + * armor slots, check them here as well: // Item being shift-clicked is armor - + * try to put in armor slot if (itemstack1.getItem() instanceof ItemArmor) { int + * type = ((ItemArmor) itemstack1.getItem()).armorType; if + * (!this.mergeItemStack(itemstack1, ARMOR_START + type, ARMOR_START + type + 1, + * false)) { return null; } } Otherwise, you have basically 2 choices: 1. + * shift-clicking between player inventory and custom inventory 2. + * shift-clicking between action bar and inventory + * + * Be sure to choose only ONE of the following implementations!!! + + *//** + * Implementation number 1: Shift-click into your custom inventory + *//* + if (index >= INV_START) { + // place in custom inventory + if (!this.mergeItemStack(itemstack1, 0, INV_START, false)) { + return null; + } + } + + *//** + * Implementation number 2: Shift-click items between action bar and inventory + *//* + // item is in player's inventory, but not in action bar + if ((index >= INV_START) && (index < HOTBAR_START)) { + // place in action bar + if (!this.mergeItemStack(itemstack1, HOTBAR_START, HOTBAR_END + 1, false)) { + return null; + } + } + // item in action bar - place in player inventory + else if ((index >= HOTBAR_START) && (index < (HOTBAR_END + 1))) { + if (!this.mergeItemStack(itemstack1, INV_START, INV_END + 1, false)) { + return null; + } + } + */} + + if (itemstack1.stackSize == 0) { + slot.putStack((ItemStack) null); + } else { + slot.onSlotChanged(); + } + + if (itemstack1.stackSize == itemstack.stackSize) { + return null; + } + + slot.onPickupFromSlot(par1EntityPlayer, itemstack1); + } + + return itemstack; + } + + /** + * You should override this method to prevent the player from moving the stack + * that opened the inventory, otherwise if the player moves it, the inventory + * will not be able to save properly + */ + @Override + public ItemStack slotClick(final int slot, final int button, final int flag, final EntityPlayer player) { + // this will prevent the player from interacting with the item that opened the + // inventory: + if ((slot >= 0) && (this.getSlot(slot) != null) && (this.getSlot(slot).getStack() == player.getHeldItem())) { + return null; + } + return super.slotClick(slot, button, flag, player); + } +} diff --git a/src/main/java/gtPlusPlus/core/container/Container_HeliumGenerator.java b/src/main/java/gtPlusPlus/core/container/Container_HeliumGenerator.java new file mode 100644 index 0000000000..39e07f2f0e --- /dev/null +++ b/src/main/java/gtPlusPlus/core/container/Container_HeliumGenerator.java @@ -0,0 +1,193 @@ +package gtPlusPlus.core.container; + +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; +import net.minecraft.world.World; + +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.inventories.InventoryHeliumGenerator; +import gtPlusPlus.core.slots.SlotFuelRod; +import gtPlusPlus.core.slots.SlotNoInput; +import gtPlusPlus.core.tileentities.general.TileEntityHeliumGenerator; + +public class Container_HeliumGenerator extends Container { + + protected TileEntityHeliumGenerator tile_entity; + public final InventoryHeliumGenerator inventoryChest; + + private final World worldObj; + private final int posX; + private final int posY; + private final int posZ; + + + public static int StorageSlotNumber = 19; //Number of slots in storage area + public static int InventorySlotNumber = 36; //Inventory Slots (Inventory and Hotbar) + public static int FullSlotNumber = InventorySlotNumber + StorageSlotNumber; //All slots + + //0 Is output, 1-18 are input. + private final int[] slotStorage = new int[19]; + + public Container_HeliumGenerator(final InventoryPlayer inventory, final TileEntityHeliumGenerator te){ + this.tile_entity = te; + this.inventoryChest = te.getInventory(); + + int var6; + int var7; + this.worldObj = te.getWorldObj(); + this.posX = te.xCoord; + this.posY = te.yCoord; + this.posZ = te.zCoord; + + int o=0; + + //Output + this.addSlotToContainer(new SlotNoInput(this.inventoryChest, 0, 80, 53)); + this.slotStorage[o] = o; + o++; + + //Side A + for (var6 = 0; var6 < 3; ++var6) + { + for (var7 = 0; var7 < 3; ++var7) + { + Logger.INFO("Adding slots at var:"+(o)+" x:"+(8 + var7 * 18)+" y:"+(9 + var6 * 18)); + this.addSlotToContainer(new SlotFuelRod(this.inventoryChest, o, 8 + (var7 * 18), 18 + (var6 * 18))); + this.slotStorage[o] = o; + o++; + } + } + + //Side B + for (var6 = 0; var6 < 3; ++var6) + { + for (var7 = 0; var7 < 3; ++var7) + { + Logger.INFO("Adding slots at var:"+(o)+" x:"+(90+8+(var7 * 18))+" y:"+(9 + var6 * 18)); + this.addSlotToContainer(new SlotFuelRod(this.inventoryChest, o, 116 + (var7 * 18), 18 + (var6 * 18))); + this.slotStorage[o] = o; + o++; + } + } + + o=0; + + //Player Inventory + for (var6 = 0; var6 < 3; ++var6) + { + for (var7 = 0; var7 < 9; ++var7) + { + this.addSlotToContainer(new Slot(inventory, var7 + (var6 * 9) + 9, 8 + (var7 * 18), 84 + (var6 * 18))); + } + } + + //Player Hotbar + for (var6 = 0; var6 < 9; ++var6) + { + this.addSlotToContainer(new Slot(inventory, var6, 8 + (var6 * 18), 142)); + } + + } + + @Override + public ItemStack slotClick(final int aSlotIndex, final int aMouseclick, final int aShifthold, final EntityPlayer aPlayer){ + + if (!aPlayer.worldObj.isRemote){ + if ((aSlotIndex == 999) || (aSlotIndex == -999)){ + //Utils.LOG_WARNING("??? - "+aSlotIndex); + } + } + return super.slotClick(aSlotIndex, aMouseclick, aShifthold, aPlayer); + } + + + + + + @Override + public void onContainerClosed(final EntityPlayer par1EntityPlayer){ + super.onContainerClosed(par1EntityPlayer); + } + + + @Override + public boolean canInteractWith(final EntityPlayer par1EntityPlayer){ + if (this.worldObj.getBlock(this.posX, this.posY, this.posZ) != ModBlocks.blockHeliumGenerator){ + return false; + } + + return par1EntityPlayer.getDistanceSq(this.posX + 0.5D, this.posY + 0.5D, this.posZ + 0.5D) <= 64D; + } + + + @Override + public ItemStack transferStackInSlot(final EntityPlayer par1EntityPlayer, final int par2) + { + ItemStack var3 = null; + final Slot var4 = (Slot)this.inventorySlots.get(par2); + + if ((var4 != null) && var4.getHasStack()) + { + final ItemStack var5 = var4.getStack(); + var3 = var5.copy(); + + /*if (par2 == 0) + { + if (!this.mergeItemStack(var5, InOutputSlotNumber, FullSlotNumber, true)) + { + return null; + } + + var4.onSlotChange(var5, var3); + } + else if (par2 >= InOutputSlotNumber && par2 < InventoryOutSlotNumber) + { + if (!this.mergeItemStack(var5, InventoryOutSlotNumber, FullSlotNumber, false)) + { + return null; + } + } + else if (par2 >= InventoryOutSlotNumber && par2 < FullSlotNumber) + { + if (!this.mergeItemStack(var5, InOutputSlotNumber, InventoryOutSlotNumber, false)) + { + return null; + } + } + else if (!this.mergeItemStack(var5, InOutputSlotNumber, FullSlotNumber, false)) + { + return null; + }*/ + + if (var5.stackSize == 0) + { + var4.putStack((ItemStack)null); + } + else + { + var4.onSlotChanged(); + } + + if (var5.stackSize == var3.stackSize) + { + return null; + } + + var4.onPickupFromSlot(par1EntityPlayer, var5); + } + + return var3; + } + + //Can merge Slot + @Override + public boolean func_94530_a(final ItemStack p_94530_1_, final Slot p_94530_2_) { + return super.func_94530_a(p_94530_1_, p_94530_2_); + } + + +} \ No newline at end of file diff --git a/src/main/java/gtPlusPlus/core/container/Container_ModularityTable.java b/src/main/java/gtPlusPlus/core/container/Container_ModularityTable.java new file mode 100644 index 0000000000..e0fb51fe61 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/container/Container_ModularityTable.java @@ -0,0 +1,252 @@ +package gtPlusPlus.core.container; + +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; +import net.minecraft.world.World; + +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.inventories.modulartable.InventoryModularMain; +import gtPlusPlus.core.inventories.modulartable.InventoryModularOutput; +import gtPlusPlus.core.slots.SlotModularBauble; +import gtPlusPlus.core.slots.SlotModularBaubleUpgrades; +import gtPlusPlus.core.slots.SlotNoInput; +import gtPlusPlus.core.tileentities.machines.TileEntityModularityTable; + +public class Container_ModularityTable extends Container { + + /** The crafting matrix inventory (3x3). */ + + protected TileEntityModularityTable tile_entity; + public final InventoryModularMain inventoryGrid; + public final InventoryModularOutput inventoryOutputs; + public int mRecipeTime; + + private final World worldObj; + private final int posX; + private final int posY; + private final int posZ; + + private final int[] slotOutputs = new int[3]; + private final int[] slotGrid = new int[9]; + + + public Container_ModularityTable(final InventoryPlayer inventory, final TileEntityModularityTable tile){ + this.tile_entity = tile; + this.inventoryGrid = tile.inventoryGrid; + this.inventoryOutputs = tile.inventoryOutputs; + this.tile_entity.setContainer(this); + this.mRecipeTime = this.tile_entity.getRecipeTime(); + Logger.INFO("Container: "+this.mRecipeTime); + + int var6; + int var7; + this.worldObj = tile.getWorldObj(); + this.posX = tile.xCoord; + this.posY = tile.yCoord; + this.posZ = tile.zCoord; + + int nextFreeSlot = 0; + + + //Output slots + this.addSlotToContainer(new SlotModularBauble(this.inventoryOutputs, 0, 26+(18*6), 8)); + this.addSlotToContainer(new SlotModularBaubleUpgrades(this.inventoryOutputs, 1, 26+(18*5), 8)); + this.addSlotToContainer(new SlotNoInput(this.inventoryOutputs, 2, 26+(18*6), 44)); + + int o = 0; + + //Storage Side + for (var6 = 0; var6 < 3; ++var6) + { + for (var7 = 0; var7 < 3; ++var7) + { + //Utils.LOG_WARNING("Adding slots at var:"+(var7 + var6 * 4)+" x:"+(8 + var7 * 18)+" y:"+(7 + var6 * 18)); + this.addSlotToContainer(new SlotModularBaubleUpgrades(this.inventoryGrid, nextFreeSlot, 8+18 + (var7 * 18), 17 + (var6 * 18))); + this.slotGrid[o] = nextFreeSlot; + nextFreeSlot++; + o++; + } + } + + //Player Inventory + for (var6 = 0; var6 < 3; ++var6) + { + for (var7 = 0; var7 < 9; ++var7) + { + this.addSlotToContainer(new Slot(inventory, var7 + (var6 * 9) + 9, 8 + (var7 * 18), 84 + (var6 * 18))); + } + } + + //Player Hotbar + for (var6 = 0; var6 < 9; ++var6) + { + this.addSlotToContainer(new Slot(inventory, var6, 8 + (var6 * 18), 142)); + } + + //this.onCraftMatrixChanged(this.craftMatrix); + + } + + /** + * Callback for when the crafting matrix is changed. + */ + /* public void onCraftMatrixChanged(IInventory p_75130_1_) + { + this.craftResult.setInventorySlotContents(0, CraftingManager.getInstance().findMatchingRecipe(this.craftMatrix, this.worldObj)); + }*/ + + /** + * Called when the container is closed. + */ + @Override + public void onContainerClosed(EntityPlayer p_75134_1_){ + super.onContainerClosed(p_75134_1_); + if (!this.worldObj.isRemote){ + /* for (int i = 0; i < 9; ++i){ + ItemStack itemstack = this.craftMatrix.getStackInSlotOnClosing(i); + if (itemstack != null){ + p_75134_1_.dropPlayerItemWithRandomChoice(itemstack, false); + } + }*/ + } + } + + public TileEntityModularityTable getTileentityViaContainer(){ + if (this.tile_entity != null){ + return this.tile_entity; + } + return null; + } + + @Override + public ItemStack slotClick(final int aSlotIndex, final int aMouseclick, final int aShifthold, final EntityPlayer aPlayer){ + + if (!aPlayer.worldObj.isRemote){ + if ((aSlotIndex == 999) || (aSlotIndex == -999)){ + //Utils.LOG_WARNING("??? - "+aSlotIndex); + } + + if (aSlotIndex == 0){ + Logger.INFO("Player Clicked on the bauble slot"); + //TODO + } + else if (aSlotIndex == 1){ + Logger.INFO("Player Clicked on the upgrade slot"); + //TODO + } + else if (aSlotIndex == 2){ + Logger.INFO("Player Clicked on the output slot"); + //TODO + } + else { + for (final int x : this.slotGrid){ + if (aSlotIndex == x){ + Logger.INFO("Player Clicked slot "+aSlotIndex+" in the crafting Grid"); + } + } + } + } + //Utils.LOG_WARNING("Player Clicked slot "+aSlotIndex+" in the Grid"); + return super.slotClick(aSlotIndex, aMouseclick, aShifthold, aPlayer); + } + + @Override + public boolean canInteractWith(final EntityPlayer par1EntityPlayer){ + if (this.worldObj.getBlock(this.posX, this.posY, this.posZ) != ModBlocks.blockModularTable){ + return false; + } + + return par1EntityPlayer.getDistanceSq(this.posX + 0.5D, this.posY + 0.5D, this.posZ + 0.5D) <= 64D; + } + + + @Override + public ItemStack transferStackInSlot(final EntityPlayer par1EntityPlayer, final int par2) + { + + return null; + + /*ItemStack var3 = null; + final Slot var4 = (Slot)this.inventorySlots.get(par2); + + if ((var4 != null) && var4.getHasStack()) + { + final ItemStack var5 = var4.getStack(); + var3 = var5.copy(); + + if (par2 == 0) + { + if (!this.mergeItemStack(var5, InOutputSlotNumber, FullSlotNumber, true)) + { + return null; + } + + var4.onSlotChange(var5, var3); + } + else if ((par2 >= InOutputSlotNumber) && (par2 < InventoryOutSlotNumber)) + { + if (!this.mergeItemStack(var5, InventoryOutSlotNumber, FullSlotNumber, false)) + { + return null; + } + } + else if ((par2 >= InventoryOutSlotNumber) && (par2 < FullSlotNumber)) + { + if (!this.mergeItemStack(var5, InOutputSlotNumber, InventoryOutSlotNumber, false)) + { + return null; + } + } + else if (!this.mergeItemStack(var5, InOutputSlotNumber, FullSlotNumber, false)) + { + return null; + } + + if (var5.stackSize == 0) + { + var4.putStack((ItemStack)null); + } + else + { + var4.onSlotChanged(); + } + + if (var5.stackSize == var3.stackSize) + { + return null; + } + + var4.onPickupFromSlot(par1EntityPlayer, var5); + } + + return var3;*/ + } + + //Can merge Slot + /*public boolean func_94530_a(ItemStack p_94530_1_, Slot p_94530_2_){ + return p_94530_2_.inventory != this.craftResult && super.func_94530_a(p_94530_1_, p_94530_2_); + }*/ + + /*public ItemStack getOutputContent(){ + ItemStack output = this.craftResult.getStackInSlot(0); + if (output != null){ + return output; + } + return null; + } + + public ItemStack[] getInputComponents(){ + ItemStack inputs[] = new ItemStack[9]; + for (int r=0;r= + * InOutputSlotNumber && par2 < InventoryOutSlotNumber) { if + * (!this.mergeItemStack(var5, InventoryOutSlotNumber, + * FullSlotNumber, false)) { return null; } } else if (par2 >= + * InventoryOutSlotNumber && par2 < FullSlotNumber) { if + * (!this.mergeItemStack(var5, InOutputSlotNumber, + * InventoryOutSlotNumber, false)) { return null; } } else if + * (!this.mergeItemStack(var5, InOutputSlotNumber, FullSlotNumber, + * false)) { return null; } + */ + + if (var5.stackSize == 0) { + var4.putStack((ItemStack) null); + } else { + var4.onSlotChanged(); + } + + if (var5.stackSize == var3.stackSize) { + return null; + } + + var4.onPickupFromSlot(par1EntityPlayer, var5); + } + + return var3; + } + + // Can merge Slot + @Override + public boolean func_94530_a(final ItemStack p_94530_1_, final Slot p_94530_2_) { + return super.func_94530_a(p_94530_1_, p_94530_2_); + } + +} \ No newline at end of file diff --git a/src/main/java/gtPlusPlus/core/container/Container_ProjectTable.java b/src/main/java/gtPlusPlus/core/container/Container_ProjectTable.java new file mode 100644 index 0000000000..2cdf7ee783 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/container/Container_ProjectTable.java @@ -0,0 +1,242 @@ +package gtPlusPlus.core.container; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.*; +import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.CraftingManager; +import net.minecraft.world.World; + +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.inventories.projecttable.InventoryProjectMain; +import gtPlusPlus.core.inventories.projecttable.InventoryProjectOutput; +import gtPlusPlus.core.slots.SlotCraftingNoCollect; +import gtPlusPlus.core.slots.SlotDataStick; +import gtPlusPlus.core.slots.SlotNoInput; +import gtPlusPlus.core.tileentities.machines.TileEntityProjectTable; + +public class Container_ProjectTable extends Container { + + /** The crafting matrix inventory (3x3). */ + public InventoryCrafting craftMatrix = new InventoryCrafting(this, 3, 3); + public IInventory craftResult = new InventoryCraftResult(); + + protected TileEntityProjectTable tile_entity; + public final InventoryProjectMain inventoryGrid; + public final InventoryProjectOutput inventoryOutputs; + + private final World worldObj; + private final int posX; + private final int posY; + private final int posZ; + + private final int[] slotOutputs = new int[2]; + private final int[] slotGrid = new int[9]; + + + public Container_ProjectTable(final InventoryPlayer inventory, final TileEntityProjectTable tile){ + this.tile_entity = tile; + this.inventoryGrid = tile.inventoryGrid; + this.inventoryOutputs = tile.inventoryOutputs; + this.tile_entity.setContainer(this); + + int var6; + int var7; + this.worldObj = tile.getWorldObj(); + this.posX = tile.xCoord; + this.posY = tile.yCoord; + this.posZ = tile.zCoord; + + int nextFreeSlot = 0; + + + //Output slots + this.addSlotToContainer(new SlotDataStick(this.inventoryOutputs, 0, 26+(18*6), 8)); + this.addSlotToContainer(new SlotNoInput(this.inventoryOutputs, 1, 26+(18*6), 44)); + + this.addSlotToContainer(new SlotCraftingNoCollect(inventory.player, this.craftMatrix, this.craftResult, 0, 26+(18*4), 25)); + + + int o = 0; + //Storage Side + for (var6 = 0; var6 < 3; ++var6) + { + for (var7 = 0; var7 < 3; ++var7) + { + //Utils.LOG_WARNING("Adding slots at var:"+(var7 + var6 * 4)+" x:"+(8 + var7 * 18)+" y:"+(7 + var6 * 18)); + this.addSlotToContainer(new Slot(this.craftMatrix, nextFreeSlot, 8+18 + (var7 * 18), 8 + (var6 * 18))); + this.slotGrid[o] = nextFreeSlot; + nextFreeSlot++; + o++; + } + } + + + //Player Inventory + for (var6 = 0; var6 < 3; ++var6) + { + for (var7 = 0; var7 < 9; ++var7) + { + this.addSlotToContainer(new Slot(inventory, var7 + (var6 * 9) + 9, 8 + (var7 * 18), 84 + (var6 * 18))); + } + } + + //Player Hotbar + for (var6 = 0; var6 < 9; ++var6) + { + this.addSlotToContainer(new Slot(inventory, var6, 8 + (var6 * 18), 142)); + } + + this.onCraftMatrixChanged(this.craftMatrix); + + } + + /** + * Callback for when the crafting matrix is changed. + */ + @Override + public void onCraftMatrixChanged(IInventory p_75130_1_) + { + this.craftResult.setInventorySlotContents(0, CraftingManager.getInstance().findMatchingRecipe(this.craftMatrix, this.worldObj)); + } + + /** + * Called when the container is closed. + */ + @Override + public void onContainerClosed(EntityPlayer p_75134_1_){ + super.onContainerClosed(p_75134_1_); + if (!this.worldObj.isRemote){ + for (int i = 0; i < 9; ++i){ + ItemStack itemstack = this.craftMatrix.getStackInSlotOnClosing(i); + if (itemstack != null){ + p_75134_1_.dropPlayerItemWithRandomChoice(itemstack, false); + } + } + } + } + + @Override + public ItemStack slotClick(final int aSlotIndex, final int aMouseclick, final int aShifthold, final EntityPlayer aPlayer){ + + if (!aPlayer.worldObj.isRemote){ + if ((aSlotIndex == 999) || (aSlotIndex == -999)){ + //Utils.LOG_WARNING("??? - "+aSlotIndex); + } + + if (aSlotIndex == 0){ + Logger.INFO("Player Clicked on the Data Stick slot"); + //TODO + }if (aSlotIndex == 1){ + Logger.INFO("Player Clicked on the output slot"); + //TODO + } + + for (final int x : this.slotGrid){ + if (aSlotIndex == x){ + Logger.INFO("Player Clicked slot "+aSlotIndex+" in the crafting Grid"); + } + } + } + //Utils.LOG_WARNING("Player Clicked slot "+aSlotIndex+" in the Grid"); + return super.slotClick(aSlotIndex, aMouseclick, aShifthold, aPlayer); + } + + @Override + public boolean canInteractWith(final EntityPlayer par1EntityPlayer){ + if (this.worldObj.getBlock(this.posX, this.posY, this.posZ) != ModBlocks.blockProjectTable){ + return false; + } + + return par1EntityPlayer.getDistanceSq(this.posX + 0.5D, this.posY + 0.5D, this.posZ + 0.5D) <= 64D; + } + + + @Override + public ItemStack transferStackInSlot(final EntityPlayer par1EntityPlayer, final int par2) + { + + return null; + + /*ItemStack var3 = null; + final Slot var4 = (Slot)this.inventorySlots.get(par2); + + if ((var4 != null) && var4.getHasStack()) + { + final ItemStack var5 = var4.getStack(); + var3 = var5.copy(); + + if (par2 == 0) + { + if (!this.mergeItemStack(var5, InOutputSlotNumber, FullSlotNumber, true)) + { + return null; + } + + var4.onSlotChange(var5, var3); + } + else if ((par2 >= InOutputSlotNumber) && (par2 < InventoryOutSlotNumber)) + { + if (!this.mergeItemStack(var5, InventoryOutSlotNumber, FullSlotNumber, false)) + { + return null; + } + } + else if ((par2 >= InventoryOutSlotNumber) && (par2 < FullSlotNumber)) + { + if (!this.mergeItemStack(var5, InOutputSlotNumber, InventoryOutSlotNumber, false)) + { + return null; + } + } + else if (!this.mergeItemStack(var5, InOutputSlotNumber, FullSlotNumber, false)) + { + return null; + } + + if (var5.stackSize == 0) + { + var4.putStack((ItemStack)null); + } + else + { + var4.onSlotChanged(); + } + + if (var5.stackSize == var3.stackSize) + { + return null; + } + + var4.onPickupFromSlot(par1EntityPlayer, var5); + } + + return var3;*/ + } + + //Can merge Slot + @Override + public boolean func_94530_a(ItemStack p_94530_1_, Slot p_94530_2_){ + return p_94530_2_.inventory != this.craftResult && super.func_94530_a(p_94530_1_, p_94530_2_); + } + + public ItemStack getOutputContent(){ + ItemStack output = this.craftResult.getStackInSlot(0); + if (output != null){ + return output; + } + return null; + } + + public ItemStack[] getInputComponents(){ + ItemStack inputs[] = new ItemStack[9]; + for (int r=0;r= 3 && c < 6) { + continue; + } + this.addSlotToContainer(new SlotJukebox(this.inventoryChest, o++, xStart+(18*c), yStart)); + } + + //Row Two + for (int c = 0; c < 9; c++) { + if (c >= 3 && c < 6) { + continue; + } + this.addSlotToContainer(new SlotJukebox(this.inventoryChest, o++, xStart+(18*c), yStart+18)); + } + + //Row Two + for (int c = 0; c < 9; c++) { + if (c >= 3 && c < 6) { + continue; + } + this.addSlotToContainer(new SlotJukebox(this.inventoryChest, o++, xStart+(18*c), yStart+36)); + } + + + //Controls + int c = 4; + + //Two Control Buttons + this.addSlotToContainer(new SlotNoInput(this.inventoryChest, SLOT_HOLO_PLAY, xStart+(18*c), 12)); + this.addSlotToContainer(new SlotNoInput(this.inventoryChest, SLOT_HOLO_LOOP, xStart+(18*c), 12+(1*18))); + + //Active playing slot for visual + this.addSlotToContainer(new SlotJukebox(this.inventoryChest, SLOT_OUTPUT, xStart+(18*c), 18+(2*18), true)); + + + + + // Player Inventory + for (var6 = 0; var6 < 3; ++var6) { + for (var7 = 0; var7 < 9; ++var7) { + this.addSlotToContainer(new Slot(inventory, var7 + (var6 * 9) + 9, 8 + (var7 * 18), 84 + (var6 * 18))); + } + } + // Player Hotbar + for (var6 = 0; var6 < 9; ++var6) { + this.addSlotToContainer(new Slot(inventory, var6, 8 + (var6 * 18), 142)); + } + + + Logger.INFO("3"); + + } + catch (Throwable t) { + t.printStackTrace(); + } + + } + + @Override + public void onContainerClosed(final EntityPlayer par1EntityPlayer) { + super.onContainerClosed(par1EntityPlayer); + } + + @Override + public boolean canInteractWith(final EntityPlayer par1EntityPlayer) { + if (this.worldObj.getBlock(this.posX, this.posY, this.posZ) != ModBlocks.blockCustomJukebox) { + return false; + } + + return par1EntityPlayer.getDistanceSq(this.posX + 0.5D, this.posY + 0.5D, this.posZ + 0.5D) <= 64D; + } + + @Override + public ItemStack transferStackInSlot(final EntityPlayer par1EntityPlayer, final int par2) { + ItemStack var3 = null; + final Slot var4 = (Slot) this.inventorySlots.get(par2); + + if ((var4 != null) && var4.getHasStack()) { + final ItemStack var5 = var4.getStack(); + var3 = var5.copy(); + + /* + * if (par2 == 0) { if (!this.mergeItemStack(var5, + * InOutputSlotNumber, FullSlotNumber, true)) { return null; } + * + * var4.onSlotChange(var5, var3); } else if (par2 >= + * InOutputSlotNumber && par2 < InventoryOutSlotNumber) { if + * (!this.mergeItemStack(var5, InventoryOutSlotNumber, + * FullSlotNumber, false)) { return null; } } else if (par2 >= + * InventoryOutSlotNumber && par2 < FullSlotNumber) { if + * (!this.mergeItemStack(var5, InOutputSlotNumber, + * InventoryOutSlotNumber, false)) { return null; } } else if + * (!this.mergeItemStack(var5, InOutputSlotNumber, FullSlotNumber, + * false)) { return null; } + */ + + if (var5.stackSize == 0) { + var4.putStack((ItemStack) null); + } else { + var4.onSlotChanged(); + } + + if (var5.stackSize == var3.stackSize) { + return null; + } + + var4.onPickupFromSlot(par1EntityPlayer, var5); + } + + return var3; + } + + // Can merge Slot + @Override + public boolean func_94530_a(final ItemStack p_94530_1_, final Slot p_94530_2_) { + return super.func_94530_a(p_94530_1_, p_94530_2_); + } + + + + @Override + public ItemStack slotClick(int aSlotIndex, int aMouseclick, int aShifthold, EntityPlayer aPlayer) { + if (tile_entity == null || tile_entity.getWorldObj().isRemote) return null; + switch (aSlotIndex) { + case SLOT_HOLO_PLAY: + if (tile_entity == null) return null; + tile_entity.mIsPlaying = !tile_entity.mIsPlaying; + Logger.INFO("Jukebox | Playing: "+tile_entity.mIsPlaying); + tile_entity.jukeboxLogicUpdate(); + return null; + case SLOT_HOLO_LOOP: + if (tile_entity == null) return null; + tile_entity.mIsLooping = !tile_entity.mIsLooping; + Logger.INFO("Jukebox | Looping: "+tile_entity.mIsLooping); + return null; + case 20: + return null; + default: + return super.slotClick(aSlotIndex, aMouseclick, aShifthold, aPlayer); + } + } + + public boolean isPlaying; + public boolean isLooping; + + @Override + public void detectAndSendChanges() { + super.detectAndSendChanges(); + if (tile_entity == null || tile_entity.getWorldObj().isRemote) return; + + isPlaying = tile_entity.mIsPlaying; + isLooping = tile_entity.mIsLooping; + + Iterator var2 = this.crafters.iterator(); + while (var2.hasNext()) { + ICrafting var1 = (ICrafting) var2.next(); + var1.sendProgressBarUpdate(this, 102, isPlaying ? 1 : 0); + var1.sendProgressBarUpdate(this, 103, isLooping ? 1 : 0); + } + } + + @Override + public void addCraftingToCrafters(ICrafting par1ICrafting) { + super.addCraftingToCrafters(par1ICrafting); + } + + @Override + @SideOnly(Side.CLIENT) + public void updateProgressBar(int par1, int par2) { + super.updateProgressBar(par1, par2); + switch (par1) { + case 102: + isPlaying = (par2 != 0); + break; + case 103: + isLooping = (par2 != 0); + break; + } + } +} \ No newline at end of file diff --git a/src/main/java/gtPlusPlus/core/container/Container_TradeTable.java b/src/main/java/gtPlusPlus/core/container/Container_TradeTable.java new file mode 100644 index 0000000000..f812e384a7 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/container/Container_TradeTable.java @@ -0,0 +1,223 @@ +package gtPlusPlus.core.container; + +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; +import net.minecraft.world.World; + +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.inventories.tradetable.InventoryTradeMain; +import gtPlusPlus.core.inventories.tradetable.InventoryTradeOutput; +import gtPlusPlus.core.slots.SlotGeneric; +import gtPlusPlus.core.slots.SlotNoInput; +import gtPlusPlus.core.tileentities.machines.TileEntityTradeTable; + +public class Container_TradeTable extends Container { + + protected TileEntityTradeTable tile_entity; + public final InventoryTradeMain inventoryChest; + public final InventoryTradeOutput inventoryOutputs; + + private final World worldObj; + private final int posX; + private final int posY; + private final int posZ; + + private final int[] slotOutputs = new int[2]; + private final int[] slotGrid = new int[9]; + + + public Container_TradeTable(final InventoryPlayer inventory, final TileEntityTradeTable te){ + + this.tile_entity = te; + this.inventoryChest = te.inventoryGrid; + this.inventoryOutputs = te.inventoryOutputs; + this.tile_entity.setContainer(this); + + if (te.isServerSide()) + Logger.INFO("Container - "+te.mOwnerName); + + int var6; + int var7; + this.worldObj = te.getWorldObj(); + this.posX = te.xCoord; + this.posY = te.yCoord; + this.posZ = te.zCoord; + + int nextFreeSlot = 0; + + + //Output slots + this.addSlotToContainer(new SlotGeneric(this.inventoryOutputs, 0, 26+(18*6), 8)); + this.addSlotToContainer(new SlotNoInput(this.inventoryOutputs, 1, 26+(18*6), 44)); + + //this.addSlotToContainer(new SlotCraftingNoCollect(inventory.player, this.craftMatrix, this.craftResult, 0, 26+(18*4), 25)); + + int o = 0; + //Storage Side + for (var6 = 0; var6 < 3; ++var6) + { + for (var7 = 0; var7 < 3; ++var7) + { + //Utils.LOG_WARNING("Adding slots at var:"+(var7 + var6 * 4)+" x:"+(8 + var7 * 18)+" y:"+(7 + var6 * 18)); + this.addSlotToContainer(new Slot(this.inventoryChest, nextFreeSlot, 8+18 + (var7 * 18), 8 + (var6 * 18))); + this.slotGrid[o] = nextFreeSlot; + nextFreeSlot++; + o++; + } + } + + //Player Inventory + for (var6 = 0; var6 < 3; ++var6) + { + for (var7 = 0; var7 < 9; ++var7) + { + this.addSlotToContainer(new Slot(inventory, var7 + (var6 * 9) + 9, 8 + (var7 * 18), 84 + (var6 * 18))); + } + } + + //Player Hotbar + for (var6 = 0; var6 < 9; ++var6) + { + this.addSlotToContainer(new Slot(inventory, var6, 8 + (var6 * 18), 142)); + } + + //this.onCraftMatrixChanged(this.craftMatrix); + } + + /** + * Called when the container is closed. + */ + @Override + public void onContainerClosed(EntityPlayer p_75134_1_){ + super.onContainerClosed(p_75134_1_); + if (!this.worldObj.isRemote){ + for (int i = 0; i < 9; ++i){ + ItemStack itemstack = this.inventoryChest.getStackInSlotOnClosing(i); + if (itemstack != null){ + p_75134_1_.dropPlayerItemWithRandomChoice(itemstack, false); + } + } + } + } + + @Override + public ItemStack slotClick(final int aSlotIndex, final int aMouseclick, final int aShifthold, final EntityPlayer aPlayer){ + + if (!aPlayer.worldObj.isRemote){ + if ((aSlotIndex == 999) || (aSlotIndex == -999)){ + //Utils.LOG_WARNING("??? - "+aSlotIndex); + } + + if (aSlotIndex == 0){ + Logger.INFO("Player Clicked on the Data Stick slot"); + //TODO + }if (aSlotIndex == 1){ + Logger.INFO("Player Clicked on the output slot"); + //TODO + } + + for (final int x : this.slotGrid){ + if (aSlotIndex == x){ + Logger.INFO("Player Clicked slot "+aSlotIndex+" in the crafting Grid"); + } + } + } + //Utils.LOG_WARNING("Player Clicked slot "+aSlotIndex+" in the Grid"); + return super.slotClick(aSlotIndex, aMouseclick, aShifthold, aPlayer); + } + + @Override + public boolean canInteractWith(final EntityPlayer par1EntityPlayer){ + if (this.worldObj.getBlock(this.posX, this.posY, this.posZ) != ModBlocks.blockTradeTable){ + return false; + } + + return par1EntityPlayer.getDistanceSq(this.posX + 0.5D, this.posY + 0.5D, this.posZ + 0.5D) <= 64D; + } + + + @Override + public ItemStack transferStackInSlot(final EntityPlayer par1EntityPlayer, final int par2) + { + + return null; + + /*ItemStack var3 = null; + final Slot var4 = (Slot)this.inventorySlots.get(par2); + + if ((var4 != null) && var4.getHasStack()) + { + final ItemStack var5 = var4.getStack(); + var3 = var5.copy(); + + if (par2 == 0) + { + if (!this.mergeItemStack(var5, InOutputSlotNumber, FullSlotNumber, true)) + { + return null; + } + + var4.onSlotChange(var5, var3); + } + else if ((par2 >= InOutputSlotNumber) && (par2 < InventoryOutSlotNumber)) + { + if (!this.mergeItemStack(var5, InventoryOutSlotNumber, FullSlotNumber, false)) + { + return null; + } + } + else if ((par2 >= InventoryOutSlotNumber) && (par2 < FullSlotNumber)) + { + if (!this.mergeItemStack(var5, InOutputSlotNumber, InventoryOutSlotNumber, false)) + { + return null; + } + } + else if (!this.mergeItemStack(var5, InOutputSlotNumber, FullSlotNumber, false)) + { + return null; + } + + if (var5.stackSize == 0) + { + var4.putStack((ItemStack)null); + } + else + { + var4.onSlotChanged(); + } + + if (var5.stackSize == var3.stackSize) + { + return null; + } + + var4.onPickupFromSlot(par1EntityPlayer, var5); + } + + return var3;*/ + } + + public ItemStack getOutputContent(){ + ItemStack output = this.inventoryOutputs.getStackInSlot(0); + if (output != null){ + return output; + } + return null; + } + + public ItemStack[] getInputComponents(){ + ItemStack inputs[] = new ItemStack[9]; + for (int r=0;r= + * InOutputSlotNumber && par2 < InventoryOutSlotNumber) { if + * (!this.mergeItemStack(var5, InventoryOutSlotNumber, + * FullSlotNumber, false)) { return null; } } else if (par2 >= + * InventoryOutSlotNumber && par2 < FullSlotNumber) { if + * (!this.mergeItemStack(var5, InOutputSlotNumber, + * InventoryOutSlotNumber, false)) { return null; } } else if + * (!this.mergeItemStack(var5, InOutputSlotNumber, FullSlotNumber, + * false)) { return null; } + */ + + if (var5.stackSize == 0) { + var4.putStack((ItemStack) null); + } else { + var4.onSlotChanged(); + } + + if (var5.stackSize == var3.stackSize) { + return null; + } + + var4.onPickupFromSlot(par1EntityPlayer, var5); + } + + return var3; + } + + @Override + public void detectAndSendChanges() { + super.detectAndSendChanges(); + if ((Utils.isClient()) || (this.mTileEntity == null)) { + return; + } + + mCustomValue = mTileEntity.getCustomValue(); + mTimer++; + + Iterator var2 = this.crafters.iterator(); + while (var2.hasNext()) { + ICrafting var1 = (ICrafting) var2.next(); + if (mTimer % 20 == 10 || oCustomValue != mCustomValue) { + var1.sendProgressBarUpdate(this, 0, mCustomValue); + } + } + + oCustomValue = mCustomValue; + } + + @SideOnly(Side.CLIENT) + @Override + public void updateProgressBar(int par1, int par2) { + super.updateProgressBar(par1, par2); + switch (par1) { + case 0: + mCustomValue = (short) par2; + break; + } + } + +} \ No newline at end of file diff --git a/src/main/java/gtPlusPlus/core/container/Container_Workbench.java b/src/main/java/gtPlusPlus/core/container/Container_Workbench.java new file mode 100644 index 0000000000..55ef1a3d0c --- /dev/null +++ b/src/main/java/gtPlusPlus/core/container/Container_Workbench.java @@ -0,0 +1,413 @@ +package gtPlusPlus.core.container; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.*; +import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.CraftingManager; +import net.minecraft.world.World; + +import gregtech.api.gui.GT_Slot_Holo; + +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.interfaces.IItemBlueprint; +import gtPlusPlus.core.inventories.InventoryWorkbenchChest; +import gtPlusPlus.core.inventories.InventoryWorkbenchHoloSlots; +import gtPlusPlus.core.inventories.InventoryWorkbenchTools; +import gtPlusPlus.core.item.general.ItemBlueprint; +import gtPlusPlus.core.slots.*; +import gtPlusPlus.core.tileentities.machines.TileEntityWorkbench; +import gtPlusPlus.core.util.minecraft.ItemUtils; + +public class Container_Workbench extends Container { + + protected TileEntityWorkbench tile_entity; + public InventoryCrafting craftMatrix = new InventoryCrafting(this, 3, 3); + public final InventoryWorkbenchChest inventoryChest; + public final InventoryWorkbenchTools inventoryTool; + public final InventoryWorkbenchHoloSlots inventoryHolo; + //public final InventoryWorkbenchHoloCrafting inventoryCrafting; + + private final World worldObj; + private final int posX; + private final int posY; + private final int posZ; + + public static int HoloSlotNumber = 6; + public static int InputSlotNumber = 0; //Number of Slots in the Crafting Grid + public static int StorageSlotNumber = 16; //Number of slots in storage area + public static int ToolSlotNumber = 5; // Number of slots in the tool area up top + public static int InOutputSlotNumber = InputSlotNumber + StorageSlotNumber + ToolSlotNumber + HoloSlotNumber; //Same plus Output Slot + public static int InventorySlotNumber = 36; //Inventory Slots (Inventory and Hotbar) + public static int InventoryOutSlotNumber = InventorySlotNumber + 1; //Inventory Slot Number + Output + public static int FullSlotNumber = InventorySlotNumber + InOutputSlotNumber; //All slots + + private final int slotOutput = 0; + private final int[] slotHolo = new int[5]; + private final int[] slotCrafting = new int[9]; + private final int[] slotStorage = new int[16]; + private final int[] slotTools = new int[5]; + + public void moveCraftingToChest(){ + //Check Chest Space + for (int i=0;i<9;i++){ + if (this.craftMatrix.getStackInSlot(i) != null){ + for (int r=0;r<16;r++){ + if ((this.inventoryChest.getStackInSlot(r) == null) || ((this.inventoryChest.getStackInSlot(r).getItem() == this.craftMatrix.getStackInSlot(i).getItem()) && ((64-this.craftMatrix.getStackInSlot(i).stackSize) <= (64-this.craftMatrix.getStackInSlot(i).stackSize)))){ + this.inventoryChest.setInventorySlotContents(r, this.craftMatrix.getStackInSlot(i)); + this.craftMatrix.setInventorySlotContents(i, null); + break; + } + } + } + } + //For Each Space or already existing itemstack, move one itemstack or fill current partial stack + //Remove old itemstack or partial stack from crafting grid + } + + public void moveChestToCrafting(){ + //Check Crafting items and slots + for (int i=0;i<9;i++){ + if ((this.craftMatrix.getStackInSlot(i) == null) || (this.craftMatrix.getStackInSlot(i).stackSize > 0)){ + for (int r=0;r<16;r++){ + if (this.inventoryChest.getStackInSlot(r) != null){ + this.craftMatrix.setInventorySlotContents(i, this.craftMatrix.getStackInSlot(r)); + this.inventoryChest.setInventorySlotContents(r, null); + } + } + } + } + //For Each already existing itemstack, fill current partial stack + //Remove partial stack from chest area + } + + + public Container_Workbench(final InventoryPlayer inventory, final TileEntityWorkbench tile){ + this.tile_entity = tile; + this.inventoryChest = tile.inventoryChest; + this.inventoryTool = tile.inventoryTool; + this.inventoryHolo = tile.inventoryHolo; + //this.inventoryCrafting = tile.inventoryCrafting; + + int var6; + int var7; + this.worldObj = tile.getWorldObj(); + this.posX = tile.xCoord; + this.posY = tile.yCoord; + this.posZ = tile.zCoord; + + int o=0; + + //Output slot + this.addSlotToContainer(new SlotOutput(inventory.player, this.craftMatrix, tile.inventoryCraftResult, 0, 136, 64)); + //Util Slots + this.addSlotToContainer(new SlotBlueprint(this.inventoryHolo, 1, 136, 28)); //Blueprint + this.addSlotToContainer(new SlotNoInput(this.inventoryHolo, 2, 154, 28)); //Hopper + this.addSlotToContainer(new GT_Slot_Holo(this.inventoryHolo, 3, 154, 64, false, false, 64)); //Parking + //Holo Slots + this.addSlotToContainer(new GT_Slot_Holo(this.inventoryHolo, 4, 154, 46, false, false, 1)); + this.addSlotToContainer(new GT_Slot_Holo(this.inventoryHolo, 5, 136, 46, false, false, 1)); + + for (int i=1; i<6; i++){ + this.slotHolo[o] = o+1; + o++; + } + + o=0; + + this.updateCraftingMatrix(); + + //Crafting Grid + for (var6 = 0; var6 < 3; ++var6) + { + for (var7 = 0; var7 < 3; ++var7) + { + //this.addSlotToContainer(new Slot(this.craftMatrix, var7 + (var6 * 3), 82 + (var7 * 18), 28 + (var6 * 18))); + + /*if (this.inventoryCrafting.getStackInSlot(o) != null){ + this.craftMatrix.setInventorySlotContents(o, inventoryCrafting.getStackInSlot(o)); + this.inventoryCrafting.setInventorySlotContents(o, null); + } */ + this.slotCrafting[o] = o+6; + o++; + } + } + + o=0; + + //Storage Side + for (var6 = 0; var6 < 4; ++var6) + { + for (var7 = 0; var7 < 4; ++var7) + { + //Utils.LOG_WARNING("Adding slots at var:"+(var7 + var6 * 4)+" x:"+(8 + var7 * 18)+" y:"+(7 + var6 * 18)); + this.addSlotToContainer(new Slot(this.inventoryChest, var7 + (var6 * 4), 8 + (var7 * 18), 7 + (var6 * 18))); + this.slotStorage[o] = o+15; + o++; + } + } + + o=0; + + //Tool Slots + for (var6 = 0; var6 < 1; ++var6) + { + for (var7 = 0; var7 < 5; ++var7) + { + this.addSlotToContainer(new SlotGtTool(this.inventoryTool, var7 + (var6 * 3), 82 + (var7 * 18), 8 + (var6 * 18))); + this.slotTools[o] = o+31; + o++; + } + } + + //Player Inventory + for (var6 = 0; var6 < 3; ++var6) + { + for (var7 = 0; var7 < 9; ++var7) + { + this.addSlotToContainer(new Slot(inventory, var7 + (var6 * 9) + 9, 8 + (var7 * 18), 84 + (var6 * 18))); + } + } + + //Player Hotbar + for (var6 = 0; var6 < 9; ++var6) + { + this.addSlotToContainer(new Slot(inventory, var6, 8 + (var6 * 18), 142)); + } + + this.onCraftMatrixChanged(this.craftMatrix); + + } + + @Override + public ItemStack slotClick(final int aSlotIndex, final int aMouseclick, final int aShifthold, final EntityPlayer aPlayer){ + + if (!aPlayer.worldObj.isRemote){ + if ((aSlotIndex == 999) || (aSlotIndex == -999)){ + //Utils.LOG_WARNING("??? - "+aSlotIndex); + } + + if (aSlotIndex == this.slotOutput){ + Logger.WARNING("Player Clicked on the output slot"); + //TODO + } + + for (final int x : this.slotHolo){ + if (aSlotIndex == x){ + Logger.WARNING("Player Clicked slot "+aSlotIndex+" in the Holo Grid"); + if (x == 1){ + Logger.WARNING("Player Clicked Blueprint slot in the Holo Grid"); + } + else if (x == 2){ + Logger.WARNING("Player Clicked Right Arrow slot in the Holo Grid"); + if (this.inventoryHolo.getStackInSlot(1) != null){ + Logger.WARNING("Found an ItemStack."); + if (this.inventoryHolo.getStackInSlot(1).getItem() instanceof IItemBlueprint){ + Logger.WARNING("Found a blueprint."); + final ItemStack tempBlueprint = this.inventoryHolo.getStackInSlot(1); + final ItemBlueprint tempItemBlueprint = (ItemBlueprint) tempBlueprint.getItem(); + if ((this.inventoryHolo.getStackInSlot(0) != null) && !tempItemBlueprint.hasBlueprint(tempBlueprint)){ + Logger.WARNING("Output slot was not empty."); + Logger.WARNING("Trying to manipulate NBT data on the blueprint stack, then replace it with the new one."); + tempItemBlueprint.setBlueprint(this.inventoryHolo.getStackInSlot(1), this.craftMatrix, this.inventoryHolo.getStackInSlot(0)); + final ItemStack newTempBlueprint = ItemUtils.getSimpleStack(tempItemBlueprint); + this.inventoryHolo.setInventorySlotContents(1, newTempBlueprint); + Logger.WARNING(ItemUtils.getArrayStackNames(tempItemBlueprint.getBlueprint(newTempBlueprint))); + } + else { + if (tempItemBlueprint.hasBlueprint(tempBlueprint)){ + Logger.WARNING("Blueprint already holds a recipe."); + } + else { + Logger.WARNING("Output slot was empty."); + } + } + } + else { + Logger.WARNING("ItemStack found was not a blueprint."); + } + } + else { + Logger.WARNING("No ItemStack found in Blueprint slot."); + } + } + else if (x == 3){ + Logger.WARNING("Player Clicked Big [P] slot in the Holo Grid"); + } + else if (x == 4){ + Logger.WARNING("Player Clicked Transfer to Crafting Grid slot in the Holo Grid"); + } + else if (x == 5){ + Logger.WARNING("Player Clicked Transfer to Storage Grid slot in the Holo Grid"); + } + } + } + + for (final int x : this.slotCrafting){ + if (aSlotIndex == x){ + Logger.WARNING("Player Clicked slot "+aSlotIndex+" in the crafting Grid"); + } + } + for (final int x : this.slotStorage){ + if (aSlotIndex == x){ + Logger.WARNING("Player Clicked slot "+aSlotIndex+" in the storage Grid"); + } + } + for (final int x : this.slotTools){ + if (aSlotIndex == x){ + Logger.WARNING("Player Clicked slot "+aSlotIndex+" in the tool Grid"); + } + } + } + //Utils.LOG_WARNING("Player Clicked slot "+aSlotIndex+" in the Grid"); + return super.slotClick(aSlotIndex, aMouseclick, aShifthold, aPlayer); + } + + private void updateCraftingMatrix() { + for (int i = 0; i < this.craftMatrix.getSizeInventory(); i++) { + //this.craftMatrix.setInventorySlotContents(i, this.tile_entity.inventoryCrafting.getStackInSlot(i)); + } + } + + @Override + public void onCraftMatrixChanged(final IInventory iiventory) { + this.tile_entity.inventoryCraftResult.setInventorySlotContents(0, CraftingManager.getInstance().findMatchingRecipe(this.craftMatrix, this.worldObj)); + } + + @Override + public void onContainerClosed(final EntityPlayer par1EntityPlayer) + { + super.onContainerClosed(par1EntityPlayer); + this.saveCraftingMatrix(); + } + + private void saveCraftingMatrix() { + for (int i = 0; i < this.craftMatrix.getSizeInventory(); i++) { + //this.tile_entity.inventoryCrafting.setInventorySlotContents(i, this.craftMatrix.getStackInSlot(i)); + } + } + + + + + /*@Override + public void onCraftMatrixChanged(IInventory par1IInventory){ + //Custom Recipe Handler + //craftResult.setInventorySlotContents(0, Workbench_CraftingHandler.getInstance().findMatchingRecipe(craftMatrix, worldObj)); + + //Vanilla CraftingManager + Utils.LOG_WARNING("checking crafting grid for a valid output."); + ItemStack temp = CraftingManager.getInstance().findMatchingRecipe(craftMatrix, worldObj); + if (temp != null){ + Utils.LOG_WARNING("Output found. "+temp.getDisplayName()+" x"+temp.stackSize); + craftResult.setInventorySlotContents(slotOutput, temp); + } + else { + Utils.LOG_WARNING("No Valid output found."); + craftResult.setInventorySlotContents(slotOutput, null); + } + }*/ + + /*@Override + public void onContainerClosed(EntityPlayer par1EntityPlayer) + { + for (int o=0; o= InOutputSlotNumber) && (par2 < InventoryOutSlotNumber)) + { + if (!this.mergeItemStack(var5, InventoryOutSlotNumber, FullSlotNumber, false)) + { + return null; + } + } + else if ((par2 >= InventoryOutSlotNumber) && (par2 < FullSlotNumber)) + { + if (!this.mergeItemStack(var5, InOutputSlotNumber, InventoryOutSlotNumber, false)) + { + return null; + } + } + else if (!this.mergeItemStack(var5, InOutputSlotNumber, FullSlotNumber, false)) + { + return null; + } + + if (var5.stackSize == 0) + { + var4.putStack((ItemStack)null); + } + else + { + var4.onSlotChanged(); + } + + if (var5.stackSize == var3.stackSize) + { + return null; + } + + var4.onPickupFromSlot(par1EntityPlayer, var5); + } + + return var3; + } + + //Can merge Slot + @Override + public boolean func_94530_a(final ItemStack p_94530_1_, final Slot p_94530_2_) { + return (p_94530_2_.inventory != this.tile_entity.inventoryCraftResult) && super.func_94530_a(p_94530_1_, p_94530_2_); + } + + +} \ No newline at end of file diff --git a/src/main/java/gtPlusPlus/core/container/Container_WorkbenchAdvanced.java b/src/main/java/gtPlusPlus/core/container/Container_WorkbenchAdvanced.java new file mode 100644 index 0000000000..dc499c570f --- /dev/null +++ b/src/main/java/gtPlusPlus/core/container/Container_WorkbenchAdvanced.java @@ -0,0 +1,377 @@ +package gtPlusPlus.core.container; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.*; +import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.CraftingManager; +import net.minecraft.world.World; + +import gregtech.api.gui.GT_Slot_Holo; + +import gtPlusPlus.api.objects.Logger; +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.interfaces.IItemBlueprint; +import gtPlusPlus.core.inventories.*; +import gtPlusPlus.core.item.general.ItemBlueprint; +import gtPlusPlus.core.slots.*; +import gtPlusPlus.core.tileentities.machines.TileEntityWorkbenchAdvanced; +import gtPlusPlus.core.util.minecraft.ItemUtils; + +public class Container_WorkbenchAdvanced extends Container { + + protected TileEntityWorkbenchAdvanced tile_entity; + public InventoryCrafting craftMatrix = new InventoryCrafting(this, 3, 3); + public final InventoryWorkbenchChest inventoryChest; + public final InventoryWorkbenchToolsElectric inventoryTool; + public final InventoryWorkbenchHoloSlots inventoryHolo; + public final InventoryWorkbenchHoloCrafting inventoryCrafting; + + private final World worldObj; + private final int posX; + private final int posY; + private final int posZ; + + public static int HoloSlotNumber = 6; + public static int InputSlotNumber = 9; //Number of Slots in the Crafting Grid + public static int StorageSlotNumber = 16; //Number of slots in storage area + public static int ToolSlotNumber = 5; // Number of slots in the tool area up top + public static int InOutputSlotNumber = InputSlotNumber + StorageSlotNumber + ToolSlotNumber + HoloSlotNumber; //Same plus Output Slot + public static int InventorySlotNumber = 36; //Inventory Slots (Inventory and Hotbar) + public static int InventoryOutSlotNumber = InventorySlotNumber + 1; //Inventory Slot Number + Output + public static int FullSlotNumber = InventorySlotNumber + InOutputSlotNumber; //All slots + + private final int slotOutput = 0; + private final int[] slotHolo = new int[5]; + private final int[] slotCrafting = new int[9]; + private final int[] slotStorage = new int[16]; + private final int[] slotTools = new int[5]; + + public Container_WorkbenchAdvanced(final InventoryPlayer inventory, final TileEntityWorkbenchAdvanced tile){ + this.tile_entity = tile; + this.inventoryChest = tile.inventoryChest; + this.inventoryTool = tile.inventoryTool; + this.inventoryHolo = tile.inventoryHolo; + this.inventoryCrafting = tile.inventoryCrafting; + + int var6; + int var7; + this.worldObj = tile.getWorldObj(); + this.posX = tile.xCoord; + this.posY = tile.yCoord; + this.posZ = tile.zCoord; + + int o=0; + + //Output slot + this.addSlotToContainer(new SlotOutput(inventory.player, this.craftMatrix, tile.inventoryCraftResult, 0, 136, 64)); + //Util Slots + this.addSlotToContainer(new SlotBlueprint(this.inventoryHolo, 1, 136, 28)); //Blueprint + this.addSlotToContainer(new SlotNoInput(this.inventoryHolo, 2, 154, 28)); //Hopper + this.addSlotToContainer(new GT_Slot_Holo(this.inventoryHolo, 3, 154, 64, false, false, 64)); //Parking + //Holo Slots + this.addSlotToContainer(new GT_Slot_Holo(this.inventoryHolo, 4, 154, 46, false, false, 1)); + this.addSlotToContainer(new GT_Slot_Holo(this.inventoryHolo, 5, 136, 46, false, false, 1)); + + for (int i=1; i<6; i++){ + this.slotHolo[o] = o+1; + o++; + } + + o=0; + + this.updateCraftingMatrix(); + + //Crafting Grid + for (var6 = 0; var6 < 3; ++var6) + { + for (var7 = 0; var7 < 3; ++var7) + { + this.addSlotToContainer(new Slot(this.craftMatrix, var7 + (var6 * 3), 82 + (var7 * 18), 28 + (var6 * 18))); + + /*if (this.inventoryCrafting.getStackInSlot(o) != null){ + this.craftMatrix.setInventorySlotContents(o, inventoryCrafting.getStackInSlot(o)); + this.inventoryCrafting.setInventorySlotContents(o, null); + } */ + this.slotCrafting[o] = o+6; + o++; + } + } + + o=0; + + //Storage Side + for (var6 = 0; var6 < 4; ++var6) + { + for (var7 = 0; var7 < 4; ++var7) + { + //Utils.LOG_WARNING("Adding slots at var:"+(var7 + var6 * 4)+" x:"+(8 + var7 * 18)+" y:"+(7 + var6 * 18)); + this.addSlotToContainer(new Slot(this.inventoryChest, var7 + (var6 * 4), 8 + (var7 * 18), 7 + (var6 * 18))); + this.slotStorage[o] = o+15; + o++; + } + } + + o=0; + + //Tool Slots + for (var6 = 0; var6 < 1; ++var6) + { + for (var7 = 0; var7 < 5; ++var7) + { + this.addSlotToContainer(new SlotGtToolElectric(this.inventoryTool, var7 + (var6 * 3), 82 + (var7 * 18), 8 + (var6 * 18), 3, false)); + this.slotTools[o] = o+31; + o++; + } + } + + //Player Inventory + for (var6 = 0; var6 < 3; ++var6) + { + for (var7 = 0; var7 < 9; ++var7) + { + this.addSlotToContainer(new Slot(inventory, var7 + (var6 * 9) + 9, 8 + (var7 * 18), 84 + (var6 * 18))); + } + } + + //Player Hotbar + for (var6 = 0; var6 < 9; ++var6) + { + this.addSlotToContainer(new Slot(inventory, var6, 8 + (var6 * 18), 142)); + } + + this.onCraftMatrixChanged(this.craftMatrix); + + } + + @Override + public ItemStack slotClick(final int aSlotIndex, final int aMouseclick, final int aShifthold, final EntityPlayer aPlayer){ + + if (!aPlayer.worldObj.isRemote){ + if ((aSlotIndex == 999) || (aSlotIndex == -999)){ + //Utils.LOG_WARNING("??? - "+aSlotIndex); + } + + if (aSlotIndex == this.slotOutput){ + Logger.WARNING("Player Clicked on the output slot"); + //TODO + } + + for (final int x : this.slotHolo){ + if (aSlotIndex == x){ + Logger.WARNING("Player Clicked slot "+aSlotIndex+" in the Holo Grid"); + if (x == 1){ + Logger.WARNING("Player Clicked Blueprint slot in the Holo Grid"); + } + else if (x == 2){ + Logger.WARNING("Player Clicked Right Arrow slot in the Holo Grid"); + if (this.inventoryHolo.getStackInSlot(1) != null){ + Logger.WARNING("Found an ItemStack."); + if (this.inventoryHolo.getStackInSlot(1).getItem() instanceof IItemBlueprint){ + Logger.WARNING("Found a blueprint."); + final ItemStack tempBlueprint = this.inventoryHolo.getStackInSlot(1); + final ItemBlueprint tempItemBlueprint = (ItemBlueprint) tempBlueprint.getItem(); + if ((this.inventoryHolo.getStackInSlot(0) != null) && !tempItemBlueprint.hasBlueprint(tempBlueprint)){ + Logger.WARNING("Output slot was not empty."); + Logger.WARNING("Trying to manipulate NBT data on the blueprint stack, then replace it with the new one."); + tempItemBlueprint.setBlueprint(this.inventoryHolo.getStackInSlot(1), this.craftMatrix, this.inventoryHolo.getStackInSlot(0)); + final ItemStack newTempBlueprint = ItemUtils.getSimpleStack(tempItemBlueprint); + this.inventoryHolo.setInventorySlotContents(1, newTempBlueprint); + Logger.WARNING(ItemUtils.getArrayStackNames(tempItemBlueprint.getBlueprint(newTempBlueprint))); + } + else { + if (tempItemBlueprint.hasBlueprint(tempBlueprint)){ + Logger.WARNING("Blueprint already holds a recipe."); + } + else { + Logger.WARNING("Output slot was empty."); + } + } + } + else { + Logger.WARNING("ItemStack found was not a blueprint."); + } + } + else { + Logger.WARNING("No ItemStack found in Blueprint slot."); + } + } + else if (x == 3){ + Logger.WARNING("Player Clicked Big [P] slot in the Holo Grid"); + } + else if (x == 4){ + Logger.WARNING("Player Clicked Transfer to Crafting Grid slot in the Holo Grid"); + } + else if (x == 5){ + Logger.WARNING("Player Clicked Transfer to Storage Grid slot in the Holo Grid"); + } + } + } + + for (final int x : this.slotCrafting){ + if (aSlotIndex == x){ + Logger.WARNING("Player Clicked slot "+aSlotIndex+" in the crafting Grid"); + } + } + for (final int x : this.slotStorage){ + if (aSlotIndex == x){ + Logger.WARNING("Player Clicked slot "+aSlotIndex+" in the storage Grid"); + } + } + for (final int x : this.slotTools){ + if (aSlotIndex == x){ + Logger.WARNING("Player Clicked slot "+aSlotIndex+" in the tool Grid"); + } + } + } + //Utils.LOG_WARNING("Player Clicked slot "+aSlotIndex+" in the Grid"); + return super.slotClick(aSlotIndex, aMouseclick, aShifthold, aPlayer); + } + + private void updateCraftingMatrix() { + for (int i = 0; i < this.craftMatrix.getSizeInventory(); i++) { + this.craftMatrix.setInventorySlotContents(i, this.tile_entity.inventoryCrafting.getStackInSlot(i)); + } + } + + @Override + public void onCraftMatrixChanged(final IInventory iiventory) { + this.tile_entity.inventoryCraftResult.setInventorySlotContents(0, CraftingManager.getInstance().findMatchingRecipe(this.craftMatrix, this.worldObj)); + } + + @Override + public void onContainerClosed(final EntityPlayer par1EntityPlayer) + { + super.onContainerClosed(par1EntityPlayer); + this.saveCraftingMatrix(); + } + + private void saveCraftingMatrix() { + for (int i = 0; i < this.craftMatrix.getSizeInventory(); i++) { + this.tile_entity.inventoryCrafting.setInventorySlotContents(i, this.craftMatrix.getStackInSlot(i)); + } + } + + + + + /*@Override + public void onCraftMatrixChanged(IInventory par1IInventory){ + //Custom Recipe Handler + //craftResult.setInventorySlotContents(0, Workbench_CraftingHandler.getInstance().findMatchingRecipe(craftMatrix, worldObj)); + + //Vanilla CraftingManager + Utils.LOG_WARNING("checking crafting grid for a valid output."); + ItemStack temp = CraftingManager.getInstance().findMatchingRecipe(craftMatrix, worldObj); + if (temp != null){ + Utils.LOG_WARNING("Output found. "+temp.getDisplayName()+" x"+temp.stackSize); + craftResult.setInventorySlotContents(slotOutput, temp); + } + else { + Utils.LOG_WARNING("No Valid output found."); + craftResult.setInventorySlotContents(slotOutput, null); + } + }*/ + + /*@Override + public void onContainerClosed(EntityPlayer par1EntityPlayer) + { + for (int o=0; o= InOutputSlotNumber) && (par2 < InventoryOutSlotNumber)) + { + if (!this.mergeItemStack(var5, InventoryOutSlotNumber, FullSlotNumber, false)) + { + return null; + } + } + else if ((par2 >= InventoryOutSlotNumber) && (par2 < FullSlotNumber)) + { + if (!this.mergeItemStack(var5, InOutputSlotNumber, InventoryOutSlotNumber, false)) + { + return null; + } + } + else if (!this.mergeItemStack(var5, InOutputSlotNumber, FullSlotNumber, false)) + { + return null; + } + + if (var5.stackSize == 0) + { + var4.putStack((ItemStack)null); + } + else + { + var4.onSlotChanged(); + } + + if (var5.stackSize == var3.stackSize) + { + return null; + } + + var4.onPickupFromSlot(par1EntityPlayer, var5); + } + + return var3; + } + + //Can merge Slot + @Override + public boolean func_94530_a(final ItemStack p_94530_1_, final Slot p_94530_2_) { + return (p_94530_2_.inventory != this.tile_entity.inventoryCraftResult) && super.func_94530_a(p_94530_1_, p_94530_2_); + } + + +} \ No newline at end of file diff --git a/src/main/java/gtPlusPlus/core/container/box/LunchBoxContainer.java b/src/main/java/gtPlusPlus/core/container/box/LunchBoxContainer.java new file mode 100644 index 0000000000..8e56c661f2 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/container/box/LunchBoxContainer.java @@ -0,0 +1,13 @@ +package gtPlusPlus.core.container.box; + +import gtPlusPlus.core.item.tool.misc.box.ContainerBoxBase; +import gtPlusPlus.core.item.tool.misc.box.CustomBoxInventory; +import gtPlusPlus.core.slots.SlotLunchBox; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; + +public class LunchBoxContainer extends ContainerBoxBase { + public LunchBoxContainer(EntityPlayer par1Player, InventoryPlayer inventoryPlayer, CustomBoxInventory CustomBoxInventory) { + super(par1Player, inventoryPlayer, CustomBoxInventory, SlotLunchBox.class, gtPlusPlus.core.item.tool.misc.box.AutoLunchBox.SLOTS); + } +} diff --git a/src/main/java/gtPlusPlus/core/container/box/MagicBagContainer.java b/src/main/java/gtPlusPlus/core/container/box/MagicBagContainer.java new file mode 100644 index 0000000000..7820d56814 --- /dev/null +++ b/src/main/java/gtPlusPlus/core/container/box/MagicBagContainer.java @@ -0,0 +1,13 @@ +package gtPlusPlus.core.container.box; + +import gtPlusPlus.core.item.tool.misc.box.ContainerBoxBase; +import gtPlusPlus.core.item.tool.misc.box.CustomBoxInventory; +import gtPlusPlus.core.slots.SlotMagicToolBag; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; + +public class MagicBagContainer extends ContainerBoxBase { + public MagicBagContainer(EntityPlayer par1Player, InventoryPlayer inventoryPlayer, CustomBoxInventory CustomBoxInventory) { + super(par1Player, inventoryPlayer, CustomBoxInventory, SlotMagicToolBag.class, gtPlusPlus.core.item.tool.misc.box.MagicToolBag.SLOTS); + } +} diff --git a/src/main/java/gtPlusPlus/core/container/box/ToolBoxContainer.java b/src/main/java/gtPlusPlus/core/container/box/ToolBoxContainer.java new file mode 100644 index 0000000000..49719aa9ba --- /dev/null +++ b/src/main/java/gtPlusPlus/core/container/box/ToolBoxContainer.java @@ -0,0 +1,15 @@ +package gtPlusPlus.core.container.box; + +import gtPlusPlus.core.item.tool.misc.box.ContainerBoxBase; +import gtPlusPlus.core.item.tool.misc.box.CustomBoxInventory; +import gtPlusPlus.core.item.tool.misc.box.UniversalToolBox; +import gtPlusPlus.core.slots.SlotToolBox; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; + +public class ToolBoxContainer extends ContainerBoxBase { + public ToolBoxContainer(EntityPlayer par1Player, InventoryPlayer inventoryPlayer, + CustomBoxInventory CustomBoxInventory) { + super(par1Player, inventoryPlayer, CustomBoxInventory, SlotToolBox.class, UniversalToolBox.SLOTS); + } +} -- cgit From 6e8a40242fcd7fd85a99009e5bc626972c8fa0d8 Mon Sep 17 00:00:00 2001 From: Alkalus <3060479+draknyte1@users.noreply.github.com> Date: Mon, 27 Dec 2021 02:50:29 +0000 Subject: Updated Build Script. Fixed Volumetric Flask Configurator not working. Fixed recipe for Reservoir Hatch. --- build.gradle | 113 ++++++-- .../core/block/machine/VolumetricFlaskSetter.java | 7 +- .../container/Container_VolumetricFlaskSetter.java | 9 +- .../gui/machine/GUI_VolumetricFlaskSetter.java | 283 ++++++++++++++------- .../gtPlusPlus/core/gui/widget/GuiValueField.java | 100 ++++---- .../gtPlusPlus/core/recipe/RECIPES_Machines.java | 2 +- .../general/TileEntityVolumetricFlaskSetter.java | 22 +- .../loaders/RecipeGen_BlastSmelterGT_Ex.java | 6 +- 8 files changed, 354 insertions(+), 188 deletions(-) (limited to 'src/main/java/gtPlusPlus/core/container') diff --git a/build.gradle b/build.gradle index 18fedd355e..43dfa37748 100644 --- a/build.gradle +++ b/build.gradle @@ -1,4 +1,4 @@ -//version: 928ecf7feb33a1149538b0e2cd17e3bc5f281428 +//version: 8fa7883b6196c1765266f4e6ddf3118d5043aafb /* DO NOT CHANGE THIS FILE! @@ -42,6 +42,7 @@ plugins { id("org.ajoberstar.grgit") version("3.1.1") id("com.github.johnrengelman.shadow") version("4.0.4") id("com.palantir.git-version") version("0.12.3") + id("maven-publish") } apply plugin: 'forge' @@ -194,7 +195,9 @@ if(file("addon.gradle").exists()) { apply from: 'repositories.gradle' configurations { - implementation.extendsFrom(shadowImplementation) + implementation.extendsFrom(shadowImplementation) // TODO: remove after all uses are refactored + implementation.extendsFrom(shadowCompile) + implementation.extendsFrom(shadeCompile) } repositories { @@ -260,16 +263,28 @@ task relocateShadowJar(type: ConfigureShadowRelocation) { } shadowJar { + project.configurations.shadeCompile.each { dep -> + from(project.zipTree(dep)) { + exclude 'META-INF', 'META-INF/**' + } + } + manifest { attributes(getManifestAttributes()) } minimize() // This will only allow shading for actually used classes - configurations = [project.configurations.shadowImplementation] + configurations = [project.configurations.shadowImplementation, project.configurations.shadowCompile] dependsOn(relocateShadowJar) } jar { + project.configurations.shadeCompile.each { dep -> + from(project.zipTree(dep)) { + exclude 'META-INF', 'META-INF/**' + } + } + manifest { attributes(getManifestAttributes()) } @@ -343,31 +358,31 @@ tasks.withType(JavaExec).configureEach { } processResources - { - // this will ensure that this task is redone when the versions change. - inputs.property "version", project.version - inputs.property "mcversion", project.minecraft.version - - // replace stuff in mcmod.info, nothing else - from(sourceSets.main.resources.srcDirs) { - include 'mcmod.info' - - // replace version and mcversion - expand "minecraftVersion": project.minecraft.version, - "modVersion": versionDetails().lastTag, - "modId": modId, - "modName": modName - } +{ + // this will ensure that this task is redone when the versions change. + inputs.property "version", project.version + inputs.property "mcversion", project.minecraft.version - if(usesMixins.toBoolean()) { - from refMap - } + // replace stuff in mcmod.info, nothing else + from(sourceSets.main.resources.srcDirs) { + include 'mcmod.info' - // copy everything else, thats not the mcmod.info - from(sourceSets.main.resources.srcDirs) { - exclude 'mcmod.info' - } - } + // replace version and mcversion + expand "minecraftVersion": project.minecraft.version, + "modVersion": versionDetails().lastTag, + "modId": modId, + "modName": modName + } + + if(usesMixins.toBoolean()) { + from refMap + } + + // copy everything else, thats not the mcmod.info + from(sourceSets.main.resources.srcDirs) { + exclude 'mcmod.info' + } +} def getManifestAttributes() { def manifestAttributes = [:] @@ -400,6 +415,12 @@ task sourcesJar(type: Jar) { } task shadowDevJar(type: ShadowJar) { + project.configurations.shadeCompile.each { dep -> + from(project.zipTree(dep)) { + exclude 'META-INF', 'META-INF/**' + } + } + from sourceSets.main.output getArchiveClassifier().set("dev") @@ -408,7 +429,7 @@ task shadowDevJar(type: ShadowJar) { } minimize() // This will only allow shading for actually used classes - configurations = [project.configurations.shadowImplementation] + configurations = [project.configurations.shadowImplementation, project.configurations.shadowCompile] } task relocateShadowDevJar(type: ConfigureShadowRelocation) { @@ -423,6 +444,12 @@ task circularResolverJar(type: Jar) { } task devJar(type: Jar) { + project.configurations.shadeCompile.each { dep -> + from(project.zipTree(dep)) { + exclude 'META-INF', 'META-INF/**' + } + } + from sourceSets.main.output getArchiveClassifier().set("dev") @@ -460,6 +487,38 @@ artifacts { } } +// publishing +publishing { + publications { + maven(MavenPublication) { + artifact source: jar + artifact source: sourcesJar, classifier: "src" + artifact source: devJar, classifier: "dev" + if (apiPackage) { + artifact source: apiJar, classifier: "api" + } + + groupId = System.getenv("ARTIFACT_GROUP_ID") ?: group + artifactId = System.getenv("ARTIFACT_ID") ?: project.name + version = System.getenv("ARTIFACT_VERSION") ?: project.version + } + } + + repositories { + maven { + String owner = System.getenv("REPOSITORY_OWNER") ?: "Unknown" + String repositoryName = System.getenv("REPOSITORY_NAME") ?: "Unknown" + String githubRepositoryUrl = "https://maven.pkg.github.com/$owner/$repositoryName" + name = "GitHubPackages" + url = githubRepositoryUrl + credentials { + username = System.getenv("GITHUB_ACTOR") ?: "NONE" + password = System.getenv("GITHUB_TOKEN") ?: "NONE" + } + } + } +} + // Updating task updateBuildScript { doLast { diff --git a/src/main/java/gtPlusPlus/core/block/machine/VolumetricFlaskSetter.java b/src/main/java/gtPlusPlus/core/block/machine/VolumetricFlaskSetter.java index 36ea2af7cc..90f9c1056a 100644 --- a/src/main/java/gtPlusPlus/core/block/machine/VolumetricFlaskSetter.java +++ b/src/main/java/gtPlusPlus/core/block/machine/VolumetricFlaskSetter.java @@ -92,12 +92,7 @@ public class VolumetricFlaskSetter extends BasicTileBlockWithTooltip { @Override public int getRenderBlockPass() { - return 1; - } - - @Override - public boolean isOpaqueCube() { - return false; + return 0; } @Override diff --git a/src/main/java/gtPlusPlus/core/container/Container_VolumetricFlaskSetter.java b/src/main/java/gtPlusPlus/core/container/Container_VolumetricFlaskSetter.java index de3106c957..65e84d7272 100644 --- a/src/main/java/gtPlusPlus/core/container/Container_VolumetricFlaskSetter.java +++ b/src/main/java/gtPlusPlus/core/container/Container_VolumetricFlaskSetter.java @@ -4,6 +4,7 @@ import java.util.Iterator; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import gtPlusPlus.api.objects.Logger; import gtPlusPlus.core.block.ModBlocks; import gtPlusPlus.core.inventories.Inventory_VolumetricFlaskSetter; import gtPlusPlus.core.slots.SlotNoInput; @@ -24,8 +25,8 @@ public class Container_VolumetricFlaskSetter extends Container { public final Inventory_VolumetricFlaskSetter inventoryChest; - public short mCustomValue; - private short oCustomValue; + public int mCustomValue; + private int oCustomValue; private int mTimer; @@ -181,5 +182,9 @@ public class Container_VolumetricFlaskSetter extends Container { break; } } + + public void log(String aString) { + Logger.INFO("[Flask-Container] "+aString); + } } \ No newline at end of file diff --git a/src/main/java/gtPlusPlus/core/gui/machine/GUI_VolumetricFlaskSetter.java b/src/main/java/gtPlusPlus/core/gui/machine/GUI_VolumetricFlaskSetter.java index 0257e51d0c..512f31dd47 100644 --- a/src/main/java/gtPlusPlus/core/gui/machine/GUI_VolumetricFlaskSetter.java +++ b/src/main/java/gtPlusPlus/core/gui/machine/GUI_VolumetricFlaskSetter.java @@ -5,13 +5,13 @@ import org.lwjgl.opengl.GL11; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import gtPlusPlus.api.objects.Logger; import gtPlusPlus.core.container.Container_VolumetricFlaskSetter; import gtPlusPlus.core.gui.widget.GuiValueField; import gtPlusPlus.core.handler.PacketHandler; import gtPlusPlus.core.lib.CORE; import gtPlusPlus.core.network.packet.Packet_VolumetricFlaskGui; import gtPlusPlus.core.tileentities.general.TileEntityVolumetricFlaskSetter; -import net.minecraft.client.gui.GuiTextField; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.client.resources.I18n; import net.minecraft.util.ResourceLocation; @@ -19,67 +19,203 @@ import net.minecraft.util.ResourceLocation; @SideOnly(Side.CLIENT) public class GUI_VolumetricFlaskSetter extends GuiContainer { - private GuiTextField mText; + private static final ResourceLocation mGuiTextures = new ResourceLocation( + CORE.MODID, "textures/gui/VolumetricFlaskSetter.png" + ); + private Container_VolumetricFlaskSetter mContainer; private boolean mIsOpen = false; + private GuiValueField mText; private TileEntityVolumetricFlaskSetter mTile; - private Container_VolumetricFlaskSetter mContainer; - private static final ResourceLocation mGuiTextures = new ResourceLocation(CORE.MODID, "textures/gui/VolumetricFlaskSetter.png"); - public GUI_VolumetricFlaskSetter(Container_VolumetricFlaskSetter aContainer){ + public GUI_VolumetricFlaskSetter(Container_VolumetricFlaskSetter aContainer) { super(aContainer); mContainer = aContainer; mTile = mContainer.mTileEntity; } - public void initGui(){ + @Override + protected void drawGuiContainerBackgroundLayer(final float f, final int i, final int j) { + GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + this.mc.renderEngine.bindTexture(mGuiTextures); + final int x = (this.width - this.xSize) / 2; + final int y = (this.height - this.ySize) / 2; + this.drawTexturedModalRect(x, y, 0, 0, this.xSize, this.ySize); + } + + @Override + protected void drawGuiContainerForegroundLayer(final int i, final int j) { + super.drawGuiContainerForegroundLayer(i, j); + this.mText.drawTextBox(); + this.fontRendererObj.drawString( + I18n.format("container.VolumetricFlaskSetter", new Object[0]), 4, 3, 4210752 + ); + int aYVal = 49; + this.fontRendererObj.drawString( + I18n.format("0 = 16l", new Object[0]), 8, aYVal, 4210752 + ); + this.fontRendererObj.drawString( + I18n.format("4 = 576l", new Object[0]), 64, aYVal, 4210752 + ); + this.fontRendererObj.drawString( + I18n.format("1 = 36l", new Object[0]), 8, aYVal += 8, 4210752 + ); + this.fontRendererObj.drawString( + I18n.format("5 = 720l", new Object[0]), 64, aYVal, 4210752 + ); + this.fontRendererObj.drawString( + I18n.format("2 = 144l", new Object[0]), 8, aYVal += 8, 4210752 + ); + this.fontRendererObj.drawString( + I18n.format("6 = 864l", new Object[0]), 64, aYVal, 4210752 + ); + this.fontRendererObj.drawString( + I18n.format("3 = 432l", new Object[0]), 8, aYVal += 8, 4210752 + ); + this.fontRendererObj.drawString( + I18n.format("-> = Custom", new Object[0]), 59, aYVal, 4210752 + ); + + } + + public void drawScreen(int par1, int par2, float par3) { + this.drawDefaultBackground(); + super.drawScreen(par1, par2, par3); + } + + protected String getText() { + return this.mText.getText(); + } + + public void initGui() { super.initGui(); - Keyboard.enableRepeatEvents(true); + // Keyboard.enableRepeatEvents(true); mIsOpen = true; - this.mText = new GuiValueField(this.fontRendererObj, 26, 31, this.width / 2 - 62, this.height/2-52, 106, 14); + this.mText = new GuiValueField( + this.fontRendererObj, 26, 31, this.width / 2 + - 62, this.height / 2 - 52, 106, 14, this + ); mText.setMaxStringLength(5); mText.setEnableBackgroundDrawing(true); mText.setText("0"); mText.setFocused(true); } - protected void keyTyped(char par1, int par2){ + public boolean isNumber(char c) { + boolean isNum = ((c >= 48 && c <= 57) || c == 45); + if (isNum) { + log("Found Digit: "+c+" | char value"); + } + else { + switch (c) { + case '0' : + case '1' : + case '2' : + case '3' : + case '4' : + case '5' : + case '6' : + case '7' : + case '8' : + case '9' : + log("Found Digit: "+c+" | char switch"); + return true; + } + } + return isNum; + } + + public boolean isNumber(int c) { + switch (c) { + case Keyboard.KEY_0 : + case Keyboard.KEY_1 : + case Keyboard.KEY_2 : + case Keyboard.KEY_3 : + case Keyboard.KEY_4 : + case Keyboard.KEY_5 : + case Keyboard.KEY_6 : + case Keyboard.KEY_7 : + case Keyboard.KEY_8 : + case Keyboard.KEY_9 : + case Keyboard.KEY_NUMPAD0 : + case Keyboard.KEY_NUMPAD1 : + case Keyboard.KEY_NUMPAD2 : + case Keyboard.KEY_NUMPAD3 : + case Keyboard.KEY_NUMPAD4 : + case Keyboard.KEY_NUMPAD5 : + case Keyboard.KEY_NUMPAD6 : + case Keyboard.KEY_NUMPAD7 : + case Keyboard.KEY_NUMPAD8 : + case Keyboard.KEY_NUMPAD9 : + log("Found Digit: "+Keyboard.getKeyName(c)+" | LWJGL Keybinding"); + return true; + } + return false; + } + + protected void keyTyped(char par1, int par2) { if (mIsOpen) { + log("Pressed " + par1 + " | " + par2); if (mText.isFocused()) { + log("Text box has focus."); if (par2 == Keyboard.KEY_RETURN) { - if (mText.isFocused()) { - mText.setFocused(false); - } + log("Pressed Enter, unfocusing."); + mText.setFocused(false); } else if (par2 == Keyboard.KEY_BACK) { + log("Pressed Backspace."); String aCurrentText = getText(); if (aCurrentText.length() > 0) { - this.mText.setText(aCurrentText.substring(0, aCurrentText.length() - 1)); + this.mText.setText( + aCurrentText.substring( + 0, aCurrentText.length() - 1 + ) + ); if (getText().length() <= 0) { - this.mText.setText("0"); + setText(0); } sendUpdateToServer(); } } else { - if (isNumber(par1)) { - if (this.mText.getText().equals("0")) { - this.mText.setText(""+par1); + if (isNumber(par2) || isNumber(par1)) { + log("Pressed number."); + if (this.mText.getText().equals("0")) { + this.mText.textboxKeyTyped(par1, par2); sendUpdateToServer(); } else { - this.mText.textboxKeyTyped(par1, par2); - sendUpdateToServer(); + this.mText.textboxKeyTyped(par1, par2); + sendUpdateToServer(); } } else { - super.keyTyped(par1, par2); + log("Pressed unused key."); + super.keyTyped(par1, par2); } - } + } } else { - super.keyTyped(par1, par2); + log("Text box not focused."); + super.keyTyped(par1, par2); } } + else { + log("Gui is not open?"); + } + } + + protected void mouseClicked(int x, int y, int btn) { + if (mIsOpen) { + log("Clicked."); + this.mText.mouseClicked(x, y, btn); + if (!mText.didClickInTextField(x, y)) { + log("Did not click in text box, passing to super."); + super.mouseClicked(x, y, btn); + } + } + else { + log("Gui is not open?"); + } } @Override @@ -88,10 +224,29 @@ public class GUI_VolumetricFlaskSetter extends GuiContainer { mText.setEnabled(false); mText.setVisible(false); super.onGuiClosed(); - Keyboard.enableRepeatEvents(false); + // Keyboard.enableRepeatEvents(false); + } + + public int parse(String aValue) { + try { + return Integer.parseInt(getText()); + } + catch (NumberFormatException e) { + return 0; + } + } + + public void sendUpdateToServer() { + if (getText().length() > 0) { + PacketHandler.sendToServer(new Packet_VolumetricFlaskGui(mTile, parse(getText()))); + } + } + + public void setText(int aValue) { + this.mText.setText("" + aValue); } - public void updateScreen(){ + public void updateScreen() { super.updateScreen(); // Update Textbox to 0 if Empty if (getText().length() <= 0) { @@ -101,83 +256,19 @@ public class GUI_VolumetricFlaskSetter extends GuiContainer { this.mText.updateCursorCounter(); // Check TextBox Value is correct - short aCustomValue = 0; if (getText().length() > 0) { - try { - aCustomValue = Short.parseShort(getText()); - short aTileValue = ((Container_VolumetricFlaskSetter) mContainer).mCustomValue; - if (mContainer != null) { - if (aTileValue != aCustomValue){ - this.mText.setText(""+aTileValue); - } + int aCustomValue = parse(getText()); + int aTileValue = ((Container_VolumetricFlaskSetter) mContainer).mCustomValue; + if (mContainer != null) { + if (aTileValue != aCustomValue) { + setText(aTileValue); } - } catch (NumberFormatException ex) { - } - } - } - - public void drawScreen(int par1, int par2, float par3){ - this.drawDefaultBackground(); - super.drawScreen(par1, par2, par3); - - - } - - protected void mouseClicked(int x, int y, int btn) { - if (mIsOpen) { - super.mouseClicked(x, y, btn); - this.mText.mouseClicked(x, y, btn); } } - - - - @Override - protected void drawGuiContainerForegroundLayer(final int i, final int j){ - super.drawGuiContainerForegroundLayer(i, j); - this.mText.drawTextBox(); - this.fontRendererObj.drawString(I18n.format("container.VolumetricFlaskSetter", new Object[0]), 4, 3, 4210752); - int aYVal = 49; - this.fontRendererObj.drawString(I18n.format("0 = 16l", new Object[0]), 8, aYVal, 4210752); - this.fontRendererObj.drawString(I18n.format("4 = 576l", new Object[0]), 64, aYVal, 4210752); - this.fontRendererObj.drawString(I18n.format("1 = 36l", new Object[0]), 8, aYVal+=8, 4210752); - this.fontRendererObj.drawString(I18n.format("5 = 720l", new Object[0]), 64, aYVal, 4210752); - this.fontRendererObj.drawString(I18n.format("2 = 144l", new Object[0]), 8, aYVal+=8, 4210752); - this.fontRendererObj.drawString(I18n.format("6 = 864l", new Object[0]), 64, aYVal, 4210752); - this.fontRendererObj.drawString(I18n.format("3 = 432l", new Object[0]), 8, aYVal+=8, 4210752); - this.fontRendererObj.drawString(I18n.format("-> = Custom", new Object[0]), 59, aYVal, 4210752); - - } - - @Override - protected void drawGuiContainerBackgroundLayer(final float f, final int i, final int j){ - GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); - this.mc.renderEngine.bindTexture(mGuiTextures); - final int x = (this.width - this.xSize) / 2; - final int y = (this.height - this.ySize) / 2; - this.drawTexturedModalRect(x, y, 0, 0, this.xSize, this.ySize); - } - - public boolean isNumber(char c) { - return ((c >= 48 && c <= 57) || c == 45); - } - - protected String getText() { - return this.mText.getText(); - } - - protected void sendUpdateToServer() { - short aCustomValue = 0; - if (getText().length() > 0) { - try { - aCustomValue = Short.parseShort(getText()); - PacketHandler.sendToServer(new Packet_VolumetricFlaskGui(mTile, aCustomValue)); - } catch (NumberFormatException ex) { - - } - } + public void log(String aString) { + Logger.INFO("[Flask-GUI] "+aString); } -} \ No newline at end of file +} diff --git a/src/main/java/gtPlusPlus/core/gui/widget/GuiValueField.java b/src/main/java/gtPlusPlus/core/gui/widget/GuiValueField.java index ac4c1a8aee..c9c294ea1c 100644 --- a/src/main/java/gtPlusPlus/core/gui/widget/GuiValueField.java +++ b/src/main/java/gtPlusPlus/core/gui/widget/GuiValueField.java @@ -2,7 +2,9 @@ package gtPlusPlus.core.gui.widget; import java.lang.reflect.Field; +import gtPlusPlus.core.gui.machine.GUI_VolumetricFlaskSetter; import gtPlusPlus.core.util.reflect.ReflectionUtils; +import gtPlusPlus.preloader.DevHelper; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.GuiTextField; @@ -11,76 +13,86 @@ public class GuiValueField extends GuiTextField { private final FontRenderer mFontRenderer; private final int mScreenLocationX; private final int mScreenLocationY; - - public GuiValueField(FontRenderer aFontRenderer, int aX, int aY, int aScreenLocationX, int aScreenLocationY, int aWidth, int aHeight) { + private final GUI_VolumetricFlaskSetter mGUI; + + public GuiValueField(FontRenderer aFontRenderer, int aX, int aY, int aScreenLocationX, int aScreenLocationY, int aWidth, int aHeight, GUI_VolumetricFlaskSetter aGUI) { super(aFontRenderer, aX, aY, aWidth, aHeight); mFontRenderer = aFontRenderer; mScreenLocationX = aScreenLocationX; mScreenLocationY = aScreenLocationY; + mGUI = aGUI; } - - public boolean canLoseFocus() { - Field canLoseFocus = ReflectionUtils.getField(GuiTextField.class, "canLoseFocus"); + + public boolean canLoseFocus() { + Field canLoseFocus = ReflectionUtils.getField(GuiTextField.class, DevHelper.isObfuscatedEnvironment() ? "field_146212_n" : "canLoseFocus"); if (canLoseFocus != null) { return (boolean) ReflectionUtils.getFieldValue(canLoseFocus, this); } return true; } - + + @Override public boolean isFocused() { - Field isFocused = ReflectionUtils.getField(GuiTextField.class, "isFocused"); - if (isFocused != null) { - return (boolean) ReflectionUtils.getFieldValue(isFocused, this); - } - return false; + return super.isFocused(); } - + public boolean isBackgroundDrawingEnabled() { - Field enableBackgroundDrawing = ReflectionUtils.getField(GuiTextField.class, "enableBackgroundDrawing"); + Field enableBackgroundDrawing = ReflectionUtils.getField(GuiTextField.class, DevHelper.isObfuscatedEnvironment() ? "field_146215_m" : "enableBackgroundDrawing"); if (enableBackgroundDrawing != null) { return (boolean) ReflectionUtils.getFieldValue(enableBackgroundDrawing, this); } return true; } + public int getLineScrollOffset() { - Field lineScrollOffset = ReflectionUtils.getField(GuiTextField.class, "lineScrollOffset"); + Field lineScrollOffset = ReflectionUtils.getField(GuiTextField.class, DevHelper.isObfuscatedEnvironment() ? "field_146225_q" : "lineScrollOffset"); if (lineScrollOffset != null) { return (int) ReflectionUtils.getFieldValue(lineScrollOffset, this); } return 0; } - - /** - * Args: x, y, buttonClicked - */ - public void mouseClicked(int aX, int aY, int aButton){ - - boolean flag = aX >= this.mScreenLocationX && aX < this.mScreenLocationX + this.width && aY >= this.mScreenLocationY && aY < this.mScreenLocationY + this.height; - //Logger.INFO("Clicked X:"+aX); - //Logger.INFO("Clicked Y:"+aY); - //Logger.INFO("ScreenPos X:"+mScreenLocationX); - //Logger.INFO("ScreenPos Y:"+mScreenLocationY); - //Logger.INFO("Render X:"+xPosition); - //Logger.INFO("Render Y:"+yPosition); - - if (canLoseFocus()) - { - this.setFocused(flag); - } - - if (isFocused() && aButton == 0) - { - int l = aX - this.mScreenLocationX; + public boolean didClickInTextField(int aX, int aY) { + mGUI.log("Clicked at X:"+aX+", Y:"+aY); + boolean aDidClick = aX >= this.mScreenLocationX && aX < this.mScreenLocationX + this.width && aY >= this.mScreenLocationY && aY < this.mScreenLocationY + this.height; + mGUI.log("Did click in textbox? "+aDidClick); + mGUI.log("Expected Region: X:"+mScreenLocationX+"-"+(this.mScreenLocationX + this.width)); + mGUI.log("Expected Region: Y:"+mScreenLocationY+"-"+(this.mScreenLocationY + this.height)); + return aDidClick; + } - if (isBackgroundDrawingEnabled()) - { - l -= 4; - } + /** + * Args: x, y, buttonClicked + */ + @Override + public void mouseClicked(int aX, int aY, int aButton){ + boolean aDidClick = didClickInTextField(aX, aY); - String s = this.mFontRenderer.trimStringToWidth(this.getText().substring(getLineScrollOffset()), this.getWidth()); - this.setCursorPosition(this.mFontRenderer.trimStringToWidth(s, l).length() + getLineScrollOffset()); - } - } + mGUI.log("Did click inside text box? "+aDidClick); + mGUI.log("Focus 1: "+this.isFocused()); + this.setFocused(aDidClick); + mGUI.log("Focus 2: "+this.isFocused()); + if (isFocused()) { + int l = aX - this.mScreenLocationX; + if (isBackgroundDrawingEnabled()) { + l -= 4; + } + if (aButton == 0) { + mGUI.log("Left clicked in text box."); + String s = this.mFontRenderer.trimStringToWidth(this.getText().substring(getLineScrollOffset()), this.getWidth()); + this.setCursorPosition(this.mFontRenderer.trimStringToWidth(s, l).length() + getLineScrollOffset()); + } + else if (aButton == 1) { + mGUI.log("Right clicked in text box."); + mGUI.setText(0); + mGUI.sendUpdateToServer(); + String s = this.mFontRenderer.trimStringToWidth(this.getText().substring(getLineScrollOffset()), this.getWidth()); + this.setCursorPosition(this.mFontRenderer.trimStringToWidth(s, l).length() + getLineScrollOffset()); + } + } + else { + mGUI.log("Clicked, but no focus."); + } + } } diff --git a/src/main/java/gtPlusPlus/core/recipe/RECIPES_Machines.java b/src/main/java/gtPlusPlus/core/recipe/RECIPES_Machines.java index 6e042a71b1..cd8d9311c0 100644 --- a/src/main/java/gtPlusPlus/core/recipe/RECIPES_Machines.java +++ b/src/main/java/gtPlusPlus/core/recipe/RECIPES_Machines.java @@ -1414,7 +1414,7 @@ public class RECIPES_Machines { RecipeUtils.addShapedGregtechRecipe( - CI.getPlate(6, 1), ItemList.Casing_Gearbox_Titanium, CI.getPlate(6, 1), + CI.getPlate(6, 1), ItemList.Casing_Gearbox_Titanium.get(1), CI.getPlate(6, 1), CI.getPlate(6, 1), CI.getFluidRegulator(5, 1), CI.getPlate(6, 1), CI.getTieredCircuit(6), ItemList.Hatch_Input_IV.get(1), CI.getTieredCircuit(6), GregtechItemList.Hatch_Reservoir.get(1)); diff --git a/src/main/java/gtPlusPlus/core/tileentities/general/TileEntityVolumetricFlaskSetter.java b/src/main/java/gtPlusPlus/core/tileentities/general/TileEntityVolumetricFlaskSetter.java index 5b837397b1..bc096c0d53 100644 --- a/src/main/java/gtPlusPlus/core/tileentities/general/TileEntityVolumetricFlaskSetter.java +++ b/src/main/java/gtPlusPlus/core/tileentities/general/TileEntityVolumetricFlaskSetter.java @@ -26,22 +26,22 @@ public class TileEntityVolumetricFlaskSetter extends TileEntity implements ISide public int locationY; public int locationZ; private int aCurrentMode = 0; - private short aCustomValue = 1000; + private int aCustomValue = 1000; public TileEntityVolumetricFlaskSetter() { this.inventoryContents = new Inventory_VolumetricFlaskSetter(); this.setTileLocation(); } - public short getCustomValue() { + public int getCustomValue() { //Logger.INFO("Value: "+this.aCustomValue); return this.aCustomValue; } public void setCustomValue(int aVal) { - Logger.INFO("Old Value: "+this.aCustomValue); + log("Old Value: "+this.aCustomValue); this.aCustomValue = (short) MathUtils.balance(aVal, 0, Short.MAX_VALUE); - Logger.INFO("New Value: "+this.aCustomValue); + log("New Value: "+this.aCustomValue); markDirty(); } @@ -141,7 +141,7 @@ public class TileEntityVolumetricFlaskSetter extends TileEntity implements ISide // Skip slot 7 (Custom) unless it has a value > 0 if (e == 7 && getCustomValue() <= 0) { - Logger.INFO("Skipping Custom slot as value <= 0"); + log("Skipping Custom slot as value <= 0"); continue; } if (e == Container_VolumetricFlaskSetter.SLOT_OUTPUT) { @@ -168,8 +168,8 @@ public class TileEntityVolumetricFlaskSetter extends TileEntity implements ISide // Check that the Circuit in the Output slot is not null and the same type as the circuit input. if (aTypeInCheckedSlot > 0 && (aTypeInSlot == aTypeInCheckedSlot) && f != null) { if (g.getItem() == f.getItem() && VolumetricFlaskHelper.getFlaskCapacity(f) == getCapacityForSlot(e) && ((aInputFluidStack == null && aFluidInCheckedSlot == null) || aInputFluidStack.isFluidEqual(aFluidInCheckedSlot))) { - Logger.INFO("Input Slot Flask Contains: "+(aInputFluidStack != null ? aInputFluidStack.getLocalizedName() : "Empty")); - Logger.INFO("Output Slot Flask Contains: "+(aFluidInCheckedSlot != null ? aFluidInCheckedSlot.getLocalizedName() : "Empty")); + log("Input Slot Flask Contains: "+(aInputFluidStack != null ? aInputFluidStack.getLocalizedName() : "Empty")); + log("Output Slot Flask Contains: "+(aFluidInCheckedSlot != null ? aFluidInCheckedSlot.getLocalizedName() : "Empty")); aSize = f.stackSize + g.stackSize; if (aSize > 16) { aInputStack = g.copy(); @@ -253,7 +253,7 @@ public class TileEntityVolumetricFlaskSetter extends TileEntity implements ISide final NBTTagCompound chestData = new NBTTagCompound(); this.inventoryContents.writeToNBT(chestData); nbt.setTag("ContentsChest", chestData); - nbt.setShort("aCustomValue", aCustomValue); + nbt.setInteger("aCustomValue", aCustomValue); if (this.hasCustomInventoryName()) { nbt.setString("CustomName", this.getCustomName()); } @@ -265,7 +265,7 @@ public class TileEntityVolumetricFlaskSetter extends TileEntity implements ISide super.readFromNBT(nbt); // Utils.LOG_WARNING("Trying to read NBT data from TE."); this.inventoryContents.readFromNBT(nbt.getCompoundTag("ContentsChest")); - this.aCustomValue = nbt.getShort("aCustomValue"); + this.aCustomValue = nbt.getInteger("aCustomValue"); if (nbt.hasKey("CustomName", 8)) { this.setCustomName(nbt.getString("CustomName")); } @@ -399,5 +399,9 @@ public class TileEntityVolumetricFlaskSetter extends TileEntity implements ISide return false; } } + + public void log(String aString) { + Logger.INFO("[Flask-Tile] "+aString); + } } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/loaders/RecipeGen_BlastSmelterGT_Ex.java b/src/main/java/gtPlusPlus/xmod/gregtech/loaders/RecipeGen_BlastSmelterGT_Ex.java index e76b769ef6..141e75c8b5 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/loaders/RecipeGen_BlastSmelterGT_Ex.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/loaders/RecipeGen_BlastSmelterGT_Ex.java @@ -47,7 +47,7 @@ public class RecipeGen_BlastSmelterGT_Ex implements IOreRecipeRegistrator { if (aMaterial.mBlastFurnaceRequired) { addBlastRecipe(GT_Utility.copyAmount(1L, new Object[]{aStack}), null, null, null, aMaterial.mBlastFurnaceTemp > 1750 ? GT_OreDictUnificator.get(OrePrefixes.ingotHot, aMaterial.mSmeltInto, tDustStack, 1L) : GT_Utility.copyAmount(1L, new Object[]{tDustStack}), null, (int) Math.max(aMaterial.getMass() / 40L, 1L) * aMaterial.mBlastFurnaceTemp, 120, aMaterial); if (aMaterial.mBlastFurnaceTemp <= 1000) { - GT_ModHandler.addRCBlastFurnaceRecipe(GT_Utility.copyAmount(1L, new Object[]{aStack}), GT_Utility.copyAmount(1L, new Object[]{tDustStack}), aMaterial.mBlastFurnaceTemp); + //GT_ModHandler.addRCBlastFurnaceRecipe(GT_Utility.copyAmount(1L, new Object[]{aStack}), GT_Utility.copyAmount(1L, new Object[]{tDustStack}), aMaterial.mBlastFurnaceTemp); } } } @@ -83,8 +83,8 @@ public class RecipeGen_BlastSmelterGT_Ex implements IOreRecipeRegistrator { if (!aMaterial.contains(SubTag.NO_SMELTING)) { if ((aMaterial.mBlastFurnaceRequired) || (aMaterial.mDirectSmelting.mBlastFurnaceRequired)) { addBlastRecipe(GT_Utility.copyAmount(1L, new Object[]{aStack}), null, null, null, aMaterial.mBlastFurnaceTemp > 1750 ? GT_OreDictUnificator.get(OrePrefixes.ingotHot, aMaterial, GT_OreDictUnificator.get(OrePrefixes.ingot, aMaterial, 1L), 1L) : GT_OreDictUnificator.get(OrePrefixes.ingot, aMaterial, 1L), null, (int) Math.max(aMaterial.getMass() / 4L, 1L) * aMaterial.mBlastFurnaceTemp, 120, aMaterial); - if (aMaterial.mBlastFurnaceTemp <= 1000) - GT_ModHandler.addRCBlastFurnaceRecipe(GT_Utility.copyAmount(1L, new Object[]{aStack}), GT_OreDictUnificator.get(OrePrefixes.ingot, aMaterial, 1L), aMaterial.mBlastFurnaceTemp * 2); + //if (aMaterial.mBlastFurnaceTemp <= 1000) + //GT_ModHandler.addRCBlastFurnaceRecipe(GT_Utility.copyAmount(1L, new Object[]{aStack}), GT_OreDictUnificator.get(OrePrefixes.ingot, aMaterial, 1L), aMaterial.mBlastFurnaceTemp * 2); } } } -- cgit