Merge branch 'master' into 1.17

This commit is contained in:
gnembon committed 2020-11-16 09:43:22 -04:00
commit 24e8c00998
40 files changed
+409 -124

No files matched your search

@@ -136,7 +136,7 @@ public class CarpetScriptHost extends ScriptHost
String hostName = main.getName();
List<String> commandArgs = path.stream().filter(t -> t.isArgument).map(t -> t.surface).collect(Collectors.toList());
if (commandArgs.size() != (functionSpec.function.getNumParams()-functionSpec.args.size()) )
throw CommandArgument.error("Number of parameters in function doesn't match parameters for a command");
throw CommandArgument.error("Number of parameters in function "+functionSpec.function.fullName()+" doesn't match parameters for a command");
if (path.isEmpty())
{
return command.executes((c) -> execute(c, hostName, functionSpec, Collections.emptyList()));
@@ -50,6 +50,13 @@ public class CarpetScriptServer
private static final List<Module> bundledModuleData = new ArrayList<>();
private static final List<Module> ruleModuleData = new ArrayList<>();
/**
* Registers a Scarpet App to be always available to be loaded
* in the /script load list.
* @see BundledModule#fromPath(ClassLoader, String, String, boolean)
*
* @param app The {@link BundledModule} of the app
*/
public static void registerBuiltInScript(BundledModule app)
{
bundledModuleData.add(app);
@@ -57,10 +64,11 @@ public class CarpetScriptServer
/**
* Registers a Scarpet App to be used as a Rule App
* (to be controlled with the value of a Carpet rule)
* (to be controlled with the value of a Carpet rule).
* Libraries should be registered with {@link #registerBuiltInScript(BundledModule)} instead
* @see BundledModule#fromPath(ClassLoader, String, String, boolean)
*
* @param app is the BundledModule of an app. Libraries
* should be registered as builtInScripts instead
* @param app The {@link BundledModule} of the app.
*/
public static void registerSettingsApp(BundledModule app) {
ruleModuleData.add(app);
@@ -214,13 +222,6 @@ public class CarpetScriptServer
// Messenger.m(source, "r Failed to add "+name+" app: invalid app config (via '__config()' function)");
// return false;
//}
if (module == null)
{
Messenger.m(source, "r Unable to locate the app, but created empty "+name+" app instead");
modules.put(name, newHost);
return true;
}
String code = module.getCode();
if (module.getCode() == null)
{
Messenger.m(source, "r Unable to load "+name+" app - not found");
-1
View File
@@ -1,7 +1,6 @@
package carpet.script;
import carpet.script.exception.ExpressionException;
import carpet.script.exception.InternalExpressionException;
import carpet.script.value.Value;
import java.util.ArrayList;
@@ -17,14 +17,46 @@ public class BundledModule extends Module
this.name = name;
this.code = code;
}
/**
* Creates a new {@link BundledModule} with an app located in Carpet's script storage.
* @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}
*/
public static BundledModule carpetNative(String scriptName, boolean isLibrary)
{
BundledModule module = new BundledModule(null, null, isLibrary);
try
{
module.name = scriptName.toLowerCase(Locale.ROOT);
return fromPath("assets/carpet/scripts/", scriptName, isLibrary);
}
/**
* Creates a new {@link BundledModule} with an app located at a specified place.
* @see #fromPathWithCustomName(ClassLoader, String, String, boolean)
*
* @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}
*/
public static BundledModule fromPath(String path, String scriptName, boolean isLibrary) {
return fromPathWithCustomName(path+scriptName+(isLibrary?".scl":".sc"), scriptName, isLibrary);
}
/**
* Creates a new {@link BundledModule} with an app located at the specified fullPath with a custom name.
* @see #fromPath(ClassLoader, String, String, boolean)
*
* @param fullPath A {@link String} being the full path to the app's code, including file and extension.
* @param scriptName A {@link String} being the custom name for the script.
* @param isLibrary A {@link boolean} indicating whether or not the script is a library
* @return The created {@link BundledModule}
*/
public static BundledModule fromPathWithCustomName(String fullPath, String customName, boolean isLibrary) {
BundledModule module = new BundledModule(null, null, isLibrary);
try
{
module.name = customName.toLowerCase(Locale.ROOT);
module.code = IOUtils.toString(
BundledModule.class.getClassLoader().getResourceAsStream("assets/carpet/scripts/"+scriptName+(isLibrary?".scl":".sc")),
BundledModule.class.getClassLoader().getResourceAsStream(fullPath),
StandardCharsets.UTF_8
);
}
@@ -1,7 +1,6 @@
package carpet.script.value;
import carpet.script.CarpetContext;
import carpet.script.LazyValue;
import carpet.script.exception.InternalExpressionException;
import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
@@ -13,7 +13,6 @@ import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.LongTag;
import net.minecraft.nbt.StringTag;
import net.minecraft.nbt.Tag;
import net.minecraft.util.registry.Registry;
import java.util.ArrayList;
import java.util.Arrays;
@@ -25,7 +24,6 @@ import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
import static carpet.script.value.NBTSerializableValue.nameFromRegistryId;
import static java.lang.Math.abs;
public class ListValue extends AbstractListValue implements ContainerValueInterface
@@ -2,7 +2,6 @@ package carpet.script.value;
import carpet.script.Context;
import carpet.script.Expression;
import carpet.script.LazyValue;
import carpet.script.Tokenizer;
import carpet.script.exception.ExitStatement;
import carpet.script.exception.ExpressionException;