From 950050e9e4c97cbd0e81967ed80cfd12423325db Mon Sep 17 00:00:00 2001 From: Vito Gamberini Date: Tue, 28 Jul 2020 18:29:13 -0400 Subject: [PATCH] Add particletypes topping --- burger/toppings/identify.py | 4 +++- burger/toppings/particletypes.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 burger/toppings/particletypes.py diff --git a/burger/toppings/identify.py b/burger/toppings/identify.py index 2523c824..59594db1 100644 --- a/burger/toppings/identify.py +++ b/burger/toppings/identify.py @@ -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 @@ -274,6 +275,7 @@ class IdentifyTopping(Topping): "identify.packet.connectionstate", "identify.packet.packetbuffer", "identify.particle", + "identify.particletypes", "identify.position", "identify.recipe.superclass", "identify.resourcelocation", diff --git a/burger/toppings/particletypes.py b/burger/toppings/particletypes.py new file mode 100644 index 00000000..9da2fe74 --- /dev/null +++ b/burger/toppings/particletypes.py @@ -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 = '').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