Jump to content

Recommended Posts

Posted

I'm newish to Minecraft coding and how the game works but I have some knowledge on other Java programs and mods. I recently tried to spawn an ore (called money ore) but it doesn't spawn.

 

Could someone please check my code for any errors?

 

package com.landuros.world;

import java.util.Random;

import com.landuros.blocks.MBlocks;

import cpw.mods.fml.common.IWorldGenerator;
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;

public class MOre 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);
		break;
	}
}

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(MBlocks.MoneyOre, Blocks.iron_ore, random, world, chunkX, chunkZ, 0, 150, 10, 50, 20);
}

private void generateNether(Random random, int chunkX, int chunkZ, World world) 
{

}

}

 

I have another .java file that registers the World Gen and calls upon GameRegistry, and I don't think that's the problem. Also, could someone please confirm what the integers in this line of code represent?

 

addOre(MBlocks.MoneyOre, Blocks.iron_ore, random, world, chunkX, chunkZ, 0, 150, 10, 50, 20);

 

I'm pretty sure the first two are the minY and maxY values, and 50 is the spawn rate.

 

Thanks

Posted

Try to replace Blocks.iron_ore with Blocks.STONE when calling the addOre method, because it looks like you want to replace iron ores with your money ores instead of normal stone blocks

Posted

Yeah, it would be rare for a random coord to hit iron ore to replace it. In overworld, you'll almost always want to specify stone as the replaceable block. In nether, normally specify netherrack. If you have an unusual purpose, then you might want to add some search logic to one of your methods (like if you wanted to replace some lava).

 

If you really want to replace something like iron ore, then there might be an ore-spawn event that you can harness to detect each impending iron-ore body and substitute your own ore block in its place

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Posted
If you have an unusual purpose, then you might want to add some search logic to one of your methods (like if you wanted to replace some lava).

 

I wrote one once that replaced [dirt, sand] but only if the block was directly under a water block.

https://github.com/Draco18s/ReasonableRealism/blob/master/src/main/java/com/draco18s/farming/world/WorldGenMinableSalt.java#L76

Required duplicating a whole method of WorldGenMinable save for the one if-statement, but whatever.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

Oh, thank you, I will try that... My brain thought that Blocks.iron_ore was the material for some reason.

 

Edit: Yup, that was the issue. Thank you to kremi151, jeffryfisher and Draco18s for quickly helping me with the problem.

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

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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