|
|
|
// 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);
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|