diff --git a/.factorypath b/.factorypath
new file mode 100644
index 00000000..7c91a24b
--- /dev/null
+++ b/.factorypath
@@ -0,0 +1,22 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/main/java/tools/redstone/redstonetools/RedstoneToolsClient.java b/src/main/java/tools/redstone/redstonetools/RedstoneToolsClient.java
index 551ad222..66467350 100644
--- a/src/main/java/tools/redstone/redstonetools/RedstoneToolsClient.java
+++ b/src/main/java/tools/redstone/redstonetools/RedstoneToolsClient.java
@@ -1,7 +1,10 @@
package tools.redstone.redstonetools;
import net.fabricmc.api.ClientModInitializer;
+import net.fabricmc.fabric.api.command.v2.ArgumentTypeRegistry;
import net.fabricmc.loader.api.FabricLoader;
+import net.minecraft.command.argument.serialize.ArgumentSerializer;
+import net.minecraft.util.Identifier;
import org.reflections.Reflections;
import org.slf4j.Logger;
@@ -9,9 +12,11 @@
import rip.hippo.inject.Doctor;
import rip.hippo.inject.Injector;
+import tools.redstone.redstonetools.features.arguments.serializers.GenericArgumentType;
import tools.redstone.redstonetools.utils.DependencyLookup;
import tools.redstone.redstonetools.utils.ReflectionUtils;
+import java.lang.reflect.InvocationTargetException;
import java.nio.file.Path;
public class RedstoneToolsClient implements ClientModInitializer {
@@ -31,6 +36,32 @@ public void onInitializeClient() {
// Register game rules
RedstoneToolsGameRules.register();
+ // Register arguments
+ ReflectionUtils.getAllArguments().forEach(argument -> {
+ var nestedClasses = (Class[]) argument
+ .getDeclaredClasses();
+
+ if (nestedClasses.length == 0) {
+ LOGGER.error("Failed to register {} because no serializer nested class was found",
+ argument.getSimpleName());
+ return;
+ }
+
+ Identifier id = new Identifier(MOD_ID, argument.getSimpleName().toLowerCase());
+
+ try {
+ var serializer = nestedClasses[0].getDeclaredConstructor().newInstance();
+
+ ArgumentTypeRegistry.registerArgumentType(
+ id,
+ argument, serializer);
+ } catch (InstantiationException | IllegalAccessException | IllegalArgumentException
+ | InvocationTargetException | NoSuchMethodException | SecurityException e) {
+ LOGGER.error("Failed to register argument type {}. Skipping registration.",
+ argument.getName());
+ }
+ });
+
// Register features
ReflectionUtils.getFeatures().forEach(feature ->
diff --git a/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/BlockColorSerializer.java b/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/BlockColorSerializer.java
index a90c2a85..b79060f0 100644
--- a/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/BlockColorSerializer.java
+++ b/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/BlockColorSerializer.java
@@ -1,5 +1,7 @@
package tools.redstone.redstonetools.features.arguments.serializers;
+import net.minecraft.command.CommandRegistryAccess;
+import net.minecraft.command.argument.serialize.ArgumentSerializer;
import tools.redstone.redstonetools.utils.BlockColor;
public class BlockColorSerializer extends EnumSerializer {
@@ -12,4 +14,27 @@ private BlockColorSerializer() {
public static BlockColorSerializer blockColor() {
return INSTANCE;
}
+
+ public static class Serializer
+ extends GenericArgumentType.Serializer {
+
+ public final class Properties
+ implements ArgumentSerializer.ArgumentTypeProperties {
+
+ @Override
+ public BlockColorSerializer createType(CommandRegistryAccess var1) {
+ return blockColor();
+ }
+
+ @Override
+ public ArgumentSerializer getSerializer() {
+ return new Serializer();
+ }
+ }
+
+ @Override
+ public Properties getArgumentTypeProperties(BlockColorSerializer var1) {
+ return new Properties();
+ }
+ }
}
diff --git a/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/BoolSerializer.java b/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/BoolSerializer.java
index 02fb39e5..81c400e1 100644
--- a/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/BoolSerializer.java
+++ b/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/BoolSerializer.java
@@ -3,6 +3,9 @@
import com.mojang.brigadier.arguments.ArgumentType;
import com.mojang.brigadier.arguments.BoolArgumentType;
+import net.minecraft.command.CommandRegistryAccess;
+import net.minecraft.command.argument.serialize.ArgumentSerializer;
+
public class BoolSerializer extends StringBrigadierSerializer {
private static final BoolSerializer INSTANCE = new BoolSerializer(BoolArgumentType.bool());
@@ -20,4 +23,27 @@ public String serialize(Boolean value) {
return String.valueOf(value);
}
+ public static class Serializer
+ extends GenericArgumentType.Serializer {
+
+ public final class Properties
+ implements ArgumentSerializer.ArgumentTypeProperties {
+
+ @Override
+ public BoolSerializer createType(CommandRegistryAccess var1) {
+ return bool();
+ }
+
+ @Override
+ public ArgumentSerializer getSerializer() {
+ return new Serializer();
+ }
+ }
+
+ @Override
+ public Properties getArgumentTypeProperties(BoolSerializer serializer) {
+ return new Properties();
+ }
+ }
+
}
diff --git a/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/CollectionSerializer.java b/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/CollectionSerializer.java
index 16bb16b7..c01c7ef6 100644
--- a/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/CollectionSerializer.java
+++ b/src/main/java/tools/redstone/redstonetools/features/arguments/serializers/CollectionSerializer.java
@@ -6,6 +6,9 @@
import com.mojang.brigadier.suggestion.Suggestions;
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
+import net.minecraft.command.CommandRegistryAccess;
+import net.minecraft.command.argument.serialize.ArgumentSerializer;
+
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.function.Function;
@@ -18,8 +21,7 @@
* @param The collection type.
*/
public class CollectionSerializer>
- extends GenericArgumentType>
-{
+ extends GenericArgumentType> {
public static CollectionSerializer> listOf(GenericArgumentType element) {
return new CollectionSerializer<>(List.class, element, ArrayList::new);
@@ -39,8 +41,8 @@ public static CollectionSerializer> setOf(GenericArgumentType clazz,
- GenericArgumentType elementType,
- Function, C> collectionFactory) {
+ GenericArgumentType elementType,
+ Function, C> collectionFactory) {
super((Class) clazz);
this.elementType = (GenericArgumentType) elementType;
this.collectionFactory = collectionFactory;
@@ -116,7 +118,8 @@ public CompletableFuture listSuggestions(CommandContext cont
int oldCursor = inputParser.getCursor();
try {
elementType.deserialize(inputParser);
- } catch (CommandSyntaxException ignored) { }
+ } catch (CommandSyntaxException ignored) {
+ }
if (oldCursor == inputParser.getCursor())
break;
inputParser.skipWhitespace();
@@ -173,4 +176,28 @@ public List