/** * MrCrayfish's Furniture Mod * Copyright (C) 2016 MrCrayfish (http://www.mrcrayfish.com/) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package com.mrcrayfish.furniture.gui.containers; import com.mrcrayfish.furniture.gui.slots.SlotFridge; 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.ItemFood; import net.minecraft.item.ItemStack; public class ContainerFridge extends Container { private IInventory lowerChestInventory; private int numRows; public ContainerFridge(IInventory playerInventory, IInventory fridgeInventory) { this.lowerChestInventory = playerInventory; fridgeInventory.openInventory(null); int var4, var5; int count = 0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 5; j++) { this.addSlotToContainer(new SlotFridge(fridgeInventory, count, j * 18 + 44, i * 18 + 18)); count++; } } for (int i = 0; i < 3; i++) { for (int j = 0; j < 9; ++j) { this.addSlotToContainer(new Slot(playerInventory, j + i * 9 + 9, j * 18 + 8, i * 18 + 85)); } } for (int i = 0; i < 9; i++) { this.addSlotToContainer(new Slot(playerInventory, i, i * 18 + 8, 143)); } } public boolean canInteractWith(EntityPlayer par1EntityPlayer) { return this.lowerChestInventory.isUsableByPlayer(par1EntityPlayer); } public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2) { ItemStack var3 = ItemStack.EMPTY; Slot var4 = (Slot) this.inventorySlots.get(par2); if (var4 != null && var4.getHasStack()) { ItemStack var5 = var4.getStack(); var3 = var5.copy(); if (!(var5.getItem() instanceof ItemFood)) return ItemStack.EMPTY; if (par2 < 16) { if (!this.mergeItemStack(var5, 16, this.inventorySlots.size(), true)) { return ItemStack.EMPTY; } } else if (!this.mergeItemStack(var5, 0, 16, false)) { return ItemStack.EMPTY; } if (var5.getCount() == 0) { var4.putStack(ItemStack.EMPTY); } else { var4.onSlotChanged(); } } return var3; } /** * Callback for when the crafting gui is closed. */ public void onContainerClosed(EntityPlayer par1EntityPlayer) { super.onContainerClosed(par1EntityPlayer); this.lowerChestInventory.closeInventory(par1EntityPlayer); } public IInventory func_85151_d() { return this.lowerChestInventory; } }