23w44a and some cleanups

This commit is contained in:
gnembon committed 2023-11-01 22:13:35 +01:00
1 parent 5b8e61c1bd
commit 7392f16785
7 files changed
+42 -32

No files matched your search

+2 -2
View File
@@ -3,10 +3,10 @@ org.gradle.jvmargs=-Xmx1G
# Fabric Properties # Fabric Properties
# check https://fabricmc.net/develop/ # check https://fabricmc.net/develop/
minecraft_version=23w43a minecraft_version=23w44a
loader_version=0.14.24 loader_version=0.14.24
jsr305_version=3.0.2 jsr305_version=3.0.2
fabric_version=0.89.3+1.20.2 fabric_version=0.90.6+1.20.3
# Mod Properties # Mod Properties
mod_version = 1.4.123 mod_version = 1.4.123
@@ -15,7 +15,7 @@ import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemp
@Mixin(StructureBlockEntity.class) @Mixin(StructureBlockEntity.class)
public abstract class StructureBlockEntity_fillUpdatesMixin 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", 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" 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"
)) ))
@@ -40,6 +40,7 @@ import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.EntityType;
import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Pair;
import javax.annotation.Nullable;
import java.math.BigInteger; import java.math.BigInteger;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.ArrayList; import java.util.ArrayList;
@@ -77,7 +78,7 @@ public class CarpetScriptHost extends ScriptHost
public AppStoreManager.StoreNode storeSource; public AppStoreManager.StoreNode storeSource;
boolean hasCommand; boolean hasCommand;
private CarpetScriptHost(CarpetScriptServer server, Module code, boolean perUser, ScriptHost parent, Map<Value, Value> config, Map<String, CommandArgument> argTypes, Predicate<CommandSourceStack> commandValidator, boolean isRuleApp) private CarpetScriptHost(CarpetScriptServer server, @Nullable Module code, boolean perUser, ScriptHost parent, Map<Value, Value> config, Map<String, CommandArgument> argTypes, Predicate<CommandSourceStack> commandValidator, boolean isRuleApp)
{ {
super(code, server, perUser, parent); super(code, server, perUser, parent);
this.saveTimeout = 0; this.saveTimeout = 0;
@@ -98,7 +99,7 @@ public class CarpetScriptHost extends ScriptHost
storeSource = null; storeSource = null;
} }
public static CarpetScriptHost create(CarpetScriptServer scriptServer, Module module, boolean perPlayer, CommandSourceStack source, Predicate<CommandSourceStack> commandValidator, boolean isRuleApp, AppStoreManager.StoreNode storeSource) public static CarpetScriptHost create(CarpetScriptServer scriptServer, @Nullable Module module, boolean perPlayer, CommandSourceStack source, Predicate<CommandSourceStack> commandValidator, boolean isRuleApp, AppStoreManager.StoreNode storeSource)
{ {
CarpetScriptHost host = new CarpetScriptHost(scriptServer, module, perPlayer, null, Collections.emptyMap(), new HashMap<>(), commandValidator, isRuleApp); CarpetScriptHost host = new CarpetScriptHost(scriptServer, module, perPlayer, null, Collections.emptyMap(), new HashMap<>(), commandValidator, isRuleApp);
// parse code and convert to expression // parse code and convert to expression
@@ -742,7 +743,7 @@ public class CarpetScriptHost extends ScriptHost
FunctionValue function = getFunction(call); FunctionValue function = getFunction(call);
if (function == null) 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<LazyValue> argv = new ArrayList<>(); List<LazyValue> argv = new ArrayList<>();
if (coords != null) if (coords != null)
@@ -968,7 +969,7 @@ public class CarpetScriptHost extends ScriptHost
public Tag readFileTag(FileArgument fdesc) public Tag readFileTag(FileArgument fdesc)
{ {
if (getName() == null && !fdesc.isShared) if (isDefaultApp() && !fdesc.isShared)
{ {
return null; return null;
} }
@@ -985,7 +986,7 @@ public class CarpetScriptHost extends ScriptHost
public boolean writeTagFile(Tag tag, 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. 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) 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<String> data) public boolean appendLogFile(FileArgument fdesc, List<String> 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<String> readTextResource(FileArgument fdesc) public List<String> 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) public JsonElement readJsonFile(FileArgument fdesc)
{ {
return getName() == null && !fdesc.isShared ? null : fdesc.readJsonFile(main); return isDefaultApp() && !fdesc.isShared ? null : fdesc.readJsonFile(main);
} }
public Stream<String> listFolder(FileArgument fdesc) public Stream<String> 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<Path> action) public boolean applyActionForResource(String path, boolean shared, Consumer<Path> action)
@@ -1202,7 +1203,7 @@ public class CarpetScriptHost extends ScriptHost
{ {
if (super.issueDeprecation(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 true;
} }
return false; return false;
@@ -421,7 +421,7 @@ public class ScriptCommand
CommandSourceStack source = context.getSource(); CommandSourceStack source = context.getSource();
CarpetScriptServer scriptServer = ss(context); 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) -> { host.globalFunctionNames(host.main, (str) -> all || !str.startsWith("__")).sorted().forEach((s) -> {
FunctionValue fun = host.getFunction(s); FunctionValue fun = host.getFunction(s);
if (fun == null) if (fun == null)
@@ -442,7 +442,7 @@ public class ScriptCommand
}); });
//Messenger.m(source, "w "+code); //Messenger.m(source, "w "+code);
Carpet.Messenger_message(source, "w "); 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) -> { host.globalVariableNames(host.main, (s) -> s.startsWith("global_")).sorted().forEach((s) -> {
LazyValue variable = host.getGlobalVariable(s); LazyValue variable = host.getGlobalVariable(s);
if (variable == null) if (variable == null)
+14 -2
View File
@@ -10,6 +10,7 @@ import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import javax.annotation.Nullable;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
@@ -121,6 +122,17 @@ public abstract class ScriptHost
return main == null ? null : main.name(); 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; public final Module main;
@FunctionalInterface @FunctionalInterface
@@ -131,7 +143,7 @@ public abstract class ScriptHost
public ErrorSnooper errorSnooper = null; 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.parent = parent;
this.main = code; this.main = code;
@@ -551,7 +563,7 @@ public abstract class ScriptHost
return false; return false;
} }
deprecations.add(feature); 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; return true;
} }
+1 -1
View File
@@ -205,7 +205,7 @@ public class Carpet
return; 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 // to be ran once during CarpetEventServer.Event static init
@@ -1,7 +1,7 @@
package carpet.script.utils; package carpet.script.utils;
import carpet.script.external.Vanilla; import carpet.script.external.Vanilla;
import net.minecraft.commands.CommandResultConsumer; import net.minecraft.commands.CommandResultCallback;
import net.minecraft.commands.CommandSigningContext; import net.minecraft.commands.CommandSigningContext;
import net.minecraft.commands.CommandSource; import net.minecraft.commands.CommandSource;
import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.CommandSourceStack;
@@ -33,7 +33,7 @@ public class SnoopyCommandSource extends CommandSourceStack
private final MinecraftServer server; private final MinecraftServer server;
// skipping silent since snooper is never silent // skipping silent since snooper is never silent
private final Entity entity; private final Entity entity;
private final CommandResultConsumer<CommandSourceStack> resultConsumer; private final CommandResultCallback resultConsumer;
private final EntityAnchorArgument.Anchor entityAnchor; private final EntityAnchorArgument.Anchor entityAnchor;
private final Vec2 rotation; private final Vec2 rotation;
// good stuff // 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()), super(CommandSource.NULL, original.getPosition(), original.getRotation(), original.getLevel(), Vanilla.MinecraftServer_getRunPermissionLevel(original.getServer()),
original.getTextName(), original.getDisplayName(), original.getServer(), original.getEntity(), false, original.getTextName(), original.getDisplayName(), original.getServer(), original.getEntity(), false,
(ctx, succ, res) -> { CommandResultCallback.EMPTY, EntityAnchorArgument.Anchor.FEET, CommandSigningContext.ANONYMOUS, TaskChainer.immediate(original.getServer()));
}, EntityAnchorArgument.Anchor.FEET, CommandSigningContext.ANONYMOUS, TaskChainer.immediate(original.getServer()), i -> {});
this.output = CommandSource.NULL; this.output = CommandSource.NULL;
this.position = original.getPosition(); this.position = original.getPosition();
this.world = original.getLevel(); this.world = original.getLevel();
@@ -57,8 +56,7 @@ public class SnoopyCommandSource extends CommandSourceStack
this.name = original.getDisplayName(); this.name = original.getDisplayName();
this.server = original.getServer(); this.server = original.getServer();
this.entity = original.getEntity(); this.entity = original.getEntity();
this.resultConsumer = (ctx, succ, res) -> { this.resultConsumer = CommandResultCallback.EMPTY;
};
this.entityAnchor = original.getAnchor(); this.entityAnchor = original.getAnchor();
this.rotation = original.getRotation(); this.rotation = original.getRotation();
this.error = error; this.error = error;
@@ -81,8 +79,7 @@ public class SnoopyCommandSource extends CommandSourceStack
this.name = player.getDisplayName(); this.name = player.getDisplayName();
this.server = player.level().getServer(); this.server = player.level().getServer();
this.entity = player; this.entity = player;
this.resultConsumer = (ctx, succ, res) -> { this.resultConsumer = CommandResultCallback.EMPTY;
};
this.entityAnchor = EntityAnchorArgument.Anchor.FEET; this.entityAnchor = EntityAnchorArgument.Anchor.FEET;
this.rotation = player.getRotationVector(); // not a client call really this.rotation = player.getRotationVector(); // not a client call really
this.error = error; this.error = error;
@@ -91,13 +88,13 @@ public class SnoopyCommandSource extends CommandSourceStack
this.taskChainer = TaskChainer.immediate(player.server); 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<CommandSourceStack> 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<Component> chatOutput Component[] error, List<Component> chatOutput
) )
{ {
super(output, pos, rot, world, level, super(output, pos, rot, world, level,
simpleName, name, server, entity, false, simpleName, name, server, entity, false,
consumer, entityAnchor, context, chainer, i -> {}); consumer, entityAnchor, context, chainer);
this.output = output; this.output = output;
this.position = pos; this.position = pos;
this.rotation = rot; this.rotation = rot;
@@ -134,15 +131,15 @@ public class SnoopyCommandSource extends CommandSourceStack
} }
@Override @Override
public CommandSourceStack withCallback(CommandResultConsumer<CommandSourceStack> consumer) public CommandSourceStack withCallback(CommandResultCallback consumer)
{ {
return new SnoopyCommandSource(output, position, rotation, world, level, simpleName, name, server, entity, consumer, entityAnchor, signingContext, taskChainer, error, chatOutput); return new SnoopyCommandSource(output, position, rotation, world, level, simpleName, name, server, entity, consumer, entityAnchor, signingContext, taskChainer, error, chatOutput);
} }
@Override @Override
public CommandSourceStack withCallback(CommandResultConsumer<CommandSourceStack> consumer, BinaryOperator<CommandResultConsumer<CommandSourceStack>> binaryOperator) public CommandSourceStack withCallback(CommandResultCallback consumer, BinaryOperator<CommandResultCallback> binaryOperator)
{ {
CommandResultConsumer<CommandSourceStack> resultConsumer = binaryOperator.apply(this.resultConsumer, consumer); CommandResultCallback resultConsumer = binaryOperator.apply(this.resultConsumer, consumer);
return this.withCallback(resultConsumer); return this.withCallback(resultConsumer);
} }