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

Parse prefixes correctly

This commit is contained in:
Steffo 2020-06-08 02:30:55 +02:00
parent 193ed2ec78
commit 7e0112a779
Signed by: steffo
GPG key ID: 896A80F55F7C97F0
5 changed files with 129 additions and 28 deletions

View file

@ -12,6 +12,5 @@ class Chest:
self.contents: typing.List[ItemStack] = contents self.contents: typing.List[ItemStack] = contents
def __repr__(self): def __repr__(self):
if self.name: return f'<Chest "{self.name}" at {self.position} ' \
return f'<Chest "{self.name}" at {self.position} with {len(self.contents)} items>' f'with {len(list(filter(lambda x: x is not None, self.contents)))} items>'
return f"<Chest at {self.position} with {len(self.contents)} items>"

View file

@ -3,6 +3,7 @@ from .entitytype import EntityType
from .itemtype import ItemType from .itemtype import ItemType
from .liquidtype import LiquidType from .liquidtype import LiquidType
from .walltype import WallType from .walltype import WallType
from .prefixtype import PrefixType
__all__ = [ __all__ = [
"BlockType", "BlockType",
@ -10,4 +11,5 @@ __all__ = [
"ItemType", "ItemType",
"LiquidType", "LiquidType",
"WallType", "WallType",
"PrefixType",
] ]

View file

@ -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}"

View file

@ -1,4 +1,5 @@
from ..enums import ItemType from typing import Optional
from ..enums import ItemType, PrefixType
class ItemStack: class ItemStack:
@ -6,7 +7,7 @@ class ItemStack:
def __init__(self, def __init__(self,
type_: ItemType, type_: ItemType,
quantity: int = 1, quantity: int = 1,
modifier: int = 0): prefix: Optional[PrefixType] = None):
self.type: ItemType = type_ self.type: ItemType = type_
"""The type of item represented in this stack.""" """The type of item represented in this stack."""
@ -14,8 +15,8 @@ class ItemStack:
self.quantity: int = quantity self.quantity: int = quantity
"""A number from 1 to 999 representing the number of items inside this stack.""" """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.""" """The modifier of the item in this stack. Should be set only when quantity is 1."""
def __repr__(self): def __repr__(self):
return f"<ItemStack of {self.quantity}x {repr(self.type)} ({self.modifier})>" return f"<ItemStack of {self.quantity}x {repr(self.type)} ({self.prefix})>"

View file

@ -691,10 +691,10 @@ class World:
item_quantity = f.int2() item_quantity = f.int2()
if item_quantity > 0: if item_quantity > 0:
item_type = ItemType(f.int4()) item_type = ItemType(f.int4())
item_modifier = f.uint1() item_modifier = PrefixType.get(f.uint1())
item = ItemStack(quantity=item_quantity, item = ItemStack(quantity=item_quantity,
type_=item_type, type_=item_type,
modifier=item_modifier) prefix=item_modifier)
else: else:
item = None item = None
chest_contents.append(item) chest_contents.append(item)
@ -766,7 +766,7 @@ class World:
# Item Frame # 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(), prefix=PrefixType.get(f.uint1()),
quantity=f.int2())) quantity=f.int2()))
# Logic Sensor # Logic Sensor
elif te_type == 2: elif te_type == 2:
@ -780,21 +780,21 @@ class World:
for index, flag in enumerate(item_flags): for index, flag in enumerate(item_flags):
if not flag: if not flag:
continue continue
slot_item_id = ItemType(f.int2()) mannequin_items[index] = ItemStack(type_=ItemType(f.int2()),
slot_item_modifier = f.int1() prefix=PrefixType.get(f.int1()),
slot_item_stack = f.int2() quantity=f.int2())
mannequin_items[index] = ItemStack(slot_item_id, slot_item_modifier, slot_item_stack)
for index, flag in enumerate(dye_flags): for index, flag in enumerate(dye_flags):
if not flag: if not flag:
continue continue
slot_item_id = ItemType(f.int2()) mannequin_dyes[index] = ItemStack(type_=ItemType(f.int2()),
slot_item_modifier = f.int1() prefix=PrefixType.get(f.int1()),
slot_item_stack = f.int2() quantity=f.int2())
mannequin_dyes[index] = ItemStack(slot_item_id, slot_item_modifier, slot_item_stack)
te_extra = Mannequin(mannequin_items, mannequin_dyes) te_extra = Mannequin(mannequin_items, mannequin_dyes)
# Weapon Rack # Weapon Rack
elif te_type == 4: 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) te_extra = WeaponRack(rack_item)
# Hat Rack # Hat Rack
elif te_type == 5: elif te_type == 5:
@ -806,21 +806,21 @@ class World:
for index, flag in enumerate(item_flags[0:2]): for index, flag in enumerate(item_flags[0:2]):
if not flag: if not flag:
continue continue
slot_item_id = ItemType(f.int2()) rack_items[index] = ItemStack(type_=ItemType(f.int2()),
slot_item_modifier = f.int1() prefix=PrefixType.get(f.int1()),
slot_item_stack = f.int2() quantity=f.int2())
rack_items[index] = ItemStack(slot_item_id, slot_item_modifier, slot_item_stack)
for index, flag in enumerate(item_flags[2:4]): for index, flag in enumerate(item_flags[2:4]):
if not flag: if not flag:
continue continue
slot_item_id = ItemType(f.int2()) rack_dyes[index] = ItemStack(type_=ItemType(f.int2()),
slot_item_modifier = f.int1() prefix=PrefixType.get(f.int1()),
slot_item_stack = f.int2() quantity=f.int2())
rack_dyes[index] = ItemStack(slot_item_id, slot_item_modifier, slot_item_stack)
te_extra = HatRack(rack_items, rack_dyes) te_extra = HatRack(rack_items, rack_dyes)
# Food Plate # Food Plate
elif te_type == 6: 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) te_extra = Plate(plate_item)
# Teleport Pylon # Teleport Pylon
elif te_type == 7: elif te_type == 7: