• Najnowsze pytania
  • Bez odpowiedzi
  • Zadaj pytanie
  • Kategorie
  • Tagi
  • Zdobyte punkty
  • Ekipa ninja
  • IRC
  • FAQ
  • Regulamin
  • Książki warte uwagi

NodeJS Perlin Noise + PrismarineJS - Generowanie Terenu w Minecraft

Cloud VPS
0 głosów
241 wizyt
pytanie zadane 16 stycznia 2021 w JavaScript przez x_000 Obywatel (1,460 p.)

Hej, tworze generator świata do Minecraft używając NodeJS, narazie wychodzi mi coś takiego: 

nie wygląda to na generator terenu minecrafta, jest gdzieś gotowy taki generator 

 

KOD:

const Vec3 = require('vec3')
function calculateLocation(x, z)
{
	let xl = x/16
	let zl = z/16
	// Change -0 to -1
	if(xl<0) xl-=1
	if(zl<0) zl-=1
	
	return({x: parseInt(xl), z: parseInt(zl)})
}

function atLocation(server, x, z)
{
	return(server.chunks[id(x,z)])
}

function id(x, z)
{
	return JSON.stringify([x,z])
}

function createExampleChunk(server, block, _x, _z)
{
	const chunk = new server.libraries['prismarine-chunk']()
	const Noise = require('noisejs')
	var noise = new Noise.Noise(100)
	for(let x=0; x<16; x++)
	{
		for(let z=0; z<16; z++)
		{
			for(let y = 0; y < 64; y++)
			{
				/*if(y == 0){ 
					chunk.setBlockType(new Vec3(x, y, z), 25) 
					chunk.setBlockData(new Vec3(x, y, z), 0)
				}
				else if(y > 0 && y < 30){
					chunk.setBlockType(new Vec3(x, y, z), 1) 
					chunk.setBlockData(new Vec3(x, y, z), 0)	
				}
				else{
					chunk.setBlockType(new Vec3(x, y, z), 8) 
					chunk.setBlockData(new Vec3(x, y, z), 1)
					for(let y=0; y<256; y++)
					{
						chunk.setSkyLight(new Vec3(x,y,z), 15) //was 15
					}
				}*/
				
				for(let y=0; y<256; y++)
				{
					chunk.setSkyLight(new Vec3(x,y,z), 15) //was 15
				}
				
				let worldX = x + _x*16
				let worldY = y
				let worldZ = z + _z*16
				
				let generatedY1 = generateHeight(worldX, worldZ, _increment)
				let generatedY2 = generateHeight(worldX, worldZ, 0.1)
				let generatedY = parseInt((generatedY1 + generatedY2) / 2)+11
				var offset = 0;
				var maxHeight = 32;
				var _increment = 0.035;
				
				function Map(from,to,from2,to2,value)
				{
					if(value <= from2) return from
					if(value >= to2) return to
					
					return (to-from) * ((value-from2) / (to2-from2)) + from
				}
				
				function generateHeight(x, z, increment)
				{
					let height = perlinNoise(x*increment + offset, z*increment + offset);
					height = Map(1, maxHeight, 0, 1, height)
					return height
				}
				
				function perlinNoise(x, z)
				{
					let height = noise.perlin2(x, z)
					return height
				}
				
				
				if(worldY <= generatedY)
				{
					if(y == generatedY){
						chunk.setBlockType(new Vec3(x, y, z), 8) 
						chunk.setBlockData(new Vec3(x, y, z), 1)
					}
					else if(y == generatedY-1 || y == generatedY-2){
						chunk.setBlockType(new Vec3(x, y, z), 9) 
						chunk.setBlockData(new Vec3(x, y, z), 0)
					}
					else if(y == 0 || y == 1){
						chunk.setBlockType(new Vec3(x, y, z), 7) 
						chunk.setBlockData(new Vec3(x, y, z), 0)
					}
					else{
						chunk.setBlockType(new Vec3(x, y, z), 1) 
						chunk.setBlockData(new Vec3(x, y, z), 0)	
					}
					
				}
				else
				{
					chunk.setBlockType(new Vec3(x, y, z), 0) 
					chunk.setBlockData(new Vec3(x, y, z), 0)
				}
				
				/*let val = noise.perlin3((_x*16+x) / 256, y/32, (_z*16+z/256))
				
				if(val * 256 + 256 > 4)
				{
					
				}*/
			}
		}
	}

	for(let x=0; x<16; x++)
		{
			for(let y = 0; y < 14; y++)
			{
				for(let z=0; z<16; z++)
				{
					if(chunk.getBlock(new Vec3(x,y,z)).stateId==0 || chunk.getBlock(new Vec3(x,y,z)).stateId=="0"){
						chunk.setBlockType(new Vec3(x, y, z), 26) 
						chunk.setBlockData(new Vec3(x, y, z), 0)
					}
				}
			}
		}
		//console.log(chunk.getBlock(new Vec3(1,1,1)),"jd")

	return(chunk)
}

module.exports = { createExampleChunk, calculateLocation, atLocation, id }  

 

Zaloguj lub zarejestruj się, aby odpowiedzieć na to pytanie.

Podobne pytania

0 głosów
1 odpowiedź 1,085 wizyt
+1 głos
1 odpowiedź 1,426 wizyt
pytanie zadane 11 lutego 2022 w OpenGL, Unity przez BarSki13 Obywatel (1,270 p.)
+1 głos
1 odpowiedź 1,649 wizyt

93,464 zapytań

142,459 odpowiedzi

322,729 komentarzy

62,844 pasjonatów

Motyw:

Akcja Pajacyk

Pajacyk od wielu lat dożywia dzieci. Pomóż klikając w zielony brzuszek na stronie. Dziękujemy! ♡

Oto polecana książka warta uwagi.
Pełną listę książek znajdziesz tutaj

Kursy INF.02 i INF.03
...