Skip to content

Commit

Permalink
Add particletypes topping
Browse files Browse the repository at this point in the history
  • Loading branch information
nickelpro authored and Pokechu22 committed Nov 12, 2020
1 parent 7b528cd commit 950050e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
4 changes: 3 additions & 1 deletion burger/toppings/identify.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@
'anvilchunkloader'
),
(['has invalidly named property'], 'blockstatecontainer'),
((['HORIZONTAL'], True), 'enumfacing.plane')
((['HORIZONTAL'], True), 'enumfacing.plane'),
((['bubble'], True), 'particletypes')
)

# Enforce a lower priority on some matches, since some classes may match both
Expand Down Expand Up @@ -274,6 +275,7 @@ class IdentifyTopping(Topping):
"identify.packet.connectionstate",
"identify.packet.packetbuffer",
"identify.particle",
"identify.particletypes",
"identify.position",
"identify.recipe.superclass",
"identify.resourcelocation",
Expand Down
30 changes: 30 additions & 0 deletions burger/toppings/particletypes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from .topping import Topping

class TagsTopping(Topping):
"""Provides a list of all particle types"""

PROVIDES = [
"particletypes"
]
DEPENDS = ["identify.particletypes"]

@staticmethod
def act(aggregate, classloader, verbose=False):
particletypes = []
cf = classloader[aggregate["classes"]["particletypes"]]
ops = tuple(cf.methods.find_one(name = '<clinit>').code.disassemble())
for idx, op in enumerate(ops):
if 'ldc' in op.name:
str_val = op.operands[0].string.value

# Enum identifiers in older version of MC are all uppercase,
# these are distinct from the particletype strings we're
# collecting here.
if str_val.isupper():
continue

# This instruction sequence is unique to particle type fields
if ops[idx + 1].name in ('bipush', 'getstatic'):
particletypes.append(str_val)

aggregate['particletypes'] = particletypes

0 comments on commit 950050e

Please sign in to comment.