Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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 xD.

 

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();
        }
    }
}

I'll give you a hint -- the bug is in this line :-)

 

if (ConfigurationHandler.enableGeneration = true)

  • Author

I'll give you a hint -- the bug is in this line :-)

 

if (ConfigurationHandler.enableGeneration = true)

 

Thanks :)

 

I changed the code to this:

if (ConfigurationHandler.enableApatiteGeneration != false)
		{
			(new WorldGenMinable(BlocksCore.ore_apatite.getDefaultState(), maxVeinSize)).generate(world, random, blockPos);
		}else{
			(new WorldGenMinable(BlocksCore.ore_apatite.getDefaultState(), 0)).generate(world, random, blockPos);
		}

 

and changed the generation to false to see if any spawned and none did (checked an entire mountain biome and found none) and then set it back to true afterwards and found some instantly, so that seems to be working now :)

 

= is assignment, == is comparison, and there's no need for explicit comparison with booleans, you can just do:

 

 

if(ConfigurationHandler.enableGeneration)

 

 

This checks if the boolean is true.

  • Author

= is assignment, == is comparison, and there's no need for explicit comparison with booleans, you can just do:

 

 

if(ConfigurationHandler.enableGeneration)

 

 

This checks if the boolean is true.

 

Thanks for the help :)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.