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,56 +159,58 @@ 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 ) final long elapsedTime = this.getMonitor().getElapsedTime();
final double remainingItems = this.getMonitor().getRemainingItemCount();
final double startItems = this.getMonitor().getStartItemCount();
final long eta = (long) ( elapsedTime / Math.max( 1d, ( startItems - remainingItems ) ) * remainingItems );
this.setEstimatedTime( eta );
}
if( !this.list.isEmpty() )
{
try
{ {
final long elapsedTime = this.getMonitor().getElapsedTime(); final PacketMEInventoryUpdate a = new PacketMEInventoryUpdate( (byte) 0 );
final double remainingItems = this.getMonitor().getRemainingItemCount(); final PacketMEInventoryUpdate b = new PacketMEInventoryUpdate( (byte) 1 );
final double startItems = this.getMonitor().getStartItemCount(); final PacketMEInventoryUpdate c = new PacketMEInventoryUpdate( (byte) 2 );
final long eta = (long) ( elapsedTime / Math.max( 1d, ( startItems - remainingItems ) ) * remainingItems );
this.setEstimatedTime( eta );
}
final PacketMEInventoryUpdate a = new PacketMEInventoryUpdate( (byte) 0 ); for( final IAEItemStack out : this.list )
final PacketMEInventoryUpdate b = new PacketMEInventoryUpdate( (byte) 1 );
final PacketMEInventoryUpdate c = new PacketMEInventoryUpdate( (byte) 2 );
for( final IAEItemStack out : this.list )
{
a.appendItem( this.getMonitor().getItemStack( out, CraftingItemList.STORAGE ) );
b.appendItem( this.getMonitor().getItemStack( out, CraftingItemList.ACTIVE ) );
c.appendItem( this.getMonitor().getItemStack( out, CraftingItemList.PENDING ) );
}
this.list.resetStatus();
for( final Object g : this.listeners )
{
if( g instanceof EntityPlayer )
{ {
if( !a.isEmpty() ) a.appendItem( this.getMonitor().getItemStack( out, CraftingItemList.STORAGE ) );
{ b.appendItem( this.getMonitor().getItemStack( out, CraftingItemList.ACTIVE ) );
NetworkHandler.instance().sendTo( a, (EntityPlayerMP) g ); c.appendItem( this.getMonitor().getItemStack( out, CraftingItemList.PENDING ) );
} }
if( !b.isEmpty() ) this.list.resetStatus();
{
NetworkHandler.instance().sendTo( b, (EntityPlayerMP) g );
}
if( !c.isEmpty() ) for( final Object g : this.listeners )
{
if( g instanceof EntityPlayer )
{ {
NetworkHandler.instance().sendTo( c, (EntityPlayerMP) g ); if( !a.isEmpty() )
{
NetworkHandler.instance().sendTo( a, (EntityPlayerMP) g );
}
if( !b.isEmpty() )
{
NetworkHandler.instance().sendTo( b, (EntityPlayerMP) g );
}
if( !c.isEmpty() )
{
NetworkHandler.instance().sendTo( c, (EntityPlayerMP) g );
}
} }
} }
} }
} catch( final IOException e )
catch( final IOException e ) {
{ // :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()