Package mekanism.common.inventory.container

Source Code of mekanism.common.inventory.container.ContainerDictionary

package mekanism.common.inventory.container;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;

public class ContainerDictionary extends Container
{
  public ContainerDictionary(InventoryPlayer inventory)
  {
    int slotX;

    for(slotX = 0; slotX < 3; slotX++)
    {
      for(int slotY = 0; slotY < 9; slotY++)
      {
        addSlotToContainer(new Slot(inventory, slotY + slotX * 9 + 9, 8 + slotY * 18, 84 + slotX * 18));
      }
    }

    for(slotX = 0; slotX < 9; slotX++)
    {
      addSlotToContainer(new Slot(inventory, slotX, 8 + slotX * 18, 142));
    }
  }

  @Override
  public boolean canInteractWith(EntityPlayer entityplayer)
  {
    return true;
  }

  @Override
  public ItemStack transferStackInSlot(EntityPlayer player, int slotID)
  {
    ItemStack stack = null;
    Slot currentSlot = (Slot)inventorySlots.get(slotID);

    if(currentSlot != null && currentSlot.getHasStack())
    {
      ItemStack slotStack = currentSlot.getStack();
      stack = slotStack.copy();

      if(slotID >= 0 && slotID <= 26)
      {
        if(!mergeItemStack(slotStack, 27, inventorySlots.size(), false))
        {
          return null;
        }
      }
      else if(slotID > 26)
      {
        if(!mergeItemStack(slotStack, 0, 26, false))
        {
          return null;
        }
      }
      else {
        if(!mergeItemStack(slotStack, 0, inventorySlots.size(), true))
        {
          return null;
        }
      }

      if(slotStack.stackSize == 0)
      {
        currentSlot.putStack((ItemStack)null);
      }
      else {
        currentSlot.onSlotChanged();
      }

      if(slotStack.stackSize == stack.stackSize)
      {
        return null;
      }

      currentSlot.onPickupFromSlot(player, slotStack);
    }

    return stack;
  }
}
TOP

Related Classes of mekanism.common.inventory.container.ContainerDictionary

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.