Use IItemHandler instead of IInventory internally (#2971)

* Use IItemHandler instead of IInventory internally
This commit is contained in:
fscan
2017-07-28 22:04:32 +02:00
committed by yueh
parent c077840988
commit 52d28fabe3
156 changed files with 2410 additions and 4604 deletions
@@ -20,11 +20,14 @@ package appeng.container.slot;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.util.NonNullList;
import net.minecraftforge.items.IItemHandler;
import appeng.util.helpers.ItemHandlerUtil;
import appeng.util.inv.WrapperInvItemHandler;
public class AppEngCraftingSlot extends AppEngSlot
@@ -33,7 +36,7 @@ public class AppEngCraftingSlot extends AppEngSlot
/**
* The craft matrix inventory linked to this result slot.
*/
private final IInventory craftMatrix;
private final IItemHandler craftMatrix;
/**
* The player that is using the GUI where this slot resides.
@@ -45,7 +48,7 @@ public class AppEngCraftingSlot extends AppEngSlot
*/
private int amountCrafted;
public AppEngCraftingSlot( final EntityPlayer par1EntityPlayer, final IInventory par2IInventory, final IInventory par3IInventory, final int par4, final int par5, final int par6 )
public AppEngCraftingSlot( final EntityPlayer par1EntityPlayer, final IItemHandler par2IInventory, final IItemHandler par3IInventory, final int par4, final int par5, final int par6 )
{
super( par3IInventory, par4, par5, par6 );
this.thePlayer = par1EntityPlayer;
@@ -136,22 +139,19 @@ public class AppEngCraftingSlot extends AppEngSlot
@Override
public ItemStack onTake( final EntityPlayer playerIn, final ItemStack stack )
{
net.minecraftforge.fml.common.FMLCommonHandler.instance().firePlayerCraftingEvent( playerIn, stack, this.craftMatrix );
net.minecraftforge.fml.common.FMLCommonHandler.instance().firePlayerCraftingEvent( playerIn, stack, new WrapperInvItemHandler( this.craftMatrix ) );
this.onCrafting( stack );
net.minecraftforge.common.ForgeHooks.setCraftingPlayer( playerIn );
final InventoryCrafting ic = new InventoryCrafting( this.getContainer(), 3, 3 );
for( int x = 0; x < this.craftMatrix.getSizeInventory(); x++ )
for( int x = 0; x < this.craftMatrix.getSlots(); x++ )
{
ic.setInventorySlotContents( x, this.craftMatrix.getStackInSlot( x ) );
}
final NonNullList<ItemStack> aitemstack = CraftingManager.getRemainingItems( ic, playerIn.world );
for( int x = 0; x < this.craftMatrix.getSizeInventory(); x++ )
{
this.craftMatrix.setInventorySlotContents( x, ic.getStackInSlot( x ) );
}
ItemHandlerUtil.copy( ic, this.craftMatrix, false );
net.minecraftforge.common.ForgeHooks.setCraftingPlayer( null );
@@ -162,14 +162,14 @@ public class AppEngCraftingSlot extends AppEngSlot
if( !itemstack1.isEmpty() )
{
this.craftMatrix.decrStackSize( i, 1 );
this.craftMatrix.extractItem( i, 1, false );
}
if( !itemstack2.isEmpty() )
{
if( this.craftMatrix.getStackInSlot( i ).isEmpty() )
{
this.craftMatrix.setInventorySlotContents( i, itemstack2 );
ItemHandlerUtil.setStackInSlot( this.craftMatrix, i, itemstack2 );
}
else if( !this.thePlayer.inventory.addItemStackToInventory( itemstack2 ) )
{