Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package io.github.hsyyid.wilsonsmp.containers;
- import io.github.hsyyid.wilsonsmp.tileentities.TileEntityReadableBookshelf;
- 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.ItemStack;
- public class ContainerReadableBookshelf extends Container
- {
- public IInventory inventory;
- public EntityPlayer player;
- public TileEntityReadableBookshelf bookshelf;
- public ContainerReadableBookshelf(EntityPlayer player, TileEntityReadableBookshelf bookshelf)
- {
- this.inventory = bookshelf.inventory;
- this.player = player;
- this.bookshelf = bookshelf;
- this.initialize();
- }
- public void initialize()
- {
- this.addSlotToContainer(new Slot(inventory, 0, 14, 26));
- for (byte x = 0; x < 9; x++)
- {
- addSlotToContainer(new Slot(player.inventory, x, 5 + (18 * x), 182));
- }
- }
- @Override
- public void onCraftMatrixChanged(IInventory iinventory)
- {
- super.onCraftMatrixChanged(iinventory);
- }
- @Override
- public void onContainerClosed(EntityPlayer par1EntityPlayer)
- {
- super.onContainerClosed(par1EntityPlayer);
- this.bookshelf.inventory = this.inventory;
- }
- @Override
- public ItemStack transferStackInSlot(EntityPlayer player, int i)
- {
- Slot slot = getSlot(i);
- if (slot != null && slot.getHasStack())
- {
- ItemStack stack = slot.getStack();
- ItemStack result = stack.copy();
- if (i >= 36)
- {
- if (!super.mergeItemStack(stack, 0, 36, false))
- {
- return null;
- }
- }
- else if (i != 36 || !this.mergeItemStack(stack, 36, 36 + (this.inventory.getSizeInventory() - 1), false))
- {
- return null;
- }
- else
- {
- return null;
- }
- if (stack.stackSize == 0)
- {
- slot.putStack(null);
- }
- else
- {
- slot.onSlotChanged();
- }
- slot.onPickupFromSlot(null, stack);
- return result;
- }
- return null;
- }
- @Override
- public boolean canInteractWith(EntityPlayer player)
- {
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement