Port and tune 26.3 wood farming
This commit is contained in:
+29
-2
@@ -2,6 +2,7 @@ import re
|
||||
import time
|
||||
import random
|
||||
from itertools import count
|
||||
from math import floor, isfinite
|
||||
from munch import Munch
|
||||
|
||||
from minecraft.networking.packets import Packet, clientbound, serverbound
|
||||
@@ -721,15 +722,41 @@ class Game(LegacyGame):
|
||||
block_id = self.g.chunks.get_block_at(*location)
|
||||
if block_id is None or block_id == blocks.AIR:
|
||||
return False
|
||||
|
||||
holding = self.g.get('holding', 0)
|
||||
held_slot = (45 if self.g.get('holding_hand', 0) == 1 else
|
||||
36 + int(self.g.get('holding_slot', 0) or 0))
|
||||
held_stack = self.g.get('inv', {}).get(held_slot)
|
||||
enchantments = (getattr(held_stack, 'components', {}) or {}).get(
|
||||
'enchantments', {})
|
||||
in_water = False
|
||||
on_ground = True
|
||||
position = self.g.get('pos')
|
||||
chunks = self.g.get('chunks')
|
||||
if position is not None and chunks is not None:
|
||||
x, y, z = (floor(position.x), floor(position.y),
|
||||
floor(position.z))
|
||||
support = chunks.get_block_at(x, floor(position.y - 0.2), z)
|
||||
if support is not None:
|
||||
on_ground = support not in blocks.NON_SOLID_IDS
|
||||
feet = chunks.get_block_at(x, y, z)
|
||||
eyes = chunks.get_block_at(x, floor(position.y + 1.62), z)
|
||||
in_water = feet in blocks.WATER_IDS or eyes in blocks.WATER_IDS
|
||||
|
||||
duration = utils.break_time(
|
||||
block_id, holding, in_water=in_water, on_ground=on_ground,
|
||||
enchantments=enchantments, effects=self.g.get('effects', {}))
|
||||
if not isfinite(duration):
|
||||
return False
|
||||
|
||||
packet = PlayerActionPacket(
|
||||
action=0, location=location, face=1,
|
||||
sequence=self._next_sequence())
|
||||
self._send_action(packet)
|
||||
self.g.breaking = location
|
||||
self.breaking_state = block_id
|
||||
hardness_time = utils.break_time(block_id, self.g.get('holding', 0))
|
||||
now = time.monotonic()
|
||||
self.break_deadline = now + max(0.05, hardness_time)
|
||||
self.break_deadline = now + duration
|
||||
self.animate()
|
||||
self.next_swing_at = now + self.ARM_SWING_INTERVAL
|
||||
return True
|
||||
|
||||
Reference in New Issue
Block a user