From 442196709381725abd09596d4283a46e9bf62c86 Mon Sep 17 00:00:00 2001 From: gnembon <41132274+gnembon@users.noreply.github.com> Date: Wed, 9 Aug 2023 00:55:00 +0200 Subject: [PATCH] fixed scoreboard scarpet API --- .../java/carpet/script/api/Scoreboards.java | 34 +++++++++---------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/src/main/java/carpet/script/api/Scoreboards.java b/src/main/java/carpet/script/api/Scoreboards.java index 293e4c24..4efe3af4 100644 --- a/src/main/java/carpet/script/api/Scoreboards.java +++ b/src/main/java/carpet/script/api/Scoreboards.java @@ -29,6 +29,7 @@ import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.BossEvent; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; +import net.minecraft.world.scores.DisplaySlot; import net.minecraft.world.scores.Objective; import net.minecraft.world.scores.PlayerTeam; import net.minecraft.world.scores.Score; @@ -225,32 +226,30 @@ public class Scoreboards } return new FormattedTextValue(objective.getDisplayName()); } - case "display_slot" -> { /* + case "display_slot" -> { if (modify) { - int slotId = Scoreboard.getDisplaySlotByName(setValue.getString()); - if (slotId == -1) + DisplaySlot slot = DisplaySlot.CODEC.byName(setValue.getString()); + if (slot == null) { throw new InternalExpressionException("Unknown scoreboard display slot: " + setValue.getString()); } - if (objective.equals(scoreboard.getDisplayObjective(slotId))) + if (objective.equals(scoreboard.getDisplayObjective(slot))) { return Value.FALSE; } - scoreboard.setDisplayObjective(slotId, objective); + scoreboard.setDisplayObjective(slot, objective); return Value.TRUE; } List slots = new ArrayList<>(); - for (int i = 0; i < 19; i++) + for (DisplaySlot slot : DisplaySlot.values()) { - if (scoreboard.getDisplayObjective(i) == objective) + if (scoreboard.getDisplayObjective(slot) == objective) { - String slotName = Scoreboard.getDisplaySlotName(i); - slots.add(StringValue.of(slotName)); + slots.add(StringValue.of(slot.getSerializedName())); } } - return ListValue.wrap(slots); */ - return Value.NULL; + return ListValue.wrap(slots); } case "render_type" -> { if (modify) @@ -270,12 +269,12 @@ public class Scoreboards }); expression.addContextFunction("scoreboard_display", 2, (c, t, lv) -> - { /* + { CarpetContext cc = (CarpetContext) c; Scoreboard scoreboard = cc.server().getScoreboard(); String location = lv.get(0).getString(); - int slot = Scoreboard.getDisplaySlotByName(location); - if (slot < 0) + DisplaySlot slot = DisplaySlot.CODEC.byName(location); + if (slot == null) { throw new InternalExpressionException("Invalid objective slot: " + location); } @@ -283,17 +282,16 @@ public class Scoreboards if (target.isNull()) { scoreboard.setDisplayObjective(slot, null); - return new NumericValue(slot); + return StringValue.of(slot.getSerializedName()); } String objectiveString = target.getString(); - Objective objective = scoreboard.getOrCreateObjective(objectiveString); + Objective objective = scoreboard.getObjective(objectiveString); if (objective == null) { return Value.NULL; } scoreboard.setDisplayObjective(slot, objective); - return new NumericValue(slot); */ - return Value.NULL; + return StringValue.of(slot.getSerializedName()); }); expression.addContextFunction("team_list", -1, (c, t, lv) ->