This commit is contained in:
gnembon committed 2023-11-16 20:52:10 +01:00
1 parent 687591c5d5
commit df017bb122
4 files changed
+35 -32

No files matched your search

+2 -2
View File
@@ -3,10 +3,10 @@ org.gradle.jvmargs=-Xmx1G
# Fabric Properties # Fabric Properties
# check https://fabricmc.net/develop/ # check https://fabricmc.net/develop/
minecraft_version=23w45a minecraft_version=23w46a
loader_version=0.14.24 loader_version=0.14.24
jsr305_version=3.0.2 jsr305_version=3.0.2
fabric_version=0.90.8+1.20.3 fabric_version=0.90.9+1.20.3
# Mod Properties # Mod Properties
mod_version = 1.4.125 mod_version = 1.4.125
@@ -27,26 +27,22 @@ import net.minecraft.server.bossevents.CustomBossEvent;
import net.minecraft.server.bossevents.CustomBossEvents; import net.minecraft.server.bossevents.CustomBossEvents;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.BossEvent; 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.DisplaySlot;
import net.minecraft.world.scores.Objective; import net.minecraft.world.scores.Objective;
import net.minecraft.world.scores.PlayerTeam; import net.minecraft.world.scores.PlayerTeam;
import net.minecraft.world.scores.Score; import net.minecraft.world.scores.ScoreAccess;
import net.minecraft.world.scores.ScoreHolder;
import net.minecraft.world.scores.Scoreboard; import net.minecraft.world.scores.Scoreboard;
import net.minecraft.world.scores.Team; import net.minecraft.world.scores.Team;
import net.minecraft.world.scores.criteria.ObjectiveCriteria; import net.minecraft.world.scores.criteria.ObjectiveCriteria;
public class Scoreboards public class Scoreboards
{ {
private static String getScoreboardKeyFromValue(Value keyValue) private static ScoreHolder getScoreboardKeyFromValue(Value keyValue)
{ {
if (keyValue instanceof final EntityValue ev) return keyValue instanceof EntityValue ev
{ ? ev.getEntity()
Entity e = ev.getEntity(); : ScoreHolder.forNameOnly(keyValue.getString());
return e instanceof Player ? e.getName().getString() : e.getStringUUID();
}
return keyValue.getString();
} }
public static void apply(Expression expression) public static void apply(Expression expression)
@@ -69,28 +65,29 @@ public class Scoreboards
} }
if (lv.size() == 1) if (lv.size() == 1)
{ {
return ListValue.wrap(scoreboard.getPlayerScores(objective).stream().map(s -> new StringValue(s.getOwner()))); return ListValue.wrap(scoreboard.listPlayerScores(objective).stream().map(s -> new StringValue(s.owner())));
} }
String key = getScoreboardKeyFromValue(lv.get(1)); ScoreHolder key = getScoreboardKeyFromValue(lv.get(1));
if (lv.size() == 2) if (lv.size() == 2)
{ {
return !scoreboard.hasPlayerScore(key, objective) return scoreboard.getPlayerScoreInfo(key, objective) == null
? Value.NULL ? Value.NULL
: NumericValue.of(scoreboard.getOrCreatePlayerScore(key, objective).getScore()); : NumericValue.of(scoreboard.getOrCreatePlayerScore(key, objective).get());
} }
Value value = lv.get(2); Value value = lv.get(2);
if (value.isNull()) if (value.isNull())
{ {
Score score = scoreboard.getOrCreatePlayerScore(key, objective); int score = scoreboard.getOrCreatePlayerScore(key, objective).get();
scoreboard.resetPlayerScore(key, objective); scoreboard.resetSinglePlayerScore(key, objective);
return NumericValue.of(score.getScore()); return NumericValue.of(score);
} }
if (value instanceof NumericValue) if (value instanceof NumericValue)
{ {
Score score = scoreboard.getOrCreatePlayerScore(key, objective); ScoreAccess score = scoreboard.getOrCreatePlayerScore(key, objective);
score.setScore(NumericValue.asNumber(value).getInt()); int previous = score.get();
return NumericValue.of(score.getScore()); score.set(NumericValue.asNumber(value).getInt());
return NumericValue.of(previous);
} }
throw new InternalExpressionException("'scoreboard' requires a number or null as the third parameter"); throw new InternalExpressionException("'scoreboard' requires a number or null as the third parameter");
}); });
@@ -114,14 +111,14 @@ public class Scoreboards
scoreboard.removeObjective(objective); scoreboard.removeObjective(objective);
return Value.TRUE; return Value.TRUE;
} }
String key = getScoreboardKeyFromValue(lv.get(1)); ScoreHolder key = getScoreboardKeyFromValue(lv.get(1));
if (!scoreboard.hasPlayerScore(key, objective)) if (scoreboard.getPlayerScoreInfo(key, objective) == null)
{ {
return Value.NULL; return Value.NULL;
} }
Score scoreboardPlayerScore = scoreboard.getOrCreatePlayerScore(key, objective); ScoreAccess scoreboardPlayerScore = scoreboard.getOrCreatePlayerScore(key, objective);
Value previous = new NumericValue(scoreboardPlayerScore.getScore()); Value previous = new NumericValue(scoreboardPlayerScore.get());
scoreboard.resetPlayerScore(key, objective); scoreboard.resetSinglePlayerScore(key, objective);
return previous; return previous;
}); });
@@ -170,7 +167,7 @@ public class Scoreboards
scoreboard.onObjectiveAdded(objective); scoreboard.onObjectiveAdded(objective);
return Value.FALSE; return Value.FALSE;
} }
scoreboard.addObjective(objectiveName, criterion, Component.literal(objectiveName), criterion.getDefaultRenderType()); scoreboard.addObjective(objectiveName, criterion, Component.literal(objectiveName), criterion.getDefaultRenderType(), false, null);
return Value.TRUE; return Value.TRUE;
}); });
@@ -106,7 +106,7 @@ import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.storage.loot.LootDataType; import net.minecraft.world.level.storage.loot.LootDataType;
import net.minecraft.world.phys.Vec2; import net.minecraft.world.phys.Vec2;
import net.minecraft.world.scores.Scoreboard; import net.minecraft.world.scores.ScoreHolder;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@@ -778,10 +778,10 @@ public abstract class CommandArgument
@Override @Override
protected Value getValueFromContext(CommandContext<CommandSourceStack> context, String param) throws CommandSyntaxException protected Value getValueFromContext(CommandContext<CommandSourceStack> context, String param) throws CommandSyntaxException
{ {
Collection<String> holders = ScoreHolderArgument.getNames(context, param); Collection<ScoreHolder> holders = ScoreHolderArgument.getNames(context, param);
if (!single) if (!single)
{ {
return ListValue.wrap(holders.stream().map(StringValue::of)); return ListValue.wrap(holders.stream().map(ValueConversions::of));
} }
int size = holders.size(); int size = holders.size();
if (size == 0) if (size == 0)
@@ -790,7 +790,7 @@ public abstract class CommandArgument
} }
if (size == 1) if (size == 1)
{ {
return StringValue.of(holders.iterator().next()); return ValueConversions.of(holders.iterator().next());
} }
throw new SimpleCommandExceptionType(Component.literal("Multiple score holders returned while only one was requested" + " for custom type " + suffix)).create(); throw new SimpleCommandExceptionType(Component.literal("Multiple score holders returned while only one was requested" + " for custom type " + suffix)).create();
} }
@@ -45,6 +45,7 @@ import net.minecraft.world.level.pathfinder.Path;
import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.Vec3;
import net.minecraft.world.scores.Objective; import net.minecraft.world.scores.Objective;
import net.minecraft.world.scores.ScoreHolder;
import net.minecraft.world.scores.criteria.ObjectiveCriteria; import net.minecraft.world.scores.criteria.ObjectiveCriteria;
import java.util.ArrayList; import java.util.ArrayList;
@@ -384,6 +385,11 @@ public class ValueConversions
return MapValue.wrap(ret); return MapValue.wrap(ret);
} }
public static Value of(final ScoreHolder scoreHolder)
{
return FormattedTextValue.of(scoreHolder.getFeedbackDisplayName());
}
public static Value fromProperty(BlockState state, Property<?> p) public static Value fromProperty(BlockState state, Property<?> p)
{ {
Comparable<?> object = state.getValue(p); Comparable<?> object = state.getValue(p);