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.InventoryPlayer;
import net.minecraft.inventory.ICrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import appeng.api.AEApi;
@ -344,4 +345,13 @@ public class ContainerMEMonitorable extends AEBaseContainer implements IConfigMa
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.core.sync.packets.PacketPatternSlot;
import appeng.helpers.IContainerCraftingPacket;
import appeng.items.storage.ItemViewCell;
import appeng.parts.reporting.PartPatternTerminal;
import appeng.tile.inventory.AppEngInternalInventory;
import appeng.tile.inventory.IAEAppEngInventory;
@ -61,7 +62,8 @@ public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEA
public PartPatternTerminal ct;
public ContainerPatternTerm(InventoryPlayer ip, ITerminalHost montiorable) {
public ContainerPatternTerm(InventoryPlayer ip, ITerminalHost montiorable)
{
super( ip, montiorable, false );
ct = (PartPatternTerminal) montiorable;
@ -73,7 +75,7 @@ public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEA
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( 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;
for (int y = 0; y < 3; y++)
@ -352,7 +354,7 @@ public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEA
if ( ic.getStackInSlot( x ) != null )
{
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 );
}
}

View file

@ -17,7 +17,9 @@ import appeng.api.storage.IStorageMonitorable;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
import appeng.container.ContainerNull;
import appeng.helpers.IContainerCraftingPacket;
import appeng.helpers.InventoryAction;
import appeng.items.storage.ItemViewCell;
import appeng.util.InventoryAdaptor;
import appeng.util.Platform;
import appeng.util.inv.AdaptorPlayerHand;
@ -32,15 +34,18 @@ public class SlotCraftingTerm extends AppEngCraftingSlot
private final BaseActionSource mySrc;
private final IEnergySource energySrc;
private final IStorageMonitorable storage;
private final IContainerCraftingPacket container;
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 );
this.energySrc = energySrc;
this.storage = storage;
this.mySrc = mySrc;
pattern = cMatrix;
craftInv = secondMatrix;
container = ccp;
}
public IInventory getCraftingMatrix()
@ -114,7 +119,7 @@ public class SlotCraftingTerm extends AppEngCraftingSlot
if ( pattern.getStackInSlot( x ) != null )
{
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] );
}
}

View file

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

View file

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

View file

@ -1,6 +1,7 @@
package appeng.helpers;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import appeng.api.networking.IGridNode;
import appeng.api.networking.security.BaseActionSource;
@ -28,4 +29,9 @@ public interface IContainerCraftingPacket
*/
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.OreHelper;
import appeng.util.item.OreRefrence;
import appeng.util.prioitylist.IPartitionList;
import buildcraft.api.tools.IToolWrench;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Loader;
@ -384,7 +385,8 @@ public class Platform
{
switch (id)
{
case 10: {
case 10:
{
NBTTagCompound ctA = (NBTTagCompound) A;
NBTTagCompound ctB = (NBTTagCompound) B;
@ -510,7 +512,8 @@ public class Platform
hash += id;
switch (id)
{
case 10: {
case 10:
{
NBTTagCompound ctA = (NBTTagCompound) A;
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,
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 )
{
@ -1625,6 +1629,8 @@ public class Platform
AEItemStack ae_req = AEItemStack.create( providedTemplate );
ae_req.setStackSize( 1 );
if ( filter == null || filter.isListed( ae_req ) )
{
IAEItemStack ae_ext = src.extractItems( ae_req, realForFake, mySrc );
if ( ae_ext != null )
{
@ -1635,6 +1641,7 @@ public class Platform
return extracted;
}
}
}
boolean checkFuzzy = ae_req.isOre() || providedTemplate.getItemDamage() == OreDictionary.WILDCARD_VALUE || providedTemplate.hasTagCompound()
|| providedTemplate.isItemStackDamageable();
@ -1653,6 +1660,8 @@ public class Platform
{
IAEItemStack ax = x.copy();
ax.setStackSize( 1 );
if ( filter == null || filter.isListed( ax ) )
{
IAEItemStack ex = src.extractItems( ax, realForFake, mySrc );
if ( ex != null )
{
@ -1660,6 +1669,7 @@ public class Platform
return ex.getItemStack();
}
}
}
ci.setInventorySlotContents( slot, providedTemplate );
}
}