Make NEI Item Extraction and crafting obey view cells.

This commit is contained in:
AlgorithmX2 2014-09-16 23:26:25 -05:00
parent ce8a34617a
commit 40ace80204
7 changed files with 427 additions and 384 deletions

View file

@ -7,6 +7,7 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.ICrafting; import net.minecraft.inventory.ICrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
import appeng.api.AEApi; import appeng.api.AEApi;
@ -344,4 +345,13 @@ public class ContainerMEMonitorable extends AEBaseContainer implements IConfigMa
return clientCM; return clientCM;
} }
public ItemStack[] getViewCells()
{
ItemStack[] list = new ItemStack[cellView.length];
for (int x = 0; x < cellView.length; x++)
list[x] = cellView[x].getStack();
return list;
}
} }

View file

@ -36,6 +36,7 @@ import appeng.container.slot.SlotRestrictedInput;
import appeng.container.slot.SlotRestrictedInput.PlaceableItemType; import appeng.container.slot.SlotRestrictedInput.PlaceableItemType;
import appeng.core.sync.packets.PacketPatternSlot; import appeng.core.sync.packets.PacketPatternSlot;
import appeng.helpers.IContainerCraftingPacket; import appeng.helpers.IContainerCraftingPacket;
import appeng.items.storage.ItemViewCell;
import appeng.parts.reporting.PartPatternTerminal; import appeng.parts.reporting.PartPatternTerminal;
import appeng.tile.inventory.AppEngInternalInventory; import appeng.tile.inventory.AppEngInternalInventory;
import appeng.tile.inventory.IAEAppEngInventory; import appeng.tile.inventory.IAEAppEngInventory;
@ -61,7 +62,8 @@ public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEA
public PartPatternTerminal ct; public PartPatternTerminal ct;
public ContainerPatternTerm(InventoryPlayer ip, ITerminalHost montiorable) { public ContainerPatternTerm(InventoryPlayer ip, ITerminalHost montiorable)
{
super( ip, montiorable, false ); super( ip, montiorable, false );
ct = (PartPatternTerminal) montiorable; ct = (PartPatternTerminal) montiorable;
@ -73,7 +75,7 @@ public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEA
for (int x = 0; x < 3; x++) for (int x = 0; x < 3; x++)
addSlotToContainer( craftingSlots[x + y * 3] = new SlotFakeCraftingMatrix( crafting, x + y * 3, 18 + x * 18, -76 + y * 18 ) ); addSlotToContainer( craftingSlots[x + y * 3] = new SlotFakeCraftingMatrix( crafting, x + y * 3, 18 + x * 18, -76 + y * 18 ) );
addSlotToContainer( craftSlot = new SlotPatternTerm( ip.player, mySrc, powerSrc, montiorable, crafting, patternInv, cOut, 110, -76 + 18, this, 2 ) ); addSlotToContainer( craftSlot = new SlotPatternTerm( ip.player, mySrc, powerSrc, montiorable, crafting, patternInv, cOut, 110, -76 + 18, this, 2, this ) );
craftSlot.IIcon = -1; craftSlot.IIcon = -1;
for (int y = 0; y < 3; y++) for (int y = 0; y < 3; y++)
@ -352,7 +354,7 @@ public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEA
if ( ic.getStackInSlot( x ) != null ) if ( ic.getStackInSlot( x ) != null )
{ {
ItemStack pulled = Platform.extractItemsByRecipe( powerSrc, mySrc, storage, p.worldObj, r, is, ic, ic.getStackInSlot( x ), x, all, ItemStack pulled = Platform.extractItemsByRecipe( powerSrc, mySrc, storage, p.worldObj, r, is, ic, ic.getStackInSlot( x ), x, all,
Actionable.MODULATE ); Actionable.MODULATE, ItemViewCell.createFilter( getViewCells() ) );
real.setInventorySlotContents( x, pulled ); real.setInventorySlotContents( x, pulled );
} }
} }

View file

