I'm building a mod that adds new ores into the world. I've managed to get them spawning in the overworld, yet am stuck when it comes to the nether. I've put ore spawning methods where I expect them to be called for the nether, but get nothing. Even when I crank up the chance of spawning to 9999 (which makes my overworld spawns hilariously common), I see nothing in the nether. Can anybody spot where I might be going wrong in my code?
public class ModOreGeneration implements IWorldGenerator
{
public void generate(Random random, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, IChunkProvider chunkProvider)
{
switch (world.provider.getDimensionId())
{
case 1:
generateEnd(world, random, new BlockPos(chunkX * 16, 64, chunkZ * 16));
break;
case 0:
generateSurface(world, random, new BlockPos(chunkX * 16, 64, chunkZ * 16));
break;
case -1:
generateNether(world, random, new BlockPos(chunkX * 16, 64, chunkZ * 16));
break;
}
}
private void addOreSpawn(Block block, World world, Random random, BlockPos pos, int maxX, int maxZ, int maxVeinSize, int chanceToSpawn, int minY, int maxY, Block generateIn)
{
WorldGenMinable mine = new WorldGenMinable(block.getDefaultState(), maxVeinSize);
for (int i = 0; i < chanceToSpawn; i++)
{
int x = pos.getX() + random.nextInt(maxX);
int y = minY + random.nextInt(maxY - minY);
int z = pos.getZ() + random.nextInt(maxZ);
mine.generate(world, random, new BlockPos(x, y, z));
}
}
private void generateEnd(World world, Random random, BlockPos pos)
{
To generate ores in anything except stone, you need to use the three-parameter constructor of WorldGenMinable (where the third parameter is a Predicate that matches the Block you want to generate in). You can create a Predicate for a Block using BlockHelper.forBlock (like the two-parameter constructor does).
Rollback Post to RevisionRollBack
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
You've been a great help Choonster, it's all working as it should now, many thanks!
For anyone else passing by stuck with the same problem, here's my fixed code:
public class ModOreGeneration implements IWorldGenerator
{
@Override
public void generate(Random random, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, IChunkProvider chunkProvider)
{
switch(world.provider.getDimensionId()){
case 1:
generateEnd(world, random, new BlockPos(chunkX * 16, 64, chunkZ * 16));
break;
case 0:
generateSurface(world, random, new BlockPos(chunkX * 16, 64, chunkZ * 16));
break;
case -1:
generateNether(world, random, new BlockPos(chunkX * 16, 64, chunkZ * 16));
break;
}
}
private void addOverworldOre(Block block, World world, Random random, BlockPos pos, int maxX, int maxZ, int maxVeinSize, int chanceToSpawn, int minY, int maxY, Block generateIn)
{
WorldGenMinable mine = new WorldGenMinable(block.getDefaultState(), maxVeinSize);
for (int i = 0; i < chanceToSpawn; i++)
{
int x = pos.getX() + random.nextInt(maxX);
int y = minY + random.nextInt(maxY - minY);
int z = pos.getZ() + random.nextInt(maxZ);
mine.generate(world, random, new BlockPos(x, y, z));
}
}
private void addNetherOre(Block block, World world, Random random, BlockPos pos, int maxX, int maxZ, int maxVeinSize, int chanceToSpawn, int minY, int maxY, Block generateIn)
{
WorldGenMinable mine = new WorldGenMinable(block.getDefaultState(), maxVeinSize , BlockHelper.forBlock(Blocks.netherrack));
for (int i = 0; i < chanceToSpawn; i++)
{
int x = pos.getX() + random.nextInt(maxX);
int y = minY + random.nextInt(maxY - minY);
int z = pos.getZ() + random.nextInt(maxZ);
mine.generate(world, random, new BlockPos(x, y, z));
}
}
private void generateEnd(World world, Random random, BlockPos pos)
{
public class CopperOre implements IWorldGenerator {
@Override
public void generate(Random random, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, IChunkProvider chunkProvider) {
switch(world.provider.dimensionId) {
case -1:
generateNether(random, chunkX * 16, chunkZ * 16, world);
break;
case 0:
generateOverworld(random, chunkX * 16, chunkZ * 16, world);
break;
case 1:
generateEnd(random, chunkX * 16, chunkZ * 16, world);
}
}
private void addOre(Block block, Block blockspawn, Random random, World world, int posX, int posZ, int minY, int maxY, int minVein, int maxVein, int spawnChance) {
for(int i = 0; i < spawnChance; i++) {
int defaultChunkSize = 16;
int xPos = posX + random.nextInt(defaultChunkSize);
int yPos = minY + random.nextInt(maxY - minY);
int zPos = posZ + random.nextInt(defaultChunkSize);
It's called CopperOre because I hadn't been planning on adding so many ores into the gen and don't feel like fixing it
Rollback Post to RevisionRollBack
"Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice: Nothing works and they don't know why."
-- Unknown
Hi 'crafters!
I'm building a mod that adds new ores into the world. I've managed to get them spawning in the overworld, yet am stuck when it comes to the nether. I've put ore spawning methods where I expect them to be called for the nether, but get nothing. Even when I crank up the chance of spawning to 9999 (which makes my overworld spawns hilariously common), I see nothing in the nether. Can anybody spot where I might be going wrong in my code?
package com.cookiehook.cookiehookcrafting;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.block.state.pattern.BlockHelper;
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.minecraftforge.fml.common.IWorldGenerator;
import com.cookiehook.cookiehookcrafting.init.ModBlocks;
public class ModOreGeneration implements IWorldGenerator
{
public void generate(Random random, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, IChunkProvider chunkProvider)
{
switch (world.provider.getDimensionId())
{
case 1:
generateEnd(world, random, new BlockPos(chunkX * 16, 64, chunkZ * 16));
break;
case 0:
generateSurface(world, random, new BlockPos(chunkX * 16, 64, chunkZ * 16));
break;
case -1:
generateNether(world, random, new BlockPos(chunkX * 16, 64, chunkZ * 16));
break;
}
}
private void addOreSpawn(Block block, World world, Random random, BlockPos pos, int maxX, int maxZ, int maxVeinSize, int chanceToSpawn, int minY, int maxY, Block generateIn)
{
WorldGenMinable mine = new WorldGenMinable(block.getDefaultState(), maxVeinSize);
for (int i = 0; i < chanceToSpawn; i++)
{
int x = pos.getX() + random.nextInt(maxX);
int y = minY + random.nextInt(maxY - minY);
int z = pos.getZ() + random.nextInt(maxZ);
mine.generate(world, random, new BlockPos(x, y, z));
}
}
private void generateEnd(World world, Random random, BlockPos pos)
{
}
private void generateSurface(World world, Random random, BlockPos pos)
{
addOreSpawn(ModBlocks.sulfur_ore, world, random, pos, 16, 16, 2 + random.nextInt(9), 12, 0, 250, Blocks.stone);
addOreSpawn(ModBlocks.potassium_ore, world, random, pos, 16, 16, 2 + random.nextInt(9), 12, 0, 250, Blocks.stone);
addOreSpawn(ModBlocks.salt_ore, world, random, pos, 16, 16, 4 + random.nextInt(13), 12, 0, 250, Blocks.stone);
}
private void generateNether(World world, Random random, BlockPos pos)
{
addOreSpawn(ModBlocks.nether_iron_ore, world, random, pos, 16, 16, 4 + random.nextInt(11), 30, 0, 120, Blocks.netherrack);
addOreSpawn(ModBlocks.nether_gold_ore, world, random, pos, 16, 16, 4 + random.nextInt(9), 30, 0, 120, Blocks.netherrack);
addOreSpawn(ModBlocks.nether_coal_ore, world, random, pos, 16, 16, 10 + random.nextInt(33), 30, 0, 120, Blocks.netherrack);
addOreSpawn(ModBlocks.nether_redstone_ore, world, random, pos, 16, 16, 4 + random.nextInt(9), 30, 0, 120, Blocks.netherrack);
addOreSpawn(ModBlocks.nether_lapis_ore, world, random, pos, 16, 16, 4 + random.nextInt(9), 0, 30, 120, Blocks.netherrack);
addOreSpawn(ModBlocks.nether_diamond_ore, world, random, pos, 16, 16, 3 + random.nextInt(9), 30, 0, 120, Blocks.netherrack);
addOreSpawn(ModBlocks.nether_emerald_ore, world, random, pos, 16, 16, 1, 12, 5, 29, Blocks.netherrack);
}
}
Cheers,
-Cookiehook
Check out my Youtube channel, where I build a theme park in vanilla Minecraft!
https://www.youtube.com/playlist?list=PLeCiIIOoWhe-mq3nYd_nXXrKw9MkjnUU7
Change everything you wrote from overworld to nether.
To generate ores in anything except stone, you need to use the three-parameter constructor of WorldGenMinable (where the third parameter is a Predicate that matches the Block you want to generate in). You can create a Predicate for a Block using BlockHelper.forBlock (like the two-parameter constructor does).
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
You've been a great help Choonster, it's all working as it should now, many thanks!
For anyone else passing by stuck with the same problem, here's my fixed code:
package com.cookiehook.cookiehookcrafting;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.block.state.pattern.BlockHelper;
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.minecraftforge.fml.common.IWorldGenerator;
import com.google.common.base.Predicate;
import com.cookiehook.cookiehookcrafting.init.ModBlocks;
public class ModOreGeneration implements IWorldGenerator
{
@Override
public void generate(Random random, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, IChunkProvider chunkProvider)
{
switch(world.provider.getDimensionId()){
case 1:
generateEnd(world, random, new BlockPos(chunkX * 16, 64, chunkZ * 16));
break;
case 0:
generateSurface(world, random, new BlockPos(chunkX * 16, 64, chunkZ * 16));
break;
case -1:
generateNether(world, random, new BlockPos(chunkX * 16, 64, chunkZ * 16));
break;
}
}
private void addOverworldOre(Block block, World world, Random random, BlockPos pos, int maxX, int maxZ, int maxVeinSize, int chanceToSpawn, int minY, int maxY, Block generateIn)
{
WorldGenMinable mine = new WorldGenMinable(block.getDefaultState(), maxVeinSize);
for (int i = 0; i < chanceToSpawn; i++)
{
int x = pos.getX() + random.nextInt(maxX);
int y = minY + random.nextInt(maxY - minY);
int z = pos.getZ() + random.nextInt(maxZ);
mine.generate(world, random, new BlockPos(x, y, z));
}
}
private void addNetherOre(Block block, World world, Random random, BlockPos pos, int maxX, int maxZ, int maxVeinSize, int chanceToSpawn, int minY, int maxY, Block generateIn)
{
WorldGenMinable mine = new WorldGenMinable(block.getDefaultState(), maxVeinSize , BlockHelper.forBlock(Blocks.netherrack));
for (int i = 0; i < chanceToSpawn; i++)
{
int x = pos.getX() + random.nextInt(maxX);
int y = minY + random.nextInt(maxY - minY);
int z = pos.getZ() + random.nextInt(maxZ);
mine.generate(world, random, new BlockPos(x, y, z));
}
}
private void generateEnd(World world, Random random, BlockPos pos)
{
}
private void generateSurface(World world, Random random, BlockPos pos)
{
addOverworldOre(ModBlocks.sulfur_ore, world, random, pos, 16, 16, 2 + random.nextInt(9), 12, 0, 250, Blocks.stone);
addOverworldOre(ModBlocks.potassium_ore, world, random, pos, 16, 16, 2 + random.nextInt(9), 12, 0, 250, Blocks.stone);
addOverworldOre(ModBlocks.salt_ore, world, random, pos, 16, 16, 4 + random.nextInt(13), 12, 0, 250, Blocks.stone);
}
private void generateNether(World world, Random random, BlockPos pos)
{
addNetherOre(ModBlocks.nether_iron_ore, world, random, pos, 16, 16, 4 + random.nextInt(11), 12, 0, 120, Blocks.netherrack);
addNetherOre(ModBlocks.nether_gold_ore, world, random, pos, 16, 16, 4 + random.nextInt(9), 8, 0, 120, Blocks.netherrack);
addNetherOre(ModBlocks.nether_coal_ore, world, random, pos, 16, 16, 10 + random.nextInt(33), 15, 0, 120, Blocks.netherrack);
addNetherOre(ModBlocks.nether_redstone_ore, world, random, pos, 16, 16, 4 + random.nextInt(9), 10, 0, 120, Blocks.netherrack);
addNetherOre(ModBlocks.nether_lapis_ore, world, random, pos, 16, 16, 4 + random.nextInt(9), 0, 8, 120, Blocks.netherrack);
addNetherOre(ModBlocks.nether_diamond_ore, world, random, pos, 16, 16, 3 + random.nextInt(9), 3, 0, 120, Blocks.netherrack);
addNetherOre(ModBlocks.nether_emerald_ore, world, random, pos, 16, 16, 1, 4, 0, 120, Blocks.netherrack);
}
}
Check out my Youtube channel, where I build a theme park in vanilla Minecraft!
https://www.youtube.com/playlist?list=PLeCiIIOoWhe-mq3nYd_nXXrKw9MkjnUU7
I've made a world gen class that works pretty good in multiple dimensions:
package com.daporkchop.world;
import java.util.Random;
import com.daporkchop.blocks.ModBlocks;
import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.world.World;
import net.minecraft.world.chunk.IChunkProvider;
import net.minecraft.world.gen.feature.WorldGenMinable;
import cpw.mods.fml.common.IWorldGenerator;
public class CopperOre implements IWorldGenerator {
@Override
public void generate(Random random, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, IChunkProvider chunkProvider) {
switch(world.provider.dimensionId) {
case -1:
generateNether(random, chunkX * 16, chunkZ * 16, world);
break;
case 0:
generateOverworld(random, chunkX * 16, chunkZ * 16, world);
break;
case 1:
generateEnd(random, chunkX * 16, chunkZ * 16, world);
}
}
private void addOre(Block block, Block blockspawn, Random random, World world, int posX, int posZ, int minY, int maxY, int minVein, int maxVein, int spawnChance) {
for(int i = 0; i < spawnChance; i++) {
int defaultChunkSize = 16;
int xPos = posX + random.nextInt(defaultChunkSize);
int yPos = minY + random.nextInt(maxY - minY);
int zPos = posZ + random.nextInt(defaultChunkSize);
new WorldGenMinable(block, (minVein + random.nextInt(maxVein - minVein)), blockspawn).generate(world, random, xPos, yPos, zPos);
}
}
private void generateEnd(Random random, int chunkX, int chunkZ, World world) {
}
private void generateOverworld(Random random, int chunkX, int chunkZ, World world) {
addOre(ModBlocks.Bronze, Blocks.stone, random, world, chunkX, chunkZ, 30, 66, 3, 7, 8);
addOre(ModBlocks.silverOre, Blocks.stone, random, world, chunkX, chunkZ, 6, 15, 3, 5, 5);
addOre(ModBlocks.tinOre, Blocks.stone, random, world, chunkX, chunkZ, 20, 256, 4, 10, 20);
addOre(ModBlocks.peridotOre, Blocks.stone, random, world, chunkX, chunkZ, 6, 20, 2, 4, 4);
addOre(ModBlocks.electrumOre, Blocks.stone, random, world, chunkX, chunkZ, 6, 10, 2, 7, 5);
addOre(ModBlocks.copOre, Blocks.stone, random, world, chunkX, chunkZ, 15, 64, 2, 6, 15);
addOre(ModBlocks.amethystOre, Blocks.stone, random, world, chunkX, chunkZ, 6, 14, 3, 15, 10);
addOre(ModBlocks.OPore, Blocks.stone, random, world, chunkX, chunkZ, 6, 256, 2, 3, 1);
}
private void generateNether(Random random, int chunkX, int chunkZ, World world) {
addOre(ModBlocks.nDiamond, Blocks.netherrack, random, world, chunkX, chunkZ, 6, 256, 5, 15, 10);
addOre(ModBlocks.nIron, Blocks.netherrack, random, world, chunkX, chunkZ, 6, 256, 5, 15, 50);
addOre(ModBlocks.nGold, Blocks.netherrack, random, world, chunkX, chunkZ, 6, 256, 5, 15, 50);
addOre(ModBlocks.nEmerald, Blocks.netherrack, random, world, chunkX, chunkZ, 6, 256, 5, 15, 50);
}
}
It's called CopperOre because I hadn't been planning on adding so many ores into the gen and don't feel like fixing it