Wait for landing before block breaking
This commit is contained in:
1 parent
3e8b95c895
commit
5a3b299aa9
5 files changed
+281
-85
No files matched your search
@@ -2,10 +2,12 @@ import math
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
from munch import Munch
|
||||
from minecraft.networking.modern import PlayerActionPacket
|
||||
|
||||
from mosfet import utils
|
||||
from mosfet.game import Game
|
||||
from mosfet.info import blocks, items
|
||||
from mosfet.vector import Point3D
|
||||
|
||||
|
||||
class BlockBreakTimingTests(unittest.TestCase):
|
||||
@@ -21,6 +23,17 @@ class BlockBreakTimingTests(unittest.TestCase):
|
||||
self.assertAlmostEqual(
|
||||
utils.break_time(oak_leaves, oak_log, on_ground=False), 1.5)
|
||||
|
||||
def test_dig_time_uses_eye_submersion_and_aqua_affinity(self):
|
||||
sand = blocks.MCD_BLOCKS['sand']['minStateId']
|
||||
wooden_shovel = items.get_id('wooden_shovel')
|
||||
|
||||
self.assertEqual(utils.break_time(sand, wooden_shovel), 0.4)
|
||||
self.assertAlmostEqual(
|
||||
utils.break_time(sand, wooden_shovel, in_water=True), 1.9)
|
||||
self.assertEqual(utils.break_time(
|
||||
sand, wooden_shovel, in_water=True,
|
||||
enchantments={'minecraft:aqua_affinity': 1}), 0.4)
|
||||
|
||||
def test_efficiency_haste_and_fatigue_affect_break_ticks(self):
|
||||
oak_leaves = blocks.MCD_BLOCKS['oak_leaves']['minStateId']
|
||||
wooden_hoe = items.get_id('wooden_hoe')
|
||||
@@ -36,7 +49,7 @@ class BlockBreakTimingTests(unittest.TestCase):
|
||||
bedrock = blocks.MCD_BLOCKS['bedrock']['minStateId']
|
||||
self.assertTrue(math.isinf(utils.break_time(bedrock)))
|
||||
|
||||
def test_game_sends_finish_after_calculated_tick_duration(self):
|
||||
def test_dig_request_waits_until_grounded_before_starting(self):
|
||||
class RecordingConnection:
|
||||
def __init__(self):
|
||||
self.packets = []
|
||||
@@ -45,9 +58,62 @@ class BlockBreakTimingTests(unittest.TestCase):
|
||||
self.packets.append(packet)
|
||||
|
||||
class FakeChunks:
|
||||
@staticmethod
|
||||
def get_block_at(*_position):
|
||||
return blocks.MCD_BLOCKS['oak_leaves']['minStateId']
|
||||
state = blocks.MCD_BLOCKS['sand']['minStateId']
|
||||
|
||||
def get_block_at(self, *_position):
|
||||
return self.state
|
||||
|
||||
def set_block_at(self, *_position):
|
||||
self.state = blocks.AIR
|
||||
|
||||
connection = RecordingConnection()
|
||||
game = object.__new__(Game)
|
||||
game.g = Munch(
|
||||
connection=connection, chunks=FakeChunks(), inv={},
|
||||
holding=items.get_id('wooden_shovel'), holding_hand=0,
|
||||
holding_slot=0, pos=Point3D((0.0, 64.0, 0.0)),
|
||||
on_ground=False, breaking=None, game_mode=0)
|
||||
game.sequence = 0
|
||||
game.break_deadline = None
|
||||
game.breaking_state = None
|
||||
game.break_pending_since = None
|
||||
game.next_swing_at = 0.0
|
||||
game._advance_world_time = lambda: None
|
||||
game._tick_single_drop = lambda: None
|
||||
|
||||
with patch('mosfet.game.time.monotonic', return_value=100.0):
|
||||
self.assertTrue(game.break_block((0, 63, 0)))
|
||||
self.assertEqual(connection.packets, [])
|
||||
with patch('mosfet.game.time.monotonic', return_value=100.5):
|
||||
game.tick()
|
||||
self.assertEqual(connection.packets, [])
|
||||
|
||||
game.g.on_ground = True
|
||||
with patch('mosfet.game.time.monotonic', return_value=100.6):
|
||||
game.tick()
|
||||
|
||||
self.assertEqual(sum(isinstance(packet, PlayerActionPacket)
|
||||
for packet in connection.packets), 1)
|
||||
self.assertEqual(connection.packets[0].action, 0)
|
||||
self.assertAlmostEqual(game.break_deadline, 101.0)
|
||||
|
||||
def test_game_finishes_at_dig_time_and_predicts_block_air(self):
|
||||
class RecordingConnection:
|
||||
def __init__(self):
|
||||
self.packets = []
|
||||
|
||||
def write_packet(self, packet, force=False):
|
||||
self.packets.append(packet)
|
||||
|
||||
class FakeChunks:
|
||||
def __init__(self):
|
||||
self.block = blocks.MCD_BLOCKS['oak_leaves']['minStateId']
|
||||
|
||||
def get_block_at(self, *_position):
|
||||
return self.block
|
||||
|
||||
def set_block_at(self, *_position):
|
||||
self.block = blocks.AIR
|
||||
|
||||
connection = RecordingConnection()
|
||||
game = object.__new__(Game)
|
||||
@@ -62,9 +128,19 @@ class BlockBreakTimingTests(unittest.TestCase):
|
||||
|
||||
with patch('mosfet.game.time.monotonic', return_value=100.0):
|
||||
self.assertTrue(game.break_block((0, 64, 0)))
|
||||
self.assertAlmostEqual(
|
||||
game.break_deadline,
|
||||
100.3 + game.BREAK_FINISH_GRACE)
|
||||
self.assertAlmostEqual(game.break_deadline, 100.3)
|
||||
|
||||
game._advance_world_time = lambda: None
|
||||
game._tick_single_drop = lambda: None
|
||||
with patch('mosfet.game.time.monotonic',
|
||||
return_value=game.break_deadline):
|
||||
game.tick()
|
||||
|
||||
actions = [packet.action for packet in connection.packets
|
||||
if isinstance(packet, PlayerActionPacket)]
|
||||
self.assertEqual(actions, [0, 3])
|
||||
self.assertIsNone(game.g.breaking)
|
||||
self.assertEqual(game.g.chunks.block, blocks.AIR)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
Reference in new issue
Block a user