Use IItemHandler instead of IInventory internally (#2971)
* Use IItemHandler instead of IInventory internally
This commit is contained in:
@@ -21,14 +21,13 @@ package appeng.container.implementations;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.IContainerListener;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.items.wrapper.EmptyHandler;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.CopyMode;
|
||||
@@ -43,16 +42,16 @@ import appeng.container.guisync.GuiSync;
|
||||
import appeng.container.slot.OptionalSlotRestrictedInput;
|
||||
import appeng.container.slot.SlotFakeTypeOnly;
|
||||
import appeng.container.slot.SlotRestrictedInput;
|
||||
import appeng.tile.inventory.AppEngNullInventory;
|
||||
import appeng.tile.misc.TileCellWorkbench;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.helpers.ItemHandlerUtil;
|
||||
import appeng.util.inv.WrapperLazyItemHandler;
|
||||
import appeng.util.iterators.NullIterator;
|
||||
|
||||
|
||||
public class ContainerCellWorkbench extends ContainerUpgradeable
|
||||
{
|
||||
private final TileCellWorkbench workBench;
|
||||
private final AppEngNullInventory nullInventory = new AppEngNullInventory();
|
||||
@GuiSync( 2 )
|
||||
public CopyMode copyMode = CopyMode.CLEAR_ON_REMOVE;
|
||||
private ItemStack prevStack = ItemStack.EMPTY;
|
||||
@@ -92,11 +91,11 @@ public class ContainerCellWorkbench extends ContainerUpgradeable
|
||||
@Override
|
||||
protected void setupConfig()
|
||||
{
|
||||
final IInventory cell = this.getUpgradeable().getInventoryByName( "cell" );
|
||||
final IItemHandler cell = this.getUpgradeable().getInventoryByName( "cell" );
|
||||
this.addSlotToContainer( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.WORKBENCH_CELL, cell, 0, 152, 8, this.getPlayerInv() ) );
|
||||
|
||||
final IInventory inv = this.getUpgradeable().getInventoryByName( "config" );
|
||||
final IInventory upgradeInventory = new Upgrades();
|
||||
final IItemHandler inv = this.getUpgradeable().getInventoryByName( "config" );
|
||||
final WrapperLazyItemHandler upgradeInventory = new WrapperLazyItemHandler( this::getCellUpgradeInventory );
|
||||
// null, 3 * 8 );
|
||||
|
||||
int offset = 0;
|
||||
@@ -138,7 +137,7 @@ public class ContainerCellWorkbench extends ContainerUpgradeable
|
||||
if( this.prevStack != is )
|
||||
{
|
||||
this.prevStack = is;
|
||||
this.lastUpgrades = this.getCellUpgradeInventory().getSizeInventory();
|
||||
this.lastUpgrades = this.getCellUpgradeInventory().getSlots();
|
||||
}
|
||||
return this.lastUpgrades;
|
||||
}
|
||||
@@ -189,11 +188,11 @@ public class ContainerCellWorkbench extends ContainerUpgradeable
|
||||
return idx < this.availableUpgrades();
|
||||
}
|
||||
|
||||
public IInventory getCellUpgradeInventory()
|
||||
public IItemHandler getCellUpgradeInventory()
|
||||
{
|
||||
final IInventory upgradeInventory = this.workBench.getCellUpgradeInventory();
|
||||
final IItemHandler upgradeInventory = this.workBench.getCellUpgradeInventory();
|
||||
|
||||
return upgradeInventory == null ? this.nullInventory : upgradeInventory;
|
||||
return upgradeInventory == null ? EmptyHandler.INSTANCE : upgradeInventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -209,11 +208,7 @@ public class ContainerCellWorkbench extends ContainerUpgradeable
|
||||
|
||||
public void clear()
|
||||
{
|
||||
final IInventory inv = this.getUpgradeable().getInventoryByName( "config" );
|
||||
for( int x = 0; x < inv.getSizeInventory(); x++ )
|
||||
{
|
||||
inv.setInventorySlotContents( x, ItemStack.EMPTY );
|
||||
}
|
||||
ItemHandlerUtil.clear( this.getUpgradeable().getInventoryByName( "config" ) );
|
||||
this.detectAndSendChanges();
|
||||
}
|
||||
|
||||
@@ -229,7 +224,7 @@ public class ContainerCellWorkbench extends ContainerUpgradeable
|
||||
|
||||
public void partition()
|
||||
{
|
||||
final IInventory inv = this.getUpgradeable().getInventoryByName( "config" );
|
||||
final IItemHandler inv = this.getUpgradeable().getInventoryByName( "config" );
|
||||
|
||||
final IMEInventory<IAEItemStack> cellInv = AEApi.instance().registries().cell().getCellInventory(
|
||||
this.getUpgradeable().getInventoryByName( "cell" ).getStackInSlot( 0 ), null, StorageChannel.ITEMS );
|
||||
@@ -241,17 +236,17 @@ public class ContainerCellWorkbench extends ContainerUpgradeable
|
||||
i = list.iterator();
|
||||
}
|
||||
|
||||
for( int x = 0; x < inv.getSizeInventory(); x++ )
|
||||
for( int x = 0; x < inv.getSlots(); x++ )
|
||||
{
|
||||
if( i.hasNext() )
|
||||
{
|
||||
final ItemStack g = i.next().getItemStack();
|
||||
g.setCount( 1 );
|
||||
inv.setInventorySlotContents( x, g );
|
||||
ItemHandlerUtil.setStackInSlot( inv, x, g );
|
||||
}
|
||||
else
|
||||
{
|
||||
inv.setInventorySlotContents( x, ItemStack.EMPTY );
|
||||
ItemHandlerUtil.setStackInSlot( inv, x, ItemStack.EMPTY );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -267,131 +262,4 @@ public class ContainerCellWorkbench extends ContainerUpgradeable
|
||||
{
|
||||
this.copyMode = copyMode;
|
||||
}
|
||||
|
||||
private class Upgrades implements IInventory
|
||||
{
|
||||
|
||||
@Override
|
||||
public int getSizeInventory()
|
||||
{
|
||||
return ContainerCellWorkbench.this.getCellUpgradeInventory().getSizeInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot( final int i )
|
||||
{
|
||||
return ContainerCellWorkbench.this.getCellUpgradeInventory().getStackInSlot( i );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize( final int i, final int j )
|
||||
{
|
||||
final IInventory inv = ContainerCellWorkbench.this.getCellUpgradeInventory();
|
||||
final ItemStack is = inv.decrStackSize( i, j );
|
||||
inv.markDirty();
|
||||
return is;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeStackFromSlot( final int i )
|
||||
{
|
||||
final IInventory inv = ContainerCellWorkbench.this.getCellUpgradeInventory();
|
||||
final ItemStack is = inv.removeStackFromSlot( i );
|
||||
inv.markDirty();
|
||||
return is;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents( final int i, final ItemStack itemstack )
|
||||
{
|
||||
final IInventory inv = ContainerCellWorkbench.this.getCellUpgradeInventory();
|
||||
inv.setInventorySlotContents( i, itemstack );
|
||||
inv.markDirty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return "Upgrades";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomName()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUsableByPlayer( EntityPlayer player )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory( final EntityPlayer player )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory( final EntityPlayer player )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot( final int i, final ItemStack itemstack )
|
||||
{
|
||||
return ContainerCellWorkbench.this.getCellUpgradeInventory().isItemValidForSlot( i, itemstack );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITextComponent getDisplayName()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getField( final int id )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setField( final int id, final int value )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFieldCount()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear()
|
||||
{
|
||||
ContainerCellWorkbench.this.getCellUpgradeInventory().clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user