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
@@ -25,7 +25,7 @@ import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import appeng.api.config.Upgrades;
import appeng.tile.inventory.IAEAppEngInventory;
import appeng.util.inv.IAEAppEngInventory;
public class BlockUpgradeInventory extends UpgradeInventory
@@ -23,7 +23,7 @@ import net.minecraft.item.ItemStack;
import appeng.api.config.Upgrades;
import appeng.api.definitions.IItemDefinition;
import appeng.tile.inventory.IAEAppEngInventory;
import appeng.util.inv.IAEAppEngInventory;
public final class DefinitionUpgradeInventory extends UpgradeInventory
@@ -26,7 +26,6 @@ import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemFirework;
@@ -43,6 +42,7 @@ import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraft.world.chunk.Chunk;
import net.minecraftforge.common.IPlantable;
import net.minecraftforge.items.IItemHandler;
import appeng.api.AEApi;
import appeng.api.config.AccessRestriction;
@@ -78,8 +78,8 @@ import appeng.items.parts.PartModels;
import appeng.me.GridAccessException;
import appeng.me.storage.MEInventoryHandler;
import appeng.tile.inventory.AppEngInternalAEInventory;
import appeng.tile.inventory.InvOperation;
import appeng.util.Platform;
import appeng.util.inv.InvOperation;
import appeng.util.prioritylist.FuzzyPriorityList;
import appeng.util.prioritylist.PrecisePriorityList;
@@ -119,7 +119,7 @@ public class PartFormationPlane extends PartUpgradeable implements ICellContaine
final IItemList<IAEItemStack> priorityList = AEApi.instance().storage().createItemList();
final int slotsToUse = 18 + this.getInstalledUpgrades( Upgrades.CAPACITY ) * 9;
for( int x = 0; x < this.Config.getSizeInventory() && x < slotsToUse; x++ )
for( int x = 0; x < this.Config.getSlots() && x < slotsToUse; x++ )
{
final IAEItemStack is = this.Config.getAEStackInSlot( x );
if( is != null )
@@ -161,7 +161,7 @@ public class PartFormationPlane extends PartUpgradeable implements ICellContaine
}
@Override
public void onChangeInventory( final IInventory inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack )
public void onChangeInventory( final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack )
{
super.onChangeInventory( inv, slot, mc, removedStack, newStack );
@@ -195,7 +195,7 @@ public class PartFormationPlane extends PartUpgradeable implements ICellContaine
}
@Override
public IInventory getInventoryByName( final String name )
public IItemHandler getInventoryByName( final String name )
{
if( name.equals( "config" ) )
{
@@ -456,7 +456,6 @@ public class PartFormationPlane extends PartUpgradeable implements ICellContaine
EnumHand hand = player.getActiveHand();
player.setHeldItem( hand, is );
// TODO: LIMIT FIREWORKS
/*
* if( i instanceof ItemFirework )
@@ -23,7 +23,6 @@ import java.util.Collection;
import java.util.Random;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@@ -34,6 +33,7 @@ import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraftforge.items.IItemHandler;
import appeng.api.config.FuzzyMode;
import appeng.api.config.LevelType;
@@ -76,8 +76,8 @@ import appeng.items.parts.PartModels;
import appeng.me.GridAccessException;
import appeng.parts.PartModel;
import appeng.tile.inventory.AppEngInternalAEInventory;
import appeng.tile.inventory.InvOperation;
import appeng.util.Platform;
import appeng.util.inv.InvOperation;
public class PartLevelEmitter extends PartUpgradeable implements IEnergyWatcherHost, IStackWatcherHost, ICraftingWatcherHost, IMEMonitorHandlerReceiver<IAEItemStack>, ICraftingProvider
@@ -479,7 +479,7 @@ public class PartLevelEmitter extends PartUpgradeable implements IEnergyWatcherH
}
@Override
public void onChangeInventory( final IInventory inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack )
public void onChangeInventory( final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack )
{
if( inv == this.config )
{
@@ -522,7 +522,7 @@ public class PartLevelEmitter extends PartUpgradeable implements IEnergyWatcherH
}
@Override
public IInventory getInventoryByName( final String name )
public IItemHandler getInventoryByName( final String name )
{
if( name.equals( "config" ) )
{
@@ -19,11 +19,11 @@
package appeng.parts.automation;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.items.IItemHandler;
import appeng.api.config.RedstoneMode;
import appeng.api.config.Upgrades;
@@ -69,7 +69,7 @@ public abstract class PartSharedItemBus extends PartUpgradeable implements IGrid
}
@Override
public IInventory getInventoryByName( final String name )
public IItemHandler getInventoryByName( final String name )
{
if( name.equals( "config" ) )
{
@@ -125,7 +125,7 @@ public abstract class PartSharedItemBus extends PartUpgradeable implements IGrid
protected int availableSlots()
{
return Math.min( 1 + this.getInstalledUpgrades( Upgrades.CAPACITY ) * 4, this.getConfig().getSizeInventory() );
return Math.min( 1 + this.getInstalledUpgrades( Upgrades.CAPACITY ) * 4, this.getConfig().getSlots() );
}
protected int calculateItemsToSend()
@@ -21,17 +21,17 @@ package appeng.parts.automation;
import java.util.List;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.IItemHandler;
import appeng.api.config.RedstoneMode;
import appeng.api.config.Upgrades;
import appeng.api.util.IConfigManager;
import appeng.parts.PartBasicState;
import appeng.tile.inventory.IAEAppEngInventory;
import appeng.tile.inventory.InvOperation;
import appeng.util.ConfigManager;
import appeng.util.IConfigManagerHost;
import appeng.util.inv.IAEAppEngInventory;
import appeng.util.inv.InvOperation;
public abstract class PartUpgradeable extends PartBasicState implements IAEAppEngInventory, IConfigManagerHost
@@ -59,7 +59,7 @@ public abstract class PartUpgradeable extends PartBasicState implements IAEAppEn
}
@Override
public void onChangeInventory( final IInventory inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack )
public void onChangeInventory( final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack )
{
if( inv == this.upgrades )
{
@@ -155,7 +155,7 @@ public abstract class PartUpgradeable extends PartBasicState implements IAEAppEn
}
@Override
public IInventory getInventoryByName( final String name )
public IItemHandler getInventoryByName( final String name )
{
if( name.equals( "upgrades" ) )
{
@@ -22,8 +22,8 @@ package appeng.parts.automation;
import net.minecraft.item.ItemStack;
import appeng.api.config.Upgrades;
import appeng.tile.inventory.IAEAppEngInventory;
import appeng.util.Platform;
import appeng.util.inv.IAEAppEngInventory;
public class StackUpgradeInventory extends UpgradeInventory
@@ -20,17 +20,18 @@ package appeng.parts.automation;
import net.minecraft.init.Items;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.items.IItemHandler;
import appeng.api.config.Upgrades;
import appeng.api.implementations.items.IUpgradeModule;
import appeng.tile.inventory.AppEngInternalInventory;
import appeng.tile.inventory.IAEAppEngInventory;
import appeng.tile.inventory.InvOperation;
import appeng.util.Platform;
import appeng.util.inv.IAEAppEngInventory;
import appeng.util.inv.InvOperation;
import appeng.util.inv.filter.IAEItemFilter;
public abstract class UpgradeInventory extends AppEngInternalInventory implements IAEAppEngInventory
@@ -47,9 +48,10 @@ public abstract class UpgradeInventory extends AppEngInternalInventory implement
public UpgradeInventory( final IAEAppEngInventory parent, final int s )
{
super( null, s );
super( null, s, 1 );
this.setTileEntity( this );
this.parent = parent;
this.setFilter( new UpgradeInvFilter() );
}
@Override
@@ -58,31 +60,6 @@ public abstract class UpgradeInventory extends AppEngInternalInventory implement
return true;
}
@Override
public int getInventoryStackLimit()
{
return 1;
}
@Override
public boolean isItemValidForSlot( final int i, final ItemStack itemstack )
{
if( itemstack.isEmpty() )
{
return false;
}
final Item it = itemstack.getItem();
if( it instanceof IUpgradeModule )
{
final Upgrades u = ( (IUpgradeModule) it ).getType( itemstack );
if( u != null )
{
return this.getInstalledUpgrades( u ) < this.getMaxInstalled( u );
}
}
return false;
}
public int getInstalledUpgrades( final Upgrades u )
{
if( !this.cached )
@@ -171,7 +148,7 @@ public abstract class UpgradeInventory extends AppEngInternalInventory implement
}
@Override
public void onChangeInventory( final IInventory inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack )
public void onChangeInventory( final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack )
{
this.cached = false;
if( this.parent != null && Platform.isServer() )
@@ -179,4 +156,33 @@ public abstract class UpgradeInventory extends AppEngInternalInventory implement
this.parent.onChangeInventory( inv, slot, mc, removedStack, newStack );
}
}
private class UpgradeInvFilter implements IAEItemFilter
{
@Override
public boolean allowExtract( IItemHandler inv, int slot, int amount )
{
return true;
}
@Override
public boolean allowInsert( IItemHandler inv, int slot, ItemStack itemstack )
{
if( itemstack.isEmpty() )
{
return false;
}
final Item it = itemstack.getItem();
if( it instanceof IUpgradeModule )
{
final Upgrades u = ( (IUpgradeModule) it ).getType( itemstack );
if( u != null )
{
return getInstalledUpgrades( u ) < getMaxInstalled( u );
}
}
return false;
}
}
}