ForgePatch/src/main/java/net/minecraftforge/items/wrapper/PlayerArmorInvWrapper.java

37 lines
1.1 KiB
Java
Raw Normal View History

2016-01-02 13:38:18 +00:00
package net.minecraftforge.items.wrapper;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.EntityEquipmentSlot;
2016-01-02 13:38:18 +00:00
import net.minecraft.item.ItemStack;
2016-03-22 01:31:33 +00:00
public class PlayerArmorInvWrapper extends RangedWrapper
2016-01-02 13:38:18 +00:00
{
public final InventoryPlayer inventoryPlayer;
public PlayerArmorInvWrapper(InventoryPlayer inv)
{
2016-03-22 01:31:33 +00:00
super(new InvWrapper(inv), inv.mainInventory.length, inv.mainInventory.length + inv.armorInventory.length);
2016-01-02 13:38:18 +00:00
inventoryPlayer = inv;
}
@Override
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate)
{
EntityEquipmentSlot equ = null;
for (EntityEquipmentSlot s : EntityEquipmentSlot.values())
{
if (s.getSlotType() == EntityEquipmentSlot.Type.ARMOR && s.getIndex() == slot)
{
equ = s;
break;
}
}
2016-01-02 13:38:18 +00:00
// check if it's valid for the armor slot
if (slot < 4 && stack != null && stack.getItem().isValidArmor(stack, equ, inventoryPlayer.player))
2016-01-02 13:38:18 +00:00
{
2016-03-22 01:31:33 +00:00
return super.insertItem(slot, stack, simulate);
2016-01-02 13:38:18 +00:00
}
return stack;
}
}