@ -17,7 +17,9 @@ import appeng.api.storage.IStorageMonitorable;
import appeng.api.storage.data.IAEItemStack; import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList; import appeng.api.storage.data.IItemList;
import appeng.container.ContainerNull; import appeng.container.ContainerNull;
import appeng.helpers.IContainerCraftingPacket;
import appeng.helpers.InventoryAction; import appeng.helpers.InventoryAction;
import appeng.items.storage.ItemViewCell;
import appeng.util.InventoryAdaptor; import appeng.util.InventoryAdaptor;
import appeng.util.Platform; import appeng.util.Platform;
import appeng.util.inv.AdaptorPlayerHand; import appeng.util.inv.AdaptorPlayerHand;
@ -32,15 +34,18 @@ public class SlotCraftingTerm extends AppEngCraftingSlot
private final BaseActionSource mySrc; private final BaseActionSource mySrc;
private final IEnergySource energySrc; private final IEnergySource energySrc;
private final IStorageMonitorable storage; private final IStorageMonitorable storage;
private final IContainerCraftingPacket container;
public SlotCraftingTerm(EntityPlayer player, BaseActionSource mySrc, IEnergySource energySrc, IStorageMonitorable storage, IInventory cMatrix, public SlotCraftingTerm(EntityPlayer player, BaseActionSource mySrc, IEnergySource energySrc, IStorageMonitorable storage, IInventory cMatrix,
IInventory secondMatrix, IInventory output, int x, int y) { IInventory secondMatrix, IInventory output, int x, int y, IContainerCraftingPacket ccp)
{
super( player, cMatrix, output, 0, x, y ); super( player, cMatrix, output, 0, x, y );
this.energySrc = energySrc; this.energySrc = energySrc;
this.storage = storage; this.storage = storage;
this.mySrc = mySrc; this.mySrc = mySrc;
pattern = cMatrix; pattern = cMatrix;
craftInv = secondMatrix; craftInv = secondMatrix;
container = ccp;
} }
public IInventory getCraftingMatrix() public IInventory getCraftingMatrix()
@ -114,7 +119,7 @@ public class SlotCraftingTerm extends AppEngCraftingSlot
if ( pattern.getStackInSlot( x ) != null ) if ( pattern.getStackInSlot( x ) != null )
{ {
set[x] = Platform.extractItemsByRecipe( energySrc, mySrc, inv, p.worldObj, r, is, ic, pattern.getStackInSlot( x ), x, all, set[x] = Platform.extractItemsByRecipe( energySrc, mySrc, inv, p.worldObj, r, is, ic, pattern.getStackInSlot( x ), x, all,
Actionable.MODULATE ); Actionable.MODULATE, ItemViewCell.createFilter( container.getViewCells() ) );
ic.setInventorySlotContents( x, set[x] ); ic.setInventorySlotContents( x, set[x] );
} }
} }

View file

