diff options
author | Anthony Hilyard <anthony.hilyard@gmail.com> | 2022-01-25 09:18:04 -0800 |
---|---|---|
committer | Anthony Hilyard <anthony.hilyard@gmail.com> | 2022-01-25 09:18:04 -0800 |
commit | 0cd83156930cf320578e09fafa17069bedd8230f (patch) | |
tree | 63e9d0322326126d4beaa497e06050ba905f555c /src/main/java/com/anthonyhilyard/iceberg/mixin/ConfigMenusForgeServerConfigUploaderMixin.java | |
parent | 7a3df325b5bb294c2836082f58b719c70792ed61 (diff) | |
download | Iceberg-0cd83156930cf320578e09fafa17069bedd8230f.tar.gz Iceberg-0cd83156930cf320578e09fafa17069bedd8230f.tar.bz2 Iceberg-0cd83156930cf320578e09fafa17069bedd8230f.zip |
Rewrote new config system, added support for Config Menus for Forge mod.
Diffstat (limited to 'src/main/java/com/anthonyhilyard/iceberg/mixin/ConfigMenusForgeServerConfigUploaderMixin.java')
-rw-r--r-- | src/main/java/com/anthonyhilyard/iceberg/mixin/ConfigMenusForgeServerConfigUploaderMixin.java | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/main/java/com/anthonyhilyard/iceberg/mixin/ConfigMenusForgeServerConfigUploaderMixin.java b/src/main/java/com/anthonyhilyard/iceberg/mixin/ConfigMenusForgeServerConfigUploaderMixin.java new file mode 100644 index 0000000..003251f --- /dev/null +++ b/src/main/java/com/anthonyhilyard/iceberg/mixin/ConfigMenusForgeServerConfigUploaderMixin.java @@ -0,0 +1,40 @@ +package com.anthonyhilyard.iceberg.mixin; + +import java.io.ByteArrayOutputStream; + +import com.anthonyhilyard.iceberg.util.ConfigMenusForgeHelper; +import com.electronwill.nightconfig.toml.TomlFormat; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import fuzs.configmenusforge.ConfigMenusForge; +import fuzs.configmenusforge.client.util.ModConfigSync; +import fuzs.configmenusforge.client.util.ServerConfigUploader; +import fuzs.configmenusforge.network.client.message.C2SSendConfigMessage; +import net.minecraft.client.Minecraft; +import net.minecraftforge.fml.config.ModConfig; + +@Mixin(ServerConfigUploader.class) +public class ConfigMenusForgeServerConfigUploaderMixin +{ + @Inject(method = "saveAndUpload", at = @At("HEAD"), remap = false, cancellable = true) + private static void saveAndUpload(ModConfig config, CallbackInfo info) + { + ConfigMenusForgeHelper.save(config.getSpec()); + ModConfigSync.fireReloadingEvent(config); + if (config.getType() == ModConfig.Type.SERVER) + { + final Minecraft minecraft = Minecraft.getInstance(); + if (minecraft.getConnection() != null && !minecraft.isLocalServer()) + { + final ByteArrayOutputStream stream = new ByteArrayOutputStream(); + TomlFormat.instance().createWriter().write(config.getConfigData(), stream); + ConfigMenusForge.NETWORK.sendToServer(new C2SSendConfigMessage(config.getFileName(), stream.toByteArray())); + } + } + info.cancel(); + } +} |