Can anyone help me with this problem I have?
Basically I want my ores to be configurable so you can choose whether to generate them or not and with the code I have at the moment (see below) this is not working as when I set it to false in the config it still generates the ore.
So if there's a certain way to do this then please let me know as this is beginning to bug me .
Ore Gen:
package common.industrialistechnologia.utility_libraries;
import java.util.Random;
import common.industrialistechnologia.initialization.core.BlocksCore;
import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.util.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.chunk.IChunkProvider;
import net.minecraft.world.gen.feature.WorldGenMinable;
import net.minecraft.world.gen.feature.WorldGenerator;
import net.minecraftforge.fml.common.IWorldGenerator;
import net.minecraftforge.fml.common.eventhandler.Event;
import net.minecraftforge.fml.common.eventhandler.Event.Result;
import net.minecraftforge.fml.common.registry.GameRegistry;
public class WorldGenerationOres implements IWorldGenerator
{
// Which dimension to generate in by dimension ID (Nether -1, Overworld 0, End 1, etc)
@Override
public void generate(Random random, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, IChunkProvider chunkProvider)
{
switch (world.provider.getDimensionId())
{
case -1:
//generateNether(world, random, chunkX * 16, chunkZ * 16);
break;
case 0:
generateSurface(world, random, chunkX * 16, chunkZ * 16);
break;
case 1:
//generateEnd(world, random, chunkX * 16, chunkZ * 16);
break;
}
}
private void generateSurface(World world, Random random, int x, int z)
{
this.addOreSpawnAmblygonite(BlocksCore.ore_amblygonite, world, random, x, z, 16, 16, 10+random.nextInt(14), 1, 18, 42, Blocks.stone);
this.addOreSpawnApatite(BlocksCore.ore_apatite, world, random, x, z, 16, 16, 20+random.nextInt(30), 1, 70, 128, Blocks.stone);
this.addOreSpawnCopper(BlocksCore.ore_bornite, world, random, x, z, 16, 16, 4+random.nextInt(6), 5, 25, 60, Blocks.stone);
this.addOreSpawnCopper(BlocksCore.ore_chalcopyrite, world, random, x, z, 16, 16, 4+random.nextInt(6), 5, 25, 60, Blocks.stone);
this.addOreSpawnCopper(BlocksCore.ore_copper, world, random, x, z, 16, 16, 4+random.nextInt(6), 2, 25, 60, Blocks.stone);
this.addOreSpawnCopper(BlocksCore.ore_malachite, world, random, x, z, 16, 16, 4+random.nextInt(6), 4, 25, 60, Blocks.stone);
}
private void addOreSpawnAmblygonite(Block block, World world, Random random, int blockXPos, int blockZPos, int maxX, int maxZ, int maxVeinSize, int chanceToSpawn, int minY, int maxY, Block generateIn)
{
for(int i = 0; i < chanceToSpawn; i++)
{
int posX = blockXPos + random.nextInt(maxX);
int posY = minY + random.nextInt(maxY - minY);
int posZ = blockZPos + random.nextInt(maxZ);
BlockPos blockPos = new BlockPos(posX, posY, posZ);
if (ConfigurationHandler.enableGeneration = true)
{
(new WorldGenMinable(BlocksCore.ore_amblygonite.getDefaultState(), maxVeinSize)).generate(world, random, blockPos);
}
}
}
private void addOreSpawnApatite(Block block, World world, Random random, int blockXPos, int blockZPos, int maxX, int maxZ, int maxVeinSize, int chanceToSpawn, int minY, int maxY, Block generateIn)
{
for(int i = 0; i < chanceToSpawn; i++)
{
int posX = blockXPos + random.nextInt(maxX);
int posY = minY + random.nextInt(maxY - minY);
int posZ = blockZPos + random.nextInt(maxZ);
BlockPos blockPos = new BlockPos(posX, posY, posZ);
if (ConfigurationHandler.enableGeneration = true)
{
(new WorldGenMinable(BlocksCore.ore_apatite.getDefaultState(), maxVeinSize)).generate(world, random, blockPos);
}else{
if (ConfigurationHandler.enableGeneration = false)
{
(new WorldGenMinable(BlocksCore.ore_apatite.getDefaultState(), 0)).generate(world, random, blockPos);
}
}
}
}
private void addOreSpawnCopper(Block block, World world, Random random, int blockXPos, int blockZPos, int maxX, int maxZ, int maxVeinSize, int chanceToSpawn, int minY, int maxY, Block generateIn)
{
for(int i = 0; i < chanceToSpawn; i++)
{
int posX = blockXPos + random.nextInt(maxX);
int posY = minY + random.nextInt(maxY - minY);
int posZ = blockZPos + random.nextInt(maxZ);
BlockPos blockPos = new BlockPos(posX, posY, posZ);
if (ConfigurationHandler.enableGeneration = true)
{
(new WorldGenMinable(BlocksCore.ore_bornite.getDefaultState(), maxVeinSize)).generate(world, random, blockPos);
(new WorldGenMinable(BlocksCore.ore_chalcopyrite.getDefaultState(), maxVeinSize)).generate(world, random, blockPos);
(new WorldGenMinable(BlocksCore.ore_copper.getDefaultState(), maxVeinSize)).generate(world, random, blockPos);
(new WorldGenMinable(BlocksCore.ore_malachite.getDefaultState(), maxVeinSize)).generate(world, random, blockPos);
}
}
}
}
Configuration Handler:
package common.industrialistechnologia.utility_libraries;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.fml.client.event.ConfigChangedEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import java.io.File;
import common.industrialistechnologia.reference_libraries.ModInfo;
import java.io.File;
public class ConfigurationHandler
{
public static Configuration configuration;
public static String generation = "Generation";
public static boolean enableGeneration;
public static void init(File configFile)
{
// Create the configuration object from the given configuration file
if (configuration == null)
{
configuration = new Configuration(configFile);
loadConfiguration();
}
}
private static void loadConfiguration()
{
enableGeneration = configuration.get(generation, "Enable Apatite Generation", true, "Enable Apatite generation").getBoolean(enableGeneration);
configuration.addCustomCategoryComment(generation, "This section contains all settings regarding ore generation.");
if (configuration.hasChanged())
{
configuration.save();
}
}
@SubscribeEvent
public void onConfigurationChangedEvent(ConfigChangedEvent.OnConfigChangedEvent event)
{
if (event.modID.equalsIgnoreCase(ModInfo.CORE_MOD_ID))
{
loadConfiguration();
}
}
}