Created
June 14, 2023 07:29
-
-
Save lorenzop/b52202c6ca26bc629fa36f9fa7859288 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// you'll need a noise library, this line uses the plugin pxnCommonPluginMC which has the FastNoiseLite library | |
importClass(Packages.com.poixson.utils.FastNoiseLiteD); | |
function print(msg) { | |
context.print(msg); | |
} | |
function error(msg) { | |
context.error(msg); | |
} | |
// prepare a worldedit session | |
let session = null; | |
let select_world = context.getSession().getSelectionWorld(); | |
let select_region = context.getSession().getSelection(select_world); | |
let origin = select_region.getMinimumPoint(); | |
if (!select_region | |
|| select_region.getWidth() != 1 | |
|| select_region.getLength() != 1 | |
|| select_region.getHeight() != 1) { | |
error("error: Invalid selection"); | |
error("Select a diamond block as the center origin point for the computer"); | |
} | |
// start a worldedit session (allows for //undo) | |
session = context.remember(); | |
function GetMaterial(type) { | |
return context.getBlock(type); | |
} | |
function SetBlock(x, y, z, block) { | |
session.setBlock(origin.add(x, y, z), block); | |
} | |
// example: place one block | |
//SetBlock(0, 1, 0, GetMaterial("minecraft:stone")); | |
// noise parameters | |
let noise = new FastNoiseLiteD(); | |
noise.setSeed(12354); | |
noise.setFrequency(0.03); | |
// type of noise (if wanting perlin noise, use OpenSimplex2 instead, it is a modern faster alternative) | |
noise.setNoiseType(FastNoiseLiteD.NoiseType.OpenSimplex2); | |
//noise.setNoiseType(FastNoiseLiteD.NoiseType.OpenSimplex2S); | |
//noise.setNoiseType(FastNoiseLiteD.NoiseType.Cellular); | |
//noise.setNoiseType(FastNoiseLiteD.NoiseType.Perlin); | |
//noise.setNoiseType(FastNoiseLiteD.NoiseType.ValueCubic); | |
//noise.setNoiseType(FastNoiseLiteD.NoiseType.Value); | |
// fractals give more detail to the noise | |
//noise.setFractalOctaves(2); | |
//noise.setFractalGain(0.6); | |
//noise.setFractalType(FastNoiseLiteD.FractalType.None); | |
//noise.setFractalType(FastNoiseLiteD.FractalType.FBm); | |
//noise.setFractalType(FastNoiseLiteD.FractalType.Ridged); | |
//noise.setFractalType(FastNoiseLiteD.FractalType.PingPong); | |
//noise.setFractalType(FastNoiseLiteD.FractalType.DomainWarpProgressive); | |
//noise.setFractalType(FastNoiseLiteD.FractalType.DomainWarpIndependent); | |
//noise.setCellularDistanceFunction(FastNoiseLiteD.CellularDistanceFunction.Euclidean); | |
//noise.setCellularDistanceFunction(FastNoiseLiteD.CellularDistanceFunction.EuclideanSq); | |
//noise.setCellularDistanceFunction(FastNoiseLiteD.CellularDistanceFunction.Manhattan); | |
//noise.setCellularDistanceFunction(FastNoiseLiteD.CellularDistanceFunction.Hybrid); | |
//noise.setCellularReturnType(FastNoiseLiteD.CellularReturnType.CellValue); | |
//noise.setCellularReturnType(FastNoiseLiteD.CellularReturnType.Distance); | |
//noise.setCellularReturnType(FastNoiseLiteD.CellularReturnType.Distance2); | |
//noise.setCellularReturnType(FastNoiseLiteD.CellularReturnType.Distance2Add); | |
//noise.setCellularReturnType(FastNoiseLiteD.CellularReturnType.Distance2Sub); | |
//noise.setCellularReturnType(FastNoiseLiteD.CellularReturnType.Distance2Mul); | |
//noise.setCellularReturnType(FastNoiseLiteD.CellularReturnType.Distance2Div); | |
//noise.setDomainWarpType(FastNoiseLiteD.DomainWarpType.OpenSimplex2); | |
//noise.setDomainWarpType(FastNoiseLiteD.DomainWarpType.OpenSimplex2Reduced); | |
//noise.setDomainWarpType(FastNoiseLiteD.DomainWarpType.BasicGrid); | |
// place a 50x50 area of blocks | |
let block = GetMaterial("minecraft:stone"); | |
for (let iz=0; iz<50; iz++) { | |
for (let ix=0; ix<50; ix++) { | |
// the noise value between -1.0 and 1.0 | |
let value = noise.getNoise(ix, iz); | |
// multiply by 5 for a wider range of numbers | |
let y = value * 5; | |
// place a block using the noise value as the y location | |
SetBlock(ix, y, iz, block); | |
} | |
} | |
// place the blocks and close the worldedit session | |
session.commit(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment