On world gen. I get a crash of index out of bounds of -45
on
final int HEIGHT = world.getChunkFromChunkCoords(x, z).getHeightValue(x, z);
I dont think changing your .getHeight to .getHeightValue should affect it, I thought i might of been a typo? It almost seems like it got a value below where it could spawn. (my guess)
edit, each time I gen a world, It spits out a different value
It spits out a different value each time because the world gen class is called for every chunk.
getHeightValue takes a block location, not a chunk location -- block locations are always positive, chunk locations can be positive or negative.
I recommend changing your generateStructure to determine height there instead of taking it as a parameter. Why? You don't know what coordinates to check the y-value of until after generateStructure picks random numbers.
So, instead of accepting a height parameter, you could assign getHeightValue(randX, randZ) to some variable after setting randX and randZ.
Rollback Post to RevisionRollBack
Click this banner for a list of illegal mod distributors -- only download from legal sites!
public void generateStructure(World world, Random random, int chunkX, int chunkZ, int chance, int height) {
WorldGenObelisk gen = new WorldGenObelisk();
for(int i = 0; i < chance; i++) {
int xRand = chunkX * 16 + random.nextInt(16);
int zRand = chunkZ * 16 + random.nextInt(16);
//insert whatever code idk here
gen.generate(world, random, xRand, height, zRand);
}
}
Okay so I removed my parameter for height, and is now determining it in the generateStructure function, but now what should I set it as? I tried this (almost seem like the same thing)
final int height = world.getChunkFromBlockCoords(xRand, zRand).getHeightValue(xRand, zRand);
but ofc it didnt work, but hey, atleast I know its trying to spawn it, but cant due to this height value
Well, the problem with getHeightValue is it is not very precise. I don't know why not. It's sometimes easier to make a function that, given x and z coordinates of a block, determines the topmost ground block.
Mine looks something like this:
public int getFirstGroundBlockFromAbove(World world, int x, int z, int maxY)
{
int y = maxY;
Block check = world.getBlock(x, y, z);
// begin psuedocode
while(check is not a ground block and y is more than 0)
{
decrement y
check = world.getBlock(x, y, z);
}
return y;
}
All it does is check every single block, starting from whatever maxY is, until it finds a ground block. What counts as ground blocks is up to you.
If the getHeightValue thing is the only problem, then that's a relief. This should fix it.
Rollback Post to RevisionRollBack
Click this banner for a list of illegal mod distributors -- only download from legal sites!
That's the maxY. That's the largest value you are willing to return -- Minecraft has a block limit of 256, so if your structure is 20 blocks tall you should pass (256 - 20 = 236). That way no structures generate outside the building limit.
It also tells the function what "above" is.
Rollback Post to RevisionRollBack
Click this banner for a list of illegal mod distributors -- only download from legal sites!
I do know concepts of java, do I know them all? No, but I know this is java 101, but yeah, I need a refresher there. But then again, If I dont do I will never learn xD
Oh goodie, So I did some debugging, and everything is fine, I used this :
Console.println(xRand + " " + height + zRand);
to get me to the obelisk, but its not there, I put some more debugs where I set the block, and they execute fine aswell, its just not spawning the blocks,
[16:03:30] [Server thread/INFO] [STDOUT]: [scala.Console$:println:148]: exec overworld
[16:03:30] [Server thread/INFO] [STDOUT]: [scala.Console$:println:148]: generating structure
[16:03:30] [Server thread/INFO] [STDOUT]: [scala.Console$:println:148]: Im making a obelisk!
[16:03:30] [Server thread/INFO] [STDOUT]: [scala.Console$:println:148]: Im done making obelisk
[16:03:30] [Server thread/INFO] [STDOUT]: [scala.Console$:println:148]: 355 63 -30
here is my WorldGenObelisk:
/*
*** MADE BY MRPONYCAPTAIN'S .SCHEMATIC TO .JAVA CONVERTING TOOL v2.0 ***
*/
package com.unassigned.unassignedmod.worldgen.schematic;
import java.util.Random;
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.WorldGenerator;
import scala.Console;
public class WorldGenObelisk extends WorldGenerator implements IWorldGenerator
{
protected Block[] getValidSpawnBlocks() {
return new Block[] {
Blocks.grass,
Blocks.dirt,
Blocks.sand
};
}
public boolean locationIsValidSpawn(World world, int i, int j, int k){
int distanceToAir = 0;
Block check = world.getBlock(i, j, k);
while (check != Blocks.air){
if (distanceToAir > 1){
return false;
}
distanceToAir++;
check = world.getBlock(i, j + distanceToAir, k);
}
j += distanceToAir - 1;
Block block = world.getBlock(i, j, k);
Block blockAbove = world.getBlock(i, j+1, k);
Block blockBelow = world.getBlock(i, j-1, k);
for (Block x : getValidSpawnBlocks()){
if (blockAbove != Blocks.air){
return false;
}
if (block == x){
return true;
}else if (block == Blocks.snow && blockBelow == x){
return true;
}
}
return false;
}
public WorldGenObelisk() { }
@Override
public void generate(Random random, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, IChunkProvider chunkProvider) {
}
public void setBlock(World world, int x, int y, int z, Block block, int metadata)
{
Block b1 = world.getBlock(x, y, z);
// if(b1.isAir(world, x, y, z) || b1.isLeaves(world, x, y, z))
//{
//world.setBlock(x, y, z, block, metadata, 2);
//}
}
public boolean generate(World world, Random rand, int i, int j, int k) {
//check that each corner is one of the valid spawn blocks
if(!locationIsValidSpawn(world, i, j, k) || !locationIsValidSpawn(world, i + 2, j, k) || !locationIsValidSpawn(world, i + 2, j, k + 2) || !locationIsValidSpawn(world, i, j, k + 2))
{
return false;
}
// k = k - 10;
// i = i - 10;
Console.println("Im making a obelisk!");
this.setBlock(world, i + 0, j + 0, k + 0, Blocks.planks, 2);
this.setBlock(world, i + 0, j + 0, k + 1, Blocks.planks, 2);
this.setBlock(world, i + 0, j + 0, k + 2, Blocks.planks, 2);
// this.setBlock(world, i + 0, j + 1, k + 0, Blocks.air, 0);
this.setBlock(world, i + 0, j + 1, k + 1, Blocks.oak_stairs, 0);
/* this.setBlock(world, i + 0, j + 1, k + 2, Blocks.air, 0);
this.setBlock(world, i + 0, j + 2, k + 0, Blocks.air, 0);
this.setBlock(world, i + 0, j + 2, k + 1, Blocks.air, 0);
this.setBlock(world, i + 0, j + 2, k + 2, Blocks.air, 0);
this.setBlock(world, i + 0, j + 3, k + 0, Blocks.air, 0);
this.setBlock(world, i + 0, j + 3, k + 1, Blocks.air, 0);
this.setBlock(world, i + 0, j + 3, k + 2, Blocks.air, 0);
this.setBlock(world, i + 0, j + 4, k + 0, Blocks.air, 0);
this.setBlock(world, i + 0, j + 4, k + 1, Blocks.air, 0);
this.setBlock(world, i + 0, j + 4, k + 2, Blocks.air, 0);
this.setBlock(world, i + 0, j + 5, k + 0, Blocks.air, 0);
this.setBlock(world, i + 0, j + 5, k + 1, Blocks.air, 0);
this.setBlock(world, i + 0, j + 5, k + 2, Blocks.air, 0);*/
this.setBlock(world, i + 1, j + 0, k + 0, Blocks.planks, 2);
this.setBlock(world, i + 1, j + 0, k + 1, Blocks.planks, 2);
this.setBlock(world, i + 1, j + 0, k + 2, Blocks.planks, 2);
this.setBlock(world, i + 1, j + 1, k + 0, Blocks.oak_stairs, 2);
this.setBlock(world, i + 1, j + 1, k + 1, Blocks.diamond_block, 0);
this.setBlock(world, i + 1, j + 1, k + 2, Blocks.oak_stairs, 3);
// this.setBlock(world, i + 1, j + 2, k + 0, Blocks.air, 0);
this.setBlock(world, i + 1, j + 2, k + 1, Blocks.stonebrick, 0);
// this.setBlock(world, i + 1, j + 2, k + 2, Blocks.air, 0);
// this.setBlock(world, i + 1, j + 3, k + 0, Blocks.air, 0);
this.setBlock(world, i + 1, j + 3, k + 1, Blocks.stonebrick, 0);
// this.setBlock(world, i + 1, j + 3, k + 2, Blocks.air, 0);
// this.setBlock(world, i + 1, j + 4, k + 0, Blocks.air, 0);
this.setBlock(world, i + 1, j + 4, k + 1, Blocks.beacon, 0);
/* this.setBlock(world, i + 1, j + 4, k + 2, Blocks.air, 0);
this.setBlock(world, i + 1, j + 5, k + 0, Blocks.air, 0);
this.setBlock(world, i + 1, j + 5, k + 1, Blocks.air, 0);
this.setBlock(world, i + 1, j + 5, k + 2, Blocks.air, 0);*/
this.setBlock(world, i + 2, j + 0, k + 0, Blocks.planks, 2);
this.setBlock(world, i + 2, j + 0, k + 1, Blocks.planks, 2);
this.setBlock(world, i + 2, j + 0, k + 2, Blocks.planks, 2);
//this.setBlock(world, i + 2, j + 1, k + 0, Blocks.air, 0);
this.setBlock(world, i + 2, j + 1, k + 1, Blocks.oak_stairs, 1);
/* this.setBlock(world, i + 2, j + 1, k + 2, Blocks.air, 0);
this.setBlock(world, i + 2, j + 2, k + 0, Blocks.air, 0);
this.setBlock(world, i + 2, j + 2, k + 1, Blocks.air, 0);
this.setBlock(world, i + 2, j + 2, k + 2, Blocks.air, 0);
this.setBlock(world, i + 2, j + 3, k + 0, Blocks.air, 0);
this.setBlock(world, i + 2, j + 3, k + 1, Blocks.air, 0);
this.setBlock(world, i + 2, j + 3, k + 2, Blocks.air, 0);
this.setBlock(world, i + 2, j + 4, k + 0, Blocks.air, 0);
this.setBlock(world, i + 2, j + 4, k + 1, Blocks.air, 0);
this.setBlock(world, i + 2, j + 4, k + 2, Blocks.air, 0);
this.setBlock(world, i + 2, j + 5, k + 0, Blocks.air, 0);
this.setBlock(world, i + 2, j + 5, k + 1, Blocks.air, 0);
this.setBlock(world, i + 2, j + 5, k + 2, Blocks.air, 0);*/
Console.println("Im done making obelisk");
return true;
}
}
if(!locationIsValidSpawn(world, i, j, k) || !locationIsValidSpawn(world, i + 2, j, k) || !locationIsValidSpawn(world, i + 2, j, k + 2) || !locationIsValidSpawn(world, i, j, k + 2))
{
return false;
}
and you can even get rid of the locationIsValidSpawn function entirely. Your structure is small enough side-to-side that it doesn't matter.
Also, remember the getFirstGroundFromAbove function returns the block that is NOT air. Try adding 1 to the height value and if it floats in mid-air, take it back out:
final int height = getFirstGroundBlockFromAbove() + 1;
OKay found it! Thank you SO much for your help, you the first person that you have actually given me resource and explanations to help me! Thank you !
btw it was here:
public void setBlock(World world, int x, int y, int z, Block block, int metadata)
{
Block b1 = world.getBlock(x, y, z);
// if(b1.isAir(world, x, y, z) || b1.isLeaves(world, x, y, z))
//{
//world.setBlock(x, y, z, block, metadata, 2);
//}
}
to
[/p]
[p]public void setBlock(World world, int x, int y, int z, Block block, int metadata)
{
Block b1 = world.getBlock(x, y, z);[/p]
[p]// if(b1.isAir(world, x, y, z) || b1.isLeaves(world, x, y, z))
//{
world.setBlock(x, y, z, block, metadata, 2);
//}
}[/p]
[p]
To have one every few chunks, do a random check to see if you should call generateStructure at all.
Example:
On world gen. I get a crash of index out of bounds of -45
on
I dont think changing your .getHeight to .getHeightValue should affect it, I thought i might of been a typo? It almost seems like it got a value below where it could spawn. (my guess)
edit, each time I gen a world, It spits out a different value
Hm, I think that I might go outside today.
It spits out a different value each time because the world gen class is called for every chunk.
getHeightValue takes a block location, not a chunk location -- block locations are always positive, chunk locations can be positive or negative.
I recommend changing your generateStructure to determine height there instead of taking it as a parameter. Why? You don't know what coordinates to check the y-value of until after generateStructure picks random numbers.
So, instead of accepting a height parameter, you could assign getHeightValue(randX, randZ) to some variable after setting randX and randZ.
So i would do something like this? :
Hm, I think that I might go outside today.
Okay so I removed my parameter for height, and is now determining it in the generateStructure function, but now what should I set it as? I tried this (almost seem like the same thing)
but ofc it didnt work, but hey, atleast I know its trying to spawn it, but cant due to this height value
and Thank you for your help so far,
Hm, I think that I might go outside today.
Well, the problem with getHeightValue is it is not very precise. I don't know why not. It's sometimes easier to make a function that, given x and z coordinates of a block, determines the topmost ground block.
Mine looks something like this:
All it does is check every single block, starting from whatever maxY is, until it finds a ground block. What counts as ground blocks is up to you.
If the getHeightValue thing is the only problem, then that's a relief. This should fix it.
How would I implement it to the height?
Hm, I think that I might go outside today.
... You call the function.
You had this, correct?
Change it to call your function instead of calling world.getChunkFromBlockCoords
So like:
or something different?
yeah this is a dumb question....
Hm, I think that I might go outside today.
Yeah, but you have to pass it the values you're checking with.
Please, please, PLEASE learn Java! LapisSea has good tutorials for people who are learning Java and modding at the same time.
it wants the y parameter though, what would I do there?
Hm, I think that I might go outside today.
That's the maxY. That's the largest value you are willing to return -- Minecraft has a block limit of 256, so if your structure is 20 blocks tall you should pass (256 - 20 = 236). That way no structures generate outside the building limit.
It also tells the function what "above" is.
I do know concepts of java, do I know them all? No, but I know this is java 101, but yeah, I need a refresher there. But then again, If I dont do I will never learn xD
Testing, lets hope this is the only problem
Hm, I think that I might go outside today.
Hm, I think that I might go outside today.
Remove this line:
and you can even get rid of the locationIsValidSpawn function entirely. Your structure is small enough side-to-side that it doesn't matter.
Also, remember the getFirstGroundFromAbove function returns the block that is NOT air. Try adding 1 to the height value and if it floats in mid-air, take it back out:
Okay will do!
Hm, I think that I might go outside today.
Yeah, that didnt change the fact it wasnt spawning.
maybe it has to do with the i, j k coords?
Hm, I think that I might go outside today.
Hm, I think that I might go outside today.
OKay found it! Thank you SO much for your help, you the first person that you have actually given me resource and explanations to help me! Thank you !
btw it was here:
to
Hm, I think that I might go outside today.