Posted March 9, 20178 yr I am trying to spawn a structure in the Nether. The structure is supposed to spawn in the air but it does not work correctly. Here is the code I am using: public boolean generate(World world, Random rand, BlockPos pos) { rand = world.getChunkFromBlockCoords(pos).getRandomWithSeed(world.getSeed()); Mirror[] mirrors = Mirror.values(); Rotation[] rotations = Rotation.values(); Mirror mirror = mirrors[rand.nextInt(mirrors.length)]; Rotation rotation = rotations[rand.nextInt(rotations.length)]; MinecraftServer server = world.getMinecraftServer(); TemplateManager manager = world.getSaveHandler().getStructureTemplateManager(); Template template = manager.getTemplate(server, WeightedUtil.getRandomStructure(rand, variants)); PlacementSettings settings = new PlacementSettings().setMirror(mirror).setRotation(rotation).setReplacedBlock(Blocks.STRUCTURE_VOID).setRandom(rand); BlockPos structureSize = template.transformedSize(rotation); BlockPos newPos = new BlockPos(pos.getX() - structureSize.getX(), 96, pos.getZ() - structureSize.getZ()); BlockPos spawnPos = getSuitableAirPos(world, template.getZeroPositionWithTransform(newPos, mirror, rotation), structureSize); if(spawnPos != BlockPos.ORIGIN) { template.addBlocksToWorld(world, spawnPos, settings, 3); return true; } return false; } private static BlockPos getSuitableAirPos(World world, BlockPos pos, BlockPos structureSize) { while(pos.getY() > 32) { float sizeX = structureSize.getX(); float sizeZ = structureSize.getZ(); float sizeY = structureSize.getY(); int airBlocks = 0; for(int x = 0; x <= sizeX; x++) { for(int z = 0; z <= sizeZ; z++) { for(int y = 0; y <= sizeY; y++) { BlockPos newPos = pos.add(x, y, z); if(world.getBlockState(newPos) == Blocks.AIR.getDefaultState()) { airBlocks++; } } } } if(airBlocks == sizeX * sizeY * sizeZ) { return pos; } pos = pos.down(); } return BlockPos.ORIGIN; } } My code is based off of the fossil generation code. Picture of the issue: Edited March 9, 20178 yr by LogicTechCorp
March 9, 20178 yr 14 hours ago, LogicTechCorp said: it does not work correctly. Looks correct to me. What was I supposed to notice? 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.
March 9, 20178 yr Author 2 hours ago, jeffryfisher said: Looks correct to me. What was I supposed to notice? The structure was saved with the air blocks around it to give it some padding. There were blocks where the structure spawned and were removed when it spawned.
March 9, 20178 yr 51 minutes ago, LogicTechCorp said: The structure was saved with the air blocks around it to give it some padding. There were blocks where the structure spawned and were removed when it spawned. If you don't want it to replace the blocks surrounding your structure with air, remove the air blocks from your template. Also, you're just counting the air blocks that it detects at each y level you iterate over. Nothing happens if it detects a non-air block, whereas I suspect you want the counter to reset back to 0. Edited March 9, 20178 yr by TheMasterGabriel I'm guessing
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.