From 4458bd28abdf7f1a67e4a5e03aaa3d9ec9d5afa4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Salom=C3=A3o?= Date: Sun, 13 Jun 2021 20:30:52 -0300 Subject: [PATCH] refresh ETA not only when items are crafted --- .../implementations/ContainerCraftingCPU.java | 80 ++++++++++--------- .../implementations/CraftingCPUCluster.java | 21 ++--- 2 files changed, 53 insertions(+), 48 deletions(-) diff --git a/src/main/java/appeng/container/implementations/ContainerCraftingCPU.java b/src/main/java/appeng/container/implementations/ContainerCraftingCPU.java index c79a1399d..230aeeca7 100644 --- a/src/main/java/appeng/container/implementations/ContainerCraftingCPU.java +++ b/src/main/java/appeng/container/implementations/ContainerCraftingCPU.java @@ -159,56 +159,58 @@ public class ContainerCraftingCPU extends AEBaseContainer implements IMEMonitorH @Override 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 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 ); - } + final PacketMEInventoryUpdate a = new PacketMEInventoryUpdate( (byte) 0 ); + final PacketMEInventoryUpdate b = new PacketMEInventoryUpdate( (byte) 1 ); + final PacketMEInventoryUpdate c = new PacketMEInventoryUpdate( (byte) 2 ); - final PacketMEInventoryUpdate a = new PacketMEInventoryUpdate( (byte) 0 ); - 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 ) + for( final IAEItemStack out : this.list ) { - if( !a.isEmpty() ) - { - NetworkHandler.instance().sendTo( a, (EntityPlayerMP) g ); - } + a.appendItem( this.getMonitor().getItemStack( out, CraftingItemList.STORAGE ) ); + b.appendItem( this.getMonitor().getItemStack( out, CraftingItemList.ACTIVE ) ); + c.appendItem( this.getMonitor().getItemStack( out, CraftingItemList.PENDING ) ); + } - if( !b.isEmpty() ) - { - NetworkHandler.instance().sendTo( b, (EntityPlayerMP) g ); - } + this.list.resetStatus(); - 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 ) - { - // :P + catch( final IOException e ) + { + // :P + } } } super.detectAndSendChanges(); diff --git a/src/main/java/appeng/me/cluster/implementations/CraftingCPUCluster.java b/src/main/java/appeng/me/cluster/implementations/CraftingCPUCluster.java index d4be8c266..8812073db 100644 --- a/src/main/java/appeng/me/cluster/implementations/CraftingCPUCluster.java +++ b/src/main/java/appeng/me/cluster/implementations/CraftingCPUCluster.java @@ -292,7 +292,7 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU { is.decStackSize( what.getStackSize() ); - this.updateElapsedTime( what ); + this.updateRemainingItemCount( what ); this.markDirty(); this.postCraftingStatusChange( what.copy().setStackSize( -what.getStackSize() ) ); @@ -939,14 +939,13 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU @Override public boolean isBusy() { - final Iterator> 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 ) - { - i.remove(); - } + this.updateElapsedTime(); } return !this.tasks.isEmpty() || !this.waitingFor.isEmpty(); @@ -1338,12 +1337,16 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU 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(); this.elapsedTime = this.getElapsedTime() + nextStartTime - this.lastTime; this.lastTime = nextStartTime; - this.remainingItemCount = this.getRemainingItemCount() - is.getStackSize(); } public long getElapsedTime()