Well-rounded Minecraft 1.18.2 modpack featuring Tech, Magic, Exploration and Decoration content. Made with love. 💚
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
1.4 KiB

// priority: 0
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, advanced, tooltip) => {
// Append time to the item's name.
let storedTime = item.nbt.getInt("storedTime");
if (storedTime > 0) {
let totalSeconds = Math.floor(storedTime / 20);
let totalMinutes = Math.floor(totalSeconds / 60)
let totalHours = Math.floor(totalMinutes / 60);
let name = tooltip[0];
name.append(" (");
if (totalHours > 0) name.append(`${totalHours}h`);
if (totalMinutes > 0) name.append(`${totalMinutes % 60}m`);
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)
.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);
});
});