From 19da9d70e3b83022300983182a5716827208fde0 Mon Sep 17 00:00:00 2001 From: Astoria Date: Sat, 8 Apr 2023 12:58:45 -0500 Subject: [PATCH] BREAKING UPDATE THIS WILL BREAK YOUR SAVES All ID's are now configurable. This does mean ids have changed, such as to make ids make more logical sense when configured. --- build.gradle | 21 ++++++ .../net/brokenmoon/afloydwiremod/WireMod.java | 32 +++++---- .../afloydwiremod/WiremodConfig.java | 72 +++++++++++++++++++ .../assets/afloydwiremod/config.toml | 20 ++++++ 4 files changed, 130 insertions(+), 15 deletions(-) create mode 100644 src/main/java/net/brokenmoon/afloydwiremod/WiremodConfig.java create mode 100644 src/main/resources/assets/afloydwiremod/config.toml diff --git a/build.gradle b/build.gradle index 2908f1f..b6be34d 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,6 @@ plugins { id 'babric-loom' version '0.12-SNAPSHOT' + id 'com.github.johnrengelman.shadow' version '7.1.2' id 'java' } @@ -7,6 +8,23 @@ group = project.mod_group archivesBaseName = project.mod_name version = project.mod_version +//Begin shadowing weirdness +configurations { + shade +} + +shadowJar { + archiveClassifier.set('shadow') + configurations = [project.configurations.shade] +} +tasks.assemble.dependsOn tasks.shadowJar + +remapJar { + dependsOn(shadowJar) + inputFile.set(shadowJar.archiveFile) +} +//End shadowing weirdness + loom { gluedMinecraftJar() noIntermediateMappings() @@ -62,6 +80,9 @@ dependencies { modImplementation "org.slf4j:slf4j-api:1.8.0-beta4" modImplementation "org.apache.logging.log4j:log4j-slf4j18-impl:2.16.0" + //TOML + modImplementation include(shadow('com.moandjiezana.toml:toml4j:0.7.2')) + } java { diff --git a/src/main/java/net/brokenmoon/afloydwiremod/WireMod.java b/src/main/java/net/brokenmoon/afloydwiremod/WireMod.java index 28ebe03..5512c83 100644 --- a/src/main/java/net/brokenmoon/afloydwiremod/WireMod.java +++ b/src/main/java/net/brokenmoon/afloydwiremod/WireMod.java @@ -23,28 +23,30 @@ import turniplabs.halplibe.helper.ItemHelper; public class WireMod implements ModInitializer { - public WireMod(){ - AccessorPacket.callAddIdClassMapping(109, true, true, WiremodProgrammerGuiPacket.class); - AccessorPacket.callAddIdClassMapping(110, true, true, WiremodProgrammerPacket.class); - AccessorPacket.callAddIdClassMapping(111, true, true, WiremodWiringGuiPacket.class); - AccessorPacket.callAddIdClassMapping(112, true, true, WiremodPacketSyncIO.class); - AccessorPacket.callAddIdClassMapping(113, true, true, WiremodWiringPacket.class); - AccessorPacket.callAddIdClassMapping(114, true, true, WiremodWireGuiPacket.class); - AccessorPacket.callAddIdClassMapping(115, true, true, WiremodSettingsPacket.class); - } public static final String MOD_ID = "afloydwiremod"; public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID); + public static final WiremodConfig config = new WiremodConfig(); + + public WireMod(){ + AccessorPacket.callAddIdClassMapping(config.programmerGuiPacket, true, true, WiremodProgrammerGuiPacket.class); + AccessorPacket.callAddIdClassMapping(config.programmingPacket, true, true, WiremodProgrammerPacket.class); + AccessorPacket.callAddIdClassMapping(config.wiringGuiPacket, true, true, WiremodWiringGuiPacket.class); + AccessorPacket.callAddIdClassMapping(config.syncPacket, true, true, WiremodPacketSyncIO.class); + AccessorPacket.callAddIdClassMapping(config.wiringPacket, true, true, WiremodWiringPacket.class); + AccessorPacket.callAddIdClassMapping(config.wiringSettingsPacket, true, true, WiremodWireGuiPacket.class); + AccessorPacket.callAddIdClassMapping(config.chipSettingsPacket, true, true, WiremodSettingsPacket.class); + } - public static Block ChipTile = BlockHelper.createBlock(MOD_ID, new ChipTile(905, Material.iron), "chipTile", "chip.png", Block.soundMetalFootstep,1.5f, 6f, 0 ); + public static Block ChipTile = BlockHelper.createBlock(MOD_ID, new ChipTile(config.chipTileID, Material.iron), "chipTile", "chip.png", Block.soundMetalFootstep,1.5f, 6f, 0 ); - public static Item ToolProgrammer = ItemHelper.createItem(MOD_ID, new ToolProgrammer(906), "toolProgrammer", "progtool.png"); - public static ToolWiring ToolWiringClass = new ToolWiring(907); + public static Item ToolProgrammer = ItemHelper.createItem(MOD_ID, new ToolProgrammer(config.programmerItemID), "toolProgrammer", "progtool.png"); + public static ToolWiring ToolWiringClass = new ToolWiring(config.wiringItemID); public static Item ToolWiring = ItemHelper.createItem(MOD_ID, ToolWiringClass, "toolWiring", "wiretool.png"); - public static Block LinkTileInactive = BlockHelper.createBlock(MOD_ID, new RedstoneLinkTile(908, Material.iron, false), "linkTile", "linkOff.png", Block.soundStoneFootstep, 1.5f, 6f, 0); - public static Block LinkTileActive = BlockHelper.createBlock(MOD_ID, new RedstoneLinkTile(909, Material.iron, true), "linkTile", "linkOn.png", Block.soundStoneFootstep, 1.5f, 6f, 0); - public static Block ScreenTile = BlockHelper.createBlock(MOD_ID, new DisplayTile(910, Material.glass), "displayTile", "display.png", Block.soundGlassFootstep, 1.5f, 6f, 0); + public static Block LinkTileInactive = BlockHelper.createBlock(MOD_ID, new RedstoneLinkTile(config.linkTileInactiveID, Material.iron, false), "linkTile", "linkOff.png", Block.soundStoneFootstep, 1.5f, 6f, 0); + public static Block LinkTileActive = BlockHelper.createBlock(MOD_ID, new RedstoneLinkTile(config.linkTileActiveID, Material.iron, true), "linkTile", "linkOn.png", Block.soundStoneFootstep, 1.5f, 6f, 0); + public static Block ScreenTile = BlockHelper.createBlock(MOD_ID, new DisplayTile(config.displayTileID, Material.glass), "displayTile", "display.png", Block.soundGlassFootstep, 1.5f, 6f, 0); @Override public void onInitialize() { diff --git a/src/main/java/net/brokenmoon/afloydwiremod/WiremodConfig.java b/src/main/java/net/brokenmoon/afloydwiremod/WiremodConfig.java new file mode 100644 index 0000000..8e1fcbb --- /dev/null +++ b/src/main/java/net/brokenmoon/afloydwiremod/WiremodConfig.java @@ -0,0 +1,72 @@ +package net.brokenmoon.afloydwiremod; +import com.moandjiezana.toml.Toml; + +import java.io.*; + +import static net.brokenmoon.afloydwiremod.WireMod.LOGGER; + +public class WiremodConfig { + + //Packet ID's + public int programmerGuiPacket; + public int programmingPacket; + public int wiringGuiPacket; + public int syncPacket; + public int wiringPacket; + public int wiringSettingsPacket; + public int chipSettingsPacket; + public int programmerItemID; + public int wiringItemID; + public int chipTileID; + public int linkTileInactiveID; + public int linkTileActiveID; + public int displayTileID; + + + public WiremodConfig(){ + Toml toml = new Toml().read(this.getConfig()); + //Packets + programmingPacket = toml.getLong("ids.packet.programming", (long)109).intValue(); + programmerGuiPacket = toml.getLong("ids.packet.programmerGui", (long)110).intValue(); + wiringPacket = toml.getLong("ids.packet.wiring", (long)111).intValue(); + wiringGuiPacket = toml.getLong("ids.packet.wiringGui", (long)112).intValue(); + wiringSettingsPacket = toml.getLong("ids.packet.wiringSettingsGui", (long)113).intValue(); + syncPacket = toml.getLong("ids.packet.sync", (long)114).intValue(); + chipSettingsPacket = toml.getLong("ids.packet.chipSettingsGui", (long)115).intValue(); + //Items + programmerItemID = toml.getLong("ids.item.programmingTool", (long)906).intValue(); + wiringItemID = toml.getLong("ids.item.wiringTool", (long)907).intValue(); + //Tiles + chipTileID = toml.getLong("ids.tile.chipTile", (long)905).intValue(); + linkTileInactiveID = toml.getLong("ids.tile.linkTileInactive", (long)906).intValue(); + linkTileActiveID = toml.getLong("ids.tile.linkTileActive", (long)907).intValue(); + displayTileID = toml.getLong("ids.tile.displayTile", (long)908).intValue(); + + } + public static File getConfig() { + File config = new File("config/AWM.toml"); + if (!config.exists()) { + LOGGER.warn("Config For AWM Not Found! Creating new config based upon default :)"); + InputStream in; + OutputStream out; + try { + File configDir = new File("config"); + if (!configDir.exists()) + configDir.mkdir(); + in = WireMod.class.getClassLoader().getResourceAsStream("assets/afloydwiremod/config.toml"); + out = new FileOutputStream(config); + byte[] buffer = new byte[1024]; + int length; + while ((length = in.read(buffer)) > 0) { + out.write(buffer, 0, length); + } + return getConfig(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } else { + LOGGER.info("Config for AWM loaded!"); + return config; + } + } +} diff --git a/src/main/resources/assets/afloydwiremod/config.toml b/src/main/resources/assets/afloydwiremod/config.toml new file mode 100644 index 0000000..71f87d6 --- /dev/null +++ b/src/main/resources/assets/afloydwiremod/config.toml @@ -0,0 +1,20 @@ +[ids] + +[ids.packet] +chipTile = 905 +linkTileInactive = 906 +linkTileActive = 907 +displayTile = 908 + +[ids.item] +programmingTool = 909 +wiringTool = 910 + +[ids.tile] +programming = 109 +programmerGui = 110 +wiring = 111 +wiringGui = 112 +wiringSettingsGui = 113 +sync = 114 +chipSettingsGui = 115 \ No newline at end of file