Skip to content

Commit

Permalink
Improve identification of BlockState
Browse files Browse the repository at this point in the history
The previous heuristic broke in 20w21a.
  • Loading branch information
Pokechu22 committed Nov 12, 2020
1 parent bf58b01 commit ccefc51
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
10 changes: 3 additions & 7 deletions burger/toppings/entitymetadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,8 @@ def identify_serializer(classloader, cls, classes, verbose):
name = "Chat"
elif inner_type == classes["position"]:
name = "BlockPos"
elif inner_type == classes["blockstate"]:
name = "BlockState"
else:
# Try some more tests, based on the class itself:
try:
Expand All @@ -360,18 +362,12 @@ def identify_serializer(classloader, cls, classes, verbose):
name = "Rotations"
elif content_cf.constants.find_one(type_=String, f=lambda c: c == "down"):
name = "Facing"
elif content_cf.constants.find_one(type_=String, f=lambda c: c == "minecraft:air"):
# This method only works in 1.14, where BlockState isn't an interface
name = "BlockState"
elif content_cf.constants.find_one(type_=String, f=lambda c: c == "FALL_FLYING"):
assert content_cf.access_flags.acc_enum
name = "Pose"
elif content_cf.access_flags.acc_interface:
# Make some _very_ bad assumptions here; both of these are hard to identify:
if name_prefix == "Opt":
name = "BlockState"
else:
name = "Particle"
name = "Particle"
except:
if verbose:
print("Failed to determine name of metadata content type %s" % inner_type)
Expand Down
16 changes: 16 additions & 0 deletions burger/toppings/identify.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,21 @@ def is_protected_final(m):
if cf:
return 'position', cf.this.name.value

if value == 'Getting block state':
# This message is found in Chunk, in the method getBlockState.
# We could also theoretically identify BlockPos from this method,
# but currently identify only allows marking one class at a time.
class_file = classloader[path]

for method in class_file.methods:
for ins in method.code.disassemble():
if ins.mnemonic in ("ldc", "ldc_w"):
if ins.operands[0] == 'Getting block state':
return 'blockstate', method.returns.name
else:
if verbose:
print("Found chunk, but didn't find the method that returns blockstate")


class IdentifyTopping(Topping):
"""Finds important superclasses needed by other toppings."""
Expand All @@ -207,6 +222,7 @@ class IdentifyTopping(Topping):
"identify.block.list",
"identify.block.register",
"identify.blockstatecontainer",
"identify.blockstate",
"identify.chatcomponent",
"identify.entity.list",
"identify.entity.trackerentry",
Expand Down

0 comments on commit ccefc51

Please sign in to comment.