Skip to content

Commit

Permalink
Add should_resolve field to modify_label_render power type
Browse files Browse the repository at this point in the history
  • Loading branch information
eggohito committed Feb 13, 2024
1 parent a248227 commit 2180b00
Showing 1 changed file with 22 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,19 @@ public enum RenderMode {
private Text replacementText;
private Integer initialTicks;

public ModifyLabelRenderPower(PowerType<?> powerType, LivingEntity livingEntity, Consumer<Entity> beforeParseAction, Consumer<Entity> afterParseAction, Text text, RenderMode renderMode, int tickRate, int priority) {
private boolean shouldResolve;

public ModifyLabelRenderPower(PowerType<?> powerType, LivingEntity livingEntity, Consumer<Entity> beforeParseAction, Consumer<Entity> 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
Expand Down Expand Up @@ -85,26 +90,33 @@ 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() {
return renderMode;
}

public Text getReplacementText() {
return replacementText;
return shouldResolve ? replacementText : text;
}

private Optional<Text> parseText() {
Expand Down Expand Up @@ -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(
Expand All @@ -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")
)
Expand Down

0 comments on commit 2180b00

Please sign in to comment.