Advertisement
Guest User

Untitled

a guest
Mar 26th, 2014
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.57 KB | None | 0 0
  1. package com.atomictim.atomiccraft.client.container;
  2.  
  3. import java.util.ArrayList;
  4.  
  5. import net.minecraft.block.Block;
  6. import net.minecraft.client.Minecraft;
  7. import net.minecraft.entity.player.EntityPlayer;
  8. import net.minecraft.entity.player.InventoryPlayer;
  9. import net.minecraft.inventory.Container;
  10. import net.minecraft.inventory.IInventory;
  11. import net.minecraft.inventory.Slot;
  12. import net.minecraft.item.Item;
  13. import net.minecraft.item.ItemStack;
  14. import net.minecraft.world.World;
  15.  
  16. import com.atomictim.atomiccraft.client.gui.GuiSciBench;
  17. import com.atomictim.atomiccraft.items.Items;
  18. import com.atomictim.atomiccraft.tileentity.TileEntitySciBench;
  19.  
  20. public class ContainerSciBench extends Container {
  21.  
  22.     public static TileEntitySciBench bench;
  23.  
  24.     public ContainerSciBench(InventoryPlayer invPlayer, TileEntitySciBench bench) {
  25.         ContainerSciBench.bench = bench;
  26.  
  27.         // Adds cutsom Input Slot to the container with ID 0, at position 21, 8
  28.         this.addSlotToContainer(new Slot(bench, 0, 21, 8));
  29.         // Adds cutsom Output Slot to the container with ID 1, at position 187,
  30.         // 8
  31.         this.addSlotToContainer(new Slot(bench, 1, 187, 8));
  32.  
  33.         int i;
  34.         // Adds player inventory hotbar slots with ID i, at yposition 197
  35.         // starting at x position 29, but adding 18*i each time.
  36.         for (i = 0; i < 9; i++) {
  37.             this.addSlotToContainer(new Slot(invPlayer, i, 29 + i * 18, 197));
  38.         }
  39.  
  40.         // Adds player inventory slots in a 3x9 grid.
  41.         for (i = 0; i < 3; i++) {
  42.             for (int j = 0; j < 9; j++) {
  43.                 this.addSlotToContainer(new Slot(invPlayer, j + i * 9 + 9,
  44.                         29 + j * 18, 139 + i * 18));
  45.             }
  46.         }
  47.     }
  48.  
  49.     // Called when the player shift clicks an item into or out of the inventory.
  50.     // (Shift clicking allows quick movement of items/blocks)
  51.     @Override
  52.     public ItemStack transferStackInSlot(EntityPlayer player, int i) {
  53.         World world = Minecraft.getMinecraft().theWorld;
  54.         if (world.isRemote) {
  55.             Slot slot = getSlot(i);
  56.             if (slot != null && slot.getHasStack()) {
  57.                 ItemStack itemstack = slot.getStack();
  58.                 ItemStack result = itemstack.copy();
  59.  
  60.                 if (i == 0 || i == 1) {
  61.                     if (!mergeItemStack(itemstack, 2, 36, false)) {
  62.                         return null;
  63.                     }
  64.                 } else if (!mergeItemStack(itemstack, 0, 1, false)) {
  65.                     return null;
  66.                 }
  67.  
  68.                 if (itemstack.stackSize == 0) {
  69.                     slot.putStack(null);
  70.                 } else {
  71.                     slot.onSlotChanged();
  72.                 }
  73.                 slot.onPickupFromSlot(player, itemstack);
  74.                 return result;
  75.             }
  76.         }
  77.         return null;
  78.     }
  79.  
  80.     // Allows the player to interact with the container, depending on the state
  81.     // set by isUsableByPlayer method in TileEntitySciBench class.
  82.     @Override
  83.     public boolean canInteractWith(EntityPlayer player) {
  84.         return bench.isUseableByPlayer(player);
  85.     }
  86.    
  87.     public void receiveButtonEvent(byte buttonID) {
  88.         switch (buttonID) {
  89.         //breakdown
  90.         case 31:
  91.             breakdown();
  92.             break;
  93.             //combine  
  94.         case 32:
  95.             combine();
  96.             break;
  97.         }
  98.     }
  99.  
  100.     public void breakdown() {
  101.         IInventory inventory = (IInventory) ContainerSciBench.bench;
  102.         ItemStack itemstack = inventory.getStackInSlot(0);
  103.         if (itemstack != null) {
  104.             if (itemstack.stackSize > 1) {
  105.                 itemstack.stackSize -= 1;
  106.             } else {
  107.                 inventory.setInventorySlotContents(0, null);
  108.                 itemstack = null;
  109.             }
  110.         }
  111.     }
  112.  
  113.     public void combine() {
  114.         IInventory inventory = (IInventory) ContainerSciBench.bench;
  115.         ItemStack itemstack = createNewItem(GuiSciBench.elements);
  116.         inventory.setInventorySlotContents(1, itemstack);
  117.         GuiSciBench.elements.clear();
  118.         System.out.println("Array list cleared");
  119.     }
  120.  
  121.     public ItemStack createNewItem(ArrayList<Integer> elements) {
  122.         if (elements != null) {
  123.             int e1 = 0, e2 = 0, e3 = 0;
  124.             if (elements.size() > 0) {
  125.                 e1 = elements.get(0);
  126.                 System.out.println("e1 = " + e1);
  127.                 if (elements.size() > 1) {
  128.                     e2 = elements.get(1);
  129.                     System.out.println("e2 = " + e2);
  130.                     if (elements.size() > 2) {
  131.                         e3 = elements.get(2);
  132.                         System.out.println("e3 = " + e3);
  133.                     }
  134.                 }
  135.             }
  136.             ItemStack itemstack = null;
  137.  
  138.             //Tar Bucket###################################################################
  139.             if (e1 == 1 && e2 == 4 && e3 == 0 || e1 == 4 && e2 == 1 && e3 == 0) {
  140.                 itemstack = new ItemStack(Items.tarbucket, 1);
  141.             }
  142.             //Water Bucket#################################################################
  143.             if (e1 == 1 && e2 == 6 && e3 == 0 || e1 == 6 && e2 == 1 && e3 == 0) {
  144.                 itemstack = new ItemStack(Item.bucketWater, 1);
  145.             }
  146.             //Iron Ingot###################################################################
  147.             if (e1 == 19 && e2 == 0 && e3 == 0) {
  148.                 itemstack = new ItemStack(Item.ingotIron, 1);
  149.             }
  150.             //Gold Ingot###################################################################
  151.             if (e1 == 29 && e2 == 0 && e3 == 0) {
  152.                 itemstack = new ItemStack(Item.ingotGold, 1);
  153.             }
  154.             //Nickel Ingot#################################################################
  155.             if (e1 == 20 && e2 == 0 && e3 == 0) {
  156.                 itemstack = new ItemStack(Items.nickelingot, 1);
  157.             }
  158.             //Titanium Ingot###############################################################
  159.             if (e1 == 17 && e2 == 0 && e3 == 0) {
  160.                 itemstack = new ItemStack(Items.titaniumingot, 1);
  161.             }                  
  162.             //Diamond######################################################################
  163.             if (e1 == 4 && e2 == 0 && e3 == 0) {
  164.                 itemstack = new ItemStack(Item.diamond, 1);
  165.             }
  166.             //Yttrium Crystal##############################################################
  167.             if (e1 == 25 && e2 == 0 && e3 == 0) {
  168.                 itemstack = new ItemStack(Items.yttriumcrystal, 1);
  169.             }
  170.             //Glass########################################################################
  171.             if (e1 == 6 && e2 == 11 && e3 == 0 || e1 == 11 && e2 == 6 && e3 == 0) {
  172.                 itemstack = new ItemStack(Block.glass, 1);
  173.             }
  174.             //Cobblestone##################################################################
  175.             if (e1 == 15 && e2 == 0 && e3 == 0) {
  176.                 itemstack = new ItemStack(Block.cobblestone, 1);
  177.             }
  178.             //LiCl Spray Bottle############################################################
  179.             if (e1 == 3 && e2 == 13 && e3 == 0) {
  180.                 itemstack = new ItemStack(Items.spraylicl, 1);
  181.             }
  182.             if (e1 == 13 && e2 == 3 && e3 == 0) {
  183.                 itemstack = new ItemStack(Items.spraylicl, 1);
  184.             }
  185.             //CaCl Spray Bottle############################################################
  186.             if (e1 == 13 && e2 == 16 && e3 == 0) {
  187.                 itemstack = new ItemStack(Items.spraycacl, 1);
  188.             }
  189.             if (e1 == 16 && e2 == 13 && e3 == 0) {
  190.                 itemstack = new ItemStack(Items.spraycacl, 1);
  191.             }
  192.             //KCl Spray Bottle#############################################################
  193.             if (e1 == 13 && e2 == 14 && e3 == 0) {
  194.                 itemstack = new ItemStack(Items.spraykcl, 1);
  195.             }
  196.             if (e1 == 14 && e2 == 13 && e3 == 0) {
  197.                 itemstack = new ItemStack(Items.spraykcl, 1);
  198.             }
  199.             //NaCl Spray Bottle############################################################
  200.             if (e1 == 8 && e2 == 13 && e3 == 0) {
  201.                 itemstack = new ItemStack(Items.spraynacl, 1);
  202.             }
  203.             if (e1 == 13 && e2 == 8 && e3 == 0) {
  204.                 itemstack = new ItemStack(Items.spraynacl, 1);
  205.             }
  206.             //CuSO4 Spray Bottle###########################################################
  207.             if (e1 == 6 && e2 == 12 && e3 == 21 || e1 == 6 && e2 == 21 && e3 == 12) {
  208.                 itemstack = new ItemStack(Items.spraycuso4, 1);
  209.             }
  210.             if (e1 == 12 && e2 == 6 && e3 == 21) {
  211.                 itemstack = new ItemStack(Items.spraycuso4, 1);
  212.             }
  213.             if (e1 == 12 && e2 == 21 && e3 == 6) {
  214.                 itemstack = new ItemStack(Items.spraycuso4, 1);
  215.             }
  216.             if (e1 == 21 && e2 == 6 && e3 == 12) {
  217.                 itemstack = new ItemStack(Items.spraycuso4, 1);
  218.             }
  219.             if (e1 == 21 && e2 == 12 && e3 == 6) {
  220.                 itemstack = new ItemStack(Items.spraycuso4, 1);
  221.             }
  222.             //CuCl2 Spray Bottle############################################################
  223.             if (e1 == 21 && e2 == 13 && e3 == 0) {
  224.                 itemstack = new ItemStack(Items.spraycucl2, 1);
  225.             }
  226.             if (e1 == 13 && e2 == 21 && e3 == 0) {
  227.                 itemstack = new ItemStack(Items.spraycucl2, 1);
  228.             }
  229.             //MgSO4 Spray Bottle############################################################           
  230.             if (e1 == 6 && e2 == 12 && e3 == 9 || e1 == 6 && e2 == 9 && e3 == 12) {
  231.                 itemstack = new ItemStack(Items.spraymgso4, 1);
  232.             }          
  233.             if (e1 == 9 && e2 == 12 && e3 == 6 || e1 == 9 && e2 == 6 && e3 == 12) {
  234.                 itemstack = new ItemStack(Items.spraymgso4, 1);
  235.             }
  236.             if (e1 == 12 && e2 == 6 && e3 == 9) {
  237.                 itemstack = new ItemStack(Items.spraymgso4, 1);
  238.             }
  239.             if (e1 == 12 && e2 == 9 && e3 == 6) {
  240.                 itemstack = new ItemStack(Items.spraymgso4, 1);
  241.             }
  242.             //##############################################################################
  243.             return itemstack;
  244.         } else {
  245.             return null;
  246.         }
  247.     }
  248. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement