another try at fixing level emitters

This commit is contained in:
Salomão
2021-03-30 21:57:53 -03:00
parent 59d7bd6c16
commit 053485a95a
2 changed files with 62 additions and 31 deletions
+1
View File
@@ -144,6 +144,7 @@ public class TickManagerCache implements ITickManager
tickTracker.getValue().getGridTickable().tickingRequest( tickTracker.getKey(), 1 ); tickTracker.getValue().getGridTickable().tickingRequest( tickTracker.getKey(), 1 );
ltIterator.remove(); ltIterator.remove();
} }
PartLevelEmitter.wipeCaches();
} }
catch( final Throwable t ) catch( final Throwable t )
{ {
@@ -22,12 +22,14 @@ package appeng.parts.automation;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import java.util.Collection; 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.IGridNode;
import appeng.api.networking.ticking.IGridTickable; import appeng.api.networking.ticking.*;
import appeng.api.networking.ticking.TickRateModulation; import appeng.me.Grid;
import appeng.api.networking.ticking.TickingRequest; import appeng.me.GridNode;
import appeng.util.item.AEItemStack;
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;
@@ -124,7 +126,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;
private IBaseMonitor<IAEItemStack> changedMonitor; static HashMap<Grid, Long> gridItemCount = new HashMap<>();
static HashMap<Grid, HashMap<AEItemStack,Long>> fuzzyAEItemStackCount = new HashMap<>();
static HashMap<Grid, HashMap<AEItemStack,Long>> preciseAEItemStackCount = new HashMap<>();
@Reflected @Reflected
public PartLevelEmitter( final ItemStack is ) public PartLevelEmitter( final ItemStack is )
@@ -325,37 +329,61 @@ public class PartLevelEmitter extends PartUpgradeable implements IEnergyWatcherH
{ {
final IAEItemStack myStack = this.config.getAEStackInSlot( 0 ); final IAEItemStack myStack = this.config.getAEStackInSlot( 0 );
if( myStack == null ) GridNode node = (GridNode) (this.getGridNode());
if( node != null )
{ {
this.lastReportedValue = 0; final Grid g = node.getInternalGrid();
for( final IAEItemStack st : monitor.getStorageList() )
if( myStack == null )
{ {
this.lastReportedValue += st.getStackSize(); if( !gridItemCount.containsKey( g ) )
{
this.lastReportedValue = 0;
for( final IAEItemStack st : monitor.getStorageList() )
{
this.lastReportedValue += st.getStackSize();
}
gridItemCount.put( g,lastReportedValue );
} else { this.lastReportedValue = gridItemCount.get( g ); }
} }
} else if( this.getInstalledUpgrades( Upgrades.FUZZY ) > 0 )
else if( this.getInstalledUpgrades( Upgrades.FUZZY ) > 0 )
{
this.lastReportedValue = 0;
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(); if( fuzzyAEItemStackCount.isEmpty() || !fuzzyAEItemStackCount.containsKey( g ) ||
} ( fuzzyAEItemStackCount.containsKey( g ) && !fuzzyAEItemStackCount.get( g ).containsKey( (AEItemStack) myStack ) ) )
} {
else this.lastReportedValue = 0;
{ final FuzzyMode fzMode = (FuzzyMode) this.getConfigManager().getSetting( Settings.FUZZY_MODE );
final IAEItemStack r = monitor.getStorageList().findPrecise( myStack ); final Collection<IAEItemStack> fuzzyList = monitor.getStorageList().findFuzzy( myStack, fzMode );
if( r == null ) for( final IAEItemStack st : fuzzyList )
{ {
this.lastReportedValue = 0; this.lastReportedValue += st.getStackSize();
}
fuzzyAEItemStackCount.put( g, new HashMap<>( 1 ));
fuzzyAEItemStackCount.get( g ).put( (AEItemStack) myStack.copy(),lastReportedValue );
} else {
this.lastReportedValue = fuzzyAEItemStackCount.get( g ).get( (AEItemStack) myStack );
}
} }
else else
{ {
this.lastReportedValue = r.getStackSize(); if( preciseAEItemStackCount.isEmpty() || !preciseAEItemStackCount.containsKey( g ) ||
( preciseAEItemStackCount.containsKey( g ) && !preciseAEItemStackCount.get( g ).containsKey( (AEItemStack) myStack ) ) )
{
final IAEItemStack r = monitor.getStorageList().findPrecise( myStack );
if( r == null )
{
this.lastReportedValue = 0;
}
else
{
this.lastReportedValue = r.getStackSize();
}
preciseAEItemStackCount.put( g, new HashMap<>( 1 ));
preciseAEItemStackCount.get( g ).put( (AEItemStack) myStack.copy(),lastReportedValue );
} else { this.lastReportedValue = preciseAEItemStackCount.get( g ).get( (AEItemStack) myStack ); }
} }
} }
this.updateState(); this.updateState();
} }
@@ -407,7 +435,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.changedMonitor = monitor; this.updateReportingValue( (IMEMonitor<IAEItemStack>) monitor );
} }
@Override @Override
@@ -595,10 +623,12 @@ public class PartLevelEmitter extends PartUpgradeable implements IEnergyWatcherH
@Override @Override
public TickRateModulation tickingRequest( @Nonnull IGridNode node, int ticksSinceLastCall ) public TickRateModulation tickingRequest( @Nonnull IGridNode node, int ticksSinceLastCall )
{ {
if (this.changedMonitor != null)
{
this.updateReportingValue((IMEMonitor<IAEItemStack>) changedMonitor);
}
return TickRateModulation.URGENT; return TickRateModulation.URGENT;
} }
static public void wipeCaches(){
gridItemCount = new HashMap<>();
fuzzyAEItemStackCount = new HashMap<>();
preciseAEItemStackCount = new HashMap<>();
}
} }