From 1e9c1a517ce95c784c5163ab052690a1aa0e8401 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Mon, 8 Jun 2020 02:30:55 +0200 Subject: [PATCH] Parse prefixes correctly --- lihzahrd/chests/chest.py | 5 +- lihzahrd/enums/__init__.py | 2 + lihzahrd/enums/prefixtype.py | 99 ++++++++++++++++++++++++++++++++++++ lihzahrd/items/itemstack.py | 9 ++-- lihzahrd/world.py | 42 +++++++-------- 5 files changed, 129 insertions(+), 28 deletions(-) create mode 100644 lihzahrd/enums/prefixtype.py diff --git a/lihzahrd/chests/chest.py b/lihzahrd/chests/chest.py index 423c66d..69b02e2 100644 --- a/lihzahrd/chests/chest.py +++ b/lihzahrd/chests/chest.py @@ -12,6 +12,5 @@ class Chest: self.contents: typing.List[ItemStack] = contents def __repr__(self): - if self.name: - return f'' - return f"" + return f'' diff --git a/lihzahrd/enums/__init__.py b/lihzahrd/enums/__init__.py index 6a1b971..7e82d03 100644 --- a/lihzahrd/enums/__init__.py +++ b/lihzahrd/enums/__init__.py @@ -3,6 +3,7 @@ from .entitytype import EntityType from .itemtype import ItemType from .liquidtype import LiquidType from .walltype import WallType +from .prefixtype import PrefixType __all__ = [ "BlockType", @@ -10,4 +11,5 @@ __all__ = [ "ItemType", "LiquidType", "WallType", + "PrefixType", ] diff --git a/lihzahrd/enums/prefixtype.py b/lihzahrd/enums/prefixtype.py new file mode 100644 index 0000000..ba7cc47 --- /dev/null +++ b/lihzahrd/enums/prefixtype.py @@ -0,0 +1,99 @@ +from typing import * +import enum + + +class PrefixType(enum.IntEnum): + Large = 1 + Massive = 2 + Dangerous = 3 + Savage = 4 + Sharp = 5 + Pointy = 6 + Tiny = 7 + Terrible = 8 + Small = 9 + Dull = 10 + Unhappy = 11 + Bulky = 12 + Shameful = 13 + Heavy = 14 + Light = 15 + Sighted = 16 + Rapid = 17 + Hasty = 18 + Intimidating = 19 + Deadly = 20 + Staunch = 21 + Awful = 22 + Lethargic = 23 + Awkward = 24 + Powerful = 25 + Mystic = 26 + Adept = 27 + Masterful = 28 + Inept = 29 + Ignorant = 30 + Deranged = 31 + Intense = 32 + Taboo = 33 + Celestial = 34 + Furious = 35 + Keen = 36 + Superior = 37 + Forceful = 38 + Broken = 39 + Damaged = 40 + Shoddy = 41 + Quick = 42 + Deadly2 = 43 + Agile = 44 + Nimble = 45 + Murderous = 46 + Slow = 47 + Sluggish = 48 + Lazy = 49 + Annoying = 50 + Nasty = 51 + Manic = 52 + Hurtful = 53 + Strong = 54 + Unpleasant = 55 + Weak = 56 + Ruthless = 57 + Frenzying = 58 + Godly = 59 + Demonic = 60 + Zealous = 61 + Hard = 62 + Guarding = 63 + Armored = 64 + Warding = 65 + Arcane = 66 + Precise = 67 + Lucky = 68 + Jagged = 69 + Spiked = 70 + Angry = 71 + Menacing = 72 + Brisk = 73 + Fleeting = 74 + Hasty2 = 75 + Quick2 = 76 + Wild = 77 + Rash = 78 + Intrepid = 79 + Violent = 80 + Legendary = 81 + Unreal = 82 + Mythical = 83 + Legendary2 = 84 + + @classmethod + def get(cls, i: int) -> Optional["PrefixType"]: + if i == 0: + return None + else: + return cls(i) + + def __repr__(self): + return f"{self.__class__.__name__}.{self.name}" diff --git a/lihzahrd/items/itemstack.py b/lihzahrd/items/itemstack.py index 231292a..50bb523 100644 --- a/lihzahrd/items/itemstack.py +++ b/lihzahrd/items/itemstack.py @@ -1,4 +1,5 @@ -from ..enums import ItemType +from typing import Optional +from ..enums import ItemType, PrefixType class ItemStack: @@ -6,7 +7,7 @@ class ItemStack: def __init__(self, type_: ItemType, quantity: int = 1, - modifier: int = 0): + prefix: Optional[PrefixType] = None): self.type: ItemType = type_ """The type of item represented in this stack.""" @@ -14,8 +15,8 @@ class ItemStack: self.quantity: int = quantity """A number from 1 to 999 representing the number of items inside this stack.""" - self.modifier: int = modifier + self.prefix: Optional[PrefixType] = prefix """The modifier of the item in this stack. Should be set only when quantity is 1.""" def __repr__(self): - return f"" + return f"" diff --git a/lihzahrd/world.py b/lihzahrd/world.py index 124ddb8..fe443aa 100644 --- a/lihzahrd/world.py +++ b/lihzahrd/world.py @@ -691,10 +691,10 @@ class World: item_quantity = f.int2() if item_quantity > 0: item_type = ItemType(f.int4()) - item_modifier = f.uint1() + item_modifier = PrefixType.get(f.uint1()) item = ItemStack(quantity=item_quantity, type_=item_type, - modifier=item_modifier) + prefix=item_modifier) else: item = None chest_contents.append(item) @@ -766,7 +766,7 @@ class World: # Item Frame elif te_type == 1: te_extra = ItemFrame(item=ItemStack(type_=ItemType(f.int2()), - modifier=f.uint1(), + prefix=PrefixType.get(f.uint1()), quantity=f.int2())) # Logic Sensor elif te_type == 2: @@ -780,21 +780,21 @@ class World: for index, flag in enumerate(item_flags): if not flag: continue - slot_item_id = ItemType(f.int2()) - slot_item_modifier = f.int1() - slot_item_stack = f.int2() - mannequin_items[index] = ItemStack(slot_item_id, slot_item_modifier, slot_item_stack) + mannequin_items[index] = ItemStack(type_=ItemType(f.int2()), + prefix=PrefixType.get(f.int1()), + quantity=f.int2()) for index, flag in enumerate(dye_flags): if not flag: continue - slot_item_id = ItemType(f.int2()) - slot_item_modifier = f.int1() - slot_item_stack = f.int2() - mannequin_dyes[index] = ItemStack(slot_item_id, slot_item_modifier, slot_item_stack) + mannequin_dyes[index] = ItemStack(type_=ItemType(f.int2()), + prefix=PrefixType.get(f.int1()), + quantity=f.int2()) te_extra = Mannequin(mannequin_items, mannequin_dyes) # Weapon Rack elif te_type == 4: - rack_item = ItemStack(ItemType(f.int2()), f.int1(), f.int2()) + rack_item = ItemStack(type_=ItemType(f.int2()), + prefix=PrefixType.get(f.int1()), + quantity=f.int2()) te_extra = WeaponRack(rack_item) # Hat Rack elif te_type == 5: @@ -806,21 +806,21 @@ class World: for index, flag in enumerate(item_flags[0:2]): if not flag: continue - slot_item_id = ItemType(f.int2()) - slot_item_modifier = f.int1() - slot_item_stack = f.int2() - rack_items[index] = ItemStack(slot_item_id, slot_item_modifier, slot_item_stack) + rack_items[index] = ItemStack(type_=ItemType(f.int2()), + prefix=PrefixType.get(f.int1()), + quantity=f.int2()) for index, flag in enumerate(item_flags[2:4]): if not flag: continue - slot_item_id = ItemType(f.int2()) - slot_item_modifier = f.int1() - slot_item_stack = f.int2() - rack_dyes[index] = ItemStack(slot_item_id, slot_item_modifier, slot_item_stack) + rack_dyes[index] = ItemStack(type_=ItemType(f.int2()), + prefix=PrefixType.get(f.int1()), + quantity=f.int2()) te_extra = HatRack(rack_items, rack_dyes) # Food Plate elif te_type == 6: - plate_item = ItemStack(ItemType(f.int2()), f.int1(), f.int2()) + plate_item = ItemStack(type_=ItemType(f.int2()), + prefix=PrefixType.get(f.int1()), + quantity=f.int2()) te_extra = Plate(plate_item) # Teleport Pylon elif te_type == 7: