From 2180b0029562bbc33a19a71e805474466ff7a515 Mon Sep 17 00:00:00 2001 From: eggohito <66972816+eggohito@users.noreply.github.com> Date: Fri, 9 Feb 2024 03:04:51 +0800 Subject: [PATCH] Add `should_resolve` field to `modify_label_render` power type --- .../eggolib/power/ModifyLabelRenderPower.java | 30 ++++++++++++++----- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/src/main/java/io/github/eggohito/eggolib/power/ModifyLabelRenderPower.java b/src/main/java/io/github/eggohito/eggolib/power/ModifyLabelRenderPower.java index c791fb6..43a8dff 100644 --- a/src/main/java/io/github/eggohito/eggolib/power/ModifyLabelRenderPower.java +++ b/src/main/java/io/github/eggohito/eggolib/power/ModifyLabelRenderPower.java @@ -41,14 +41,19 @@ public enum RenderMode { private Text replacementText; private Integer initialTicks; - public ModifyLabelRenderPower(PowerType powerType, LivingEntity livingEntity, Consumer beforeParseAction, Consumer afterParseAction, Text text, RenderMode renderMode, int tickRate, int priority) { + private boolean shouldResolve; + + public ModifyLabelRenderPower(PowerType powerType, LivingEntity livingEntity, Consumer beforeParseAction, Consumer afterParseAction, Text text, RenderMode renderMode, boolean shouldResolve, int tickRate, int priority) { super(powerType, livingEntity, priority); this.beforeParseAction = beforeParseAction; this.afterParseAction = afterParseAction; this.text = text; this.renderMode = renderMode; + this.shouldResolve = shouldResolve; this.tickRate = tickRate; - this.setTicking(true); + if (shouldResolve) { + this.setTicking(true); + } } @Override @@ -85,18 +90,25 @@ public void tick() { @Override public NbtElement toTag() { - NbtCompound nbtCompound = new NbtCompound(); - nbtCompound.putString("ReplacementText", Text.Serializer.toJson(replacementText)); + NbtCompound rootNbt = new NbtCompound(); + + rootNbt.putString("ReplacementText", Text.Serializer.toJson(replacementText)); + rootNbt.putBoolean("ShouldResolve", shouldResolve); - return nbtCompound; + return rootNbt; } @Override public void fromTag(NbtElement tag) { - if (tag instanceof NbtCompound nbtCompound) { - replacementText = Text.Serializer.fromJson(nbtCompound.getString("ReplacementText")); + + if (!(tag instanceof NbtCompound rootNbt)) { + return; } + + this.replacementText = Text.Serializer.fromJson(rootNbt.getString("ReplacementText")); + this.shouldResolve = rootNbt.getBoolean("ShouldResolve"); + } public RenderMode getMode() { @@ -104,7 +116,7 @@ public RenderMode getMode() { } public Text getReplacementText() { - return replacementText; + return shouldResolve ? replacementText : text; } private Optional parseText() { @@ -139,6 +151,7 @@ public static PowerFactory getFactory() { .add("after_parse_action", ApoliDataTypes.ENTITY_ACTION, null) .add("text", SerializableDataTypes.TEXT, null) .add("render_mode", SerializableDataType.enumValue(RenderMode.class), RenderMode.DEFAULT) + .add("should_resolve", SerializableDataTypes.BOOLEAN, true) .add("tick_rate", EggolibDataTypes.POSITIVE_INT, 20) .add("priority", SerializableDataTypes.INT, 0), data -> (powerType, livingEntity) -> new ModifyLabelRenderPower( @@ -148,6 +161,7 @@ public static PowerFactory getFactory() { data.get("after_parse_action"), data.get("text"), data.get("render_mode"), + data.get("should_resolve"), data.get("tick_rate"), data.get("priority") )