Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2e0250de37 | |||
| 34c490f92b | |||
| 401f1ebb3e |
@@ -39,6 +39,7 @@ import appeng.api.util.IReadOnlyCollection;
|
||||
import appeng.core.worlddata.WorldData;
|
||||
import appeng.hooks.TickHandler;
|
||||
import appeng.util.ReadOnlyCollection;
|
||||
import appeng.me.cache.CraftingGridCache;
|
||||
|
||||
|
||||
public class Grid implements IGrid
|
||||
@@ -219,7 +220,10 @@ public class Grid implements IGrid
|
||||
@Override
|
||||
public MENetworkEvent postEvent( final MENetworkEvent ev )
|
||||
{
|
||||
return this.eventBus.postEvent( this, ev );
|
||||
CraftingGridCache.pauseRebuilds();
|
||||
final MENetworkEvent ret = this.eventBus.postEvent( this, ev );
|
||||
CraftingGridCache.unpauseRebuilds();
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -55,6 +55,7 @@ import appeng.api.util.IReadOnlyCollection;
|
||||
import appeng.core.AELog;
|
||||
import appeng.core.worlddata.WorldData;
|
||||
import appeng.hooks.TickHandler;
|
||||
import appeng.me.cache.CraftingGridCache;
|
||||
import appeng.me.pathfinding.IPathItem;
|
||||
import appeng.util.IWorldCallable;
|
||||
import appeng.util.ReadOnlyCollection;
|
||||
@@ -164,6 +165,8 @@ public class GridNode implements IGridNode, IPathItem
|
||||
{
|
||||
final Object tracker = new Object();
|
||||
|
||||
CraftingGridCache.pauseRebuilds();
|
||||
|
||||
Deque<GridNode> nextRun = new ArrayDeque<>();
|
||||
nextRun.add( this );
|
||||
|
||||
@@ -203,6 +206,7 @@ public class GridNode implements IGridNode, IPathItem
|
||||
}
|
||||
}
|
||||
}
|
||||
CraftingGridCache.unpauseRebuilds();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -114,6 +114,8 @@ public class CraftingGridCache implements ICraftingGrid, ICraftingProviderHelper
|
||||
private IStorageGrid storageGrid;
|
||||
private IEnergyGrid energyGrid;
|
||||
private boolean updateList = false;
|
||||
private static int pauseRebuilds = 0;
|
||||
private static Set<CraftingGridCache> rebuildNeeded = new HashSet<>();
|
||||
|
||||
public CraftingGridCache( final IGrid grid )
|
||||
{
|
||||
@@ -240,8 +242,34 @@ public class CraftingGridCache implements ICraftingGrid, ICraftingProviderHelper
|
||||
// nothing!
|
||||
}
|
||||
|
||||
public static void pauseRebuilds()
|
||||
{
|
||||
pauseRebuilds++;
|
||||
}
|
||||
|
||||
public static void unpauseRebuilds()
|
||||
{
|
||||
pauseRebuilds--;
|
||||
if (pauseRebuilds == 0 && rebuildNeeded.size() > 0)
|
||||
{
|
||||
ImmutableSet<CraftingGridCache> needed = ImmutableSet.copyOf(rebuildNeeded);
|
||||
rebuildNeeded.clear();
|
||||
for ( CraftingGridCache cache: needed )
|
||||
{
|
||||
cache.updatePatterns();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updatePatterns()
|
||||
{
|
||||
// coalesce change events during a grid traversal to a single rebuild
|
||||
if (pauseRebuilds != 0)
|
||||
{
|
||||
rebuildNeeded.add(this);
|
||||
return;
|
||||
}
|
||||
|
||||
final Map<IAEItemStack, ImmutableList<ICraftingPatternDetails>> oldItems = this.craftableItems;
|
||||
|
||||
// erase list.
|
||||
|
||||
Reference in New Issue
Block a user