Commit 5c45e84
committed
Bind BlockTypes constants to explicit ids instead of field order
BlockTypes resolved each of its constants by reading its own field list
reflectively and lowercasing the field name at the matching index.
Class.getDeclaredFields() explicitly does not specify an order, so this
depended on undefined behaviour; a sentinel static block was the only
thing standing between a reordered array and every constant silently
bound to the wrong block.
Each constant now calls the existing get(String) lookup directly with its
namespaced id, which is also the scheme upstream WorldEdit already uses.
Field order carries no meaning, so the sentinel block, the
fieldsTmp/initIndex state, the reflective walk, and the intermediate
init(String) wrapper are all gone.
Forcing BlockTypesCache to initialise moves into a static block above the
constants, since only its position relative to them matters. That removes
the per-call primed flag and the branch it guarded.
Reconcile the constant list with upstream while here. Add DRIED_GHAST;
drop POTTED_AZALEA and POTTED_FLOWERING_AZALEA, which upstream does not
declare; and drop the fork-local deprecation of POTTED_AZALEA_BUSH and
POTTED_FLOWERING_AZALEA_BUSH, whose comment pointed at the two constants
being removed. The declarations are now identical to upstream's 1,201,
with __RESERVED__ as the single deliberate addition the ordinal scheme
depends on.
Every id is "minecraft:" + the lowercased field name, matching both what
the previous scheme produced and what upstream declares, so the resolved
values are unchanged for every constant that survives.1 parent 5a11173 commit 5c45e84
1 file changed
Lines changed: 1252 additions & 1230 deletions
0 commit comments