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
@@ -19,11 +19,10 @@
package appeng.tile.spatial;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import net.minecraft.world.World;
import net.minecraftforge.items.IItemHandler;
import appeng.api.config.Actionable;
import appeng.api.config.PowerMultiplier;
@@ -45,21 +44,22 @@ import appeng.tile.TileEvent;
import appeng.tile.events.TileEventType;
import appeng.tile.grid.AENetworkInvTile;
import appeng.tile.inventory.AppEngInternalInventory;
import appeng.tile.inventory.InvOperation;
import appeng.util.IWorldCallable;
import appeng.util.Platform;
import appeng.util.inv.InvOperation;
import appeng.util.inv.filter.IAEItemFilter;
public class TileSpatialIOPort extends AENetworkInvTile implements IWorldCallable<Void>
{
private final int[] sides = { 0, 1 };
private final AppEngInternalInventory inv = new AppEngInternalInventory( this, 2 );
private YesNo lastRedstoneState = YesNo.UNDECIDED;
public TileSpatialIOPort()
{
this.getProxy().setFlags( GridFlags.REQUIRE_CHANNEL );
inv.setFilter( new SpatialIOFilter() );
}
@TileEvent( TileEventType.WORLD_NBT_WRITE )
@@ -104,7 +104,7 @@ public class TileSpatialIOPort extends AENetworkInvTile implements IWorldCallabl
{
if( Platform.isServer() )
{
final ItemStack cell = this.getStackInSlot( 0 );
final ItemStack cell = this.inv.getStackInSlot( 0 );
if( this.isSpatialCell( cell ) )
{
TickHandler.INSTANCE.addCallable( null, this );// this needs to be cross world synced.
@@ -125,8 +125,8 @@ public class TileSpatialIOPort extends AENetworkInvTile implements IWorldCallabl
@Override
public Void call( final World world ) throws Exception
{
final ItemStack cell = this.getStackInSlot( 0 );
if( this.isSpatialCell( cell ) && this.getStackInSlot( 1 ).isEmpty() )
final ItemStack cell = this.inv.getStackInSlot( 0 );
if( this.isSpatialCell( cell ) && this.inv.getStackInSlot( 1 ).isEmpty() )
{
final IGrid gi = this.getProxy().getGrid();
final IEnergyGrid energy = this.getProxy().getEnergy();
@@ -147,8 +147,8 @@ public class TileSpatialIOPort extends AENetworkInvTile implements IWorldCallabl
if( tr.success )
{
energy.extractAEPower( req, Actionable.MODULATE, PowerMultiplier.CONFIG );
this.setInventorySlotContents( 0, ItemStack.EMPTY );
this.setInventorySlotContents( 1, cell );
this.inv.setStackInSlot( 0, ItemStack.EMPTY );
this.inv.setStackInSlot( 1, cell );
}
}
}
@@ -171,45 +171,30 @@ public class TileSpatialIOPort extends AENetworkInvTile implements IWorldCallabl
}
@Override
public IInventory getInternalInventory()
public IItemHandler getInternalInventory()
{
return this.inv;
}
@Override
public boolean isItemValidForSlot( final int i, final ItemStack itemstack )
{
return( i == 0 && this.isSpatialCell( itemstack ) );
}
@Override
public void onChangeInventory( final IInventory inv, final int slot, final InvOperation mc, final ItemStack removed, final ItemStack added )
public void onChangeInventory( final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removed, final ItemStack added )
{
}
@Override
public boolean canInsertItem( final int slotIndex, final ItemStack insertingItem, final EnumFacing side )
private class SpatialIOFilter implements IAEItemFilter
{
return this.isItemValidForSlot( slotIndex, insertingItem );
}
@Override
public boolean allowExtract( IItemHandler inv, int slot, int amount )
{
return slot == 1;
}
@Override
public boolean canExtractItem( final int slotIndex, final ItemStack extractedItem, final EnumFacing side )
{
return slotIndex == 1;
}
@Override
public boolean allowInsert( IItemHandler inv, int slot, ItemStack stack )
{
return( slot == 0 && TileSpatialIOPort.this.isSpatialCell( stack ) );
}
@Override
public int[] getAccessibleSlotsBySide( final EnumFacing side )
{
return this.sides;
}
@Override
public boolean isEmpty()
{
// TODO Auto-generated method stub
return false;
}
}