Compare commits

...

5 Commits

Author SHA1 Message Date
yueh 9481c9a7d7 Fixes #3428: Invalidate container when the corresponding TE no longer exists. (#3433) 2018-03-22 13:52:07 +01:00
yueh ccefb47581 Added a config option to disable the CraftingManager fallback. (#3415) 2018-03-08 16:44:48 +01:00
yueh 59af05aeb1 Fixes #3417: Avoid creating ItemStacks when injecting them into a cell. (#3418) 2018-03-08 16:38:00 +01:00
yueh b32834e2b3 Fixes #3411: Limit patterns without substitute to precise operations. (#3413)
This will no longer ignore NBT data when searching for an itemstack,
thus less likely to trigger the CraftingManager fallback.
2018-03-08 16:35:13 +01:00
yueh 6c7cbb7ee1 Added a simple warning to patterns when using CraftingManager fallback. (#3412) 2018-03-08 16:34:48 +01:00
7 changed files with 97 additions and 27 deletions
@@ -356,6 +356,11 @@ public abstract class AEBaseContainer extends Container
if( Platform.isServer() )
{
if( this.tileEntity != null && this.tileEntity.getWorld().getTileEntity( this.tileEntity.getPos() ) != this.tileEntity )
{
this.setValidContainer( false );
}
for( final IContainerListener listener : this.listeners )
{
for( final SyncData sd : this.syncData.values() )
@@ -148,11 +148,6 @@ public class ContainerCellWorkbench extends ContainerUpgradeable
final ItemStack is = this.workBench.getInventoryByName( "cell" ).getStackInSlot( 0 );
if( Platform.isServer() )
{
if( this.workBench.getWorld().getTileEntity( this.workBench.getPos() ) != this.workBench )
{
this.setValidContainer( false );
}
for( final IContainerListener listener : this.listeners )
{
if( this.prevStack != is )
+3 -1
View File
@@ -213,7 +213,9 @@ public final class AEConfig extends Configuration implements IConfigurableObject
{
if( feature.isVisible() )
{
if( this.get( "Features." + feature.category(), feature.key(), feature.isEnabled() ).getBoolean( feature.isEnabled() ) )
final Property option = this.get( "Features." + feature.category(), feature.key(), feature.isEnabled(), feature.comment() );
if( option.getBoolean( feature.isEnabled() ) )
{
this.featureFlags.add( feature );
}
@@ -155,6 +155,7 @@ public enum AEFeature
MOLECULAR_ASSEMBLER( "MolecularAssembler", Constants.CATEGORY_CRAFTING_FEATURES ),
PATTERNS( "Patterns", Constants.CATEGORY_CRAFTING_FEATURES ),
CRAFTING_CPU( "CraftingCPU", Constants.CATEGORY_CRAFTING_FEATURES ),
CRAFTING_MANAGER_FALLBACK( "CraftingManagerFallback", Constants.CATEGORY_CRAFTING_FEATURES, "Use CraftingManager to find an alternative recipe, after a pattern rejected an ingredient. Should be enabled to avoid issues, but can have a minor performance impact." ),
BASIC_CARDS( "BasicCards", Constants.CATEGORY_UPGRADES ),
ADVANCED_CARDS( "AdvancedCards", Constants.CATEGORY_UPGRADES ),
@@ -178,17 +179,29 @@ public enum AEFeature
private final String key;
private final String category;
private final boolean enabled;
private final String comment;
AEFeature( final String key, final String cat )
{
this( key, cat, true );
}
AEFeature( final String key, final String cat, final String comment )
{
this( key, cat, true, comment );
}
AEFeature( final String key, final String cat, final boolean enabled )
{
this( key, cat, enabled, null );
}
AEFeature( final String key, final String cat, final boolean enabled, final String comment )
{
this.key = key;
this.category = cat;
this.enabled = enabled;
this.comment = comment;
}
/**
@@ -216,6 +229,11 @@ public enum AEFeature
return this.enabled;
}
public String comment()
{
return this.comment;
}
private enum Constants
{
;
@@ -25,6 +25,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.StringJoiner;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.Item;
@@ -40,6 +41,9 @@ import appeng.api.networking.crafting.ICraftingPatternDetails;
import appeng.api.storage.channels.IItemStorageChannel;
import appeng.api.storage.data.IAEItemStack;
import appeng.container.ContainerNull;
import appeng.core.AEConfig;
import appeng.core.AELog;
import appeng.core.features.AEFeature;
import appeng.util.ItemSorters;
import appeng.util.Platform;
import appeng.util.item.AEItemStack;
@@ -265,7 +269,7 @@ public class PatternHelper implements ICraftingPatternDetails, Comparable<Patter
return true;
}
}
else
else if( AEConfig.instance().isFeatureEnabled( AEFeature.CRAFTING_MANAGER_FALLBACK ) )
{
final ItemStack testOutput = CraftingManager.findMatchingResult( this.testFrame, w );
@@ -273,8 +277,16 @@ public class PatternHelper implements ICraftingPatternDetails, Comparable<Patter
{
this.testFrame.setInventorySlotContents( slotIndex, this.crafting.getStackInSlot( slotIndex ) );
this.markItemAs( slotIndex, i, TestStatus.ACCEPT );
if( AELog.isCraftingDebugLogEnabled() )
{
this.warnAboutCraftingManager( true );
}
return true;
}
this.warnAboutCraftingManager( false );
}
this.markItemAs( slotIndex, i, TestStatus.DECLINE );
@@ -395,6 +407,24 @@ public class PatternHelper implements ICraftingPatternDetails, Comparable<Patter
return this.pattern.hashCode();
}
private void warnAboutCraftingManager( boolean foundAlternative )
{
final String foundAlternativeRecipe = foundAlternative ? "Found alternative recipe." : "NOT FOUND, please report.";
final StringJoiner joinActualInputs = new StringJoiner( ", " );
for( int j = 0; j < this.testFrame.getSizeInventory(); j++ )
{
final ItemStack stack = this.testFrame.getStackInSlot( j );
if( !stack.isEmpty() )
{
joinActualInputs.add( stack.toString() );
}
}
AELog.warn( "Using CraftingManager fallback: Recipe <%s> for output <%s> rejected inputs [%s]. %s",
this.standardRecipe.getRegistryName(), this.standardRecipe.getRecipeOutput(), joinActualInputs, foundAlternativeRecipe );
}
@Override
public boolean equals( final Object obj )
{
@@ -19,6 +19,7 @@
package appeng.me.cluster.implementations;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
@@ -227,7 +228,7 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU
{
if( input instanceof IAEItemStack )
{
final IAEItemStack is = this.waitingFor.findPrecise( (IAEItemStack) input );
final IAEItemStack is = this.waitingFor.findPrecise( input );
if( is != null && is.getStackSize() > 0 )
{
return true;
@@ -243,7 +244,7 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU
return input;
}
final IAEItemStack what = (IAEItemStack) input.copy();
final IAEItemStack what = input.copy();
final IAEItemStack is = this.waitingFor.findPrecise( what );
if( type == Actionable.SIMULATE )// causes crafting to lock up?
@@ -684,7 +685,25 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU
if( details.isCraftable() )
{
for( IAEItemStack fuzz : this.inventory.getItemList().findFuzzy( input[x], FuzzyMode.IGNORE_ALL ) )
final Collection<IAEItemStack> itemList;
if( details.canSubstitute() )
{
itemList = this.inventory.getItemList().findFuzzy( input[x], FuzzyMode.IGNORE_ALL );
}
else
{
itemList = new ArrayList<>( 1 );
final IAEItemStack item = this.inventory.getItemList().findPrecise( input[x] );
if( item != null )
{
itemList.add( item );
}
}
for( IAEItemStack fuzz : itemList )
{
fuzz = fuzz.copy();
fuzz.setStackSize( input[x].getStackSize() );
@@ -218,11 +218,12 @@ public class CellInventory implements ICellInventory
return input;
}
final ItemStack sharedItemStack = input.createItemStack();
if( CellInventory.isStorageCell( sharedItemStack ) )
// This is slightly hacky as it expects a read-only access, but fine for now.
// TODO: Guarantee a read-only access. E.g. provide an isEmpty() method and ensure CellInventory does not write
// any NBT data for empty cells instead of relying on an empty IItemContainer
if( CellInventory.isStorageCell( input.getDefinition() ) )
{
final IMEInventory meInventory = getCell( sharedItemStack, null );
final IMEInventory meInventory = getCell( input.getDefinition(), null );
if( meInventory != null && !this.isEmpty( meInventory ) )
{
return input;
@@ -232,20 +233,20 @@ public class CellInventory implements ICellInventory
final IAEItemStack l = this.getCellItems().findPrecise( input );
if( l != null )
{
final long remainingItemSlots = this.getRemainingItemCount();
if( remainingItemSlots < 0 )
final long remainingItemCount = this.getRemainingItemCount();
if( remainingItemCount < 0 )
{
return input;
}
if( input.getStackSize() > remainingItemSlots )
if( input.getStackSize() > remainingItemCount )
{
final IAEItemStack r = input.copy();
r.setStackSize( r.getStackSize() - remainingItemSlots );
r.setStackSize( r.getStackSize() - remainingItemCount );
if( mode == Actionable.MODULATE )
{
l.setStackSize( l.getStackSize() + remainingItemSlots );
this.updateItemCount( remainingItemSlots );
l.setStackSize( l.getStackSize() + remainingItemCount );
this.updateItemCount( remainingItemCount );
this.saveChanges();
}
return r;
@@ -269,19 +270,19 @@ public class CellInventory implements ICellInventory
{
if( input.getStackSize() > remainingItemCount )
{
final ItemStack toReturn = sharedItemStack.copy();
toReturn.setCount( sharedItemStack.getCount() - remainingItemCount );
final IAEItemStack toReturn = input.copy();
toReturn.setStackSize( input.getStackSize() - remainingItemCount );
if( mode == Actionable.MODULATE )
{
final ItemStack toWrite = sharedItemStack.copy();
toWrite.setCount( remainingItemCount );
final IAEItemStack toWrite = input.copy();
toWrite.setStackSize( remainingItemCount );
this.cellItems.add( AEItemStack.fromItemStack( toWrite ) );
this.updateItemCount( toWrite.getCount() );
this.cellItems.add( toWrite );
this.updateItemCount( toWrite.getStackSize() );
this.saveChanges();
}
return AEItemStack.fromItemStack( toReturn );
return toReturn;
}
if( mode == Actionable.MODULATE )