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 1/2] 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 1eab51a8e0..0840cf7eda 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 2737992195..6dd1558695 100644 --- a/src/main/java/carpet/mixins/StructureBlockEntity_fillUpdatesMixin.java +++ b/src/main/java/carpet/mixins/StructureBlockEntity_fillUpdatesMixin.java @@ -15,7 +15,7 @@ @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 9c775c60b3..7a8d8412f5 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.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 @@ else if (parent != null) 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 Value callLegacy(CommandSourceStack source, String call, List co 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 @@ private Tag loadState() public Tag readFileTag(FileArgument fdesc) { - if (getName() == null && !fdesc.isShared) + if (isDefaultApp() && !fdesc.isShared) { return null; } @@ -985,7 +986,7 @@ public Tag readFileTag(FileArgument fdesc) 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 boolean writeTagFile(Tag tag, FileArgument fdesc) 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 boolean issueDeprecation(String feature) { 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 7ea254405b..e8bc716a4f 100644 --- a/src/main/java/carpet/script/ScriptCommand.java +++ b/src/main/java/carpet/script/ScriptCommand.java @@ -421,7 +421,7 @@ private static int listGlobals(CommandContext context, boole 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 @@ private static int listGlobals(CommandContext context, boole }); //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 e20e79c397..29cd523306 100644 --- a/src/main/java/carpet/script/ScriptHost.java +++ b/src/main/java/carpet/script/ScriptHost.java @@ -10,6 +10,7 @@ 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 String getName() 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 interface ErrorSnooper 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 boolean issueDeprecation(String feature) 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 cf6408b699..a6fdc1c66a 100644 --- a/src/main/java/carpet/script/external/Carpet.java +++ b/src/main/java/carpet/script/external/Carpet.java @@ -205,7 +205,7 @@ public static void assertRequirementMet(CarpetScriptHost host, String requiredMo 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 7e7a89c617..39d582e2d0 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 SnoopyCommandSource(CommandSourceStack original, Component[] error, List< { 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 SnoopyCommandSource(CommandSourceStack original, Component[] error, List< 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 SnoopyCommandSource(ServerPlayer player, Component[] error, List { - }; + 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 SnoopyCommandSource(ServerPlayer player, Component[] error, List 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 CommandSourceStack withRotation(Vec2 rotation) } @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); } From fd7c3370945ec738e7f8c5bf96fcc808d712215a Mon Sep 17 00:00:00 2001 From: gnembon <41132274+gnembon@users.noreply.github.com> Date: Wed, 1 Nov 2023 22:14:51 +0100 Subject: [PATCH 2/2] 1.4.124 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 0840cf7eda..574659ab50 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,7 +9,7 @@ org.gradle.jvmargs=-Xmx1G fabric_version=0.90.6+1.20.3 # Mod Properties - mod_version = 1.4.123 + mod_version = 1.4.124 maven_group = carpet archives_base_name = fabric-carpet