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
@@ -1,11 +1,12 @@
|
||||
import io
|
||||
import time
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
from munch import Munch
|
||||
|
||||
from minecraft.networking.modern import (
|
||||
ClientTickEnd, EntityAnimationPacket, EntitySwingAnimationPacket,
|
||||
PunchPacket,
|
||||
PlayerActionPacket, PunchPacket,
|
||||
)
|
||||
from mosfet.game import Game
|
||||
|
||||
@@ -22,7 +23,18 @@ class BlockBreakAnimationTests(unittest.TestCase):
|
||||
def make_game(self):
|
||||
connection = RecordingConnection()
|
||||
game = object.__new__(Game)
|
||||
game.g = Munch(connection=connection, inv={}, inventory_state_ids={})
|
||||
class FakeChunks:
|
||||
block = 10
|
||||
|
||||
def get_block_at(self, *_position):
|
||||
return self.block
|
||||
|
||||
def set_block_at(self, *_position):
|
||||
self.block = 0
|
||||
|
||||
game.g = Munch(
|
||||
connection=connection, inv={}, inventory_state_ids={},
|
||||
chunks=FakeChunks())
|
||||
game.sequence = 0
|
||||
game.break_deadline = None
|
||||
game.breaking_state = None
|
||||
@@ -54,24 +66,33 @@ class BlockBreakAnimationTests(unittest.TestCase):
|
||||
[PunchPacket, ClientTickEnd])
|
||||
self.assertTrue(all(force for _, force in connection.packets))
|
||||
|
||||
def test_breaking_sends_initial_and_periodic_punches(self):
|
||||
def test_breaking_sends_finish_and_predicts_block_air(self):
|
||||
game, connection = self.make_game()
|
||||
game._advance_world_time = lambda: None
|
||||
game._tick_single_drop = lambda: None
|
||||
game.g.breaking = (1, 2, 3)
|
||||
game.break_deadline = time.monotonic() + 5
|
||||
game.break_deadline = 101.0
|
||||
game.breaking_state = 10
|
||||
game.next_swing_at = 0
|
||||
|
||||
game.tick()
|
||||
self.assertEqual(sum(isinstance(packet, PunchPacket)
|
||||
for packet, _ in connection.packets), 1)
|
||||
sent = len(connection.packets)
|
||||
game.tick()
|
||||
self.assertEqual(len(connection.packets), sent)
|
||||
with patch('mosfet.game.time.monotonic', return_value=100.0):
|
||||
game.tick()
|
||||
self.assertEqual(sum(isinstance(packet, PunchPacket)
|
||||
for packet, _ in connection.packets), 1)
|
||||
sent = len(connection.packets)
|
||||
game.tick()
|
||||
self.assertEqual(len(connection.packets), sent)
|
||||
|
||||
game.next_swing_at = 0
|
||||
game.tick()
|
||||
self.assertEqual(sum(isinstance(packet, PunchPacket)
|
||||
for packet, _ in connection.packets), 2)
|
||||
game.break_deadline = 99.0
|
||||
with patch('mosfet.game.time.monotonic', return_value=100.0):
|
||||
game.tick()
|
||||
actions = [packet.action for packet, _ in connection.packets
|
||||
if isinstance(packet, PlayerActionPacket)]
|
||||
self.assertEqual(actions, [3])
|
||||
self.assertIsNone(game.g.breaking)
|
||||
sent = len(connection.packets)
|
||||
game.tick()
|
||||
self.assertEqual(len(connection.packets), sent)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
Reference in new issue
Block a user