Skip to content

Commit bf84ca6

Browse files
authored
Add isWaterlogged to API (#105)
* Add waterlog to api * update types * investigate test fail * ok
1 parent 785b74b commit bf84ca6

File tree

3 files changed

+30
-14
lines changed

3 files changed

+30
-14
lines changed

doc/API.md

+14-5
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,27 @@ Tells you how long it will take to dig the block, in milliseconds.
4949
* `enchantments` list of enchantments from the held item (from simplified nbt data) **AND** equipped armor - Aqua Affinity enchantment on helmet also affects breaking speed
5050
* `effects` effects on the bot (bot.entity.effects)
5151

52-
#### block.position
52+
#### block.stateId
5353

54-
Vec3 instance.
54+
The numeric ID for this block and its state, post-flattening. Pre-flattening, this is generated by combining the block ID and the metadata bits into one integer.
5555

5656
#### block.type
5757

58-
Numerical id.
58+
The numeric ID for this block, pre-flattening. Post-flattening, this holds the index for the block in minecraft-data's block list.
5959

6060
#### block.name
6161

62-
Minecraft ID (string) of the block.
62+
A string used to uniquely identify this block internally.
6363

6464
#### block.displayName
6565

66-
Display name of the block.
66+
The English formatted display name for this block.
67+
68+
#### block.position
69+
70+
Vec3 instance.
71+
72+
*Note: This is not present on prismarine-block instantiation, it's defined externally by prismarine-chunk's `getBlock` methods.*
6773

6874
#### block.shapes
6975

@@ -113,6 +119,9 @@ If the block is a painting, contains information about the painting.
113119

114120
Boolean, whether the block is considered diggable.
115121

122+
#### block.isWaterlogged
123+
Whether the block's state is currently waterlogged. This is only possible since [the aqatic update](https://minecraft.wiki/w/Update_Aquatic).
124+
116125
#### block.boundingBox
117126

118127
The shape of the block according to the physics engine's collision detection. Currently one of:

index.d.ts

+10-8
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ export declare class Block {
2525
*/
2626
constructor(type: number, biomeId: number, metadata: number, stateId?: number);
2727

28+
// The numeric ID for this block and its state, post-flattening. Pre-flattening, this is generated by combining the block ID and the metadata bits into one integer.
29+
stateId: number;
30+
// The numeric ID for this block, pre-flattening. Post-flattening, this holds the index for the block in minecraft-data's block list.
2831
type: number;
2932

3033
/**
@@ -52,13 +55,6 @@ export declare class Block {
5255
*/
5356
biome: Biome;
5457

55-
/**
56-
* Position of the block
57-
*/
58-
position: Vec3;
59-
60-
stateId?: number;
61-
6258
/**
6359
* Minecraft Id (string) of the block
6460
* @example diamond_ore
@@ -97,6 +93,9 @@ export declare class Block {
9793
*/
9894
diggable: boolean;
9995

96+
// Whether the block's state is currently waterlogged. This is only possible since [the aqatic update](https://minecraft.wiki/w/Update_Aquatic).
97+
isWaterlogged?: boolean
98+
10099
/**
101100
* This tells what types of tools will be effective against the block.
102101
* Possible values are: null, rock, wood, plant, melon, leaves, dirt, web, and wool.
@@ -183,12 +182,15 @@ export declare class Block {
183182
*/
184183
static fromString(stateString: string, biomeId: number): Block;
185184

185+
// Position of the block (mineflayer)
186+
position: Vec3;
187+
186188
/**
187189
* (Bedrock Edition) Returns an integer hash to represent the block state
188190
* @param prefixedName name of the block, with a minecraft: prefix
189191
* @param states a record of block state properties
190192
*/
191-
static getHash(prefixedName: string, states: States): number | undefined
193+
static getHash(prefixedName: string, states: States): number | undefined;
192194
}
193195

194196
/** @deprecated */

index.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ function provider (registry, { Biome, version }) {
163163
this.diggable = false
164164
}
165165

166+
// Properties - this is set for all versions even those with metadata
166167
this._properties = {}
167168
if (version.type === 'pc') {
168169
if (usesBlockStates) {
@@ -183,15 +184,19 @@ function provider (registry, { Biome, version }) {
183184
if (this._properties) break
184185
}
185186
}
187+
this._properties ??= {}
186188
}
187189
} else if (version.type === 'bedrock') {
188190
const states = registry.blockStates?.[this.stateId]?.states || {}
189191
for (const state in states) {
190192
this._properties[state] = states[state].value
191193
}
194+
} else {
195+
throw new Error('Unknown registry type: ' + version.type)
192196
}
197+
this.isWaterlogged = this._properties.waterlogged
193198

194-
// This can be expanded to other non-sign related things
199+
// Extras - Inject helper methods based on the specific block type.
195200
if (this.name.includes('sign')) {
196201
mergeObject(this, blockMethods.sign)
197202
}

0 commit comments

Comments
 (0)