Port wood gathering and fix 26.3 swing animation
This commit is contained in:
+20
-3
@@ -8,7 +8,8 @@ from minecraft.networking.packets import Packet, clientbound, serverbound
|
||||
from minecraft.networking.types import BlockFace, Byte, Short, VarInt
|
||||
from minecraft.networking.modern import (
|
||||
ClientTickEnd, ContainerClickSwapPacket, PlayerActionPacket,
|
||||
SetCarriedItemPacket, SetHeldSlotPacket, UseItemOnBlockPacket,
|
||||
PunchPacket, SetCarriedItemPacket, SetHeldSlotPacket,
|
||||
UseItemOnBlockPacket,
|
||||
)
|
||||
|
||||
from mosfet.protocol.packets import (
|
||||
@@ -651,11 +652,14 @@ class LegacyGame:
|
||||
# Active game facade. The constructor registers no legacy packet listeners;
|
||||
# migrated actions use the 26.3 packet classes imported above.
|
||||
class Game(LegacyGame):
|
||||
ARM_SWING_INTERVAL = 0.1
|
||||
|
||||
def __init__(self, global_state):
|
||||
self.g = global_state
|
||||
self.sequence = 0
|
||||
self.break_deadline = None
|
||||
self.breaking_state = None
|
||||
self.next_swing_at = 0.0
|
||||
|
||||
from mosfet.protocol.packets import SetHealthPacket
|
||||
# Health is a protocol-777 packet, not the legacy UpdateHealthPacket.
|
||||
@@ -708,6 +712,10 @@ class Game(LegacyGame):
|
||||
self.sequence += 1
|
||||
return self.sequence
|
||||
|
||||
def animate(self):
|
||||
"""Ask the 26.3 server to broadcast a main-hand punch animation."""
|
||||
self._send_action(PunchPacket())
|
||||
|
||||
def break_block(self, location):
|
||||
location = tuple(int(value) for value in location)
|
||||
block_id = self.g.chunks.get_block_at(*location)
|
||||
@@ -720,7 +728,10 @@ class Game(LegacyGame):
|
||||
self.g.breaking = location
|
||||
self.breaking_state = block_id
|
||||
hardness_time = utils.break_time(block_id, self.g.get('holding', 0))
|
||||
self.break_deadline = time.monotonic() + max(0.05, hardness_time)
|
||||
now = time.monotonic()
|
||||
self.break_deadline = now + max(0.05, hardness_time)
|
||||
self.animate()
|
||||
self.next_swing_at = now + self.ARM_SWING_INTERVAL
|
||||
return True
|
||||
|
||||
def respawn(self):
|
||||
@@ -922,7 +933,11 @@ class Game(LegacyGame):
|
||||
self._tick_drain()
|
||||
if not self.g.get('breaking') or self.break_deadline is None:
|
||||
return
|
||||
if time.monotonic() < self.break_deadline:
|
||||
now = time.monotonic()
|
||||
if now < self.break_deadline:
|
||||
if now >= self.next_swing_at:
|
||||
self.animate()
|
||||
self.next_swing_at = now + self.ARM_SWING_INTERVAL
|
||||
return
|
||||
packet = PlayerActionPacket(
|
||||
action=3, location=self.g.breaking, face=1,
|
||||
@@ -937,6 +952,7 @@ class Game(LegacyGame):
|
||||
self.g.breaking = None
|
||||
self.break_deadline = None
|
||||
self.breaking_state = None
|
||||
self.next_swing_at = 0.0
|
||||
|
||||
def cancel_break(self):
|
||||
if not self.g.get('breaking'):
|
||||
@@ -948,6 +964,7 @@ class Game(LegacyGame):
|
||||
self.g.breaking = None
|
||||
self.break_deadline = None
|
||||
self.breaking_state = None
|
||||
self.next_swing_at = 0.0
|
||||
|
||||
def select_item(self, item_ids):
|
||||
item_ids = set(item_ids)
|
||||
|
||||
Reference in New Issue
Block a user