diff --git a/src/api/java/mcp/mobius/waila/api/WailaConstants.java b/src/api/java/mcp/mobius/waila/api/WailaConstants.java
index a9380507c..0e788ebfa 100644
--- a/src/api/java/mcp/mobius/waila/api/WailaConstants.java
+++ b/src/api/java/mcp/mobius/waila/api/WailaConstants.java
@@ -50,6 +50,13 @@ public class WailaConstants {
*/
public static final ResourceLocation MOD_NAME_TAG = id("mod_name");
+ /**
+ * Tooltip tag for errors.
+ *
+ * @see ITooltip#setLine
+ */
+ public static final ResourceLocation ERROR_TAG = id("error");
+
/**
* Whether Waila should show tooltip for blocks.
*
diff --git a/src/main/java/mcp/mobius/waila/util/ExceptionUtil.java b/src/main/java/mcp/mobius/waila/util/ExceptionUtil.java
index e08ec51ea..921621fd9 100644
--- a/src/main/java/mcp/mobius/waila/util/ExceptionUtil.java
+++ b/src/main/java/mcp/mobius/waila/util/ExceptionUtil.java
@@ -4,6 +4,7 @@
import java.util.Set;
import mcp.mobius.waila.api.ITooltip;
+import mcp.mobius.waila.api.WailaConstants;
import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component;
import org.apache.commons.lang3.exception.ExceptionUtils;
@@ -23,8 +24,9 @@ public static boolean dump(Throwable e, String errorName, @Nullable ITooltip too
}
if (tooltip != null) {
- tooltip.addLine(Component.literal("Error on " + errorName).withStyle(ChatFormatting.RED));
- tooltip.addLine(Component.literal("See logs for more info").withStyle(ChatFormatting.RED));
+ tooltip.setLine(WailaConstants.ERROR_TAG, Component
+ .literal("Error on " + errorName + "\nSee logs for more info")
+ .withStyle(ChatFormatting.RED));
}
return log;
diff --git a/src/pluginExtra/java/mcp/mobius/waila/plugin/extra/provider/FluidProvider.java b/src/pluginExtra/java/mcp/mobius/waila/plugin/extra/provider/FluidProvider.java
index 58cff8f63..2f7a5832f 100644
--- a/src/pluginExtra/java/mcp/mobius/waila/plugin/extra/provider/FluidProvider.java
+++ b/src/pluginExtra/java/mcp/mobius/waila/plugin/extra/provider/FluidProvider.java
@@ -12,6 +12,7 @@
import mcp.mobius.waila.api.component.WrappedComponent;
import mcp.mobius.waila.api.data.FluidData;
import mcp.mobius.waila.plugin.extra.data.FluidDataImpl;
+import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.Block;
@@ -64,7 +65,7 @@ private void addFluidTooltip(ITooltip tooltip, FluidDataImpl data, IPluginConfig
text += " " + displayUnit.symbol;
var sprite = desc.sprite();
- tooltip.addLine(new PairComponent(
+ tooltip.setLine(FluidData.ID.withSuffix("." + BuiltInRegistries.FLUID.getKey(entry.fluid()).toLanguageKey()), new PairComponent(
new WrappedComponent(desc.name().getString()),
new SpriteBarComponent(ratio, sprite, 16, 16, desc.tint(), Component.literal(text))));
}
diff --git a/src/pluginHarvest/java/mcp/mobius/waila/plugin/harvest/provider/HarvestProvider.java b/src/pluginHarvest/java/mcp/mobius/waila/plugin/harvest/provider/HarvestProvider.java
index 81d2a6a00..3c934d9cf 100644
--- a/src/pluginHarvest/java/mcp/mobius/waila/plugin/harvest/provider/HarvestProvider.java
+++ b/src/pluginHarvest/java/mcp/mobius/waila/plugin/harvest/provider/HarvestProvider.java
@@ -25,6 +25,7 @@
import net.minecraft.client.resources.language.I18n;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
+import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TieredItem;
import net.minecraft.world.level.block.state.BlockState;
@@ -34,6 +35,12 @@ public enum HarvestProvider implements IBlockComponentProvider, IEventListener {
INSTANCE;
+ private static final ResourceLocation CLASSIC_HARVESTABLE = Options.rl("classic.harvestable");
+ private static final ResourceLocation CLASSIC_EFFECTIVE_TOOL = Options.rl("classic.effective_tool");
+ private static final ResourceLocation CLASSIC_LEVEL = Options.rl("classic.level");
+
+ private static final ResourceLocation CLASSIC_MINIMAL = Options.rl("classic.minimal");
+
private static final ToolType UNBREAKABLE = new ToolType();
public final Map> toolsCache = new Reference2ObjectOpenHashMap<>();
@@ -89,16 +96,16 @@ public void appendBody(ITooltip tooltip, IBlockAccessor accessor, IPluginConfig
var heldStack = accessor.getPlayer().getInventory().getSelected();
if (displayMode == HarvestDisplayMode.CLASSIC) {
- tooltip.addLine(Component.empty()
+ tooltip.setLine(CLASSIC_HARVESTABLE, Component.empty()
.append(getHarvestableSymbol(accessor, unbreakable))
.append(" ")
.append(Component.translatable(Tl.Tooltip.Harvest.HARVESTABLE)));
- if (!tools.isEmpty() && !unbreakable) tooltip.addLine(new PairComponent(
+ if (!tools.isEmpty() && !unbreakable) tooltip.setLine(CLASSIC_EFFECTIVE_TOOL, new PairComponent(
Component.translatable(Tl.Tooltip.Harvest.EFFECTIVE_TOOL),
getToolText(tools, heldStack)));
- if (highestTier != ToolTier.NONE) tooltip.addLine(new PairComponent(
+ if (highestTier != ToolTier.NONE) tooltip.setLine(CLASSIC_LEVEL, new PairComponent(
Component.translatable(Tl.Tooltip.Harvest.LEVEL),
getTierText(highestTier, heldStack)));
} else if (displayMode == HarvestDisplayMode.CLASSIC_MINIMAL) {
@@ -116,7 +123,7 @@ public void appendBody(ITooltip tooltip, IBlockAccessor accessor, IPluginConfig
text.append(getTierText(highestTier, heldStack));
}
- tooltip.addLine(text);
+ tooltip.setLine(CLASSIC_MINIMAL, text);
}
}
diff --git a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/BeaconProvider.java b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/BeaconProvider.java
index 59cfadf8d..daa446960 100644
--- a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/BeaconProvider.java
+++ b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/BeaconProvider.java
@@ -2,22 +2,13 @@
import mcp.mobius.waila.api.IBlockAccessor;
import mcp.mobius.waila.api.IBlockComponentProvider;
-import mcp.mobius.waila.api.IData;
-import mcp.mobius.waila.api.IDataProvider;
-import mcp.mobius.waila.api.IDataWriter;
import mcp.mobius.waila.api.IPluginConfig;
-import mcp.mobius.waila.api.IServerAccessor;
import mcp.mobius.waila.api.ITooltip;
-import mcp.mobius.waila.mixin.BeaconBlockEntityAccess;
import mcp.mobius.waila.plugin.vanilla.config.Options;
import mcp.mobius.waila.plugin.vanilla.provider.data.BeaconDataProvider;
-import net.minecraft.core.registries.BuiltInRegistries;
-import net.minecraft.network.FriendlyByteBuf;
+import net.minecraft.network.chat.CommonComponents;
import net.minecraft.network.chat.MutableComponent;
-import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.effect.MobEffect;
-import net.minecraft.world.level.block.entity.BeaconBlockEntity;
-import org.jetbrains.annotations.Nullable;
public enum BeaconProvider implements IBlockComponentProvider {
@@ -33,17 +24,16 @@ public void appendBody(ITooltip tooltip, IBlockAccessor accessor, IPluginConfig
if (!config.getBoolean(Options.EFFECT_BEACON)) return;
var data = accessor.getData().get(BeaconDataProvider.Data.class);
- if (data == null) return;
+ if (data == null || data.primary() == null) return;
- if (data.primary() != null) {
- var text = getText(data.primary());
- if (data.primary() == data.secondary()) text.append(" II");
- tooltip.addLine(text);
- }
+ var text = getText(data.primary());
+ if (data.primary() == data.secondary()) text.append(" II");
if (data.secondary() != null && data.primary() != data.secondary()) {
- tooltip.addLine(getText(data.secondary()));
+ text.append(CommonComponents.NEW_LINE).append(getText(data.secondary()));
}
+
+ tooltip.setLine(Options.EFFECT_BEACON, text);
}
}
diff --git a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/BeeProvider.java b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/BeeProvider.java
index 25ed249c3..284d14da8 100644
--- a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/BeeProvider.java
+++ b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/BeeProvider.java
@@ -20,7 +20,7 @@ public enum BeeProvider implements IEntityComponentProvider {
public void appendBody(ITooltip tooltip, IEntityAccessor accessor, IPluginConfig config) {
var hivePos = accessor.getData().get(BeeDataProvider.HivePosData.class);
if (hivePos != null && config.getBoolean(Options.BEE_HIVE_POS)) {
- tooltip.addLine(new PairComponent(
+ tooltip.setLine(Options.BEE_HIVE_POS, new PairComponent(
new WrappedComponent(Component.translatable(Tl.Tooltip.Bee.HIVE)),
new PositionComponent(hivePos.pos())));
}
diff --git a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/BeehiveProvider.java b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/BeehiveProvider.java
index 70e430cb9..bea331328 100644
--- a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/BeehiveProvider.java
+++ b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/BeehiveProvider.java
@@ -9,6 +9,7 @@
import mcp.mobius.waila.buildconst.Tl;
import mcp.mobius.waila.plugin.vanilla.config.Options;
import mcp.mobius.waila.plugin.vanilla.provider.data.BeehiveDataProvider;
+import net.minecraft.network.chat.CommonComponents;
import net.minecraft.network.chat.Component;
import net.minecraft.world.level.block.BeehiveBlock;
@@ -31,17 +32,24 @@ public void appendBody(ITooltip tooltip, IBlockAccessor accessor, IPluginConfig
names.put(name, names.getOrDefault(name, 0) + 1);
}
- for (var entry : names.object2IntEntrySet()) {
- var name = entry.getKey();
- var count = entry.getIntValue();
- if (count > 1) tooltip.addLine(Component.literal(count + " " + name));
- else tooltip.addLine(Component.literal(name));
+ if (!names.isEmpty()) {
+ var component = Component.empty();
+
+ for (var entry : names.object2IntEntrySet()) {
+ if (!component.getSiblings().isEmpty()) component.append(CommonComponents.NEW_LINE);
+ var name = entry.getKey();
+ var count = entry.getIntValue();
+ if (count > 1) component.append(Component.literal(count + " " + name));
+ else component.append(Component.literal(name));
+ }
+
+ tooltip.setLine(Options.BEE_HIVE_OCCUPANTS, component);
}
}
if (config.getBoolean(Options.BEE_HIVE_HONEY_LEVEL)) {
var state = accessor.getBlockState();
- tooltip.addLine(new PairComponent(
+ tooltip.setLine(Options.BEE_HIVE_HONEY_LEVEL, new PairComponent(
Component.translatable(Tl.Tooltip.HONEY_LEVEL),
Component.literal(state.getValue(BeehiveBlock.HONEY_LEVEL).toString())));
}
diff --git a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/BlockAttributesProvider.java b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/BlockAttributesProvider.java
index ee857e397..ec9f347ef 100644
--- a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/BlockAttributesProvider.java
+++ b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/BlockAttributesProvider.java
@@ -18,19 +18,20 @@ public enum BlockAttributesProvider implements IBlockComponentProvider {
@Override
public void appendBody(ITooltip tooltip, IBlockAccessor accessor, IPluginConfig config) {
if (config.getBoolean(Options.BLOCK_POSITION)) {
- tooltip.addLine(new PositionComponent(accessor.getPosition()));
+ tooltip.setLine(Options.BLOCK_POSITION, new PositionComponent(accessor.getPosition()));
}
if (config.getBoolean(Options.BLOCK_STATE)) {
var state = accessor.getBlockState();
- state.getProperties().forEach(property -> {
- Comparable> value = state.getValue(property);
+ for (var property : state.getProperties()) {
+ var value = state.getValue(property);
var valueText = Component.literal(value.toString());
if (property instanceof BooleanProperty) {
valueText.withStyle(value == Boolean.TRUE ? ChatFormatting.GREEN : ChatFormatting.RED);
}
- tooltip.addLine(new PairComponent(Component.literal(property.getName()), valueText));
- });
+ var name = property.getName();
+ tooltip.setLine(Options.BLOCK_STATE.withSuffix("." + name), new PairComponent(Component.literal(name), valueText));
+ }
}
}
diff --git a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/ComposterProvider.java b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/ComposterProvider.java
index 1719ec7d1..d2b1f555b 100644
--- a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/ComposterProvider.java
+++ b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/ComposterProvider.java
@@ -18,7 +18,7 @@ public enum ComposterProvider implements IBlockComponentProvider {
public void appendBody(ITooltip tooltip, IBlockAccessor accessor, IPluginConfig config) {
if (config.getBoolean(Options.LEVEL_COMPOSTER)) {
var state = accessor.getBlockState();
- tooltip.addLine(new PairComponent(
+ tooltip.setLine(Options.LEVEL_COMPOSTER, new PairComponent(
Component.translatable(Tl.Tooltip.COMPOST_LEVEL),
Component.literal(state.getValue(ComposterBlock.LEVEL).toString())));
}
diff --git a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/EntityAttributesProvider.java b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/EntityAttributesProvider.java
index 992794a9d..29302dd37 100644
--- a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/EntityAttributesProvider.java
+++ b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/EntityAttributesProvider.java
@@ -66,7 +66,7 @@ public void appendHead(ITooltip tooltip, IEntityAccessor accessor, IPluginConfig
var data = accessor.getData().raw();
if (compact) {
- var line = tooltip.addLine();
+ var line = tooltip.setLine(Options.ENTITY_COMPACT);
var i = 0;
if (showHealth) {
@@ -84,22 +84,24 @@ public void appendHead(ITooltip tooltip, IEntityAccessor accessor, IPluginConfig
var maxPerLine = config.getInt(Options.ENTITY_ICON_PER_LINE);
if (showHealth) {
+ var line = tooltip.setLine(Options.ENTITY_HEALTH);
var absorption = data.contains("abs") ? data.getFloat("abs") : 0f;
if (entity.getMaxHealth() + absorption > config.getInt(Options.ENTITY_LONG_HEALTH_MAX)) {
- addHealth(tooltip.addLine(), entity, data, showAbsorption);
+ addHealth(line, entity, data, showAbsorption);
} else {
- tooltip.addLine(new HealthComponent(entity.getHealth(), entity.getMaxHealth(), maxPerLine, false));
+ line.with(new HealthComponent(entity.getHealth(), entity.getMaxHealth(), maxPerLine, false));
if (showAbsorption && absorption > 0) {
- tooltip.addLine(new HealthComponent(absorption, 0, maxPerLine, true));
+ line.with(new HealthComponent(absorption, 0, maxPerLine, true));
}
}
}
if (showArmor) {
+ var line = tooltip.setLine(Options.ENTITY_ARMOR);
if (entity.getArmorValue() > config.getInt(Options.ENTITY_LONG_ARMOR_MAX)) {
- addArmor(tooltip.addLine(), entity);
+ addArmor(line, entity);
} else {
- tooltip.addLine(new ArmorComponent(entity.getArmorValue(), maxPerLine));
+ line.with(new ArmorComponent(entity.getArmorValue(), maxPerLine));
}
}
}
@@ -108,7 +110,7 @@ public void appendHead(ITooltip tooltip, IEntityAccessor accessor, IPluginConfig
@Override
public void appendBody(ITooltip tooltip, IEntityAccessor accessor, IPluginConfig config) {
if (config.getBoolean(Options.ENTITY_POSITION)) {
- tooltip.addLine(new PositionComponent(accessor.getEntity().position()));
+ tooltip.setLine(Options.ENTITY_POSITION, new PositionComponent(accessor.getEntity().position()));
}
}
diff --git a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/HorseProvider.java b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/HorseProvider.java
index e92be3d46..e2788252a 100644
--- a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/HorseProvider.java
+++ b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/HorseProvider.java
@@ -38,7 +38,7 @@ else if (jumpHeight > 4.0f)
else
format = ChatFormatting.RESET;
- tooltip.addLine(new PairComponent(JUMP_KEY,
+ tooltip.setLine(Options.HORSE_JUMP_HEIGHT, new PairComponent(JUMP_KEY,
Component.translatable(Tl.Tooltip.Horse.Jump.VALUE, FORMAT.format(jumpHeight)).withStyle(format)));
}
@@ -54,7 +54,7 @@ else if (speed > 11.0f)
else
format = ChatFormatting.RESET;
- tooltip.addLine(new PairComponent(SPEED_KEY,
+ tooltip.setLine(Options.HORSE_SPEED, new PairComponent(SPEED_KEY,
Component.translatable(Tl.Tooltip.Horse.Speed.VALUE, FORMAT.format(speed)).withStyle(format)));
}
}
diff --git a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/ItemEntityProvider.java b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/ItemEntityProvider.java
index b71380a0c..b10bfd4e5 100644
--- a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/ItemEntityProvider.java
+++ b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/ItemEntityProvider.java
@@ -15,8 +15,10 @@
import mcp.mobius.waila.plugin.vanilla.config.EnchantmentDisplayMode;
import mcp.mobius.waila.plugin.vanilla.config.Options;
import net.minecraft.core.registries.BuiltInRegistries;
+import net.minecraft.network.chat.CommonComponents;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
+import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.StringUtil;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.item.ItemEntity;
@@ -32,6 +34,9 @@ public enum ItemEntityProvider implements IEntityComponentProvider {
INSTANCE;
+ private static final ResourceLocation AUTHOR = Options.BOOK_WRITTEN.withSuffix(".author");
+ private static final ResourceLocation GENERATION = Options.BOOK_WRITTEN.withSuffix(".generation");
+
private static long lastEnchantmentTime = 0;
private static int enchantmentIndex = 0;
private static int curseIndex = 0;
@@ -107,17 +112,24 @@ public static void appendBookProperties(ITooltip tooltip, ItemStack stack, IPlug
if (curseIndex > (curses.size() - 1)) curseIndex = 0;
}
+ Component text = null;
+
if (!enchantments.isEmpty()) {
var instance = enchantments.get(enchantmentIndex);
- tooltip.addLine(instance.enchantment.getFullname(instance.level));
+ text = instance.enchantment.getFullname(instance.level);
}
if (!curses.isEmpty()) {
var instance = curses.get(curseIndex);
- tooltip.addLine(instance.enchantment.getFullname(instance.level));
+ var curse = instance.enchantment.getFullname(instance.level);
+ if (text == null) text = curse;
+ else text = text.copy().append(CommonComponents.NEW_LINE).append(curse);
}
+
+ if (text != null) tooltip.setLine(Options.BOOK_ENCHANTMENT_DISPLAY_MODE, text);
} else {
var enchantments = EnchantmentHelper.getEnchantments(stack);
+ MutableComponent text = null;
if (mode == EnchantmentDisplayMode.COMBINED) {
MutableComponent enchantmentLine = null;
@@ -143,11 +155,20 @@ public static void appendBookProperties(ITooltip tooltip, ItemStack stack, IPlug
}
}
- if (enchantmentLine != null) tooltip.addLine(enchantmentLine);
- if (curseLine != null) tooltip.addLine(curseLine);
+ if (enchantmentLine != null) text = enchantmentLine;
+ if (curseLine != null) {
+ if (text == null) text = curseLine;
+ else text.append(CommonComponents.NEW_LINE).append(curseLine);
+ }
} else {
- enchantments.forEach((enchantment, level) -> tooltip.addLine(enchantment.getFullname(level)));
+ for (var entry : enchantments.entrySet()) {
+ var name = entry.getKey().getFullname(entry.getValue());
+ if (text == null) text = Component.empty().append(name);
+ else text.append(CommonComponents.NEW_LINE).append(name);
+ }
}
+
+ if (text != null) tooltip.setLine(Options.BOOK_ENCHANTMENT_DISPLAY_MODE, text);
}
} else if (stack.is(Items.WRITTEN_BOOK)) {
if (!config.getBoolean(Options.BOOK_WRITTEN) || !stack.hasTag()) return;
@@ -157,11 +178,10 @@ public static void appendBookProperties(ITooltip tooltip, ItemStack stack, IPlug
var generation = WrittenBookItem.getGeneration(stack);
if (!StringUtil.isNullOrEmpty(author)) {
- tooltip.addLine(Component.translatable("book.byAuthor", author));
+ tooltip.setLine(AUTHOR, Component.translatable("book.byAuthor", author));
}
- tooltip.addLine(Component.translatable("book.generation." + generation));
-
+ tooltip.setLine(GENERATION, Component.translatable("book.generation." + generation));
}
}
diff --git a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/JukeboxProvider.java b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/JukeboxProvider.java
index 60c0321d6..b75fe8bbb 100644
--- a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/JukeboxProvider.java
+++ b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/JukeboxProvider.java
@@ -2,15 +2,10 @@
import mcp.mobius.waila.api.IBlockAccessor;
import mcp.mobius.waila.api.IBlockComponentProvider;
-import mcp.mobius.waila.api.IDataProvider;
-import mcp.mobius.waila.api.IDataWriter;
import mcp.mobius.waila.api.IPluginConfig;
-import mcp.mobius.waila.api.IServerAccessor;
import mcp.mobius.waila.api.ITooltip;
import mcp.mobius.waila.plugin.vanilla.config.Options;
import net.minecraft.network.chat.Component;
-import net.minecraft.world.item.RecordItem;
-import net.minecraft.world.level.block.entity.JukeboxBlockEntity;
public enum JukeboxProvider implements IBlockComponentProvider {
@@ -19,7 +14,7 @@ public enum JukeboxProvider implements IBlockComponentProvider {
@Override
public void appendBody(ITooltip tooltip, IBlockAccessor accessor, IPluginConfig config) {
if (config.getBoolean(Options.JUKEBOX_RECORD) && accessor.getData().raw().contains("record")) {
- tooltip.addLine(Component.Serializer.fromJson(accessor.getData().raw().getString("record")));
+ tooltip.setLine(Options.JUKEBOX_RECORD, Component.Serializer.fromJson(accessor.getData().raw().getString("record")));
}
}
diff --git a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/MobEffectProvider.java b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/MobEffectProvider.java
index 6de559459..80e2d82de 100644
--- a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/MobEffectProvider.java
+++ b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/MobEffectProvider.java
@@ -36,7 +36,7 @@ public void appendBody(ITooltip tooltip, IEntityAccessor accessor, IPluginConfig
if (it.getEffect().getCategory() == MobEffectCategory.HARMFUL) text.withStyle(ChatFormatting.RED);
- tooltip.addLine(text);
+ tooltip.setLine(Options.EFFECT_MOB, text);
});
}
diff --git a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/MobTimerProvider.java b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/MobTimerProvider.java
index d42fd05b6..7d31170a7 100644
--- a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/MobTimerProvider.java
+++ b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/MobTimerProvider.java
@@ -37,7 +37,7 @@ public void appendBody(ITooltip tooltip, IEntityAccessor accessor, IPluginConfig
var seconds = ((-lastAge) / 20) + 1;
var minutes = seconds / 60;
seconds = seconds - (minutes * 60);
- tooltip.addLine(new PairComponent(
+ tooltip.setLine(Options.TIMER_GROW, new PairComponent(
Component.translatable(Tl.Tooltip.Timer.GROW),
Component.literal(TIMER.formatted(minutes, seconds))));
}
@@ -46,7 +46,7 @@ public void appendBody(ITooltip tooltip, IEntityAccessor accessor, IPluginConfig
var seconds = ((lastAge) / 20) + 1;
var minutes = seconds / 60;
seconds = seconds - (minutes * 60);
- tooltip.addLine(new PairComponent(
+ tooltip.setLine(Options.TIMER_BREED, new PairComponent(
Component.translatable(Tl.Tooltip.Timer.BREED),
Component.literal(TIMER.formatted(minutes, seconds))));
}
diff --git a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/NoteBlockProvider.java b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/NoteBlockProvider.java
index bba999745..35fde8518 100644
--- a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/NoteBlockProvider.java
+++ b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/NoteBlockProvider.java
@@ -38,7 +38,7 @@ public void appendBody(ITooltip tooltip, IBlockAccessor accessor, IPluginConfig
if (config.getBoolean(Options.NOTE_BLOCK_TYPE)) {
var state = accessor.getBlockState();
var instrument = state.getValue(NoteBlock.INSTRUMENT);
- var line = tooltip.addLine();
+ var line = tooltip.setLine(Options.NOTE_BLOCK_TYPE);
Component instrumentText;
if (instrument.hasCustomSound()) {
diff --git a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/PandaProvider.java b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/PandaProvider.java
index ce9069ac7..2c24c2d8f 100644
--- a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/PandaProvider.java
+++ b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/PandaProvider.java
@@ -10,12 +10,16 @@
import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
+import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.animal.Panda;
public enum PandaProvider implements IEntityComponentProvider {
INSTANCE;
+ private static final ResourceLocation PERSONALITY = Options.PANDA_GENES.withSuffix(".personality");
+ private static final ResourceLocation TRAITS = Options.PANDA_GENES.withSuffix(".traits");
+
@Override
public void appendBody(ITooltip tooltip, IEntityAccessor accessor, IPluginConfig config) {
if (!config.getBoolean(Options.PANDA_GENES)) return;
@@ -25,10 +29,10 @@ public void appendBody(ITooltip tooltip, IEntityAccessor accessor, IPluginConfig
var mainGene = panda.getMainGene();
var hiddenGene = panda.getHiddenGene();
- tooltip.addLine(new PairComponent(
+ tooltip.setLine(PERSONALITY, new PairComponent(
Component.translatable(Tl.Tooltip.Panda.PERSONALITY),
geneText(personality)));
- tooltip.addLine(new PairComponent(
+ tooltip.setLine(TRAITS, new PairComponent(
Component.translatable(Tl.Tooltip.Panda.TRAITS),
Component.empty().append(geneText(mainGene)).append(", ").append(geneText(hiddenGene))));
}
diff --git a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/PetOwnerProvider.java b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/PetOwnerProvider.java
index 1b937858d..335e89420 100644
--- a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/PetOwnerProvider.java
+++ b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/PetOwnerProvider.java
@@ -55,7 +55,7 @@ public void appendBody(ITooltip tooltip, IEntityAccessor accessor, IPluginConfig
}
if (!(name == UNKNOWN || name == LOADING) || !config.getBoolean(Options.PET_HIDE_UNKNOWN_OWNER)) {
- tooltip.addLine(new PairComponent(KEY, name));
+ tooltip.setLine(Options.PET_OWNER, new PairComponent(KEY, name));
}
}
}
diff --git a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/PlantProvider.java b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/PlantProvider.java
index 56276d0e6..390ba08c2 100644
--- a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/PlantProvider.java
+++ b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/PlantProvider.java
@@ -11,6 +11,7 @@
import mcp.mobius.waila.buildconst.Tl;
import mcp.mobius.waila.plugin.vanilla.config.Options;
import net.minecraft.network.chat.Component;
+import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.CropBlock;
@@ -25,24 +26,25 @@ public enum PlantProvider implements IBlockComponentProvider {
INSTANCE;
private static void addMaturityTooltip(ITooltip tooltip, float growthValue) {
+ var line = tooltip.setLine(Options.PLANT_CROP_PROGRESS);
growthValue *= 100.0F;
if (growthValue < 100.0F) {
- tooltip.addLine(new PairComponent(
+ line.with(new PairComponent(
Component.translatable(Tl.Tooltip.CROP_GROWTH), Component.literal(String.format("%.0f%%", growthValue))));
} else {
- tooltip.addLine(new PairComponent(
+ line.with(new PairComponent(
Component.translatable(Tl.Tooltip.CROP_GROWTH), Component.translatable(Tl.Tooltip.CROP_MATURE)));
}
}
- private static void addGrowableTooltip(ITooltip tooltip, String translationKey, boolean growable) {
- tooltip.addLine(new PairComponent(Component.translatable(translationKey),
+ private static void addGrowableTooltip(ITooltip tooltip, ResourceLocation tag, String translationKey, boolean growable) {
+ tooltip.setLine(tag, new PairComponent(Component.translatable(translationKey),
growable ? Component.translatable(Tl.Tooltip.TRUE) : Component.translatable(Tl.Tooltip.FALSE)));
}
private static void addCropGrowableTooltip(ITooltip tooltip, IBlockAccessor accessor) {
var lightLevel = accessor.getWorld().getRawBrightness(accessor.getPosition(), 0);
- addGrowableTooltip(tooltip, Tl.Tooltip.CROP_GROWABLE, lightLevel >= 9);
+ addGrowableTooltip(tooltip, Options.PLANT_CROP_GROWABLE, Tl.Tooltip.CROP_GROWABLE, lightLevel >= 9);
}
private static void addTreeGrowableTooltip(ITooltip tooltip, IBlockAccessor accessor) {
@@ -53,7 +55,7 @@ private static void addTreeGrowableTooltip(ITooltip tooltip, IBlockAccessor acce
growable = false;
}
- addGrowableTooltip(tooltip, Tl.Tooltip.TREE_GROWABLE, growable);
+ addGrowableTooltip(tooltip, Options.PLANT_TREE_GROWABLE, Tl.Tooltip.TREE_GROWABLE, growable);
}
@Nullable
diff --git a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/PlayerHeadProvider.java b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/PlayerHeadProvider.java
index ea47a5503..168d2c204 100644
--- a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/PlayerHeadProvider.java
+++ b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/PlayerHeadProvider.java
@@ -39,7 +39,7 @@ public void appendBody(ITooltip tooltip, IBlockAccessor accessor, IPluginConfig
if (config.getBoolean(Options.PLAYER_HEAD_NAME)) {
SkullBlockEntity skull = accessor.getBlockEntity();
if (skull != null && skull.getOwnerProfile() != null && !StringUtils.isBlank(skull.getOwnerProfile().getName())) {
- tooltip.addLine(Component.translatable(skull.getOwnerProfile().getName()));
+ tooltip.setLine(Options.PLAYER_HEAD_NAME, Component.translatable(skull.getOwnerProfile().getName()));
}
}
}
diff --git a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/RedstoneProvider.java b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/RedstoneProvider.java
index 4691175da..2a791208a 100644
--- a/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/RedstoneProvider.java
+++ b/src/pluginVanilla/java/mcp/mobius/waila/plugin/vanilla/provider/RedstoneProvider.java
@@ -21,7 +21,7 @@ public enum RedstoneProvider implements IBlockComponentProvider {
public void appendBody(ITooltip tooltip, IBlockAccessor accessor, IPluginConfig config) {
if (config.getBoolean(Options.REDSTONE_LEVER) && accessor.getBlock() instanceof LeverBlock) {
boolean active = accessor.getBlockState().getValue(BlockStateProperties.POWERED);
- tooltip.addLine(new PairComponent(
+ tooltip.setLine(Options.REDSTONE_LEVER, new PairComponent(
Component.translatable(Tl.Tooltip.STATE),
Component.translatable(active ? Tl.Tooltip.STATE_ON : Tl.Tooltip.STATE_OFF)));
return;
@@ -29,7 +29,7 @@ public void appendBody(ITooltip tooltip, IBlockAccessor accessor, IPluginConfig
if (config.getBoolean(Options.REDSTONE_REPEATER) && accessor.getBlock() == Blocks.REPEATER) {
int delay = accessor.getBlockState().getValue(BlockStateProperties.DELAY);
- tooltip.addLine(new PairComponent(
+ tooltip.setLine(Options.REDSTONE_REPEATER, new PairComponent(
Component.translatable(Tl.Tooltip.DELAY),
Component.literal(String.valueOf(delay))));
return;
@@ -37,14 +37,14 @@ public void appendBody(ITooltip tooltip, IBlockAccessor accessor, IPluginConfig
if (config.getBoolean(Options.REDSTONE_COMPARATOR) && accessor.getBlock() == Blocks.COMPARATOR) {
var mode = accessor.getBlockState().getValue(BlockStateProperties.MODE_COMPARATOR);
- tooltip.addLine(new PairComponent(
+ tooltip.setLine(Options.REDSTONE_COMPARATOR, new PairComponent(
Component.translatable(Tl.Tooltip.MODE),
Component.translatable(mode == ComparatorMode.COMPARE ? Tl.Tooltip.MODE_COMPARATOR : Tl.Tooltip.MODE_SUBTRACTOR)));
return;
}
if (config.getBoolean(Options.REDSTONE_LEVEL) && accessor.getBlock() == Blocks.REDSTONE_WIRE) {
- tooltip.addLine(new PairComponent(
+ tooltip.setLine(Options.REDSTONE_LEVEL, new PairComponent(
Component.translatable(Tl.Tooltip.POWER),
Component.literal(accessor.getBlockState().getValue(BlockStateProperties.POWER).toString())));
}