refresh ETA not only when items are crafted

This commit is contained in:
Salomão
2021-06-13 20:30:52 -03:00
parent df3f00d978
commit 4458bd28ab
2 changed files with 53 additions and 48 deletions
@@ -159,9 +159,7 @@ public class ContainerCraftingCPU extends AEBaseContainer implements IMEMonitorH
@Override @Override
public void detectAndSendChanges() public void detectAndSendChanges()
{ {
if( Platform.isServer() && this.getMonitor() != null && !this.list.isEmpty() ) if( Platform.isServer() && this.getMonitor() != null )
{
try
{ {
if( this.getEstimatedTime() >= 0 ) if( this.getEstimatedTime() >= 0 )
{ {
@@ -171,7 +169,10 @@ public class ContainerCraftingCPU extends AEBaseContainer implements IMEMonitorH
final long eta = (long) ( elapsedTime / Math.max( 1d, ( startItems - remainingItems ) ) * remainingItems ); final long eta = (long) ( elapsedTime / Math.max( 1d, ( startItems - remainingItems ) ) * remainingItems );
this.setEstimatedTime( eta ); this.setEstimatedTime( eta );
} }
if( !this.list.isEmpty() )
{
try
{
final PacketMEInventoryUpdate a = new PacketMEInventoryUpdate( (byte) 0 ); final PacketMEInventoryUpdate a = new PacketMEInventoryUpdate( (byte) 0 );
final PacketMEInventoryUpdate b = new PacketMEInventoryUpdate( (byte) 1 ); final PacketMEInventoryUpdate b = new PacketMEInventoryUpdate( (byte) 1 );
final PacketMEInventoryUpdate c = new PacketMEInventoryUpdate( (byte) 2 ); final PacketMEInventoryUpdate c = new PacketMEInventoryUpdate( (byte) 2 );
@@ -211,6 +212,7 @@ public class ContainerCraftingCPU extends AEBaseContainer implements IMEMonitorH
// :P // :P
} }
} }
}
super.detectAndSendChanges(); super.detectAndSendChanges();
} }
@@ -292,7 +292,7 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU
{ {
is.decStackSize( what.getStackSize() ); is.decStackSize( what.getStackSize() );
this.updateElapsedTime( what ); this.updateRemainingItemCount( what );
this.markDirty(); this.markDirty();
this.postCraftingStatusChange( what.copy().setStackSize( -what.getStackSize() ) ); this.postCraftingStatusChange( what.copy().setStackSize( -what.getStackSize() ) );
@@ -939,14 +939,13 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU
@Override @Override
public boolean isBusy() public boolean isBusy()
{ {
final Iterator<Entry<ICraftingPatternDetails, TaskProgress>> i = this.tasks.entrySet().iterator();
while( i.hasNext() ) this.tasks.entrySet().removeIf(
taskProgressEntry -> taskProgressEntry.getValue().value <= 0 );
if( !this.waitingFor.isEmpty() || !this.tasks.isEmpty() )
{ {
if( i.next().getValue().value <= 0 ) this.updateElapsedTime();
{
i.remove();
}
} }
return !this.tasks.isEmpty() || !this.waitingFor.isEmpty(); return !this.tasks.isEmpty() || !this.waitingFor.isEmpty();
@@ -1338,12 +1337,16 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU
this.remainingItemCount = itemCount; this.remainingItemCount = itemCount;
} }
private void updateElapsedTime( final IAEItemStack is ) private void updateRemainingItemCount( final IAEItemStack is )
{
this.remainingItemCount = this.getRemainingItemCount() - is.getStackSize();
}
private void updateElapsedTime()
{ {
final long nextStartTime = System.nanoTime(); final long nextStartTime = System.nanoTime();
this.elapsedTime = this.getElapsedTime() + nextStartTime - this.lastTime; this.elapsedTime = this.getElapsedTime() + nextStartTime - this.lastTime;
this.lastTime = nextStartTime; this.lastTime = nextStartTime;
this.remainingItemCount = this.getRemainingItemCount() - is.getStackSize();
} }
public long getElapsedTime() public long getElapsedTime()