Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2016
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.38 KB | None | 0 0
  1. package com.nitrodev.constructio.gui;
  2.  
  3. import net.minecraft.entity.player.EntityPlayer;
  4. import net.minecraft.inventory.*;
  5. import net.minecraft.item.ItemStack;
  6.  
  7. public class ContainerWoodencrate extends Container {
  8.  
  9.     public EntityPlayer player;
  10.     private IInventory woodencrateInventory;
  11.     static final int MachineSlots = 36;
  12.     static final int PlayerSlots = 9*4;
  13.  
  14.     public ContainerWoodencrate(IInventory playerInv, IInventory tileEntity) {
  15.         this.woodencrateInventory = tileEntity;
  16.  
  17.         int i;
  18.         int j;
  19.         for(i = 0; i < 6; ++i) {
  20.             for(j = 0; j < 6; ++j) {
  21.                 this.addSlotToContainer(new Slot(tileEntity, j + i * 6, 26 + j * 18, 17 + i * 18));
  22.             }
  23.         }
  24.  
  25.         for(i = 0; i < 3; ++i) {
  26.             for(j = 0; j < 9; ++j) {
  27.                 this.addSlotToContainer(new Slot(playerInv, j + i * 9 + 9, 8 + j * 18, 117 + i * 18));
  28.             }
  29.         }
  30.  
  31.         for(i = 0; i < 9; ++i) {
  32.             this.addSlotToContainer(new Slot(playerInv, i, 8 + i * 18, 175));
  33.         }
  34.  
  35.     }
  36.  
  37.     public boolean canInteractWith(EntityPlayer player) {
  38.         return this.woodencrateInventory.isUseableByPlayer(player);
  39.     }
  40.  
  41.     //For shift-clicking from the inventory
  42.     //If return null then can't be shift-clicked
  43.     @Override
  44.     public ItemStack transferStackInSlot(EntityPlayer playerEntity, int slotIndex) {
  45.  
  46.         Slot slot = this.inventorySlots.get(slotIndex);
  47.         if (slot == null || !slot.getHasStack()) {
  48.  
  49.             return null;
  50.         }
  51.  
  52.         ItemStack stack = slot.getStack();
  53.         ItemStack stackCopy = stack.copy();
  54.  
  55.         int startIndex;
  56.         int endIndex;
  57.  
  58.         if (slotIndex < MachineSlots) {
  59.  
  60.             startIndex = MachineSlots;
  61.             endIndex = MachineSlots + PlayerSlots;
  62.  
  63.         } else {
  64.  
  65.             startIndex = 0;
  66.             endIndex = MachineSlots;
  67.         }
  68.  
  69.  
  70.  
  71.         if (!this.mergeItemStack(stack, startIndex, endIndex, false))
  72.         {
  73.             return null;
  74.         }
  75.  
  76.         if (stack.stackSize == 0)
  77.         {
  78.             slot.putStack(null);
  79.         }
  80.         else
  81.         {
  82.             slot.onSlotChanged();
  83.         }
  84.  
  85.         if (stack.stackSize == stackCopy.stackSize)
  86.         {
  87.             return null;
  88.         }
  89.  
  90.         slot.onPickupFromSlot(playerEntity, stack);
  91.         return stackCopy;
  92.     }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement