Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.theviolentsquirrels.questsystem.inventory;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.entity.player.InventoryPlayer;
- import net.minecraft.init.Blocks;
- import net.minecraft.inventory.IInventory;
- import net.minecraft.inventory.InventoryBasic;
- import net.minecraft.inventory.InventoryCraftResult;
- import net.minecraft.inventory.Slot;
- import net.minecraft.item.Item;
- import net.minecraft.item.ItemStack;
- import net.minecraft.world.World;
- public class ContainerSieve extends ModContainer {
- private IInventory sieveInventory;
- private IInventory siftingResult;
- private World worldObj;
- public ContainerSieve(InventoryPlayer playerInventory, World worldIn) {
- this.worldObj = worldIn;
- this.sieveInventory = new InventoryBasic("container.sifting", false, 1);
- this.siftingResult = new InventoryCraftResult();
- this.addSlotToContainer(new Slot(this.sieveInventory, 0, 48, 35));
- this.addSlotToContainer(new SlotSiftingResult(this.siftingResult, 0, 124, 35));
- this.addPlayerSlots(playerInventory);
- }
- @Override
- public boolean canInteractWith(EntityPlayer playerIn) {
- return (true);
- }
- @Override
- public void onContainerClosed(EntityPlayer playerIn) {
- super.onContainerClosed(playerIn);
- if (!this.worldObj.isRemote) {
- ItemStack itemStack;
- itemStack = this.sieveInventory.removeStackFromSlot(0);
- if (itemStack != null)
- playerIn.dropPlayerItemWithRandomChoice(itemStack, false);
- itemStack = this.siftingResult.removeStackFromSlot(1);
- if (itemStack != null)
- playerIn.dropPlayerItemWithRandomChoice(itemStack, false);
- }
- }
- @Override
- public ItemStack transferStackInSlot(EntityPlayer playerIn, int index) {
- ItemStack itemStack = null;
- Slot slot = this.inventorySlots.get(index);
- if (slot != null && slot.getHasStack()) {
- ItemStack itemStack1 = slot.getStack();
- itemStack = itemStack1.copy();
- if (index < 2) {
- if (!this.mergeItemStack(itemStack1, 2, 28, index == 1))
- return (null);
- slot.onSlotChange(itemStack1, itemStack);
- } else {
- if (this.canBeSifted(itemStack1)) {
- if (!this.mergeItemStack(itemStack1, 0, 1, false))
- return (null);
- } else if (index >= 2 && index <= 28) {
- if (!this.mergeItemStack(itemStack1, 29, 37, false))
- return (null);
- } else if (index >= 29 && index <= 37) {
- if (!this.mergeItemStack(itemStack1, 2, 28, false))
- return (null);
- }
- }
- if (itemStack1.stackSize == 0)
- slot.putStack(null);
- else
- slot.onSlotChanged();
- if (itemStack1.stackSize == itemStack.stackSize)
- return (null);
- slot.onPickupFromSlot(playerIn, itemStack1);
- }
- return (itemStack);
- }
- @Override
- public ItemStack slotClick(int slotId, int clickedButton, int mode, EntityPlayer playerIn) {
- boolean result;
- result = slotId >= 0 && this.getSlot(slotId) != null &&
- this.getSlot(slotId).getStack() == playerIn.getHeldItem();
- if (result) return (null);
- return super.slotClick(slotId, clickedButton, mode, playerIn);
- }
- private boolean canBeSifted(ItemStack itemStack) {
- return (itemStack.getItem() == Item.getItemFromBlock(Blocks.gravel));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement