Expose IItemHandler on vanilla entities

This commit is contained in:
Vincent Lee 2016-03-21 09:24:36 -05:00
parent 558348125d
commit 30db41be9a
8 changed files with 164 additions and 9 deletions

View file

@ -285,3 +285,38 @@
}
this.func_184602_cy();
@@ -2626,4 +2707,34 @@
{
return true;
}
+
+ // FORGE
+ private final net.minecraftforge.items.IItemHandlerModifiable handHandler = new net.minecraftforge.items.ItemStackHandler(field_184630_bs);
+ private final net.minecraftforge.items.IItemHandlerModifiable armorHandler = new net.minecraftforge.items.ItemStackHandler(field_184631_bt);
+ private final net.minecraftforge.items.IItemHandler joinedHandler = new net.minecraftforge.items.wrapper.CombinedInvWrapper(armorHandler, handHandler);
+
+ @Override
+ public <T> T getCapability(net.minecraftforge.common.capabilities.Capability<T> capability, net.minecraft.util.EnumFacing facing)
+ {
+ if (capability == net.minecraftforge.items.CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)
+ {
+ if (facing == net.minecraft.util.EnumFacing.UP)
+ {
+ return (T) armorHandler;
+ } else if (facing.func_176740_k().func_176722_c())
+ {
+ return (T) handHandler;
+ } else
+ {
+ return (T) joinedHandler;
+ }
+ }
+ return super.getCapability(capability, facing);
+ }
+
+ @Override
+ public boolean hasCapability(net.minecraftforge.common.capabilities.Capability<?> capability, net.minecraft.util.EnumFacing facing)
+ {
+ return capability == net.minecraftforge.items.CapabilityItemHandler.ITEM_HANDLER_CAPABILITY || super.hasCapability(capability, facing);
+ }
}

View file

@ -1,6 +1,14 @@
--- ../src-base/minecraft/net/minecraft/entity/passive/EntityHorse.java
+++ ../src-work/minecraft/net/minecraft/entity/passive/EntityHorse.java
@@ -1200,6 +1200,7 @@
@@ -433,6 +433,7 @@
this.field_110296_bG.func_110134_a(this);
this.func_110232_cE();
+ this.itemHandler = new net.minecraftforge.items.wrapper.InvWrapper(this.field_110296_bG);
}
private void func_110232_cE()
@@ -1200,6 +1201,7 @@
}
this.field_110277_bt = 0.0F;
@ -8,3 +16,29 @@
}
this.field_70138_W = 1.0F;
@@ -1793,4 +1795,25 @@
this.field_188477_b = p_i46589_2_;
}
}
+
+ // FORGE
+ private net.minecraftforge.items.IItemHandler itemHandler = null; // Initialized by initHorseChest above.
+
+ @Override
+ public <T> T getCapability(net.minecraftforge.common.capabilities.Capability<T> capability, net.minecraft.util.EnumFacing facing)
+ {
+ if (capability == net.minecraftforge.items.CapabilityItemHandler.ITEM_HANDLER_CAPABILITY
+ && itemHandler != null)
+ {
+ return (T) itemHandler;
+ }
+ return super.getCapability(capability, facing);
+ }
+
+ @Override
+ public boolean hasCapability(net.minecraftforge.common.capabilities.Capability<?> capability, net.minecraft.util.EnumFacing facing)
+ {
+ return capability == net.minecraftforge.items.CapabilityItemHandler.ITEM_HANDLER_CAPABILITY && itemHandler != null
+ || super.hasCapability(capability, facing);
+ }
}

View file

