Add Create-themed tooltip for Time In A Bottle

pull/2/head
Chloe 2 years ago
parent 51e0230722
commit 51d374e684
Signed by: HeckinChloe
GPG Key ID: 4E8B3A6874317E73
  1. 6
      kubejs/assets/time_in_a_bottle/lang/en_us.json
  2. 39
      kubejs/client_scripts/time_in_a_bottle.js

@ -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."
}

@ -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);
});
});
Loading…
Cancel
Save