-
Notifications
You must be signed in to change notification settings - Fork 0
WorldGeneration
Code at: https://github.com/OxillenGlow/MtSharpGrain/blob/main/src/main/resources/chunkgen.js
Mtsharpgrain uses a deterministic, procedural world generation system to create its terrain. Every chunk is generated using a combination of mathematical functions and pseudo-randomness, ensuring consistency across the world and between game sessions.
The world is divided into 16x16x16 chunks, and each chunk is generated independently using a seed value. The generation pipeline combines multiple layers of terrain features, including:
- Base heightmap (rolling sine/cosine waves)
- Sparse terrain features (mountains and slashes)
- Polar ice caps (linear cone-shaped ice layers)
- Subsurface layers (dirt/rock gradient and underground ores)
- Surface decorations (stray dirt/rock nubs)
- Chunk-level templates (rare storage structures)
- Spherical "ball" structures (glass shell with grass interior)
- A pure function that takes
(ix, iz, seed)and returns a pseudo-random value in[0, 1). - Used as the single source of randomness for all other functions, ensuring 100% order-independent and reproducible generation.
- A combination of three stacked sine/cosine waves at different frequencies and amplitudes.
- Creates a rolling, Mars-like dune terrain with a height range of roughly ±10 blocks.
- Formula:
h += 6 * Math.sin(wx * 0.013 + seed) * Math.cos(wz * 0.011 - seed); h += 3 * Math.sin(wx * 0.041 - seed * 0.7) * Math.cos(wz * 0.037 + seed * 0.7); h += 1.2 * Math.sin(wx * 0.097 + seed * 1.3) * Math.cos(wz * 0.083 - seed * 1.3);
- Mountains: Cone-shaped peaks with a radius of 40–150 blocks and a height of 20–80 blocks.
- Slashes: Capsule-shaped pits with a length of 200–1000 blocks, width of 20–60 blocks, and depth of 15–50 blocks.
- Features are spawned in ~40% of cells (20% mountains, 20% slashes).
- Features are placed on a coarse grid with a cell size of 600 blocks and a maximum reach of 600 blocks.
- A linear cone centered at the world origin (
0, 0). - Full thickness (10 blocks) at the origin, tapering to 0 at a radius of 10,000 blocks.
- Ice layers are raised by 1.5 blocks where they exist.
- The top 4 layers below the surface use a dirt/rock gradient based on depth:
- 99% dirt at the topmost layer.
- 80% dirt at the second layer.
- 60% dirt at the third layer.
- 10% dirt at the fourth layer.
- Below this, the terrain is pure rock.
- Stone is the default underground block.
-
Crystal Ore (block ID 5) has a chance of spawning that increases with depth:
- Base chance: 1%
- Increases by 0.06% per block below the surface (capped at 10%).
- 2% chance of a stray dirt nub (block ID 3).
- 1% chance of a stray rock nub (block ID 2).
- 5% chance of an extra dirt block on top of the surface (only on dirt, not ice).
-
All-Air Chunks: If a chunk is entirely above the surface, there is a 0.5% chance of replacing it with a storage template (
storageAir). -
All-Underground Chunks: If a chunk is entirely below the surface, there is a 10% chance of replacing it with a storage template (
storageGround).
- 5% of chunks that contain both air and ground will generate a spherical structure.
- Radius: 5–10 blocks.
-
Composition:
- Inner region: Dirt is replaced with grass (block ID 4).
- Outer shell (2-block thick): Glass (block ID 10).
- Placement: Centered on the surface boundary (between air and ground).
| ID | Block Type |
|---|---|
| 0 | Air |
| 2 | Rock |
| 3 | Dirt |
| 4 | Grass |
| 5 | Crystal Ore |
| 6 | Ice |
| 7 | Not naturally spawned |
| 8 | Not naturally spawned |
| 10 | Glass |
- Adjust the amplitudes and frequencies in
baseHeightto change the rolling terrain shape. - Modify the feature spawn rates in
featureAtto control the density of mountains and slashes. - Tweak the ice cap radius and thickness in
iceThicknessto change polar regions. - Change the dirt/rock gradient in
DIRT_CHANCE_BY_DEPTHto alter subsurface layers. - Adjust the ore spawn chance in
pickUndergroundBlockto control resource distribution.
- The generation is fully deterministic, meaning the same seed will always produce the same world.
- Chunks are generated independently, allowing for infinite world expansion without pre-generation.
- The use of
hash2ensures no reliance onMath.random(), making the system thread-safe and reproducible.
(don't worry ANYONE can make their own mod as modding is super easy especially with AI. You can make a mini game mod of whatever fun idea you had!)
jVisualScripting (still in construction 🚧)
Go to Downloads scroll down to bottom of the release card and click the assets to find the build for your platform. For more see install page
MtSharpGrain