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

64 lines
2.0 KiB
Java
Raw Normal View History

/*
* Minecraft Forge
* Copyright (c) 2016.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
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-11-13 22:09:54 +00:00
import javax.annotation.Nonnull;
2016-03-22 01:31:33 +00:00
public class PlayerArmorInvWrapper extends RangedWrapper
2016-01-02 13:38:18 +00:00
{
private final InventoryPlayer inventoryPlayer;
2016-01-02 13:38:18 +00:00
public PlayerArmorInvWrapper(InventoryPlayer inv)
{
2016-11-13 22:09:54 +00:00
super(new InvWrapper(inv), inv.mainInventory.size(), inv.mainInventory.size() + inv.armorInventory.size());
2016-01-02 13:38:18 +00:00
inventoryPlayer = inv;
}
@Override
2016-11-13 22:09:54 +00:00
@Nonnull
public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate)
2016-01-02 13:38:18 +00:00
{
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 (equ != null && slot < 4 && !stack.isEmpty() && stack.getItem().isValidArmor(stack, equ, getInventoryPlayer().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;
}
public InventoryPlayer getInventoryPlayer()
{
return inventoryPlayer;
}
2016-01-02 13:38:18 +00:00
}