diff --git a/packages/java-edition/src/mcfunction/common/index.ts b/packages/java-edition/src/mcfunction/common/index.ts index 3ee91968b..6fc48723e 100644 --- a/packages/java-edition/src/mcfunction/common/index.ts +++ b/packages/java-edition/src/mcfunction/common/index.ts @@ -4,6 +4,8 @@ export const ColorArgumentValues = [...core.Color.ColorNames, 'reset'] export const EntityAnchorArgumentValues = ['feet', 'eyes'] +export const GamemodeArgumentValues = ['adventure', 'survival', 'creative', 'spectator'] + export const ItemSlotArgumentValues = [ ...[...Array(54).keys()].map((n) => `container.${n}`), ...[...Array(27).keys()].map((n) => `enderchest.${n}`), diff --git a/packages/java-edition/src/mcfunction/completer/argument.ts b/packages/java-edition/src/mcfunction/completer/argument.ts index febbaae44..84aab0ae3 100644 --- a/packages/java-edition/src/mcfunction/completer/argument.ts +++ b/packages/java-edition/src/mcfunction/completer/argument.ts @@ -30,6 +30,7 @@ import { getTagValues } from '../../common/index.js' import { ColorArgumentValues, EntityAnchorArgumentValues, + GamemodeArgumentValues, ItemSlotArgumentValues, OperationArgumentValues, ScoreboardSlotArgumentValues, @@ -103,6 +104,8 @@ export const getMockNodes: mcf.completer.MockNodesGetter = ( return ResourceLocationNode.mock(range, { category: 'entity_type' }) case 'minecraft:function': return ResourceLocationNode.mock(range, { category: 'function' }) + case 'minecraft:gamemode': + return LiteralNode.mock(range, { pool: GamemodeArgumentValues }) case 'minecraft:int_range': return IntRangeNode.mock(range) case 'minecraft:item_enchantment': diff --git a/packages/java-edition/src/mcfunction/parser/argument.ts b/packages/java-edition/src/mcfunction/parser/argument.ts index 7b5fb5fc8..159b6c788 100644 --- a/packages/java-edition/src/mcfunction/parser/argument.ts +++ b/packages/java-edition/src/mcfunction/parser/argument.ts @@ -8,6 +8,7 @@ import { ReleaseVersion } from '../../dependency/index.js' import { ColorArgumentValues, EntityAnchorArgumentValues, + GamemodeArgumentValues, ItemSlotArgumentValues, OperationArgumentValues, ScoreboardSlotArgumentValues, @@ -168,6 +169,8 @@ export const argument: mcf.ArgumentParserGetter = ( allowTag: true, }), ) + case 'minecraft:gamemode': + return wrap(core.literal(...GamemodeArgumentValues)) case 'minecraft:game_profile': return wrap(entity('multiple', 'players')) case 'minecraft:int_range': @@ -898,12 +901,7 @@ function selector(): core.Parser { .BrigadierUnquotableOption, value: { type: 'literal', - parser: core.literal( - 'adventure', - 'creative', - 'spectator', - 'survival', - ), + parser: core.literal(...GamemodeArgumentValues), }, }), ), diff --git a/packages/java-edition/src/mcfunction/tree/argument.ts b/packages/java-edition/src/mcfunction/tree/argument.ts index b32fdac26..53df90e6c 100644 --- a/packages/java-edition/src/mcfunction/tree/argument.ts +++ b/packages/java-edition/src/mcfunction/tree/argument.ts @@ -102,6 +102,9 @@ export interface MinecraftFunctionArgumentTreeNode { parser: 'minecraft:function' } +export interface MinecraftGamemodeArgumentTreeNode extends mcf.ArgumentTreeNode { + parser: 'minecraft:gamemode' +} export interface MinecraftGameProfileArgumentTreeNode extends mcf.ArgumentTreeNode { @@ -255,6 +258,7 @@ export type ArgumentTreeNode = | MinecraftEntitySummonArgumentTreeNode | MinecraftFloatRangeArgumentTreeNode | MinecraftFunctionArgumentTreeNode + | MinecraftGamemodeArgumentTreeNode | MinecraftGameProfileArgumentTreeNode | MinecraftIntRangeArgumentTreeNode | MinecraftItemEnchantmentArgumentTreeNode diff --git a/packages/java-edition/test/mcfunction/parser/argument.spec.ts b/packages/java-edition/test/mcfunction/parser/argument.spec.ts index 1f7e9e63c..6601f1c9d 100644 --- a/packages/java-edition/test/mcfunction/parser/argument.spec.ts +++ b/packages/java-edition/test/mcfunction/parser/argument.spec.ts @@ -130,6 +130,7 @@ const Suites: Partial< { content: ['0..5.2', '0', '-5.4', '-100.76..', '..100', '..'] }, ], 'minecraft:function': [{ content: ['foo', 'foo:bar', '#foo'] }], + 'minecraft:gamemode': [{ content: ['adventure', 'survival', 'spectator', 'creative'] }], 'minecraft:game_profile': [ { content: [