Improve Time In a Bottle tooltip script

pull/3/head
copygirl 2 years ago
parent 51d374e684
commit 104a4a43b8
  1. 46
      kubejs/client_scripts/time_in_a_bottle.js

@ -1,38 +1,30 @@
// 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
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];
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(")"));
tooltip.pop(); // Remove "Stored time hh:mm:ss" line.
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 (totalSeconds > 0) {
name.append(" (");
if (totalHours > 0) name.append(`${totalHours}h`);
if (totalMinutes > 0) name.append(`${totalMinutes % 60}m`);
name.append(`${totalSeconds % 60}s)`);
}
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
.withControl(Component.translate('item.tiab.time_in_a_bottle.tooltip.condition').string,
Component.translate('item.tiab.time_in_a_bottle.tooltip.behaviour').string)
.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