Port and tune 26.3 wood farming
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
import io
|
||||
import unittest
|
||||
from munch import Munch
|
||||
|
||||
from minecraft.networking.modern import (
|
||||
ModernPlayingReactor, SetEntityDataPacket,
|
||||
)
|
||||
from mosfet.info import items
|
||||
from mosfet.protocol.managers import EntityManager
|
||||
from mosfet.world import World
|
||||
|
||||
|
||||
def encode_varint(value):
|
||||
encoded = bytearray()
|
||||
while value & ~0x7F:
|
||||
encoded.append((value & 0x7F) | 0x80)
|
||||
value >>= 7
|
||||
encoded.append(value)
|
||||
return bytes(encoded)
|
||||
|
||||
|
||||
class SaplingEntityTests(unittest.TestCase):
|
||||
def test_protocol_777_item_metadata_decodes_item_stack(self):
|
||||
sapling_id = items.get_id('oak_sapling')
|
||||
payload = (
|
||||
encode_varint(42) +
|
||||
bytes((8,)) + encode_varint(7) +
|
||||
encode_varint(1) + encode_varint(sapling_id) +
|
||||
encode_varint(0) + encode_varint(0) +
|
||||
bytes((0xFF,))
|
||||
)
|
||||
packet = SetEntityDataPacket()
|
||||
packet.read(io.BytesIO(payload))
|
||||
|
||||
self.assertEqual(packet.entity_id, 42)
|
||||
self.assertEqual(len(packet.item_stacks), 1)
|
||||
self.assertEqual(packet.item_stacks[0].item_id, sapling_id)
|
||||
self.assertIn(SetEntityDataPacket,
|
||||
ModernPlayingReactor.get_clientbound_packets(None))
|
||||
|
||||
def test_item_metadata_makes_dropped_sapling_searchable(self):
|
||||
sapling_id = items.get_id('oak_sapling')
|
||||
entity = Munch(entity_id=42, x=1.0, y=65.0, z=2.0)
|
||||
manager = object.__new__(EntityManager)
|
||||
manager.g = Munch(objects={42: entity})
|
||||
packet = Munch(
|
||||
entity_id=42,
|
||||
item_stacks=[Munch(present=True, item_id=sapling_id,
|
||||
item_count=1)],
|
||||
)
|
||||
manager.handle_entity_data(packet)
|
||||
|
||||
found = World(Munch(objects={42: entity})).find_objects(
|
||||
items.SAPLING_IDS)
|
||||
self.assertEqual(found, [entity])
|
||||
self.assertEqual(entity.item_count, 1)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user