Compare block state property values with equals, not reference identity - #5122
Merged
leijurv merged 1 commit intoSep 16, 2026
Merged
Conversation
pirateben820
force-pushed
the
fix/blockstate-property-equality
branch
from
September 16, 2026 12:04
f02b020 to
a31caee
Compare
sameBlockstate compares each property's value with !=. The values come out of BlockState.getValues() as boxed Comparable, so this is reference identity. It is correct for enum and Boolean properties, whose values are singletons, and for an IntegerProperty it happens to work today because every vanilla integer property stays inside the -128..127 range the JVM's Integer cache interns (the largest, age, tops out at 25). Nothing in the comparison guarantees that, and identity is not what is meant here; equality is. Objects.equals to match the three other comparisons in this file. Plain equals would also be correct: both states share one StateDefinition, so the lookups cannot return null. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
pirateben820
force-pushed
the
fix/blockstate-property-equality
branch
from
September 16, 2026 14:01
a31caee to
4aa223d
Compare
Contributor
Author
|
Retargeted to 1.21.4 as requested on #5123. The change had to be re-expressed rather than rebased: on 1.21.4 the comparison is |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
BuilderProcess.sameBlockstatecompares each property's value with!=:The values are boxed
Comparables, so this is reference identity. It is fine forEnumPropertyandBooleanProperty, whose values are singletons. For anIntegerPropertyit happens to work today because everyvanilla integer property stays inside the
-128..127range the JVM'sIntegercache interns — I checked: the largest,age, tops out at 25. Nothing in the comparison guarantees that, and identity is not what is meant here; equality is.Objects.equalsto match the three other comparisons in this file. Plainequalswould also be correct, since bothstates share one
StateDefinitionand the lookups cannot return null.This branch is only reached when
buildIgnoreDirectionorbuildIgnorePropertiesis set (both default off);otherwise the early
first.equals(second)return is taken.Verification
Compiles on this branch (
./gradlew compileJava, Gradle 8.7, Temurin JDK 21.0.12.1). GitHub's own runs are waiting on first-contributor approval. Not run in game - it is a one-line change to a comparison.Authorship
This patch and this description were written by an AI assistant (Claude, via Claude Code) working under my direction,
while I was debugging my own mod, which drives Baritone from a language model. I am submitting it and I answer for it.
If the project would rather not take AI-written changes, say so and I will close it.
🤖 Generated with Claude Code