I have been trying to figure out how to make a block or a plant be able to spawn underwater and haven't been able to get it right. I want the block to spawn on top of a dirt or sand block, but I also want the block to be underwater. I don't know how to make those checks to tell it to spawn like that... Can somebody give an example code, or give me some kind of advice?? Thanks in advance!
First of all you need to check if the biome is ocean or beach. The check some random blocks, if they're sand or dirt and then check if there is a block of water above!
Does it have to be ocean or beach, because I wanted to make it in any body of water. To be honest, I don't really know how to do all the checks and ifs and all of that.
I'm kinda sorry to tell you, but if you no clue how to look at a class and alter it, this is to high for you. You should really start with the basics. Then get more complex stuff step by step. That's how I did it and now I am able to solve most of my problems within minutes. I really recommend doing something easier. You can come back to that later!
/**
* Populates chunk with ores etc etc
*/
public void populate(IChunkProvider par1IChunkProvider, int par2, int par3)
function. It is located in the "ChunkProvider" files. ChunkProviderGenerate.java is the one used for normal world generation, there is also one for the nether, the end and flat worlds.
I made sloped dirt, sand, etc. as part of my mod and this is where I generated the metadata for my blocks. There is also another function run inside this one, decorate, that might be a better place for what you're doing. Just take a look at all the code surrounding that, particularily the plants.
This is what my code looks like... It't just a regular generation code that I learned from a tutorial I watched, I just added it to the ChunkProviderGenerate class.
private void generateSurface(World world, Random random, int BlockX, int BlockZ){
for(int k =200; k < 2000; k++){
int XCOORD = BlockX+random.nextInt(16);
int ZCOORD = BlockZ +random.nextInt(16);
int YCOORD = (60);
if (YCOORD + 1 == Block.waterStill.blockID || YCOORD - 1 ==Block.dirt.blockID){
world.setBlock(YCOORD, YCOORD, YCOORD, mod_Main.TestBlock.blockID);
{
(new WorldGenMinable(mod_Main.TestBlock.blockID, 40)).generate(world, random, XCOORD, YCOORD, ZCOORD);
}
}
}
}
It's mainly bs, I am just testing it out before going to the trouble of creating a real block. I'll do that when I figure this out.
Everything checks out fine, I can run the client without any errors. The only problem is that when the new world generates, there are floating TestBlocks everywhere, including underwater. I just want them underwater, not up in the air too.
I generate plastic in much the same way, but you still have to call your class to generate it.
for (i = 0; i < 3; i++) {
int randPosX = chunkX + rand.nextInt(16);
int randPosY = rand.nextInt(127);
int randPosZ = chunkZ + rand.nextInt(16);
(new WorldGenPlastic(5)).generate(world, rand, randPosX, randPosY, randPosZ);
}
Well I tried it again, I just copied the WorldGenClay class and changed a few things. Thought it would work but my block is STILL not showing up... Any suggestions, or am I doing something wrong?
Here's my code:
package Mods.Common;
import java.util.Random;
import net.minecraft.src.Block;
import net.minecraft.src.Material;
import net.minecraft.src.World;
import net.minecraft.src.WorldGenMinable;
import net.minecraft.src.WorldGenerator;
public class WorldGenFlower extends WorldGenerator
{
private int block;
/** The number of blocks to generate. */
private int numberOfBlocks;
public WorldGenFlower()
{
this.block = mod_Main.TestBlock.blockID;
}
public boolean generate(World par1World, Random par2Random, int par3, int par4, int par5)
{
if (par1World.getBlockMaterial(par3, par4, par5) != Material.water)
{
return false;
}
else
{
int var6 = par2Random.nextInt(this.numberOfBlocks - 2) + 2;
byte var7 = 1;
for (int var8 = par3 - var6; var8 <= par3 + var6; ++var8)
{
for (int var9 = par5 - var6; var9 <= par5 + var6; ++var9)
{
int var10 = var8 - par3;
int var11 = var9 - par5;
if (var10 * var10 + var11 * var11 <= var6 * var6)
{
for (int var12 = par4 - var7; var12 <= par4 + var7; ++var12)
{
int var13 = par1World.getBlockId(var8, var12, var9);
if (var13 == Block.dirt.blockID || var13 == Block.sand.blockID)
{
par1World.setBlock(var8, var12, var9, this.block);
for(int var14 = par4 - var7; var14<=par4+var7; ++var14){
int XCOORD = par4+par2Random.nextInt(16);
int ZCOORD = par5+par2Random.nextInt(16);
int YCOORD = (60);
if (YCOORD + 1 == Block.waterStill.blockID|| YCOORD - 1 == Block.dirt.blockID){
par1World.setBlockWithNotify(XCOORD, YCOORD, ZCOORD, mod_Main.TestBlock.blockID);
(new WorldGenMinable(mod_Main.TestBlock.blockID, 50)).generate(par1World, par2Random, XCOORD, YCOORD, ZCOORD);
}
}
}
}
}
}
}
return true;
}
}
}
PM's are fine too.
The BrainStoneMod! GET IT NOW!
The BrainStoneMod! GET IT NOW!
function. It is located in the "ChunkProvider" files. ChunkProviderGenerate.java is the one used for normal world generation, there is also one for the nether, the end and flat worlds.
I made sloped dirt, sand, etc. as part of my mod and this is where I generated the metadata for my blocks. There is also another function run inside this one, decorate, that might be a better place for what you're doing. Just take a look at all the code surrounding that, particularily the plants.
It's mainly bs, I am just testing it out before going to the trouble of creating a real block. I'll do that when I figure this out.
Everything checks out fine, I can run the client without any errors. The only problem is that when the new world generates, there are floating TestBlocks everywhere, including underwater. I just want them underwater, not up in the air too.
I have looked and tried that a lot. I change the right things and everything, but my custom block doesn't show up.
for (i = 0; i < 3; i++) {
int randPosX = chunkX + rand.nextInt(16);
int randPosY = rand.nextInt(127);
int randPosZ = chunkZ + rand.nextInt(16);
(new WorldGenPlastic(5)).generate(world, rand, randPosX, randPosY, randPosZ);
}
Here's my code:
Thanks for all the help everyone!