Skip to content

Commit

Permalink
Added custom catalysts
Browse files Browse the repository at this point in the history
Can now add any block as a catalyst in configs
  • Loading branch information
uberifix committed Feb 20, 2020
1 parent 64fe51b commit efb7ba1
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 3 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.15.2-1.0.0"
version = "1.15.2-1.1.0"
group = "network.pxl8.stonecatalysts"
archivesBaseName = "stonecatalysts"

Expand Down
10 changes: 8 additions & 2 deletions src/main/java/network/pxl8/stonecatalysts/StoneCatalysts.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -22,4 +24,8 @@ public StoneCatalysts() {
}

private void setup(final 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,15 @@ 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
28 changes: 28 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,11 +4,17 @@

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.common.Mod;
import net.minecraftforge.registries.ForgeRegistries;
import network.pxl8.stonecatalysts.config.Configuration;
import network.pxl8.stonecatalysts.lib.LibMeta;

import java.util.ArrayList;
import java.util.List;
//import vazkii.quark.world.module.NewStoneTypesModule;


Expand Down Expand Up @@ -48,5 +54,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 efb7ba1

Please sign in to comment.