Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into screen
Browse files Browse the repository at this point in the history
  • Loading branch information
17183248569 committed Nov 2, 2023
2 parents 3c35adf + fd7c337 commit 7e9b8bf
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 33 deletions.
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ 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
mod_version = 1.4.124
maven_group = carpet
archives_base_name = fabric-carpet

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
))
Expand Down
23 changes: 12 additions & 11 deletions src/main/java/carpet/script/CarpetScriptHost.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<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);
this.saveTimeout = 0;
Expand All @@ -98,7 +99,7 @@ else if (parent != 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);
// parse code and convert to expression
Expand Down Expand Up @@ -742,7 +743,7 @@ public Value callLegacy(CommandSourceStack source, String call, List<Integer> 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<LazyValue> argv = new ArrayList<>();
if (coords != null)
Expand Down Expand Up @@ -968,7 +969,7 @@ private Tag loadState()

public Tag readFileTag(FileArgument fdesc)
{
if (getName() == null && !fdesc.isShared)
if (isDefaultApp() && !fdesc.isShared)
{
return null;
}
Expand All @@ -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.
}
Expand All @@ -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<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)
{
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<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)
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/carpet/script/ScriptCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ private static int listGlobals(CommandContext<CommandSourceStack> 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)
Expand All @@ -442,7 +442,7 @@ private static int listGlobals(CommandContext<CommandSourceStack> 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)
Expand Down
16 changes: 14 additions & 2 deletions src/main/java/carpet/script/ScriptHost.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/carpet/script/external/Carpet.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 10 additions & 13 deletions src/main/java/carpet/script/utils/SnoopyCommandSource.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<CommandSourceStack> resultConsumer;
private final CommandResultCallback resultConsumer;
private final EntityAnchorArgument.Anchor entityAnchor;
private final Vec2 rotation;
// good stuff
Expand All @@ -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();
Expand All @@ -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;
Expand All @@ -81,8 +79,7 @@ public SnoopyCommandSource(ServerPlayer player, Component[] error, List<Componen
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;
Expand All @@ -91,13 +88,13 @@ public SnoopyCommandSource(ServerPlayer player, Component[] error, List<Componen
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
)
{
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;
Expand Down Expand Up @@ -134,15 +131,15 @@ public CommandSourceStack withRotation(Vec2 rotation)
}

@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);
}

@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);
}

Expand Down

0 comments on commit 7e9b8bf

Please sign in to comment.