From 104a4a43b8b7fd3148347d497a73d61e02f5f084 Mon Sep 17 00:00:00 2001 From: copygirl Date: Thu, 4 Aug 2022 21:30:19 +0200 Subject: [PATCH] Improve Time In a Bottle tooltip script --- kubejs/client_scripts/time_in_a_bottle.js | 46 ++++++++++------------- 1 file changed, 19 insertions(+), 27 deletions(-) diff --git a/kubejs/client_scripts/time_in_a_bottle.js b/kubejs/client_scripts/time_in_a_bottle.js index ef68224..c5ea8ea 100644 --- a/kubejs/client_scripts/time_in_a_bottle.js +++ b/kubejs/client_scripts/time_in_a_bottle.js @@ -1,38 +1,30 @@ // priority: 0 -const ItemDescription = java('com.simibubi.create.foundation.item.ItemDescription'); -const Palette = java('com.simibubi.create.foundation.item.ItemDescription$Palette'); - -onEvent('item.tooltip', event => { - event.addAdvanced('tiab:time_in_a_bottle', (item, _, tooltip) => { - tooltip.pop(); // Remove "Stored time hh:mm:ss" line +onEvent("item.tooltip", event => { + const ItemDescription = java("com.simibubi.create.foundation.item.ItemDescription"); + const Palette = java("com.simibubi.create.foundation.item.ItemDescription$Palette"); + event.addAdvanced("tiab:time_in_a_bottle", (item, _, tooltip) => { let name = tooltip[0]; - let time = item.nbt.getInt('storedTime') / 20; - let hours = Math.floor(time / 3600); - let minutes = Math.floor(time % 3600 / 60); - let seconds = Math.floor(time % 3600 % 60); - - if (hours > 0 || minutes > 0 || seconds > 0) { - name.append(Component.string(" (")); - - if (hours > 0) - name.append(Component.string(`${hours}h`)); - - if (minutes > 0) - name.append(Component.string(`${minutes}m`)); - - if (seconds > 0) - name.append(Component.string(`${seconds}s`)); - - name.append(Component.string(")")); + tooltip.pop(); // Remove "Stored time hh:mm:ss" line. + + let storedTime = item.nbt.getInt("storedTime"); + let totalSeconds = Math.floor(storedTime / 20); + let totalMinutes = Math.floor(totalSeconds / 60) + let totalHours = Math.floor(totalMinutes / 60); + + if (totalSeconds > 0) { + name.append(" ("); + if (totalHours > 0) name.append(`${totalHours}h`); + if (totalMinutes > 0) name.append(`${totalMinutes % 60}m`); + name.append(`${totalSeconds % 60}s)`); } new ItemDescription(Palette.Gray) - .withSummary(Component.translate('item.tiab.time_in_a_bottle.tooltip.summary')) + .withSummary(Component.translate("item.tiab.time_in_a_bottle.tooltip.summary")) // Create expects localized strings instead of components here, so we localize ourselves - .withControl(Component.translate('item.tiab.time_in_a_bottle.tooltip.condition').string, - Component.translate('item.tiab.time_in_a_bottle.tooltip.behaviour').string) + .withControl(Component.translate("item.tiab.time_in_a_bottle.tooltip.condition").string, + Component.translate("item.tiab.time_in_a_bottle.tooltip.behaviour").string) .createTabs() .addInformation(tooltip); });