diamond-square 1.5.0 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -24,6 +24,9 @@ world.getBlock(new Vec3(3, 50, 3)).then(block => console.log(JSON.stringify(bloc
24
24
 
25
25
  ## History
26
26
 
27
+ ### 1.6.0
28
+ * [Update for 1.17+ (#20)](https://github.com/PrismarineJS/diamond-square/commit/1b1a097dcb64c95a921f07c07cd239d571175a57) (thanks @extremeheat)
29
+
27
30
  ### 1.5.0
28
31
  * [Update publish.yml](https://github.com/PrismarineJS/diamond-square/commit/4e5681e3d12fbeca9f809c472ecbb148689fabaf) (thanks @rom1504)
29
32
 
package/diamond_square.js CHANGED
@@ -3,8 +3,6 @@
3
3
  const Vec3 = require('vec3').Vec3
4
4
  const rand = require('random-seed')
5
5
 
6
- const theFlattening = ['1.13', '1.14', '1.15', '1.16']
7
-
8
6
  class DiamondSquare {
9
7
  constructor (size, roughness, seed) {
10
8
  // public fields
@@ -82,14 +80,29 @@ class DiamondSquare {
82
80
  }
83
81
  }
84
82
 
85
- function generation ({ version = '1.8', seed, worldHeight = 80, waterline = 20 } = {}) {
83
+ function generation ({ registry, version = '1.8', seed, worldHeight = 80, waterline = 20 } = {}) {
84
+ registry ??= require('prismarine-registry')(version)
85
+ const isFlatteningVersion = registry.supportFeature('theFlattening')
86
86
  // Selected empirically
87
87
  const size = 10000000
88
- const Chunk = require('prismarine-chunk')(version)
89
- const mcData = require('minecraft-data')(version)
90
- const majorVersion = mcData.version.majorVersion
88
+ const Chunk = require('prismarine-chunk')(registry)
91
89
  const space = new DiamondSquare(size, size / 500, seed)
92
90
 
91
+ const blockPalette = {
92
+ water: registry.blocksByName.water.defaultState,
93
+ stone: registry.blocksByName.stone.defaultState,
94
+ bedrock: registry.blocksByName.bedrock.defaultState,
95
+ sand: registry.blocksByName.sand.defaultState,
96
+ grassBlock: (registry.blocksByName.grass_block ?? registry.blocksByName.grass).defaultState,
97
+ tallgrass: (registry.blocksByName.tall_grass ?? registry.blocksByName.tallgrass).defaultState,
98
+ dirt: registry.blocksByName.dirt.defaultState
99
+ }
100
+ if (!isFlatteningVersion) {
101
+ // 1.8-1.12 - for state IDs, the final 4 bits are the data value
102
+ blockPalette.grassBlock |= 1 // 0 is snowy
103
+ // Default sand data is 0, but we don't need to set it as it's already 0
104
+ }
105
+
93
106
  function generateSimpleChunk (chunkX, chunkZ) {
94
107
  const chunk = new Chunk()
95
108
  const seedRand = rand.create(seed + ':' + chunkX + ':' + chunkZ)
@@ -102,40 +115,24 @@ function generation ({ version = '1.8', seed, worldHeight = 80, waterline = 20 }
102
115
  const dirtheight = level - 4 + seedRand(3)
103
116
  const bedrockheight = 1 + seedRand(4)
104
117
  for (let y = 0; y < 256; y++) {
105
- let block
106
- let data
107
- const surfaceblock = level < waterline ? mcData.blocksByName.sand.id : (isFlatteningVersion(majorVersion) ? mcData.blocksByName.grass_block.id : mcData.blocksByName.grass.id) // Sand below water, grass
108
- const belowblock = level < waterline ? mcData.blocksByName.sand.id : mcData.blocksByName.dirt.id // 3-5 blocks below surface
109
- if (y < bedrockheight) block = mcData.blocksByName.bedrock.id // Solid bedrock at bottom
110
- else if (y < level && y >= dirtheight) {
118
+ let block = null
119
+ const surfaceblock = level < waterline ? blockPalette.sand : blockPalette.grassBlock // Sand below water, grass
120
+ const belowblock = level < waterline ? blockPalette.sand : blockPalette.dirt // 3-5 blocks below surface
121
+ if (y < bedrockheight) {
122
+ block = blockPalette.bedrock // Solid bedrock at bottom
123
+ } else if (y < level && y >= dirtheight) {
111
124
  block = belowblock // Dirt/sand below surface
112
- if (isFlatteningVersion(majorVersion)) {
113
- if (level < waterline) data = 0 // Default sand data is 0
114
- else data = 1 // Default dirt data is 1, 0 is snowy
115
- }
116
- } else if (y < level) block = mcData.blocksByName.stone.id // Set stone inbetween
117
- else if (y === level) {
125
+ } else if (y < level) {
126
+ block = blockPalette.stone // Set stone inbetween
127
+ } else if (y === level) {
118
128
  block = surfaceblock // Set surface sand/grass
119
- if (isFlatteningVersion(majorVersion)) {
120
- if (level < waterline) data = 0 // Default sand data is 0
121
- else data = 1 // Default dirt data is 1, 0 is snowy
122
- }
123
- } else if (y <= waterline) block = mcData.blocksByName.water.id // Set the water
124
- else if (y === level + 1 && level >= waterline && seedRand(10) === 0) { // 1/10 chance of grass
125
- if (isFlatteningVersion(majorVersion)) {
126
- block = mcData.blocksByName.grass.id
127
- data = 0
128
- } else {
129
- block = mcData.blocksByName.tall_grass?.id ?? mcData.blocksByName.tallgrass?.id
130
- data = 1
131
- }
129
+ } else if (y <= waterline) {
130
+ block = blockPalette.water // Set the water
131
+ } else if (y === level + 1 && level >= waterline && seedRand(10) === 0) { // 1/10 chance of tall grass
132
+ block = blockPalette.tallgrass
132
133
  }
133
134
  const pos = new Vec3(x, y, z)
134
- if (block) chunk.setBlockType(pos, block)
135
- if (data) {
136
- if (isFlatteningVersion(majorVersion)) chunk.setBlockData(pos, data)
137
- else chunk.setBlockData(pos, data)
138
- }
135
+ if (block != null) chunk.setBlockStateId(pos, block)
139
136
  chunk.setSkyLight(pos, 15)
140
137
  }
141
138
  }
@@ -145,8 +142,4 @@ function generation ({ version = '1.8', seed, worldHeight = 80, waterline = 20 }
145
142
  return generateSimpleChunk
146
143
  }
147
144
 
148
- function isFlatteningVersion (version) {
149
- if (theFlattening.indexOf(version) > -1) { return true } else { return false }
150
- }
151
-
152
145
  module.exports = generation
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "diamond-square",
3
- "version": "1.5.0",
3
+ "version": "1.6.0",
4
4
  "description": "A diamond square minecraft generation",
5
5
  "main": "diamond_square.js",
6
6
  "scripts": {