diff --git a/src/main/java/forestry/core/gui/ledgers/Ledger.java b/src/main/java/forestry/core/gui/ledgers/Ledger.java index 1b2f40b48..bdbd06379 100644 --- a/src/main/java/forestry/core/gui/ledgers/Ledger.java +++ b/src/main/java/forestry/core/gui/ledgers/Ledger.java @@ -11,7 +11,6 @@ package forestry.core.gui.ledgers; import java.awt.Rectangle; -import java.util.Date; import java.util.List; import net.minecraft.client.Minecraft; @@ -87,36 +86,48 @@ public abstract class Ledger { } // adjust the update's move amount to match the look of 60 fps (16.67 ms per update) - private static final float msPerUpdate = 67.667f; - private long lastUpdateTime = -1; + private static final float msPerUpdate = 16.667f; + private long lastUpdateTime = 0; public void update() { - if (lastUpdateTime < 0) { - lastUpdateTime = (new Date()).getTime(); - } - long updateTime = (new Date()).getTime(); - int updateVal = (int) Math.round((updateTime - lastUpdateTime) / 8.0); + long updateTime; + if (lastUpdateTime == 0) { + lastUpdateTime = System.currentTimeMillis(); + updateTime = lastUpdateTime + Math.round(msPerUpdate); + } else { + updateTime = System.currentTimeMillis(); + } - // Width - if (open && currentWidth < maxWidth) { - currentWidth += updateVal; - currentWidth = Math.min(maxWidth, currentWidth); - } else if (!open && currentWidth > minWidth) { - currentWidth -= updateVal; - currentWidth = Math.max(minWidth, currentWidth); - } + float moveAmount = Config.guiTabSpeed * (updateTime - lastUpdateTime) / msPerUpdate; - // Height - if (open && currentHeight < maxHeight) { - currentHeight += updateVal; - currentHeight = Math.min(maxWidth, currentHeight); - } else if (!open && currentHeight > minHeight) { - currentHeight -= updateVal; - currentHeight = Math.max(minHeight, currentHeight); - } + lastUpdateTime = updateTime; - lastUpdateTime = updateTime; + // Width + if (open && currentWidth < maxWidth) { + currentWidth += moveAmount; + if (currentWidth > maxWidth) { + currentWidth = maxWidth; + } + } else if (!open && currentWidth > minWidth) { + currentWidth -= moveAmount; + if (currentWidth < minWidth) { + currentWidth = minWidth; + } + } + + // Height + if (open && currentHeight < maxHeight) { + currentHeight += moveAmount; + if (currentHeight > maxHeight) { + currentHeight = maxHeight; + } + } else if (!open && currentHeight > minHeight) { + currentHeight -= moveAmount; + if (currentHeight < minHeight) { + currentHeight = minHeight; + } + } } public int getHeight() {