Files
MagicBees/magicbees_src/magicbees/client/gui/SlotCustomItems.java
T

119 lines
2.2 KiB
Java
Raw Normal View History

2013-05-23 21:05:19 -07:00
package magicbees.client.gui;
2013-04-21 15:38:52 -07:00
import java.util.ArrayList;
import java.util.List;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
2013-04-21 15:38:52 -07:00
/**
*
* @author MysteriousAges
*
*/
2013-04-21 15:38:52 -07:00
public class SlotCustomItems extends Slot
{
private List<ItemStack> items;
public SlotCustomItems(IInventory inventory, int slotIndex, int xPos, int yPos)
{
this(inventory, slotIndex, xPos, yPos, new ItemStack[0]);
}
public SlotCustomItems(IInventory inventory, int slotIndex, int xPos, int yPos, ItemStack... items)
{
super(inventory, slotIndex, xPos, yPos);
this.items = new ArrayList<ItemStack>();
for (ItemStack i : items)
{
this.items.add(i);
}
}
/**
*
* @return List of valid ItemStacks
*/
2013-04-21 15:38:52 -07:00
public List<ItemStack> getValidItems()
{
return this.items;
}
public void addValidItem(ItemStack newItem)
{
boolean contains = false;
for (int i = 0; i < this.items.size(); ++i)
{
ItemStack s = this.items.get(i);
if (s.itemID == newItem.itemID)
{
if (s.getItemDamage() == OreDictionary.WILDCARD_VALUE)
2013-04-21 15:38:52 -07:00
{
contains = true;
break;
}
else if (s.getItemDamage() == newItem.getItemDamage())
{
contains = true;
break;
}
}
}
if (!contains)
{
this.items.add(newItem);
}
}
/**
*
* @param removeItem ItemStack to remove.
*/
public void removeValidItem(ItemStack removeItem)
{
for (int i = 0; i < this.items.size(); ++i)
{
ItemStack s = this.items.get(i);
if (s.itemID == removeItem.itemID)
{
if (s.getItemDamage() == OreDictionary.WILDCARD_VALUE)
2013-04-21 15:38:52 -07:00
{
this.items.remove(i);
break;
}
else if (s.getItemDamage() == removeItem.getItemDamage())
{
this.items.remove(i);
break;
}
}
}
}
@Override
public boolean isItemValid(ItemStack itemStack)
{
boolean flag = false;
for (int i = 0; i < this.items.size(); ++i)
{
if (this.items.get(i).itemID == itemStack.itemID)
{
if (this.items.get(i).getItemDamage() == itemStack.getItemDamage())
{
flag = true;
2013-04-22 16:03:27 -07:00
break;
2013-04-21 15:38:52 -07:00
}
else
{
flag = this.items.get(i).getItemDamage() ==OreDictionary.WILDCARD_VALUE;
2013-04-22 16:03:27 -07:00
break;
2013-04-21 15:38:52 -07:00
}
}
}
return flag;
}
}