Use IItemHandler instead of IInventory internally (#2971)
* Use IItemHandler instead of IInventory internally
This commit is contained in:
@@ -38,7 +38,7 @@ public class CellConfig extends AppEngInternalInventory
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty()
|
||||
protected void onContentsChanged( int slot )
|
||||
{
|
||||
this.writeToNBT( Platform.openNbtData( this.is ), "list" );
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ public final class CellUpgrades extends StackUpgradeInventory
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty()
|
||||
protected void onContentsChanged( int slot )
|
||||
{
|
||||
this.writeToNBT( Platform.openNbtData( this.is ), "upgrades" );
|
||||
}
|
||||
|
||||
@@ -19,18 +19,20 @@
|
||||
package appeng.items.contents;
|
||||
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
import appeng.api.implementations.guiobjects.INetworkTool;
|
||||
import appeng.api.implementations.items.IUpgradeModule;
|
||||
import appeng.api.networking.IGridHost;
|
||||
import appeng.tile.inventory.AppEngInternalInventory;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.inv.IAEAppEngInventory;
|
||||
import appeng.util.inv.InvOperation;
|
||||
import appeng.util.inv.filter.IAEItemFilter;
|
||||
|
||||
|
||||
public class NetworkToolViewer implements INetworkTool
|
||||
public class NetworkToolViewer implements INetworkTool, IAEAppEngInventory
|
||||
{
|
||||
|
||||
private final AppEngInternalInventory inv;
|
||||
@@ -41,7 +43,8 @@ public class NetworkToolViewer implements INetworkTool
|
||||
{
|
||||
this.is = is;
|
||||
this.gh = gHost;
|
||||
this.inv = new AppEngInternalInventory( null, 9 );
|
||||
this.inv = new AppEngInternalInventory( this, 9 );
|
||||
this.inv.setFilter( new NetworkToolInventoryFilter() );
|
||||
if( is.hasTagCompound() ) // prevent crash when opening network status screen.
|
||||
{
|
||||
this.inv.readFromNBT( Platform.openNbtData( is ), "inv" );
|
||||
@@ -49,85 +52,17 @@ public class NetworkToolViewer implements INetworkTool
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory()
|
||||
public void saveChanges()
|
||||
{
|
||||
return this.inv.getSizeInventory();
|
||||
inv.markDirty( -1 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot( final int i )
|
||||
public void onChangeInventory( IItemHandler inv, int slot, InvOperation mc, ItemStack removedStack, ItemStack newStack )
|
||||
{
|
||||
return this.inv.getStackInSlot( i );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize( final int i, final int j )
|
||||
{
|
||||
return this.inv.decrStackSize( i, j );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeStackFromSlot( int i )
|
||||
{
|
||||
return this.inv.removeStackFromSlot( i );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents( final int i, final ItemStack itemstack )
|
||||
{
|
||||
this.inv.setInventorySlotContents( i, itemstack );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return this.inv.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomName()
|
||||
{
|
||||
return this.inv.hasCustomName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit()
|
||||
{
|
||||
return this.inv.getInventoryStackLimit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty()
|
||||
{
|
||||
this.inv.markDirty();
|
||||
this.inv.writeToNBT( Platform.openNbtData( this.is ), "inv" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUsableByPlayer( final EntityPlayer entityplayer )
|
||||
{
|
||||
return this.inv.isUsableByPlayer( entityplayer );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory( final EntityPlayer player )
|
||||
{
|
||||
this.inv.openInventory( player );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory( final EntityPlayer player )
|
||||
{
|
||||
this.inv.closeInventory( player );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot( final int i, final ItemStack itemstack )
|
||||
{
|
||||
return this.inv.isItemValidForSlot( i,
|
||||
itemstack ) && itemstack.getItem() instanceof IUpgradeModule && ( (IUpgradeModule) itemstack.getItem() ).getType( itemstack ) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItemStack()
|
||||
{
|
||||
@@ -140,39 +75,29 @@ public class NetworkToolViewer implements INetworkTool
|
||||
return this.gh;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getField( final int id )
|
||||
private static class NetworkToolInventoryFilter implements IAEItemFilter
|
||||
{
|
||||
return this.inv.getField( id );
|
||||
@Override
|
||||
public boolean allowExtract( IItemHandler inv, int slot, int amount )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allowInsert( IItemHandler inv, int slot, ItemStack stack )
|
||||
{
|
||||
return stack.getItem() instanceof IUpgradeModule && ( (IUpgradeModule) stack.getItem() ).getType( stack ) != null;
|
||||
}
|
||||
}
|
||||
|
||||
public IItemHandler getInternalInventory()
|
||||
{
|
||||
return inv;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setField( final int id, final int value )
|
||||
public IItemHandler getInventory()
|
||||
{
|
||||
this.inv.setField( id, value );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFieldCount()
|
||||
{
|
||||
return this.inv.getFieldCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear()
|
||||
{
|
||||
this.inv.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITextComponent getDisplayName()
|
||||
{
|
||||
return this.inv.getDisplayName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty()
|
||||
{
|
||||
return false;
|
||||
return this.inv;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,6 @@ import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
@@ -51,6 +50,7 @@ import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import appeng.api.config.Upgrades;
|
||||
@@ -68,6 +68,7 @@ import appeng.core.features.MaterialStackSrc;
|
||||
import appeng.items.AEBaseItem;
|
||||
import appeng.util.InventoryAdaptor;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.inv.AdaptorItemHandler;
|
||||
|
||||
|
||||
public final class ItemMaterial extends AEBaseItem implements IStorageComponent, IUpgradeModule
|
||||
@@ -289,7 +290,7 @@ public final class ItemMaterial extends AEBaseItem implements IStorageComponent,
|
||||
if( player.isSneaking() )
|
||||
{
|
||||
final TileEntity te = world.getTileEntity( pos );
|
||||
IInventory upgrades = null;
|
||||
IItemHandler upgrades = null;
|
||||
|
||||
if( te instanceof IPartHost )
|
||||
{
|
||||
@@ -311,17 +312,14 @@ public final class ItemMaterial extends AEBaseItem implements IStorageComponent,
|
||||
|
||||
if( u != null )
|
||||
{
|
||||
final InventoryAdaptor ad = InventoryAdaptor.getAdaptor( upgrades, EnumFacing.UP );
|
||||
if( ad != null )
|
||||
if( player.world.isRemote )
|
||||
{
|
||||
if( player.world.isRemote )
|
||||
{
|
||||
return EnumActionResult.PASS;
|
||||
}
|
||||
|
||||
player.inventory.setInventorySlotContents( player.inventory.currentItem, ad.addItems( player.getHeldItem( hand ) ) );
|
||||
return EnumActionResult.SUCCESS;
|
||||
return EnumActionResult.PASS;
|
||||
}
|
||||
|
||||
final InventoryAdaptor ad = new AdaptorItemHandler( upgrades );
|
||||
player.inventory.setInventorySlotContents( player.inventory.currentItem, ad.addItems( player.getHeldItem( hand ) ) );
|
||||
return EnumActionResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@ import java.util.Set;
|
||||
import net.minecraft.client.util.ITooltipFlag;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
@@ -35,6 +34,7 @@ import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.FuzzyMode;
|
||||
@@ -188,13 +188,13 @@ public final class ItemBasicStorageCell extends AEBaseItem implements IStorageCe
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getUpgradesInventory( final ItemStack is )
|
||||
public IItemHandler getUpgradesInventory( final ItemStack is )
|
||||
{
|
||||
return new CellUpgrades( is, 2 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getConfigInventory( final ItemStack is )
|
||||
public IItemHandler getConfigInventory( final ItemStack is )
|
||||
{
|
||||
return new CellConfig( is );
|
||||
}
|
||||
@@ -239,7 +239,7 @@ public final class ItemBasicStorageCell extends AEBaseItem implements IStorageCe
|
||||
final IMEInventoryHandler inv = AEApi.instance().registries().cell().getCellInventory( stack, null, StorageChannel.ITEMS );
|
||||
if( inv != null && playerInventory.getCurrentItem() == stack )
|
||||
{
|
||||
final InventoryAdaptor ia = InventoryAdaptor.getAdaptor( player, EnumFacing.UP );
|
||||
final InventoryAdaptor ia = InventoryAdaptor.getAdaptor( player );
|
||||
final IItemList<IAEItemStack> list = inv.getAvailableItems( StorageChannel.ITEMS.createList() );
|
||||
if( list.isEmpty() && ia != null )
|
||||
{
|
||||
@@ -253,8 +253,8 @@ public final class ItemBasicStorageCell extends AEBaseItem implements IStorageCe
|
||||
}
|
||||
|
||||
// drop upgrades
|
||||
final IInventory upgradesInventory = this.getUpgradesInventory( stack );
|
||||
for( int upgradeIndex = 0; upgradeIndex < upgradesInventory.getSizeInventory(); upgradeIndex++ )
|
||||
final IItemHandler upgradesInventory = this.getUpgradesInventory( stack );
|
||||
for( int upgradeIndex = 0; upgradeIndex < upgradesInventory.getSlots(); upgradeIndex++ )
|
||||
{
|
||||
final ItemStack upgradeStack = upgradesInventory.getStackInSlot( upgradeIndex );
|
||||
final ItemStack leftStack = ia.addItems( upgradeStack );
|
||||
|
||||
@@ -22,11 +22,11 @@ package appeng.items.storage;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.util.ITooltipFlag;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.FuzzyMode;
|
||||
@@ -53,13 +53,13 @@ public class ItemCreativeStorageCell extends AEBaseItem implements ICellWorkbenc
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getUpgradesInventory( final ItemStack is )
|
||||
public IItemHandler getUpgradesInventory( final ItemStack is )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getConfigInventory( final ItemStack is )
|
||||
public IItemHandler getConfigInventory( final ItemStack is )
|
||||
{
|
||||
return new CellConfig( is );
|
||||
}
|
||||
|
||||
@@ -19,8 +19,8 @@
|
||||
package appeng.items.storage;
|
||||
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.FuzzyMode;
|
||||
@@ -65,14 +65,14 @@ public class ItemViewCell extends AEBaseItem implements ICellWorkbenchItem
|
||||
final IItemList<IAEItemStack> priorityList = AEApi.instance().storage().createItemList();
|
||||
|
||||
final ICellWorkbenchItem vc = (ICellWorkbenchItem) currentViewCell.getItem();
|
||||
final IInventory upgrades = vc.getUpgradesInventory( currentViewCell );
|
||||
final IInventory config = vc.getConfigInventory( currentViewCell );
|
||||
final IItemHandler upgrades = vc.getUpgradesInventory( currentViewCell );
|
||||
final IItemHandler config = vc.getConfigInventory( currentViewCell );
|
||||
final FuzzyMode fzMode = vc.getFuzzyMode( currentViewCell );
|
||||
|
||||
boolean hasInverter = false;
|
||||
boolean hasFuzzy = false;
|
||||
|
||||
for( int x = 0; x < upgrades.getSizeInventory(); x++ )
|
||||
for( int x = 0; x < upgrades.getSlots(); x++ )
|
||||
{
|
||||
final ItemStack is = upgrades.getStackInSlot( x );
|
||||
if( !is.isEmpty() && is.getItem() instanceof IUpgradeModule )
|
||||
@@ -94,7 +94,7 @@ public class ItemViewCell extends AEBaseItem implements ICellWorkbenchItem
|
||||
}
|
||||
}
|
||||
|
||||
for( int x = 0; x < config.getSizeInventory(); x++ )
|
||||
for( int x = 0; x < config.getSlots(); x++ )
|
||||
{
|
||||
final ItemStack is = config.getStackInSlot( x );
|
||||
if( !is.isEmpty() )
|
||||
@@ -129,13 +129,13 @@ public class ItemViewCell extends AEBaseItem implements ICellWorkbenchItem
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getUpgradesInventory( final ItemStack is )
|
||||
public IItemHandler getUpgradesInventory( final ItemStack is )
|
||||
{
|
||||
return new CellUpgrades( is, 2 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getConfigInventory( final ItemStack is )
|
||||
public IItemHandler getConfigInventory( final ItemStack is )
|
||||
{
|
||||
return new CellConfig( is );
|
||||
}
|
||||
|
||||
@@ -37,7 +37,6 @@ import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.util.ITooltipFlag;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.EnumDyeColor;
|
||||
import net.minecraft.item.ItemSnowball;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -50,6 +49,7 @@ import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
@@ -516,13 +516,13 @@ public class ToolColorApplicator extends AEBasePoweredItem implements IStorageCe
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getUpgradesInventory( final ItemStack is )
|
||||
public IItemHandler getUpgradesInventory( final ItemStack is )
|
||||
{
|
||||
return new CellUpgrades( is, 2 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getConfigInventory( final ItemStack is )
|
||||
public IItemHandler getConfigInventory( final ItemStack is )
|
||||
{
|
||||
return new CellConfig( is );
|
||||
}
|
||||
|
||||
@@ -31,7 +31,6 @@ import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.passive.EntitySheep;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ActionResult;
|
||||
@@ -46,6 +45,7 @@ import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.Actionable;
|
||||
@@ -445,13 +445,13 @@ public class ToolMatterCannon extends AEBasePoweredItem implements IStorageCell
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getUpgradesInventory( final ItemStack is )
|
||||
public IItemHandler getUpgradesInventory( final ItemStack is )
|
||||
{
|
||||
return new CellUpgrades( is, 4 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getConfigInventory( final ItemStack is )
|
||||
public IItemHandler getConfigInventory( final ItemStack is )
|
||||
{
|
||||
return new CellConfig( is );
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@ import java.util.Set;
|
||||
|
||||
import net.minecraft.client.util.ITooltipFlag;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
@@ -33,6 +32,7 @@ import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.FuzzyMode;
|
||||
@@ -152,13 +152,13 @@ public class ToolPortableCell extends AEBasePoweredItem implements IStorageCell,
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getUpgradesInventory( final ItemStack is )
|
||||
public IItemHandler getUpgradesInventory( final ItemStack is )
|
||||
{
|
||||
return new CellUpgrades( is, 2 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getConfigInventory( final ItemStack is )
|
||||
public IItemHandler getConfigInventory( final ItemStack is )
|
||||
{
|
||||
return new CellConfig( is );
|
||||
}
|
||||
|
||||
@@ -27,7 +27,6 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.capabilities.ICapabilityProvider;
|
||||
import net.minecraftforge.energy.CapabilityEnergy;
|
||||
import net.minecraftforge.energy.IEnergyStorage;
|
||||
|
||||
import appeng.api.config.PowerUnits;
|
||||
|
||||
Reference in New Issue
Block a user