Skip to content

Commit

Permalink
🐛 Fix not completing NBT for certain selectors
Browse files Browse the repository at this point in the history
Fix #482.
  • Loading branch information
SPGoding committed Jun 19, 2020
1 parent d3ff235 commit 46d8b29
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 41 deletions.
17 changes: 6 additions & 11 deletions src/CommandTree.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
import { CommandTree, CommandTreeNode, CommandTreeNodeChildren } from './types/CommandTree'
import { LineArgumentNode } from './types/LineNode'
import { EntityNode } from './nodes/EntityNode'
import { SelectorArgumentsNode } from './nodes/SelectorArgumentsNode'

export function getNbtdocRegistryId(entity: EntityNode): null | string
export function getNbtdocRegistryId(selectorArguments: SelectorArgumentsNode): null | string
export function getNbtdocRegistryId(param: EntityNode | SelectorArgumentsNode): null | string {
if (param instanceof EntityNode) {
param = param.argument
export function getNbtdocRegistryId(entity: EntityNode): null | string {
if (entity.variable === 'a' || entity.variable === 'p' || entity.variable === 'r') {
return 'minecraft:player'
}
if (param.type) {
const firstID = param.type[0]
if (firstID && !firstID.isTag) {
return firstID.toString()
}
const firstID = entity.argument.type?.[0]
if (firstID && !firstID.isTag) {
return firstID.toString()
}
return null
}
Expand Down
6 changes: 3 additions & 3 deletions src/data/VanillaData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ export const VanillaDataCache: {
Nbtdoc: { [version: string]: nbtdoc.Root },
Registry: { [version: string]: Registry }
} = {
BlockDefinition: { '20w17a': FallbackBlockDefinition },
NamespaceSummary: { '20w17a': FallbackNamespaceSummary },
BlockDefinition: { '1.16-rc1': FallbackBlockDefinition },
NamespaceSummary: { '1.16-rc1': FallbackNamespaceSummary },
Nbtdoc: { '20w16a': FallbackNbtdoc },
Registry: { '20w17a': FallbackRegistry }
Registry: { '1.16-rc1': FallbackRegistry }
}

export type DataType = 'BlockDefinition' | 'NamespaceSummary' | 'Nbtdoc' | 'Registry'
Expand Down
54 changes: 27 additions & 27 deletions src/parsers/EntityArgumentParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ export class EntityArgumentParser extends ArgumentParser<EntityNode> {
}
new MapParser<SelectorArgumentsNode>(
EntitySelectorNodeChars,
(ans, reader, ctx) => {
(argumentAns, reader, ctx) => {
const start = reader.cursor
const result = ctx.parsers
.get('String', [
Expand All @@ -229,61 +229,61 @@ export class EntityArgumentParser extends ArgumentParser<EntityNode> {
const key = result.data.value
/* istanbul ignore else */
if (key) {
ans.data[Keys][key] = result.data
argumentAns.data[Keys][key] = result.data
}
result.tokens = [Token.from(start, reader, TokenType.property)]
return { ...result, data: key }
},
(ans, reader, ctx, key) => {
(argumentAns, reader, ctx, key) => {
if (key === 'sort') {
const start = reader.cursor
const result = ctx.parsers.get('Literal', ['arbitrary', 'furthest', 'nearest', 'random']).parse(reader, ctx)
if (result.data) {
ans.data.sort = result.data as SelectorSortMethod
argumentAns.data.sort = result.data as SelectorSortMethod
}
result.tokens = [Token.from(start, reader, TokenType.string)]
combineArgumentParserResult(ans, result)
combineArgumentParserResult(argumentAns, result)
} else if (key === 'x' || key === 'y' || key === 'z' || key === 'dx' || key === 'dy' || key === 'dz') {
const result: ArgumentParserResult<NumberNode> = ctx.parsers.get('Number', ['float']).parse(reader, ctx)
ans.data[key] = result.data
combineArgumentParserResult(ans, result)
argumentAns.data[key] = result.data
combineArgumentParserResult(argumentAns, result)
} else if (key === 'limit') {
const result: ArgumentParserResult<NumberNode> = ctx.parsers.get('Number', ['integer', 1]).parse(reader, ctx)
ans.data.limit = result.data
if (ans.data.limit.valueOf() === 1) {
argumentAns.data.limit = result.data
if (argumentAns.data.limit.valueOf() === 1) {
isMultiple = false
} else {
isMultiple = true
}
combineArgumentParserResult(ans, result)
combineArgumentParserResult(argumentAns, result)
} else if (key === 'gamemode') {
dealWithNegativableArray(ans, ctx.parsers.get('Literal', ['adventure', 'creative', 'spectator', 'survival']), key)
dealWithNegativableArray(argumentAns, ctx.parsers.get('Literal', ['adventure', 'creative', 'spectator', 'survival']), key)
} else if (key === 'name') {
dealWithNegativableArray(ans, ctx.parsers.get('String', [StringType.String, null, 'stringQuote', 'stringQuoteType']), key)
dealWithNegativableArray(argumentAns, ctx.parsers.get('String', [StringType.String, null, 'stringQuote', 'stringQuoteType']), key)
} else if (key === 'nbt') {
dealWithNegativableArray(ans, ctx.parsers.get('Nbt', [
dealWithNegativableArray(argumentAns, ctx.parsers.get('Nbt', [
'Compound', 'minecraft:entity', getNbtdocRegistryId(ans.data), true
]), key)
} else if (key === 'predicate') {
dealWithNegativableArray(ans, ctx.parsers.get('Identity', ['$predicates']), key)
dealWithNegativableArray(argumentAns, ctx.parsers.get('Identity', ['$predicates']), key)
} else if (key === 'tag') {
dealWithNegativableArray(ans, ctx.parsers.get('Tag'), key)
dealWithNegativableArray(argumentAns, ctx.parsers.get('Tag'), key)
} else if (key === 'team') {
dealWithNegativableArray(ans, ctx.parsers.get('Team'), key)
dealWithNegativableArray(argumentAns, ctx.parsers.get('Team'), key)
} else if (key === 'type') {
dealWithNegativableArray(ans, ctx.parsers.get('Identity', ['minecraft:entity_type', true]), key)
dealWithNegativableArray(argumentAns, ctx.parsers.get('Identity', ['minecraft:entity_type', true]), key)
} else if (key === 'distance') {
const result = ctx.parsers.get('NumberRange', ['float']).parse(reader, ctx)
ans.data[key] = result.data
combineArgumentParserResult(ans, result)
argumentAns.data[key] = result.data
combineArgumentParserResult(argumentAns, result)
} else if (key === 'x_rotation' || key === 'y_rotation') {
const result = ctx.parsers.get('NumberRange', ['float', true]).parse(reader, ctx)
ans.data[key] = result.data
combineArgumentParserResult(ans, result)
argumentAns.data[key] = result.data
combineArgumentParserResult(argumentAns, result)
} else if (key === 'level') {
const result = ctx.parsers.get('NumberRange', ['integer']).parse(reader, ctx)
ans.data[key] = result.data
combineArgumentParserResult(ans, result)
argumentAns.data[key] = result.data
combineArgumentParserResult(argumentAns, result)
} else if (key === 'advancements') {
const advancementsAns: ArgumentParserResult<SelectorAdvancementsNode> = {
data: new SelectorAdvancementsNode(),
Expand Down Expand Up @@ -344,8 +344,8 @@ export class EntityArgumentParser extends ArgumentParser<EntityNode> {
}
}
).parse(advancementsAns, reader, ctx)
ans.data.advancements = advancementsAns.data
combineArgumentParserResult(ans, advancementsAns)
argumentAns.data.advancements = advancementsAns.data
combineArgumentParserResult(argumentAns, advancementsAns)
} else if (key === 'scores') {
const scoresAns: ArgumentParserResult<SelectorScoresNode> = {
data: new SelectorScoresNode(),
Expand All @@ -364,8 +364,8 @@ export class EntityArgumentParser extends ArgumentParser<EntityNode> {
combineArgumentParserResult(ans, rangeResult)
}
).parse(scoresAns, reader, ctx)
ans.data.scores = scoresAns.data
combineArgumentParserResult(ans, scoresAns)
argumentAns.data.scores = scoresAns.data
combineArgumentParserResult(argumentAns, scoresAns)
}
}
).parse(argumentAns, reader, ctx)
Expand Down

0 comments on commit 46d8b29

Please sign in to comment.