Improve trading villager selection based on profession

This commit is contained in:
2021-05-01 21:31:21 +00:00
parent 080895421d
commit a87cc85eab
9 changed files with 82 additions and 15 deletions

View File

@@ -304,7 +304,7 @@ class EntityMetadataPacket(Packet):
self.metadata = []
for _ in range(99):
entry = Entry.read(file_object, self.context)
if not entry: break
if not entry: break # hit an unimplemented type, stops parsing
self.metadata.append(entry)

View File

@@ -141,7 +141,7 @@ class Slot(Type):
class Entry(Type):
types = {
simple_types = {
0: Byte,
1: VarInt,
2: Float,
@@ -169,12 +169,19 @@ class Entry(Type):
index = UnsignedByte.read(file_object)
if index == 0xff: return None
type = VarInt.read(file_object)
try:
value = Entry.types[type].read(file_object)
except TypeError:
value = Entry.types[type].read_with_context(file_object, context)
except KeyError:
return None
if type == 10: # optional position
present = Boolean.read(file_object)
value = Position.read_with_context(file_object, context) if present else None
elif type == 16: # villager data
value = (VarInt.read(file_object), VarInt.read(file_object), VarInt.read(file_object))
else:
try:
value = Entry.simple_types[type].read(file_object)
except TypeError:
value = Entry.simple_types[type].read_with_context(file_object, context)
except KeyError:
return None # unimplemented data type, stops parsing entries
return Entry(index, type, value)