@ -401,7 +401,7 @@
if (this.func_70608_bn())
{
@@ -2340,6 +2447,136 @@
@@ -2340,6 +2447,169 @@
return (float)this.func_110148_a(SharedMonsterAttributes.field_188792_h).func_111126_e();
}
@ -533,6 +533,39 @@
+ public java.util.Collection<ITextComponent> getPrefixes() { return this.prefixes; }
+ public java.util.Collection<ITextComponent> getSuffixes() { return this.suffixes; }
+
+ private final net.minecraftforge.items.IItemHandler playerMainHandler = new net.minecraftforge.items.wrapper.PlayerMainInvWrapper(field_71071_by);
+ private final net.minecraftforge.items.IItemHandler playerArmorHandler = new net.minecraftforge.items.wrapper.PlayerArmorInvWrapper(field_71071_by);
+ private final net.minecraftforge.items.IItemHandler playerOffhandHandler = new net.minecraftforge.items.wrapper.PlayerOffhandInvWrapper(field_71071_by);
+ private final net.minecraftforge.items.IItemHandler playerJoinedHandler = new net.minecraftforge.items.wrapper.PlayerInvWrapper(field_71071_by);
+
+ @Override
+ public <T> T getCapability(net.minecraftforge.common.capabilities.Capability<T> capability, net.minecraft.util.EnumFacing facing)
+ {
+ if (capability == net.minecraftforge.items.CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)
+ {
+ if (facing == net.minecraft.util.EnumFacing.UP)
+ {
+ return (T) playerArmorHandler;
+ } else if (facing == net.minecraft.util.EnumFacing.DOWN)
+ {
+ return (T) playerMainHandler;
+ } else if (facing.func_176740_k().func_176722_c())
+ {
+ return (T) playerOffhandHandler;
+ } else
+ {
+ return (T) playerJoinedHandler;
+ }
+ }
+ return super.getCapability(capability, facing);
+ }
+
+ @Override
+ public boolean hasCapability(net.minecraftforge.common.capabilities.Capability<?> capability, net.minecraft.util.EnumFacing facing)
+ {
+ return capability == net.minecraftforge.items.CapabilityItemHandler.ITEM_HANDLER_CAPABILITY || super.hasCapability(capability, facing);
+ }
+
+ /* ======================================== FORGE END =====================================*/
+
public static enum EnumChatVisibility

View file

@ -20,6 +20,11 @@ public class ItemStackHandler implements IItemHandler, IItemHandlerModifiable, I
stacks = new ItemStack[size];
}
public ItemStackHandler(ItemStack[] stacks)
{
this.stacks = stacks;
}
public void setSize(int size)
{
stacks = new ItemStack[size];

View file

@ -7,7 +7,7 @@ import net.minecraft.item.ItemStack;
public class PlayerArmorInvWrapper extends InvWrapper
{
public final InventoryPlayer inventoryPlayer;
public final int offset;
private final int offset;
public PlayerArmorInvWrapper(InventoryPlayer inv)
{

View file

@ -6,6 +6,6 @@ public class PlayerInvWrapper extends CombinedInvWrapper
{
public PlayerInvWrapper(InventoryPlayer inv)
{
super(new PlayerMainInvWrapper(inv), new PlayerArmorInvWrapper(inv));
super(new PlayerMainInvWrapper(inv), new PlayerArmorInvWrapper(inv), new PlayerOffhandInvWrapper(inv));
}
}

View file

@ -10,7 +10,6 @@ import net.minecraft.item.ItemStack;
*/
public class PlayerMainInvWrapper extends InvWrapper
{
public final InventoryPlayer inventoryPlayer;
public PlayerMainInvWrapper(InventoryPlayer inv)
@ -29,7 +28,7 @@ public class PlayerMainInvWrapper extends InvWrapper
@Override
public void setStackInSlot(int slot, ItemStack stack)
{
// prevent setting of armor inventory
// prevent setting of armor and offhand
if (slot > getSlots())
{
return;
@ -40,7 +39,7 @@ public class PlayerMainInvWrapper extends InvWrapper
@Override
public ItemStack getStackInSlot(int slot)
{
// prevent getting of armor inventory
// prevent getting of armor and offhand
if (slot > getSlots())
{
return null;
@ -51,7 +50,7 @@ public class PlayerMainInvWrapper extends InvWrapper
@Override
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate)
{
// prevent inserting into armor inventory
// prevent inserting into armor and offhand
if (slot > getSlots())
{
return stack;
@ -79,7 +78,7 @@ public class PlayerMainInvWrapper extends InvWrapper
@Override
public ItemStack extractItem(int slot, int amount, boolean simulate)
{
// prevent extraction from armor inventory
// prevent extraction from armor and offhand
if (slot > getSlots())
{
return null;

View file

@ -0,0 +1,49 @@
package net.minecraftforge.items.wrapper;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
public class PlayerOffhandInvWrapper extends InvWrapper
{
public final InventoryPlayer inventoryPlayer;
private final int offset;
public PlayerOffhandInvWrapper(InventoryPlayer inv)
{
super(inv);
inventoryPlayer = inv;
offset = inventoryPlayer.mainInventory.length + inventoryPlayer.armorInventory.length;
}
@Override
public int getSlots()
{
return inventoryPlayer.offHandInventory.length;
}
@Override
public ItemStack getStackInSlot(int slot)
{
return super.getStackInSlot(slot + offset);
}
@Override
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate)
{
return super.insertItem(slot + offset, stack, simulate);
}
@Override
public void setStackInSlot(int slot, ItemStack stack)
{
super.setStackInSlot(slot + offset, stack);
}
@Override
public ItemStack extractItem(int slot, int amount, boolean simulate)
{
return super.extractItem(slot + offset, amount, simulate);
}
}