From 51d374e68465a81d3a67b47745ef5d3cd62a4aa4 Mon Sep 17 00:00:00 2001 From: Chloe Dawn Date: Wed, 3 Aug 2022 21:22:45 +0100 Subject: [PATCH] Add Create-themed tooltip for Time In A Bottle --- .../assets/time_in_a_bottle/lang/en_us.json | 6 +++ kubejs/client_scripts/time_in_a_bottle.js | 39 +++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 kubejs/assets/time_in_a_bottle/lang/en_us.json create mode 100644 kubejs/client_scripts/time_in_a_bottle.js diff --git a/kubejs/assets/time_in_a_bottle/lang/en_us.json b/kubejs/assets/time_in_a_bottle/lang/en_us.json new file mode 100644 index 0000000..3e4eb19 --- /dev/null +++ b/kubejs/assets/time_in_a_bottle/lang/en_us.json @@ -0,0 +1,6 @@ +{ + "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 new file mode 100644 index 0000000..ef68224 --- /dev/null +++ b/kubejs/client_scripts/time_in_a_bottle.js @@ -0,0 +1,39 @@ +// 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 + + 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(")")); + } + + 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 + .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); + }); +});