diff --git a/build.gradle b/build.gradle index 2908f1f..3b3e6e9 100644 --- a/build.gradle +++ b/build.gradle @@ -62,6 +62,9 @@ dependencies { modImplementation "org.slf4j:slf4j-api:1.8.0-beta4" modImplementation "org.apache.logging.log4j:log4j-slf4j18-impl:2.16.0" + //TOML + implementation 'com.moandjiezana.toml:toml4j:0.7.2' + } java { diff --git a/src/main/java/net/brokenmoon/afloydironchest/IronChestMain.java b/src/main/java/net/brokenmoon/afloydironchest/IronChestMain.java index 7306436..eaaa607 100644 --- a/src/main/java/net/brokenmoon/afloydironchest/IronChestMain.java +++ b/src/main/java/net/brokenmoon/afloydironchest/IronChestMain.java @@ -1,12 +1,12 @@ package net.brokenmoon.afloydironchest; +import com.moandjiezana.toml.Toml; import net.brokenmoon.afloydironchest.blocks.DiamondChest; import net.brokenmoon.afloydironchest.blocks.IronChest; import net.brokenmoon.afloydironchest.blocks.GoldChest; import net.brokenmoon.afloydironchest.blocks.SteelChest; import net.fabricmc.api.ModInitializer; import net.minecraft.src.Block; -import net.minecraft.src.BlockChest; import net.minecraft.src.Item; import net.minecraft.src.Material; import org.slf4j.Logger; @@ -14,32 +14,52 @@ import org.slf4j.LoggerFactory; import turniplabs.halplibe.helper.BlockHelper; import turniplabs.halplibe.helper.RecipeHelper; +import java.io.*; +import java.net.URISyntaxException; +import java.net.URL; + public class IronChestMain implements ModInitializer { public static final String MOD_ID = "ironchest"; public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID); - public static Block IronChest = BlockHelper.createBlock(MOD_ID, new IronChest(900, Material.iron), "ironchest", - "ironchesttop.png", "ironchestbottom.png", - "ironchestfront.png", "ironchestside.png", "ironchestside.png", "ironchestside.png", - Block.soundMetalFootstep, 5, 6, 0); - public static Block GoldChest = BlockHelper.createBlock(MOD_ID, new GoldChest(901, Material.iron), "goldchest", - "goldchesttop.png", "goldchestbottom.png", - "goldchestfront.png", "goldchestside.png", "goldchestside.png", "goldchestside.png", - Block.soundMetalFootstep, 5, 6, 0); - public static Block DiamondChest = BlockHelper.createBlock(MOD_ID, new DiamondChest(902, Material.iron), "diamondchest", - "diamondchesttop.png", "diamondchestbottom.png", - "diamondchestfront.png", "diamondchestside.png", "diamondchestside.png", "diamondchestside.png", - Block.soundMetalFootstep, 5, 6, 0); - public static Block SteelChest = BlockHelper.createBlock(MOD_ID, new SteelChest(903, Material.iron), "steelchest", - "steelchesttop.png", "steelchestbottom.png", - "steelchestfront.png", "steelchestside.png", "steelchestside.png", "steelchestside.png", - Block.soundMetalFootstep, 5, 6, 0); + public static Block IronChest; + public static Block GoldChest; + public static Block DiamondChest; + public static Block SteelChest; @Override public void onInitialize() { LOGGER.info("AFloydIronChest initialized."); + //Config + Toml toml = new Toml().read(this.getConfig()); + int ironChestId = toml.getLong("ids.ironChestID").intValue(); + int goldChestId = toml.getLong("ids.goldChestID").intValue(); + int diamondChestId = toml.getLong("ids.diamondChestID").intValue(); + int steelChestId = toml.getLong("ids.steelChestID").intValue(); + + + //Blocks + IronChest = BlockHelper.createBlock(MOD_ID, new IronChest(ironChestId, Material.iron), "ironchest", + "ironchesttop.png", "ironchestbottom.png", + "ironchestfront.png", "ironchestside.png", "ironchestside.png", "ironchestside.png", + Block.soundMetalFootstep, 5, 6, 0); + + GoldChest = BlockHelper.createBlock(MOD_ID, new GoldChest(goldChestId, Material.iron), "goldchest", + "goldchesttop.png", "goldchestbottom.png", + "goldchestfront.png", "goldchestside.png", "goldchestside.png", "goldchestside.png", + Block.soundMetalFootstep, 5, 6, 0); + + DiamondChest = BlockHelper.createBlock(MOD_ID, new DiamondChest(diamondChestId, Material.iron), "diamondchest", + "diamondchesttop.png", "diamondchestbottom.png", + "diamondchestfront.png", "diamondchestside.png", "diamondchestside.png", "diamondchestside.png", + Block.soundMetalFootstep, 5, 6, 0); + SteelChest = BlockHelper.createBlock(MOD_ID, new SteelChest(steelChestId, Material.iron), "steelchest", + "steelchesttop.png", "steelchestbottom.png", + "steelchestfront.png", "steelchestside.png", "steelchestside.png", "steelchestside.png", + Block.soundMetalFootstep, 5, 6, 0); + //Recipes RecipeHelper.Crafting.createRecipe(IronChest, 1, new Object[]{ "AAA", "ABA", @@ -76,4 +96,42 @@ public class IronChestMain implements ModInitializer { 'B', GoldChest }); } + + public File getConfig(){ + File config = new File("config/AstoriaIronChest.toml"); + if (!config.exists()) { + LOGGER.warn("Config For afloydironchest Not Found! Creating new config based upon default :)"); + InputStream in; + OutputStream out; + try { + in = new FileInputStream(getDefaultConfig()); + 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 afloydironchest loaded!"); + return config; + } + } + + public File getDefaultConfig() { + URL defaultConfig = getClass().getClassLoader().getResource("assets/ironchest/config.toml"); + if (defaultConfig == null) { + LOGGER.warn("Default Config For afloydironchest Not Found! REAL BAD."); + } else { + try { + return new File(defaultConfig.toURI()); + } catch (URISyntaxException e) { + throw new RuntimeException(e); + } + } + return null; + } } diff --git a/src/main/resources/assets/ironchest/config.toml b/src/main/resources/assets/ironchest/config.toml new file mode 100644 index 0000000..f04f9fe --- /dev/null +++ b/src/main/resources/assets/ironchest/config.toml @@ -0,0 +1,5 @@ +[ids] +ironChestID = 900 +goldChestID = 901 +diamondChestID = 902 +steelChestID = 903 \ No newline at end of file