Skip to content

Commit

Permalink
✨ Implement various command parsers and tree patch changes (#1128)
Browse files Browse the repository at this point in the history
  • Loading branch information
misode authored May 12, 2024
1 parent f0d8613 commit 4f010d5
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/core/src/symbol/Symbol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ export type TagFileCategory = (typeof TagFileCategories)[number]
export const FileCategories = Object.freeze(
[
'advancement',
'chat_type',
'damage_type',
'dimension',
'dimension_type',
'function',
Expand All @@ -127,6 +129,8 @@ export const FileCategories = Object.freeze(
'predicate',
'recipe',
'structure',
'trim_material',
'trim_pattern',
...TagFileCategories,
...WorldgenFileCategories,
] as const,
Expand Down
7 changes: 6 additions & 1 deletion packages/java-edition/src/dependency/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ export const PackVersionMap: Record<number, RegExp | undefined> = {
7: /^1\.17.*$/,
8: /^1\.18(\.1)?$/,
9: /^1\.18.*$/,
10: /^1\.19.*$/,
10: /^1\.19(\.[1-3])?$/,
12: /^1\.19.*$/,
15: /^1\.20(\.1)?$/,
18: /^1\.20\.2$/,
26: /^1\.20\.[3-4]$/,
41: /^1\.20\.[5-6]$/,
}

export interface PackMcmeta {
Expand Down
22 changes: 22 additions & 0 deletions packages/java-edition/src/mcfunction/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,25 @@ export const SwizzleArgumentValues = [
'zxy',
'zyx',
]

export const HeightmapValues = [
'motion_blocking',
'motion_blocking_no_leaves',
'ocean_floor',
'ocean_floor_wg',
'world_surface',
'world_surface_wg',
]

export const RotationValues = [
'none',
'clockwise_90',
'180',
'counterclockwise_90',
]

export const MirrorValues = [
'none',
'left_right',
'front_back',
]
10 changes: 10 additions & 0 deletions packages/java-edition/src/mcfunction/completer/argument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ import {
ColorArgumentValues,
EntityAnchorArgumentValues,
GamemodeArgumentValues,
HeightmapValues,
ItemSlotArgumentValues,
MirrorValues,
OperationArgumentValues,
RotationValues,
ScoreboardSlotArgumentValues,
SwizzleArgumentValues,
} from '../common/index.js'
Expand Down Expand Up @@ -98,6 +101,8 @@ export const getMockNodes: mcf.completer.MockNodesGetter = (
case 'minecraft:entity':
case 'minecraft:game_profile':
return EntitySelectorNode.mock(range)
case 'minecraft:heightmap':
return LiteralNode.mock(range, { pool: HeightmapValues })
case 'minecraft:entity_anchor':
return LiteralNode.mock(range, { pool: EntityAnchorArgumentValues })
case 'minecraft:entity_summon':
Expand Down Expand Up @@ -130,6 +135,7 @@ export const getMockNodes: mcf.completer.MockNodesGetter = (
case 'minecraft:particle':
return ParticleNode.mock(range)
case 'minecraft:resource':
case 'minecraft:resource_key':
case 'minecraft:resource_or_tag':
return ResourceLocationNode.mock(range, {
category: ResourceLocation.shorten(treeNode.properties.registry) as
Expand All @@ -152,6 +158,10 @@ export const getMockNodes: mcf.completer.MockNodesGetter = (
return LiteralNode.mock(range, { pool: SwizzleArgumentValues })
case 'minecraft:team':
return SymbolNode.mock(range, { category: 'team' })
case 'minecraft:template_mirror':
return LiteralNode.mock(range, { pool: MirrorValues })
case 'minecraft:template_rotation':
return LiteralNode.mock(range, { pool: RotationValues })
case 'minecraft:vec2':
return VectorNode.mock(range, { dimension: 2, integersOnly: true })
case 'minecraft:vec3':
Expand Down
10 changes: 10 additions & 0 deletions packages/java-edition/src/mcfunction/parser/argument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ import {
ColorArgumentValues,
EntityAnchorArgumentValues,
GamemodeArgumentValues,
HeightmapValues,
ItemSlotArgumentValues,
MirrorValues,
OperationArgumentValues,
RotationValues,
ScoreboardSlotArgumentValues,
SwizzleArgumentValues,
} from '../common/index.js'
Expand Down Expand Up @@ -173,6 +176,8 @@ export const argument: mcf.ArgumentParserGetter = (
return wrap(core.literal(...GamemodeArgumentValues))
case 'minecraft:game_profile':
return wrap(entity('multiple', 'players'))
case 'minecraft:heightmap':
return wrap(core.literal(...HeightmapValues))
case 'minecraft:int_range':
return wrap(range('integer'))
case 'minecraft:item_enchantment':
Expand Down Expand Up @@ -221,6 +226,7 @@ export const argument: mcf.ArgumentParserGetter = (
case 'minecraft:particle':
return wrap(particle)
case 'minecraft:resource':
case 'minecraft:resource_key':
case 'minecraft:resource_or_tag':
return wrap(
core.resourceLocation({
Expand Down Expand Up @@ -257,6 +263,10 @@ export const argument: mcf.ArgumentParserGetter = (
: undefined,
),
)
case 'minecraft:template_mirror':
return wrap(core.literal(...MirrorValues))
case 'minecraft:template_rotation':
return wrap(core.literal(...RotationValues))
case 'minecraft:time':
return wrap(time)
case 'minecraft:uuid':
Expand Down
27 changes: 27 additions & 0 deletions packages/java-edition/src/mcfunction/tree/argument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ export interface MinecraftGameProfileArgumentTreeNode
{
parser: 'minecraft:game_profile'
}
export interface MinecraftHeightmapArgumentTreeNode
extends mcf.ArgumentTreeNode
{
parser: 'minecraft:heightmap'
}
export interface MinecraftIntRangeArgumentTreeNode
extends mcf.ArgumentTreeNode
{
Expand Down Expand Up @@ -184,6 +189,14 @@ export interface MinecraftResourceArgumentTreeNode
registry: string
}
}
export interface MinecraftResourceKeyArgumentTreeNode
extends mcf.ArgumentTreeNode
{
parser: 'minecraft:resource_key'
properties: {
registry: string
}
}
export interface MinecraftResourceLocationArgumentTreeNode
extends mcf.ArgumentTreeNode
{
Expand Down Expand Up @@ -222,6 +235,16 @@ export interface MinecraftSwizzleArgumentTreeNode extends mcf.ArgumentTreeNode {
export interface MinecraftTeamArgumentTreeNode extends mcf.ArgumentTreeNode {
parser: 'minecraft:team'
}
export interface MinecraftTemplateMirrorArgumentTreeNode
extends mcf.ArgumentTreeNode
{
parser: 'minecraft:template_mirror'
}
export interface MinecraftTemplateRotationArgumentTreeNode
extends mcf.ArgumentTreeNode
{
parser: 'minecraft:template_rotation'
}
export interface MinecraftTimeArgumentTreeNode extends mcf.ArgumentTreeNode {
parser: 'minecraft:time'
}
Expand Down Expand Up @@ -262,6 +285,7 @@ export type ArgumentTreeNode =
| MinecraftFunctionArgumentTreeNode
| MinecraftGamemodeArgumentTreeNode
| MinecraftGameProfileArgumentTreeNode
| MinecraftHeightmapArgumentTreeNode
| MinecraftIntRangeArgumentTreeNode
| MinecraftItemEnchantmentArgumentTreeNode
| MinecraftItemPredicateArgumentTreeNode
Expand All @@ -277,13 +301,16 @@ export type ArgumentTreeNode =
| MinecraftOperationArgumentTreeNode
| MinecraftParticleArgumentTreeNode
| MinecraftResourceArgumentTreeNode
| MinecraftResourceKeyArgumentTreeNode
| MinecraftResourceLocationArgumentTreeNode
| MinecraftResourceOrTagArgumentTreeNode
| MinecraftRotationArgumentTreeNode
| MinecraftScoreHolderArgumentTreeNode
| MinecraftScoreboardSlotArgumentTreeNode
| MinecraftSwizzleArgumentTreeNode
| MinecraftTeamArgumentTreeNode
| MinecraftTemplateMirrorArgumentTreeNode
| MinecraftTemplateRotationArgumentTreeNode
| MinecraftTimeArgumentTreeNode
| MinecraftUuidArgumentTreeNode
| MinecraftVec2ArgumentTreeNode
Expand Down
38 changes: 38 additions & 0 deletions packages/java-edition/src/mcfunction/tree/patch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,13 @@ export function getPatch(release: ReleaseVersion): PartialRootTreeNode {
help: {
permission: 0,
},
...(ReleaseVersion.cmp(release, '1.18') >= 0
? {
jfr: {
permission: 4,
},
}
: {}),
kick: {
permission: 3,
},
Expand Down Expand Up @@ -418,6 +425,30 @@ export function getPatch(release: ReleaseVersion): PartialRootTreeNode {
'pardon-ip': {
permission: 3,
},
...(ReleaseVersion.cmp(release, '1.17') >= 0
? {
perf: {
permission: 4,
},
}
: {}),
...(ReleaseVersion.cmp(release, '1.19') >= 0
? {
place: {
children: {
template: {
children: {
template: {
properties: {
category: 'structure'
}
}
}
}
}
},
}
: {}),
playsound: Sound,
publish: {
permission: 4,
Expand Down Expand Up @@ -559,6 +590,13 @@ export function getPatch(release: ReleaseVersion): PartialRootTreeNode {
tell: {
permission: 0,
},
...(ReleaseVersion.cmp(release, '1.20.2') >= 0
? {
tick: {
permission: 3,
},
}
: {}),
tm: {
permission: 0,
},
Expand Down

0 comments on commit 4f010d5

Please sign in to comment.