Skip to content

Commit

Permalink
🐛 Patch all resource_location parsers
Browse files Browse the repository at this point in the history
  • Loading branch information
SPGoding committed May 18, 2024
1 parent b626aff commit 69d2a6e
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 8 deletions.
4 changes: 4 additions & 0 deletions packages/core/src/symbol/Symbol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ export const MiscCategories = Object.freeze(
[
'attribute_modifier_uuid',
'bossbar',
'jigsaw_block_name',
'objective',
'random_sequence',
'score_holder',
'storage',
'tag',
Expand Down Expand Up @@ -171,6 +173,8 @@ export type AllCategory = (typeof AllCategories)[number]
export const ResourceLocationCategories = Object.freeze(
[
'bossbar',
'jigsaw_block_name',
'random_sequence',
'storage',
'mcdoc/dispatcher',
...FileCategories,
Expand Down
12 changes: 12 additions & 0 deletions packages/java-edition/src/dependency/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ export namespace ReleaseVersion {
export function cmp(a: ReleaseVersion, b: ReleaseVersion): number {
return Math.sign(Number(a.slice(2)) - Number(b.slice(2)))
}

/**
* @returns `true` if `version` is newer than `since` (inclusive) and older
* than `until` (exclusive)
*/
export function isBetween(
version: ReleaseVersion,
since: ReleaseVersion,
until: ReleaseVersion,
): boolean {
return cmp(version, since) >= 0 && cmp(version, until) < 0
}
}

export interface VersionInfo {
Expand Down
99 changes: 91 additions & 8 deletions packages/java-edition/src/mcfunction/tree/patch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,23 @@ export function getPatch(release: ReleaseVersion): PartialRootTreeNode {
unless: ExecuteCondition,
},
},
function: {
children: {
name: {
...(ReleaseVersion.cmp(release, '1.20.2') >= 0
? {
children: {
// Added in 23w31a (1.20.2, pack format 16)
with: DataSource,
},
}
: {}),
},
},
},
...(ReleaseVersion.cmp(release, '1.17') >= 0
? {
// Added in 20w46a (1.17, pack format 7)
item: {
children: {
replace: {
Expand Down Expand Up @@ -335,6 +350,7 @@ export function getPatch(release: ReleaseVersion): PartialRootTreeNode {
},
...(ReleaseVersion.cmp(release, '1.18') >= 0
? {
// Added in 21w37a (1.18, pack format 8)
jfr: {
permission: 4,
},
Expand All @@ -346,13 +362,16 @@ export function getPatch(release: ReleaseVersion): PartialRootTreeNode {
list: {
permission: 0,
},
...(ReleaseVersion.cmp(release, '1.16') >= 0
...(ReleaseVersion.isBetween(release, '1.16', '1.19')
? {
// Added in 20w06a (1.16, pack format 5)
// Removed in 22w19a (1.19, pack format 10)
locatebiome: {
children: {
biome: {
properties: {
category: 'worldgen/biome',
allowTag: true,
},
},
},
Expand Down Expand Up @@ -427,32 +446,95 @@ export function getPatch(release: ReleaseVersion): PartialRootTreeNode {
},
...(ReleaseVersion.cmp(release, '1.17') >= 0
? {
// Added in 1.17 Pre-release 1 (1.17, pack format 7)
perf: {
permission: 4,
},
}
: {}),
...(ReleaseVersion.cmp(release, '1.19') >= 0
? {
// Added in 22w18a (1.19, pack format 10)
place: {
children: {
jigsaw: {
children: {
pool: {
children: {
target: {
properties: {
category: 'jigsaw_block_name',
allowUnknown: true,
},
},
},
},
},
},
template: {
children: {
template: {
properties: {
category: 'structure'
}
}
}
}
}
category: 'structure',
},
},
},
},
},
},
}
: {}),
playsound: Sound,
publish: {
permission: 4,
},
...(ReleaseVersion.cmp(release, '1.20.2') >= 0
? {
// Added in 23w31a (1.20.2, pack format 16)
random: {
children: {
reset: {
children: {
sequence: {
properties: {
category: 'random_sequence',
allowUnknown: true,
},
},
},
},
roll: {
children: {
range: {
children: {
sequence: {
properties: {
category: 'random_sequence',
allowUnknown: true,
},
},
},
},
},
},
value: {
children: {
range: {
children: {
sequence: {
properties: {
category: 'random_sequence',
allowUnknown: true,
},
},
},
},
},
},
},
},
}
: {}),
recipe: {
children: {
give: RecipeTargets,
Expand Down Expand Up @@ -590,8 +672,9 @@ export function getPatch(release: ReleaseVersion): PartialRootTreeNode {
tell: {
permission: 0,
},
...(ReleaseVersion.cmp(release, '1.20.2') >= 0
...(ReleaseVersion.cmp(release, '1.20.3') >= 0
? {
// Added in 23w43a (1.20.3, pack format 22)
tick: {
permission: 3,
},
Expand Down

0 comments on commit 69d2a6e

Please sign in to comment.