Skip to content

Add boolean logical operators (&&, ||, !) to NBT path expressions#216

Closed
Copilot wants to merge 5 commits intomaster-1.21-ltsfrom
copilot/add-logical-operator-support
Closed

Add boolean logical operators (&&, ||, !) to NBT path expressions#216
Copilot wants to merge 5 commits intomaster-1.21-ltsfrom
copilot/add-logical-operator-support

Conversation

Copy link

Copilot AI commented Feb 12, 2026

NBT path expressions previously lacked boolean operators for combining conditions in filters and comparisons.

Changes

New parse handlers following the relational operator pattern:

  • NbtPathExpressionParseHandlerBooleanLogicalAnd - && operator
  • NbtPathExpressionParseHandlerBooleanLogicalOr - || operator
  • NbtPathExpressionParseHandlerBooleanLogicalNot - ! prefix operator

Key implementation detail: Operators use parent execution context to evaluate right-hand expressions against original tag values, not the boolean result from the left side. This enables chained comparisons like @.value > 5 && < 10.

Shared utility: Extracted NbtPathExpressionHelpers.isTruthy() for consistent truthiness evaluation (ByteTag(1) = true, ByteTag(0) = false, other non-null tags = true).

Usage

// Range checks
$.value > 5 && < 10

// Either/or conditions  
$.price < 100 || > 1000

// Negation
!(@.disabled == 1)

// Filter expressions with logical operators
$.items[?(@.score > 50 && < 100)]
$.items[?(@.type == "A" || @.priority > 5)]
$.items[?(!(@.archived == 1))]

Test coverage includes unit tests for each operator and integration tests with filter expressions.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • maven.fabricmc.net
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-opens=java.base/java.nio.charset=ALL-UNNAMED --add-opens=java.base/java.net=ALL-UNNAMED --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED -Xmx3G -Dfile.encoding=UTF-8 -Duser.country -Duser.language=en -Duser.variant -cp /home/REDACTED/.gradle/wrapper/dists/gradle-8.8-bin/dl7vupf4psengwqhwktix4v1/gradle-8.8/lib/gradle-launcher-8.8.jar -javaagent:/home/REDACTED/.gradle/wrapper/dists/gradle-8.8-bin/dl7vupf4psengwqhwktix4v1/gradle-8.8/lib/agents/gradle-instrumentation-agent-8.8.jar org.gradle.launcher.daemon.bootstrap.GradleDaemon 8.8 (dns block)
  • www.puppycrawl.com
    • Triggering command: /opt/hostedtoolcache/CodeQL/2.24.1/x64/codeql/tools/linux64/java/bin/java /opt/hostedtoolcache/CodeQL/2.24.1/x64/codeql/tools/linux64/java/bin/java -jar /opt/hostedtoolcache/CodeQL/2.24.1/x64/codeql/xml/tools/xml-extractor.jar --fileList=/home/REDACTED/work/CyclopsCore/.codeql-scratch/dbs/java/working/files-to-index12823067718343908668.list --sourceArchiveDir=/home/REDACTED/work/CyclopsCore/.codeql-scratch/dbs/java/src --outputDir=/home/REDACTED/work/CyclopsCore/.codeql-scratch/dbs/java/trap/java (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Add basic logical operator support to NBT expression parasing</issue_title>
<issue_description>

Issue type:

  • ➕ Feature request

Short description:

As of right now, when testing or filtering an NBT path expression, boolean operators such as OR, AND, and NOT are unsupported. It would be nice if we were able to use basic boolean operators such as these.

The ability to use basic boolean operators
ex1. .someKey.someListKey[(?:@.someBoolKey || (@.someIntKey < someConstantInt))]
ex2. .someKey.someBoolKey && !(someOtherKey.someStringValue == "someConstantString")</issue_description>

<agent_instructions>Could you implement this? Make sure to add unit tests to cover all cases. If you try to build locally, make sure to define GITHUB_USER and GITHUB_TOKEN like here: https://github.com/CyclopsMC/IntegratedDynamics/blob/master-1.21-lts/.github/workflows/ci.yml#L53-L54. Otherwise this part of the build file will fail: https://github.com/CyclopsMC/IntegratedDynamics/blob/master-1.21-lts/build.gradle#L118-L119</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@rubensworks

Thanks for the suggestion!


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 4 commits February 12, 2026 16:18
Co-authored-by: rubensworks <440384+rubensworks@users.noreply.github.com>
Co-authored-by: rubensworks <440384+rubensworks@users.noreply.github.com>
… expressions

Co-authored-by: rubensworks <440384+rubensworks@users.noreply.github.com>
Co-authored-by: rubensworks <440384+rubensworks@users.noreply.github.com>
Copilot AI changed the title [WIP] Add basic logical operator support to NBT expression parsing Add boolean logical operators (&&, ||, !) to NBT path expressions Feb 12, 2026
Copilot AI requested a review from rubensworks February 12, 2026 16:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add basic logical operator support to NBT expression parasing

2 participants