sandstone 1.1.2 → 1.1.3

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "sandstone",
3
3
  "description": "Sandstone, a Typescript library for Minecraft datapacks & resource packs.",
4
- "version": "1.1.2",
4
+ "version": "1.1.3",
5
5
  "contributors": [
6
6
  {
7
7
  "name": "TheMrZZ - Florian ERNST",
@@ -71,7 +71,7 @@
71
71
  "publishToNpm": "bun dev:build && bun publish",
72
72
  "format": "bun oxlint src --fix",
73
73
  "lint": "bun oxlint src",
74
- "update-from-mcdoc": "mcdoc-ts-generator --out-dir \"src/arguments/generated/\" --no-tsconfig"
74
+ "update-from-mcdoc": "MCDOC_TARGET_VERSION=26.2 mcdoc-ts-generator --out-dir \"src/arguments/generated/\" --no-tsconfig"
75
75
  },
76
76
  "type": "module",
77
77
  "main": "dist/exports/index.js",
@@ -1,4 +1,5 @@
1
1
  import type { Macroable } from 'sandstone/core'
2
+ import type { AllowConst } from 'sandstone/utils'
2
3
  import type { VectorClass } from 'sandstone/variables'
3
4
 
4
5
  type AbsoluteFloat<MACRO extends boolean = false> = Macroable<`${number}` | number, MACRO>
@@ -19,31 +20,24 @@ type LocalVec2<MACRO extends boolean = false> = Macroable<`${LocalFloat} ${Local
19
20
  type VectorArrayComponent<MACRO extends boolean = false> = Macroable<AbsoluteOrRelativeFloat<MACRO> | LocalFloat<MACRO> | number, MACRO>
20
21
 
21
22
  export type AbsoluteCoordinates<MACRO extends boolean = false> =
22
- | [x: AbsoluteFloat<MACRO>, y: AbsoluteFloat<MACRO>, z: AbsoluteFloat<MACRO>]
23
- | readonly [x: AbsoluteFloat<MACRO>, y: AbsoluteFloat<MACRO>, z: AbsoluteFloat<MACRO>]
23
+ | AllowConst<[x: AbsoluteFloat<MACRO>, y: AbsoluteFloat<MACRO>, z: AbsoluteFloat<MACRO>]>
24
24
  | VectorClass<[string, string, string]>
25
25
  | AbsoluteVec3<MACRO>
26
26
 
27
27
  export type Coordinates<MACRO extends boolean = false> =
28
- | [x: VectorArrayComponent<MACRO>, y: VectorArrayComponent<MACRO>, z: VectorArrayComponent<MACRO>]
29
- | readonly [x: VectorArrayComponent<MACRO>, y: VectorArrayComponent<MACRO>, z: VectorArrayComponent<MACRO>]
28
+ | AllowConst<[x: VectorArrayComponent<MACRO>, y: VectorArrayComponent<MACRO>, z: VectorArrayComponent<MACRO>]>
30
29
  | VectorClass<[string, string, string]>
31
30
  | AbsoluteOrRelativeVec3<MACRO>
32
31
  | LocalVec3<MACRO>
33
32
  export type Rotation<MACRO extends boolean = false> =
34
- | [
33
+ | AllowConst<[
35
34
  horizontal: Macroable<AbsoluteOrRelativeFloat<MACRO> | number, MACRO>,
36
35
  vertical: Macroable<AbsoluteOrRelativeFloat<MACRO> | number, MACRO>,
37
- ]
38
- | readonly [
39
- horizontal: Macroable<AbsoluteOrRelativeFloat<MACRO> | number, MACRO>,
40
- vertical: Macroable<AbsoluteOrRelativeFloat<MACRO> | number, MACRO>,
41
- ]
36
+ ]>
42
37
  | VectorClass<[string, string]>
43
38
  | AbsoluteOrRelativeVec2<MACRO>
44
39
  export type ColumnCoordinates<MACRO extends boolean = false> =
45
- | [x: VectorArrayComponent<MACRO>, z: VectorArrayComponent<MACRO>]
46
- | readonly [x: VectorArrayComponent<MACRO>, z: VectorArrayComponent<MACRO>]
40
+ | AllowConst<[x: VectorArrayComponent<MACRO>, z: VectorArrayComponent<MACRO>]>
47
41
  | VectorClass<[string, string]>
48
42
  | AbsoluteOrRelativeVec2<MACRO>
49
43
  | LocalVec2<MACRO>
@@ -1,10 +1,11 @@
1
- import type { Coordinates, NBTObject, SymbolBlock, SymbolMcdocBlockStates } from 'sandstone/arguments'
1
+ import type { Coordinates, RootNBT, SymbolBlock, SymbolMcdocBlockStates } from 'sandstone/arguments'
2
2
  import type { Macroable, TagClass } from 'sandstone/core'
3
3
  import { CommandNode } from 'sandstone/core/nodes'
4
4
  import { coordinatesParser, nbtResolver } from 'sandstone/variables'
5
5
  import { CommandArguments, type FinalCommandOutput } from '../../helpers'
6
6
  import type { Registry } from 'sandstone/arguments/generated/registry'
7
7
  import { blockStateStringifier, type BlockEntity, type BlockStatic, type ParseBlockState } from './setblock'
8
+ import type { AllowConst } from 'sandstone/utils'
8
9
 
9
10
  export class FillCommandNode extends CommandNode {
10
11
  command = 'fill' as const
@@ -71,7 +72,10 @@ export class FillCommand<MACRO extends boolean> extends CommandArguments {
71
72
  to: Macroable<Coordinates<MACRO>, MACRO>,
72
73
  block: BLOCK,
73
74
  state?: Macroable<BLOCK extends keyof SymbolMcdocBlockStates ? ParseBlockState<NonNullable<SymbolMcdocBlockStates[BLOCK]>> : Record<string, string | boolean | number>, MACRO>,
74
- nbt?: Macroable<BLOCK extends keyof SymbolBlock ? NonNullable<SymbolBlock[BLOCK]> : SymbolBlock<'%fallback'>, MACRO>,
75
+ nbt?: Macroable<BLOCK extends keyof SymbolBlock
76
+ ? NonNullable<AllowConst<SymbolBlock[Extract<BLOCK, keyof SymbolBlock>]>>
77
+ : AllowConst<RootNBT>,
78
+ MACRO>,
75
79
  ): FillArgumentsCommand<MACRO>
76
80
 
77
81
  fill(
@@ -79,7 +83,7 @@ export class FillCommand<MACRO extends boolean> extends CommandArguments {
79
83
  to: Macroable<Coordinates<MACRO>, MACRO>,
80
84
  block: Macroable<Registry['minecraft:block'], MACRO>,
81
85
  state?: Record<string, string | boolean | number>,
82
- nbt?: NBTObject,
86
+ nbt?: AllowConst<RootNBT>,
83
87
  ): FillArgumentsCommand<MACRO> {
84
88
  const stateStr = state && Object.keys(state).length > 0 ? blockStateStringifier(state) : ''
85
89
  const nbtStr = nbt ? nbtResolver(nbt).toString() : ''
@@ -1,11 +1,11 @@
1
- import type { Coordinates, NBTObject, SymbolBlock, SymbolMcdocBlockStates } from 'sandstone/arguments'
1
+ import type { Coordinates, RootNBT, SymbolBlock, SymbolMcdocBlockStates } from 'sandstone/arguments'
2
2
  import type { Macroable } from 'sandstone/core'
3
3
  import { CommandNode } from 'sandstone/core/nodes'
4
4
  import { coordinatesParser, nbtResolver } from 'sandstone/variables'
5
5
  import type { FinalCommandOutput } from '../../helpers'
6
6
  import { CommandArguments } from '../../helpers'
7
7
  import type { Registry } from 'sandstone/arguments/generated/registry'
8
- import type { NamespacedLiteralUnion } from 'sandstone/utils'
8
+ import type { AllowConst, NamespacedLiteralUnion } from 'sandstone/utils'
9
9
 
10
10
  /** Converts stringified boolean/numeric literals to actual booleans/numbers */
11
11
  export type ParseLiteral<T> = (
@@ -21,7 +21,7 @@ export type ParseBlockState<T> = {
21
21
 
22
22
  export type BlockEntity = NamespacedLiteralUnion<keyof SymbolBlock>
23
23
 
24
- export type BlockStatic = NamespacedLiteralUnion<Exclude<keyof SymbolMcdocBlockStates, keyof SymbolBlock>>
24
+ export type BlockStatic = NamespacedLiteralUnion<Exclude<keyof SymbolMcdocBlockStates, keyof SymbolBlock>> | 'air' | 'minecraft:air'
25
25
 
26
26
  export class SetBlockCommandNode extends CommandNode {
27
27
  command = 'setblock' as const
@@ -37,24 +37,24 @@ export class SetBlockCommand<MACRO extends boolean> extends CommandArguments {
37
37
  * This is the basic form for simple block placement without NBT data.
38
38
  *
39
39
  * @param pos The coordinates where to place the block. Supports:
40
- * - Absolute: `abs(100, 64, 200)` - exact world coordinates
41
- * - Relative: `['~5', '~1', '~-3']` - relative to command position
42
- * - Local: `['^2', '^', '^-1']` - relative to facing direction
43
- * - Mixed: `[100, '~5', '^2']` - combination of systems
40
+ * - Absolute: `abs(100, 64, 200)` - exact world coordinates
41
+ * - Relative: `['~5', '~1', '~-3']` - relative to command position
42
+ * - Local: `['^2', '^', '^-1']` - relative to facing direction
43
+ * - Mixed: `[100, '~5', '^2']` - combination of systems
44
44
  *
45
45
  * @param block The block type to place (e.g., `'minecraft:stone'`, `'oak_log'`).
46
46
  *
47
47
  * @param state Optional block state properties as an object. The available
48
- * properties are type-checked based on the block type:
49
- * - Oak log: `{ axis: 'x' | 'y' | 'z' }`
50
- * - Redstone wire: `{ power: 0-15, north: 'none' | 'side' | 'up', ... }`
51
- * - Stairs: `{ facing: 'north' | 'south' | 'east' | 'west', half: 'top' | 'bottom', ... }`
48
+ * properties are type-checked based on the block type:
49
+ * - Oak log: `{ axis: 'x' | 'y' | 'z' }`
50
+ * - Redstone wire: `{ power: 0-15, north: 'none' | 'side' | 'up', ... }`
51
+ * - Stairs: `{ facing: 'north' | 'south' | 'east' | 'west', half: 'top' | 'bottom', ... }`
52
52
  *
53
- * @param type How to handle the placement. Options:
54
- * - `'replace'` (default): Silently replace any existing block
55
- * - `'destroy'`: Break existing block, dropping items and playing sound
56
- * - `'keep'`: Only place if the target location is air
57
- * - `'strict'`: Replace without issuing block updates
53
+ * @param flag How to handle the placement. Options:
54
+ * - `'replace'` (default): Silently replace any existing block
55
+ * - `'destroy'`: Break existing block, dropping items and playing sound
56
+ * - `'keep'`: Only place if the target location is air
57
+ * - `'strict'`: Replace without issuing block updates
58
58
  *
59
59
  * @example
60
60
  * ```ts
@@ -82,7 +82,7 @@ export class SetBlockCommand<MACRO extends boolean> extends CommandArguments {
82
82
  pos: Macroable<Coordinates<MACRO>, MACRO>,
83
83
  block: BLOCK,
84
84
  state?: Macroable<BLOCK extends keyof SymbolMcdocBlockStates ? ParseBlockState<NonNullable<SymbolMcdocBlockStates[Extract<BLOCK, keyof SymbolMcdocBlockStates>]>> : Record<string, string | boolean | number>, MACRO>,
85
- type?: 'destroy' | 'keep' | 'replace' | 'strict',
85
+ flag?: 'destroy' | 'keep' | 'replace' | 'strict',
86
86
  ): FinalCommandOutput
87
87
 
88
88
  /**
@@ -95,23 +95,27 @@ export class SetBlockCommand<MACRO extends boolean> extends CommandArguments {
95
95
  * @param pos The coordinates where to place the block. Same format as basic variant.
96
96
  *
97
97
  * @param block The block type to place. Must be a block that supports NBT data:
98
- * - `'minecraft:chest'` - for containers
99
- * - `'minecraft:command_block'` - for command storage
100
- * - `'minecraft:sign'` - for text display
101
- * - `'minecraft:spawner'` - for mob spawning
98
+ * - `'minecraft:chest'` - for containers
99
+ * - `'minecraft:command_block'` - for command storage
100
+ * - `'minecraft:sign'` - for text display
101
+ * - `'minecraft:spawner'` - for mob spawning
102
102
  *
103
103
  * @param state Optional block state properties as an object. Type-checked based on block:
104
- * - Chest: `{ facing: 'north' | 'south' | 'east' | 'west', type: 'single' | 'left' | 'right', ... }`
105
- * - Command block: `{ facing: 'north' | 'south' | 'east' | 'west' | 'up' | 'down', conditional: true | false }`
106
- * - Sign: `{ rotation: 0-15 }` or `{ facing: ... }` for wall signs
104
+ * - Chest: `{ facing: 'north' | 'south' | 'east' | 'west', type: 'single' | 'left' | 'right', ... }`
105
+ * - Command block: `{ facing: 'north' | 'south' | 'east' | 'west' | 'up' | 'down', conditional: true | false }`
106
+ * - Sign: `{ rotation: 0-15 }` or `{ facing: ... }` for wall signs
107
107
  *
108
108
  * @param nbt The NBT data object defining the block's properties:
109
- * - For chests: `{ Items: [{ Slot: 0, id: 'diamond', Count: 1 }] }`
110
- * - For signs: `{ front_text: { messages: [...] } }`
111
- * - For command blocks: `{ Command: 'say Hello' }`
112
- * - For spawners: `{ SpawnData: { id: 'minecraft:zombie' } }`
109
+ * - For chests: `{ Items: [{ Slot: 0, id: 'diamond', Count: 1 }] }`
110
+ * - For signs: `{ front_text: { messages: [...] } }`
111
+ * - For command blocks: `{ Command: 'say Hello' }`
112
+ * - For spawners: `{ SpawnData: { id: 'minecraft:zombie' } }`
113
113
  *
114
- * @param type Placement behavior, same as basic variant.
114
+ * @param flag How to handle the placement. Options:
115
+ * - `'replace'` (default): Silently replace any existing block
116
+ * - `'destroy'`: Break existing block, dropping items and playing sound
117
+ * - `'keep'`: Only place if the target location is air
118
+ * - `'strict'`: Replace without issuing block updates
115
119
  *
116
120
  * @example
117
121
  * ```ts
@@ -139,8 +143,11 @@ export class SetBlockCommand<MACRO extends boolean> extends CommandArguments {
139
143
  pos: Macroable<Coordinates<MACRO>, MACRO>,
140
144
  block: BLOCK,
141
145
  state?: Macroable<BLOCK extends keyof SymbolMcdocBlockStates ? ParseBlockState<NonNullable<SymbolMcdocBlockStates[Extract<BLOCK, keyof SymbolMcdocBlockStates>]>> : Record<string, string | boolean | number>, MACRO>,
142
- nbt?: Macroable<BLOCK extends keyof SymbolBlock ? NonNullable<SymbolBlock[Extract<BLOCK, keyof SymbolBlock>]> : SymbolBlock<'%fallback'>, MACRO>,
143
- type?: 'destroy' | 'keep' | 'replace' | 'strict',
146
+ nbt?: Macroable<BLOCK extends keyof SymbolBlock
147
+ ? NonNullable<AllowConst<SymbolBlock[Extract<BLOCK, keyof SymbolBlock>]>>
148
+ : AllowConst<RootNBT>,
149
+ MACRO>,
150
+ flag?: 'destroy' | 'keep' | 'replace' | 'strict',
144
151
  ): FinalCommandOutput
145
152
 
146
153
  setblock(
@@ -158,7 +165,7 @@ export class SetBlockCommand<MACRO extends boolean> extends CommandArguments {
158
165
  : blockStateStringifier(arg3 as any as Record<string, string | number | boolean>)
159
166
  const nbt = typeof arg4 === 'string' || arg4 === undefined ?
160
167
  ''
161
- : nbtResolver(arg4 as any as NBTObject).toString()
168
+ : nbtResolver(arg4 as any as RootNBT).toString()
162
169
  const setblockType = typeof arg4 === 'string' ? arg4 : arg5
163
170
 
164
171
  return this.finalCommand([coordinatesParser(pos), `${block}${state}${nbt}`, setblockType])
@@ -14,6 +14,7 @@ import type {
14
14
  SingleEntityArgumentOf,
15
15
  SymbolBlock,
16
16
  SymbolMcdocBlockStates,
17
+ RootNBT,
17
18
  } from 'sandstone/arguments'
18
19
  import { blockStateStringifier } from '../block/setblock'
19
20
  import type { SandstoneCommands } from 'sandstone/commands'
@@ -28,7 +29,7 @@ import type { Node } from 'sandstone/core/nodes'
28
29
  import { ContainerCommandNode } from 'sandstone/core/nodes'
29
30
  import type { _RawMCFunctionClass } from 'sandstone/core/resources/datapack/mcfunction'
30
31
  import type { SandstonePack } from 'sandstone/pack'
31
- import { makeCallable, type NamespacedLiteralUnion } from 'sandstone/utils'
32
+ import { type AllowConst, makeCallable, type NamespacedLiteralUnion } from 'sandstone/utils'
32
33
  import type { DataPointClass } from 'sandstone/variables/Data'
33
34
  import type { ObjectiveClass } from 'sandstone/variables/Objective'
34
35
  import type { ItemPredicateClass } from 'sandstone/variables/ItemPredicate'
@@ -561,15 +562,16 @@ export class ExecuteIfUnlessCommand<MACRO extends boolean> extends ExecuteComman
561
562
  ? ParseBlockState<NonNullable<SymbolMcdocBlockStates[Extract<BLOCK, keyof SymbolMcdocBlockStates>]>>
562
563
  : Record<string, string | boolean | number> | undefined, MACRO>,
563
564
  nbt: Macroable<BLOCK extends keyof SymbolBlock
564
- ? NonNullable<SymbolBlock[Extract<BLOCK, keyof SymbolBlock>]>
565
- : SymbolBlock<'%fallback'>, MACRO>,
565
+ ? NonNullable<AllowConst<SymbolBlock[Extract<BLOCK, keyof SymbolBlock>]>>
566
+ : AllowConst<RootNBT>,
567
+ MACRO>,
566
568
  ): ExecuteCommand<MACRO>
567
569
 
568
570
  block(
569
571
  pos: Macroable<Coordinates<MACRO>, MACRO>,
570
572
  block: Macroable<Registry['minecraft:block'], MACRO>,
571
573
  state?: Macroable<Record<string, string | boolean | number>, MACRO>,
572
- nbt?: Macroable<NBTObject, MACRO>,
574
+ nbt?: Macroable<AllowConst<RootNBT>, MACRO>,
573
575
  ) {
574
576
  const stateStr = state && typeof state === 'object' && Object.keys(state).length > 0
575
577
  ? blockStateStringifier(state as Record<string, string | number | boolean>)
@@ -5,6 +5,7 @@ import { NBT, nbtResolver } from 'sandstone/variables/nbt/NBTs'
5
5
  import { coordinatesParser } from 'sandstone/variables/parsers'
6
6
  import { CommandArguments } from '../../helpers'
7
7
  import type { Registry } from 'sandstone/arguments/generated/registry'
8
+ import { AllowConst } from 'sandstone/utils'
8
9
 
9
10
  export class SummonCommandNode extends CommandNode {
10
11
  command = 'summon' as const
@@ -50,7 +51,7 @@ export class SummonCommand<MACRO extends boolean> extends CommandArguments {
50
51
  summon<ENTITY extends Macroable<Registry['minecraft:entity_type'], MACRO>>(
51
52
  entity: ENTITY,
52
53
  pos?: Macroable<Coordinates<MACRO>, MACRO>,
53
- nbt?: Macroable<ENTITY extends keyof SymbolEntity ? NonNullable<SymbolEntity[ENTITY]> : RootNBT, MACRO>,
54
+ nbt?: Macroable<AllowConst<ENTITY extends keyof SymbolEntity ? NonNullable<SymbolEntity[ENTITY]> : RootNBT>, MACRO>,
54
55
  ) {
55
56
  const args: unknown[] = [entity]
56
57
  if (pos !== undefined) {
package/src/utils.ts CHANGED
@@ -721,4 +721,6 @@ export type SmartRange<Min extends number, Max extends number> = (
721
721
  : ToNegative<PositiveRange<1, Abs<Min>>> | 0 | PositiveRange<1, Max>
722
722
  :
723
723
  PositiveRange<Min, Max>
724
- )
724
+ )
725
+
726
+ export type AllowConst<T> = T | (readonly [T])[0]