Jump to content

[1.8.8] Structure generation generating in wrong Y coordenet


Recommended Posts

Posted

I'm working on making a structure but it keeps generating at the world height and not at the ground level, I have tried a lot of times but they just don't generate right.

 

package com.moreoresmod.main.worldgeneration.structure;

import java.util.List;
import java.util.Random;

import com.google.common.collect.Lists;
import com.moreoresmod.main.entitys.EntityDungonProtector;
import com.moreoresmod.main.init.MoreOresModBiomes;
import com.moreoresmod.main.init.MoreOresModBlocks;
import com.moreoresmod.main.init.MoreOresModItems;

import net.minecraft.block.BlockChest;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityChest;
import net.minecraft.tileentity.TileEntityMobSpawner;
import net.minecraft.util.BlockPos;
import net.minecraft.util.WeightedRandomChestContent;
import net.minecraft.world.World;
import net.minecraft.world.biome.BiomeGenBase;
import net.minecraft.world.chunk.IChunkProvider;
import net.minecraftforge.common.ChestGenHooks;
import net.minecraftforge.fml.common.IWorldGenerator;

public class Structures implements IWorldGenerator {

@Override
public void generate(Random random, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, IChunkProvider chunkProvider) {
	if(world.provider.getDimensionId() == 0){
		if(world.getBiomeGenForCoords(new BlockPos(chunkX*16, 64, chunkZ*16)).equals(MoreOresModBiomes.otherlyworldBiome)){
			//generateTeleporterStructure(random,chunkX,chunkZ,world);
		}
	}else if(world.provider.getDimensionId() == 2){
		generateOtherlyworldDungen(random, chunkX, chunkZ, world);
	}


}

private void generateTeleporterStructure(Random random, int chunkX, int chunkZ, World world){
	int startX = chunkX * 16 + random.nextInt(16);
	int startY = world.getActualHeight() - 256 + random.nextInt(50);
	int startZ = chunkZ * 16 + random.nextInt(16);
	BlockPos pos = new BlockPos(startX,startY,startZ);
	world.setBlockState(pos, Blocks.bedrock.getDefaultState());
	int width = random.nextInt(5) *2 + 10;
	int length = width*2;
	int height = 7;
	for (int x=0; x<width; x++) {
		for (int z=0; z<length; z++) {
			for (int y=0; y<height; y++) {
				BlockPos bpos = pos.add(x, y, z);
				if (x==0 || x==width-1 || y==0 || y== height-1 || z==0 || z== length-1) 
					world.setBlockState(bpos, Blocks.bedrock.getDefaultState());
				else world.setBlockState(bpos, Blocks.air.getDefaultState());
			}
		}
	}
	int doorX = width /2;
	int chestZ = length-2;

	//door
	world.setBlockState(pos.add(doorX-1,1,0), Blocks.air.getDefaultState());
	world.setBlockState(pos.add(doorX-1,2,0), Blocks.air.getDefaultState());
	world.setBlockState(pos.add(doorX,1,0), Blocks.air.getDefaultState());
	world.setBlockState(pos.add(doorX,2,0), Blocks.air.getDefaultState());

	//chest
	world.setBlockState(pos.add(doorX, 1, chestZ), Blocks.chest.getDefaultState());
	world.setBlockState(pos.add(doorX-1, 1, chestZ), Blocks.chest.getDefaultState());

}

private void generateOtherlyworldDungen(Random rand, int chunkX, int chunkZ,World world){
	int startX = chunkX * 16 + rand.nextInt(50);
	int startY = world.getActualHeight() - 1;
	int startZ = chunkZ * 16 + rand.nextInt(50);



	while(world.getBlockState(new BlockPos(startX,startY,startZ)) == Blocks.air){
		startY--;
	}

	if(world.getBlockState(new BlockPos(startX,startY,startZ)) != Blocks.air){

		BlockPos pos = new BlockPos(startX, startY, startZ);

		for(int x = pos.getX() - 5; x == pos.getX() + 5; x++){
			for(int z = pos.getZ() - 5; z == pos.getX() + 5; z++){
				int y = pos.getY();

				world.setBlockState(new BlockPos(x, y, z), MoreOresModBlocks.otherlyworld_brick.getDefaultState());

			}
		}

		BlockPos spawner1 = pos.add(-3, 0, -3);

		 world.setBlockState(spawner1, Blocks.mob_spawner.getDefaultState(), 2);
             TileEntity tileentity1 = world.getTileEntity(spawner1);

             if (tileentity1 instanceof TileEntityMobSpawner)
             {
                  ((TileEntityMobSpawner)tileentity1).getSpawnerBaseLogic().setEntityName("Darkness");
             }
             
             BlockPos spawner2 = pos.add(3, 0, -3);

		 world.setBlockState(spawner2, Blocks.mob_spawner.getDefaultState(), 2);
             TileEntity tileentity2 = world.getTileEntity(spawner2);

             if (tileentity2 instanceof TileEntityMobSpawner)
             {
                  ((TileEntityMobSpawner)tileentity2).getSpawnerBaseLogic().setEntityName("Darkness");
             }
             
             BlockPos spawner3 = pos.add(-3, 0, 3);
  			
		 world.setBlockState(spawner3, Blocks.mob_spawner.getDefaultState(), 2);
             TileEntity tileentity3 = world.getTileEntity(spawner3);

             if (tileentity3 instanceof TileEntityMobSpawner)
             {
                  ((TileEntityMobSpawner)tileentity3).getSpawnerBaseLogic().setEntityName("Darkness");
             }

             BlockPos spawner4 = pos.add(3, 0, 3);
   			
		 world.setBlockState(spawner4, Blocks.mob_spawner.getDefaultState(), 2);
             TileEntity tileentity4 = world.getTileEntity(spawner4);

             if (tileentity4 instanceof TileEntityMobSpawner)
             {
                  ((TileEntityMobSpawner)tileentity4).getSpawnerBaseLogic().setEntityName("Darkness");
             }
             
	}

}

}

[\code]

Posted

It appears in 1.8.8 forge they removed world.getHeightValue Is there another way?

 

The method you want is

World#getHeight(BlockPos)

in 1.8+.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

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.