Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package RUMatter.containers;
- 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;
- import RUMatter.tileEntities.TileEntityRUMad;
- public class ContainerRUMad extends Container {
- protected TileEntityRUMad tileEntity;
- public ContainerRUMad(InventoryPlayer playerInv, TileEntityRUMad tileEntity) {
- this.tileEntity = tileEntity;
- this.addSlotToContainer(new Slot(tileEntity, 0, 26, 15 + 24));
- this.addSlotToContainer(new Slot(tileEntity, 1, 57, 15 + 24));
- this.addSlotToContainer(new Slot(tileEntity, 2, 123, 15 + 24));
- bindPlayerInventory(playerInv);
- }
- @Override
- public boolean canInteractWith(EntityPlayer player) {
- return tileEntity.isUseableByPlayer(player);
- }
- protected void bindPlayerInventory(InventoryPlayer inv) {
- for (int y = 0; y < 3; y++) {
- for (int x = 0; x < 9; x++) {
- addSlotToContainer(new Slot(inv, x + y * 9 + 9, 8 + x * 18, 44 + y * 18 + 24));
- }
- }
- for (int i = 0; i < 9; i++) {
- addSlotToContainer(new Slot(inv, i, 8 + i * 18, 102 + 24));
- }
- }
- @Override
- public ItemStack transferStackInSlot(EntityPlayer player, int slot) {
- ItemStack stack = null;
- Slot slotObject = (Slot) inventorySlots.get(slot);
- // null checks and checks if the item can be stacked (maxStackSize > 1)
- if (slotObject != null && slotObject.getHasStack()) {
- ItemStack stackInSlot = slotObject.getStack();
- stack = stackInSlot.copy();
- // merges the item into player inventory since its in the tileEntity
- if (slot < 3) {
- if (!this.mergeItemStack(stackInSlot, 0, 35, true)) { return null; }
- }
- // places it into the tileEntity is possible since its in the player
- // inventory
- else if (!this.mergeItemStack(stackInSlot, 0, 3, false)) { return null; }
- if (stackInSlot.stackSize == 0) {
- slotObject.putStack(null);
- } else {
- slotObject.onSlotChanged();
- }
- if (stackInSlot.stackSize == stack.stackSize) { return null; }
- slotObject.onPickupFromSlot(player, stackInSlot);
- }
- return stack;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment