Advertisement
Guest User

Untitled

a guest
Mar 2nd, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.90 KB | None | 0 0
  1. package net.theviolentsquirrels.questsystem.inventory;
  2.  
  3. import net.minecraft.entity.player.EntityPlayer;
  4. import net.minecraft.entity.player.InventoryPlayer;
  5. import net.minecraft.init.Blocks;
  6. import net.minecraft.inventory.IInventory;
  7. import net.minecraft.inventory.InventoryBasic;
  8. import net.minecraft.inventory.InventoryCraftResult;
  9. import net.minecraft.inventory.Slot;
  10. import net.minecraft.item.Item;
  11. import net.minecraft.item.ItemStack;
  12. import net.minecraft.world.World;
  13.  
  14. public class                    ContainerSieve extends ModContainer {
  15.     private IInventory          sieveInventory;
  16.     private IInventory          siftingResult;
  17.  
  18.     private World               worldObj;
  19.  
  20.     public                      ContainerSieve(InventoryPlayer playerInventory, World worldIn) {
  21.         this.worldObj = worldIn;
  22.         this.sieveInventory = new InventoryBasic("container.sifting", false, 1);
  23.         this.siftingResult = new InventoryCraftResult();
  24.         this.addSlotToContainer(new Slot(this.sieveInventory, 0, 48, 35));
  25.         this.addSlotToContainer(new SlotSiftingResult(this.siftingResult, 0, 124, 35));
  26.         this.addPlayerSlots(playerInventory);
  27.     }
  28.  
  29.     @Override
  30.     public boolean              canInteractWith(EntityPlayer playerIn) {
  31.         return (true);
  32.     }
  33.  
  34.     @Override
  35.     public void                 onContainerClosed(EntityPlayer playerIn) {
  36.         super.onContainerClosed(playerIn);
  37.         if (!this.worldObj.isRemote) {
  38.             ItemStack           itemStack;
  39.  
  40.             itemStack = this.sieveInventory.removeStackFromSlot(0);
  41.             if (itemStack != null)
  42.                 playerIn.dropPlayerItemWithRandomChoice(itemStack, false);
  43.             itemStack = this.siftingResult.removeStackFromSlot(1);
  44.             if (itemStack != null)
  45.                 playerIn.dropPlayerItemWithRandomChoice(itemStack, false);
  46.         }
  47.     }
  48.  
  49.     @Override
  50.     public ItemStack            transferStackInSlot(EntityPlayer playerIn, int index) {
  51.         ItemStack               itemStack = null;
  52.         Slot                    slot = this.inventorySlots.get(index);
  53.  
  54.         if (slot != null && slot.getHasStack()) {
  55.             ItemStack           itemStack1 = slot.getStack();
  56.  
  57.             itemStack = itemStack1.copy();
  58.             if (index < 2) {
  59.                 if (!this.mergeItemStack(itemStack1, 2, 28, index == 1))
  60.                     return (null);
  61.                 slot.onSlotChange(itemStack1, itemStack);
  62.             } else {
  63.                 if (this.canBeSifted(itemStack1)) {
  64.                     if (!this.mergeItemStack(itemStack1, 0, 1, false))
  65.                         return (null);
  66.                 } else if (index >= 2 && index <= 28) {
  67.                     if (!this.mergeItemStack(itemStack1, 29, 37, false))
  68.                         return (null);
  69.                 } else if (index >= 29 && index <= 37) {
  70.                     if (!this.mergeItemStack(itemStack1, 2, 28, false))
  71.                         return (null);
  72.                 }
  73.             }
  74.             if (itemStack1.stackSize == 0)
  75.                 slot.putStack(null);
  76.             else
  77.                 slot.onSlotChanged();
  78.             if (itemStack1.stackSize == itemStack.stackSize)
  79.                 return (null);
  80.             slot.onPickupFromSlot(playerIn, itemStack1);
  81.         }
  82.         return (itemStack);
  83.     }
  84.  
  85.     @Override
  86.     public ItemStack            slotClick(int slotId, int clickedButton, int mode, EntityPlayer playerIn) {
  87.         boolean                 result;
  88.  
  89.         result = slotId >= 0 && this.getSlot(slotId) != null &&
  90.                 this.getSlot(slotId).getStack() == playerIn.getHeldItem();
  91.         if (result) return (null);
  92.         return super.slotClick(slotId, clickedButton, mode, playerIn);
  93.     }
  94.  
  95.     private boolean             canBeSifted(ItemStack itemStack) {
  96.         return (itemStack.getItem() == Item.getItemFromBlock(Blocks.gravel));
  97.     }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement