From 7392f16785b615e78420fd47a99fbd8cb774d6fd Mon Sep 17 00:00:00 2001 From: gnembon <41132274+gnembon@users.noreply.github.com> Date: Wed, 1 Nov 2023 22:13:35 +0100 Subject: [PATCH] 23w44a and some cleanups --- gradle.properties | 4 ++-- ...StructureBlockEntity_fillUpdatesMixin.java | 2 +- .../java/carpet/script/CarpetScriptHost.java | 23 ++++++++++--------- .../java/carpet/script/ScriptCommand.java | 4 ++-- src/main/java/carpet/script/ScriptHost.java | 16 +++++++++++-- .../java/carpet/script/external/Carpet.java | 2 +- .../script/utils/SnoopyCommandSource.java | 23 ++++++++----------- 7 files changed, 42 insertions(+), 32 deletions(-) diff --git a/gradle.properties b/gradle.properties index 1eab51a8..0840cf7e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,10 +3,10 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check https://fabricmc.net/develop/ - minecraft_version=23w43a + minecraft_version=23w44a loader_version=0.14.24 jsr305_version=3.0.2 - fabric_version=0.89.3+1.20.2 + fabric_version=0.90.6+1.20.3 # Mod Properties mod_version = 1.4.123 diff --git a/src/main/java/carpet/mixins/StructureBlockEntity_fillUpdatesMixin.java b/src/main/java/carpet/mixins/StructureBlockEntity_fillUpdatesMixin.java index 27379921..6dd15586 100644 --- a/src/main/java/carpet/mixins/StructureBlockEntity_fillUpdatesMixin.java +++ b/src/main/java/carpet/mixins/StructureBlockEntity_fillUpdatesMixin.java @@ -15,7 +15,7 @@ import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemp @Mixin(StructureBlockEntity.class) public abstract class StructureBlockEntity_fillUpdatesMixin { - @Redirect(method = "Lnet/minecraft/world/level/block/entity/StructureBlockEntity;loadStructure(Lnet/minecraft/server/level/ServerLevel;ZLnet/minecraft/world/level/levelgen/structure/templatesystem/StructureTemplate;)Z", at = @At( + @Redirect(method = "placeStructure(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/world/level/levelgen/structure/templatesystem/StructureTemplate;)V", at = @At( value = "INVOKE", target = "Lnet/minecraft/world/level/levelgen/structure/templatesystem/StructureTemplate;placeInWorld(Lnet/minecraft/world/level/ServerLevelAccessor;Lnet/minecraft/core/BlockPos;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/levelgen/structure/templatesystem/StructurePlaceSettings;Lnet/minecraft/util/RandomSource;I)Z" )) diff --git a/src/main/java/carpet/script/CarpetScriptHost.java b/src/main/java/carpet/script/CarpetScriptHost.java index 9c775c60..7a8d8412 100644 --- a/src/main/java/carpet/script/CarpetScriptHost.java +++ b/src/main/java/carpet/script/CarpetScriptHost.java @@ -40,6 +40,7 @@ import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; import org.apache.commons.lang3.tuple.Pair; +import javax.annotation.Nullable; import java.math.BigInteger; import java.nio.file.Path; import java.util.ArrayList; @@ -77,7 +78,7 @@ public class CarpetScriptHost extends ScriptHost public AppStoreManager.StoreNode storeSource; boolean hasCommand; - private CarpetScriptHost(CarpetScriptServer server, Module code, boolean perUser, ScriptHost parent, Map config, Map argTypes, Predicate commandValidator, boolean isRuleApp) + private CarpetScriptHost(CarpetScriptServer server, @Nullable Module code, boolean perUser, ScriptHost parent, Map config, Map argTypes, Predicate commandValidator, boolean isRuleApp) { super(code, server, perUser, parent); this.saveTimeout = 0; @@ -98,7 +99,7 @@ public class CarpetScriptHost extends ScriptHost storeSource = null; } - public static CarpetScriptHost create(CarpetScriptServer scriptServer, Module module, boolean perPlayer, CommandSourceStack source, Predicate commandValidator, boolean isRuleApp, AppStoreManager.StoreNode storeSource) + public static CarpetScriptHost create(CarpetScriptServer scriptServer, @Nullable Module module, boolean perPlayer, CommandSourceStack source, Predicate commandValidator, boolean isRuleApp, AppStoreManager.StoreNode storeSource) { CarpetScriptHost host = new CarpetScriptHost(scriptServer, module, perPlayer, null, Collections.emptyMap(), new HashMap<>(), commandValidator, isRuleApp); // parse code and convert to expression @@ -742,7 +743,7 @@ public class CarpetScriptHost extends ScriptHost FunctionValue function = getFunction(call); if (function == null) { - throw new CarpetExpressionException("Couldn't find function '" + call + "' in app '" + this.getName() + "'", null); + throw new CarpetExpressionException("Couldn't find function '" + call + "' in app '" + this.getVisualName() + "'", null); } List argv = new ArrayList<>(); if (coords != null) @@ -968,7 +969,7 @@ public class CarpetScriptHost extends ScriptHost public Tag readFileTag(FileArgument fdesc) { - if (getName() == null && !fdesc.isShared) + if (isDefaultApp() && !fdesc.isShared) { return null; } @@ -985,7 +986,7 @@ public class CarpetScriptHost extends ScriptHost public boolean writeTagFile(Tag tag, FileArgument fdesc) { - if (getName() == null && !fdesc.isShared) + if (isDefaultApp() && !fdesc.isShared) { return false; // if belongs to an app, cannot be default host. } @@ -1007,27 +1008,27 @@ public class CarpetScriptHost extends ScriptHost public boolean removeResourceFile(FileArgument fdesc) { - return (getName() != null || fdesc.isShared) && fdesc.dropExistingFile(main); // + return (!isDefaultApp() || fdesc.isShared) && fdesc.dropExistingFile(main); // } public boolean appendLogFile(FileArgument fdesc, List data) { - return (getName() != null || fdesc.isShared) && fdesc.appendToTextFile(main, data); // if belongs to an app, cannot be default host. + return (!isDefaultApp() || fdesc.isShared) && fdesc.appendToTextFile(main, data); // if belongs to an app, cannot be default host. } public List readTextResource(FileArgument fdesc) { - return getName() == null && !fdesc.isShared ? null : fdesc.listFile(main); + return isDefaultApp() && !fdesc.isShared ? null : fdesc.listFile(main); } public JsonElement readJsonFile(FileArgument fdesc) { - return getName() == null && !fdesc.isShared ? null : fdesc.readJsonFile(main); + return isDefaultApp() && !fdesc.isShared ? null : fdesc.readJsonFile(main); } public Stream listFolder(FileArgument fdesc) { - return getName() == null && !fdesc.isShared ? null : fdesc.listFolder(main); + return isDefaultApp() && !fdesc.isShared ? null : fdesc.listFolder(main); } public boolean applyActionForResource(String path, boolean shared, Consumer action) @@ -1202,7 +1203,7 @@ public class CarpetScriptHost extends ScriptHost { if (super.issueDeprecation(feature)) { - Carpet.Messenger_message(responsibleSource, "rb App '" +getName() + "' uses '" + feature + "', which is deprecated for removal. Check the docs for a replacement"); + Carpet.Messenger_message(responsibleSource, "rb App '" +getVisualName() + "' uses '" + feature + "', which is deprecated for removal. Check the docs for a replacement"); return true; } return false; diff --git a/src/main/java/carpet/script/ScriptCommand.java b/src/main/java/carpet/script/ScriptCommand.java index 7ea25440..e8bc716a 100644 --- a/src/main/java/carpet/script/ScriptCommand.java +++ b/src/main/java/carpet/script/ScriptCommand.java @@ -421,7 +421,7 @@ public class ScriptCommand CommandSourceStack source = context.getSource(); CarpetScriptServer scriptServer = ss(context); - Carpet.Messenger_message(source, "lb Stored functions" + ((host == scriptServer.globalHost) ? ":" : " in " + host.getName() + ":")); + Carpet.Messenger_message(source, "lb Stored functions" + ((host == scriptServer.globalHost) ? ":" : " in " + host.getVisualName() + ":")); host.globalFunctionNames(host.main, (str) -> all || !str.startsWith("__")).sorted().forEach((s) -> { FunctionValue fun = host.getFunction(s); if (fun == null) @@ -442,7 +442,7 @@ public class ScriptCommand }); //Messenger.m(source, "w "+code); Carpet.Messenger_message(source, "w "); - Carpet.Messenger_message(source, "lb Global variables" + ((host == scriptServer.globalHost) ? ":" : " in " + host.getName() + ":")); + Carpet.Messenger_message(source, "lb Global variables" + ((host == scriptServer.globalHost) ? ":" : " in " + host.getVisualName() + ":")); host.globalVariableNames(host.main, (s) -> s.startsWith("global_")).sorted().forEach((s) -> { LazyValue variable = host.getGlobalVariable(s); if (variable == null) diff --git a/src/main/java/carpet/script/ScriptHost.java b/src/main/java/carpet/script/ScriptHost.java index e20e79c3..29cd5233 100644 --- a/src/main/java/carpet/script/ScriptHost.java +++ b/src/main/java/carpet/script/ScriptHost.java @@ -10,6 +10,7 @@ import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import javax.annotation.Nullable; import java.nio.file.Path; import java.util.HashMap; import java.util.HashSet; @@ -121,6 +122,17 @@ public abstract class ScriptHost return main == null ? null : main.name(); } + public String getVisualName() + { + return main == null ? "built-in default app" : main.name(); + } + + public boolean isDefaultApp() + { + return main == null; + } + + @Nullable public final Module main; @FunctionalInterface @@ -131,7 +143,7 @@ public abstract class ScriptHost public ErrorSnooper errorSnooper = null; - protected ScriptHost(Module code, ScriptServer scriptServer, boolean perUser, ScriptHost parent) + protected ScriptHost(@Nullable Module code, ScriptServer scriptServer, boolean perUser, ScriptHost parent) { this.parent = parent; this.main = code; @@ -551,7 +563,7 @@ public abstract class ScriptHost return false; } deprecations.add(feature); - DEPRECATION_LOG.warn("App '" + getName() + "' uses '" + feature + "', which is deprecated for removal. Check the docs for a replacement"); + DEPRECATION_LOG.warn("App '" + getVisualName() + "' uses '" + feature + "', which is deprecated for removal. Check the docs for a replacement"); return true; } diff --git a/src/main/java/carpet/script/external/Carpet.java b/src/main/java/carpet/script/external/Carpet.java index cf6408b6..a6fdc1c6 100644 --- a/src/main/java/carpet/script/external/Carpet.java +++ b/src/main/java/carpet/script/external/Carpet.java @@ -205,7 +205,7 @@ public class Carpet return; } } - throw new LoadException(String.format("%s requires a version of mod '%s' matching '%s', which is missing!", host.getName(), requiredModId, stringPredicate)); + throw new LoadException(String.format("%s requires a version of mod '%s' matching '%s', which is missing!", host.getVisualName(), requiredModId, stringPredicate)); } // to be ran once during CarpetEventServer.Event static init diff --git a/src/main/java/carpet/script/utils/SnoopyCommandSource.java b/src/main/java/carpet/script/utils/SnoopyCommandSource.java index 7e7a89c6..39d582e2 100644 --- a/src/main/java/carpet/script/utils/SnoopyCommandSource.java +++ b/src/main/java/carpet/script/utils/SnoopyCommandSource.java @@ -1,7 +1,7 @@ package carpet.script.utils; import carpet.script.external.Vanilla; -import net.minecraft.commands.CommandResultConsumer; +import net.minecraft.commands.CommandResultCallback; import net.minecraft.commands.CommandSigningContext; import net.minecraft.commands.CommandSource; import net.minecraft.commands.CommandSourceStack; @@ -33,7 +33,7 @@ public class SnoopyCommandSource extends CommandSourceStack private final MinecraftServer server; // skipping silent since snooper is never silent private final Entity entity; - private final CommandResultConsumer resultConsumer; + private final CommandResultCallback resultConsumer; private final EntityAnchorArgument.Anchor entityAnchor; private final Vec2 rotation; // good stuff @@ -47,8 +47,7 @@ public class SnoopyCommandSource extends CommandSourceStack { super(CommandSource.NULL, original.getPosition(), original.getRotation(), original.getLevel(), Vanilla.MinecraftServer_getRunPermissionLevel(original.getServer()), original.getTextName(), original.getDisplayName(), original.getServer(), original.getEntity(), false, - (ctx, succ, res) -> { - }, EntityAnchorArgument.Anchor.FEET, CommandSigningContext.ANONYMOUS, TaskChainer.immediate(original.getServer()), i -> {}); + CommandResultCallback.EMPTY, EntityAnchorArgument.Anchor.FEET, CommandSigningContext.ANONYMOUS, TaskChainer.immediate(original.getServer())); this.output = CommandSource.NULL; this.position = original.getPosition(); this.world = original.getLevel(); @@ -57,8 +56,7 @@ public class SnoopyCommandSource extends CommandSourceStack this.name = original.getDisplayName(); this.server = original.getServer(); this.entity = original.getEntity(); - this.resultConsumer = (ctx, succ, res) -> { - }; + this.resultConsumer = CommandResultCallback.EMPTY; this.entityAnchor = original.getAnchor(); this.rotation = original.getRotation(); this.error = error; @@ -81,8 +79,7 @@ public class SnoopyCommandSource extends CommandSourceStack this.name = player.getDisplayName(); this.server = player.level().getServer(); this.entity = player; - this.resultConsumer = (ctx, succ, res) -> { - }; + this.resultConsumer = CommandResultCallback.EMPTY; this.entityAnchor = EntityAnchorArgument.Anchor.FEET; this.rotation = player.getRotationVector(); // not a client call really this.error = error; @@ -91,13 +88,13 @@ public class SnoopyCommandSource extends CommandSourceStack this.taskChainer = TaskChainer.immediate(player.server); } - private SnoopyCommandSource(CommandSource output, Vec3 pos, Vec2 rot, ServerLevel world, int level, String simpleName, Component name, MinecraftServer server, @Nullable Entity entity, CommandResultConsumer consumer, EntityAnchorArgument.Anchor entityAnchor, CommandSigningContext context, TaskChainer chainer, + private SnoopyCommandSource(CommandSource output, Vec3 pos, Vec2 rot, ServerLevel world, int level, String simpleName, Component name, MinecraftServer server, @Nullable Entity entity, CommandResultCallback consumer, EntityAnchorArgument.Anchor entityAnchor, CommandSigningContext context, TaskChainer chainer, Component[] error, List chatOutput ) { super(output, pos, rot, world, level, simpleName, name, server, entity, false, - consumer, entityAnchor, context, chainer, i -> {}); + consumer, entityAnchor, context, chainer); this.output = output; this.position = pos; this.rotation = rot; @@ -134,15 +131,15 @@ public class SnoopyCommandSource extends CommandSourceStack } @Override - public CommandSourceStack withCallback(CommandResultConsumer consumer) + public CommandSourceStack withCallback(CommandResultCallback consumer) { return new SnoopyCommandSource(output, position, rotation, world, level, simpleName, name, server, entity, consumer, entityAnchor, signingContext, taskChainer, error, chatOutput); } @Override - public CommandSourceStack withCallback(CommandResultConsumer consumer, BinaryOperator> binaryOperator) + public CommandSourceStack withCallback(CommandResultCallback consumer, BinaryOperator binaryOperator) { - CommandResultConsumer resultConsumer = binaryOperator.apply(this.resultConsumer, consumer); + CommandResultCallback resultConsumer = binaryOperator.apply(this.resultConsumer, consumer); return this.withCallback(resultConsumer); }