fixups from errorprone
This commit is contained in:
1 parent
c6d48ab485
commit
e7671bd022
52 files changed
+439
-554
No files matched your search
@@ -49,11 +49,11 @@ public abstract class Explosion_scarpetEventMixin
|
||||
}
|
||||
|
||||
@Inject(method = "explode", locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/ServerExplosion;hurtEntities()V", shift = At.Shift.AFTER))
|
||||
private void onExplosionDone(CallbackInfoReturnable<Integer> cir, List list)
|
||||
private void onExplosionDone(CallbackInfoReturnable<Integer> cir, List toBlow)
|
||||
{
|
||||
if (EXPLOSION_OUTCOME.isNeeded() && !level.isClientSide())
|
||||
{
|
||||
EXPLOSION_OUTCOME.onExplosion((ServerLevel) level, source, this::getIndirectSourceEntity, center, radius, fire, list, affectedEntities, blockInteraction);
|
||||
EXPLOSION_OUTCOME.onExplosion((ServerLevel) level, source, this::getIndirectSourceEntity, center, radius, fire, toBlow, affectedEntities, blockInteraction);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,21 +18,28 @@ public abstract class Inventory_scarpetEventMixin
|
||||
{
|
||||
@Shadow @Final public Player player;
|
||||
|
||||
@Shadow
|
||||
@Final
|
||||
public static int NOT_FOUND_INDEX;
|
||||
|
||||
@Shadow
|
||||
public abstract boolean add(int slot, ItemStack itemStack);
|
||||
|
||||
@Redirect(method = "add(Lnet/minecraft/world/item/ItemStack;)Z", at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Lnet/minecraft/world/entity/player/Inventory;add(ILnet/minecraft/world/item/ItemStack;)Z"
|
||||
))
|
||||
private boolean onItemAcquired(Inventory playerInventory, int slot, ItemStack stack)
|
||||
private boolean onItemAcquired(Inventory playerInventory, int slot, ItemStack itemStack)
|
||||
{
|
||||
if (!PLAYER_PICKS_UP_ITEM.isNeeded() || !(player instanceof ServerPlayer))
|
||||
return playerInventory.add(-1, stack);
|
||||
int count = stack.getCount();
|
||||
ItemStack previous = stack.copy();
|
||||
boolean res = playerInventory.add(-1, stack);
|
||||
if (count != stack.getCount()) // res returns false for larger item adding to a almost full ineventory
|
||||
if (!PLAYER_PICKS_UP_ITEM.isNeeded() || !(player instanceof final ServerPlayer serverPlayer))
|
||||
return add(NOT_FOUND_INDEX, itemStack);
|
||||
int count = itemStack.getCount();
|
||||
ItemStack prevStack = itemStack.copy();
|
||||
boolean res = add(NOT_FOUND_INDEX, itemStack);
|
||||
if (count != itemStack.getCount()) // res returns false for larger item adding to a almost full ineventory
|
||||
{
|
||||
ItemStack diffStack = previous.copyWithCount(count - stack.getCount());
|
||||
PLAYER_PICKS_UP_ITEM.onItemAction((ServerPlayer) player, null, diffStack);
|
||||
ItemStack diffStack = prevStack.copyWithCount(count - itemStack.getCount());
|
||||
PLAYER_PICKS_UP_ITEM.onItemAction(serverPlayer, null, diffStack);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ public class PersistentEntitySectionManager_scarpetMixin
|
||||
}
|
||||
else
|
||||
{
|
||||
CarpetScriptServer.LOG.error("Failed to handle entity type " + entity.getType().getDescriptionId());
|
||||
CarpetScriptServer.LOG.error("Failed to handle entity type {}", entity.getType().getDescriptionId());
|
||||
}
|
||||
|
||||
event = CarpetEventServer.Event.ENTITY_LOAD.get(entity.getType());
|
||||
@@ -43,7 +43,7 @@ public class PersistentEntitySectionManager_scarpetMixin
|
||||
}
|
||||
else
|
||||
{
|
||||
CarpetScriptServer.LOG.error("Failed to handle entity type " + entity.getType().getDescriptionId());
|
||||
CarpetScriptServer.LOG.error("Failed to handle entity type {}", entity.getType().getDescriptionId());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -152,28 +152,29 @@ public class ServerGamePacketListenerImpl_scarpetEventsMixin
|
||||
{
|
||||
if (PLAYER_RELEASED_ITEM.isNeeded())
|
||||
{
|
||||
InteractionHand hand = serverPlayerEntity.getUsedItemHand();
|
||||
ItemStack stack = serverPlayerEntity.getUseItem().copy();
|
||||
serverPlayerEntity.releaseUsingItem();
|
||||
InteractionHand hand = player.getUsedItemHand();
|
||||
ItemStack stack = player.getUseItem().copy();
|
||||
player.releaseUsingItem();
|
||||
PLAYER_RELEASED_ITEM.onItemAction(player, hand, stack);
|
||||
}
|
||||
else
|
||||
{
|
||||
serverPlayerEntity.releaseUsingItem();
|
||||
player.releaseUsingItem();
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "handleUseItemOn", cancellable = true, at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Lnet/minecraft/server/level/ServerPlayerGameMode;useItemOn(Lnet/minecraft/server/level/ServerPlayer;Lnet/minecraft/world/level/Level;Lnet/minecraft/world/item/ItemStack;Lnet/minecraft/world/InteractionHand;Lnet/minecraft/world/phys/BlockHitResult;)Lnet/minecraft/world/InteractionResult;"
|
||||
target = "Lnet/minecraft/server/level/ServerPlayerGameMode;useItemOn(Lnet/minecraft/server/level/ServerPlayer;Lnet/minecraft/world/level/Level;Lnet/minecraft/world/item/ItemStack;Lnet/minecraft/world/InteractionHand;Lnet/minecraft/world/phys/BlockHitResult;)Lnet/minecraft/world/InteractionResult;",
|
||||
shift = At.Shift.BEFORE
|
||||
))
|
||||
private void onBlockInteracted(ServerboundUseItemOnPacket playerInteractBlockC2SPacket_1, CallbackInfo ci)
|
||||
private void onBlockInteracted(ServerboundUseItemOnPacket packet, CallbackInfo ci)
|
||||
{
|
||||
if (PLAYER_RIGHT_CLICKS_BLOCK.isNeeded())
|
||||
{
|
||||
InteractionHand hand = playerInteractBlockC2SPacket_1.hand();
|
||||
BlockHitResult hitRes = playerInteractBlockC2SPacket_1.hitResult();
|
||||
if(PLAYER_RIGHT_CLICKS_BLOCK.onBlockHit(player, hand, hitRes)) {
|
||||
InteractionHand handd = packet.hand();
|
||||
BlockHitResult hitRes = packet.hitResult();
|
||||
if(PLAYER_RIGHT_CLICKS_BLOCK.onBlockHit(player, handd, hitRes)) {
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
@@ -183,11 +184,11 @@ public class ServerGamePacketListenerImpl_scarpetEventsMixin
|
||||
value = "INVOKE",
|
||||
target = "Lnet/minecraft/server/level/ServerPlayer;resetLastActionTime()V"
|
||||
))
|
||||
private void onItemClicked(ServerboundUseItemPacket playerInteractItemC2SPacket_1, CallbackInfo ci)
|
||||
private void onItemClicked(ServerboundUseItemPacket packet, CallbackInfo ci)
|
||||
{
|
||||
if (PLAYER_USES_ITEM.isNeeded())
|
||||
{
|
||||
InteractionHand hand = playerInteractItemC2SPacket_1.hand();
|
||||
InteractionHand hand = packet.hand();
|
||||
if(PLAYER_USES_ITEM.onItemAction(player, hand, player.getItemInHand(hand).copy())) {
|
||||
ci.cancel();
|
||||
}
|
||||
@@ -283,10 +284,10 @@ public class ServerGamePacketListenerImpl_scarpetEventsMixin
|
||||
@Inject(method = "lambda$handleChatCommand$0", // lambda of handleChatCommand(ServerboundChatCommandPacket)
|
||||
at = @At(value = "HEAD")
|
||||
)
|
||||
private void onChatCommandMessage(ServerboundChatCommandPacket serverboundChatCommandPacket, CallbackInfo ci) {
|
||||
private void onChatCommandMessage(ServerboundChatCommandPacket packet, CallbackInfo ci) {
|
||||
if (PLAYER_COMMAND.isNeeded())
|
||||
{
|
||||
PLAYER_COMMAND.onPlayerMessage(player, serverboundChatCommandPacket.command());
|
||||
PLAYER_COMMAND.onPlayerMessage(player, packet.command());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -69,10 +69,10 @@ public abstract class ServerLevel_scarpetMixin extends Level
|
||||
}
|
||||
|
||||
@Inject(method = "explode", at = @At("HEAD"), cancellable = true)
|
||||
private void handleExplosion(Entity entity, DamageSource damageSource, ExplosionDamageCalculator explosionDamageCalculator, double x, double y, double z, float g, boolean bl, ExplosionInteraction explosionInteraction, ParticleOptions particleOptions, ParticleOptions particleOptions2, WeightedList<ExplosionParticleInfo> weightedList, Holder<SoundEvent> holder, CallbackInfo ci)
|
||||
private void handleExplosion(Entity source, DamageSource damageSource, ExplosionDamageCalculator damageCalculator, double x, double y, double z, float r, boolean fire, ExplosionInteraction interactionType, ParticleOptions smallExplosionParticles, ParticleOptions largeExplosionParticles, WeightedList<ExplosionParticleInfo> blockParticles, Holder<SoundEvent> explosionSound, CallbackInfo ci)
|
||||
{
|
||||
if (EXPLOSION.isNeeded()) {
|
||||
Explosion.BlockInteraction var10000 = switch (explosionInteraction) {
|
||||
Explosion.BlockInteraction var10000 = switch (interactionType) {
|
||||
case NONE -> Explosion.BlockInteraction.KEEP;
|
||||
case BLOCK -> this.getCMDestroyType(GameRules.BLOCK_EXPLOSION_DROP_DECAY);
|
||||
case MOB -> this.getGameRules().get(GameRules.MOB_GRIEFING) ? this.getCMDestroyType(GameRules.MOB_EXPLOSION_DROP_DECAY) : Explosion.BlockInteraction.KEEP;
|
||||
@@ -80,7 +80,7 @@ public abstract class ServerLevel_scarpetMixin extends Level
|
||||
case TRIGGER -> Explosion.BlockInteraction.TRIGGER_BLOCK;
|
||||
};
|
||||
|
||||
boolean cancelled = EXPLOSION.onExplosion((ServerLevel) (Object) this, entity, null, new Vec3(x, y, z), g, bl, null, null, var10000);
|
||||
boolean cancelled = EXPLOSION.onExplosion((ServerLevel) (Object) this, source, null, new Vec3(x, y, z), r, fire, null, null, var10000);
|
||||
if (cancelled) ci.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,8 +88,7 @@ public class CarpetEventServer
|
||||
public static class Callback
|
||||
{
|
||||
public final String host;
|
||||
@Nullable
|
||||
public final String optionalTarget;
|
||||
public final @Nullable String optionalTarget;
|
||||
public final FunctionValue function;
|
||||
public final List<Value> parametrizedArgs;
|
||||
public final CarpetScriptServer scriptServer;
|
||||
@@ -382,15 +381,15 @@ public class CarpetEventServer
|
||||
public void removeEventCall(String hostName, String target, String funName)
|
||||
{
|
||||
removeCallsIf((c) -> c.function.getString().equals(funName)
|
||||
&& (Objects.equals(c.host, hostName))
|
||||
&& (Objects.equals(c.optionalTarget, target))
|
||||
&& Objects.equals(c.host, hostName)
|
||||
&& Objects.equals(c.optionalTarget, target)
|
||||
);
|
||||
}
|
||||
|
||||
public void removeAllCalls(CarpetScriptHost host)
|
||||
{
|
||||
removeCallsIf((c) -> (Objects.equals(c.host, host.getName()))
|
||||
&& (Objects.equals(c.optionalTarget, host.user)));
|
||||
removeCallsIf((c) -> Objects.equals(c.host, host.getName())
|
||||
&& Objects.equals(c.optionalTarget, host.user));
|
||||
}
|
||||
|
||||
public void createChildEvents(CarpetScriptHost host)
|
||||
@@ -398,7 +397,7 @@ public class CarpetEventServer
|
||||
List<Callback> copyCalls = new ArrayList<>();
|
||||
callList.forEach((c) ->
|
||||
{
|
||||
if ((Objects.equals(c.host, host.getName())) // TODO fix me
|
||||
if (Objects.equals(c.host, host.getName()) // TODO fix me
|
||||
&& c.optionalTarget == null)
|
||||
{
|
||||
copyCalls.add(new Callback(c.host, host.user, c.function, c.parametrizedArgs, host.scriptServer()));
|
||||
|
||||
@@ -772,61 +772,49 @@ public class CarpetScriptHost extends ScriptHost
|
||||
String sign = "";
|
||||
for (Token tok : Tokenizer.simple(arg).parseTokens())
|
||||
{
|
||||
switch (tok.type)
|
||||
{
|
||||
case VARIABLE:
|
||||
switch (tok.type) {
|
||||
case VARIABLE -> {
|
||||
LazyValue variable = getGlobalVariable(tok.surface);
|
||||
if (variable != null)
|
||||
{
|
||||
if (variable != null) {
|
||||
argv.add(variable);
|
||||
}
|
||||
break;
|
||||
case STRINGPARAM:
|
||||
}
|
||||
case STRINGPARAM -> {
|
||||
argv.add((c, t) -> new StringValue(tok.surface));
|
||||
sign = "";
|
||||
break;
|
||||
|
||||
case LITERAL:
|
||||
try
|
||||
{
|
||||
}
|
||||
case LITERAL -> {
|
||||
try {
|
||||
String finalSign = sign;
|
||||
argv.add((c, t) -> new NumericValue(finalSign + tok.surface));
|
||||
sign = "";
|
||||
}
|
||||
catch (NumberFormatException exception)
|
||||
{
|
||||
} catch (NumberFormatException exception) {
|
||||
throw new CarpetExpressionException("Fail: " + sign + tok.surface + " seems like a number but it is" +
|
||||
" not a number. Use quotes to ensure its a string", null);
|
||||
}
|
||||
break;
|
||||
case HEX_LITERAL:
|
||||
try
|
||||
{
|
||||
}
|
||||
case HEX_LITERAL -> {
|
||||
try {
|
||||
String finalSign = sign;
|
||||
argv.add((c, t) -> new NumericValue(new BigInteger(finalSign + tok.surface.substring(2), 16).doubleValue()));
|
||||
sign = "";
|
||||
}
|
||||
catch (NumberFormatException exception)
|
||||
{
|
||||
} catch (NumberFormatException exception) {
|
||||
throw new CarpetExpressionException("Fail: " + sign + tok.surface + " seems like a number but it is" +
|
||||
" not a number. Use quotes to ensure its a string", null);
|
||||
}
|
||||
break;
|
||||
case OPERATOR, UNARY_OPERATOR:
|
||||
if ((tok.surface.equals("-") || tok.surface.equals("-u")) && sign.isEmpty())
|
||||
{
|
||||
sign = "-";
|
||||
}
|
||||
else
|
||||
{
|
||||
case OPERATOR, UNARY_OPERATOR -> {
|
||||
if ((tok.surface.equals("-") || tok.surface.equals("-u")) && sign.isEmpty()) {
|
||||
sign = "-";
|
||||
} else {
|
||||
throw new CarpetExpressionException("Fail: operators, like " + tok.surface + " are not " +
|
||||
"allowed in invoke", null);
|
||||
}
|
||||
break;
|
||||
case FUNCTION:
|
||||
}
|
||||
case FUNCTION ->
|
||||
throw new CarpetExpressionException("Fail: passing functions like " + tok.surface + "() to invoke is " +
|
||||
"not allowed", null);
|
||||
case OPEN_PAREN, COMMA, CLOSE_PAREN, MARKER:
|
||||
case OPEN_PAREN, COMMA, CLOSE_PAREN, MARKER ->
|
||||
throw new CarpetExpressionException("Fail: " + tok.surface + " is not allowed in invoke", null);
|
||||
}
|
||||
}
|
||||
@@ -1109,7 +1097,7 @@ public class CarpetScriptHost extends ScriptHost
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Creates a {@link Component} using {@link carper.utils.Messenger} that has the locals in the {@code line} snippet with a hover over
|
||||
* <p>Creates a {@link Component} using carpet.utils.Messenger that has the locals in the {@code line} snippet with a hover over
|
||||
* tooltip with the value of the local at that location</p>
|
||||
*
|
||||
* @param line The line to find references to locals on
|
||||
@@ -1189,7 +1177,7 @@ public class CarpetScriptHost extends ScriptHost
|
||||
}
|
||||
else
|
||||
{
|
||||
CarpetScriptServer.LOG.error(intro + ": " + exception.getMessage());
|
||||
CarpetScriptServer.LOG.error("{}", intro, exception);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -83,7 +83,7 @@ public class CarpetScriptServer extends ScriptServer
|
||||
|
||||
/**
|
||||
* Registers a Scarpet App to be used as a Rule App (to be controlled with the value of a Carpet rule).
|
||||
* Libraries should be registered with {@link #registerBuiltInScript(BundledModule)} instead
|
||||
* Libraries should be registered with #registerBuiltInScript(BundledModule) instead
|
||||
*
|
||||
* @param app The {@link Module} of the app.
|
||||
* @see Module#fromJarPath(String, String, boolean)
|
||||
@@ -330,7 +330,7 @@ public class CarpetScriptServer extends ScriptServer
|
||||
}
|
||||
token.run();
|
||||
long end = System.nanoTime();
|
||||
LOG.info("App " + name + " loaded in " + (end - start) / 1000000 + " ms");
|
||||
LOG.info("App {} loaded in {} ms", name, (end - start) / 1000000);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -71,8 +71,7 @@ public class Expression
|
||||
private boolean allowNewlineSubstitutions = true;
|
||||
private boolean allowComments = false;
|
||||
|
||||
@Nullable
|
||||
public Module module = null;
|
||||
public @Nullable Module module = null;
|
||||
|
||||
public String getModuleName()
|
||||
{
|
||||
@@ -93,11 +92,9 @@ public class Expression
|
||||
/**
|
||||
* Cached AST (Abstract Syntax Tree) (root) of the expression
|
||||
*/
|
||||
@Nullable
|
||||
private LazyValue ast = null;
|
||||
private @Nullable LazyValue ast = null;
|
||||
|
||||
@Nullable
|
||||
private ExpressionNode root = null;
|
||||
private @Nullable ExpressionNode root = null;
|
||||
|
||||
/**
|
||||
* script specific operatos and built-in functions
|
||||
@@ -1102,118 +1099,94 @@ public class Expression
|
||||
Token previousToken = null;
|
||||
for (Token token : tokens)
|
||||
{
|
||||
switch (token.type)
|
||||
{
|
||||
case STRINGPARAM:
|
||||
switch (token.type) {
|
||||
case STRINGPARAM,
|
||||
//stack.push(token); // changed that so strings are treated like literals
|
||||
//break;
|
||||
case LITERAL, HEX_LITERAL:
|
||||
LITERAL, HEX_LITERAL -> {
|
||||
if (previousToken != null && (
|
||||
previousToken.type == Token.TokenType.LITERAL ||
|
||||
previousToken.type == Token.TokenType.HEX_LITERAL ||
|
||||
previousToken.type == Token.TokenType.STRINGPARAM))
|
||||
{
|
||||
previousToken.type == Token.TokenType.STRINGPARAM)) {
|
||||
throw new ExpressionException(c, this, token, "Missing operator");
|
||||
}
|
||||
outputQueue.add(token);
|
||||
break;
|
||||
case VARIABLE:
|
||||
outputQueue.add(token);
|
||||
break;
|
||||
case FUNCTION:
|
||||
}
|
||||
case VARIABLE -> outputQueue.add(token);
|
||||
case FUNCTION -> {
|
||||
stack.push(token);
|
||||
lastFunction = token;
|
||||
break;
|
||||
case COMMA:
|
||||
if (previousToken != null && previousToken.type == Token.TokenType.OPERATOR)
|
||||
{
|
||||
}
|
||||
case COMMA -> {
|
||||
if (previousToken != null && previousToken.type == Token.TokenType.OPERATOR) {
|
||||
throw new ExpressionException(c, this, previousToken, "Missing parameter(s) for operator ");
|
||||
}
|
||||
while (!stack.isEmpty() && stack.top().type != Token.TokenType.OPEN_PAREN)
|
||||
{
|
||||
while (!stack.isEmpty() && stack.top().type != Token.TokenType.OPEN_PAREN) {
|
||||
outputQueue.add(stack.pop());
|
||||
}
|
||||
if (stack.isEmpty())
|
||||
{
|
||||
if (lastFunction == null)
|
||||
{
|
||||
if (stack.isEmpty()) {
|
||||
if (lastFunction == null) {
|
||||
throw new ExpressionException(c, this, token, "Unexpected comma");
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
throw new ExpressionException(c, this, lastFunction, "Parse error for function");
|
||||
}
|
||||
}
|
||||
break;
|
||||
case OPERATOR:
|
||||
{
|
||||
}
|
||||
case OPERATOR -> {
|
||||
if (previousToken != null
|
||||
&& (previousToken.type == Token.TokenType.COMMA || previousToken.type == Token.TokenType.OPEN_PAREN))
|
||||
{
|
||||
&& (previousToken.type == Token.TokenType.COMMA || previousToken.type == Token.TokenType.OPEN_PAREN)) {
|
||||
throw new ExpressionException(c, this, token, "Missing parameter(s) for operator '" + token + "'");
|
||||
}
|
||||
ILazyOperator o1 = operators.get(token.surface);
|
||||
if (o1 == null)
|
||||
{
|
||||
if (o1 == null) {
|
||||
throw new ExpressionException(c, this, token, "Unknown operator '" + token + "'");
|
||||
}
|
||||
|
||||
shuntOperators(outputQueue, stack, o1);
|
||||
stack.push(token);
|
||||
break;
|
||||
}
|
||||
case UNARY_OPERATOR:
|
||||
{
|
||||
case UNARY_OPERATOR -> {
|
||||
if (previousToken != null && previousToken.type != Token.TokenType.OPERATOR
|
||||
&& previousToken.type != Token.TokenType.COMMA && previousToken.type != Token.TokenType.OPEN_PAREN)
|
||||
{
|
||||
&& previousToken.type != Token.TokenType.COMMA && previousToken.type != Token.TokenType.OPEN_PAREN) {
|
||||
throw new ExpressionException(c, this, token, "Invalid position for unary operator " + token);
|
||||
}
|
||||
ILazyOperator o1 = operators.get(token.surface);
|
||||
if (o1 == null)
|
||||
{
|
||||
if (o1 == null) {
|
||||
throw new ExpressionException(c, this, token, "Unknown unary operator '" + token.surface.substring(0, token.surface.length() - 1) + "'");
|
||||
}
|
||||
|
||||
shuntOperators(outputQueue, stack, o1);
|
||||
stack.push(token);
|
||||
break;
|
||||
}
|
||||
case OPEN_PAREN:
|
||||
case OPEN_PAREN -> {
|
||||
// removed implicit multiplication in this missing code block
|
||||
if (previousToken != null && previousToken.type == Token.TokenType.FUNCTION)
|
||||
{
|
||||
if (previousToken != null && previousToken.type == Token.TokenType.FUNCTION) {
|
||||
outputQueue.add(token);
|
||||
}
|
||||
stack.push(token);
|
||||
break;
|
||||
case CLOSE_PAREN:
|
||||
if (previousToken != null && previousToken.type == Token.TokenType.OPERATOR)
|
||||
{
|
||||
}
|
||||
case CLOSE_PAREN -> {
|
||||
if (previousToken != null && previousToken.type == Token.TokenType.OPERATOR) {
|
||||
throw new ExpressionException(c, this, previousToken, "Missing parameter(s) for operator " + previousToken);
|
||||
}
|
||||
while (!stack.isEmpty() && stack.top().type != Token.TokenType.OPEN_PAREN)
|
||||
{
|
||||
while (!stack.isEmpty() && stack.top().type != Token.TokenType.OPEN_PAREN) {
|
||||
outputQueue.add(stack.pop());
|
||||
}
|
||||
if (stack.isEmpty())
|
||||
{
|
||||
if (stack.isEmpty()) {
|
||||
throw new ExpressionException(c, this, "Mismatched parentheses");
|
||||
}
|
||||
stack.pop();
|
||||
if (!stack.isEmpty() && stack.top().type == Token.TokenType.FUNCTION)
|
||||
{
|
||||
if (!stack.isEmpty() && stack.top().type == Token.TokenType.FUNCTION) {
|
||||
outputQueue.add(stack.pop());
|
||||
}
|
||||
break;
|
||||
case MARKER:
|
||||
if ("$".equals(token.surface))
|
||||
{
|
||||
}
|
||||
case MARKER -> {
|
||||
if ("$".equals(token.surface)) {
|
||||
StringBuilder sb = new StringBuilder(expression);
|
||||
sb.setCharAt(token.pos, '\n');
|
||||
expression = sb.toString();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (token.type != Token.TokenType.MARKER)
|
||||
{
|
||||
@@ -1437,7 +1410,7 @@ public class Expression
|
||||
}
|
||||
else
|
||||
{
|
||||
ExpressionNode newNode = new ExpressionNode(((c, t) -> getOrSetAnyVariable(c, token.surface).evalValue(c, t)), Collections.emptyList(), token);
|
||||
ExpressionNode newNode = new ExpressionNode((c, t) -> getOrSetAnyVariable(c, token.surface).evalValue(c, t), Collections.emptyList(), token);
|
||||
token.node = newNode;
|
||||
nodeStack.push(newNode);
|
||||
}
|
||||
@@ -1767,7 +1740,7 @@ public class Expression
|
||||
boolean leftOptimizable = operators.get(operator).isLeftAssoc();
|
||||
ExpressionNode optimizedChild = node.args.get(leftOptimizable ? 0 : (node.args.size() - 1));
|
||||
String type = optimizedChild.token.surface;
|
||||
if ((type.equals(operator) || type.equals(function)) && (!(optimizedChild.op instanceof LazyValue.ContextFreeLazyValue)))
|
||||
if ((type.equals(operator) || type.equals(function)) && !(optimizedChild.op instanceof LazyValue.ContextFreeLazyValue))
|
||||
{
|
||||
List<ExpressionNode> newargs = new ArrayList<>();
|
||||
if (leftOptimizable)
|
||||
@@ -1883,9 +1856,9 @@ public class Expression
|
||||
// applying argument unpacking
|
||||
args = AbstractLazyFunction.lazify(AbstractLazyFunction.unpackLazy(args, ctx, requestedType));
|
||||
Value result;
|
||||
if (operation instanceof ILazyFunction)
|
||||
if (operation instanceof final ILazyFunction iLazyFunction)
|
||||
{
|
||||
result = ((ILazyFunction) operation).lazyEval(ctx, expectedType, this, node.token, args).evalValue(null, expectedType);
|
||||
result = iLazyFunction.lazyEval(ctx, expectedType, this, node.token, args).evalValue(null, expectedType);
|
||||
}
|
||||
else if (args.size() == 1)
|
||||
{
|
||||
@@ -1922,38 +1895,31 @@ public class Expression
|
||||
return (c, t) -> ret;
|
||||
}
|
||||
Token token = node.token;
|
||||
switch (token.type)
|
||||
{
|
||||
case UNARY_OPERATOR:
|
||||
{
|
||||
return switch (token.type) {
|
||||
case UNARY_OPERATOR -> {
|
||||
ILazyOperator op = operators.get(token.surface);
|
||||
Context.Type requestedType = op.staticType(expectedType);
|
||||
LazyValue arg = extractOp(ctx, node.args.get(0), requestedType);
|
||||
return (c, t) -> op.lazyEval(c, t, this, token, arg, null).evalValue(c, t);
|
||||
yield (c, t) -> op.lazyEval(c, t, this, token, arg, null).evalValue(c, t);
|
||||
}
|
||||
case OPERATOR:
|
||||
{
|
||||
case OPERATOR -> {
|
||||
ILazyOperator op = operators.get(token.surface);
|
||||
Context.Type requestedType = op.staticType(expectedType);
|
||||
LazyValue arg = extractOp(ctx, node.args.get(0), requestedType);
|
||||
LazyValue arh = extractOp(ctx, node.args.get(1), requestedType);
|
||||
return (c, t) -> op.lazyEval(c, t, this, token, arg, arh).evalValue(c, t);
|
||||
yield (c, t) -> op.lazyEval(c, t, this, token, arg, arh).evalValue(c, t);
|
||||
}
|
||||
case VARIABLE:
|
||||
return (c, t) -> getOrSetAnyVariable(c, token.surface).evalValue(c, t);
|
||||
case FUNCTION:
|
||||
{
|
||||
case VARIABLE -> (c, t) -> getOrSetAnyVariable(c, token.surface).evalValue(c, t);
|
||||
case FUNCTION -> {
|
||||
ILazyFunction f = functions.get(token.surface);
|
||||
Context.Type requestedType = f.staticType(expectedType);
|
||||
List<LazyValue> params = node.args.stream().map(n -> extractOp(ctx, n, requestedType)).collect(Collectors.toList());
|
||||
return (c, t) -> f.lazyEval(c, t, this, token, params).evalValue(c, t);
|
||||
yield (c, t) -> f.lazyEval(c, t, this, token, params).evalValue(c, t);
|
||||
}
|
||||
case CONSTANT:
|
||||
return node.op;
|
||||
default:
|
||||
case CONSTANT -> node.op;
|
||||
default ->
|
||||
throw new ExpressionException(ctx, this, node.token, "Unexpected token '" + node.token.type + " " + node.token.surface + "'");
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void validate(Context c, List<Token> rpn)
|
||||
@@ -1973,27 +1939,23 @@ public class Expression
|
||||
|
||||
for (Token token : rpn)
|
||||
{
|
||||
switch (token.type)
|
||||
{
|
||||
case UNARY_OPERATOR:
|
||||
if (stack.topInt() < 1)
|
||||
{
|
||||
switch (token.type) {
|
||||
case UNARY_OPERATOR -> {
|
||||
if (stack.topInt() < 1) {
|
||||
throw new ExpressionException(c, this, token, "Missing parameter(s) for operator " + token);
|
||||
}
|
||||
break;
|
||||
case OPERATOR:
|
||||
if (stack.topInt() < 2)
|
||||
{
|
||||
if (token.surface.equals(";"))
|
||||
{
|
||||
}
|
||||
case OPERATOR -> {
|
||||
if (stack.topInt() < 2) {
|
||||
if (token.surface.equals(";")) {
|
||||
throw new ExpressionException(c, this, token, "Empty expression found for ';'");
|
||||
}
|
||||
throw new ExpressionException(c, this, token, "Missing parameter(s) for operator " + token);
|
||||
}
|
||||
// pop the operator's 2 parameters and add the result
|
||||
stack.set(stack.size() - 1, stack.topInt() - 2 + 1);
|
||||
break;
|
||||
case FUNCTION:
|
||||
}
|
||||
case FUNCTION -> {
|
||||
//ILazyFunction f = functions.get(token.surface);// don't validate global - userdef functions
|
||||
//int numParams = stack.pop();
|
||||
//if (f != null && !f.numParamsVaries() && numParams != f.getNumParams())
|
||||
@@ -2004,18 +1966,14 @@ public class Expression
|
||||
// due to unpacking, all functions can have variable number of arguments
|
||||
// we will be checking that at runtime.
|
||||
// TODO try analyze arguments and assess if its possible that they are static
|
||||
if (stack.size() <= 0)
|
||||
{
|
||||
if (stack.size() <= 0) {
|
||||
throw new ExpressionException(c, this, token, "Too many function calls, maximum scope exceeded");
|
||||
}
|
||||
// push the result of the function
|
||||
stack.set(stack.size() - 1, stack.topInt() + 1);
|
||||
break;
|
||||
case OPEN_PAREN:
|
||||
stack.push(0);
|
||||
break;
|
||||
default:
|
||||
stack.set(stack.size() - 1, stack.topInt() + 1);
|
||||
}
|
||||
case OPEN_PAREN -> stack.push(0);
|
||||
default -> stack.set(stack.size() - 1, stack.topInt() + 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ public record Module(String name, String code, boolean library)
|
||||
*
|
||||
* @param scriptName A {@link String} being the name of the script. The extension will be autocompleted
|
||||
* @param isLibrary A {@link boolean} indicating whether or not the script is a library
|
||||
* @return The created {@link BundledModule}
|
||||
* @return The created BundledModule
|
||||
*/
|
||||
public static Module carpetNative(String scriptName, boolean isLibrary)
|
||||
{
|
||||
@@ -53,7 +53,7 @@ public record Module(String name, String code, boolean library)
|
||||
* @param path A {@link String} being the path to the directory where the app is located.
|
||||
* @param scriptName A {@link String} being the name of the script. The extension will be autocompleted
|
||||
* @param isLibrary A {@link boolean} indicating whether or not the script is a library
|
||||
* @return The created {@link BundledModule}
|
||||
* @return The created BundledModule
|
||||
* @see #fromJarPathWithCustomName(String, String, boolean)
|
||||
*/
|
||||
public static Module fromJarPath(String path, String scriptName, boolean isLibrary)
|
||||
@@ -90,7 +90,7 @@ public record Module(String name, String code, boolean library)
|
||||
public static Tag getData(Module module, ScriptServer scriptServer)
|
||||
{
|
||||
Path dataFile = resolveResource(module, scriptServer);
|
||||
if (dataFile == null || !Files.exists(dataFile) || !(Files.isRegularFile(dataFile)))
|
||||
if (dataFile == null || !Files.exists(dataFile) || !Files.isRegularFile(dataFile))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ public class ScriptCommand
|
||||
|
||||
static
|
||||
{
|
||||
Set<String> allFunctions = (new CarpetExpression(null, "null", null, null)).getExpr().getFunctionNames();
|
||||
Set<String> allFunctions = new CarpetExpression(null, "null", null, null).getExpr().getFunctionNames();
|
||||
scarpetFunctions = new TreeSet<>(Expression.none.getFunctionNames());
|
||||
APIFunctions = allFunctions.stream().filter(s -> !scarpetFunctions.contains(s)).collect(Collectors.toCollection(TreeSet::new));
|
||||
}
|
||||
@@ -123,7 +123,7 @@ public class ScriptCommand
|
||||
}
|
||||
|
||||
/**
|
||||
* A method to suggest the available scarpet scripts based off of the current player input and {@link AppStoreManager#APP_STORE_ROOT}
|
||||
* A method to suggest the available scarpet scripts based off of the current player input and AppStoreManager#APP_STORE_ROOT
|
||||
* variable.
|
||||
*/
|
||||
private static CompletableFuture<Suggestions> suggestDownloadableApps(
|
||||
|
||||
@@ -48,7 +48,7 @@ public abstract class ScriptHost
|
||||
{
|
||||
randomizers.clear();
|
||||
}
|
||||
return randomizers.computeIfAbsent(aLong, Random::new);
|
||||
return randomizers.computeIfAbsent(aLong, seed -> new Random(seed));
|
||||
}
|
||||
|
||||
public boolean resetRandom(long aLong)
|
||||
@@ -134,8 +134,7 @@ public abstract class ScriptHost
|
||||
return main == null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public final Module main;
|
||||
public final @Nullable Module main;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface ErrorSnooper
|
||||
@@ -234,8 +233,7 @@ public abstract class ScriptHost
|
||||
|
||||
protected abstract void runModuleCode(Context c, Module module); // this should be shell out in the executor
|
||||
|
||||
@Nullable
|
||||
public FunctionValue getFunction(String name)
|
||||
public @Nullable FunctionValue getFunction(String name)
|
||||
{
|
||||
return getFunction(main, name);
|
||||
}
|
||||
@@ -257,8 +255,7 @@ public abstract class ScriptHost
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private FunctionValue getFunction(Module module, String name)
|
||||
private @Nullable FunctionValue getFunction(Module module, String name)
|
||||
{
|
||||
ModuleData local = getModuleData(module);
|
||||
FunctionValue ret = local.globalFunctions.get(name); // most uses would be from local scope anyways
|
||||
@@ -291,8 +288,7 @@ public abstract class ScriptHost
|
||||
return target.globalFunctions.get(name);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private ModuleData findModuleDataFromFunctionImports(String name, ModuleData source, int ttl)
|
||||
private @Nullable ModuleData findModuleDataFromFunctionImports(String name, ModuleData source, int ttl)
|
||||
{
|
||||
if (ttl > 64)
|
||||
{
|
||||
@@ -570,7 +566,7 @@ public abstract class ScriptHost
|
||||
return false;
|
||||
}
|
||||
deprecations.add(feature);
|
||||
DEPRECATION_LOG.warn("App '" + getVisualName() + "' uses '" + feature + "', which is deprecated for removal. Check the docs for a replacement");
|
||||
DEPRECATION_LOG.warn("App '{}' uses '{}', which is deprecated for removal. Check the docs for a replacement", getVisualName(), feature);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -34,15 +34,13 @@ final class ListConverter<T> implements ValueConverter<List<T>>
|
||||
return (allowSingletonCreation ? itemConverter.getTypeName() + " or " : "") + "list of " + itemConverter.getTypeName() + "s";
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public List<T> convert(Value value, @Nullable Context context)
|
||||
public @Nullable List<T> convert(Value value, @Nullable Context context)
|
||||
{
|
||||
return value instanceof ListValue ? convertListValue((ListValue) value, context) : allowSingletonCreation ? convertSingleton(value, context) : null;
|
||||
return value instanceof final ListValue listValue ? convertListValue(listValue, context) : allowSingletonCreation ? convertSingleton(value, context) : null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private List<T> convertListValue(ListValue values, @Nullable Context context)
|
||||
private @Nullable List<T> convertListValue(ListValue values, @Nullable Context context)
|
||||
{
|
||||
List<T> list = new ArrayList<>(values.getItems().size());
|
||||
for (Value value : values)
|
||||
@@ -57,8 +55,7 @@ final class ListConverter<T> implements ValueConverter<List<T>>
|
||||
return list;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private List<T> convertSingleton(Value val, @Nullable Context context)
|
||||
private @Nullable List<T> convertSingleton(Value val, @Nullable Context context)
|
||||
{
|
||||
T converted = itemConverter.convert(val, context);
|
||||
if (converted == null)
|
||||
|
||||
@@ -42,9 +42,9 @@ class MapConverter<K, V> implements ValueConverter<Map<K, V>>
|
||||
public Map<K, V> convert(Value value, @Nullable Context context)
|
||||
{
|
||||
Map<K, V> result = new HashMap<>();
|
||||
if (value instanceof MapValue)
|
||||
if (value instanceof MapValue mapValue)
|
||||
{
|
||||
for (Entry<Value, Value> entry : ((MapValue) value).getMap().entrySet())
|
||||
for (Entry<Value, Value> entry : mapValue.getMap().entrySet())
|
||||
{
|
||||
K key = keyConverter.convert(entry.getKey(), context);
|
||||
V val = valueConverter.convert(entry.getValue(), context);
|
||||
@@ -106,17 +106,14 @@ class MapConverter<K, V> implements ValueConverter<Map<K, V>>
|
||||
return acceptMultiParam;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Map<K, V> convert(Value value, @Nullable Context context) {
|
||||
public @Nullable Map<K, V> convert(Value value, @Nullable Context context) {
|
||||
return value instanceof MapValue ? super.convert(value, context)
|
||||
: value instanceof ListValue ? convertList(((ListValue)value).getItems(), context)
|
||||
: value instanceof final ListValue listValue ? convertList(listValue.getItems(), context)
|
||||
: null; // Multiparam mode can only be used in evalAndConvert
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
private Map<K, V> convertList(List<Value> valueList, @Nullable Context context)
|
||||
private @Nullable Map<K, V> convertList(List<Value> valueList, @Nullable Context context)
|
||||
{
|
||||
if (valueList.size() % 2 == 1)
|
||||
{
|
||||
@@ -137,9 +134,8 @@ class MapConverter<K, V> implements ValueConverter<Map<K, V>>
|
||||
return map;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Map<K, V> checkAndConvert(Iterator<Value> valueIterator, Context context, Context.Type theLazyT)
|
||||
public @Nullable Map<K, V> checkAndConvert(Iterator<Value> valueIterator, Context context, Context.Type theLazyT)
|
||||
{
|
||||
if (!valueIterator.hasNext())
|
||||
{
|
||||
|
||||
@@ -51,9 +51,8 @@ final class OptionalConverter<R> implements ValueConverter<Optional<R>>
|
||||
* @implNote Unlike most other converters, {@link OptionalConverter} will not call this method from
|
||||
* {@link #checkAndConvert(Iterator, Context, Context.Type)} and is only used as a fallback in types that don't support it.
|
||||
*/
|
||||
@Nullable
|
||||
@Override
|
||||
public Optional<R> convert(Value value, @Nullable Context context)
|
||||
public @Nullable Optional<R> convert(Value value, @Nullable Context context)
|
||||
{
|
||||
if (value.isNull())
|
||||
{
|
||||
@@ -67,9 +66,8 @@ final class OptionalConverter<R> implements ValueConverter<Optional<R>>
|
||||
return Optional.of(converted);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Optional<R> checkAndConvert(Iterator<Value> valueIterator, Context context, Context.Type theLazyT)
|
||||
public @Nullable Optional<R> checkAndConvert(Iterator<Value> valueIterator, Context context, Context.Type theLazyT)
|
||||
{
|
||||
if (!valueIterator.hasNext() || valueIterator.next().isNull())
|
||||
{
|
||||
|
||||
@@ -146,9 +146,8 @@ public interface Param
|
||||
*/
|
||||
static final ValueConverter<Context> CONTEXT_PROVIDER = new ValueConverter<>()
|
||||
{
|
||||
@Nullable
|
||||
@Override
|
||||
public String getTypeName()
|
||||
public @Nullable String getTypeName()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@@ -178,9 +177,8 @@ public interface Param
|
||||
*/
|
||||
static final ValueConverter<Context.Type> CONTEXT_TYPE_PROVIDER = new ValueConverter<>()
|
||||
{
|
||||
@Nullable
|
||||
@Override
|
||||
public String getTypeName()
|
||||
public @Nullable String getTypeName()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -106,10 +106,9 @@ public final class SimpleTypeConverter<T extends Value, R> implements ValueConve
|
||||
return (SimpleTypeConverter<Value, R>) byResult.get(outputType);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
@SuppressWarnings("unchecked") // more than checked. not using class.cast because then "method is too big" for inlining, because javac is useless
|
||||
public R convert(Value value, @Nullable Context context) // and adds millions of casts. This one is even removed
|
||||
public @Nullable R convert(Value value, @Nullable Context context) // and adds millions of casts. This one is even removed
|
||||
{
|
||||
return valueClass.isInstance(value) ? converter.apply((T)value, context) : null;
|
||||
}
|
||||
|
||||
@@ -80,10 +80,9 @@ public final class ValueCaster<R> implements ValueConverter<R> // R always exten
|
||||
return (ValueCaster<R>) byResult.get(outputType);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
@SuppressWarnings("unchecked") // more than checked, see SimpleTypeConverter#converter for reasoning
|
||||
public R convert(Value value, @Nullable Context context)
|
||||
public @Nullable R convert(Value value, @Nullable Context context)
|
||||
{
|
||||
if (!outputType.isInstance(value))
|
||||
{
|
||||
|
||||
@@ -77,9 +77,8 @@ public interface ValueConverter<R>
|
||||
* @return A converted value
|
||||
* @deprecated Calling this method instead of {@link #convert(Value, Context)} may not return values for some converters
|
||||
*/
|
||||
@Nullable
|
||||
@Deprecated(forRemoval = true)
|
||||
default R convert(Value value)
|
||||
default @Nullable R convert(Value value)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -211,8 +210,7 @@ public interface ValueConverter<R>
|
||||
* @implNote This method's default implementation runs the {@link #convert(Value, Context)} function in the next {@link Value} ignoring {@link Context} and
|
||||
* {@code theLazyT}.
|
||||
*/
|
||||
@Nullable
|
||||
default R checkAndConvert(Iterator<Value> valueIterator, Context context, Context.Type contextType)
|
||||
default @Nullable R checkAndConvert(Iterator<Value> valueIterator, Context context, Context.Type contextType)
|
||||
{
|
||||
return !valueIterator.hasNext() ? null : convert(valueIterator.next(), context);
|
||||
}
|
||||
|
||||
@@ -207,7 +207,7 @@ public class Auxiliary
|
||||
Vec3 vec = locator.vec;
|
||||
if (player == null)
|
||||
{
|
||||
for (ServerPlayer p : (world.players()))
|
||||
for (ServerPlayer p : world.players())
|
||||
{
|
||||
world.sendParticles(p, particle, true, true, vec.x, vec.y, vec.z, count,
|
||||
spread, spread, spread, speed);
|
||||
@@ -346,7 +346,7 @@ public class Auxiliary
|
||||
}
|
||||
|
||||
ShapeDispatcher.sendShape(
|
||||
(playerTargets.isEmpty()) ? cc.level().players() : playerTargets,
|
||||
playerTargets.isEmpty() ? cc.level().players() : playerTargets,
|
||||
shapes, cc.registryAccess()
|
||||
);
|
||||
return Value.TRUE;
|
||||
@@ -469,8 +469,8 @@ public class Auxiliary
|
||||
{
|
||||
return Value.FALSE;
|
||||
}
|
||||
Tag source = ((NBTSerializableValue) (NBTSerializableValue.fromValue(lv.get(0)))).getTag();
|
||||
Tag match = ((NBTSerializableValue) (NBTSerializableValue.fromValue(lv.get(1)))).getTag();
|
||||
Tag source = ((NBTSerializableValue) NBTSerializableValue.fromValue(lv.get(0))).getTag();
|
||||
Tag match = ((NBTSerializableValue) NBTSerializableValue.fromValue(lv.get(1))).getTag();
|
||||
return BooleanValue.of(NbtUtils.compareNbt(match, source, numParam == 2 || lv.get(2).getBoolean()));
|
||||
});
|
||||
|
||||
@@ -560,38 +560,29 @@ public class Auxiliary
|
||||
});
|
||||
Function<Component, Packet<?>> packetGetter = null;
|
||||
String actionString = lv.get(1).getString().toLowerCase(Locale.ROOT);
|
||||
switch (actionString)
|
||||
{
|
||||
case "title":
|
||||
switch (actionString) {
|
||||
case "title" -> {
|
||||
packetGetter = ClientboundSetTitleTextPacket::new;
|
||||
if (lv.size() < 3)
|
||||
{
|
||||
if (lv.size() < 3) {
|
||||
throw new InternalExpressionException("Third argument of 'display_title' must be present except for 'clear' type");
|
||||
}
|
||||
|
||||
break;
|
||||
case "subtitle":
|
||||
}
|
||||
case "subtitle" -> {
|
||||
packetGetter = ClientboundSetSubtitleTextPacket::new;
|
||||
if (lv.size() < 3)
|
||||
{
|
||||
if (lv.size() < 3) {
|
||||
throw new InternalExpressionException("Third argument of 'display_title' must be present except for 'clear' type");
|
||||
}
|
||||
|
||||
break;
|
||||
case "actionbar":
|
||||
}
|
||||
case "actionbar" -> {
|
||||
packetGetter = ClientboundSetActionBarTextPacket::new;
|
||||
if (lv.size() < 3)
|
||||
{
|
||||
if (lv.size() < 3) {
|
||||
throw new InternalExpressionException("Third argument of 'display_title' must be present except for 'clear' type");
|
||||
}
|
||||
|
||||
break;
|
||||
case "clear":
|
||||
packetGetter = x -> new ClientboundClearTitlesPacket(true); // resetting default fade
|
||||
break;
|
||||
case "player_list_header", "player_list_footer":
|
||||
break;
|
||||
default:
|
||||
}
|
||||
case "clear" -> packetGetter = x -> new ClientboundClearTitlesPacket(true); // resetting default fade
|
||||
case "player_list_header", "player_list_footer" -> {
|
||||
}
|
||||
default ->
|
||||
throw new InternalExpressionException("'display_title' requires 'title', 'subtitle', 'actionbar', 'player_list_header', 'player_list_footer' or 'clear' as second argument");
|
||||
}
|
||||
Component title;
|
||||
@@ -915,7 +906,7 @@ public class Auxiliary
|
||||
if (lv.size() == 1)
|
||||
{
|
||||
res = lv.get(0);
|
||||
CarpetScriptServer.LOG.info(res.getString());
|
||||
CarpetScriptServer.LOG.info("{}", res.getString());
|
||||
}
|
||||
else if (lv.size() == 2)
|
||||
{
|
||||
@@ -923,11 +914,11 @@ public class Auxiliary
|
||||
res = lv.get(1);
|
||||
switch (level)
|
||||
{
|
||||
case "debug" -> CarpetScriptServer.LOG.debug(res.getString());
|
||||
case "warn" -> CarpetScriptServer.LOG.warn(res.getString());
|
||||
case "info" -> CarpetScriptServer.LOG.info(res.getString());
|
||||
case "debug" -> CarpetScriptServer.LOG.debug("{}", res.getString());
|
||||
case "warn" -> CarpetScriptServer.LOG.warn("{}", res.getString());
|
||||
case "info" -> CarpetScriptServer.LOG.info("{}", res.getString());
|
||||
// Somehow issue deprecation
|
||||
case "fatal", "error" -> CarpetScriptServer.LOG.error(res.getString());
|
||||
case "fatal", "error" -> CarpetScriptServer.LOG.error("{}", res.getString());
|
||||
default -> throw new InternalExpressionException("Unknown log level for 'logger': " + level);
|
||||
}
|
||||
}
|
||||
@@ -1386,8 +1377,7 @@ public class Auxiliary
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static <T> Stat<T> getStat(StatType<T> type, Identifier id)
|
||||
private static <T> @Nullable Stat<T> getStat(StatType<T> type, Identifier id)
|
||||
{
|
||||
T key = type.getRegistry().getValue(id);
|
||||
if (key == null || !type.contains(key))
|
||||
|
||||
@@ -365,7 +365,7 @@ public class Inventories
|
||||
amount = (int) NumericValue.asNumber(lv.get(inventoryLocator.offset() + 1)).getLong();
|
||||
}
|
||||
// not enough
|
||||
if (((amount == 1) && (!inventoryLocator.inventory().hasAnyOf(Set.of(searchItem.getItem()))))
|
||||
if (((amount == 1) && !inventoryLocator.inventory().hasAnyOf(Set.of(searchItem.getItem())))
|
||||
|| (inventoryLocator.inventory().countItem(searchItem.getItem()) < amount))
|
||||
{
|
||||
return Value.FALSE;
|
||||
|
||||
@@ -170,7 +170,7 @@ public class Scoreboards
|
||||
}
|
||||
Vanilla.Scoreboard_getObjectivesByCriterion(scoreboard).get(objective.getCriteria()).remove(objective);
|
||||
Vanilla.Objective_setCriterion(objective, criterion);
|
||||
(Vanilla.Scoreboard_getObjectivesByCriterion(scoreboard).computeIfAbsent(criterion, cr -> Lists.newArrayList())).add(objective);
|
||||
Vanilla.Scoreboard_getObjectivesByCriterion(scoreboard).computeIfAbsent(criterion, cr -> Lists.newArrayList()).add(objective);
|
||||
scoreboard.onObjectiveAdded(objective);
|
||||
return Value.FALSE;
|
||||
}
|
||||
@@ -215,7 +215,7 @@ public class Scoreboards
|
||||
}
|
||||
Vanilla.Scoreboard_getObjectivesByCriterion(scoreboard).get(objective.getCriteria()).remove(objective);
|
||||
Vanilla.Objective_setCriterion(objective, criterion);
|
||||
(Vanilla.Scoreboard_getObjectivesByCriterion(scoreboard).computeIfAbsent(criterion, cr -> Lists.newArrayList())).add(objective);
|
||||
Vanilla.Scoreboard_getObjectivesByCriterion(scoreboard).computeIfAbsent(criterion, cr -> Lists.newArrayList()).add(objective);
|
||||
scoreboard.onObjectiveAdded(objective);
|
||||
return Value.TRUE;
|
||||
}
|
||||
@@ -585,7 +585,7 @@ public class Scoreboards
|
||||
case "color" -> {
|
||||
if (propertyValue == null)
|
||||
{
|
||||
BossEvent.BossBarColor color = (bossBar).getColor();
|
||||
BossEvent.BossBarColor color = bossBar.getColor();
|
||||
return color == null ? Value.NULL : StringValue.of(color.getName());
|
||||
}
|
||||
BossEvent.BossBarColor color = ((StringRepresentable.EnumCodec<BossEvent.BossBarColor>)BossEvent.BossBarColor.CODEC).byName(propertyValue.getString());
|
||||
|
||||
@@ -348,7 +348,7 @@ public class WorldAccess
|
||||
{
|
||||
status = PoiManager.Occupancy.HAS_SPACE;
|
||||
}
|
||||
else if (!("any".equals(statusString)))
|
||||
else if (!"any".equals(statusString))
|
||||
{
|
||||
throw new InternalExpressionException(
|
||||
"Incorrect POI occupation status " + status + " use `any`, " + "`occupied` or `available`"
|
||||
@@ -600,7 +600,7 @@ public class WorldAccess
|
||||
});
|
||||
|
||||
expression.addContextFunction("loaded", -1, (c, t, lv) ->
|
||||
BooleanValue.of((((CarpetContext) c).level().hasChunkAt(BlockArgument.findIn((CarpetContext) c, lv, 0).block.getPos()))));
|
||||
BooleanValue.of(((CarpetContext) c).level().hasChunkAt(BlockArgument.findIn((CarpetContext) c, lv, 0).block.getPos())));
|
||||
|
||||
// Deprecated, use loaded_status as more indicative
|
||||
expression.addContextFunction("loaded_ep", -1, (c, t, lv) ->
|
||||
@@ -1085,9 +1085,7 @@ public class WorldAccess
|
||||
ServerExplosion serverExplosion = new ServerExplosion(cc.level(), source, null, null, pos, powah, createFire, mode)
|
||||
{
|
||||
@Override
|
||||
@Nullable
|
||||
public
|
||||
LivingEntity getIndirectSourceEntity()
|
||||
public @Nullable LivingEntity getIndirectSourceEntity()
|
||||
{
|
||||
return theAttacker;
|
||||
}
|
||||
@@ -1481,7 +1479,7 @@ public class WorldAccess
|
||||
}
|
||||
catch (NullPointerException npe)
|
||||
{
|
||||
CarpetScriptServer.LOG.error("Failed to detect structure: " + reg.getKey(str));
|
||||
CarpetScriptServer.LOG.error("Failed to detect structure: {}", reg.getKey(str));
|
||||
start = null;
|
||||
}
|
||||
|
||||
@@ -1491,7 +1489,7 @@ public class WorldAccess
|
||||
}
|
||||
|
||||
Value key = NBTSerializableValue.nameFromRegistryId(reg.getKey(str));
|
||||
ret.put(key, (!needSize) ? Value.NULL : ValueConversions.of(start, cc.registryAccess()));
|
||||
ret.put(key, !needSize ? Value.NULL : ValueConversions.of(start, cc.registryAccess()));
|
||||
}
|
||||
return MapValue.wrap(ret);
|
||||
});
|
||||
@@ -1735,8 +1733,8 @@ public class WorldAccess
|
||||
}
|
||||
|
||||
|
||||
@Nullable static DensitySamplerSet samplersCache = null;
|
||||
@Nullable static ServerLevel samplerLevel = null;
|
||||
private static @Nullable DensitySamplerSet samplersCache = null;
|
||||
private static @Nullable ServerLevel samplerLevel = null;
|
||||
|
||||
public static double sampleNoise(ServerLevel level, String what, BlockPos pos)
|
||||
{
|
||||
|
||||
@@ -19,7 +19,7 @@ import org.jspecify.annotations.Nullable;
|
||||
public class BlockArgument extends Argument
|
||||
{
|
||||
public final BlockValue block;
|
||||
@Nullable public final String replacement;
|
||||
public final @Nullable String replacement;
|
||||
|
||||
private BlockArgument(BlockValue b, int o)
|
||||
{
|
||||
@@ -68,14 +68,14 @@ public class BlockArgument extends Argument
|
||||
{
|
||||
return new BlockArgument(BlockValue.fromString(v1.getString(), c.level()), 1 + offset);
|
||||
}
|
||||
if (v1 instanceof BlockValue)
|
||||
if (v1 instanceof final BlockValue blockValue)
|
||||
{
|
||||
return new BlockArgument(((BlockValue) v1), 1 + offset);
|
||||
return new BlockArgument(blockValue, 1 + offset);
|
||||
}
|
||||
BlockPos pos = c.origin();
|
||||
if (v1 instanceof ListValue)
|
||||
if (v1 instanceof final ListValue listValue)
|
||||
{
|
||||
List<Value> args = ((ListValue) v1).getItems();
|
||||
List<Value> args = listValue.getItems();
|
||||
int xpos = (int) NumericValue.asNumber(args.get(0)).getLong();
|
||||
int ypos = (int) NumericValue.asNumber(args.get(1)).getLong();
|
||||
int zpos = (int) NumericValue.asNumber(args.get(2)).getLong();
|
||||
|
||||
@@ -202,8 +202,7 @@ public class FileArgument
|
||||
return host.resolveScriptFile(suffix);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private Path toPath(@Nullable Module module)
|
||||
private @Nullable Path toPath(@Nullable Module module)
|
||||
{
|
||||
if (!isShared && module == null)
|
||||
{
|
||||
@@ -245,8 +244,7 @@ public class FileArgument
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private Path moduleRootPath(@Nullable Module module)
|
||||
private @Nullable Path moduleRootPath(@Nullable Module module)
|
||||
{
|
||||
return !isShared && module == null
|
||||
? null
|
||||
@@ -294,8 +292,7 @@ public class FileArgument
|
||||
return true;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Stream<Path> listFiles(Module module)
|
||||
public @Nullable Stream<Path> listFiles(Module module)
|
||||
{
|
||||
Path dir = toPath(module);
|
||||
if (dir == null || !Files.exists(dir))
|
||||
@@ -316,8 +313,7 @@ public class FileArgument
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Stream<String> listFolder(Module module)
|
||||
public @Nullable Stream<String> listFolder(Module module)
|
||||
{
|
||||
Stream<String> strings;
|
||||
try (Stream<Path> result = listFiles(module))
|
||||
@@ -407,8 +403,7 @@ public class FileArgument
|
||||
return true;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Tag getNbtData(Module module) // aka getData
|
||||
public @Nullable Tag getNbtData(Module module) // aka getData
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -430,8 +425,7 @@ public class FileArgument
|
||||
|
||||
//copied private method from net.minecraft.nbt.NbtIo.read()
|
||||
// to read non-compound tags - these won't be compressed
|
||||
@Nullable
|
||||
public static Tag readTag(Path path)
|
||||
public static @Nullable Tag readTag(Path path)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -567,8 +561,7 @@ public class FileArgument
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public List<String> listFile(Module module)
|
||||
public @Nullable List<String> listFile(Module module)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -615,8 +608,7 @@ public class FileArgument
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public JsonElement readJsonFile(Module module)
|
||||
public @Nullable JsonElement readJsonFile(Module module)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
@@ -96,9 +96,9 @@ public class FunctionArgument extends Argument
|
||||
throw CommandArgument.error("Function has empty spec");
|
||||
}
|
||||
Value first = params.get(0);
|
||||
if (first instanceof FunctionValue)
|
||||
if (first instanceof final FunctionValue functionValue)
|
||||
{
|
||||
function = (FunctionValue) first;
|
||||
function = functionValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -22,8 +22,7 @@ public class Vector3Argument extends Argument
|
||||
public final double yaw;
|
||||
public final double pitch;
|
||||
public boolean fromBlock = false;
|
||||
@Nullable
|
||||
public Entity entity = null;
|
||||
public @Nullable Entity entity = null;
|
||||
|
||||
private Vector3Argument(Vec3 v, int o)
|
||||
{
|
||||
@@ -68,18 +67,18 @@ public class Vector3Argument extends Argument
|
||||
try
|
||||
{
|
||||
Value v1 = params.next();
|
||||
if (v1 instanceof BlockValue)
|
||||
if (v1 instanceof final BlockValue blockValue)
|
||||
{
|
||||
return (new Vector3Argument(Vec3.atCenterOf(((BlockValue) v1).getPos()), 1 + offset)).fromBlock();
|
||||
return new Vector3Argument(Vec3.atCenterOf(blockValue.getPos()), 1 + offset).fromBlock();
|
||||
}
|
||||
if (optionalEntity && v1 instanceof EntityValue)
|
||||
if (optionalEntity && v1 instanceof final EntityValue entityValue)
|
||||
{
|
||||
Entity e = ((EntityValue) v1).getEntity();
|
||||
Entity e = entityValue.getEntity();
|
||||
return new Vector3Argument(e.position(), 1 + offset).withEntity(e);
|
||||
}
|
||||
if (v1 instanceof ListValue)
|
||||
if (v1 instanceof final ListValue listValue)
|
||||
{
|
||||
List<Value> args = ((ListValue) v1).getItems();
|
||||
List<Value> args = listValue.getItems();
|
||||
Vec3 pos = new Vec3(
|
||||
NumericValue.asNumber(args.get(0)).getDouble(),
|
||||
NumericValue.asNumber(args.get(1)).getDouble(),
|
||||
|
||||
@@ -321,8 +321,7 @@ public abstract class CommandArgument
|
||||
}
|
||||
|
||||
protected String suffix;
|
||||
@Nullable
|
||||
protected Collection<String> examples;
|
||||
protected @Nullable Collection<String> examples;
|
||||
protected boolean needsMatching;
|
||||
protected boolean caseSensitive = true;
|
||||
protected Function<String, SuggestionProvider<CommandSourceStack>> suggestionProvider;
|
||||
@@ -385,11 +384,11 @@ public abstract class CommandArgument
|
||||
throw error("Attempted to provide 'suggest' list while 'suggester' is present" + " for custom type " + suffix);
|
||||
}
|
||||
Value suggestionValue = config.get("suggest");
|
||||
if (!(suggestionValue instanceof ListValue))
|
||||
if (!(suggestionValue instanceof final ListValue listValue))
|
||||
{
|
||||
throw error("Argument suggestions needs to be a list" + " for custom type " + suffix);
|
||||
}
|
||||
examples = ((ListValue) suggestionValue).getItems().stream()
|
||||
examples = listValue.getItems().stream()
|
||||
.map(Value::getString)
|
||||
.collect(Collectors.toSet());
|
||||
if (!examples.isEmpty())
|
||||
@@ -437,11 +436,11 @@ public abstract class CommandArgument
|
||||
args.add(MapValue.wrap(params));
|
||||
args.addAll(customSuggester.args);
|
||||
Value response = host.handleCommand(context.getSource(), customSuggester.function, args);
|
||||
if (!(response instanceof ListValue))
|
||||
if (!(response instanceof final ListValue listValue))
|
||||
{
|
||||
throw error("Custom suggester should return a list of options" + " for custom type " + suffix);
|
||||
}
|
||||
Collection<String> res = ((ListValue) response).getItems().stream().map(Value::getString).collect(Collectors.toList());
|
||||
Collection<String> res = listValue.getItems().stream().map(Value::getString).collect(Collectors.toList());
|
||||
currentSection.run();
|
||||
return res;
|
||||
}
|
||||
@@ -504,12 +503,12 @@ public abstract class CommandArgument
|
||||
if (config.containsKey("options"))
|
||||
{
|
||||
Value optionsValue = config.get("options");
|
||||
if (!(optionsValue instanceof ListValue))
|
||||
if (!(optionsValue instanceof final ListValue listValue))
|
||||
{
|
||||
throw error("Custom string type requires options passed as a list" + " for custom type " + suffix);
|
||||
}
|
||||
validOptions = ((ListValue) optionsValue).getItems().stream()
|
||||
.map(v -> caseSensitive ? v.getString() : (v.getString().toLowerCase(Locale.ROOT)))
|
||||
validOptions = listValue.getItems().stream()
|
||||
.map(v -> caseSensitive ? v.getString() : v.getString().toLowerCase(Locale.ROOT))
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
}
|
||||
@@ -879,11 +878,11 @@ public abstract class CommandArgument
|
||||
if (config.containsKey("options"))
|
||||
{
|
||||
Value optionsValue = config.get("options");
|
||||
if (!(optionsValue instanceof ListValue))
|
||||
if (!(optionsValue instanceof final ListValue listValue))
|
||||
{
|
||||
throw error("Custom sting type requires options passed as a list" + " for custom type " + suffix);
|
||||
}
|
||||
validOptions = ((ListValue) optionsValue).getItems().stream().map(v -> Identifier.parse(v.getString())).collect(Collectors.toSet());
|
||||
validOptions = listValue.getItems().stream().map(v -> Identifier.parse(v.getString())).collect(Collectors.toSet());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1005,6 +1004,7 @@ public abstract class CommandArgument
|
||||
}
|
||||
|
||||
private String restrict;
|
||||
@SuppressWarnings("DoubleBraceInitialization")
|
||||
private static final Map<String, ContainerIds> RESTRICTED_CONTAINERS = new HashMap<>()
|
||||
{{
|
||||
int i;
|
||||
@@ -1293,8 +1293,8 @@ public abstract class CommandArgument
|
||||
protected Supplier<CommandArgument> factory(MinecraftServer server)
|
||||
{
|
||||
return argumentTypeSupplier != null
|
||||
? (() -> new VanillaUnconfigurableArgument(getTypeSuffix(), argumentTypeSupplier, valueExtractor, providesExamples))
|
||||
: (() -> new VanillaUnconfigurableArgument(getTypeSuffix(), argumentTypeSupplierEx, valueExtractor, providesExamples, server));
|
||||
? () -> new VanillaUnconfigurableArgument(getTypeSuffix(), argumentTypeSupplier, valueExtractor, providesExamples)
|
||||
: () -> new VanillaUnconfigurableArgument(getTypeSuffix(), argumentTypeSupplierEx, valueExtractor, providesExamples, server);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,8 +22,7 @@ public class CommandToken implements Comparable<CommandToken>
|
||||
{
|
||||
public final String surface;
|
||||
public final boolean isArgument;
|
||||
@Nullable
|
||||
public final CommandArgument type;
|
||||
public final @Nullable CommandArgument type;
|
||||
|
||||
private CommandToken(String surface, @Nullable CommandArgument type)
|
||||
{
|
||||
@@ -32,8 +31,7 @@ public class CommandToken implements Comparable<CommandToken>
|
||||
isArgument = type != null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static CommandToken getToken(String source, CarpetScriptHost host)
|
||||
public static @Nullable CommandToken getToken(String source, CarpetScriptHost host)
|
||||
{
|
||||
// todo add more type checking and return null
|
||||
if (!source.startsWith("<"))
|
||||
|
||||
@@ -7,8 +7,7 @@ import org.jspecify.annotations.Nullable;
|
||||
/* Exception thrown to terminate execution mid expression (aka return statement) */
|
||||
public class ExitStatement extends StacklessRuntimeException
|
||||
{
|
||||
@Nullable
|
||||
public final Value retval;
|
||||
public final @Nullable Value retval;
|
||||
|
||||
public ExitStatement(@Nullable Value value)
|
||||
{
|
||||
|
||||
@@ -11,8 +11,7 @@ import java.util.Map;
|
||||
public class Throwables
|
||||
{
|
||||
private final String id;
|
||||
@Nullable
|
||||
private final Throwables parent;
|
||||
private final @Nullable Throwables parent;
|
||||
|
||||
private static final Map<String, Throwables> byId = new HashMap<>();
|
||||
|
||||
|
||||
@@ -17,7 +17,10 @@ import com.mojang.brigadier.CommandDispatcher;
|
||||
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.fabricmc.loader.api.ModContainer;
|
||||
import net.minecraft.commands.CommandResultCallback;
|
||||
import net.minecraft.commands.CommandSigningContext;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.arguments.EntityAnchorArgument;
|
||||
import net.minecraft.commands.arguments.blocks.BlockInput;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
@@ -31,6 +34,7 @@ import net.minecraft.server.level.ServerPlayerGameMode;
|
||||
import net.minecraft.server.level.Ticket;
|
||||
import net.minecraft.server.permissions.PermissionSet;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.util.TaskChainer;
|
||||
import net.minecraft.world.Container;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
@@ -64,6 +68,7 @@ import net.minecraft.world.scores.criteria.ObjectiveCriteria;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.OptionalLong;
|
||||
import java.util.function.BooleanSupplier;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
@@ -139,6 +144,10 @@ public class Vanilla
|
||||
return CarpetSettings.runPermissionLevel;
|
||||
}
|
||||
|
||||
public static void CommandSourceStack_setupPrivates(CommandSourceStack css, boolean bl, CommandResultCallback commandResultCallback, EntityAnchorArgument.Anchor anchor, CommandSigningContext commandSigningContext, TaskChainer taskChainer) {
|
||||
((CommandSourceStackInterface) css).setupPrivates(bl, commandResultCallback, anchor, commandSigningContext, taskChainer);
|
||||
};
|
||||
|
||||
public static int [] MinecraftServer_getReleaseTarget(MinecraftServer server)
|
||||
{
|
||||
return CarpetSettings.releaseTarget;
|
||||
|
||||
@@ -58,8 +58,8 @@ public class Arithmetic
|
||||
expression.addMathematicalUnaryFunction("cot", d -> 1.0 / Math.tan(Math.toRadians(d))); // Formula: cot(x) = cos(x) / sin(x) = 1 / tan(x)
|
||||
expression.addMathematicalUnaryFunction("acot", d -> Math.toDegrees(Math.atan(1.0 / d)));// Formula: acot(x) = atan(1/x)
|
||||
expression.addMathematicalUnaryFunction("coth", d -> 1.0 / Math.tanh(d)); // Formula: coth(x) = 1 / tanh(x)
|
||||
expression.addMathematicalUnaryFunction("asinh", d -> Math.log(d + (Math.sqrt(Math.pow(d, 2) + 1)))); // Formula: asinh(x) = ln(x + sqrt(x^2 + 1))
|
||||
expression.addMathematicalUnaryFunction("acosh", d -> Math.log(d + (Math.sqrt(Math.pow(d, 2) - 1)))); // Formula: acosh(x) = ln(x + sqrt(x^2 - 1))
|
||||
expression.addMathematicalUnaryFunction("asinh", d -> Math.log(d + Math.sqrt(Math.pow(d, 2) + 1))); // Formula: asinh(x) = ln(x + sqrt(x^2 + 1))
|
||||
expression.addMathematicalUnaryFunction("acosh", d -> Math.log(d + Math.sqrt(Math.pow(d, 2) - 1))); // Formula: acosh(x) = ln(x + sqrt(x^2 - 1))
|
||||
expression.addMathematicalUnaryFunction("atanh", d -> // Formula: atanh(x) = 0.5*ln((1 + x)/(1 - x))
|
||||
{
|
||||
if (Math.abs(d) > 1 || Math.abs(d) == 1)
|
||||
|
||||
@@ -14,6 +14,7 @@ import carpet.script.value.ListValue;
|
||||
import carpet.script.value.MapValue;
|
||||
import carpet.script.value.NumericValue;
|
||||
import carpet.script.value.Value;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
@@ -23,21 +24,19 @@ import java.util.Map;
|
||||
|
||||
public class Operators
|
||||
{
|
||||
public static final Map<String, Integer> precedence = new HashMap<>()
|
||||
{{
|
||||
put("attribute~:", 80);
|
||||
put("unary+-!...", 60);
|
||||
put("exponent^", 40);
|
||||
put("multiplication*/%", 30);
|
||||
put("addition+-", 20);
|
||||
put("compare>=><=<", 10);
|
||||
put("equal==!=", 7);
|
||||
put("and&&", 5);
|
||||
put("or||", 4);
|
||||
put("assign=<>", 3);
|
||||
put("def->", 2);
|
||||
put("nextop;", 1);
|
||||
}};
|
||||
public static final Map<String, Integer> precedence = ImmutableMap.<String, Integer>builder()
|
||||
.put("attribute~:", 80)
|
||||
.put("unary+-!...", 60)
|
||||
.put("exponent^", 40)
|
||||
.put("multiplication*/%", 30)
|
||||
.put("addition+-", 20)
|
||||
.put("compare>=><=<", 10)
|
||||
.put("equal==!=", 7)
|
||||
.put("and&&", 5)
|
||||
.put("or||", 4)
|
||||
.put("assign=<>", 3)
|
||||
.put("def->", 2)
|
||||
.put("nextop;", 1).build();
|
||||
|
||||
public static void apply(Expression expression)
|
||||
{
|
||||
@@ -149,7 +148,7 @@ public class Operators
|
||||
expression.addLazyBinaryOperator("&&", "and", precedence.get("and&&"), false, true, t -> Context.Type.BOOLEAN, (c, t, lv1, lv2) ->
|
||||
{ // todo check how is optimizations going
|
||||
Value v1 = lv1.evalValue(c, Context.BOOLEAN);
|
||||
return v1.getBoolean() ? lv2 : ((cc, tt) -> v1);
|
||||
return v1.getBoolean() ? lv2 : (cc, tt) -> v1;
|
||||
}, (c, t, lv) -> {
|
||||
int last = lv.size() - 1;
|
||||
if (last == -1)
|
||||
@@ -184,7 +183,7 @@ public class Operators
|
||||
expression.addLazyBinaryOperator("||", "or", precedence.get("or||"), false, true, t -> Context.Type.BOOLEAN, (c, t, lv1, lv2) ->
|
||||
{
|
||||
Value v1 = lv1.evalValue(c, Context.BOOLEAN);
|
||||
return v1.getBoolean() ? ((cc, tt) -> v1) : lv2;
|
||||
return v1.getBoolean() ? (cc, tt) -> v1 : lv2;
|
||||
}, (c, t, lv) -> {
|
||||
int last = lv.size() - 1;
|
||||
if (last == -1)
|
||||
@@ -379,7 +378,7 @@ public class Operators
|
||||
return (cc, tt) -> Value.NULL;
|
||||
}
|
||||
Value address = lcv.address();
|
||||
if (!(container.put(address, v2)))
|
||||
if (!container.put(address, v2))
|
||||
{
|
||||
return (cc, tt) -> Value.NULL;
|
||||
}
|
||||
|
||||
@@ -493,7 +493,7 @@ public class Sys
|
||||
c.host.scriptServer().systemGlobals.computeIfAbsent(key, k -> lv.get(1).evalValue(c));
|
||||
}
|
||||
Value res = c.host.scriptServer().systemGlobals.get(key);
|
||||
return res == null ? LazyValue.NULL : ((cc, tt) -> res);
|
||||
return res == null ? LazyValue.NULL : (cc, tt) -> res;
|
||||
});
|
||||
|
||||
expression.addContextFunction("system_variable_set", 2, (c, t, lv) ->
|
||||
|
||||
@@ -41,7 +41,7 @@ public class Threading
|
||||
|
||||
|
||||
expression.addContextFunction("task_count", -1, (c, t, lv) ->
|
||||
(!lv.isEmpty()) ? new NumericValue(c.host.taskCount(lv.get(0))) : new NumericValue(c.host.taskCount()));
|
||||
!lv.isEmpty() ? new NumericValue(c.host.taskCount(lv.get(0))) : new NumericValue(c.host.taskCount()));
|
||||
|
||||
expression.addUnaryFunction("task_value", v ->
|
||||
{
|
||||
@@ -174,7 +174,7 @@ public class Threading
|
||||
throw new InternalExpressionException("'task_await' requires a coroutine task value");
|
||||
}
|
||||
Value ret = thread.next();
|
||||
return ret == Value.EOL ? ((cc, tt) -> Value.NULL) : ((cc, tt) -> ret);
|
||||
return ret == Value.EOL ? (cc, tt) -> Value.NULL : (cc, tt) -> ret;
|
||||
});
|
||||
|
||||
expression.addLazyFunction("task_ready", 1, (c, t, lv) ->
|
||||
|
||||
@@ -71,8 +71,7 @@ public class AppStoreManager
|
||||
public static class StoreNode
|
||||
{
|
||||
public String name;
|
||||
@Nullable
|
||||
public StoreNode parent;
|
||||
public @Nullable StoreNode parent;
|
||||
public Map<String, StoreNode> children;
|
||||
public boolean sealed;
|
||||
public String value;
|
||||
@@ -406,7 +405,7 @@ public class AppStoreManager
|
||||
{
|
||||
throw new InternalExpressionException("Unable to write resource " + target);
|
||||
}
|
||||
CarpetScriptServer.LOG.info("Downloaded resource " + target + " from " + contentUrl);
|
||||
CarpetScriptServer.LOG.info("Downloaded resource {} from {}", target, contentUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -417,8 +416,7 @@ public class AppStoreManager
|
||||
* @param contentUrl The full content URL, from {@link #getFullContentUrl(String, StoreNode, CommandSourceStack)}
|
||||
* @return A {@link StoreNode} that can be used in an app that came from the provided source
|
||||
*/
|
||||
@Nullable
|
||||
private static StoreNode getNewStoreNode(CommandSourceStack commandSource, StoreNode originalSource, String sourceString, String contentUrl)
|
||||
private static @Nullable StoreNode getNewStoreNode(CommandSourceStack commandSource, StoreNode originalSource, String sourceString, String contentUrl)
|
||||
{
|
||||
StoreNode next = originalSource;
|
||||
if (sourceString == contentUrl) // External URL (check getFullUrlContent)
|
||||
@@ -471,7 +469,7 @@ public class AppStoreManager
|
||||
{
|
||||
throw new InternalExpressionException("Error when installing app dependencies: " + e);
|
||||
}
|
||||
CarpetScriptServer.LOG.info("Downloaded app " + target + " from " + contentUrl);
|
||||
CarpetScriptServer.LOG.info("Downloaded app {} from {}", target, contentUrl);
|
||||
}
|
||||
|
||||
public static class CommandRuntimeException extends RuntimeException {
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.joml.Vector3fc;
|
||||
|
||||
public class BiomeInfo
|
||||
{
|
||||
@SuppressWarnings("DoubleBraceInitialization")
|
||||
public static final Map<String, BiFunction<ServerLevel, Biome, Value>> biomeFeatures = new HashMap<>()
|
||||
{{
|
||||
put("tags", (w, b) -> ListValue.wrap(w.registryAccess().lookupOrThrow(Registries.BIOME).getTags().filter(p -> p.stream().anyMatch(h -> h.value() == b)).map(ValueConversions::of)));
|
||||
|
||||
@@ -88,8 +88,7 @@ import org.jspecify.annotations.Nullable;
|
||||
|
||||
public class FeatureGenerator
|
||||
{
|
||||
@Nullable
|
||||
public static synchronized Boolean plop(String featureName, ServerLevel world, BlockPos pos)
|
||||
public static synchronized @Nullable Boolean plop(String featureName, ServerLevel world, BlockPos pos)
|
||||
{
|
||||
Function<ServerLevel, Thing> custom = featureMap.get(featureName);
|
||||
if (custom != null)
|
||||
@@ -147,8 +146,7 @@ public class FeatureGenerator
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Structure resolveConfiguredStructure(String name, ServerLevel world, BlockPos pos)
|
||||
public static @Nullable Structure resolveConfiguredStructure(String name, ServerLevel world, BlockPos pos)
|
||||
{
|
||||
Identifier id = Identifier.parse(name);
|
||||
Structure configuredStructureFeature = world.registryAccess().lookupOrThrow(Registries.STRUCTURE).getValue(id);
|
||||
@@ -365,8 +363,7 @@ public class FeatureGenerator
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@SuppressWarnings("DoubleBraceInitialization")
|
||||
public static final Map<String, Function<ServerLevel, Thing>> featureMap = new HashMap<>()
|
||||
{{
|
||||
|
||||
@@ -551,7 +548,7 @@ public class FeatureGenerator
|
||||
}
|
||||
catch (Exception booboo)
|
||||
{
|
||||
CarpetScriptServer.LOG.error("Unknown Exception while plopping structure: " + booboo, booboo);
|
||||
CarpetScriptServer.LOG.error("Unknown Exception while plopping structure: {}", booboo, booboo);
|
||||
return false;
|
||||
}
|
||||
finally
|
||||
|
||||
@@ -50,8 +50,7 @@ public class GlocalFlag extends ThreadLocal<Boolean>
|
||||
return result;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public <T> T runIfEnabled(Supplier<T> action)
|
||||
public <T> @Nullable T runIfEnabled(Supplier<T> action)
|
||||
{
|
||||
synchronized (this)
|
||||
{
|
||||
|
||||
@@ -26,8 +26,7 @@ public class ParticleParser
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static ParticleOptions getEffect(@Nullable String name, RegistryAccess lookup)
|
||||
public static @Nullable ParticleOptions getEffect(@Nullable String name, RegistryAccess lookup)
|
||||
{
|
||||
if (name == null)
|
||||
{
|
||||
|
||||
@@ -21,6 +21,7 @@ import carpet.script.value.StringValue;
|
||||
import carpet.script.value.Value;
|
||||
import carpet.script.value.ValueConversions;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Sets;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
@@ -236,8 +237,7 @@ public class ShapeDispatcher
|
||||
}
|
||||
|
||||
// client
|
||||
@Nullable
|
||||
public static ExpiringShape fromTag(CompoundTag tag, Level level)
|
||||
public static @Nullable ExpiringShape fromTag(CompoundTag tag, Level level)
|
||||
{
|
||||
Map<String, Value> options = new HashMap<>();
|
||||
for (String key : tag.keySet())
|
||||
@@ -245,7 +245,7 @@ public class ShapeDispatcher
|
||||
Param decoder = Param.of.get(key);
|
||||
if (decoder == null)
|
||||
{
|
||||
CarpetScriptServer.LOG.info("Unknown parameter for shape: " + key);
|
||||
CarpetScriptServer.LOG.info("Unknown parameter for shape: {}", key);
|
||||
return null;
|
||||
}
|
||||
Value decodedValue = decoder.decode(tag.get(key), level);
|
||||
@@ -254,13 +254,13 @@ public class ShapeDispatcher
|
||||
Value shapeValue = options.get("shape");
|
||||
if (shapeValue == null)
|
||||
{
|
||||
CarpetScriptServer.LOG.info("Shape id missing in " + String.join(", ", tag.keySet()));
|
||||
CarpetScriptServer.LOG.info("Shape id missing in {}", String.join(", ", tag.keySet()));
|
||||
return null;
|
||||
}
|
||||
BiFunction<Map<String, Value>, RegistryAccess, ExpiringShape> factory = ExpiringShape.shapeProviders.get(shapeValue.getString());
|
||||
if (factory == null)
|
||||
{
|
||||
CarpetScriptServer.LOG.info("Unknown shape: " + shapeValue.getString());
|
||||
CarpetScriptServer.LOG.info("Unknown shape: {}", shapeValue.getString());
|
||||
return null;
|
||||
}
|
||||
try
|
||||
@@ -269,24 +269,23 @@ public class ShapeDispatcher
|
||||
}
|
||||
catch (InternalExpressionException exc)
|
||||
{
|
||||
CarpetScriptServer.LOG.info(exc.getMessage());
|
||||
CarpetScriptServer.LOG.info("", exc);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public abstract static class ExpiringShape
|
||||
{
|
||||
public static final Map<String, BiFunction<Map<String, Value>, RegistryAccess, ExpiringShape>> shapeProviders = new HashMap<>()
|
||||
{{
|
||||
put("line", creator(Line::new));
|
||||
put("box", creator(Box::new));
|
||||
put("sphere", creator(Sphere::new));
|
||||
put("cylinder", creator(Cylinder::new));
|
||||
put("label", creator(DisplayedText::new));
|
||||
put("polygon", creator(Polyface::new));
|
||||
put("block", creator(() -> new DisplayedSprite(false)));
|
||||
put("item", creator(() -> new DisplayedSprite(true)));
|
||||
}};
|
||||
public static final ImmutableMap<String, BiFunction<Map<String, Value>, RegistryAccess, ExpiringShape>> shapeProviders = ImmutableMap.<String, BiFunction<Map<String, Value>, RegistryAccess, ExpiringShape>>builder().
|
||||
put("line", creator(Line::new)).
|
||||
put("box", creator(Box::new)).
|
||||
put("sphere", creator(Sphere::new)).
|
||||
put("cylinder", creator(Cylinder::new)).
|
||||
put("label", creator(DisplayedText::new)).
|
||||
put("polygon", creator(Polyface::new)).
|
||||
put("block", creator(() -> new DisplayedSprite(false))).
|
||||
put("item", creator(() -> new DisplayedSprite(true))).
|
||||
build();
|
||||
|
||||
private static BiFunction<Map<String, Value>, RegistryAccess, ExpiringShape> creator(Supplier<ExpiringShape> shapeFactory)
|
||||
{
|
||||
@@ -978,78 +977,65 @@ public class ShapeDispatcher
|
||||
return alterPoint;
|
||||
}
|
||||
alterPoint = new ArrayList<>();
|
||||
switch (mode)
|
||||
{
|
||||
case 4:
|
||||
for (int i = 0; i < vertexList.size(); i++)
|
||||
{
|
||||
switch (mode) {
|
||||
case 4 -> {
|
||||
for (int i = 0; i < vertexList.size(); i++) {
|
||||
Vec3 vecA = vertexList.get(i);
|
||||
if (relative.get(i))
|
||||
{
|
||||
if (relative.get(i)) {
|
||||
vecA = relativiseRender(p.level(), vecA, 0);
|
||||
}
|
||||
i++;
|
||||
Vec3 vecB = vertexList.get(i);
|
||||
if (relative.get(i))
|
||||
{
|
||||
if (relative.get(i)) {
|
||||
vecB = relativiseRender(p.level(), vecB, 0);
|
||||
}
|
||||
i++;
|
||||
Vec3 vecC = vertexList.get(i);
|
||||
if (relative.get(i))
|
||||
{
|
||||
if (relative.get(i)) {
|
||||
vecC = relativiseRender(p.level(), vecC, 0);
|
||||
}
|
||||
alterDrawTriangles(vecA, vecB, vecC);
|
||||
}
|
||||
break;
|
||||
case 6:
|
||||
}
|
||||
case 6 -> {
|
||||
Vec3 vec0 = vertexList.get(0);
|
||||
if (relative.get(0))
|
||||
{
|
||||
if (relative.get(0)) {
|
||||
vec0 = relativiseRender(p.level(), vec0, 0);
|
||||
}
|
||||
Vec3 vec1 = vertexList.get(1);
|
||||
if (relative.get(1))
|
||||
{
|
||||
if (relative.get(1)) {
|
||||
vec1 = relativiseRender(p.level(), vec1, 0);
|
||||
}
|
||||
for (int i = 2; i < vertexList.size(); i++)
|
||||
{
|
||||
for (int i = 2; i < vertexList.size(); i++) {
|
||||
Vec3 vec = vertexList.get(i);
|
||||
if (relative.get(i))
|
||||
{
|
||||
if (relative.get(i)) {
|
||||
vec = relativiseRender(p.level(), vec, 0);
|
||||
}
|
||||
alterDrawTriangles(vec0, vec1, vec);
|
||||
vec1 = vec;
|
||||
}
|
||||
break;
|
||||
case 5:
|
||||
}
|
||||
case 5 -> {
|
||||
Vec3 vecA = vertexList.get(0);
|
||||
if (relative.get(0))
|
||||
{
|
||||
if (relative.get(0)) {
|
||||
vecA = relativiseRender(p.level(), vecA, 0);
|
||||
}
|
||||
Vec3 vecB = vertexList.get(1);
|
||||
if (relative.get(1))
|
||||
{
|
||||
if (relative.get(1)) {
|
||||
vecB = relativiseRender(p.level(), vecB, 0);
|
||||
}
|
||||
for (int i = 2; i < vertexList.size(); i++)
|
||||
{
|
||||
for (int i = 2; i < vertexList.size(); i++) {
|
||||
Vec3 vec = vertexList.get(i);
|
||||
if (relative.get(i))
|
||||
{
|
||||
if (relative.get(i)) {
|
||||
vec = relativiseRender(p.level(), vec, 0);
|
||||
}
|
||||
alterDrawTriangles(vecA, vecB, vec);
|
||||
vecA = vecB;
|
||||
vecB = vec;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
default -> {
|
||||
}
|
||||
}
|
||||
|
||||
return alterPoint;
|
||||
@@ -1466,17 +1452,16 @@ public class ShapeDispatcher
|
||||
|
||||
public abstract static class Param
|
||||
{
|
||||
public static final Map<String, Param> of = new HashMap<>()
|
||||
{{
|
||||
put("mode", new StringChoiceParam("mode", "polygon", "strip", "triangles"));
|
||||
put("relative", new OptionalBoolListParam("relative"));
|
||||
put("inner", new BoolParam("inner"));
|
||||
put("shape", new ShapeParam());
|
||||
put("dim", new DimensionParam());
|
||||
put("duration", new NonNegativeIntParam("duration"));
|
||||
put("color", new ColorParam("color"));
|
||||
put("follow", new EntityParam("follow"));
|
||||
put("variant", new StringChoiceParam("variant",
|
||||
public static final ImmutableMap<String, Param> of = ImmutableMap.<String, Param>builder()
|
||||
.put("mode", new StringChoiceParam("mode", "polygon", "strip", "triangles"))
|
||||
.put("relative", new OptionalBoolListParam("relative"))
|
||||
.put("inner", new BoolParam("inner"))
|
||||
.put("shape", new ShapeParam())
|
||||
.put("dim", new DimensionParam())
|
||||
.put("duration", new NonNegativeIntParam("duration"))
|
||||
.put("color", new ColorParam("color"))
|
||||
.put("follow", new EntityParam("follow"))
|
||||
.put("variant", new StringChoiceParam("variant",
|
||||
"NONE",
|
||||
"THIRD_PERSON_LEFT_HAND",
|
||||
"THIRD_PERSON_RIGHT_HAND",
|
||||
@@ -1493,25 +1478,24 @@ public class ShapeDispatcher
|
||||
{
|
||||
return super.validate(o, s, new StringValue(v.getString().toUpperCase(Locale.ROOT)));
|
||||
}
|
||||
});
|
||||
put("snap", new StringChoiceParam("snap",
|
||||
})
|
||||
.put("snap", new StringChoiceParam("snap",
|
||||
"xyz", "xz", "yz", "xy", "x", "y", "z",
|
||||
"dxdydz", "dxdz", "dydz", "dxdy", "dx", "dy", "dz",
|
||||
"xdz", "dxz", "ydz", "dyz", "xdy", "dxy",
|
||||
"xydz", "xdyz", "xdydz", "dxyz", "dxydz", "dxdyz"
|
||||
));
|
||||
put("line", new PositiveFloatParam("line"));
|
||||
put("fill", new ColorParam("fill"));
|
||||
|
||||
put("from", new Vec3Param("from", false));
|
||||
put("to", new Vec3Param("to", true));
|
||||
put("center", new Vec3Param("center", false));
|
||||
put("pos", new Vec3Param("pos", false));
|
||||
put("radius", new PositiveFloatParam("radius"));
|
||||
put("level", new PositiveIntParam("level"));
|
||||
put("height", new FloatParam("height"));
|
||||
put("width", new FloatParam("width"));
|
||||
put("scale", new Vec3Param("scale", false)
|
||||
))
|
||||
.put("line", new PositiveFloatParam("line"))
|
||||
.put("fill", new ColorParam("fill"))
|
||||
.put("from", new Vec3Param("from", false))
|
||||
.put("to", new Vec3Param("to", true))
|
||||
.put("center", new Vec3Param("center", false))
|
||||
.put("pos", new Vec3Param("pos", false))
|
||||
.put("radius", new PositiveFloatParam("radius"))
|
||||
.put("level", new PositiveIntParam("level"))
|
||||
.put("height", new FloatParam("height"))
|
||||
.put("width", new FloatParam("width"))
|
||||
.put("scale", new Vec3Param("scale", false)
|
||||
{
|
||||
@Override
|
||||
public Value validate(java.util.Map<String, Value> options, MinecraftServer server, Value value)
|
||||
@@ -1522,29 +1506,27 @@ public class ShapeDispatcher
|
||||
}
|
||||
return super.validate(options, server, value);
|
||||
}
|
||||
})
|
||||
.put("axis", new StringChoiceParam("axis", "x", "y", "z"))
|
||||
.put("points", new PointsParam("points"))
|
||||
.put("text", new FormattedTextParam("text"))
|
||||
.put("value", new FormattedTextParam("value"))
|
||||
.put("size", new PositiveIntParam("size"))
|
||||
.put("align", new StringChoiceParam("align", "center", "left", "right"))
|
||||
.put("block", new BlockParam("block"))
|
||||
.put("item", new ItemParam("item"))
|
||||
.put("blocklight", new NonNegativeIntParam("blocklight"))
|
||||
.put("skylight", new NonNegativeIntParam("skylight"))
|
||||
.put("indent", new FloatParam("indent"))
|
||||
.put("raise", new FloatParam("raise"))
|
||||
.put("tilt", new FloatParam("tilt"))
|
||||
.put("lean", new FloatParam("lean"))
|
||||
.put("turn", new FloatParam("turn"))
|
||||
.put("facing", new StringChoiceParam("facing", "player", "camera", "north", "south", "east", "west", "up", "down"))
|
||||
.put("doublesided", new BoolParam("doublesided"))
|
||||
.put("debug", new BoolParam("debug"))
|
||||
.build();
|
||||
|
||||
});
|
||||
put("axis", new StringChoiceParam("axis", "x", "y", "z"));
|
||||
put("points", new PointsParam("points"));
|
||||
put("text", new FormattedTextParam("text"));
|
||||
put("value", new FormattedTextParam("value"));
|
||||
put("size", new PositiveIntParam("size"));
|
||||
put("align", new StringChoiceParam("align", "center", "left", "right"));
|
||||
|
||||
put("block", new BlockParam("block"));
|
||||
put("item", new ItemParam("item"));
|
||||
put("blocklight", new NonNegativeIntParam("blocklight"));
|
||||
put("skylight", new NonNegativeIntParam("skylight"));
|
||||
put("indent", new FloatParam("indent"));
|
||||
put("raise", new FloatParam("raise"));
|
||||
put("tilt", new FloatParam("tilt"));
|
||||
put("lean", new FloatParam("lean"));
|
||||
put("turn", new FloatParam("turn"));
|
||||
put("facing", new StringChoiceParam("facing", "player", "camera", "north", "south", "east", "west", "up", "down"));
|
||||
put("doublesided", new BoolParam("doublesided"));
|
||||
put("debug", new BoolParam("debug"));
|
||||
|
||||
}};
|
||||
protected String id;
|
||||
|
||||
protected Param(String id)
|
||||
@@ -1552,8 +1534,7 @@ public class ShapeDispatcher
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public abstract Tag toTag(Value value, final RegistryAccess regs); //validates value, returning null if not necessary to keep it and serialize
|
||||
public abstract @Nullable Tag toTag(Value value, final RegistryAccess regs); //validates value, returning null if not necessary to keep it and serialize
|
||||
|
||||
public abstract Value validate(Map<String, Value> options, MinecraftServer server, Value value); // makes sure the value is proper
|
||||
|
||||
@@ -1640,9 +1621,8 @@ public class ShapeDispatcher
|
||||
return BlockValue.fromString(value.getString(), server.overworld());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Tag toTag(Value value, final RegistryAccess regs)
|
||||
public @Nullable Tag toTag(Value value, final RegistryAccess regs)
|
||||
{
|
||||
if (value instanceof final BlockValue blv)
|
||||
{
|
||||
@@ -1758,9 +1738,8 @@ public class ShapeDispatcher
|
||||
this.options = Sets.newHashSet(options);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Value validate(Map<String, Value> options, MinecraftServer server, Value value)
|
||||
public @Nullable Value validate(Map<String, Value> options, MinecraftServer server, Value value)
|
||||
{
|
||||
if (this.options.contains(value.getString()))
|
||||
{
|
||||
@@ -2046,7 +2025,7 @@ public class ShapeDispatcher
|
||||
new NumericValue(e.getZ())
|
||||
);
|
||||
}
|
||||
CarpetScriptServer.LOG.error("Value: " + value.getString());
|
||||
CarpetScriptServer.LOG.error("Value: {}", value.getString());
|
||||
throw new InternalExpressionException("'" + p.id + "' requires a triple, block or entity to indicate position");
|
||||
}
|
||||
|
||||
@@ -2206,7 +2185,7 @@ public class ShapeDispatcher
|
||||
{
|
||||
ServerLevel world = player.level();
|
||||
world.sendParticles(player, particle, true, true,
|
||||
(towards.x) / 2 + from.x, (towards.y) / 2 + from.y, (towards.z) / 2 + from.z, particles / 3,
|
||||
towards.x / 2 + from.x, towards.y / 2 + from.y, towards.z / 2 + from.z, particles / 3,
|
||||
towards.x / 6, towards.y / 6, towards.z / 6, 0.0);
|
||||
world.sendParticles(player, particle, true, true,
|
||||
from.x, from.y, from.z, 1, 0.0, 0.0, 0.0, 0.0);
|
||||
@@ -2223,10 +2202,10 @@ public class ShapeDispatcher
|
||||
{
|
||||
ServerLevel world = player.level();
|
||||
world.sendParticles(player, particle, true, true,
|
||||
(towards.x) / center + from.x, (towards.y) / center + from.y, (towards.z) / center + from.z, particles / divider,
|
||||
towards.x / center + from.x, towards.y / center + from.y, towards.z / center + from.z, particles / divider,
|
||||
towards.x / dev, towards.y / dev, towards.z / dev, 0.0);
|
||||
world.sendParticles(player, particle, true, true,
|
||||
(towards.x) * (1.0 - 1.0 / center) + from.x, (towards.y) * (1.0 - 1.0 / center) + from.y, (towards.z) * (1.0 - 1.0 / center) + from.z, particles / divider,
|
||||
towards.x * (1.0 - 1.0 / center) + from.x, towards.y * (1.0 - 1.0 / center) + from.y, towards.z * (1.0 - 1.0 / center) + from.z, particles / divider,
|
||||
towards.x / dev, towards.y / dev, towards.z / dev, 0.0);
|
||||
}
|
||||
parts += 2 * particles / divider;
|
||||
|
||||
@@ -4,6 +4,7 @@ import carpet.script.CarpetScriptServer;
|
||||
import carpet.script.external.Carpet;
|
||||
import carpet.script.utils.shapes.ShapeDirection;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.mojang.blaze3d.pipeline.RenderTarget;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
@@ -63,18 +64,16 @@ public class ShapesRenderer
|
||||
private final Map<ResourceKey<Level>, Long2ObjectOpenHashMap<RenderedShape<? extends ShapeDispatcher.ExpiringShape>>> labels;
|
||||
private final Minecraft client;
|
||||
|
||||
private final Map<String, BiFunction<Minecraft, ShapeDispatcher.ExpiringShape, RenderedShape<? extends ShapeDispatcher.ExpiringShape>>> renderedShapes
|
||||
= new HashMap<>()
|
||||
{{
|
||||
put("line", RenderedLine::new);
|
||||
put("box", RenderedBox::new);
|
||||
put("sphere", RenderedSphere::new);
|
||||
put("cylinder", RenderedCylinder::new);
|
||||
put("label", RenderedText::new);
|
||||
put("polygon", RenderedPolyface::new);
|
||||
put("block", (c, s) -> new RenderedSprite(c, s, false));
|
||||
put("item", (c, s) -> new RenderedSprite(c, s, true));
|
||||
}};
|
||||
private final Map<String, BiFunction<Minecraft, ShapeDispatcher.ExpiringShape, RenderedShape<? extends ShapeDispatcher.ExpiringShape>>> renderedShapes = ImmutableMap.<String, BiFunction<Minecraft, ShapeDispatcher.ExpiringShape, RenderedShape<? extends ShapeDispatcher.ExpiringShape>>>builder()
|
||||
.put("line", RenderedLine::new)
|
||||
.put("box", RenderedBox::new)
|
||||
.put("sphere", RenderedSphere::new)
|
||||
.put("cylinder", RenderedCylinder::new)
|
||||
.put("label", RenderedText::new)
|
||||
.put("polygon", RenderedPolyface::new)
|
||||
.put("block", (c, s) -> new RenderedSprite(c, s, false))
|
||||
.put("item", (c, s) -> new RenderedSprite(c, s, true))
|
||||
.build();
|
||||
|
||||
public static void rotatePoseStackByShapeDirection(PoseStack poseStack, ShapeDirection shapeDirection, Camera camera, Vec3 objectPos)
|
||||
{
|
||||
@@ -93,8 +92,8 @@ public class ShapesRenderer
|
||||
double y = vector.y;
|
||||
double z = vector.z;
|
||||
double d = Math.sqrt(x * x + z * z);
|
||||
float rotX = (float) (Math.atan2(x, z));
|
||||
float rotY = (float) (Math.atan2(y, d));
|
||||
float rotX = (float) Math.atan2(x, z);
|
||||
float rotY = (float) Math.atan2(y, d);
|
||||
|
||||
// that should work somehow but it doesn't for some reason
|
||||
//matrices.mulPose(new Quaternion( -rotY, rotX, 0, false));
|
||||
@@ -239,7 +238,7 @@ public class ShapesRenderer
|
||||
shapeFactory = renderedShapes.get(tag.getString("shape").orElseThrow());
|
||||
if (shapeFactory == null)
|
||||
{
|
||||
CarpetScriptServer.LOG.info("Unrecognized shape: " + tag.getString("shape"));
|
||||
CarpetScriptServer.LOG.info("Unrecognized shape: {}", tag.getString("shape"));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -564,11 +563,11 @@ public class ShapesRenderer
|
||||
float text_x = 0;
|
||||
if (shape.align == 0)
|
||||
{
|
||||
text_x = (float) (-textRenderer.width(shape.value.getString())) / 2.0F;
|
||||
text_x = (float) -textRenderer.width(shape.value.getString()) / 2.0F;
|
||||
}
|
||||
else if (shape.align == 1)
|
||||
{
|
||||
text_x = (float) (-textRenderer.width(shape.value.getString()));
|
||||
text_x = (float) -textRenderer.width(shape.value.getString());
|
||||
}
|
||||
//try (ByteBufferBuilder bbb = new ByteBufferBuilder(RenderType.TRANSIENT_BUFFER_SIZE))
|
||||
//{
|
||||
@@ -620,7 +619,7 @@ public class ShapesRenderer
|
||||
}
|
||||
catch (ClassCastException ignored)
|
||||
{
|
||||
CarpetScriptServer.LOG.error("shape " + rshape.shape.getClass() + " cannot cast to a Label");
|
||||
CarpetScriptServer.LOG.error("shape {} cannot cast to a Label", rshape.shape.getClass());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -893,7 +892,7 @@ public class ShapesRenderer
|
||||
}
|
||||
Vec3 vc = shape.relativiseRender(client.level, shape.center, partialTick);
|
||||
drawSphereWireframe(primitives,
|
||||
(float) (vc.x), (float) (vc.y), (float) (vc.z),
|
||||
(float) vc.x, (float) vc.y, (float) vc.z,
|
||||
(float) (shape.radius + renderEpsilon), shape.subdivisions,
|
||||
shape.argb, shape.lineWidth);
|
||||
}
|
||||
@@ -907,7 +906,7 @@ public class ShapesRenderer
|
||||
}
|
||||
Vec3 vc = shape.relativiseRender(client.level, shape.center, partialTick);
|
||||
drawSphereFaces(primitives,
|
||||
(float) (vc.x ), (float) (vc.y ), (float) (vc.z ),
|
||||
(float) vc.x, (float) vc.y, (float) vc.z,
|
||||
(float) (shape.radius + renderEpsilon), shape.subdivisions,
|
||||
shape.fargb);
|
||||
}
|
||||
@@ -1358,8 +1357,8 @@ public class ShapesRenderer
|
||||
|
||||
private static int shuffleColor(int argb) {
|
||||
int a = 0xff000000 & argb;
|
||||
argb = (new Random(argb)).nextInt();
|
||||
argb = (a) | (0x00ffffff & argb);
|
||||
argb = new Random(argb).nextInt();
|
||||
argb = a | (0x00ffffff & argb);
|
||||
return argb;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package carpet.script.utils;
|
||||
|
||||
import carpet.fakes.CommandSourceStackInterface;
|
||||
import carpet.script.external.Vanilla;
|
||||
import net.minecraft.commands.CommandResultCallback;
|
||||
import net.minecraft.commands.CommandSigningContext;
|
||||
@@ -65,18 +64,18 @@ public class SnoopyCommandSource extends CommandSourceStack
|
||||
this.chatOutput = chatOutput;
|
||||
this.signingContext = original.getSigningContext();
|
||||
this.taskChainer = TaskChainer.immediate(original.getServer());
|
||||
((CommandSourceStackInterface) this).setupPrivates(false, (b, i) -> returnValue[0] = OptionalLong.of(i), EntityAnchorArgument.Anchor.FEET, CommandSigningContext.ANONYMOUS, TaskChainer.immediate(original.getServer()));
|
||||
Vanilla.CommandSourceStack_setupPrivates(this, false, (b, i) -> returnValue[0] = OptionalLong.of(i), EntityAnchorArgument.Anchor.FEET, CommandSigningContext.ANONYMOUS, TaskChainer.immediate(original.getServer()));
|
||||
}
|
||||
|
||||
public SnoopyCommandSource(ServerPlayer player, Component[] error, List<Component> output, int [] result)
|
||||
{
|
||||
super(player.commandSource(), player.position(), player.getRotationVector(),
|
||||
player.level() instanceof final ServerLevel serverLevel ? serverLevel : null,
|
||||
player.level(),
|
||||
player.level().getServer().getProfilePermissions(player.nameAndId()),
|
||||
player.level().getServer(), player);
|
||||
this.output = player.commandSource();
|
||||
this.position = player.position();
|
||||
this.world = player.level() instanceof final ServerLevel serverLevel ? serverLevel : null;
|
||||
this.world = player.level();
|
||||
this.level = player.level().getServer().getProfilePermissions(player.nameAndId());
|
||||
this.namesProvider = NamesProvider.FOR_ENTITY;
|
||||
this.server = player.level().getServer();
|
||||
@@ -88,7 +87,7 @@ public class SnoopyCommandSource extends CommandSourceStack
|
||||
this.chatOutput = output;
|
||||
this.signingContext = CommandSigningContext.ANONYMOUS;
|
||||
this.taskChainer = TaskChainer.immediate(player.level().getServer());
|
||||
((CommandSourceStackInterface) this).setupPrivates(false, (b, i) -> result[0] = i, EntityAnchorArgument.Anchor.FEET, CommandSigningContext.ANONYMOUS, TaskChainer.immediate(player.level().getServer()));
|
||||
Vanilla.CommandSourceStack_setupPrivates(this, false, (b, i) -> result[0] = i, EntityAnchorArgument.Anchor.FEET, CommandSigningContext.ANONYMOUS, TaskChainer.immediate(player.level().getServer()));
|
||||
}
|
||||
|
||||
private SnoopyCommandSource(CommandSource output, Vec3 pos, Vec2 rot, ServerLevel world, PermissionSet level, CommandSourceStack.NamesProvider namesProvider, MinecraftServer server, @Nullable Entity entity, CommandResultCallback consumer, EntityAnchorArgument.Anchor entityAnchor, CommandSigningContext context, TaskChainer chainer,
|
||||
@@ -113,7 +112,7 @@ public class SnoopyCommandSource extends CommandSourceStack
|
||||
this.chatOutput = chatOutput;
|
||||
this.signingContext = context;
|
||||
this.taskChainer = chainer;
|
||||
((CommandSourceStackInterface) this).setupPrivates(false, consumer, entityAnchor, context, chainer);
|
||||
Vanilla.CommandSourceStack_setupPrivates(this, false, consumer, entityAnchor, context, chainer);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -191,7 +190,7 @@ public class SnoopyCommandSource extends CommandSourceStack
|
||||
double e = position.y - vec3d.y;
|
||||
double f = position.z - vec3d.z;
|
||||
double g = Math.sqrt(d * d + f * f);
|
||||
float h = Mth.wrapDegrees((float) (-(Mth.atan2(e, g) * 57.2957763671875D)));
|
||||
float h = Mth.wrapDegrees((float) -(Mth.atan2(e, g) * 57.2957763671875D));
|
||||
float i = Mth.wrapDegrees((float) (Mth.atan2(f, d) * 57.2957763671875D) - 90.0F);
|
||||
return this.withRotation(new Vec2(h, i));
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ import java.util.function.Function;
|
||||
|
||||
public class SystemInfo
|
||||
{
|
||||
@SuppressWarnings("DoubleBraceInitialization")
|
||||
private static final Map<String, Function<CarpetContext, Value>> options = new HashMap<>()
|
||||
{{
|
||||
put("app_name", c ->
|
||||
@@ -43,7 +44,7 @@ public class SystemInfo
|
||||
return name == null ? Value.NULL : new StringValue(name);
|
||||
});
|
||||
put("app_list", c -> ListValue.wrap(((CarpetScriptHost) c.host).scriptServer().modules.keySet().stream().filter(Objects::nonNull).map(StringValue::new)));
|
||||
put("app_scope", c -> StringValue.of((c.host).isPerUser() ? "player" : "global"));
|
||||
put("app_scope", c -> StringValue.of(c.host.isPerUser() ? "player" : "global"));
|
||||
put("app_players", c -> ListValue.wrap(c.host.getUserList().stream().map(StringValue::new)));
|
||||
|
||||
put("world_name", c -> new StringValue(c.server().getWorldData().getLevelName()));
|
||||
@@ -133,7 +134,7 @@ public class SystemInfo
|
||||
long[] tickArray = c.server().getTickTimesNanos();
|
||||
for (int i = currentReportedTick + 100; i > currentReportedTick; i--)
|
||||
{
|
||||
ticks.add(new NumericValue((tickArray[i % 100]) / 1000000.0));
|
||||
ticks.add(new NumericValue(tickArray[i % 100] / 1000000.0));
|
||||
}
|
||||
return ListValue.wrap(ticks);
|
||||
});
|
||||
|
||||
@@ -14,8 +14,7 @@ public enum ShapeDirection
|
||||
CAMERA,
|
||||
PLAYER;
|
||||
|
||||
@Nullable
|
||||
public static ShapeDirection fromString(String direction)
|
||||
public static @Nullable ShapeDirection fromString(String direction)
|
||||
{
|
||||
return switch (direction.toLowerCase(Locale.ROOT))
|
||||
{
|
||||
|
||||
@@ -298,6 +298,7 @@ public class EntityValue extends Value
|
||||
return ListValue.wrap(types.stream().map(et -> nameFromRegistryId(entityRegs.getKey(et))));
|
||||
}
|
||||
|
||||
@SuppressWarnings("DoubleBraceInitialization")
|
||||
public static final Map<String, EntityClassDescriptor> byName = new HashMap<>()
|
||||
{{
|
||||
List<EntityType<?>> allTypes = BuiltInRegistries.ENTITY_TYPE.stream().toList();
|
||||
@@ -409,7 +410,7 @@ public class EntityValue extends Value
|
||||
|
||||
public Value get(String what, @Nullable Value arg)
|
||||
{
|
||||
if (!(featureAccessors.containsKey(what)))
|
||||
if (!featureAccessors.containsKey(what))
|
||||
{
|
||||
throw new InternalExpressionException("Unknown entity feature: " + what);
|
||||
}
|
||||
@@ -432,6 +433,7 @@ public class EntityValue extends Value
|
||||
"feet", EquipmentSlot.FEET
|
||||
);
|
||||
|
||||
@SuppressWarnings("DoubleBraceInitialization")
|
||||
private static final Map<String, BiFunction<Entity, Value, Value>> featureAccessors = new HashMap<String, BiFunction<Entity, Value, Value>>()
|
||||
{{
|
||||
//put("test", (e, a) -> a == null ? Value.NULL : new StringValue(a.getString()));
|
||||
@@ -834,16 +836,11 @@ public class EntityValue extends Value
|
||||
{
|
||||
return ValueConversions.of(hitres.getLocation());
|
||||
}
|
||||
switch (hitres.getType())
|
||||
{
|
||||
case MISS:
|
||||
return Value.NULL;
|
||||
case BLOCK:
|
||||
return new BlockValue((ServerLevel) e.level(), ((BlockHitResult) hitres).getBlockPos());
|
||||
case ENTITY:
|
||||
return new EntityValue(((EntityHitResult) hitres).getEntity());
|
||||
}
|
||||
return Value.NULL;
|
||||
return switch (hitres.getType()) {
|
||||
case MISS -> Value.NULL;
|
||||
case BLOCK -> new BlockValue((ServerLevel) e.level(), ((BlockHitResult) hitres).getBlockPos());
|
||||
case ENTITY -> new EntityValue(((EntityHitResult) hitres).getEntity());
|
||||
};
|
||||
});
|
||||
|
||||
put("attribute", (e, a) -> {
|
||||
@@ -888,7 +885,7 @@ public class EntityValue extends Value
|
||||
|
||||
public void set(String what, @Nullable Value toWhat)
|
||||
{
|
||||
if (!(featureModifiers.containsKey(what)))
|
||||
if (!featureModifiers.containsKey(what))
|
||||
{
|
||||
throw new InternalExpressionException("Unknown entity action: " + what);
|
||||
}
|
||||
@@ -947,10 +944,11 @@ public class EntityValue extends Value
|
||||
e.syncVelocity = true;
|
||||
if (Math.abs(scale) > 10000)
|
||||
{
|
||||
CarpetScriptServer.LOG.warn("Moved entity " + e.getScoreboardName() + " " + e.getName() + " at " + e.position() + " extremely fast: " + e.getDeltaMovement());
|
||||
CarpetScriptServer.LOG.warn("Moved entity {} {} at {} extremely fast: {}", e.getScoreboardName(), e.getName(), e.position(), e.getDeltaMovement());
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("DoubleBraceInitialization")
|
||||
private static final Map<String, BiConsumer<Entity, Value>> featureModifiers = new HashMap<String, BiConsumer<Entity, Value>>()
|
||||
{{
|
||||
put("remove", (entity, value) -> entity.discard()); // using discard here - will see other options if valid
|
||||
@@ -1547,8 +1545,8 @@ public class EntityValue extends Value
|
||||
{
|
||||
return;
|
||||
}
|
||||
GameType toSet = v instanceof NumericValue ?
|
||||
GameType.byId(((NumericValue) v).getInt()) :
|
||||
GameType toSet = v instanceof final NumericValue numericValue ?
|
||||
GameType.byId(numericValue.getInt()) :
|
||||
GameType.byName(v.getString().toLowerCase(Locale.ROOT), null);
|
||||
if (toSet != null)
|
||||
{
|
||||
|
||||
@@ -434,9 +434,9 @@ public class ListValue extends AbstractListValue implements ContainerValueInterf
|
||||
{
|
||||
if (ind.isNull())
|
||||
{
|
||||
if (extend && value instanceof AbstractListValue)
|
||||
if (extend && value instanceof final AbstractListValue abstractListValue)
|
||||
{
|
||||
((AbstractListValue) value).iterator().forEachRemaining(items::add);
|
||||
abstractListValue.iterator().forEachRemaining(items::add);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -446,11 +446,11 @@ public class ListValue extends AbstractListValue implements ContainerValueInterf
|
||||
else
|
||||
{
|
||||
int numitems = items.size();
|
||||
if (!(ind instanceof NumericValue))
|
||||
if (!(ind instanceof final NumericValue numericValue))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
int index = (int) ((NumericValue) ind).getLong();
|
||||
int index = (int) numericValue.getLong();
|
||||
if (index < 0)
|
||||
{// only for values < 0
|
||||
index = normalizeIndex(index, numitems);
|
||||
@@ -469,9 +469,9 @@ public class ListValue extends AbstractListValue implements ContainerValueInterf
|
||||
items.add(Value.NULL);
|
||||
}
|
||||
|
||||
if (extend && value instanceof AbstractListValue)
|
||||
if (extend && value instanceof final AbstractListValue abstractListValue)
|
||||
{
|
||||
Iterable<Value> iterable = ((AbstractListValue) value)::iterator;
|
||||
Iterable<Value> iterable = abstractListValue::iterator;
|
||||
List<Value> appendix = StreamSupport.stream(iterable.spliterator(), false).collect(Collectors.toList());
|
||||
items.addAll(index, appendix);
|
||||
return true;
|
||||
@@ -498,11 +498,11 @@ public class ListValue extends AbstractListValue implements ContainerValueInterf
|
||||
@Override
|
||||
public boolean delete(Value where)
|
||||
{
|
||||
if (!(where instanceof NumericValue) || items.isEmpty())
|
||||
if (!(where instanceof final NumericValue numericValue) || items.isEmpty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
long index = ((NumericValue) where).getLong();
|
||||
long index = numericValue.getLong();
|
||||
items.remove(normalizeIndex(index, items.size()));
|
||||
return true;
|
||||
}
|
||||
@@ -592,8 +592,8 @@ public class ListValue extends AbstractListValue implements ContainerValueInterf
|
||||
}
|
||||
// only numbers / mixed types
|
||||
tags.forEach(cases.contains(TagTypeCompat.DBL)
|
||||
? (t -> tag.add(DoubleTag.valueOf(((NumericTag) t).doubleValue())))
|
||||
: (t -> tag.add(LongTag.valueOf(((NumericTag) t).longValue()))));
|
||||
? t -> tag.add(DoubleTag.valueOf(((NumericTag) t).doubleValue()))
|
||||
: t -> tag.add(LongTag.valueOf(((NumericTag) t).longValue())));
|
||||
return tag;
|
||||
}
|
||||
|
||||
|
||||
@@ -118,14 +118,12 @@ public class NBTSerializableValue extends Value implements ContainerValueInterfa
|
||||
return StringValue.of(nameFromResource(id));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String nameFromResource(@Nullable Identifier id)
|
||||
public static @Nullable String nameFromResource(@Nullable Identifier id)
|
||||
{
|
||||
return id == null ? null : id.getNamespace().equals("minecraft") ? id.getPath() : id.toString();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static NBTSerializableValue parseString(String nbtString)
|
||||
public static @Nullable NBTSerializableValue parseString(String nbtString)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -356,7 +354,7 @@ public class NBTSerializableValue extends Value implements ContainerValueInterfa
|
||||
{
|
||||
return res.createItemStack(1);
|
||||
}
|
||||
ItemInput parser = (new ItemParser(regs)).parse(new StringReader(itemString));
|
||||
ItemInput parser = new ItemParser(regs).parse(new StringReader(itemString));
|
||||
res = new ItemInput(parser.item(), parser.components());
|
||||
|
||||
itemCache.put(itemString, res);
|
||||
@@ -477,11 +475,11 @@ public class NBTSerializableValue extends Value implements ContainerValueInterfa
|
||||
Tag tag = getTag();
|
||||
if (tag instanceof final CompoundTag ctag)
|
||||
{
|
||||
return !(ctag).isEmpty();
|
||||
return !ctag.isEmpty();
|
||||
}
|
||||
if (tag instanceof final CollectionTag ltag)
|
||||
{
|
||||
return !(ltag).isEmpty();
|
||||
return !ltag.isEmpty();
|
||||
}
|
||||
if (tag instanceof final NumericTag number)
|
||||
{
|
||||
|
||||
@@ -88,13 +88,13 @@ public class ScreenValue extends Value
|
||||
screenHandlerFactories.put("crafting", CraftingMenu::new);
|
||||
screenHandlerFactories.put("enchantment", EnchantmentMenu::new);
|
||||
screenHandlerFactories.put("furnace", FurnaceMenu::new);
|
||||
screenHandlerFactories.put("generic_3x3", ((syncId, playerInventory) -> new ChestMenu(GENERIC_3x3, syncId, playerInventory, new SimpleContainer(9), 1)));
|
||||
screenHandlerFactories.put("generic_9x1", ((syncId, playerInventory) -> new ChestMenu(GENERIC_9x1, syncId, playerInventory, new SimpleContainer(9), 1)));
|
||||
screenHandlerFactories.put("generic_9x2", ((syncId, playerInventory) -> new ChestMenu(GENERIC_9x2, syncId, playerInventory, new SimpleContainer(9 * 2), 2)));
|
||||
screenHandlerFactories.put("generic_9x3", ((syncId, playerInventory) -> new ChestMenu(GENERIC_9x3, syncId, playerInventory, new SimpleContainer(9 * 3), 3)));
|
||||
screenHandlerFactories.put("generic_9x4", ((syncId, playerInventory) -> new ChestMenu(GENERIC_9x4, syncId, playerInventory, new SimpleContainer(9 * 4), 4)));
|
||||
screenHandlerFactories.put("generic_9x5", ((syncId, playerInventory) -> new ChestMenu(GENERIC_9x5, syncId, playerInventory, new SimpleContainer(9 * 5), 5)));
|
||||
screenHandlerFactories.put("generic_9x6", ((syncId, playerInventory) -> new ChestMenu(GENERIC_9x6, syncId, playerInventory, new SimpleContainer(9 * 6), 6)));
|
||||
screenHandlerFactories.put("generic_3x3", (syncId, playerInventory) -> new ChestMenu(GENERIC_3x3, syncId, playerInventory, new SimpleContainer(9), 1));
|
||||
screenHandlerFactories.put("generic_9x1", (syncId, playerInventory) -> new ChestMenu(GENERIC_9x1, syncId, playerInventory, new SimpleContainer(9), 1));
|
||||
screenHandlerFactories.put("generic_9x2", (syncId, playerInventory) -> new ChestMenu(GENERIC_9x2, syncId, playerInventory, new SimpleContainer(9 * 2), 2));
|
||||
screenHandlerFactories.put("generic_9x3", (syncId, playerInventory) -> new ChestMenu(GENERIC_9x3, syncId, playerInventory, new SimpleContainer(9 * 3), 3));
|
||||
screenHandlerFactories.put("generic_9x4", (syncId, playerInventory) -> new ChestMenu(GENERIC_9x4, syncId, playerInventory, new SimpleContainer(9 * 4), 4));
|
||||
screenHandlerFactories.put("generic_9x5", (syncId, playerInventory) -> new ChestMenu(GENERIC_9x5, syncId, playerInventory, new SimpleContainer(9 * 5), 5));
|
||||
screenHandlerFactories.put("generic_9x6", (syncId, playerInventory) -> new ChestMenu(GENERIC_9x6, syncId, playerInventory, new SimpleContainer(9 * 6), 6));
|
||||
screenHandlerFactories.put("grindstone", GrindstoneMenu::new);
|
||||
screenHandlerFactories.put("hopper", HopperMenu::new);
|
||||
screenHandlerFactories.put("lectern", (syncId, playerInventory) -> new LecternMenu(syncId, new SimpleContainer(1), new SimpleContainerData(1)));
|
||||
|
||||
@@ -149,9 +149,9 @@ public class ValueConversions
|
||||
|
||||
public static Level dimFromValue(Value dimensionValue, MinecraftServer server)
|
||||
{
|
||||
if (dimensionValue instanceof EntityValue)
|
||||
if (dimensionValue instanceof final EntityValue entityValue)
|
||||
{
|
||||
return ((EntityValue) dimensionValue).getEntity().level();
|
||||
return entityValue.getEntity().level();
|
||||
}
|
||||
else if (dimensionValue instanceof BlockValue bv)
|
||||
{
|
||||
@@ -175,7 +175,7 @@ public class ValueConversions
|
||||
ResourceKey<Level> dim = null;
|
||||
Identifier id = Identifier.parse(dimString);
|
||||
// not using RegistryKey.of since that one creates on check
|
||||
for (ResourceKey<Level> world : (server.levelKeys()))
|
||||
for (ResourceKey<Level> world : server.levelKeys())
|
||||
{
|
||||
if (id.equals(world.identifier()))
|
||||
{
|
||||
@@ -419,6 +419,7 @@ public class ValueConversions
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("DoubleBraceInitialization")
|
||||
private static final Int2ObjectMap<SlotParam> slotIdsToSlotParams = new Int2ObjectOpenHashMap<>()
|
||||
{{
|
||||
int n;
|
||||
|
||||
@@ -257,10 +257,10 @@ public class Messenger
|
||||
MutableComponent previousComponent = null;
|
||||
for (Object o: fields)
|
||||
{
|
||||
if (o instanceof MutableComponent)
|
||||
if (o instanceof final MutableComponent mutableComponent)
|
||||
{
|
||||
message.append((MutableComponent)o);
|
||||
previousComponent = (MutableComponent)o;
|
||||
message.append(mutableComponent);
|
||||
previousComponent = mutableComponent;
|
||||
continue;
|
||||
}
|
||||
String txt = o.toString();
|
||||
@@ -300,7 +300,7 @@ public class Messenger
|
||||
public static void print_server_message(MinecraftServer server, String message)
|
||||
{
|
||||
if (server == null)
|
||||
LOG.error("Message not delivered: "+message);
|
||||
LOG.error("Message not delivered: {}", message);
|
||||
server.sendSystemMessage(Component.literal(message));
|
||||
Component txt = c("gi "+message);
|
||||
for (ServerPlayer entityplayer : server.getPlayerList().getPlayers())
|
||||
@@ -311,7 +311,7 @@ public class Messenger
|
||||
public static void print_server_message(MinecraftServer server, Component message)
|
||||
{
|
||||
if (server == null)
|
||||
LOG.error("Message not delivered: "+message.getString());
|
||||
LOG.error("Message not delivered: {}", message.getString());
|
||||
server.sendSystemMessage(message);
|
||||
for (ServerPlayer entityplayer : server.getPlayerList().getPlayers())
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user