Files
minecraft-bot/tests/test_world_threats.py
2026-11-14 17:08:13 +00:00

39 lines
1.3 KiB
Python

import unittest
from munch import Munch
from mosfet.info import blocks, mobs
from mosfet.world import World
class FakeChunks:
def __init__(self, solid=()):
self.solid = set(solid)
def get_block_at(self, x, y, z):
return blocks.STONE if (x, y, z) in self.solid else blocks.AIR
class WorldThreatTests(unittest.TestCase):
def test_find_threats_filters_passive_and_distant_entities(self):
zombie = mobs.MOBS['minecraft:zombie']['protocol_id']
villager = mobs.MOBS['minecraft:villager']['protocol_id']
world = World(Munch(mobs={
1: Munch(entity_id=1, type=zombie, x=3.2, y=64, z=0),
2: Munch(entity_id=2, type=villager, x=2, y=64, z=0),
3: Munch(entity_id=3, type=zombie, x=30, y=64, z=0),
}))
world.check_air_column = lambda pos, distance: True
result = world.find_threats((0, 64, 0), 12)
self.assertEqual([threat.entity_id for threat in result], [1])
def test_air_column_excludes_mobs_under_a_solid_roof(self):
world = World(Munch(chunks=FakeChunks(solid={(0, 67, 0)})))
self.assertFalse(world.check_air_column((0, 64, 0), 5))
self.assertTrue(world.check_air_column((2, 64, 0), 5))
if __name__ == '__main__':
unittest.main()