Package cofh.lib.gui.slot

Source Code of cofh.lib.gui.slot.SlotSpecificItem

package cofh.lib.gui.slot;

import cofh.lib.inventory.ComparableItemStack;

import net.minecraft.init.Blocks;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;

/**
* Slot which is restricted to a specific item and maximum amount.
*
* @author King Lemming
*
*/
public class SlotSpecificItem extends Slot {

  protected final ComparableItemStack stack;
  protected ComparableItemStack query = new ComparableItemStack(new ItemStack(Blocks.stone));
  protected int slotStackLimit = -1;

  public SlotSpecificItem(IInventory inventory, int index, int x, int y, ItemStack stack) {

    super(inventory, index, x, y);

    this.stack = new ComparableItemStack(stack);
  }

  @Override
  public boolean isItemValid(ItemStack stack) {

    return this.stack.isItemEqual(query.set(stack));
  }

  public SlotSpecificItem setSlotStackLimit(int slotStackLimit) {

    this.slotStackLimit = slotStackLimit;
    return this;
  }

  @Override
  public int getSlotStackLimit() {

    return slotStackLimit <= 0 ? inventory.getInventoryStackLimit() : slotStackLimit;
  }

}
TOP

Related Classes of cofh.lib.gui.slot.SlotSpecificItem

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.