@@ -30,18 +30,13 @@ import io.netty.buffer.Unpooled;
|
|||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.entity.player.EntityPlayerMP;
|
import net.minecraft.entity.player.EntityPlayerMP;
|
||||||
import net.minecraft.inventory.Container;
|
import net.minecraft.inventory.Container;
|
||||||
import net.minecraft.inventory.InventoryCrafting;
|
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.item.crafting.CraftingManager;
|
|
||||||
import net.minecraft.item.crafting.IRecipe;
|
|
||||||
import net.minecraft.nbt.CompressedStreamTools;
|
import net.minecraft.nbt.CompressedStreamTools;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.nbt.NBTTagList;
|
import net.minecraft.nbt.NBTTagList;
|
||||||
import net.minecraftforge.items.IItemHandler;
|
import net.minecraftforge.items.IItemHandler;
|
||||||
import net.minecraftforge.oredict.OreDictionary;
|
|
||||||
|
|
||||||
import appeng.api.config.Actionable;
|
import appeng.api.config.Actionable;
|
||||||
import appeng.api.config.FuzzyMode;
|
|
||||||
import appeng.api.config.SecurityPermissions;
|
import appeng.api.config.SecurityPermissions;
|
||||||
import appeng.api.networking.IGrid;
|
import appeng.api.networking.IGrid;
|
||||||
import appeng.api.networking.IGridNode;
|
import appeng.api.networking.IGridNode;
|
||||||
@@ -50,15 +45,13 @@ import appeng.api.networking.security.ISecurityGrid;
|
|||||||
import appeng.api.networking.storage.IStorageGrid;
|
import appeng.api.networking.storage.IStorageGrid;
|
||||||
import appeng.api.storage.IMEMonitor;
|
import appeng.api.storage.IMEMonitor;
|
||||||
import appeng.api.storage.data.IAEItemStack;
|
import appeng.api.storage.data.IAEItemStack;
|
||||||
import appeng.api.storage.data.IItemList;
|
|
||||||
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.items.storage.ItemViewCell;
|
||||||
import appeng.util.InventoryAdaptor;
|
|
||||||
import appeng.util.Platform;
|
import appeng.util.Platform;
|
||||||
import appeng.util.helpers.ItemHandlerUtil;
|
import appeng.util.helpers.ItemHandlerUtil;
|
||||||
|
import appeng.util.inv.AdaptorItemHandler;
|
||||||
import appeng.util.inv.WrapperInvItemHandler;
|
import appeng.util.inv.WrapperInvItemHandler;
|
||||||
import appeng.util.item.AEItemStack;
|
import appeng.util.item.AEItemStack;
|
||||||
import appeng.util.prioritylist.IPartitionList;
|
import appeng.util.prioritylist.IPartitionList;
|
||||||
@@ -115,12 +108,19 @@ public class PacketJEIRecipe extends AppEngPacket
|
|||||||
final EntityPlayerMP pmp = (EntityPlayerMP) player;
|
final EntityPlayerMP pmp = (EntityPlayerMP) player;
|
||||||
final Container con = pmp.openContainer;
|
final Container con = pmp.openContainer;
|
||||||
|
|
||||||
if( con instanceof IContainerCraftingPacket )
|
if( !( con instanceof IContainerCraftingPacket ) )
|
||||||
{
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
final IContainerCraftingPacket cct = (IContainerCraftingPacket) con;
|
final IContainerCraftingPacket cct = (IContainerCraftingPacket) con;
|
||||||
final IGridNode node = cct.getNetworkNode();
|
final IGridNode node = cct.getNetworkNode();
|
||||||
if( node != null )
|
|
||||||
|
if( node == null )
|
||||||
{
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
final IGrid grid = node.getGrid();
|
final IGrid grid = node.getGrid();
|
||||||
if( grid == null )
|
if( grid == null )
|
||||||
{
|
{
|
||||||
@@ -133,147 +133,107 @@ public class PacketJEIRecipe extends AppEngPacket
|
|||||||
final IItemHandler craftMatrix = cct.getInventoryByName( "crafting" );
|
final IItemHandler craftMatrix = cct.getInventoryByName( "crafting" );
|
||||||
final IItemHandler playerInventory = cct.getInventoryByName( "player" );
|
final IItemHandler playerInventory = cct.getInventoryByName( "player" );
|
||||||
|
|
||||||
final Actionable realForFake = cct.useRealItems() ? Actionable.MODULATE : Actionable.SIMULATE;
|
|
||||||
|
|
||||||
if( inv != null && this.recipe != null && security != null )
|
if( inv != null && this.recipe != null && security != null )
|
||||||
{
|
|
||||||
final InventoryCrafting testInv = new InventoryCrafting( new ContainerNull(), 3, 3 );
|
|
||||||
for( int x = 0; x < 9; x++ )
|
|
||||||
{
|
|
||||||
if( this.recipe[x] != null && this.recipe[x].length > 0 )
|
|
||||||
{
|
|
||||||
testInv.setInventorySlotContents( x, this.recipe[x][0] );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final IRecipe r = CraftingManager.findMatchingRecipe( testInv, pmp.world );
|
|
||||||
|
|
||||||
if( r != null && security.hasPermission( player, SecurityPermissions.EXTRACT ) )
|
|
||||||
{
|
|
||||||
final ItemStack is = r.getCraftingResult( testInv );
|
|
||||||
|
|
||||||
if( !is.isEmpty() )
|
|
||||||
{
|
{
|
||||||
final IMEMonitor<IAEItemStack> storage = inv.getItemInventory();
|
final IMEMonitor<IAEItemStack> storage = inv.getItemInventory();
|
||||||
final IItemList all = storage.getStorageList();
|
|
||||||
final IPartitionList<IAEItemStack> filter = ItemViewCell.createFilter( cct.getViewCells() );
|
final IPartitionList<IAEItemStack> filter = ItemViewCell.createFilter( cct.getViewCells() );
|
||||||
|
|
||||||
for( int x = 0; x < craftMatrix.getSlots(); x++ )
|
for( int x = 0; x < craftMatrix.getSlots(); x++ )
|
||||||
{
|
{
|
||||||
final ItemStack patternItem = testInv.getStackInSlot( x );
|
|
||||||
|
|
||||||
ItemStack currentItem = craftMatrix.getStackInSlot( x );
|
ItemStack currentItem = craftMatrix.getStackInSlot( x );
|
||||||
|
|
||||||
|
// prepare slots
|
||||||
if( !currentItem.isEmpty() )
|
if( !currentItem.isEmpty() )
|
||||||
{
|
{
|
||||||
testInv.setInventorySlotContents( x, currentItem );
|
// already the correct item?
|
||||||
final ItemStack newItemStack = r.matches( testInv, pmp.world ) ? r.getCraftingResult( testInv ) : ItemStack.EMPTY;
|
ItemStack newItem = canUseInSlot( x, currentItem );
|
||||||
testInv.setInventorySlotContents( x, patternItem );
|
|
||||||
|
|
||||||
if( newItemStack.isEmpty() || !Platform.itemComparisons().isSameItem( newItemStack, is ) )
|
// put away old item
|
||||||
|
if( newItem != currentItem && security.hasPermission( player, SecurityPermissions.INJECT ) )
|
||||||
{
|
{
|
||||||
final IAEItemStack in = AEItemStack.create( currentItem );
|
final IAEItemStack in = AEItemStack.create( currentItem );
|
||||||
if( in != null )
|
final IAEItemStack out = cct.useRealItems() ? Platform.poweredInsert( energy, storage, in, cct.getActionSource() ) : null;
|
||||||
{
|
|
||||||
final IAEItemStack out = realForFake == Actionable.SIMULATE ? null : Platform.poweredInsert( energy, storage, in,
|
|
||||||
cct.getActionSource() );
|
|
||||||
if( out != null )
|
if( out != null )
|
||||||
{
|
{
|
||||||
ItemHandlerUtil.setStackInSlot( craftMatrix, x, out.getItemStack() );
|
currentItem = out.getItemStack();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ItemHandlerUtil.setStackInSlot( craftMatrix, x, ItemStack.EMPTY );
|
currentItem = ItemStack.EMPTY;
|
||||||
}
|
|
||||||
|
|
||||||
currentItem = craftMatrix.getStackInSlot( x );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// True if we need to fetch an item for the recipe
|
if( currentItem.isEmpty() && this.recipe[x] != null )
|
||||||
if( !patternItem.isEmpty() && currentItem.isEmpty() )
|
|
||||||
{
|
{
|
||||||
// Grab from network by recipe
|
// for each variant
|
||||||
ItemStack whichItem = Platform.extractItemsByRecipe( energy, cct.getActionSource(), storage, player.world, r, is, testInv,
|
for( int y = 0; y < this.recipe[x].length && currentItem.isEmpty(); y++ )
|
||||||
patternItem, x, all, realForFake, filter );
|
|
||||||
|
|
||||||
// If that doesn't get it, grab exact items from network (?)
|
|
||||||
// TODO see if this code is necessary
|
|
||||||
if( whichItem.isEmpty() )
|
|
||||||
{
|
|
||||||
for( int y = 0; y < this.recipe[x].length; y++ )
|
|
||||||
{
|
{
|
||||||
final IAEItemStack request = AEItemStack.create( this.recipe[x][y] );
|
final IAEItemStack request = AEItemStack.create( this.recipe[x][y] );
|
||||||
if( request != null )
|
if( request != null )
|
||||||
{
|
{
|
||||||
if( filter == null || filter.isListed( request ) )
|
// try ae
|
||||||
|
if( ( filter == null || filter.isListed( request ) ) && security.hasPermission( player, SecurityPermissions.EXTRACT ) )
|
||||||
{
|
{
|
||||||
request.setStackSize( 1 );
|
request.setStackSize( 1 );
|
||||||
final IAEItemStack out = Platform.poweredExtraction( energy, storage, request, cct.getActionSource() );
|
IAEItemStack out;
|
||||||
|
if( cct.useRealItems() )
|
||||||
|
{
|
||||||
|
out = Platform.poweredExtraction( energy, storage, request, cct.getActionSource() );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
out = storage.extractItems( request, Actionable.SIMULATE, cct.getActionSource() );
|
||||||
|
}
|
||||||
|
|
||||||
if( out != null )
|
if( out != null )
|
||||||
{
|
{
|
||||||
whichItem = out.getItemStack();
|
currentItem = out.getItemStack();
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If that doesn't work, grab from the player's inventory
|
// try inventory
|
||||||
if( whichItem.isEmpty() && playerInventory != null )
|
if( currentItem.isEmpty() )
|
||||||
{
|
{
|
||||||
whichItem = this.extractItemFromPlayerInventory( player, realForFake, patternItem );
|
AdaptorItemHandler ad = new AdaptorItemHandler( playerInventory );
|
||||||
}
|
|
||||||
|
|
||||||
ItemHandlerUtil.setStackInSlot( craftMatrix, x, whichItem );
|
if( cct.useRealItems() )
|
||||||
|
{
|
||||||
|
currentItem = ad.removeItems( 1, this.recipe[x][y], null );
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
currentItem = ad.simulateRemove( 1, this.recipe[x][y], null );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ItemHandlerUtil.setStackInSlot( craftMatrix, x, currentItem );
|
||||||
}
|
}
|
||||||
con.onCraftMatrixChanged( new WrapperInvItemHandler( craftMatrix ) );
|
con.onCraftMatrixChanged( new WrapperInvItemHandler( craftMatrix ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tries to extract an item from the player inventory. Does account for fuzzy items.
|
|
||||||
*
|
*
|
||||||
* @param player the {@link EntityPlayer} to extract from
|
* @param slot
|
||||||
* @param mode the {@link Actionable} to simulate or modulate the operation
|
* @param is itemstack
|
||||||
* @param patternItem which {@link ItemStack} to extract
|
* @return is if it can be used, else EMPTY
|
||||||
* @return null or a found {@link ItemStack}
|
|
||||||
*/
|
*/
|
||||||
private ItemStack extractItemFromPlayerInventory( final EntityPlayer player, final Actionable mode, final ItemStack patternItem )
|
private ItemStack canUseInSlot( int slot, ItemStack is )
|
||||||
{
|
{
|
||||||
final InventoryAdaptor ia = InventoryAdaptor.getAdaptor( player );
|
if( this.recipe[slot] != null )
|
||||||
final AEItemStack request = AEItemStack.create( patternItem );
|
{
|
||||||
final boolean isSimulated = mode == Actionable.SIMULATE;
|
for( ItemStack option : this.recipe[slot] )
|
||||||
final boolean checkFuzzy = request.isOre() || patternItem.getItemDamage() == OreDictionary.WILDCARD_VALUE || patternItem.hasTagCompound() || patternItem
|
{
|
||||||
.isItemStackDamageable();
|
if( is.isItemEqual( option ) )
|
||||||
|
{
|
||||||
|
return is;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ItemStack.EMPTY;
|
||||||
|
}
|
||||||
|
|
||||||
if( !checkFuzzy )
|
|
||||||
{
|
|
||||||
if( isSimulated )
|
|
||||||
{
|
|
||||||
return ia.simulateRemove( 1, patternItem, null );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return ia.removeItems( 1, patternItem, null );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if( isSimulated )
|
|
||||||
{
|
|
||||||
return ia.simulateSimilarRemove( 1, patternItem, FuzzyMode.IGNORE_ALL, null );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return ia.removeSimilarItems( 1, patternItem, FuzzyMode.IGNORE_ALL, null );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,6 +93,13 @@ class RecipeTransferHandler<T extends Container> implements IRecipeTransferHandl
|
|||||||
{
|
{
|
||||||
final NBTTagList tags = new NBTTagList();
|
final NBTTagList tags = new NBTTagList();
|
||||||
final List<ItemStack> list = new LinkedList<>();
|
final List<ItemStack> list = new LinkedList<>();
|
||||||
|
final ItemStack displayed = ingredient.getDisplayedIngredient();
|
||||||
|
|
||||||
|
// prefer currently displayed item
|
||||||
|
if( displayed != null && !displayed.isEmpty() )
|
||||||
|
{
|
||||||
|
list.add( displayed );
|
||||||
|
}
|
||||||
|
|
||||||
// prefer pure crystals.
|
// prefer pure crystals.
|
||||||
for( ItemStack stack : ingredient.getAllIngredients() )
|
for( ItemStack stack : ingredient.getAllIngredients() )
|
||||||
|
|||||||
Reference in New Issue
Block a user