Hey, i tried to get the right height for a place to generate a structure but the structure generates always on the bottom of a netherrack overhang like this:
Here is my code:
public static int getGroundFromAbove(World world, int x, int z) {
int y = world.getActualHeight();
The problem is that your code loops until either "foundAir" or "foundNetherrack" are true without checking to see what order the blocks are in; if you want it to generate on the ground (air over Netherrack) you should check for that combination of blocks. For example, here is some of my own code which generates "trees" in the Nether (it is also better to start with a randomized height, not the dimension height, as otherwise it will be less likely to place them further down as the first valid surface found will be the one it generates on):
Chunk chunk = this.worldObj.getChunkFromBlockCoords(x, z);
int block1 = chunk.getBlockID(x & 15, y, z & 15);
int block2 = chunk.getBlockID(x & 15, y - 1, z & 15);
// Searches down for air over Netherrack
while (true)
{
if (block1 == 0 && block2 == Block.netherrack.blockID) break;
--y;
if (y < minY) break;
block1 = block2;
block2 = chunk.getBlockID(x & 15, y - 1, z & 15);
}
if (y >= minY && this.generateNetherTree(x, y, z))
{
if (y < 64)
{
++count1;
}
else
{
++count2;
}
if (count1 >= 2 && count2 >= 2) return;
}
(this uses code based on 1.6.4 but the same principle applies if you change the method calls; I also directly access chunks to bypass expensive chunk lookups for performance. Note also how I reassign block2 to block1 so only one getBlockID call is needed. You also want to make sure that if the check fails to find a valid location your feature does not generate, and I also split the range into two to help ensure they are vertically distributed throughout the Nether).
The trees themselves also make sure there is enough space for them to generate as even if a valid location was found by the above check ("y >= minY" also prevents them from generating outside of their ranges, either 4-63 or 64-123) it might just be a small cave (depending on the feature you might want to either overwrite blocks or only replace air or another block); I also perform up to 16 attempts per chunk to help ensure that the desired number generate in a chunk:
// Checks for space around tree
for (int x = -3; x <= 3; ++x)
{
for (int z = -3; z <= 3; ++z)
{
Chunk chunk = this.worldObj.getChunkFromBlockCoords(posX + x, posZ + z);
int dist = Math.max(Math.abs(x), Math.abs(z));
int maxY = (dist == 3 ? height - 1 : (dist == 2 ? height : height + 1));
for (int y = (dist == 3 ? height - 3 : height - 4); y <= maxY; ++y)
{
if (chunk.getBlockID((posX + x) & 15, posY + y, (posZ + z) & 15) != 0) return false;
}
}
}
Hey, i tried to get the right height for a place to generate a structure but the structure generates always on the bottom of a netherrack overhang like this:
Here is my code:
I can´t find the issue... can anyone help me?
>> https://minecraft.curseforge.com/members/XxRexRaptorxX/projects
The problem is that your code loops until either "foundAir" or "foundNetherrack" are true without checking to see what order the blocks are in; if you want it to generate on the ground (air over Netherrack) you should check for that combination of blocks. For example, here is some of my own code which generates "trees" in the Nether (it is also better to start with a randomized height, not the dimension height, as otherwise it will be less likely to place them further down as the first valid surface found will be the one it generates on):
(this uses code based on 1.6.4 but the same principle applies if you change the method calls; I also directly access chunks to bypass expensive chunk lookups for performance. Note also how I reassign block2 to block1 so only one getBlockID call is needed. You also want to make sure that if the check fails to find a valid location your feature does not generate, and I also split the range into two to help ensure they are vertically distributed throughout the Nether).
The trees themselves also make sure there is enough space for them to generate as even if a valid location was found by the above check ("y >= minY" also prevents them from generating outside of their ranges, either 4-63 or 64-123) it might just be a small cave (depending on the feature you might want to either overwrite blocks or only replace air or another block); I also perform up to 16 attempts per chunk to help ensure that the desired number generate in a chunk:
TheMasterCaver's First World - possibly the most caved-out world in Minecraft history - includes world download.
TheMasterCaver's World - my own version of Minecraft largely based on my views of how the game should have evolved since 1.6.4.
Why do I still play in 1.6.4?
Thats my code now
The structures still spawning on the bottom of a netherrack overhang
.
>> https://minecraft.curseforge.com/members/XxRexRaptorxX/projects
*bump*
>> https://minecraft.curseforge.com/members/XxRexRaptorxX/projects