-
-
Save JayZX535/c8e7a600f04d4f27fa469bb29038a4dc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.wildcraft.wildcraft.container; | |
import com.wildcraft.wildcraft.block.BlockFoodDish; | |
import com.wildcraft.wildcraft.item.ItemKibble; | |
import com.wildcraft.wildcraft.tileentity.TileEntityFoodDish; | |
import com.wildcraft.wildcraft.util.KibbleSlot; | |
import com.wildcraft.wildcraft.util.WCDishTraits; | |
import com.wildcraft.wildcraft.util.WCItems; | |
import net.minecraft.entity.player.EntityPlayer; | |
import net.minecraft.entity.player.InventoryPlayer; | |
import net.minecraft.inventory.Container; | |
import net.minecraft.inventory.IContainerListener; | |
import net.minecraft.inventory.IInventory; | |
import net.minecraft.inventory.Slot; | |
import net.minecraft.item.ItemStack; | |
import net.minecraft.util.math.BlockPos; | |
import net.minecraftforge.items.CapabilityItemHandler; | |
import net.minecraftforge.items.IItemHandler; | |
public class ContainerFoodDish extends Container{ | |
private TileEntityFoodDish fooddish; | |
IItemHandler handler; | |
public ContainerFoodDish(IInventory playerInv, TileEntityFoodDish fooddish) | |
{ | |
this.handler = fooddish.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null); | |
this.addSlotToContainer(new KibbleSlot(handler, 0, 8, 8) | |
{ | |
@Override | |
public void onSlotChanged() { | |
fooddish.markDirty(); | |
} | |
}); | |
int xPos = 8; | |
int yPos = 97; | |
for (int y = 0; y < 3; ++y) { | |
for (int x = 0; x < 9; ++x) { | |
this.addSlotToContainer(new Slot(playerInv, x + y * 9 + 9, xPos + x * 18, yPos + y * 18)); | |
} | |
} | |
for (int x = 0; x < 9; ++x) { | |
this.addSlotToContainer(new Slot(playerInv, x, xPos + x * 18, yPos + 58)); | |
} | |
} | |
@Override | |
public boolean canInteractWith(EntityPlayer playerIn) { | |
return !playerIn.isSpectator(); | |
} | |
public void addListener(IContainerListener listener) | |
{ | |
super.addListener(listener); | |
} | |
public void detectAndSendChanges() | |
{ | |
super.detectAndSendChanges(); | |
} | |
@Override | |
public ItemStack transferStackInSlot(EntityPlayer playerIn, int index) | |
{ | |
ItemStack itemstack = ItemStack.EMPTY; | |
Slot slot = (Slot)this.inventorySlots.get(index); | |
if (slot != null && slot.getHasStack()) | |
{ | |
ItemStack itemstack1 = slot.getStack(); | |
itemstack = itemstack1.copy(); | |
if (index == 0) | |
{ | |
if (!this.mergeItemStack(itemstack1, 1, this.inventorySlots.size(), true)) | |
{ | |
return ItemStack.EMPTY; | |
} | |
} | |
else if (!this.mergeItemStack(itemstack1, 0, 1, false)) | |
{ | |
return ItemStack.EMPTY; | |
} | |
if (itemstack1.isEmpty()) | |
{ | |
slot.putStack(ItemStack.EMPTY); | |
} | |
else | |
{ | |
slot.onSlotChanged(); | |
} | |
} | |
return itemstack; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment