From f105f2877a78583a9fdee5fca681ca04efc54880 Mon Sep 17 00:00:00 2001 From: copygirl Date: Mon, 8 Aug 2022 13:05:12 +0200 Subject: [PATCH] Fix Time in a Bottle tooltip script some more --- .../assets/time_in_a_bottle/lang/en_us.json | 2 +- kubejs/client_scripts/time_in_a_bottle.js | 20 ++++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/kubejs/assets/time_in_a_bottle/lang/en_us.json b/kubejs/assets/time_in_a_bottle/lang/en_us.json index 3e4eb19..3e4ce0c 100644 --- a/kubejs/assets/time_in_a_bottle/lang/en_us.json +++ b/kubejs/assets/time_in_a_bottle/lang/en_us.json @@ -1,5 +1,5 @@ { - "item.tiab.time_in_a_bottle": "Time In A Bottle", + "item.tiab.time_in_a_bottle": "Time in a Bottle", "item.tiab.time_in_a_bottle.tooltip.summary": "A _solitary_ bottle of tick-manipulating power that _accumulates time_ when carried in _your inventory_. Can be used to _accelerate_ machine speed and plant growth.", "item.tiab.time_in_a_bottle.tooltip.condition": "R-Click on Block", "item.tiab.time_in_a_bottle.tooltip.behaviour": "_Multiplies_ the speed of the targeted block by a power of two, _consuming_ 30s from the bottle per multiplier. The effect _expires_ after 30s." diff --git a/kubejs/client_scripts/time_in_a_bottle.js b/kubejs/client_scripts/time_in_a_bottle.js index c5ea8ea..ca06ba3 100644 --- a/kubejs/client_scripts/time_in_a_bottle.js +++ b/kubejs/client_scripts/time_in_a_bottle.js @@ -4,22 +4,27 @@ 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]; - tooltip.pop(); // Remove "Stored time hh:mm:ss" line. + event.addAdvanced("tiab:time_in_a_bottle", (item, advanced, tooltip) => { + // Append time to the item's name. 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 (storedTime > 0) { + let totalSeconds = Math.floor(storedTime / 20); + let totalMinutes = Math.floor(totalSeconds / 60) + let totalHours = Math.floor(totalMinutes / 60); - if (totalSeconds > 0) { + let name = tooltip[0]; name.append(" ("); if (totalHours > 0) name.append(`${totalHours}h`); if (totalMinutes > 0) name.append(`${totalMinutes % 60}m`); name.append(`${totalSeconds % 60}s)`); } + // Remove "Stored time hh:mm:ss" line. + // NOTE: This is a Java list, not a JavaScript(-like) one. + tooltip.remove(1); + + // Add Create-style description and usage hint. new ItemDescription(Palette.Gray) .withSummary(Component.translate("item.tiab.time_in_a_bottle.tooltip.summary")) // Create expects localized strings instead of components here, so we localize ourselves @@ -27,5 +32,6 @@ onEvent("item.tooltip", event => { Component.translate("item.tiab.time_in_a_bottle.tooltip.behaviour").string) .createTabs() .addInformation(tooltip); + }); });