Improve Time In a Bottle tooltip script

carryon-pedestal
copygirl 2 years ago
parent 51d374e684
commit 104a4a43b8
  1. 46
      kubejs/client_scripts/time_in_a_bottle.js

@ -1,38 +1,30 @@
// priority: 0 // priority: 0
const ItemDescription = java('com.simibubi.create.foundation.item.ItemDescription'); onEvent("item.tooltip", event => {
const Palette = java('com.simibubi.create.foundation.item.ItemDescription$Palette'); 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
event.addAdvanced("tiab:time_in_a_bottle", (item, _, tooltip) => {
let name = tooltip[0]; let name = tooltip[0];
let time = item.nbt.getInt('storedTime') / 20; tooltip.pop(); // Remove "Stored time hh:mm:ss" line.
let hours = Math.floor(time / 3600);
let minutes = Math.floor(time % 3600 / 60); let storedTime = item.nbt.getInt("storedTime");
let seconds = Math.floor(time % 3600 % 60); let totalSeconds = Math.floor(storedTime / 20);
let totalMinutes = Math.floor(totalSeconds / 60)
if (hours > 0 || minutes > 0 || seconds > 0) { let totalHours = Math.floor(totalMinutes / 60);
name.append(Component.string(" ("));
if (totalSeconds > 0) {
if (hours > 0) name.append(" (");
name.append(Component.string(`${hours}h`)); if (totalHours > 0) name.append(`${totalHours}h`);
if (totalMinutes > 0) name.append(`${totalMinutes % 60}m`);
if (minutes > 0) name.append(`${totalSeconds % 60}s)`);
name.append(Component.string(`${minutes}m`));
if (seconds > 0)
name.append(Component.string(`${seconds}s`));
name.append(Component.string(")"));
} }
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
.withControl(Component.translate('item.tiab.time_in_a_bottle.tooltip.condition').string, .withControl(Component.translate("item.tiab.time_in_a_bottle.tooltip.condition").string,
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