better level emitting

This commit is contained in:
PrototypeTrousers
2021-03-31 11:57:46 -03:00
committed by Salomão
parent 40ec517480
commit c3b1dea7c5
2 changed files with 68 additions and 44 deletions
+1 -1
View File
@@ -130,7 +130,6 @@ public class TickManagerCache implements ITickManager
this.addToQueue( tt ); this.addToQueue( tt );
} }
} }
PartLevelEmitter.wipeCaches();
} }
catch( final Throwable t ) catch( final Throwable t )
{ {
@@ -139,6 +138,7 @@ public class TickManagerCache implements ITickManager
tt.addEntityCrashInfo( crashreportcategory ); tt.addEntityCrashInfo( crashreportcategory );
throw new ReportedException( crashreport ); throw new ReportedException( crashreport );
} }
PartLevelEmitter.wipeCache();
} }
private void addToQueue( final TickTracker tt ) private void addToQueue( final TickTracker tt )
@@ -19,17 +19,14 @@
package appeng.parts.automation; package appeng.parts.automation;
import javax.annotation.Nonnull;
import java.util.Collection;
import java.util.HashMap;
import java.util.Random; import java.util.Random;
import appeng.api.networking.IGridNode;
import appeng.api.networking.ticking.*;
import appeng.me.Grid; import appeng.me.Grid;
import appeng.me.GridNode; import appeng.me.GridNode;
import appeng.util.item.AEItemStack; import appeng.util.item.AEItemStack;
import it.unimi.dsi.fastutil.objects.Object2LongMap;
import it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.InventoryCrafting; import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
@@ -126,9 +123,9 @@ public class PartLevelEmitter extends PartUpgradeable implements IEnergyWatcherH
private double centerX; private double centerX;
private double centerY; private double centerY;
private double centerZ; private double centerZ;
static HashMap<Grid, Long> gridItemCount = new HashMap<>(); static Object2LongMap<Grid> gridItemCount = new Object2LongOpenHashMap<>();
static HashMap<Grid, HashMap<AEItemStack,Long>> fuzzyAEItemStackCount = new HashMap<>(); static Object2ObjectOpenHashMap<Grid, Object2LongMap<AEItemStack>> fuzzyAEItemStackCount = new Object2ObjectOpenHashMap<>();
static HashMap<Grid, HashMap<AEItemStack,Long>> preciseAEItemStackCount = new HashMap<>(); static Object2ObjectOpenHashMap<Grid, Object2LongMap<AEItemStack>> preciseAEItemStackCount = new Object2ObjectOpenHashMap<>();
@Reflected @Reflected
public PartLevelEmitter( final ItemStack is ) public PartLevelEmitter( final ItemStack is )
@@ -326,6 +323,11 @@ public class PartLevelEmitter extends PartUpgradeable implements IEnergyWatcherH
} }
private void updateReportingValue( final IMEMonitor<IAEItemStack> monitor ) private void updateReportingValue( final IMEMonitor<IAEItemStack> monitor )
{
updateReportingValue( monitor,null );
}
private void updateReportingValue( final IMEMonitor<IAEItemStack> monitor, Iterable<IAEItemStack> change )
{ {
final IAEItemStack myStack = this.config.getAEStackInSlot( 0 ); final IAEItemStack myStack = this.config.getAEStackInSlot( 0 );
@@ -333,55 +335,77 @@ public class PartLevelEmitter extends PartUpgradeable implements IEnergyWatcherH
if( node != null ) if( node != null )
{ {
final Grid g = node.getInternalGrid(); final Grid g = node.getInternalGrid();
if( myStack == null ) if( myStack == null )
{ {
if( !gridItemCount.containsKey( g ) ) if( change != null )
{ {
this.lastReportedValue = 0; if( gridItemCount.containsKey( g ) )
for( final IAEItemStack st : monitor.getStorageList() )
{ {
this.lastReportedValue += st.getStackSize(); change.forEach( iaeItemStack -> lastReportedValue += iaeItemStack.getStackSize() );
} }
gridItemCount.put( g,lastReportedValue ); }
} else { this.lastReportedValue = gridItemCount.get( g ); } gridItemCount.computeIfAbsent( g, ( aLong ) -> {
this.lastReportedValue = 0;
monitor.getStorageList().forEach( iaeItemStack -> lastReportedValue += iaeItemStack.getStackSize() );
return ( lastReportedValue );
} );
this.lastReportedValue = gridItemCount.get( g );
} }
else if( this.getInstalledUpgrades( Upgrades.FUZZY ) > 0 ) else if( this.getInstalledUpgrades( Upgrades.FUZZY ) > 0 )
{ {
if( fuzzyAEItemStackCount.isEmpty() || !fuzzyAEItemStackCount.containsKey( g ) || final FuzzyMode fzMode = (FuzzyMode) this.getConfigManager().getSetting( Settings.FUZZY_MODE );
( fuzzyAEItemStackCount.containsKey( g ) && !fuzzyAEItemStackCount.get( g ).containsKey( (AEItemStack) myStack ) ) ) if( change != null )
{ {
this.lastReportedValue = 0; if( fuzzyAEItemStackCount.containsKey( g ) )
final FuzzyMode fzMode = (FuzzyMode) this.getConfigManager().getSetting( Settings.FUZZY_MODE );
final Collection<IAEItemStack> fuzzyList = monitor.getStorageList().findFuzzy( myStack, fzMode );
for( final IAEItemStack st : fuzzyList )
{ {
this.lastReportedValue += st.getStackSize(); change.forEach( iaeItemStack -> {
if( iaeItemStack.sameOre( myStack ) ) lastReportedValue += iaeItemStack.getStackSize();
} );
} }
fuzzyAEItemStackCount.put( g, new HashMap<>( 1 )); }
fuzzyAEItemStackCount.get( g ).put( (AEItemStack) myStack.copy(),lastReportedValue );
} else { fuzzyAEItemStackCount.computeIfAbsent( g, ( grid -> new Object2LongOpenHashMap<>() ) );
this.lastReportedValue = fuzzyAEItemStackCount.get( g ).get( (AEItemStack) myStack ); fuzzyAEItemStackCount.get( g ).computeIfAbsent( (AEItemStack) myStack, ( aLong -> {
this.lastReportedValue = 0;
monitor.getStorageList().findFuzzy( myStack, fzMode ).forEach( iaeItemStack -> lastReportedValue += iaeItemStack.getStackSize() );
return ( lastReportedValue );
} ) );
this.lastReportedValue = fuzzyAEItemStackCount.get( g ).get( myStack );
if( this.lastReportedValue == 0 )
{
fuzzyAEItemStackCount.get( g ).remove( myStack );
fuzzyAEItemStackCount.trim();
} }
} }
else else
{ {
if( preciseAEItemStackCount.isEmpty() || !preciseAEItemStackCount.containsKey( g ) || if( change != null )
( preciseAEItemStackCount.containsKey( g ) && !preciseAEItemStackCount.get( g ).containsKey( (AEItemStack) myStack ) ) )
{ {
final IAEItemStack r = monitor.getStorageList().findPrecise( myStack ); if( preciseAEItemStackCount.containsKey( g ) )
if( r == null )
{ {
this.lastReportedValue = 0; change.forEach( iaeItemStack -> {
if( iaeItemStack.isSameType( myStack ) ) lastReportedValue += iaeItemStack.getStackSize();
} );
} }
else }
{ preciseAEItemStackCount.computeIfAbsent( g, ( grid -> new Object2LongOpenHashMap<>() ) );
this.lastReportedValue = r.getStackSize(); preciseAEItemStackCount.get( g ).computeIfAbsent( (AEItemStack) myStack, ( aLong -> {
} this.lastReportedValue = 0;
preciseAEItemStackCount.put( g, new HashMap<>( 1 )); IAEItemStack precise = monitor.getStorageList().findPrecise( myStack );
preciseAEItemStackCount.get( g ).put( (AEItemStack) myStack.copy(),lastReportedValue ); if( precise != null ) lastReportedValue = precise.getStackSize();
} else { this.lastReportedValue = preciseAEItemStackCount.get( g ).get( (AEItemStack) myStack ); } return ( lastReportedValue );
} ) );
this.lastReportedValue = preciseAEItemStackCount.get( g ).get( myStack );
if( this.lastReportedValue == 0 )
{
preciseAEItemStackCount.get( g ).remove( myStack );
preciseAEItemStackCount.trim();
}
} }
} }
this.updateState(); this.updateState();
@@ -435,7 +459,7 @@ public class PartLevelEmitter extends PartUpgradeable implements IEnergyWatcherH
@Override @Override
public void postChange( final IBaseMonitor<IAEItemStack> monitor, final Iterable<IAEItemStack> change, final IActionSource actionSource ) public void postChange( final IBaseMonitor<IAEItemStack> monitor, final Iterable<IAEItemStack> change, final IActionSource actionSource )
{ {
this.updateReportingValue( (IMEMonitor<IAEItemStack>) monitor ); this.updateReportingValue( (IMEMonitor<IAEItemStack>) monitor, change );
} }
@Override @Override
@@ -612,9 +636,9 @@ public class PartLevelEmitter extends PartUpgradeable implements IEnergyWatcherH
} }
} }
static public void wipeCaches(){ public static void wipeCache(){
gridItemCount = new HashMap<>(); fuzzyAEItemStackCount.clear();
fuzzyAEItemStackCount = new HashMap<>(); preciseAEItemStackCount.clear();
preciseAEItemStackCount = new HashMap<>(); gridItemCount.clear();
} }
} }