Skip to content

Commit

Permalink
🔨 Add gamemode parser (SpyglassMC#1075)
Browse files Browse the repository at this point in the history
  • Loading branch information
NeunEinser authored May 6, 2024
1 parent db8f41b commit 911a92f
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
2 changes: 2 additions & 0 deletions packages/java-edition/src/mcfunction/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`),
Expand Down
3 changes: 3 additions & 0 deletions packages/java-edition/src/mcfunction/completer/argument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { getTagValues } from '../../common/index.js'
import {
ColorArgumentValues,
EntityAnchorArgumentValues,
GamemodeArgumentValues,
ItemSlotArgumentValues,
OperationArgumentValues,
ScoreboardSlotArgumentValues,
Expand Down Expand Up @@ -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':
Expand Down
10 changes: 4 additions & 6 deletions packages/java-edition/src/mcfunction/parser/argument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { ReleaseVersion } from '../../dependency/index.js'
import {
ColorArgumentValues,
EntityAnchorArgumentValues,
GamemodeArgumentValues,
ItemSlotArgumentValues,
OperationArgumentValues,
ScoreboardSlotArgumentValues,
Expand Down Expand Up @@ -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':
Expand Down Expand Up @@ -898,12 +901,7 @@ function selector(): core.Parser<EntitySelectorNode> {
.BrigadierUnquotableOption,
value: {
type: 'literal',
parser: core.literal(
'adventure',
'creative',
'spectator',
'survival',
),
parser: core.literal(...GamemodeArgumentValues),
},
}),
),
Expand Down
4 changes: 4 additions & 0 deletions packages/java-edition/src/mcfunction/tree/argument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -255,6 +258,7 @@ export type ArgumentTreeNode =
| MinecraftEntitySummonArgumentTreeNode
| MinecraftFloatRangeArgumentTreeNode
| MinecraftFunctionArgumentTreeNode
| MinecraftGamemodeArgumentTreeNode
| MinecraftGameProfileArgumentTreeNode
| MinecraftIntRangeArgumentTreeNode
| MinecraftItemEnchantmentArgumentTreeNode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down

0 comments on commit 911a92f

Please sign in to comment.