@ -11,6 +11,7 @@ import appeng.api.networking.security.BaseActionSource;
import appeng.api.storage.IStorageMonitorable; import appeng.api.storage.IStorageMonitorable;
import appeng.core.sync.AppEngPacket; import appeng.core.sync.AppEngPacket;
import appeng.core.sync.packets.PacketPatternSlot; import appeng.core.sync.packets.PacketPatternSlot;
import appeng.helpers.IContainerCraftingPacket;
public class SlotPatternTerm extends SlotCraftingTerm public class SlotPatternTerm extends SlotCraftingTerm
{ {
@ -19,8 +20,9 @@ public class SlotPatternTerm extends SlotCraftingTerm
IOptionalSlotHost host; IOptionalSlotHost host;
public SlotPatternTerm(EntityPlayer player, BaseActionSource mySrc, IEnergySource energySrc, IStorageMonitorable storage, IInventory cMatrix, public SlotPatternTerm(EntityPlayer player, BaseActionSource mySrc, IEnergySource energySrc, IStorageMonitorable storage, IInventory cMatrix,
IInventory secondMatrix, IInventory output, int x, int y, IOptionalSlotHost h, int grpnum) { IInventory secondMatrix, IInventory output, int x, int y, IOptionalSlotHost h, int grpnum, IContainerCraftingPacket c)
super( player, mySrc, energySrc, storage, cMatrix, secondMatrix, output, x, y ); {
super( player, mySrc, energySrc, storage, cMatrix, secondMatrix, output, x, y, c );
host = h; host = h;
groupNum = grpnum; groupNum = grpnum;

View file

@ -32,8 +32,10 @@ import appeng.container.ContainerNull;
import appeng.core.sync.AppEngPacket; import appeng.core.sync.AppEngPacket;
import appeng.core.sync.network.INetworkInfo; import appeng.core.sync.network.INetworkInfo;
import appeng.helpers.IContainerCraftingPacket; import appeng.helpers.IContainerCraftingPacket;
import appeng.items.storage.ItemViewCell;
import appeng.util.Platform; import appeng.util.Platform;
import appeng.util.item.AEItemStack; import appeng.util.item.AEItemStack;
import appeng.util.prioitylist.IPartitionList;
public class PacketNEIRecipe extends AppEngPacket public class PacketNEIRecipe extends AppEngPacket
{ {
@ -41,7 +43,8 @@ public class PacketNEIRecipe extends AppEngPacket
ItemStack[][] recipe; ItemStack[][] recipe;
// automatic. // automatic.
public PacketNEIRecipe(ByteBuf stream) throws IOException { public PacketNEIRecipe(ByteBuf stream) throws IOException
{
ByteArrayInputStream bytes = new ByteArrayInputStream( stream.array() ); ByteArrayInputStream bytes = new ByteArrayInputStream( stream.array() );
bytes.skip( stream.readerIndex() ); bytes.skip( stream.readerIndex() );
NBTTagCompound comp = CompressedStreamTools.readCompressed( bytes ); NBTTagCompound comp = CompressedStreamTools.readCompressed( bytes );
@ -50,13 +53,13 @@ public class PacketNEIRecipe extends AppEngPacket
recipe = new ItemStack[9][]; recipe = new ItemStack[9][];
for (int x = 0; x < recipe.length; x++) for (int x = 0; x < recipe.length; x++)
{ {
NBTTagList list = comp.getTagList( "#"+x, 10 ); NBTTagList list = comp.getTagList( "#" + x, 10 );
if ( list.tagCount() > 0 ) if ( list.tagCount() > 0 )
{ {
recipe[x] = new ItemStack[ list.tagCount() ]; recipe[x] = new ItemStack[list.tagCount()];
for ( int y = 0; y < list.tagCount(); y++ ) for (int y = 0; y < list.tagCount(); y++)
{ {
recipe[x][y] = ItemStack.loadItemStackFromNBT( list.getCompoundTagAt(y) ); recipe[x][y] = ItemStack.loadItemStackFromNBT( list.getCompoundTagAt( y ) );
} }
} }
} }
@ -91,7 +94,7 @@ public class PacketNEIRecipe extends AppEngPacket
InventoryCrafting ic = new InventoryCrafting( new ContainerNull(), 3, 3 ); InventoryCrafting ic = new InventoryCrafting( new ContainerNull(), 3, 3 );
for (int x = 0; x < 9; x++) for (int x = 0; x < 9; x++)
{ {
if ( recipe[x] != null && recipe[x].length > 0 ) if ( recipe[x] != null && recipe[x].length > 0 )
{ {
ic.setInventorySlotContents( x, recipe[x][0] ); ic.setInventorySlotContents( x, recipe[x][0] );
} }
@ -107,6 +110,7 @@ public class PacketNEIRecipe extends AppEngPacket
{ {
IMEMonitor<IAEItemStack> stor = inv.getItemInventory(); IMEMonitor<IAEItemStack> stor = inv.getItemInventory();
IItemList all = stor.getStorageList(); IItemList all = stor.getStorageList();
IPartitionList<IAEItemStack> filter = ItemViewCell.createFilter( cct.getViewCells() );
for (int x = 0; x < craftMatrix.getSizeInventory(); x++) for (int x = 0; x < craftMatrix.getSizeInventory(); x++)
{ {
@ -138,22 +142,25 @@ public class PacketNEIRecipe extends AppEngPacket
if ( PatternItem != null && currentItem == null ) if ( PatternItem != null && currentItem == null )
{ {
ItemStack whichItem = Platform.extractItemsByRecipe( energy, cct.getSource(), stor, player.worldObj, r, ItemStack whichItem = Platform.extractItemsByRecipe( energy, cct.getSource(), stor, player.worldObj, r, is, ic,
is, ic, PatternItem, x, all, realForFake ); PatternItem, x, all, realForFake, filter );
if ( whichItem == null ) if ( whichItem == null )
{ {
for ( int y = 0; y < recipe[x].length; y++ ) for (int y = 0; y < recipe[x].length; y++)
{ {
IAEItemStack request = AEItemStack.create( recipe[x][y] ); IAEItemStack request = AEItemStack.create( recipe[x][y] );
if ( request != null ) if ( request != null )
{ {
request.setStackSize( 1 ); if ( filter == null || filter.isListed( request ) )
IAEItemStack out = Platform.poweredExtraction( energy, stor, request, cct.getSource() );
if ( out != null )
{ {
whichItem = out.getItemStack(); request.setStackSize( 1 );
break; IAEItemStack out = Platform.poweredExtraction( energy, stor, request, cct.getSource() );
if ( out != null )
{
whichItem = out.getItemStack();
break;
}
} }
} }
} }
@ -171,7 +178,8 @@ public class PacketNEIRecipe extends AppEngPacket
} }
// api // api
public PacketNEIRecipe(NBTTagCompound recipe) throws IOException { public PacketNEIRecipe(NBTTagCompound recipe) throws IOException
{
ByteBuf data = Unpooled.buffer(); ByteBuf data = Unpooled.buffer();
ByteArrayOutputStream bytes = new ByteArrayOutputStream(); ByteArrayOutputStream bytes = new ByteArrayOutputStream();

View file

@ -1,6 +1,7 @@
package appeng.helpers; package appeng.helpers;
import net.minecraft.inventory.IInventory; import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import appeng.api.networking.IGridNode; import appeng.api.networking.IGridNode;
import appeng.api.networking.security.BaseActionSource; import appeng.api.networking.security.BaseActionSource;
@ -28,4 +29,9 @@ public interface IContainerCraftingPacket
*/ */
boolean useRealItems(); boolean useRealItems();
/**
* @return array of view cells
*/
ItemStack[] getViewCells();
} }

View file

@ -105,6 +105,7 @@ import appeng.util.item.AEItemStack;
import appeng.util.item.AESharedNBT; import appeng.util.item.AESharedNBT;
import appeng.util.item.OreHelper; import appeng.util.item.OreHelper;
import appeng.util.item.OreRefrence; import appeng.util.item.OreRefrence;
import appeng.util.prioitylist.IPartitionList;
import buildcraft.api.tools.IToolWrench; import buildcraft.api.tools.IToolWrench;
import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.Loader;
@ -384,7 +385,8 @@ public class Platform
{ {
switch (id) switch (id)
{ {
case 10: { case 10:
{
NBTTagCompound ctA = (NBTTagCompound) A; NBTTagCompound ctA = (NBTTagCompound) A;
NBTTagCompound ctB = (NBTTagCompound) B; NBTTagCompound ctB = (NBTTagCompound) B;
@ -510,7 +512,8 @@ public class Platform
hash += id; hash += id;
switch (id) switch (id)
{ {
case 10: { case 10:
{
NBTTagCompound ctA = (NBTTagCompound) A; NBTTagCompound ctA = (NBTTagCompound) A;
Set<String> cA = ctA.func_150296_c(); Set<String> cA = ctA.func_150296_c();
@ -1615,7 +1618,8 @@ public class Platform
} }
public static ItemStack extractItemsByRecipe(IEnergySource energySrc, BaseActionSource mySrc, IMEMonitor<IAEItemStack> src, World w, IRecipe r, public static ItemStack extractItemsByRecipe(IEnergySource energySrc, BaseActionSource mySrc, IMEMonitor<IAEItemStack> src, World w, IRecipe r,
ItemStack output, InventoryCrafting ci, ItemStack providedTemplate, int slot, IItemList<IAEItemStack> aitems, Actionable realForFake) ItemStack output, InventoryCrafting ci, ItemStack providedTemplate, int slot, IItemList<IAEItemStack> aitems, Actionable realForFake,
IPartitionList<IAEItemStack> filter)
{ {
if ( energySrc.extractAEPower( 1, Actionable.SIMULATE, PowerMultiplier.CONFIG ) > 0.9 ) if ( energySrc.extractAEPower( 1, Actionable.SIMULATE, PowerMultiplier.CONFIG ) > 0.9 )
{ {
@ -1625,14 +1629,17 @@ public class Platform
AEItemStack ae_req = AEItemStack.create( providedTemplate ); AEItemStack ae_req = AEItemStack.create( providedTemplate );
ae_req.setStackSize( 1 ); ae_req.setStackSize( 1 );
IAEItemStack ae_ext = src.extractItems( ae_req, realForFake, mySrc ); if ( filter == null || filter.isListed( ae_req ) )
if ( ae_ext != null )
{ {
ItemStack extracted = ae_ext.getItemStack(); IAEItemStack ae_ext = src.extractItems( ae_req, realForFake, mySrc );
if ( extracted != null ) if ( ae_ext != null )
{ {
energySrc.extractAEPower( 1, realForFake, PowerMultiplier.CONFIG ); ItemStack extracted = ae_ext.getItemStack();
return extracted; if ( extracted != null )
{
energySrc.extractAEPower( 1, realForFake, PowerMultiplier.CONFIG );
return extracted;
}
} }
} }
@ -1653,11 +1660,14 @@ public class Platform
{ {
IAEItemStack ax = x.copy(); IAEItemStack ax = x.copy();
ax.setStackSize( 1 ); ax.setStackSize( 1 );
IAEItemStack ex = src.extractItems( ax, realForFake, mySrc ); if ( filter == null || filter.isListed( ax ) )
if ( ex != null )
{ {
energySrc.extractAEPower( 1, realForFake, PowerMultiplier.CONFIG ); IAEItemStack ex = src.extractItems( ax, realForFake, mySrc );
return ex.getItemStack(); if ( ex != null )
{
energySrc.extractAEPower( 1, realForFake, PowerMultiplier.CONFIG );
return ex.getItemStack();
}
} }
} }
ci.setInventorySlotContents( slot, providedTemplate ); ci.setInventorySlotContents( slot, providedTemplate );