Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.jam.icc.container;
- import javax.annotation.Nullable;
- import com.jam.icc.slots.SlotGhost;
- import com.jam.icc.slots.SlotUnstackable;
- import com.jam.icc.tileentity.TileEntityICSB;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.inventory.Container;
- import net.minecraft.inventory.IInventory;
- import net.minecraft.inventory.Slot;
- import net.minecraft.item.Item;
- import net.minecraft.item.ItemStack;
- import net.minecraft.util.EnumFacing;
- import net.minecraftforge.items.CapabilityItemHandler;
- import net.minecraftforge.items.IItemHandler;
- import net.minecraftforge.items.SlotItemHandler;
- public class ICSBContainer extends Container{
- private TileEntityICSB te;
- public ICSBContainer(IInventory playerInventory, TileEntityICSB te) {
- this.te = te;
- // This container references items out of our own inventory (the 10 slots we hold ourselves)
- // as well as the slots from the player inventory so that the user can transfer items between
- // both inventories. The two calls below make sure that slots are defined for both inventories.
- addOwnSlots();
- addPlayerSlots(playerInventory);
- }
- private void addPlayerSlots(IInventory playerInventory) {
- // Slots for the main inventory
- for (int row = 0; row < 3; ++row) {
- for (int col = 0; col < 9; ++col) {
- int x = 8 + col * 18;
- int y = row * 18 + 54;
- this.addSlotToContainer(new Slot(playerInventory, col + row * 9 + 9, x, y));
- }
- }
- // Slots for the hotbar
- for (int row = 0; row < 9; ++row) {
- int x = 8 + row * 18;
- int y = 58 + 54;
- this.addSlotToContainer(new Slot(playerInventory, row, x, y));
- }
- }
- private void addOwnSlots() {
- IItemHandler itemHandler = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
- IItemHandler filterHandler = te.filterstack();
- int x = 8;
- int y = 22;
- // Add our own slots
- int slotIndex = 0;
- for(int i = 0; i < 9; i++)
- {
- int x1 = 8 + 18 * i;
- int y1 = 18;
- this.addSlotToContainer(new SlotItemHandler(itemHandler, i, x1, y1));
- }
- for(int i = 0; i < 9; i++)
- {
- int x1 = 8 + 18 * i;
- int y1 = 18 + 18;
- this.addSlotToContainer(new SlotItemHandler(itemHandler, i + 9, x1, y1));
- }
- for(int i = 0; i < 9; i++)
- {
- int x1 = 8 + 18 * i;
- int y1 = 18 + 36;
- this.addSlotToContainer(new SlotItemHandler(itemHandler, i + 18, x1, y1));
- }
- //add other slots
- //item filter slot
- addSlotToContainer(new SlotGhost(filterHandler, 0, 173, 5));
- }
- @Nullable
- @Override
- public ItemStack transferStackInSlot(EntityPlayer playerIn, int index) {
- ItemStack itemstack = ItemStack.EMPTY;
- Slot slot = this.inventorySlots.get(index);
- if (slot != null && slot.getHasStack()) {
- ItemStack itemstack1 = slot.getStack();
- itemstack = itemstack1.copy();
- if (index < TileEntityICSB.SIZE) {
- if (!this.mergeItemStack(itemstack1, 10, this.inventorySlots.size(), true)) {
- return ItemStack.EMPTY;
- }
- } else if (!this.mergeItemStack(itemstack1, 0, 9, false)) {
- return ItemStack.EMPTY;
- }
- if (itemstack1.isEmpty()) {
- slot.putStack(ItemStack.EMPTY);
- } else {
- slot.onSlotChanged();
- }
- }
- return itemstack;
- }
- @Override
- public boolean canInteractWith(EntityPlayer playerIn) {
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment