Jump to content

Recommended Posts

Posted

I'm not sure if this is a bug or if done or missed something.

 

I have created a new WorldType, where I have overridden getChunkManager and getChunkGenerator.

 

I also have 2 biomes types, "Grassland" and "Desert", which are generated using perlin noise. I have used grass blocks for the grassland biome and sand blocks for the desert biome.

 

But as you can see from the screen shot below, the F3 debug info is displaying a different biome to what the block is, minecraft is also coloring the grass as if it is the desert biome.

 

 

iMzgkTC.png

 

 

WorldType

 

public class WorldTypeYAWGM extends WorldType
{
public WorldChunkManager yawgmChunkManager = null;

public WorldTypeYAWGM()
{
	super(Reference.MOD_ID);
}


@Override
	public WorldChunkManager getChunkManager(World world) {
	if ( yawgmChunkManager == null ) {
		yawgmChunkManager = new ChunkManagerYAWGM(world);
	}

	return yawgmChunkManager;
}

@Override
public IChunkProvider getChunkGenerator(World world, String generatorOptions)
{
	return new ChunkGeneratorYAWGM(world);
}

@Override
public float getCloudHeight()
{
	return 256F;
}
}

 

 

WorldChunkManager

 

public class ChunkManagerYAWGM extends WorldChunkManager
{
private BiomeCache biomeCache;
private List biomesToSpawnIn;

public CellNoise biomecell;
private PerlinNoise perlin;

public World world;

public ChunkManagerYAWGM(World world) {
	this.world = world;
	this.biomeCache = new BiomeCache(this);
	this.biomesToSpawnIn = new ArrayList();

	biomecell = new CellNoise(world.getSeed(), (short)0);
	this.perlin = new PerlinNoise(world.getSeed());


}

public float getBiomeNoiseAt (int x, int z ) {

	float temp_variance = 800F;

	float b = perlin.noise2(x / temp_variance, z / temp_variance);
	b += (perlin.noise2(x / 20f, z / 20f) * 0.1f);
	b *= 0.5f;
	b += 0.5f;

	b = b < 0f ? 0f : b >= 0.9999999f ? 0.9999999f : b;

	return b;
}

public SubBiome getBiomeDataAt ( int x, int z ) {

	SubBiome output = null;

	float b = getBiomeNoiseAt(x, z);
	if ( b < 0.5f ) {
		output = SubBiome.grassland;
	}
	else {
		output = SubBiome.desert;
	}

	return output;
}



@Override
public BiomeGenBase getBiomeGenAt(int x, int z) {

	return getBiomeDataAt(x, z).baseBiome;
}


@Override
public List getBiomesToSpawnIn() {
	LogHelper.info("getBiomesToSpawnIn");
	return this.biomesToSpawnIn;
}

@Override
public float[] getRainfall(float[] listToReuse, int x, int y, int width, int length) {
	LogHelper.info("getRainfall");
	return listToReuse;
}

@Override
public float getTemperatureAtHeight(float par1, int par2) {
	LogHelper.info("getTemperatureAtHeight: " + par1);
	return par1;
}

@Override
public BiomeGenBase[] getBiomesForGeneration(BiomeGenBase[] par1ArrayOfBiomeGenBase, int par2, int par3, int par4, int par5) {
	LogHelper.info("getBiomesForGeneration");
	return par1ArrayOfBiomeGenBase;
}

@Override
public BiomeGenBase[] loadBlockGeneratorData(BiomeGenBase[] par1ArrayOfBiomeGenBase, int par2, int par3, int par4, int par5) {
	LogHelper.info("loadBlockGeneratorData");
	return this.getBiomeGenAt(par1ArrayOfBiomeGenBase, par2, par3, par4, par5, true);
}

@Override
public BiomeGenBase[] getBiomeGenAt(BiomeGenBase[] listToReuse, int x, int y, int width, int length, boolean cacheFlag) {
	LogHelper.info("getBiomeGenAt 2");
	return listToReuse;
}

@Override
public boolean areBiomesViable(int x, int y, int par3, List par4List) {
	LogHelper.info("areBiomesViable");
	return false;
}

@Override
public ChunkPosition findBiomePosition(int p_150795_1_, int p_150795_2_, int p_150795_3_, List p_150795_4_, Random p_150795_5_) {
	LogHelper.info("findBiomePosition");
	return null;
}

@Override
public void cleanupCache()
{
	this.biomeCache.cleanupCache();
}
}

 

 

IChunkProvider

 

public class ChunkGeneratorYAWGM  implements IChunkProvider
{
private World world;
private long seed;

private ChunkManagerYAWGM chunkManager;

private Random 		rand;
private PerlinNoise perlin;
private CellNoise 	cellNoise;

private SubBiome[] biomesForGeneration;

private BiomeGenBase[] baseBiomesList;

private int[] biomeData;
private float[] heightMap;

public ChunkGeneratorYAWGM(World world) {
	this.world = world;
	this.seed = world.getSeed();
	this.rand = new Random(this.seed);
	this.perlin = new PerlinNoise(seed);

	this.cellNoise = new CellNoise(seed, (short)0);
	this.cellNoise.setUseDistance(true);

	this.chunkManager = (ChunkManagerYAWGM)world.getWorldChunkManager();

	baseBiomesList = new BiomeGenBase[256];
	heightMap = new float[256];

}


@Override
public Chunk provideChunk(int chunkX, int chunkZ)
{
	biomesForGeneration = new SubBiome[256];

	//LogHelper.info("provideChunk: " + chunkX + " - " + chunkY);
	rand.setSeed((long)chunkX * 0x4f9939f508L + (long)chunkZ * 0x1ef1565bd5L);

	Block[] blocks = new Block[65536];
	byte[] metadata = new byte[65536];
	float[] noise = new float[256];

	generateTerrain(blocks, chunkX, chunkZ, biomesForGeneration, noise);
	for(int k = 0; k < 256; k++)
	{
		baseBiomesList[k] = biomesForGeneration[k].baseBiome;
	}
	replaceBlocksForBiome(chunkX, chunkZ, blocks, biomesForGeneration, metadata, baseBiomesList);

	Chunk chunk = new Chunk(this.world, blocks, metadata, chunkX, chunkZ);
	byte[] abyte1 = chunk.getBiomeArray();
	for (int k = 0; k < abyte1.length; ++k)
	{
		abyte1[k] = (byte)this.baseBiomesList[k].biomeID;
	}
	chunk.generateSkylightMap();


	return chunk;
}


public void generateTerrain(Block[] blocks, int chunkX, int chunkZ, SubBiome biomes[], float[] n) {
	int b, r, height, xzIdx;

	genNoise(chunkX * 16, chunkZ * 16, biomes);

	for ( int x = 0; x < 16; x++ ) {
		for ( int z = 0; z < 16; z++ ) {

			xzIdx = x * 16 + z;
			height = (int)heightMap[xzIdx];

			for ( int y = 0; y < 256; y++ ) {
				b = xzIdx * 256 + y;

				if ( y > height ) {
					if ( y < 63 ) {
						blocks[b] = Blocks.water;
					}
					else {
						blocks[b] = Blocks.air;
					}

				}
				else {
					blocks[b] = Blocks.stone;
				}
			}
			n[xzIdx] = heightMap[xzIdx];
		}
	}
}


public void genNoise(int worldX, int worldZ, SubBiome biomes[]) {

	int x, z, xIdx, zIdx, k, l, idx, biomeIdx, i;

	for ( x = 0; x < 16; x++ ) {
		for ( z = 0; z < 16; z++ ) {


			if ( x + worldX == 19 && z + worldZ == 28 ) {
				LogHelper.info("genNoise: " + worldX + " - " + worldZ);
				LogHelper.info ( "genNoise - BIOME: " + this.chunkManager.getBiomeDataAt(worldX + x, worldZ + z).baseBiome.biomeName );
				LogHelper.info( "Seed: " + this.chunkManager.biomecell.getSeed());

			}

			heightMap[x * 16 + z] = 0f;

			SubBiome subBiome = this.chunkManager.getBiomeDataAt(worldX + x, worldZ + z);
			biomes[x * 16 + z] = subBiome;

			float rNoise = subBiome.rNoise(perlin, cellNoise, worldX + x, worldZ + z, 0f/*ocean*/, 0f, 0f);
			heightMap[x * 16 + z] = rNoise;


		}
	}

}


public void replaceBlocksForBiome(int chunkX, int chunkZ, Block[] blocks, SubBiome[] biomes, byte[] metadata, BiomeGenBase[] base) {
	int x, z;
	int worldX = chunkX * 16;
	int worldZ = chunkZ * 16;

	ChunkProviderEvent.ReplaceBiomeBlocks event = new ChunkProviderEvent.ReplaceBiomeBlocks(this, chunkX, chunkZ, blocks, metadata, base, this.world);
	MinecraftForge.EVENT_BUS.post(event);
	if (event.getResult() == Event.Result.DENY) return;


	for(x = 0; x < 16; x++) {
		for(z = 0; z < 16; z++) {

			int depth = -1;

			SubBiome biome = this.chunkManager.getBiomeDataAt(worldX + x, worldZ + z);

			biome.replace(blocks, metadata, worldX + x, worldZ + z, x, z, depth, this.world, rand, perlin, cellNoise, heightMap);

			blocks[(x * 16 + z) * 256] = Blocks.bedrock;

			if ( ConfigurationHandler.flatBedrock == false ) {
				blocks[(x * 16 + z) * 256 + rand.nextInt(2)] = Blocks.bedrock;
				blocks[(x * 16 + z) * 256 + rand.nextInt(3)] = Blocks.bedrock;
				blocks[(x * 16 + z) * 256 + rand.nextInt(4)] = Blocks.bedrock;
				blocks[(x * 16 + z) * 256 + rand.nextInt(5)] = Blocks.bedrock;
			}
		}
	}
}


@Override
public Chunk loadChunk(int x, int z)
{
	LogHelper.info("loadChunk");
	return provideChunk(x, z);
}

private double[] func_4061_a(double ad[], int i, int j, int k, int l, int i1, int j1)
{
	return null;
}

@Override
public boolean chunkExists(int p_73149_1_, int p_73149_2_)
{
	LogHelper.info("chunkExists");
	return true;
}

@Override
public void populate(IChunkProvider chunkProvider, int chunkX, int chunkZ)
{
	BlockFalling.fallInstantly = true;
	this.world.scheduledUpdatesAreImmediate = true;

	this.world.scheduledUpdatesAreImmediate = false;
	BlockFalling.fallInstantly = false;
}

@Override
public boolean saveChunks(boolean p_73151_1_, IProgressUpdate p_73151_2_)
{
	LogHelper.info("saveChunks");
	return true;
}

@Override
public boolean unloadQueuedChunks()
{
	//LogHelper.info("unloadQueuedChunks");
	return false;
}

@Override
public boolean canSave()
{
	LogHelper.info("canSave");
	return true;
}

@Override
public String makeString()
{
	LogHelper.info("makeString");
	return null;
}

@Override
public List getPossibleCreatures(EnumCreatureType p_73155_1_, int p_73155_2_, int p_73155_3_, int p_73155_4_)
{
	//LogHelper.info("getPossibleCreatures");
	return null;
}

@Override
public ChunkPosition func_147416_a(World p_147416_1_, String p_147416_2_, int p_147416_3_, int p_147416_4_, int p_147416_5_)
{
	LogHelper.info("func_147416_a");
	return null;
}

@Override
public int getLoadedChunkCount()
{
	LogHelper.info("getLoadedChunkCount");
	return 0;
}

@Override
public void saveExtraData()
{
	LogHelper.info("saveExtraData");
}

@Override
public void recreateStructures(int p_82695_1_, int p_82695_2_)
{
	//LogHelper.info("recreateStructures");
}


}

 

 

This has been driving me crazy for days now.

 

Any help would be greatly appreciated.

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.