Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2014
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.05 KB | None | 0 0
  1. package com.vognersmods.fleshworks;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.HashSet;
  5. import java.util.Iterator;
  6. import java.util.List;
  7. import java.util.Set;
  8.  
  9. import net.minecraft.entity.player.EntityPlayer;
  10. import net.minecraft.entity.player.InventoryPlayer;
  11. import net.minecraft.init.Blocks;
  12. import net.minecraft.inventory.Container;
  13. import net.minecraft.inventory.IInventory;
  14. import net.minecraft.inventory.InventoryCraftResult;
  15. import net.minecraft.inventory.InventoryCrafting;
  16. import net.minecraft.inventory.Slot;
  17. import net.minecraft.inventory.SlotCrafting;
  18. import net.minecraft.item.Item;
  19. import net.minecraft.item.ItemStack;
  20. import net.minecraft.item.crafting.CraftingManager;
  21. import net.minecraft.world.World;
  22.  
  23. public class ContainerBolus extends Container
  24. {
  25.     /** The crafting matrix inventory (3x3). */
  26.     public InventoryCrafting craftMatrix = new InventoryCrafting(this, 3, 3);
  27.     public IInventory craftResult = new InventoryCraftResult();
  28.     private World worldObj;
  29.     private int posX;
  30.     public int posY;
  31.     private int posZ;
  32.     TileEntityBolus teBolus;
  33.     private short transactionID;
  34.     private int field_94535_f = -1;
  35.     private int field_94536_g;
  36.     private final Set field_94537_h = new HashSet();
  37.     /** list of all people that need to be notified when this craftinventory changes */
  38.     protected List crafters = new ArrayList();
  39.     private Set playerList = new HashSet();
  40.     public InventoryPlayer inv;//always null I guess
  41.     public ArrayList fwItems = new ArrayList();
  42.  
  43.     public ContainerBolus(InventoryPlayer inventory, TileEntityBolus teBolus, World p_i1808_2_, int p_i1808_3_, int p_i1808_4_, int p_i1808_5_)
  44.     {
  45.         this.worldObj = p_i1808_2_;
  46.         this.teBolus = teBolus;
  47.         this.posX = p_i1808_3_;
  48.         this.posY = p_i1808_4_;
  49.         this.posZ = p_i1808_5_;
  50.         this.inv = inventory;
  51.        
  52.         int l = 0;
  53.         int i1 = 0;
  54.        
  55.         //result
  56.         for (l = 0; l < 3; ++l)
  57.         {
  58.             for (i1 = 0; i1 < 3; ++i1)
  59.             {
  60.                 this.addSlotToContainer(new SlotCrafting(inventory.player, this.teBolus, this.craftResult, i1 + l * 2, 117 + i1 * 18, 18 + l * 18));
  61.             }
  62.         }
  63.  
  64.         //"offerings"
  65.         for (l = 0; l < 3; ++l)
  66.         {
  67.             for (i1 = 0; i1 < 3; ++i1)
  68.             {
  69.                 this.addSlotToContainer(new Slot(this.teBolus, i1 + l * 3, 27 + i1 * 18, 18 + l * 18));
  70.             }
  71.         }
  72.        
  73.         l = 0;
  74.         i1 = 0;
  75.  
  76.         //inventory sans hotbar
  77.         for (l = 0; l < 3; ++l)
  78.         {
  79.             for (i1 = 0; i1 < 9; ++i1)
  80.             {
  81.                 this.addSlotToContainer(new Slot(inventory, i1 + l * 9 + 9, 18 + i1 * 18, 85 + l * 18));
  82.             }
  83.         }
  84.  
  85.         //hotbar
  86.         for (l = 0; l < 9; ++l)
  87.         {
  88.             this.addSlotToContainer(new Slot(inventory, l, 18 + l * 18, 143)); //x+10, y + 5
  89.         }
  90.         //this.onCraftMatrixChanged(this.craftMatrix);
  91.     }
  92.    
  93.     public ArrayList updateFWItems(){
  94.         this.fwItems.clear();
  95.         for(int i = 0; i < this.inventorySlots.size(); i++){
  96.             if(getSlot(i).getHasStack()){
  97.                 if((getSlot(i).getStack().getItem().getUnlocalizedName()).equals(FleshWorks.itemFWWeaponBase.getUnlocalizedName()) ||
  98.                    (getSlot(i).getStack().getItem().getUnlocalizedName()).equals(FleshWorks.itemBootsFW.getUnlocalizedName()) ||   
  99.                    (getSlot(i).getStack().getItem().getUnlocalizedName()).equals(FleshWorks.itemChestplateFW.getUnlocalizedName()) ||
  100.                    (getSlot(i).getStack().getItem().getUnlocalizedName()).equals(FleshWorks.itemLeggingsFW.getUnlocalizedName()) ||
  101.                    (getSlot(i).getStack().getItem().getUnlocalizedName()).equals(FleshWorks.itemHelmetFW.getUnlocalizedName()))
  102.                 {              
  103.                     this.fwItems.add(inventorySlots.get(i));
  104.                 }
  105.             }
  106.         }      
  107.         //System.out.println("\nNumber of FW items: " + fwItems.size() + "\n");
  108.         return this.fwItems;
  109.     }
  110.    
  111.     public int getNumberOfFWItems(){
  112.         return this.fwItems.size();
  113.     }
  114.    
  115.     public ArrayList getFWItems(){
  116.         return this.fwItems;
  117.     }
  118.  
  119.     /**
  120.      * Callback for when the crafting matrix is changed.
  121.      */
  122.     /*@Override
  123.     public void onCraftMatrixChanged(IInventory p_75130_1_)
  124.     {
  125.         this.craftResult.setInventorySlotContents(0, CraftingManagerFW.getInstance().findMatchingRecipe(this.craftMatrix, this.worldObj));
  126.         updateFWItems();
  127.     }*/
  128.  
  129.     /**
  130.      * Called when the container is closed.
  131.      */
  132.     /*public void onContainerClosed(EntityPlayer p_75134_1_)
  133.     {
  134.         super.onContainerClosed(p_75134_1_);
  135.  
  136.         if (!this.worldObj.isRemote)
  137.         {
  138.             for (int i = 0; i < 9; ++i)
  139.             {
  140.                 ItemStack itemstack = this.craftMatrix.getStackInSlotOnClosing(i);
  141.  
  142.                 if (itemstack != null)
  143.                 {
  144.                     p_75134_1_.dropPlayerItemWithRandomChoice(itemstack, false);
  145.                 }
  146.             }
  147.         }
  148.     }*/
  149.  
  150.     public boolean canInteractWith(EntityPlayer player)
  151.     {
  152.         return true;
  153.     }
  154.  
  155.     /**
  156.      * Called when a player shift-clicks on a slot. You must override this or you will crash when someone does that.
  157.      */
  158.     public ItemStack transferStackInSlot(EntityPlayer p_82846_1_, int p_82846_2_)
  159.     {
  160.         ItemStack itemstack = null;
  161.         Slot slot = (Slot)this.inventorySlots.get(p_82846_2_);
  162.  
  163.         if (slot != null && slot.getHasStack())
  164.         {
  165.             ItemStack itemstack1 = slot.getStack();
  166.             itemstack = itemstack1.copy();
  167.  
  168.             if (p_82846_2_ == 0)
  169.             {
  170.                 if (!this.mergeItemStack(itemstack1, 10, 46, true))
  171.                 {
  172.                     return null;
  173.                 }
  174.  
  175.                 slot.onSlotChange(itemstack1, itemstack);
  176.             }
  177.             else if (p_82846_2_ >= 10 && p_82846_2_ < 37)
  178.             {
  179.                 if (!this.mergeItemStack(itemstack1, 37, 46, false))
  180.                 {
  181.                     return null;
  182.                 }
  183.             }
  184.             else if (p_82846_2_ >= 37 && p_82846_2_ < 46)
  185.             {
  186.                 if (!this.mergeItemStack(itemstack1, 10, 37, false))
  187.                 {
  188.                     return null;
  189.                 }
  190.             }
  191.             else if (!this.mergeItemStack(itemstack1, 10, 46, false))
  192.             {
  193.                 return null;
  194.             }
  195.  
  196.             if (itemstack1.stackSize == 0)
  197.             {
  198.                 slot.putStack((ItemStack)null);
  199.             }
  200.             else
  201.             {
  202.                 slot.onSlotChanged();
  203.             }
  204.  
  205.             if (itemstack1.stackSize == itemstack.stackSize)
  206.             {
  207.                 return null;
  208.             }
  209.  
  210.             slot.onPickupFromSlot(p_82846_1_, itemstack1);
  211.         }
  212.  
  213.         return itemstack;
  214.     }
  215.  
  216.     @Override
  217.     public boolean func_94530_a(ItemStack itemStack, Slot slot)//canInteractWithSlot, maybe?
  218.     {
  219.         return /*slot.inventory != this.craftResult && */super.func_94530_a(itemStack, slot);
  220.     }
  221. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement