Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.atomictim.atomiccraft.client.container;
- import java.util.ArrayList;
- import net.minecraft.block.Block;
- import net.minecraft.client.Minecraft;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.entity.player.InventoryPlayer;
- import net.minecraft.inventory.Container;
- import net.minecraft.inventory.IInventory;
- import net.minecraft.inventory.Slot;
- import net.minecraft.item.Item;
- import net.minecraft.item.ItemStack;
- import net.minecraft.world.World;
- import com.atomictim.atomiccraft.client.gui.GuiSciBench;
- import com.atomictim.atomiccraft.items.Items;
- import com.atomictim.atomiccraft.tileentity.TileEntitySciBench;
- public class ContainerSciBench extends Container {
- public static TileEntitySciBench bench;
- public ContainerSciBench(InventoryPlayer invPlayer, TileEntitySciBench bench) {
- ContainerSciBench.bench = bench;
- // Adds cutsom Input Slot to the container with ID 0, at position 21, 8
- this.addSlotToContainer(new Slot(bench, 0, 21, 8));
- // Adds cutsom Output Slot to the container with ID 1, at position 187,
- // 8
- this.addSlotToContainer(new Slot(bench, 1, 187, 8));
- int i;
- // Adds player inventory hotbar slots with ID i, at yposition 197
- // starting at x position 29, but adding 18*i each time.
- for (i = 0; i < 9; i++) {
- this.addSlotToContainer(new Slot(invPlayer, i, 29 + i * 18, 197));
- }
- // Adds player inventory slots in a 3x9 grid.
- for (i = 0; i < 3; i++) {
- for (int j = 0; j < 9; j++) {
- this.addSlotToContainer(new Slot(invPlayer, j + i * 9 + 9,
- 29 + j * 18, 139 + i * 18));
- }
- }
- }
- // Called when the player shift clicks an item into or out of the inventory.
- // (Shift clicking allows quick movement of items/blocks)
- @Override
- public ItemStack transferStackInSlot(EntityPlayer player, int i) {
- World world = Minecraft.getMinecraft().theWorld;
- if (world.isRemote) {
- Slot slot = getSlot(i);
- if (slot != null && slot.getHasStack()) {
- ItemStack itemstack = slot.getStack();
- ItemStack result = itemstack.copy();
- if (i == 0 || i == 1) {
- if (!mergeItemStack(itemstack, 2, 36, false)) {
- return null;
- }
- } else if (!mergeItemStack(itemstack, 0, 1, false)) {
- return null;
- }
- if (itemstack.stackSize == 0) {
- slot.putStack(null);
- } else {
- slot.onSlotChanged();
- }
- slot.onPickupFromSlot(player, itemstack);
- return result;
- }
- }
- return null;
- }
- // Allows the player to interact with the container, depending on the state
- // set by isUsableByPlayer method in TileEntitySciBench class.
- @Override
- public boolean canInteractWith(EntityPlayer player) {
- return bench.isUseableByPlayer(player);
- }
- public void receiveButtonEvent(byte buttonID) {
- switch (buttonID) {
- //breakdown
- case 31:
- breakdown();
- break;
- //combine
- case 32:
- combine();
- break;
- }
- }
- public void breakdown() {
- IInventory inventory = (IInventory) ContainerSciBench.bench;
- ItemStack itemstack = inventory.getStackInSlot(0);
- if (itemstack != null) {
- if (itemstack.stackSize > 1) {
- itemstack.stackSize -= 1;
- } else {
- inventory.setInventorySlotContents(0, null);
- itemstack = null;
- }
- }
- }
- public void combine() {
- IInventory inventory = (IInventory) ContainerSciBench.bench;
- ItemStack itemstack = createNewItem(GuiSciBench.elements);
- inventory.setInventorySlotContents(1, itemstack);
- GuiSciBench.elements.clear();
- System.out.println("Array list cleared");
- }
- public ItemStack createNewItem(ArrayList<Integer> elements) {
- if (elements != null) {
- int e1 = 0, e2 = 0, e3 = 0;
- if (elements.size() > 0) {
- e1 = elements.get(0);
- System.out.println("e1 = " + e1);
- if (elements.size() > 1) {
- e2 = elements.get(1);
- System.out.println("e2 = " + e2);
- if (elements.size() > 2) {
- e3 = elements.get(2);
- System.out.println("e3 = " + e3);
- }
- }
- }
- ItemStack itemstack = null;
- //Tar Bucket###################################################################
- if (e1 == 1 && e2 == 4 && e3 == 0 || e1 == 4 && e2 == 1 && e3 == 0) {
- itemstack = new ItemStack(Items.tarbucket, 1);
- }
- //Water Bucket#################################################################
- if (e1 == 1 && e2 == 6 && e3 == 0 || e1 == 6 && e2 == 1 && e3 == 0) {
- itemstack = new ItemStack(Item.bucketWater, 1);
- }
- //Iron Ingot###################################################################
- if (e1 == 19 && e2 == 0 && e3 == 0) {
- itemstack = new ItemStack(Item.ingotIron, 1);
- }
- //Gold Ingot###################################################################
- if (e1 == 29 && e2 == 0 && e3 == 0) {
- itemstack = new ItemStack(Item.ingotGold, 1);
- }
- //Nickel Ingot#################################################################
- if (e1 == 20 && e2 == 0 && e3 == 0) {
- itemstack = new ItemStack(Items.nickelingot, 1);
- }
- //Titanium Ingot###############################################################
- if (e1 == 17 && e2 == 0 && e3 == 0) {
- itemstack = new ItemStack(Items.titaniumingot, 1);
- }
- //Diamond######################################################################
- if (e1 == 4 && e2 == 0 && e3 == 0) {
- itemstack = new ItemStack(Item.diamond, 1);
- }
- //Yttrium Crystal##############################################################
- if (e1 == 25 && e2 == 0 && e3 == 0) {
- itemstack = new ItemStack(Items.yttriumcrystal, 1);
- }
- //Glass########################################################################
- if (e1 == 6 && e2 == 11 && e3 == 0 || e1 == 11 && e2 == 6 && e3 == 0) {
- itemstack = new ItemStack(Block.glass, 1);
- }
- //Cobblestone##################################################################
- if (e1 == 15 && e2 == 0 && e3 == 0) {
- itemstack = new ItemStack(Block.cobblestone, 1);
- }
- //LiCl Spray Bottle############################################################
- if (e1 == 3 && e2 == 13 && e3 == 0) {
- itemstack = new ItemStack(Items.spraylicl, 1);
- }
- if (e1 == 13 && e2 == 3 && e3 == 0) {
- itemstack = new ItemStack(Items.spraylicl, 1);
- }
- //CaCl Spray Bottle############################################################
- if (e1 == 13 && e2 == 16 && e3 == 0) {
- itemstack = new ItemStack(Items.spraycacl, 1);
- }
- if (e1 == 16 && e2 == 13 && e3 == 0) {
- itemstack = new ItemStack(Items.spraycacl, 1);
- }
- //KCl Spray Bottle#############################################################
- if (e1 == 13 && e2 == 14 && e3 == 0) {
- itemstack = new ItemStack(Items.spraykcl, 1);
- }
- if (e1 == 14 && e2 == 13 && e3 == 0) {
- itemstack = new ItemStack(Items.spraykcl, 1);
- }
- //NaCl Spray Bottle############################################################
- if (e1 == 8 && e2 == 13 && e3 == 0) {
- itemstack = new ItemStack(Items.spraynacl, 1);
- }
- if (e1 == 13 && e2 == 8 && e3 == 0) {
- itemstack = new ItemStack(Items.spraynacl, 1);
- }
- //CuSO4 Spray Bottle###########################################################
- if (e1 == 6 && e2 == 12 && e3 == 21 || e1 == 6 && e2 == 21 && e3 == 12) {
- itemstack = new ItemStack(Items.spraycuso4, 1);
- }
- if (e1 == 12 && e2 == 6 && e3 == 21) {
- itemstack = new ItemStack(Items.spraycuso4, 1);
- }
- if (e1 == 12 && e2 == 21 && e3 == 6) {
- itemstack = new ItemStack(Items.spraycuso4, 1);
- }
- if (e1 == 21 && e2 == 6 && e3 == 12) {
- itemstack = new ItemStack(Items.spraycuso4, 1);
- }
- if (e1 == 21 && e2 == 12 && e3 == 6) {
- itemstack = new ItemStack(Items.spraycuso4, 1);
- }
- //CuCl2 Spray Bottle############################################################
- if (e1 == 21 && e2 == 13 && e3 == 0) {
- itemstack = new ItemStack(Items.spraycucl2, 1);
- }
- if (e1 == 13 && e2 == 21 && e3 == 0) {
- itemstack = new ItemStack(Items.spraycucl2, 1);
- }
- //MgSO4 Spray Bottle############################################################
- if (e1 == 6 && e2 == 12 && e3 == 9 || e1 == 6 && e2 == 9 && e3 == 12) {
- itemstack = new ItemStack(Items.spraymgso4, 1);
- }
- if (e1 == 9 && e2 == 12 && e3 == 6 || e1 == 9 && e2 == 6 && e3 == 12) {
- itemstack = new ItemStack(Items.spraymgso4, 1);
- }
- if (e1 == 12 && e2 == 6 && e3 == 9) {
- itemstack = new ItemStack(Items.spraymgso4, 1);
- }
- if (e1 == 12 && e2 == 9 && e3 == 6) {
- itemstack = new ItemStack(Items.spraymgso4, 1);
- }
- //##############################################################################
- return itemstack;
- } else {
- return null;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement