From dfaf41df91ce5f11673c1a536958cbed6928e60b Mon Sep 17 00:00:00 2001 From: Dale Floer Date: Mon, 1 Jun 2020 21:22:52 -0700 Subject: [PATCH] Added pylon, plate + hat/weapon rack parsing. Combined Mannequin and Hat Tack into ClothingDisplay class. Plate and weapon rack into single item display. Perhaps they'd be better as tile entities? --- lihzahrd/chests/__init__.py | 5 +-- .../{mannequin.py => clothingdisplay.py} | 16 ++++++--- lihzahrd/chests/singleitemdisplay.py | 23 +++++++++++++ lihzahrd/tileentities/__init__.py | 3 +- lihzahrd/tileentities/pylon.py | 8 +++++ lihzahrd/world.py | 33 ++++++++++++++++++- 6 files changed, 79 insertions(+), 9 deletions(-) rename lihzahrd/chests/{mannequin.py => clothingdisplay.py} (56%) create mode 100755 lihzahrd/chests/singleitemdisplay.py create mode 100755 lihzahrd/tileentities/pylon.py diff --git a/lihzahrd/chests/__init__.py b/lihzahrd/chests/__init__.py index 9f5531d..55e999c 100644 --- a/lihzahrd/chests/__init__.py +++ b/lihzahrd/chests/__init__.py @@ -1,6 +1,7 @@ from .itemtype import ItemType from .itemstack import ItemStack from .chest import Chest -from .mannequin import Mannequin +from .clothingdisplay import ClothingDisplay +from .singleitemdisplay import SingleItemDisplay -__all__ = ["ItemType", "ItemStack", "Chest", "Mannequin"] +__all__ = ["ItemType", "ItemStack", "Chest", "ClothingDisplay", "SingleItemDisplay"] diff --git a/lihzahrd/chests/mannequin.py b/lihzahrd/chests/clothingdisplay.py similarity index 56% rename from lihzahrd/chests/mannequin.py rename to lihzahrd/chests/clothingdisplay.py index 59fdf67..d49479b 100755 --- a/lihzahrd/chests/mannequin.py +++ b/lihzahrd/chests/clothingdisplay.py @@ -1,16 +1,20 @@ import typing from .itemstack import ItemStack -class Mannequin: - """Data pertaining to a Logic Sensor (https://terraria.gamepedia.com/Mannequin).""" +class ClothingDisplay: + """Data pertaining to an item to display clothing. + Currently this is a Womannequin/Mannequin (https://terraria.gamepedia.com/Womannequin) + and hat rack (https://terraria.gamepedia.com/Hat_Rack). + """ - __slots__ = "item_flags", "dye_flags", "wearing_items", "wearing_dyes" + __slots__ = "item_flags", "dye_flags", "wearing_items", "wearing_dyes", "display_type" def __init__(self, item_flags: typing.List[bool], dye_flags: typing.List[bool], wearing_items: typing.List[ItemStack], - wearing_dyes: typing.List[ItemStack],): + wearing_dyes: typing.List[ItemStack], + display_type: str,): self.item_flags: typing.List[bool] = item_flags """Which slots have items in them.""" @@ -20,7 +24,9 @@ class Mannequin: """What items is the mannequin wearing.""" self.wearing_dyes: typing.List[ItemStack] = wearing_dyes """What dyes is the mannequin wearing.""" + self.display_type: str = display_type + """What type of display is this?""" def __repr__(self): - return f"Mannequin()" + return f"ClothingDisplay(type={self.display_type}, dyes={len(self.wearing_dyes)}, )" diff --git a/lihzahrd/chests/singleitemdisplay.py b/lihzahrd/chests/singleitemdisplay.py new file mode 100755 index 0000000..6b851ac --- /dev/null +++ b/lihzahrd/chests/singleitemdisplay.py @@ -0,0 +1,23 @@ +import typing +from .itemstack import ItemStack + +class SingleItemDisplay: + """Data pertaining to a single display item. + Currently weapon rack (https://terraria.gamepedia.com/Weapon_Rack) + and food plate (https://terraria.gamepedia.com/Plate). + """ + + __slots__ = "display_item", "display_type" + + def __init__(self, + display_item: typing.List[ItemStack], + display_type: str): + + self.display_item: typing.List[ItemStack] = display_item + """What item is on display.""" + + self.display_type: str = display_type + """What type of single item display this is.""" + + def __repr__(self): + return f"SingleItemDisplay(display_type={self.display_type}, display_item={self.display_item})" diff --git a/lihzahrd/tileentities/__init__.py b/lihzahrd/tileentities/__init__.py index 7947236..43e497c 100644 --- a/lihzahrd/tileentities/__init__.py +++ b/lihzahrd/tileentities/__init__.py @@ -2,5 +2,6 @@ from .tileentity import TileEntity from .itemframe import ItemFrame from .logicsensor import LogicSensor from .targetdummy import TargetDummy +from .pylon import Pylon -__all__ = ["TileEntity", "ItemFrame", "LogicSensor", "TargetDummy"] +__all__ = ["TileEntity", "ItemFrame", "LogicSensor", "TargetDummy", "Pylon"] diff --git a/lihzahrd/tileentities/pylon.py b/lihzahrd/tileentities/pylon.py new file mode 100755 index 0000000..c578a6a --- /dev/null +++ b/lihzahrd/tileentities/pylon.py @@ -0,0 +1,8 @@ +class Pylon: + """Data pertaining to a Pylon (https://terraria.gamepedia.com/Pylons)""" + + def __init__(self, pylon: bool = True): + self.pylon: bool = pylon + + def __repr__(self): + return f"pylon={self.pylon}" diff --git a/lihzahrd/world.py b/lihzahrd/world.py index dac14b4..ec3d985 100644 --- a/lihzahrd/world.py +++ b/lihzahrd/world.py @@ -757,7 +757,38 @@ class World: slot_item_modifier = f.int1() slot_item_stack = f.int2() mannequin_dyes[slot] = ItemStack(slot_item_id, slot_item_modifier, slot_item_stack) - te_extra = Mannequin(item_flags, dye_flags, mannequin_items, mannequin_dyes) + te_extra = ClothingDisplay(item_flags, dye_flags, mannequin_items, mannequin_dyes, "mannequin") + # Weapon Rack + elif te_type == 4: + rack_item = ItemStack(ItemType(f.int2()), f.int1(), f.int2()) + te_extra = SingleItemDisplay(rack_item, "weapon_rack") + # Hat Rack + elif te_type == 5: + # This isn't 100% tested, but the first two flags should be items, and the second two should be dyes. + item_flags = f.bits() + # Maximum of two items slots and two dye slots. + rack_items = [None for _ in range(2)] + rack_dyes = [None for _ in range(2)] + for slot in range(2): + if item_flags[slot]: + slot_item_id = ItemType(f.int2()) + slot_item_modifier = f.int1() + slot_item_stack = f.int2() + rack_items[slot] = ItemStack(slot_item_id, slot_item_modifier, slot_item_stack) + for slot in range(2): + if item_flags[slot + 2]: + slot_item_id = ItemType(f.int2()) + slot_item_modifier = f.int1() + slot_item_stack = f.int2() + rack_dyes[slot] = ItemStack(slot_item_id, slot_item_modifier, slot_item_stack) + te_extra = ClothingDisplay(item_flags, dye_flags, mannequin_items, mannequin_dyes, "hat_rack") + # Food Plate + elif te_type == 6: + plate_item = ItemStack(ItemType(f.int2()), f.int1(), f.int2()) + te_extra = SingleItemDisplay(plate_item, "food_plate") + # Teleport Pylon + elif te_type == 7: + te_extra = Pylon() else: print(f"te_type:", te_type) te_extra = None