diamond-square 1.5.0 → 1.7.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/.github/workflows/ci.yml +1 -1
- package/.github/workflows/publish.yml +7 -5
- package/README.md +9 -0
- package/diamond_square.js +33 -40
- package/package.json +1 -1
package/.github/workflows/ci.yml
CHANGED
|
@@ -3,6 +3,9 @@ on:
|
|
|
3
3
|
push:
|
|
4
4
|
branches:
|
|
5
5
|
- master # Change this to your default branch
|
|
6
|
+
permissions:
|
|
7
|
+
id-token: write
|
|
8
|
+
contents: write
|
|
6
9
|
jobs:
|
|
7
10
|
npm-publish:
|
|
8
11
|
name: npm-publish
|
|
@@ -13,13 +16,12 @@ jobs:
|
|
|
13
16
|
- name: Set up Node.js
|
|
14
17
|
uses: actions/setup-node@master
|
|
15
18
|
with:
|
|
16
|
-
node-version:
|
|
19
|
+
node-version: 24
|
|
20
|
+
registry-url: 'https://registry.npmjs.org'
|
|
17
21
|
- id: publish
|
|
18
|
-
uses: JS-DevTools/npm-publish@
|
|
19
|
-
with:
|
|
20
|
-
token: ${{ secrets.NPM_AUTH_TOKEN }}
|
|
22
|
+
uses: JS-DevTools/npm-publish@v4
|
|
21
23
|
- name: Create Release
|
|
22
|
-
if: steps.publish.outputs.type
|
|
24
|
+
if: ${{ steps.publish.outputs.type }}
|
|
23
25
|
id: create_release
|
|
24
26
|
uses: actions/create-release@v1
|
|
25
27
|
env:
|
package/README.md
CHANGED
|
@@ -24,6 +24,15 @@ world.getBlock(new Vec3(3, 50, 3)).then(block => console.log(JSON.stringify(bloc
|
|
|
24
24
|
|
|
25
25
|
## History
|
|
26
26
|
|
|
27
|
+
### 1.7.0
|
|
28
|
+
* [Update CI to Node 24 (#25)](https://github.com/PrismarineJS/diamond-square/commit/bf96a033be58c5a2f1085074055224742c7e6bc3) (thanks @rom1504)
|
|
29
|
+
* [Fix publish condition for npm-publish v4 (#24)](https://github.com/PrismarineJS/diamond-square/commit/be7fa79cba7362f6f513a7e6aa78f97e66f14165) (thanks @rom1504)
|
|
30
|
+
* [Switch to trusted publishing via OIDC (#23)](https://github.com/PrismarineJS/diamond-square/commit/7da053d958d8b6625e7c104b8b8b85941fe3b918) (thanks @rom1504)
|
|
31
|
+
* [node 22 (#22)](https://github.com/PrismarineJS/diamond-square/commit/48828d65708d90a1e709f0b29ba958ed99161de6) (thanks @rom1504)
|
|
32
|
+
|
|
33
|
+
### 1.6.0
|
|
34
|
+
* [Update for 1.17+ (#20)](https://github.com/PrismarineJS/diamond-square/commit/1b1a097dcb64c95a921f07c07cd239d571175a57) (thanks @extremeheat)
|
|
35
|
+
|
|
27
36
|
### 1.5.0
|
|
28
37
|
* [Update publish.yml](https://github.com/PrismarineJS/diamond-square/commit/4e5681e3d12fbeca9f809c472ecbb148689fabaf) (thanks @rom1504)
|
|
29
38
|
|
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')(
|
|
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
|
-
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
|
|
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
|
-
|
|
113
|
-
|
|
114
|
-
|
|
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
|
-
|
|
120
|
-
|
|
121
|
-
|
|
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.
|
|
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
|