Compare commits

...

2 Commits

Author SHA1 Message Date
PrototypeTrousers e09f74cb5f 2 2021-08-14 00:09:32 -03:00
PrototypeTrousers facc1b4ef4 prevent crafting job to be fired if its a pattern failed previously till
the lack of ingredient that caused the failure is satisfied
2021-08-13 22:50:14 -03:00
11 changed files with 347 additions and 52 deletions
+1 -1
View File
@@ -3,7 +3,7 @@ aechannel=stable
aebuild=7
aegroup=appeng
aebasename=appliedenergistics2
trousers=omni-fixes-v46e
trousers=omni-fixes-v47
#########################################################
# Versions #
+11 -4
View File
@@ -22,6 +22,7 @@ package appeng.crafting;
import java.util.HashMap;
import java.util.concurrent.TimeUnit;
import appeng.me.cache.CraftingGridCache;
import com.google.common.base.Stopwatch;
import net.minecraft.entity.player.EntityPlayer;
@@ -71,6 +72,8 @@ public class CraftingJob implements Runnable, ICraftingJob
private boolean done = false;
private int time;
private int incTime;
private final ICraftingGrid cc;
private final IStorageGrid sg;
private World wrapWorld( final World w )
{
@@ -84,10 +87,9 @@ public class CraftingJob implements Runnable, ICraftingJob
this.actionSrc = actionSrc;
this.callback = callback;
final ICraftingGrid cc = grid.getCache( ICraftingGrid.class );
final IStorageGrid sg = grid.getCache( IStorageGrid.class );
this.original = new MECraftingInventory( sg
.getInventory( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) ), actionSrc, false, false, false );
this.cc = grid.getCache( ICraftingGrid.class );
this.sg = grid.getCache( IStorageGrid.class );
this.original = new MECraftingInventory( sg.getInventory( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) ), actionSrc, false, false, false );
this.setTree( this.getCraftingTree( cc, what ) );
this.availableCheck = null;
@@ -380,6 +382,11 @@ public class CraftingJob implements Runnable, ICraftingJob
}
}
public void addIncompletablePattern( ICraftingPatternDetails details, IAEItemStack stack )
{
( (CraftingGridCache) cc ).getPatternStatusManager().put( details, stack );
}
private static class TwoIntegers
{
private final long perOp = 0;
@@ -22,7 +22,10 @@ package appeng.crafting;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import appeng.util.item.OreHelper;
import appeng.util.item.OreReference;
import com.google.common.collect.Lists;
import net.minecraft.world.World;
@@ -117,6 +120,11 @@ public class CraftingTreeNode
return this.parent.notRecursive( details );
}
public CraftingTreeProcess getParent()
{
return parent;
}
IAEItemStack request( final MECraftingInventory inv, long l, final IActionSource src ) throws CraftBranchFailure, InterruptedException
{
this.job.handlePausing();
@@ -318,6 +326,7 @@ public class CraftingTreeNode
if( this.missing > 0 )
{
job.addMissing( this.getStack( this.missing ) );
addMissingIAEStack();
}
// missing = 0;
@@ -329,6 +338,29 @@ public class CraftingTreeNode
}
}
void addMissingIAEStack()
{
if( parent != null )
{
parent.addMissingIAEStack();
if( missing > 0 )
{
if( this.parent.details.canSubstitute() && this.getSlot() >= 0 )
{
final List<IAEItemStack> substitutes = this.parent.details.getSubstituteInputs( this.slot );
for( IAEItemStack stack : substitutes )
{
job.addIncompletablePattern( this.getParent().details, stack.copy().setStackSize( this.missing ) );
}
}
else
{
job.addIncompletablePattern( this.getParent().details, this.getStack( this.missing ) );
}
}
}
}
IAEItemStack getStack( final long size )
{
final IAEItemStack is = this.what.copy();
@@ -23,11 +23,10 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import appeng.me.cache.CraftingGridCache;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraftforge.fml.common.FMLCommonHandler;
import appeng.api.AEApi;
import appeng.api.config.Actionable;
@@ -66,7 +65,7 @@ public class CraftingTreeProcess
this.depth = depth;
final World world = job.getWorld();
if( details.isCraftable() )
if( !( (CraftingGridCache) cc ).getPatternStatusManager().containsIncompletablePattern( details ) && details.isCraftable() )
{
final IAEItemStack[] list = details.getInputs();
@@ -174,6 +173,11 @@ public class CraftingTreeProcess
return this.parent == null || this.parent.notRecursive( details );
}
public CraftingTreeNode getParent()
{
return parent;
}
long getTimes( final long remaining, final long stackSize )
{
if( this.limitQty || this.fullSimulation )
@@ -317,4 +321,12 @@ public class CraftingTreeProcess
pro.getPlan( plan );
}
}
public void addMissingIAEStack()
{
if( parent != null )
{
parent.addMissingIAEStack();
}
}
}
@@ -24,9 +24,12 @@ import java.util.*;
import javax.annotation.Nullable;
import appeng.api.definitions.IItemDefinition;
import appeng.api.networking.crafting.*;
import appeng.integration.modules.gregtech.GTCEInventoryAdaptor;
import appeng.me.cache.CraftingGridCache;
import appeng.util.*;
import appeng.util.inv.*;
import com.google.common.collect.ImmutableCollection;
import com.google.common.collect.ImmutableSet;
import de.ellpeck.actuallyadditions.api.tile.IPhantomTile;
@@ -65,10 +68,6 @@ import appeng.api.implementations.tiles.ICraftingMachine;
import appeng.api.networking.GridFlags;
import appeng.api.networking.IGrid;
import appeng.api.networking.IGridNode;
import appeng.api.networking.crafting.ICraftingLink;
import appeng.api.networking.crafting.ICraftingPatternDetails;
import appeng.api.networking.crafting.ICraftingProvider;
import appeng.api.networking.crafting.ICraftingProviderHelper;
import appeng.api.networking.energy.IEnergySource;
import appeng.api.networking.events.MENetworkCraftingPatternChange;
import appeng.api.networking.security.IActionHost;
@@ -110,7 +109,6 @@ import static gregtech.api.block.machines.BlockMachine.getMetaTileEntity;
public class DualityInterface implements IGridTickable, IStorageMonitorable, IInventoryDestination, IAEAppEngInventory, IConfigManagerHost, ICraftingProvider, IUpgradeableHost
{
private int[] failedCraftTriesSlot = {0,0,0,0,0,0,0,0,0};
public static final int NUMBER_OF_STORAGE_SLOTS = 9;
public static final int NUMBER_OF_CONFIG_SLOTS = 9;
@@ -931,17 +929,7 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
{
if( this.getInstalledUpgrades( Upgrades.CRAFTING ) > 0 && itemStack != null )
{
if (this.failedCraftTriesSlot[x] <= 0)
{
boolean crafted = this.craftingTracker.handleCrafting( x, itemStack.getStackSize(), itemStack, d, this.iHost.getTileEntity().getWorld(),
this.gridProxy.getGrid(), this.gridProxy.getCrafting(), this.mySource );
if (crafted) this.failedCraftTriesSlot[x] = 0;
else{
this.failedCraftTriesSlot[x] += 2;
}
}
this.failedCraftTriesSlot[x] -= 1;
return this.craftingTracker.handleCrafting( x, itemStack.getStackSize(), itemStack, d, this.iHost.getTileEntity().getWorld(), this.gridProxy.getGrid(), this.gridProxy.getCrafting(), this.mySource );
}
}
catch( final GridAccessException e )
@@ -22,6 +22,9 @@ package appeng.helpers;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import appeng.api.networking.crafting.*;
import appeng.me.cache.CraftingGridCache;
import com.google.common.collect.ImmutableCollection;
import com.google.common.collect.ImmutableSet;
import net.minecraft.nbt.NBTTagCompound;
@@ -29,10 +32,6 @@ import net.minecraft.world.World;
import appeng.api.AEApi;
import appeng.api.networking.IGrid;
import appeng.api.networking.crafting.ICraftingGrid;
import appeng.api.networking.crafting.ICraftingJob;
import appeng.api.networking.crafting.ICraftingLink;
import appeng.api.networking.crafting.ICraftingRequester;
import appeng.api.networking.security.IActionSource;
import appeng.api.storage.data.IAEItemStack;
import appeng.util.InventoryAdaptor;
@@ -132,6 +131,17 @@ public class MultiCraftingTracker
final IAEItemStack aisC = ais.copy();
aisC.setStackSize( itemToCraft );
CraftingGridCache cgc = (CraftingGridCache) cg;
ImmutableCollection<ICraftingPatternDetails> cl = cgc.getCraftingFor( aisC, null, x, w );
for( ICraftingPatternDetails craftingPatternDetails : cl )
{
if( cgc.getPatternStatusManager().containsIncompletablePattern( craftingPatternDetails ) )
{
return false;
}
}
this.setJob( x, cg.beginCraftingJob( w, g, mySrc, aisC, null ) );
}
}
+10 -4
View File
@@ -35,7 +35,7 @@ import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.ThreadFactory;
import appeng.api.storage.data.IAEFluidStack;
import appeng.me.helpers.PatternStatusManager;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.ImmutableCollection;
import com.google.common.collect.ImmutableList;
@@ -267,16 +267,17 @@ public class CraftingGridCache implements ICraftingGrid, ICraftingProviderHelper
// coalesce change events during a grid traversal to a single rebuild
if (pauseRebuilds != 0)
{
rebuildNeeded.add(this);
rebuildNeeded.add( this );
return;
}
final Object2ObjectMap<IAEItemStack, ImmutableList<ICraftingPatternDetails>> oldItems = new Object2ObjectOpenHashMap<>(this.craftableItems);
final Object2ObjectMap<IAEItemStack, ImmutableList<ICraftingPatternDetails>> oldItems = new Object2ObjectOpenHashMap<>( this.craftableItems );
// erase list.
this.craftingMethods.clear();
this.craftableItems.clear();
this.emitableItems.clear();
( (GridStorageCache) this.storageGrid ).clearPatternStatus();
// re-create list..
for( final ICraftingProvider provider : this.craftingProviders )
@@ -648,7 +649,7 @@ public class CraftingGridCache implements ICraftingGrid, ICraftingProviderHelper
public boolean hasCpu( final ICraftingCPU cpu )
{
if (cpu instanceof CraftingCPUCluster)
if( cpu instanceof CraftingCPUCluster )
{
return this.craftingCPUClusters.contains( (CraftingCPUCluster) cpu );
}
@@ -660,6 +661,11 @@ public class CraftingGridCache implements ICraftingGrid, ICraftingProviderHelper
return this.interestManager;
}
public PatternStatusManager getPatternStatusManager()
{
return ( (GridStorageCache) this.storageGrid ).getPatternStatusManager();
}
private static class ActiveCpuIterator implements Iterator<ICraftingCPU>
{
+19
View File
@@ -26,7 +26,10 @@ import java.util.IdentityHashMap;
import java.util.List;
import java.util.Map;
import appeng.api.networking.crafting.ICraftingPatternDetails;
import appeng.me.helpers.PatternStatusManager;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
import com.google.common.collect.SetMultimap;
import appeng.api.AEApi;
@@ -65,6 +68,10 @@ public class GridStorageCache implements IStorageGrid
private final HashSet<ICellProvider> inactiveCellProviders = new HashSet<>();
private final SetMultimap<IAEStack, ItemWatcher> interests = HashMultimap.create();
private final GenericInterestManager<ItemWatcher> interestManager = new GenericInterestManager<>( this.interests );
private final Multimap<ICraftingPatternDetails, IAEStack> patternDetails2IAEStackMultimap = HashMultimap.create();
private final Multimap<IAEStack, ICraftingPatternDetails> iaeStack2PatternDetailsMultimap = HashMultimap.create();
private final PatternStatusManager patternStatusManager = new PatternStatusManager( this.patternDetails2IAEStackMultimap, this.iaeStack2PatternDetailsMultimap );
private final HashMap<IGridNode, IStackWatcher> watchers = new HashMap<>();
private Map<IStorageChannel<? extends IAEStack>, NetworkInventoryHandler<?>> storageNetworks;
private Map<IStorageChannel<? extends IAEStack>, NetworkMonitor<?>> storageMonitors;
@@ -304,6 +311,18 @@ public class GridStorageCache implements IStorageGrid
return this.interestManager;
}
public PatternStatusManager getPatternStatusManager()
{
return this.patternStatusManager;
}
public void clearPatternStatus()
{
System.out.println( "reseting pattern status due to pattern changes" );
this.patternDetails2IAEStackMultimap.clear();
this.iaeStack2PatternDetailsMultimap.clear();
}
IGrid getGrid()
{
return this.myGrid;
+64
View File
@@ -25,6 +25,8 @@ import javax.annotation.Nullable;
import appeng.api.AEApi;
import appeng.api.config.AccessRestriction;
import appeng.api.config.Actionable;
import appeng.api.config.FuzzyMode;
import appeng.api.networking.crafting.ICraftingPatternDetails;
import appeng.api.networking.events.MENetworkStorageEvent;
import appeng.api.networking.security.IActionSource;
import appeng.api.storage.IMEInventoryHandler;
@@ -33,6 +35,7 @@ import appeng.api.storage.IMEMonitorHandlerReceiver;
import appeng.api.storage.IStorageChannel;
import appeng.api.storage.channels.IFluidStorageChannel;
import appeng.api.storage.channels.IItemStorageChannel;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IAEStack;
import appeng.api.storage.data.IItemList;
import appeng.me.storage.ItemWatcher;
@@ -268,6 +271,67 @@ public class NetworkMonitor<T extends IAEStack<T>> implements IMEMonitor<T>
this.myGridCache.getInterestManager().disableTransactions();
}
}
if( changedItem instanceof IAEItemStack )
{
if( this.myGridCache.getPatternStatusManager().containsMissingIAEStack( changedItem ) )
{
this.myGridCache.getPatternStatusManager().enableTransactions();
for( ICraftingPatternDetails craftingPatternDetails : this.myGridCache.getPatternStatusManager().getIncompletablePattern( changedItem ) )
{
for( IAEStack stack : this.myGridCache.getPatternStatusManager().getMissingIAEStack( craftingPatternDetails ) )
{
if( craftingPatternDetails.canSubstitute() )
{
if( ( (IAEItemStack) stack ).getItem().isDamageable() )
{
if( ( (IAEStack) changedItem ).fuzzyComparison( stack, FuzzyMode.IGNORE_ALL ) )
{
if( changedItem.getStackSize() > 0 )
{
this.myGridCache.getPatternStatusManager().remove( craftingPatternDetails, stack );
}
}
}
else
{
if( ( (IAEItemStack) stack ).sameOre( (IAEItemStack) changedItem ) )
{
if( changedItem.getStackSize() > 0 )
{
if( changedItem.getStackSize() >= stack.getStackSize() )
{
this.myGridCache.getPatternStatusManager().remove( craftingPatternDetails, stack );
}
else
{
stack.decStackSize( changedItem.getStackSize() );
}
}
}
}
}
else if( stack.equals( changedItem ) )
{
if( changedItem.getStackSize() > 0 )
{
if( changedItem.getStackSize() >= stack.getStackSize() )
{
this.myGridCache.getPatternStatusManager().remove( craftingPatternDetails, stack );
}
else
{
stack.decStackSize( changedItem.getStackSize() );
}
}
}
}
}
this.myGridCache.getPatternStatusManager().disableTransactions();
}
}
}
this.notifyListenersOfChange( changes, src );
@@ -0,0 +1,166 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.me.helpers;
import appeng.api.config.FuzzyMode;
import appeng.api.networking.crafting.ICraftingPatternDetails;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IAEStack;
import com.google.common.collect.Multimap;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
public class PatternStatusManager
{
private final Multimap<ICraftingPatternDetails, IAEStack> patternDetailsIAEStackMultimap;
private final Multimap<IAEStack, ICraftingPatternDetails> iaeStackPatternDetailsMultimap;
private List<SavedTransactions> transactions = null;
private int transDepth = 0;
public PatternStatusManager( final Multimap<ICraftingPatternDetails, IAEStack> interests, final Multimap<IAEStack, ICraftingPatternDetails> interested )
{
this.patternDetailsIAEStackMultimap = interests;
this.iaeStackPatternDetailsMultimap = interested;
}
public void enableTransactions()
{
if( this.transDepth == 0 )
{
this.transactions = new ArrayList<>();
}
this.transDepth++;
}
public void disableTransactions()
{
this.transDepth--;
if( this.transDepth == 0 )
{
final List<SavedTransactions> myActions = this.transactions;
this.transactions = null;
for( final SavedTransactions t : myActions )
{
if( t.put )
{
this.put( t.patternDetails, t.stack );
}
else
{
this.remove( t.patternDetails, t.stack );
}
}
}
}
public boolean put( final ICraftingPatternDetails craftingPatternDetails, final IAEStack debtStack )
{
if( this.transactions != null )
{
this.transactions.add( new SavedTransactions( true, craftingPatternDetails, debtStack ) );
return true;
}
else
{
this.iaeStackPatternDetailsMultimap.put( debtStack, craftingPatternDetails );
return this.patternDetailsIAEStackMultimap.put( craftingPatternDetails, debtStack );
}
}
public boolean remove( final ICraftingPatternDetails craftingPatternDetails, final IAEStack debtStack )
{
if( this.transactions != null )
{
this.transactions.add( new SavedTransactions( false, craftingPatternDetails, debtStack ) );
return true;
}
else
{
this.iaeStackPatternDetailsMultimap.remove( debtStack, craftingPatternDetails );
return this.patternDetailsIAEStackMultimap.remove( craftingPatternDetails, debtStack );
}
}
public boolean containsIncompletablePattern( final ICraftingPatternDetails craftingPatternDetails )
{
return this.patternDetailsIAEStackMultimap.containsKey( craftingPatternDetails );
}
public boolean containsMissingIAEStack( final IAEStack stack )
{
if( ( (IAEItemStack) stack ).getItem().isDamageable() )
{
for( IAEStack i : iaeStackPatternDetailsMultimap.keySet() )
{
if( i.fuzzyComparison( stack, FuzzyMode.IGNORE_ALL ) )
{
return true;
}
}
return false;
}
return this.iaeStackPatternDetailsMultimap.containsKey( stack );
}
public Collection<IAEStack> getMissingIAEStack( final ICraftingPatternDetails patternDetails )
{
return this.patternDetailsIAEStackMultimap.get( patternDetails );
}
public Collection<ICraftingPatternDetails> getIncompletablePattern( final IAEStack stack )
{
Collection<ICraftingPatternDetails> a = new ArrayList<>();
if( ( (IAEItemStack) stack ).getItem().isDamageable() )
{
for( IAEStack i : iaeStackPatternDetailsMultimap.keySet() )
{
if( i.fuzzyComparison( stack, FuzzyMode.IGNORE_ALL ) )
{
a.addAll( this.iaeStackPatternDetailsMultimap.get( i ) );
}
}
return a;
}
return this.iaeStackPatternDetailsMultimap.get( stack );
}
private class SavedTransactions
{
private final boolean put;
private final ICraftingPatternDetails patternDetails;
private final IAEStack stack;
public SavedTransactions( final boolean putOperation, final ICraftingPatternDetails myPatternDetails, final IAEStack stack )
{
this.put = putOperation;
this.patternDetails = myPatternDetails;
this.stack = stack;
}
}
}
@@ -19,6 +19,9 @@
package appeng.parts.automation;
import appeng.api.networking.crafting.ICraftingPatternDetails;
import appeng.me.cache.CraftingGridCache;
import com.google.common.collect.ImmutableCollection;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
@@ -150,18 +153,14 @@ public class PartExportBus extends PartSharedItemBus implements ICraftingRequest
final IAEItemStack ais = this.getConfig().getAEStackInSlot( slotToExport );
if( ais == null || this.itemToSend <= 0 ) continue;
if( ais == null || this.itemToSend <= 0 )
{
continue;
}
if ( this.craftOnly() ) {
if (this.failedCraftTriesSlot[x] <= 0) {
this.didSomething = this.craftingTracker.handleCrafting(slotToExport, this.itemToSend, ais, destination, this.getTile().getWorld(),
this.getProxy().getGrid(), cg, this.mySrc) || this.didSomething;
if (this.didSomething) this.failedCraftTriesSlot[x] = 0;
else this.failedCraftTriesSlot[x] += 2;
}
this.failedCraftTriesSlot[x] -= 1;
if( this.craftOnly() )
{
this.didSomething = this.craftingTracker.handleCrafting( slotToExport, this.itemToSend, ais, destination, this.getTile().getWorld(), this.getProxy().getGrid(), cg, this.mySrc ) || this.didSomething;
continue;
}
@@ -188,15 +187,7 @@ public class PartExportBus extends PartSharedItemBus implements ICraftingRequest
if( this.itemToSend == before && this.isCraftingEnabled() )
{
if (this.failedCraftTriesSlot[x] <= 0) {
this.didSomething = this.craftingTracker.handleCrafting(slotToExport, this.itemToSend, ais, destination, this.getTile().getWorld(),
this.getProxy().getGrid(), cg, this.mySrc) || this.didSomething;
if (this.didSomething) this.failedCraftTriesSlot[x] = 0;
else this.failedCraftTriesSlot[x] += 2;
}
this.failedCraftTriesSlot[x] -= 1;
this.didSomething = this.craftingTracker.handleCrafting( slotToExport, this.itemToSend, ais, destination, this.getTile().getWorld(), this.getProxy().getGrid(), cg, this.mySrc ) || this.didSomething;
}
}