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 }