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
@@ -24,12 +24,12 @@ import java.util.Arrays;
import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.items.IItemHandler;
import appeng.api.config.Actionable;
import appeng.api.networking.energy.IEnergySource;
@@ -44,22 +44,25 @@ import appeng.helpers.InventoryAction;
import appeng.items.storage.ItemViewCell;
import appeng.util.InventoryAdaptor;
import appeng.util.Platform;
import appeng.util.inv.AdaptorPlayerHand;
import appeng.util.helpers.ItemHandlerUtil;
import appeng.util.inv.AdaptorItemHandler;
import appeng.util.inv.WrapperCursorItemHandler;
import appeng.util.inv.WrapperInvItemHandler;
import appeng.util.item.AEItemStack;
public class SlotCraftingTerm extends AppEngCraftingSlot
{
private final IInventory craftInv;
private final IInventory pattern;
private final IItemHandler craftInv;
private final IItemHandler pattern;
private final BaseActionSource mySrc;
private final IEnergySource energySrc;
private final IStorageMonitorable storage;
private final IContainerCraftingPacket container;
public SlotCraftingTerm( final EntityPlayer player, final BaseActionSource mySrc, final IEnergySource energySrc, final IStorageMonitorable storage, final IInventory cMatrix, final IInventory secondMatrix, final IInventory output, final int x, final int y, final IContainerCraftingPacket ccp )
public SlotCraftingTerm( final EntityPlayer player, final BaseActionSource mySrc, final IEnergySource energySrc, final IStorageMonitorable storage, final IItemHandler cMatrix, final IItemHandler secondMatrix, final IItemHandler output, final int x, final int y, final IContainerCraftingPacket ccp )
{
super( player, cMatrix, output, 0, x, y );
this.energySrc = energySrc;
@@ -70,7 +73,7 @@ public class SlotCraftingTerm extends AppEngCraftingSlot
this.container = ccp;
}
public IInventory getCraftingMatrix()
public IItemHandler getCraftingMatrix()
{
return this.craftInv;
}
@@ -105,18 +108,18 @@ public class SlotCraftingTerm extends AppEngCraftingSlot
InventoryAdaptor ia = null;
if( action == InventoryAction.CRAFT_SHIFT ) // craft into player inventory...
{
ia = InventoryAdaptor.getAdaptor( who, null );
ia = InventoryAdaptor.getAdaptor( who );
maxTimesToCraft = (int) Math.floor( (double) this.getStack().getMaxStackSize() / (double) howManyPerCraft );
}
else if( action == InventoryAction.CRAFT_STACK ) // craft into hand, full stack
{
ia = new AdaptorPlayerHand( who );
ia = new AdaptorItemHandler( new WrapperCursorItemHandler( who.inventory ) );
maxTimesToCraft = (int) Math.floor( (double) this.getStack().getMaxStackSize() / (double) howManyPerCraft );
}
else
// pick up what was crafted...
{
ia = new AdaptorPlayerHand( who );
ia = new AdaptorItemHandler( new WrapperCursorItemHandler( who.inventory ) );
maxTimesToCraft = 1;
}
@@ -162,7 +165,7 @@ public class SlotCraftingTerm extends AppEngCraftingSlot
if( !is.isEmpty() && Platform.itemComparisons().isEqualItem( request, is ) )
{
final ItemStack[] set = new ItemStack[this.getPattern().getSizeInventory()];
final ItemStack[] set = new ItemStack[this.getPattern().getSlots()];
// Safeguard for empty slots in the inventory for now
Arrays.fill( set, ItemStack.EMPTY );
@@ -199,7 +202,7 @@ public class SlotCraftingTerm extends AppEngCraftingSlot
{
super.onTake( p, is );
// actually necessary to cleanup this case...
p.openContainer.onCraftMatrixChanged( this.craftInv );
p.openContainer.onCraftMatrixChanged( new WrapperInvItemHandler( this.craftInv ) );
return request;
}
}
@@ -210,7 +213,7 @@ public class SlotCraftingTerm extends AppEngCraftingSlot
if( inv != null )
{
for( int x = 0; x < this.getPattern().getSizeInventory(); x++ )
for( int x = 0; x < this.getPattern().getSlots(); x++ )
{
if( !this.getPattern().getStackInSlot( x ).isEmpty() )
{
@@ -229,8 +232,7 @@ public class SlotCraftingTerm extends AppEngCraftingSlot
this.postCraft( p, inv, set, is );
}
// shouldn't be necessary...
p.openContainer.onCraftMatrixChanged( this.craftInv );
p.openContainer.onCraftMatrixChanged( new WrapperInvItemHandler( this.craftInv ) );
return is;
}
@@ -256,11 +258,11 @@ public class SlotCraftingTerm extends AppEngCraftingSlot
if( Platform.isServer() )
{
// set new items onto the crafting table...
for( int x = 0; x < this.craftInv.getSizeInventory(); x++ )
for( int x = 0; x < this.craftInv.getSlots(); x++ )
{
if( this.craftInv.getStackInSlot( x ).isEmpty() )
{
this.craftInv.setInventorySlotContents( x, set[x] );
ItemHandlerUtil.setStackInSlot( this.craftInv, x, set[x] );
}
else if( !set[x].isEmpty() )
{
@@ -280,7 +282,7 @@ public class SlotCraftingTerm extends AppEngCraftingSlot
}
}
IInventory getPattern()
IItemHandler getPattern()
{
return this.pattern;
}