Fix Time in a Bottle tooltip script some more

pull/3/head
copygirl 2 years ago
parent b6054ca261
commit f105f2877a
  1. 2
      kubejs/assets/time_in_a_bottle/lang/en_us.json
  2. 20
      kubejs/client_scripts/time_in_a_bottle.js

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

@ -4,22 +4,27 @@ onEvent("item.tooltip", event => {
const ItemDescription = java("com.simibubi.create.foundation.item.ItemDescription"); const ItemDescription = java("com.simibubi.create.foundation.item.ItemDescription");
const Palette = java("com.simibubi.create.foundation.item.ItemDescription$Palette"); const Palette = java("com.simibubi.create.foundation.item.ItemDescription$Palette");
event.addAdvanced("tiab:time_in_a_bottle", (item, _, tooltip) => { event.addAdvanced("tiab:time_in_a_bottle", (item, advanced, tooltip) => {
let name = tooltip[0];
tooltip.pop(); // Remove "Stored time hh:mm:ss" line.
// Append time to the item's name.
let storedTime = item.nbt.getInt("storedTime"); let storedTime = item.nbt.getInt("storedTime");
let totalSeconds = Math.floor(storedTime / 20); if (storedTime > 0) {
let totalMinutes = Math.floor(totalSeconds / 60) let totalSeconds = Math.floor(storedTime / 20);
let totalHours = Math.floor(totalMinutes / 60); let totalMinutes = Math.floor(totalSeconds / 60)
let totalHours = Math.floor(totalMinutes / 60);
if (totalSeconds > 0) { let name = tooltip[0];
name.append(" ("); name.append(" (");
if (totalHours > 0) name.append(`${totalHours}h`); if (totalHours > 0) name.append(`${totalHours}h`);
if (totalMinutes > 0) name.append(`${totalMinutes % 60}m`); if (totalMinutes > 0) name.append(`${totalMinutes % 60}m`);
name.append(`${totalSeconds % 60}s)`); 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) 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 // 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) Component.translate("item.tiab.time_in_a_bottle.tooltip.behaviour").string)
.createTabs() .createTabs()
.addInformation(tooltip); .addInformation(tooltip);
}); });
}); });

Loading…
Cancel
Save