fix looping item count and hopefully energy issues
This commit is contained in:
+1
-1
@@ -3,7 +3,7 @@ aechannel=stable
|
||||
aebuild=7
|
||||
aegroup=appeng
|
||||
aebasename=appliedenergistics2
|
||||
trousers=omni-fixes-v46aa
|
||||
trousers=omni-fixes-v49
|
||||
|
||||
#########################################################
|
||||
# Versions #
|
||||
|
||||
@@ -178,8 +178,9 @@ public class PartFluidFormationPlane extends PartAbstractFormationPlane<IAEFluid
|
||||
this.stateChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
@MENetworkEventSubscribe
|
||||
public void updateChannels( final MENetworkChannelsChanged changedChannels )
|
||||
public void chanRender( final MENetworkChannelsChanged changedChannels )
|
||||
{
|
||||
this.stateChanged();
|
||||
}
|
||||
|
||||
@@ -90,14 +90,16 @@ public class PartFluidInterface extends PartBasicState implements IGridTickable,
|
||||
return this.duality;
|
||||
}
|
||||
|
||||
@Override
|
||||
@MENetworkEventSubscribe
|
||||
public void stateChange( final MENetworkChannelsChanged c )
|
||||
public void chanRender( final MENetworkChannelsChanged c )
|
||||
{
|
||||
this.duality.notifyNeighbors();
|
||||
}
|
||||
|
||||
@Override
|
||||
@MENetworkEventSubscribe
|
||||
public void stateChange( final MENetworkPowerStatusChange c )
|
||||
public void powerRender( final MENetworkPowerStatusChange c )
|
||||
{
|
||||
this.duality.notifyNeighbors();
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ package appeng.fluids.parts;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import appeng.api.networking.events.MENetworkChannelChanged;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
import appeng.fluids.helper.IConfigurableFluidInventory;
|
||||
import appeng.me.cache.NetworkMonitor;
|
||||
@@ -118,7 +117,7 @@ public class PartFluidLevelEmitter extends PartUpgradeable implements IStackWatc
|
||||
{
|
||||
if( chan == AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ) && diffStack.equals( this.config.getFluidInSlot( 0 ) ) )
|
||||
{
|
||||
this.lastReportedValue += diffStack.getStackSize();
|
||||
this.lastReportedValue = fullStack.getStackSize();
|
||||
this.updateState();
|
||||
}
|
||||
}
|
||||
@@ -129,8 +128,9 @@ public class PartFluidLevelEmitter extends PartUpgradeable implements IStackWatc
|
||||
this.configureWatchers();
|
||||
}
|
||||
|
||||
@Override
|
||||
@MENetworkEventSubscribe
|
||||
public void powerStatusChange( final MENetworkPowerStatusChange powerEvent )
|
||||
public void powerRender( final MENetworkPowerStatusChange powerEvent )
|
||||
{
|
||||
if (this.getProxy().isActive())
|
||||
{
|
||||
@@ -139,8 +139,9 @@ public class PartFluidLevelEmitter extends PartUpgradeable implements IStackWatc
|
||||
this.updateState();
|
||||
}
|
||||
|
||||
@Override
|
||||
@MENetworkEventSubscribe
|
||||
public void channelChanged( final MENetworkChannelsChanged c )
|
||||
public void chanRender( final MENetworkChannelsChanged c )
|
||||
{
|
||||
if (this.getProxy().isActive())
|
||||
{
|
||||
|
||||
@@ -25,6 +25,7 @@ import java.util.Objects;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import appeng.api.storage.channels.IItemStorageChannel;
|
||||
import appeng.fluids.helper.IConfigurableFluidInventory;
|
||||
import appeng.util.ConfigManager;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -170,7 +171,6 @@ public class PartFluidStorageBus extends PartSharedStorageBus implements IMEMoni
|
||||
|
||||
final MEInventoryHandler<IAEFluidStack> in = this.getInternalHandler();
|
||||
IItemList<IAEFluidStack> before = AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ).createList();
|
||||
boolean denyRead = false;
|
||||
if( in != null )
|
||||
{
|
||||
if( accessChanged )
|
||||
@@ -179,7 +179,7 @@ public class PartFluidStorageBus extends PartSharedStorageBus implements IMEMoni
|
||||
AccessRestriction oldAccess = (AccessRestriction) ( (ConfigManager) this.getConfigManager() ).getOldSetting( Settings.ACCESS );
|
||||
if( oldAccess.hasPermission( AccessRestriction.READ ) && !currentAccess.hasPermission( AccessRestriction.READ ) )
|
||||
{
|
||||
denyRead = true;
|
||||
readOncePass = true;
|
||||
}
|
||||
in.setBaseAccess( oldAccess );
|
||||
before = in.getAvailableItems( before );
|
||||
@@ -199,16 +199,14 @@ public class PartFluidStorageBus extends PartSharedStorageBus implements IMEMoni
|
||||
}
|
||||
|
||||
final MEInventoryHandler<IAEFluidStack> out = this.getInternalHandler();
|
||||
IItemList<IAEFluidStack> after = AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ).createList();
|
||||
|
||||
if( in != out || denyRead )
|
||||
if( in != out )
|
||||
{
|
||||
IItemList<IAEFluidStack> after = AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ).createList();
|
||||
|
||||
if( out != null && !denyRead )
|
||||
if( out != null )
|
||||
{
|
||||
after = out.getAvailableItems( after );
|
||||
}
|
||||
|
||||
Platform.postListChanges( before, after, this, this.source );
|
||||
}
|
||||
}
|
||||
@@ -284,24 +282,34 @@ public class PartFluidStorageBus extends PartSharedStorageBus implements IMEMoni
|
||||
@Override
|
||||
public void postChange( final IBaseMonitor<IAEFluidStack> monitor, final Iterable<IAEFluidStack> change, final IActionSource source )
|
||||
{
|
||||
if( this.source.machine().map( machine -> machine == this ).orElse( false ) && monitor != null )
|
||||
if( this.getProxy().isActive() )
|
||||
{
|
||||
AccessRestriction currentAccess = (AccessRestriction) ( (ConfigManager) this.getConfigManager() ).getSetting( Settings.ACCESS );
|
||||
if( readOncePass )
|
||||
{
|
||||
readOncePass = false;
|
||||
try
|
||||
{
|
||||
this.getProxy().getStorage().postAlterationOfStoredItems( AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ), change, source );
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
// :(
|
||||
}
|
||||
return;
|
||||
}
|
||||
if( !currentAccess.hasPermission( AccessRestriction.READ ) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
try
|
||||
{
|
||||
if( this.getProxy().isActive() )
|
||||
try
|
||||
{
|
||||
this.getProxy().getStorage().postAlterationOfStoredItems( AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ), change, this.source );
|
||||
this.getProxy().getStorage().postAlterationOfStoredItems( AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ), change, source );
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
// :(
|
||||
}
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
// :(
|
||||
}
|
||||
}
|
||||
|
||||
@@ -337,7 +345,7 @@ public class PartFluidStorageBus extends PartSharedStorageBus implements IMEMoni
|
||||
if( inv instanceof ITickingMonitor )
|
||||
{
|
||||
this.monitor = (ITickingMonitor) inv;
|
||||
this.monitor.setActionSource( new MachineSource( this ) );
|
||||
this.monitor.setActionSource( this.source );
|
||||
this.monitor.setMode( (StorageFilter) this.getConfigManager().getSetting( Settings.STORAGE_FILTER ) );
|
||||
}
|
||||
|
||||
@@ -375,7 +383,10 @@ public class PartFluidStorageBus extends PartSharedStorageBus implements IMEMoni
|
||||
|
||||
if( inv instanceof IBaseMonitor )
|
||||
{
|
||||
( (IBaseMonitor<IAEFluidStack>) inv ).addListener( this, this.handler );
|
||||
if( ( (AccessRestriction) ( (ConfigManager) this.getConfigManager() ).getSetting( Settings.ACCESS ) ).hasPermission( AccessRestriction.READ ) )
|
||||
{
|
||||
( (IBaseMonitor<IAEFluidStack>) inv ).addListener( this, this.handler );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+112
-132
@@ -64,23 +64,18 @@ import appeng.me.energy.EnergyWatcher;
|
||||
public class EnergyGridCache implements IEnergyGrid
|
||||
{
|
||||
|
||||
private static final double MAX_BUFFER_STORAGE = 800;
|
||||
private static final Comparator<IEnergyGridProvider> COMPARATOR_HIGHEST_AMOUNT_STORED_FIRST = ( o1, o2 ) -> Double.compare( o2.getProviderStoredEnergy(),
|
||||
o1.getProviderStoredEnergy() );
|
||||
private static final double MAX_BUFFER_STORAGE = 800.0;
|
||||
private static final Comparator<IEnergyGridProvider> COMPARATOR_HIGHEST_AMOUNT_STORED_FIRST = ( o1, o2 ) -> Double.compare( o2.getProviderStoredEnergy(), o1.getProviderStoredEnergy() );
|
||||
|
||||
private static final Comparator<IEnergyGridProvider> COMPARATOR_LOWEST_PERCENTAGE_FIRST = ( o1, o2 ) ->
|
||||
{
|
||||
final double percent1 = ( o1.getProviderStoredEnergy() + 1 ) / ( o1.getProviderMaxEnergy() + 1 );
|
||||
final double percent2 = ( o2.getProviderStoredEnergy() + 1 ) / ( o2.getProviderMaxEnergy() + 1 );
|
||||
private static final Comparator<IEnergyGridProvider> COMPARATOR_LOWEST_PERCENTAGE_FIRST = ( o1, o2 ) -> {
|
||||
final double percent1 = ( o1.getProviderStoredEnergy() + 1.0 ) / ( o1.getProviderMaxEnergy() + 1.0 );
|
||||
final double percent2 = ( o2.getProviderStoredEnergy() + 1.0 ) / ( o2.getProviderMaxEnergy() + 1.0 );
|
||||
|
||||
return Double.compare( percent1, percent2 );
|
||||
};
|
||||
|
||||
private final NavigableSet<EnergyThreshold> interests = Sets.newTreeSet();
|
||||
|
||||
// Should only be modified from the add/remove methods below to guard against
|
||||
// concurrent modifications
|
||||
private final double averageLength = 40.0;
|
||||
private final Set<IAEPowerStorage> providers = new LinkedHashSet<>();
|
||||
// Used to track whether an extraction is currently in progress, to fail fast
|
||||
// when something externally
|
||||
@@ -96,40 +91,40 @@ public class EnergyGridCache implements IEnergyGrid
|
||||
private boolean ongoingInjectOperation = false;
|
||||
|
||||
private final Multiset<IEnergyGridProvider> energyGridProviders = HashMultiset.create();
|
||||
private final IGrid myGrid;
|
||||
final IGrid myGrid;
|
||||
private final HashMap<IGridNode, IEnergyWatcher> watchers = new HashMap<>();
|
||||
|
||||
/**
|
||||
* estimated power available.
|
||||
*/
|
||||
private int availableTicksSinceUpdate = 0;
|
||||
private double globalAvailablePower = 0;
|
||||
private double globalAvailablePower = 0.0;
|
||||
private double globalMaxPower = MAX_BUFFER_STORAGE;
|
||||
|
||||
/**
|
||||
* idle draw.
|
||||
*/
|
||||
private double drainPerTick = 0;
|
||||
private double avgDrainPerTick = 0;
|
||||
private double avgInjectionPerTick = 0;
|
||||
private double tickDrainPerTick = 0;
|
||||
private double tickInjectionPerTick = 0;
|
||||
private double drainPerTick = 0.0;
|
||||
private double avgDrainPerTick = 0.0;
|
||||
private double avgInjectionPerTick = 0.0;
|
||||
private double tickDrainPerTick = 0.0;
|
||||
private double tickInjectionPerTick = 0.0;
|
||||
|
||||
/**
|
||||
* power status
|
||||
*/
|
||||
private boolean publicHasPower = false;
|
||||
private boolean hasPower = true;
|
||||
private long ticksSinceHasPowerChange = 900;
|
||||
long ticksSinceHasPowerChange = 900L;
|
||||
|
||||
private PathGridCache pgc;
|
||||
private double lastStoredPower = -1;
|
||||
private double lastStoredPower = -1.0;
|
||||
|
||||
private final GridPowerStorage localStorage = new GridPowerStorage();
|
||||
private Set<IAEPowerStorage> providerToRemove = new HashSet<>();
|
||||
private Set<IAEPowerStorage> requesterToRemove = new HashSet<>();
|
||||
private Set<IAEPowerStorage> providersToAdd = new HashSet<>();
|
||||
private Set<IAEPowerStorage> requesterToAdd = new HashSet<>();
|
||||
private final Set<IAEPowerStorage> providersToRemove = new HashSet<>();
|
||||
private final Set<IAEPowerStorage> requestersToRemove = new HashSet<>();
|
||||
private final Set<IAEPowerStorage> providersToAdd = new HashSet<>();
|
||||
private final Set<IAEPowerStorage> requestersToAdd = new HashSet<>();
|
||||
|
||||
public EnergyGridCache( final IGrid g )
|
||||
{
|
||||
@@ -163,34 +158,33 @@ public class EnergyGridCache implements IEnergyGrid
|
||||
{
|
||||
if( ev.storage.isAEPublicPowerStorage() )
|
||||
{
|
||||
switch ( ev.type )
|
||||
if( ev.type == PowerEventType.PROVIDE_POWER )
|
||||
{
|
||||
case PROVIDE_POWER:
|
||||
if( ev.storage.getPowerFlow() != AccessRestriction.WRITE )
|
||||
if( ev.storage.getPowerFlow() != AccessRestriction.WRITE )
|
||||
{
|
||||
if( !ongoingExtractOperation )
|
||||
{
|
||||
if( !ongoingExtractOperation )
|
||||
{
|
||||
addProvider( ev.storage );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.providersToAdd.add( ev.storage );
|
||||
}
|
||||
addProvider( ev.storage );
|
||||
}
|
||||
break;
|
||||
case REQUEST_POWER:
|
||||
if( ev.storage.getPowerFlow() != AccessRestriction.READ )
|
||||
else
|
||||
{
|
||||
if( !ongoingInjectOperation )
|
||||
{
|
||||
addRequester( ev.storage );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.requesterToAdd.add( ev.storage );
|
||||
}
|
||||
this.providersToAdd.add( ev.storage );
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if( ev.type == PowerEventType.REQUEST_POWER )
|
||||
{
|
||||
if( ev.storage.getPowerFlow() != AccessRestriction.READ )
|
||||
{
|
||||
if( !ongoingInjectOperation )
|
||||
{
|
||||
addRequester( ev.storage );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.requestersToAdd.add( ev.storage );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -216,17 +210,20 @@ public class EnergyGridCache implements IEnergyGrid
|
||||
}
|
||||
}
|
||||
|
||||
this.avgDrainPerTick *= ( this.averageLength - 1 ) / this.averageLength;
|
||||
this.avgInjectionPerTick *= ( this.averageLength - 1 ) / this.averageLength;
|
||||
// Should only be modified from the add/remove methods below to guard against
|
||||
// concurrent modifications
|
||||
double averageLength = 40.0;
|
||||
this.avgDrainPerTick *= ( averageLength - 1.0 ) / averageLength;
|
||||
this.avgInjectionPerTick *= ( averageLength - 1.0 ) / averageLength;
|
||||
|
||||
this.avgDrainPerTick += this.tickDrainPerTick / this.averageLength;
|
||||
this.avgInjectionPerTick += this.tickInjectionPerTick / this.averageLength;
|
||||
this.avgDrainPerTick += this.tickDrainPerTick / averageLength;
|
||||
this.avgInjectionPerTick += this.tickInjectionPerTick / averageLength;
|
||||
|
||||
this.tickDrainPerTick = 0;
|
||||
this.tickInjectionPerTick = 0;
|
||||
this.tickDrainPerTick = 0.0;
|
||||
this.tickInjectionPerTick = 0.0;
|
||||
|
||||
// power information.
|
||||
boolean currentlyHasPower = false;
|
||||
boolean currentlyHasPower;
|
||||
|
||||
if( this.drainPerTick > 0.0001 )
|
||||
{
|
||||
@@ -235,7 +232,7 @@ public class EnergyGridCache implements IEnergyGrid
|
||||
}
|
||||
else
|
||||
{
|
||||
currentlyHasPower = this.extractAEPower( 0.1, Actionable.SIMULATE, PowerMultiplier.CONFIG ) > 0;
|
||||
currentlyHasPower = this.extractAEPower( 0.1, Actionable.SIMULATE, PowerMultiplier.CONFIG ) > 0.0;
|
||||
}
|
||||
|
||||
// ticks since change..
|
||||
@@ -245,14 +242,14 @@ public class EnergyGridCache implements IEnergyGrid
|
||||
}
|
||||
else
|
||||
{
|
||||
this.ticksSinceHasPowerChange = 0;
|
||||
this.ticksSinceHasPowerChange = 0L;
|
||||
}
|
||||
|
||||
// update status..
|
||||
this.hasPower = currentlyHasPower;
|
||||
|
||||
// update public status, this buffers power ups for 30 ticks.
|
||||
if( this.hasPower && this.ticksSinceHasPowerChange > 30 )
|
||||
if( this.hasPower && this.ticksSinceHasPowerChange > 30L )
|
||||
{
|
||||
this.publicPowerState( true, this.myGrid );
|
||||
}
|
||||
@@ -271,10 +268,10 @@ public class EnergyGridCache implements IEnergyGrid
|
||||
final Queue<IEnergyGridProvider> toVisit = new PriorityQueue<>( COMPARATOR_HIGHEST_AMOUNT_STORED_FIRST );
|
||||
final Set<IEnergyGridProvider> visited = new HashSet<>();
|
||||
|
||||
double extracted = 0;
|
||||
double extracted = 0.0;
|
||||
toVisit.add( this );
|
||||
|
||||
while( !toVisit.isEmpty() && extracted < toExtract )
|
||||
while ( !toVisit.isEmpty() && extracted < toExtract )
|
||||
{
|
||||
final IEnergyGridProvider next = toVisit.poll();
|
||||
visited.add( next );
|
||||
@@ -299,7 +296,7 @@ public class EnergyGridCache implements IEnergyGrid
|
||||
return this.drainPerTick + this.pgc.getChannelPowerUsage();
|
||||
}
|
||||
|
||||
private void publicPowerState( final boolean newState, final IGrid grid )
|
||||
void publicPowerState( final boolean newState, final IGrid grid )
|
||||
{
|
||||
if( this.publicHasPower == newState )
|
||||
{
|
||||
@@ -317,7 +314,7 @@ public class EnergyGridCache implements IEnergyGrid
|
||||
private void refreshPower()
|
||||
{
|
||||
this.availableTicksSinceUpdate = 0;
|
||||
this.globalAvailablePower = 0;
|
||||
this.globalAvailablePower = 0.0;
|
||||
for( final IAEPowerStorage p : this.providers )
|
||||
{
|
||||
this.globalAvailablePower += p.getAECurrentPower();
|
||||
@@ -333,57 +330,39 @@ public class EnergyGridCache implements IEnergyGrid
|
||||
@Override
|
||||
public double extractProviderPower( final double amt, final Actionable mode )
|
||||
{
|
||||
double extractedPower = 0;
|
||||
double extractedPower = 0.0;
|
||||
|
||||
this.providers.addAll( providersToAdd );
|
||||
providersToAdd.clear();
|
||||
if( !ongoingExtractOperation )
|
||||
{
|
||||
this.providers.addAll( providersToAdd );
|
||||
providersToAdd.clear();
|
||||
|
||||
if( providers.remove( localStorage ) )
|
||||
{
|
||||
providers.add( localStorage );
|
||||
}
|
||||
}
|
||||
|
||||
final Iterator<IAEPowerStorage> it = this.providers.iterator();
|
||||
|
||||
ongoingExtractOperation = true;
|
||||
boolean ls = false;
|
||||
try
|
||||
{
|
||||
while ( extractedPower < amt && it.hasNext() )
|
||||
{
|
||||
final IAEPowerStorage node = it.next();
|
||||
|
||||
if( node == localStorage && mode == Actionable.MODULATE )
|
||||
{
|
||||
ls = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
final double req = amt - extractedPower;
|
||||
final double newPower = node.extractAEPower( req, mode, PowerMultiplier.ONE );
|
||||
extractedPower += newPower;
|
||||
|
||||
if( newPower < req && mode == Actionable.MODULATE )
|
||||
{
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
} finally
|
||||
{
|
||||
ongoingExtractOperation = false;
|
||||
this.providers.removeIf( providersToRemove::contains );
|
||||
this.providersToRemove.clear();
|
||||
}
|
||||
|
||||
if( ls && extractedPower < amt )
|
||||
{
|
||||
final double req = amt - extractedPower;
|
||||
final double newPower = localStorage.extractAEPower( req, mode, PowerMultiplier.ONE );
|
||||
|
||||
extractedPower += newPower;
|
||||
|
||||
if( newPower < req )
|
||||
{
|
||||
providers.remove( localStorage );
|
||||
}
|
||||
}
|
||||
|
||||
providers.removeIf( p -> providerToRemove.contains( p ) );
|
||||
this.providerToRemove.clear();
|
||||
|
||||
final double result = Math.min( extractedPower, amt );
|
||||
|
||||
if( mode == Actionable.MODULATE )
|
||||
@@ -405,33 +384,30 @@ public class EnergyGridCache implements IEnergyGrid
|
||||
{
|
||||
final double originalAmount = amt;
|
||||
|
||||
this.requesters.addAll( requesterToAdd );
|
||||
requesterToAdd.clear();
|
||||
if( !ongoingInjectOperation )
|
||||
{
|
||||
this.requesters.addAll( requestersToAdd );
|
||||
requestersToAdd.clear();
|
||||
}
|
||||
|
||||
final Iterator<IAEPowerStorage> it = this.requesters.iterator();
|
||||
|
||||
ongoingInjectOperation = true;
|
||||
try
|
||||
{
|
||||
while ( amt > 0 && it.hasNext() )
|
||||
while ( amt > 0.0 && it.hasNext() )
|
||||
{
|
||||
final IAEPowerStorage node = it.next();
|
||||
|
||||
amt = node.injectAEPower( amt, mode );
|
||||
|
||||
if( amt > 0 && mode == Actionable.MODULATE )
|
||||
{
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
} finally
|
||||
{
|
||||
ongoingInjectOperation = false;
|
||||
this.requesters.removeIf( requestersToRemove::contains );
|
||||
this.requestersToRemove.clear();
|
||||
}
|
||||
|
||||
requesters.removeIf( r -> requesterToRemove.contains( r ) );
|
||||
this.requesterToRemove.clear();
|
||||
|
||||
final double overflow = Math.max( 0.0, amt );
|
||||
|
||||
if( mode == Actionable.MODULATE )
|
||||
@@ -445,7 +421,7 @@ public class EnergyGridCache implements IEnergyGrid
|
||||
@Override
|
||||
public double getProviderEnergyDemand( final double maxRequired )
|
||||
{
|
||||
double required = 0;
|
||||
double required = 0.0;
|
||||
|
||||
final Iterator<IAEPowerStorage> it = this.requesters.iterator();
|
||||
while ( required < maxRequired && it.hasNext() )
|
||||
@@ -487,7 +463,7 @@ public class EnergyGridCache implements IEnergyGrid
|
||||
|
||||
double leftover = amt;
|
||||
|
||||
while( !toVisit.isEmpty() && leftover > 0 )
|
||||
while ( !toVisit.isEmpty() && leftover > 0.0 )
|
||||
{
|
||||
final IEnergyGridProvider next = toVisit.poll();
|
||||
visited.add( next );
|
||||
@@ -526,9 +502,9 @@ public class EnergyGridCache implements IEnergyGrid
|
||||
final Set<IEnergyGridProvider> visited = new HashSet<>();
|
||||
toVisit.add( this );
|
||||
|
||||
double required = 0;
|
||||
double required = 0.0;
|
||||
|
||||
while( !toVisit.isEmpty() && required < maxRequired )
|
||||
while ( !toVisit.isEmpty() && required < maxRequired )
|
||||
{
|
||||
final IEnergyGridProvider next = toVisit.poll();
|
||||
visited.add( next );
|
||||
@@ -556,7 +532,7 @@ public class EnergyGridCache implements IEnergyGrid
|
||||
@Override
|
||||
public double getProviderMaxEnergy()
|
||||
{
|
||||
return this.getMaxStoredPower();
|
||||
return this.globalMaxPower;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -588,7 +564,7 @@ public class EnergyGridCache implements IEnergyGrid
|
||||
}
|
||||
else
|
||||
{
|
||||
this.providerToRemove.add( ps );
|
||||
this.providersToRemove.add( ps );
|
||||
}
|
||||
if( !ongoingInjectOperation )
|
||||
{
|
||||
@@ -596,7 +572,7 @@ public class EnergyGridCache implements IEnergyGrid
|
||||
}
|
||||
else
|
||||
{
|
||||
this.requesterToRemove.add( ps );
|
||||
this.requestersToRemove.add( ps );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -613,28 +589,28 @@ public class EnergyGridCache implements IEnergyGrid
|
||||
}
|
||||
}
|
||||
|
||||
private void addRequester(IAEPowerStorage requester) {
|
||||
Preconditions.checkState(!ongoingInjectOperation,
|
||||
"Cannot modify energy requesters while energy is being injected.");
|
||||
this.requesters.add(requester);
|
||||
private void addRequester( IAEPowerStorage requester )
|
||||
{
|
||||
Preconditions.checkState( !ongoingInjectOperation, "Cannot modify energy requesters while energy is being injected." );
|
||||
this.requesters.add( requester );
|
||||
}
|
||||
|
||||
private void removeRequester(IAEPowerStorage requester) {
|
||||
Preconditions.checkState(!ongoingInjectOperation,
|
||||
"Cannot modify energy requesters while energy is being injected.");
|
||||
this.requesters.remove(requester);
|
||||
private void removeRequester( IAEPowerStorage requester )
|
||||
{
|
||||
Preconditions.checkState( !ongoingInjectOperation, "Cannot modify energy requesters while energy is being injected." );
|
||||
this.requesters.remove( requester );
|
||||
}
|
||||
|
||||
private void addProvider(IAEPowerStorage provider) {
|
||||
Preconditions.checkState(!ongoingExtractOperation,
|
||||
"Cannot modify energy providers while energy is being extracted.");
|
||||
this.providers.add(provider);
|
||||
private void addProvider( IAEPowerStorage provider )
|
||||
{
|
||||
Preconditions.checkState( !ongoingExtractOperation, "Cannot modify energy providers while energy is being extracted." );
|
||||
this.providers.add( provider );
|
||||
}
|
||||
|
||||
private void removeProvider(IAEPowerStorage provider) {
|
||||
Preconditions.checkState(!ongoingExtractOperation,
|
||||
"Cannot modify energy providers while energy is being extracted.");
|
||||
this.providers.remove(provider);
|
||||
private void removeProvider( IAEPowerStorage provider )
|
||||
{
|
||||
Preconditions.checkState( !ongoingExtractOperation, "Cannot modify energy providers while energy is being extracted." );
|
||||
this.providers.remove( provider );
|
||||
}
|
||||
|
||||
|
||||
@@ -666,7 +642,7 @@ public class EnergyGridCache implements IEnergyGrid
|
||||
this.globalMaxPower += ps.getAEMaxPower();
|
||||
}
|
||||
|
||||
if( current > 0 && ps.getPowerFlow() != AccessRestriction.WRITE )
|
||||
if( current > 0.0 && ps.getPowerFlow() != AccessRestriction.WRITE )
|
||||
{
|
||||
this.globalAvailablePower += current;
|
||||
if( !ongoingExtractOperation )
|
||||
@@ -687,7 +663,7 @@ public class EnergyGridCache implements IEnergyGrid
|
||||
}
|
||||
else
|
||||
{
|
||||
this.requesterToAdd.add( ps );
|
||||
this.requestersToAdd.add( ps );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -708,7 +684,7 @@ public class EnergyGridCache implements IEnergyGrid
|
||||
@Override
|
||||
public void onSplit( final IGridStorage storageB )
|
||||
{
|
||||
final double newBuffer = this.localStorage.getAECurrentPower() / 2;
|
||||
final double newBuffer = this.localStorage.getAECurrentPower() / 2.0;
|
||||
this.localStorage.removeCurrentAEPower( newBuffer );
|
||||
storageB.dataObject().setDouble( "buffer", newBuffer );
|
||||
}
|
||||
@@ -737,7 +713,11 @@ public class EnergyGridCache implements IEnergyGrid
|
||||
|
||||
private class GridPowerStorage implements IAEPowerStorage
|
||||
{
|
||||
private double stored = 0;
|
||||
private double stored = 0.0;
|
||||
|
||||
GridPowerStorage()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public double extractAEPower( double amt, Actionable mode, PowerMultiplier usePowerMultiplier )
|
||||
@@ -789,7 +769,7 @@ public class EnergyGridCache implements IEnergyGrid
|
||||
return this.stored;
|
||||
}
|
||||
|
||||
private void addCurrentAEPower( double amount )
|
||||
void addCurrentAEPower( double amount )
|
||||
{
|
||||
this.stored += amount;
|
||||
|
||||
@@ -799,7 +779,7 @@ public class EnergyGridCache implements IEnergyGrid
|
||||
}
|
||||
}
|
||||
|
||||
private void removeCurrentAEPower( double amount )
|
||||
void removeCurrentAEPower( double amount )
|
||||
{
|
||||
this.stored -= amount;
|
||||
|
||||
@@ -810,7 +790,7 @@ public class EnergyGridCache implements IEnergyGrid
|
||||
|
||||
if( this.stored < 0.01 )
|
||||
{
|
||||
EnergyGridCache.this.ticksSinceHasPowerChange = 0;
|
||||
EnergyGridCache.this.ticksSinceHasPowerChange = 0L;
|
||||
EnergyGridCache.this.publicPowerState( false, EnergyGridCache.this.myGrid );
|
||||
}
|
||||
}
|
||||
|
||||
+4
-7
@@ -109,9 +109,6 @@ public class GridStorageCache implements IStorageGrid
|
||||
this.watchers.remove( node );
|
||||
}
|
||||
}
|
||||
|
||||
this.storageMonitors.forEach( ( channel, monitor ) -> monitor.forceUpdate() );
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -140,9 +137,6 @@ public class GridStorageCache implements IStorageGrid
|
||||
this.watchers.put( node, iw );
|
||||
swh.updateWatcher( iw );
|
||||
}
|
||||
|
||||
this.storageMonitors.forEach( ( channel, monitor ) -> monitor.forceUpdate() );
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -334,7 +328,10 @@ public class GridStorageCache implements IStorageGrid
|
||||
|
||||
public void applyChanges()
|
||||
{
|
||||
GridStorageCache.this.postChangesToNetwork( this.channel, this.up_or_down, this.list, this.src );
|
||||
if( !this.list.isEmpty() )
|
||||
{
|
||||
GridStorageCache.this.postChangesToNetwork( this.channel, this.up_or_down, this.list, this.src );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+79
-39
@@ -40,9 +40,7 @@ import com.google.common.collect.Queues;
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Deque;
|
||||
import java.util.Iterator;
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
|
||||
@@ -50,6 +48,9 @@ public class NetworkMonitor<T extends IAEStack<T>> implements IMEMonitor<T>
|
||||
{
|
||||
@Nonnull
|
||||
private static final Deque<NetworkMonitor<?>> GLOBAL_DEPTH = Queues.newArrayDeque();
|
||||
private static final Set<NetworkMonitor<?>> MONITORS = new HashSet<>();
|
||||
protected static boolean nested = false;
|
||||
protected boolean isNested = false;
|
||||
|
||||
@Nonnull
|
||||
private final GridStorageCache myGridCache;
|
||||
@@ -125,10 +126,6 @@ public class NetworkMonitor<T extends IAEStack<T>> implements IMEMonitor<T>
|
||||
|
||||
public long getGridCurrentCount()
|
||||
{
|
||||
if( forceUpdate )
|
||||
{
|
||||
getStorageList();
|
||||
}
|
||||
if( myChannel == AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) )
|
||||
{
|
||||
return gridItemCount;
|
||||
@@ -140,42 +137,23 @@ public class NetworkMonitor<T extends IAEStack<T>> implements IMEMonitor<T>
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void incGridCurrentCount(long count)
|
||||
public long incGridCurrentCount(long count)
|
||||
{
|
||||
if( myChannel == AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) )
|
||||
{
|
||||
gridItemCount += count;
|
||||
return gridItemCount += count;
|
||||
}
|
||||
else if( myChannel == AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ) )
|
||||
{
|
||||
gridFluidCount += count;
|
||||
return gridFluidCount += count;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public IItemList<T> getStorageList()
|
||||
{
|
||||
if( forceUpdate )
|
||||
{
|
||||
forceUpdate = false;
|
||||
this.cachedList.resetStatus();
|
||||
this.getAvailableItems( this.cachedList );
|
||||
|
||||
long count = 0;
|
||||
for (T stack : this.cachedList) {
|
||||
count += stack.getStackSize();
|
||||
}
|
||||
if( myChannel == AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) )
|
||||
{
|
||||
gridItemCount = count;
|
||||
}
|
||||
else if( myChannel == AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ) )
|
||||
{
|
||||
gridFluidCount = count;
|
||||
}
|
||||
}
|
||||
|
||||
return this.cachedList;
|
||||
}
|
||||
|
||||
@@ -222,6 +200,7 @@ public class NetworkMonitor<T extends IAEStack<T>> implements IMEMonitor<T>
|
||||
{
|
||||
final Entry<IMEMonitorHandlerReceiver<T>, Object> o = i.next();
|
||||
final IMEMonitorHandlerReceiver<T> receiver = o.getKey();
|
||||
|
||||
if( receiver.isValid( o.getValue() ) )
|
||||
{
|
||||
receiver.postChange( this, diff, src );
|
||||
@@ -251,27 +230,29 @@ public class NetworkMonitor<T extends IAEStack<T>> implements IMEMonitor<T>
|
||||
|
||||
protected void postChange( final boolean add, final Iterable<T> changes, final IActionSource src )
|
||||
{
|
||||
if( this.localDepthSemaphore > 0 || GLOBAL_DEPTH.contains( this ) )
|
||||
if( MONITORS.contains( this ) )
|
||||
{
|
||||
nested = true;
|
||||
return;
|
||||
}
|
||||
|
||||
this.localDepthSemaphore++;
|
||||
MONITORS.add( this );
|
||||
|
||||
GLOBAL_DEPTH.push( this );
|
||||
|
||||
this.sendEvent = true;
|
||||
|
||||
for( final T changed : changes )
|
||||
for( final T change : changes )
|
||||
{
|
||||
T change = changed;
|
||||
//T change = changed;
|
||||
if( !add && change != null )
|
||||
{
|
||||
change = changed.copy();
|
||||
//change = changed.copy();
|
||||
change.setStackSize( -change.getStackSize() );
|
||||
}
|
||||
|
||||
incGridCurrentCount( change.getStackSize() );
|
||||
this.cachedList.add( change );
|
||||
this.cachedList.addStorage( change );
|
||||
|
||||
if( this.myGridCache.getInterestManager().containsKey( change ) )
|
||||
{
|
||||
@@ -302,7 +283,16 @@ public class NetworkMonitor<T extends IAEStack<T>> implements IMEMonitor<T>
|
||||
this.notifyListenersOfChange( changes, src );
|
||||
|
||||
final NetworkMonitor<?> last = GLOBAL_DEPTH.pop();
|
||||
this.localDepthSemaphore--;
|
||||
|
||||
if( GLOBAL_DEPTH.isEmpty() )
|
||||
{
|
||||
for( NetworkMonitor<?> nm : MONITORS )
|
||||
{
|
||||
nm.setupForceUpdate();
|
||||
}
|
||||
nested = false;
|
||||
MONITORS.clear();
|
||||
}
|
||||
|
||||
if( last != this )
|
||||
{
|
||||
@@ -310,9 +300,60 @@ public class NetworkMonitor<T extends IAEStack<T>> implements IMEMonitor<T>
|
||||
}
|
||||
}
|
||||
|
||||
void setupForceUpdate()
|
||||
{
|
||||
if( nested != isNested )
|
||||
{
|
||||
isNested = nested;
|
||||
forceUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
void forceUpdate()
|
||||
{
|
||||
this.forceUpdate = true;
|
||||
forceUpdate = false;
|
||||
this.cachedList.resetStatus();
|
||||
this.getAvailableItems( this.cachedList );
|
||||
|
||||
long count = 0;
|
||||
for( T stack : this.cachedList )
|
||||
{
|
||||
count += stack.getStackSize();
|
||||
|
||||
if( this.myGridCache.getInterestManager().containsKey( stack ) )
|
||||
{
|
||||
final Collection<ItemWatcher> list = this.myGridCache.getInterestManager().get( stack );
|
||||
|
||||
if( !list.isEmpty() )
|
||||
{
|
||||
IAEStack<T> fullStack = this.getStorageList().findPrecise( stack );
|
||||
|
||||
if( fullStack == null )
|
||||
{
|
||||
fullStack = stack.copy();
|
||||
fullStack.setStackSize( 0 );
|
||||
}
|
||||
|
||||
this.myGridCache.getInterestManager().enableTransactions();
|
||||
|
||||
for ( final ItemWatcher iw : list )
|
||||
{
|
||||
iw.getHost().onStackChange( this.getStorageList(), fullStack, stack, null, this.getChannel() );
|
||||
}
|
||||
|
||||
this.myGridCache.getInterestManager().disableTransactions();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( myChannel == AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) )
|
||||
{
|
||||
gridItemCount = count;
|
||||
}
|
||||
else if( myChannel == AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ) )
|
||||
{
|
||||
gridFluidCount = count;
|
||||
}
|
||||
|
||||
final Iterator<Entry<IMEMonitorHandlerReceiver<T>, Object>> i = this.getListeners();
|
||||
while ( i.hasNext() )
|
||||
@@ -338,6 +379,5 @@ public class NetworkMonitor<T extends IAEStack<T>> implements IMEMonitor<T>
|
||||
this.sendEvent = false;
|
||||
this.myGridCache.getGrid().postEvent( new MENetworkStorageEvent( this, this.myChannel ) );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,11 +23,10 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
import appeng.util.item.AEItemStack;
|
||||
import com.google.common.collect.Multimap;
|
||||
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
|
||||
|
||||
public class GenericInterestManager<T>
|
||||
{
|
||||
@@ -102,30 +101,12 @@ public class GenericInterestManager<T>
|
||||
|
||||
public boolean containsKey( final IAEStack stack )
|
||||
{
|
||||
if( stack.isItem() && ( ( AEItemStack ) stack ).getItem().isDamageable() )
|
||||
{
|
||||
return this.container.keySet().stream().filter( s -> s.isItem() )
|
||||
.anyMatch( s -> s.fuzzyComparison( stack, FuzzyMode.IGNORE_ALL ) );
|
||||
}
|
||||
return this.container.containsKey( stack );
|
||||
}
|
||||
|
||||
public Collection<T> get( final IAEStack stack )
|
||||
{
|
||||
Collection<T> watchers = new ArrayList<>();
|
||||
if( stack.isItem() && ( ( AEItemStack ) stack ).getItem().isDamageable() )
|
||||
{
|
||||
this.container.keySet().stream().filter( s -> s.isItem() )
|
||||
.filter( k -> k.fuzzyComparison( stack, FuzzyMode.IGNORE_ALL ) )
|
||||
.forEach( key ->
|
||||
watchers.addAll( this.container.get( key ) )
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.container.get( stack );
|
||||
}
|
||||
return watchers;
|
||||
return this.container.get( stack );
|
||||
}
|
||||
|
||||
private class SavedTransactions
|
||||
@@ -142,4 +123,4 @@ public class GenericInterestManager<T>
|
||||
this.iw = watcher;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@
|
||||
package appeng.me.helpers;
|
||||
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -55,4 +56,24 @@ public class MachineSource implements IActionSource
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals( Object o )
|
||||
{
|
||||
if( this == o )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if( o == null || getClass() != o.getClass() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
MachineSource that = (MachineSource) o;
|
||||
return via.equals( that.via );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return Objects.hash( via );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,12 +26,13 @@ import com.google.common.collect.ImmutableList;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.implementations.tiles.IChestOrDrive;
|
||||
import appeng.api.networking.security.IActionSource;
|
||||
import appeng.api.storage.ICellHandler;
|
||||
import appeng.api.storage.ICellInventoryHandler;
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
|
||||
public class DriveWatcher<T extends IAEStack<T>> extends MEInventoryHandler<T>
|
||||
{
|
||||
@@ -39,16 +40,16 @@ public class DriveWatcher<T extends IAEStack<T>> extends MEInventoryHandler<T>
|
||||
private int oldStatus = 0;
|
||||
private final ItemStack is;
|
||||
private final ICellHandler handler;
|
||||
private final IChestOrDrive cord;
|
||||
private final TileDrive drive;
|
||||
private IActionSource source;
|
||||
|
||||
public DriveWatcher( final ICellInventoryHandler<T> i, final ItemStack is, final ICellHandler han, final IChestOrDrive cod )
|
||||
public DriveWatcher( final ICellInventoryHandler<T> i, final ItemStack is, final ICellHandler han, final TileDrive drive )
|
||||
{
|
||||
super( i, i.getChannel() );
|
||||
this.is = is;
|
||||
this.handler = han;
|
||||
this.cord = cod;
|
||||
this.source = new MachineSource( cod );
|
||||
this.drive = drive;
|
||||
this.source = new MachineSource( drive );
|
||||
}
|
||||
|
||||
public int getStatus()
|
||||
@@ -69,16 +70,18 @@ public class DriveWatcher<T extends IAEStack<T>> extends MEInventoryHandler<T>
|
||||
|
||||
if( newStatus != this.oldStatus )
|
||||
{
|
||||
this.cord.blinkCell( this.getSlot() );
|
||||
this.drive.blinkCell( this.getSlot() );
|
||||
this.oldStatus = newStatus;
|
||||
}
|
||||
try
|
||||
if (this.drive.getProxy().isActive())
|
||||
{
|
||||
( (TileDrive) this.cord ).getProxy().getStorage().postAlterationOfStoredItems( this.getChannel(), ImmutableList.of( input.copy().setStackSize( input.getStackSize() - ( a == null ? 0 : a.getStackSize() ) ) ), this.source );
|
||||
}
|
||||
catch( GridAccessException e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
try
|
||||
{
|
||||
this.drive.getProxy().getStorage().postAlterationOfStoredItems( this.getChannel(), Collections.singletonList( input.copy().setStackSize( input.getStackSize() - ( a == null ? 0 : a.getStackSize() ) ) ), this.source );
|
||||
} catch ( GridAccessException e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,17 +99,18 @@ public class DriveWatcher<T extends IAEStack<T>> extends MEInventoryHandler<T>
|
||||
|
||||
if( newStatus != this.oldStatus )
|
||||
{
|
||||
this.cord.blinkCell( this.getSlot() );
|
||||
this.drive.blinkCell( this.getSlot() );
|
||||
this.oldStatus = newStatus;
|
||||
}
|
||||
|
||||
try
|
||||
if (this.drive.getProxy().isActive())
|
||||
{
|
||||
( (TileDrive) this.cord ).getProxy().getStorage().postAlterationOfStoredItems( this.getChannel(), ImmutableList.of( request.copy().setStackSize( -a.getStackSize() ) ), this.source );
|
||||
}
|
||||
catch( GridAccessException e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
try
|
||||
{
|
||||
this.drive.getProxy().getStorage().postAlterationOfStoredItems( this.getChannel(), Collections.singletonList( request.copy().setStackSize( -a.getStackSize() ) ), this.source );
|
||||
} catch ( GridAccessException e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -288,24 +288,4 @@ public class MEMonitorIInventory implements IMEMonitor<IAEItemStack>, ITickingMo
|
||||
this.mySource = mySource;
|
||||
}
|
||||
|
||||
private static class CachedItemStack
|
||||
{
|
||||
|
||||
private final ItemStack itemStack;
|
||||
private final IAEItemStack aeStack;
|
||||
|
||||
public CachedItemStack( final ItemStack is )
|
||||
{
|
||||
if( is.isEmpty() )
|
||||
{
|
||||
this.itemStack = ItemStack.EMPTY;
|
||||
this.aeStack = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.itemStack = is.copy();
|
||||
this.aeStack = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createStack( is );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -171,4 +171,5 @@ public class MEMonitorPassThrough<T extends IAEStack<T>> extends MEPassThrough<T
|
||||
{
|
||||
this.changeSource = changeSource;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -187,8 +187,9 @@ public class PartFormationPlane extends PartAbstractFormationPlane<IAEItemStack>
|
||||
this.stateChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
@MENetworkEventSubscribe
|
||||
public void updateChannels( final MENetworkChannelsChanged changedChannels )
|
||||
public void chanRender( final MENetworkChannelsChanged changedChannels )
|
||||
{
|
||||
this.stateChanged();
|
||||
}
|
||||
|
||||
@@ -184,8 +184,9 @@ public class PartLevelEmitter extends PartUpgradeable implements IEnergyWatcherH
|
||||
return flipState ? this.reportingValue >= this.lastReportedValue + 1 : this.reportingValue < this.lastReportedValue + 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
@MENetworkEventSubscribe
|
||||
public void powerStatusChange( final MENetworkPowerStatusChange powerEvent )
|
||||
public void powerRender( final MENetworkPowerStatusChange powerEvent )
|
||||
{
|
||||
if (this.getProxy().isActive())
|
||||
{
|
||||
@@ -194,8 +195,9 @@ public class PartLevelEmitter extends PartUpgradeable implements IEnergyWatcherH
|
||||
this.updateState();
|
||||
}
|
||||
|
||||
@Override
|
||||
@MENetworkEventSubscribe
|
||||
public void channelChanged( final MENetworkChannelsChanged c )
|
||||
public void chanRender( final MENetworkChannelsChanged c )
|
||||
{
|
||||
if (this.getProxy().isActive())
|
||||
{
|
||||
@@ -288,37 +290,24 @@ public class PartLevelEmitter extends PartUpgradeable implements IEnergyWatcherH
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
if( myStack == null )
|
||||
if( this.getInstalledUpgrades( Upgrades.FUZZY ) > 0 || myStack == null )
|
||||
{
|
||||
this.getProxy().getStorage().getInventory( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) ).addListener( this, this.getProxy().getGrid() );
|
||||
this.getProxy()
|
||||
.getStorage()
|
||||
.getInventory( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) )
|
||||
.addListener( this,
|
||||
this.getProxy().getGrid() );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.getProxy().getStorage().getInventory( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) ).removeListener( this );
|
||||
|
||||
if( this.myWatcher != null )
|
||||
{
|
||||
if( this.getInstalledUpgrades( Upgrades.FUZZY ) > 0 )
|
||||
{
|
||||
Optional<OreReference> ores = OreHelper.INSTANCE.getOre( myStack.getDefinition() );
|
||||
if( ores.isPresent() )
|
||||
{
|
||||
for( IAEItemStack iaeItemStack : ores.get().getAEEquivalents() )
|
||||
{
|
||||
this.myWatcher.add( iaeItemStack );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.myWatcher.add( myStack );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.myWatcher.add( myStack );
|
||||
}
|
||||
this.myWatcher.add( myStack );
|
||||
}
|
||||
}
|
||||
|
||||
this.updateReportingValue( this.getProxy().getStorage().getInventory( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) ) );
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
|
||||
@@ -95,14 +95,16 @@ public class PartInterface extends PartBasicState implements IGridTickable, ISto
|
||||
super( is );
|
||||
}
|
||||
|
||||
@Override
|
||||
@MENetworkEventSubscribe
|
||||
public void stateChange( final MENetworkChannelsChanged c )
|
||||
public void chanRender( final MENetworkChannelsChanged c )
|
||||
{
|
||||
this.duality.notifyNeighbors();
|
||||
}
|
||||
|
||||
@Override
|
||||
@MENetworkEventSubscribe
|
||||
public void stateChange( final MENetworkPowerStatusChange c )
|
||||
public void powerRender( final MENetworkPowerStatusChange c )
|
||||
{
|
||||
this.duality.notifyNeighbors();
|
||||
}
|
||||
|
||||
@@ -62,6 +62,7 @@ public abstract class PartSharedStorageBus extends PartUpgradeable implements IG
|
||||
private boolean wasActive = false;
|
||||
private int priority = 0;
|
||||
protected boolean accessChanged;
|
||||
protected boolean readOncePass;
|
||||
|
||||
public PartSharedStorageBus( ItemStack is )
|
||||
{
|
||||
@@ -86,8 +87,9 @@ public abstract class PartSharedStorageBus extends PartUpgradeable implements IG
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@MENetworkEventSubscribe
|
||||
public void updateChannels( final MENetworkChannelsChanged changedChannels )
|
||||
public void chanRender( final MENetworkChannelsChanged changedChannels )
|
||||
{
|
||||
this.updateStatus();
|
||||
}
|
||||
@@ -153,7 +155,7 @@ public abstract class PartSharedStorageBus extends PartUpgradeable implements IG
|
||||
@Override
|
||||
public void updateSetting( final IConfigManager manager, final Enum settingName, final Enum newValue )
|
||||
{
|
||||
if( settingName instanceof AccessRestriction )
|
||||
if( settingName.name().equals( "ACCESS" ) )
|
||||
{
|
||||
this.accessChanged = true;
|
||||
}
|
||||
@@ -178,7 +180,7 @@ public abstract class PartSharedStorageBus extends PartUpgradeable implements IG
|
||||
this.resetCache();
|
||||
}
|
||||
}
|
||||
if( te == null || te instanceof TileFluidInterface )
|
||||
else if( te == null || te instanceof TileFluidInterface )
|
||||
{
|
||||
this.resetCache( true );
|
||||
this.resetCache();
|
||||
@@ -195,6 +197,7 @@ public abstract class PartSharedStorageBus extends PartUpgradeable implements IG
|
||||
{
|
||||
super.readFromNBT( data );
|
||||
this.priority = data.getInteger( "priority" );
|
||||
this.accessChanged = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -23,9 +23,6 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import appeng.fluids.parts.FluidHandlerAdapter;
|
||||
import appeng.me.storage.MEPassThrough;
|
||||
import appeng.parts.AEBasePart;
|
||||
import appeng.tile.misc.TileInterface;
|
||||
import appeng.tile.networking.TileCableBus;
|
||||
import appeng.util.ConfigManager;
|
||||
@@ -92,7 +89,6 @@ import appeng.me.GridAccessException;
|
||||
import appeng.me.helpers.MachineSource;
|
||||
import appeng.me.storage.ITickingMonitor;
|
||||
import appeng.me.storage.MEInventoryHandler;
|
||||
import appeng.me.storage.MEMonitorIInventory;
|
||||
import appeng.parts.PartModel;
|
||||
import appeng.parts.automation.PartUpgradeable;
|
||||
import appeng.tile.inventory.AppEngInternalAEInventory;
|
||||
@@ -128,6 +124,7 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
|
||||
private boolean wasActive = false;
|
||||
private byte resetCacheLogic = 0;
|
||||
private boolean accessChanged;
|
||||
private boolean readOncePass;
|
||||
|
||||
@Reflected
|
||||
public PartStorageBus( final ItemStack is )
|
||||
@@ -164,8 +161,9 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@MENetworkEventSubscribe
|
||||
public void updateChannels( final MENetworkChannelsChanged changedChannels )
|
||||
public void chanRender( final MENetworkChannelsChanged changedChannels )
|
||||
{
|
||||
this.updateStatus();
|
||||
}
|
||||
@@ -179,7 +177,7 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
|
||||
@Override
|
||||
public void updateSetting( final IConfigManager manager, final Enum settingName, final Enum newValue )
|
||||
{
|
||||
if( settingName instanceof AccessRestriction )
|
||||
if( settingName.name().equals( "ACCESS" ) )
|
||||
{
|
||||
this.accessChanged = true;
|
||||
}
|
||||
@@ -211,6 +209,7 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
|
||||
super.readFromNBT( data );
|
||||
this.Config.readFromNBT( data, "config" );
|
||||
this.priority = data.getInteger( "priority" );
|
||||
this.accessChanged = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -269,24 +268,34 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
|
||||
@Override
|
||||
public void postChange( final IBaseMonitor<IAEItemStack> monitor, final Iterable<IAEItemStack> change, final IActionSource source )
|
||||
{
|
||||
if( this.mySrc.machine().map( machine -> machine == this ).orElse( false ) && monitor != null )
|
||||
if( this.getProxy().isActive() )
|
||||
{
|
||||
AccessRestriction currentAccess = (AccessRestriction) ( (ConfigManager) this.getConfigManager() ).getSetting( Settings.ACCESS );
|
||||
if( readOncePass )
|
||||
{
|
||||
readOncePass = false;
|
||||
try
|
||||
{
|
||||
this.getProxy().getStorage().postAlterationOfStoredItems( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ), change, source );
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
// :(
|
||||
}
|
||||
return;
|
||||
}
|
||||
if( !currentAccess.hasPermission( AccessRestriction.READ ) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
try
|
||||
{
|
||||
if( this.getProxy().isActive() )
|
||||
try
|
||||
{
|
||||
this.getProxy().getStorage().postAlterationOfStoredItems( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ), change, this.mySrc );
|
||||
this.getProxy().getStorage().postAlterationOfStoredItems( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ), change, source );
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
// :(
|
||||
}
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
// :(
|
||||
}
|
||||
}
|
||||
|
||||
@@ -321,7 +330,7 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
|
||||
this.resetCache();
|
||||
}
|
||||
}
|
||||
if( te == null || te instanceof TileInterface )
|
||||
else if( te == null || te instanceof TileInterface )
|
||||
{
|
||||
this.resetCache( true );
|
||||
this.resetCache();
|
||||
@@ -377,8 +386,8 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
|
||||
this.resetCacheLogic = 0;
|
||||
|
||||
final MEInventoryHandler<IAEItemStack> in = this.getInternalHandler();
|
||||
|
||||
IItemList<IAEItemStack> before = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
|
||||
boolean denyRead = false;
|
||||
if( in != null )
|
||||
{
|
||||
if( accessChanged )
|
||||
@@ -387,7 +396,7 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
|
||||
AccessRestriction oldAccess = (AccessRestriction) ( (ConfigManager) this.getConfigManager() ).getOldSetting( Settings.ACCESS );
|
||||
if( oldAccess.hasPermission( AccessRestriction.READ ) && !currentAccess.hasPermission( AccessRestriction.READ ) )
|
||||
{
|
||||
denyRead = true;
|
||||
readOncePass = true;
|
||||
}
|
||||
in.setBaseAccess( oldAccess );
|
||||
before = in.getAvailableItems( before );
|
||||
@@ -408,17 +417,15 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
|
||||
|
||||
final MEInventoryHandler<IAEItemStack> out = this.getInternalHandler();
|
||||
|
||||
if( in != out || denyRead )
|
||||
{
|
||||
IItemList<IAEItemStack> after = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
|
||||
IItemList<IAEItemStack> after = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
|
||||
|
||||
if( out != null && !denyRead )
|
||||
if( in != out )
|
||||
{
|
||||
if( out != null )
|
||||
{
|
||||
after = out.getAvailableItems( after );
|
||||
}
|
||||
|
||||
Platform.postListChanges( before, after, this, this.mySrc );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -522,7 +529,7 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
|
||||
if( inv instanceof ITickingMonitor )
|
||||
{
|
||||
this.monitor = (ITickingMonitor) inv;
|
||||
this.monitor.setActionSource( new MachineSource( this ) );
|
||||
this.monitor.setActionSource( mySrc );
|
||||
this.monitor.setMode( (StorageFilter) this.getConfigManager().getSetting( Settings.STORAGE_FILTER ) );
|
||||
}
|
||||
|
||||
@@ -561,7 +568,10 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
|
||||
|
||||
if( inv instanceof IBaseMonitor )
|
||||
{
|
||||
( (IBaseMonitor<IAEItemStack>) inv ).addListener( this, this.handler );
|
||||
if( ( (AccessRestriction) ( (ConfigManager) this.getConfigManager() ).getSetting( Settings.ACCESS ) ).hasPermission( AccessRestriction.READ ) )
|
||||
{
|
||||
( (IBaseMonitor<IAEItemStack>) inv ).addListener( this, this.handler );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -417,7 +417,7 @@ public abstract class AbstractPartMonitor extends AbstractPartDisplay implements
|
||||
@Override
|
||||
public void onStackChange( IItemList<?> o, IAEStack<?> fullStack, IAEStack<?> diffStack, IActionSource src, IStorageChannel<?> chan )
|
||||
{
|
||||
this.configuredAmount = this.configuredAmount + diffStack.getStackSize();
|
||||
this.configuredAmount = fullStack.getStackSize();
|
||||
|
||||
if( this.configuredItem != null )
|
||||
{
|
||||
|
||||
@@ -155,7 +155,7 @@ public class TileEnergyCell extends AENetworkTile implements IAEPowerStorage
|
||||
return 0;
|
||||
}
|
||||
|
||||
if( this.internalCurrentPower < 0.01 && amt > 0.01 )
|
||||
if( this.internalCurrentPower < 0.01 && amt > 0 )
|
||||
{
|
||||
this.getProxy().getNode().getGrid().postEvent( new MENetworkPowerStorage( this, PowerEventType.PROVIDE_POWER ) );
|
||||
}
|
||||
@@ -217,7 +217,7 @@ public class TileEnergyCell extends AENetworkTile implements IAEPowerStorage
|
||||
|
||||
final boolean wasFull = this.internalCurrentPower >= this.getInternalMaxPower() - 0.001;
|
||||
|
||||
if( wasFull && amt > 0.001 )
|
||||
if( wasFull && amt > 0 )
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user