1
Fork 0
mirror of https://github.com/Steffo99/lihzahrd.git synced 2024-11-21 23:54:23 +00:00

Mannequin parsing.

This commit is contained in:
Dale Floer 2020-06-01 17:30:05 -07:00 committed by Stefano Pigozzi
parent ebd6535d4d
commit f6df5928b0
3 changed files with 53 additions and 2 deletions

View file

@ -1,5 +1,6 @@
from .itemtype import ItemType from .itemtype import ItemType
from .itemstack import ItemStack from .itemstack import ItemStack
from .chest import Chest from .chest import Chest
from .mannequin import Mannequin
__all__ = ["ItemType", "ItemStack", "Chest"] __all__ = ["ItemType", "ItemStack", "Chest", "Mannequin"]

26
lihzahrd/chests/mannequin.py Executable file
View file

@ -0,0 +1,26 @@
import typing
from .itemstack import ItemStack
class Mannequin:
"""Data pertaining to a Logic Sensor (https://terraria.gamepedia.com/Mannequin)."""
__slots__ = "item_flags", "dye_flags", "wearing_items", "wearing_dyes"
def __init__(self,
item_flags: typing.List[bool],
dye_flags: typing.List[bool],
wearing_items: typing.List[ItemStack],
wearing_dyes: typing.List[ItemStack],):
self.item_flags: typing.List[bool] = item_flags
"""Which slots have items in them."""
self.dye_flags: typing.List[bool] = dye_flags
"""Which slots have dyes in them."""
self.wearing_items: typing.List[ItemStack] = wearing_items
"""What items is the mannequin wearing."""
self.wearing_dyes: typing.List[ItemStack] = wearing_dyes
"""What dyes is the mannequin wearing."""
def __repr__(self):
return f"Mannequin()"

View file

@ -728,16 +728,40 @@ class World:
te_type = f.uint1() te_type = f.uint1()
te_id = f.int4() te_id = f.int4()
te_position = Coordinates(f.int2(), f.int2()) te_position = Coordinates(f.int2(), f.int2())
# Target Dummy
if te_type == 0: if te_type == 0:
te_extra = TargetDummy(npc=f.int2()) te_extra = TargetDummy(npc=f.int2())
# Item Frame
elif te_type == 1: elif te_type == 1:
te_extra = ItemFrame(item=ItemStack(type_=ItemType(f.int2()), te_extra = ItemFrame(item=ItemStack(type_=ItemType(f.int2()),
modifier=f.uint1(), modifier=f.uint1(),
quantity=f.int2())) quantity=f.int2()))
# Logic Sensor
elif te_type == 2: elif te_type == 2:
te_extra = LogicSensor(logic_check=f.uint1(), enabled=f.bool()) te_extra = LogicSensor(logic_check=f.uint1(), enabled=f.bool())
# Mannequin
elif te_type == 3:
item_flags = f.bits()
dye_flags = f.bits()
mannequin_items = [None for _ in range(len(item_flags))]
mannequin_dyes = [None for _ in range(len(dye_flags))]
for slot in range(len(item_flags)):
if item_flags[slot]:
slot_item_id = ItemType(f.int2())
slot_item_modifier = f.int1()
slot_item_stack = f.int2()
mannequin_items[slot] = ItemStack(slot_item_id, slot_item_modifier, slot_item_stack)
for slot in range(len(mannequin_dyes)):
if dye_flags[slot]:
slot_item_id = ItemType(f.int2())
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)
else: else:
te_extra = ... print(f"te_type:", te_type)
te_extra = None
tile_entity = TileEntity(id_=te_id, position=te_position, extra=te_extra) tile_entity = TileEntity(id_=te_id, position=te_position, extra=te_extra)
tile_entities.append(tile_entity) tile_entities.append(tile_entity)
tm[tile_entity.position].extra = tile_entity tm[tile_entity.position].extra = tile_entity