From 05adc662b275b4aa1bd11fdf1e40826d82208778 Mon Sep 17 00:00:00 2001 From: uberifix Date: Thu, 20 Feb 2020 14:43:22 -0500 Subject: [PATCH] Added custom catalysts config Can now add any block as a catalyst in the config --- build.gradle | 2 +- .../pxl8/stonecatalysts/StoneCatalysts.java | 12 ++++++--- .../stonecatalysts/config/Configuration.java | 17 ++++++++++++ .../pxl8/stonecatalysts/event/StoneGen.java | 27 +++++++++++++++++++ 4 files changed, 53 insertions(+), 5 deletions(-) diff --git a/build.gradle b/build.gradle index 56d7e8a..7c5d7a2 100644 --- a/build.gradle +++ b/build.gradle @@ -13,7 +13,7 @@ apply plugin: 'net.minecraftforge.gradle' apply plugin: 'eclipse' apply plugin: 'maven-publish' -version = "1.14.4-1.0.0" +version = "1.14.4-1.1.0" group = "network.pxl8.stonecatalysts" archivesBaseName = "stonecatalysts" diff --git a/src/main/java/network/pxl8/stonecatalysts/StoneCatalysts.java b/src/main/java/network/pxl8/stonecatalysts/StoneCatalysts.java index abc5830..a40974a 100644 --- a/src/main/java/network/pxl8/stonecatalysts/StoneCatalysts.java +++ b/src/main/java/network/pxl8/stonecatalysts/StoneCatalysts.java @@ -5,15 +5,17 @@ import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.config.ModConfig; import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; -import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; +import net.minecraftforge.fml.event.server.FMLServerStartingEvent; import net.minecraftforge.fml.loading.FMLPaths; import network.pxl8.stonecatalysts.config.Configuration; +import network.pxl8.stonecatalysts.event.StoneGen; import network.pxl8.stonecatalysts.lib.LibMeta; @Mod("stonecatalysts") public class StoneCatalysts { public StoneCatalysts() { - FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup); + Mod.EventBusSubscriber.Bus.FORGE.bus().get().addListener(this::setup); + Mod.EventBusSubscriber.Bus.FORGE.bus().get().addListener(this::serverStart); MinecraftForge.EVENT_BUS.register(this); @@ -21,7 +23,9 @@ public StoneCatalysts() { Configuration.loadConfig(Configuration.COMMON_CONFIG, FMLPaths.CONFIGDIR.get().resolve("stonecatalysts-common.toml")); } - private void setup(final FMLCommonSetupEvent event) { - LibMeta.LOG.debug("StoneCatalysts"); + private void setup(FMLCommonSetupEvent event) { } + + private void serverStart(FMLServerStartingEvent event) { + StoneGen.getCustomCatalysts(); } } diff --git a/src/main/java/network/pxl8/stonecatalysts/config/Configuration.java b/src/main/java/network/pxl8/stonecatalysts/config/Configuration.java index 410f159..399356b 100644 --- a/src/main/java/network/pxl8/stonecatalysts/config/Configuration.java +++ b/src/main/java/network/pxl8/stonecatalysts/config/Configuration.java @@ -7,6 +7,8 @@ import network.pxl8.stonecatalysts.lib.LibMeta; import java.nio.file.Path; +import java.util.ArrayList; +import java.util.List; @Mod.EventBusSubscriber public class Configuration { @@ -18,11 +20,16 @@ public class Configuration { public static ForgeConfigSpec.BooleanValue ENABLE_QUARK_COMPAT; + public static ForgeConfigSpec.ConfigValue> CUSTOM_CATALYSTS; + public static ForgeConfigSpec.BooleanValue DEBUG_MESSAGES; + static { COMMON_BUILDER.push("base_config"); setupBaseConfig(); COMMON_BUILDER.push("compat_config"); setupCompatConfig(); + COMMON_BUILDER.push("custom_config"); + setupCustomConfig(); COMMON_CONFIG = COMMON_BUILDER.build(); } @@ -40,6 +47,16 @@ private static void setupCompatConfig() { COMMON_BUILDER.pop(); } + private static void setupCustomConfig() { + List catalysts = new ArrayList<>(); + + CUSTOM_CATALYSTS = COMMON_BUILDER.comment("Add additional catalysts", "Usage: Add namespaced ids in \"\" seperated by commas", "Example: [\"minecraft:netherrack\", \"quark:brimstone\"]") + .define("CUSTOM_CATALYSTS", catalysts); + DEBUG_MESSAGES = COMMON_BUILDER.comment("Prints debug messages to the log for each custom catalyst added") + .define("DEBUG_MESSAGES", true); + COMMON_BUILDER.pop(); + } + public static void loadConfig(ForgeConfigSpec spec, Path path) { final CommentedFileConfig configData = CommentedFileConfig.builder(path) .sync() diff --git a/src/main/java/network/pxl8/stonecatalysts/event/StoneGen.java b/src/main/java/network/pxl8/stonecatalysts/event/StoneGen.java index 28f7ef0..1ae4547 100644 --- a/src/main/java/network/pxl8/stonecatalysts/event/StoneGen.java +++ b/src/main/java/network/pxl8/stonecatalysts/event/StoneGen.java @@ -4,15 +4,20 @@ import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; +import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; import net.minecraftforge.event.world.BlockEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.ModList; import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.registries.ForgeRegistries; import network.pxl8.stonecatalysts.config.Configuration; + import network.pxl8.stonecatalysts.lib.LibMeta; import vazkii.quark.world.module.NewStoneTypesModule; +import java.util.ArrayList; +import java.util.List; @Mod.EventBusSubscriber public class StoneGen { @@ -50,5 +55,27 @@ private static void doReplacements(BlockEvent.FluidPlaceBlockEvent event, BlockS replaceBlock(event, catalyst, NewStoneTypesModule.slateBlock.getDefaultState()); replaceBlock(event, catalyst, NewStoneTypesModule.basaltBlock.getDefaultState()); } + + if(!StoneGen.customCatalysts.isEmpty()) { + for(BlockState block : StoneGen.customCatalysts) { + replaceBlock(event, catalyst, block); + } + } + } + + private static List customCatalysts = new ArrayList<>(); + + public static void getCustomCatalysts() { + if(!Configuration.CUSTOM_CATALYSTS.get().isEmpty()) { + for(String catalyst : Configuration.CUSTOM_CATALYSTS.get()) { + Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(catalyst)); + if(!block.equals(Blocks.AIR)) { + customCatalysts.add(block.getDefaultState()); + if(Configuration.DEBUG_MESSAGES.get()) { LibMeta.LOG.debug("Added custom catalyst: " + block); } + } else { + LibMeta.LOG.warn("Could not find catalyst from namespaced id: " + catalyst); + } + } + } } }