diff --git a/gradle.properties b/gradle.properties index 2e73f25..2114f64 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,7 +9,7 @@ yarn_mappings=1.20.2+build.1 loader_version=0.14.22 # Mod Properties -mod_version=0.4.0 +mod_version=0.4.1 maven_group=com.provismet archives_base_name=vmc-mc diff --git a/src/main/java/com/provismet/vmcmc/config/ClothVMC.java b/src/main/java/com/provismet/vmcmc/config/ClothVMC.java index d8d0a52..6af2316 100644 --- a/src/main/java/com/provismet/vmcmc/config/ClothVMC.java +++ b/src/main/java/com/provismet/vmcmc/config/ClothVMC.java @@ -31,6 +31,13 @@ public static Screen build (Screen parent) { .build() ); + general.addEntry(entryBuilder.startBooleanToggle(Text.translatable("entry.vmcmc.general.compat_identifiers"), Config.shouldUseCompatibilityIds()) + .setDefaultValue(false) + .setTooltip(Text.translatable("tooltip.vmcmc.general.compat_identifiers")) + .setSaveConsumer(newValue -> Config.setCompatibilityIdMode(newValue)) + .build() + ); + builder.setSavingRunnable(() -> { Config.saveJSON(); PacketSender.initPort(Config.getIP(), Config.getPort()); diff --git a/src/main/java/com/provismet/vmcmc/config/Config.java b/src/main/java/com/provismet/vmcmc/config/Config.java index afe41fc..9602b94 100644 --- a/src/main/java/com/provismet/vmcmc/config/Config.java +++ b/src/main/java/com/provismet/vmcmc/config/Config.java @@ -8,13 +8,16 @@ import com.provismet.vmcmc.ClientVMC; import com.provismet.vmcmc.vmc.PacketSender; +import net.minecraft.util.Identifier; import net.minecraft.util.Pair; public class Config { private static final String HOST = "host"; private static final String PORT = "port"; + private static final String COMPAT_IDENTIFIERS_LABEL = "compatibility_identifiers"; private static final String FILEPATH = "config/vmc-mc.json"; + private static boolean useCompatIds = false; private static String host = PacketSender.LOCALHOST; private static int port = PacketSender.DEFAULT_PORT; @@ -35,6 +38,10 @@ public static Pair readJSON () { port = parser.nextInt(); break; + case COMPAT_IDENTIFIERS_LABEL: + useCompatIds = parser.nextBoolean(); + break; + default: break; } @@ -45,20 +52,21 @@ public static Pair readJSON () { catch (FileNotFoundException e) { ClientVMC.LOGGER.warn("Config not found, creating default config."); saveJSON(); - return new Pair(PacketSender.LOCALHOST, PacketSender.DEFAULT_PORT); + return new Pair<>(PacketSender.LOCALHOST, PacketSender.DEFAULT_PORT); } catch (Exception e) { ClientVMC.LOGGER.warn("Config could not be read, using default parameters.", e); - return new Pair(PacketSender.LOCALHOST, PacketSender.DEFAULT_PORT); + return new Pair<>(PacketSender.LOCALHOST, PacketSender.DEFAULT_PORT); } } public static void saveJSON () { try { FileWriter writer = new FileWriter(FILEPATH); - String simpleJSON = String.format("{\n\t\"%s\": \"%s\",\n\t\"%s\": %d\n}", + String simpleJSON = String.format("{\n\t\"%s\": \"%s\",\n\t\"%s\": %d,\n\t\"%s\": %b\n}", HOST, host, - PORT, port + PORT, port, + COMPAT_IDENTIFIERS_LABEL, useCompatIds ); writer.write(simpleJSON); writer.close(); @@ -68,6 +76,19 @@ public static void saveJSON () { } } + public static boolean shouldUseCompatibilityIds () { + return useCompatIds; + } + + public static void setCompatibilityIdMode (boolean shouldUseCompat) { + useCompatIds = shouldUseCompat; + } + + public static String getBlendName (Identifier blendshape) { + if (useCompatIds) return blendshape.toString().replace(':', '_'); + return blendshape.toString(); + } + public static String getIP () { return host; } diff --git a/src/main/java/com/provismet/vmcmc/vmc/CaptureRegistry.java b/src/main/java/com/provismet/vmcmc/vmc/CaptureRegistry.java index 2c2e3b0..941de78 100644 --- a/src/main/java/com/provismet/vmcmc/vmc/CaptureRegistry.java +++ b/src/main/java/com/provismet/vmcmc/vmc/CaptureRegistry.java @@ -7,6 +7,7 @@ import com.illposed.osc.OSCPacket; import com.provismet.vmcmc.ClientVMC; +import com.provismet.vmcmc.config.Config; import com.provismet.vmcmc.utility.HealthTracker; import net.fabricmc.api.EnvType; @@ -33,7 +34,7 @@ public class CaptureRegistry { private static final HashMap BLENDSTORE_REGISTRY = new HashMap<>(); public static BlendStore getBlendStore (Identifier identifier) { - return BLENDSTORE_REGISTRY.get(identifier.toString()); + return BLENDSTORE_REGISTRY.get(Config.getBlendName(identifier)); } public static boolean containsKey (String key) { @@ -41,20 +42,20 @@ public static boolean containsKey (String key) { } public static boolean containsKey (Identifier key) { - return containsKey(key.toString()); + return containsKey(Config.getBlendName(key)); } /** * Registers a callback that generates a BlendShape. Minecraft identifiers are used to softly-enforce unique names. - * - * It is recommend, but not required, that callbacks have their output bound between 0 and 1. + *

+ * It is recommended, but not required, that callbacks have their output bound between 0 and 1. * * @param identifier The ID for the BlendShape. Note: This will be converted into a string when being sent over OSC. * @param callback A function that uses the client to output a float. */ public static void registerBlendShape (Identifier identifier, Function callback) { - if (containsKey(identifier)) ClientVMC.LOGGER.error("Duplicate BlendShape register attempt: " + identifier.toString()); - else BLEND_REGISTRY.put(identifier.toString(), callback); + if (containsKey(identifier)) ClientVMC.LOGGER.error("Duplicate BlendShape register attempt: " + Config.getBlendName(identifier)); + else BLEND_REGISTRY.put(Config.getBlendName(identifier), callback); } /** @@ -72,8 +73,8 @@ public static void registerBlendShape (String path, Function