Skip to content

Commit

Permalink
Added custom catalysts config
Browse files Browse the repository at this point in the history
Can now add any block as a catalyst in the config
  • Loading branch information
uberifix committed Feb 20, 2020
1 parent ca0e8cc commit 05adc66
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 5 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
12 changes: 8 additions & 4 deletions src/main/java/network/pxl8/stonecatalysts/StoneCatalysts.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,27 @@
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);

ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, Configuration.COMMON_CONFIG);
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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -18,11 +20,16 @@ public class Configuration {

public static ForgeConfigSpec.BooleanValue ENABLE_QUARK_COMPAT;

public static ForgeConfigSpec.ConfigValue<List<String>> 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();
}

Expand All @@ -40,6 +47,16 @@ private static void setupCompatConfig() {
COMMON_BUILDER.pop();
}

private static void setupCustomConfig() {
List<String> 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()
Expand Down
27 changes: 27 additions & 0 deletions src/main/java/network/pxl8/stonecatalysts/event/StoneGen.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<BlockState> 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);
}
}
}
}
}

0 comments on commit 05adc66

Please sign in to comment.