Port and tune 26.3 wood farming

This commit is contained in:
Tanner
2026-11-05 16:36:10 +00:00
parent b89f0f6ed2
commit 4c27f5058e
15 changed files with 412 additions and 40 deletions
+34 -19
View File
@@ -82,33 +82,48 @@ def diffrange(n):
sign = 1 if n >= 0 else -1
return range(0, n+sign, sign)
def break_time(block_id, held_item=0, in_water=False, on_ground=True, enchantments=[], effects={}):
# from PrismarineJS/prismarine-block
def break_time(block_id, held_item=0, in_water=False, on_ground=True,
enchantments=None, effects=None):
"""Return vanilla block-breaking duration rounded to whole game ticks."""
held_item = str(held_item)
block_data = blocks.get(block_id)
hardness = block_data.get('hardness', 0)
if hardness < 0:
return float('inf')
can_harvest = 'harvestTools' not in block_data or str(held_item) in block_data['harvestTools']
can_harvest = (
'harvestTools' not in block_data or
held_item in block_data['harvestTools'])
material = block_data.get('material', 'n/a')
tool_multipliers = mcdata.mcd.materials.get(material, [])
is_best_tool = held_item in tool_multipliers
time = block_data['hardness']
tool_multipliers = mcdata.mcd.materials.get(material, {})
speed = tool_multipliers.get(held_item, 1.0)
if can_harvest:
time *= 1.5
else:
time *= 5.0
enchantments = enchantments or {}
if speed > 1:
efficiency = int(enchantments.get(
'efficiency', enchantments.get('minecraft:efficiency', 0)) or 0)
if efficiency > 0:
speed += efficiency * efficiency + 1
if is_best_tool:
speed_multiplier = tool_multipliers[held_item]
# TODO: calc efficiency, haste, mining fatigue
else:
speed_multiplier = 1.0
effects = effects or {}
haste = int(effects.get('haste', effects.get('minecraft:haste', 0)) or 0)
if haste >= 0 and ('haste' in effects or 'minecraft:haste' in effects):
speed *= 1 + 0.2 * (haste + 1)
fatigue = int(effects.get(
'mining_fatigue', effects.get('minecraft:mining_fatigue', -1)))
if fatigue >= 0:
speed *= (0.3, 0.09, 0.0027, 0.00081, 0.000243)[min(fatigue, 4)]
time /= speed_multiplier
if in_water: time *= 5.0
if not on_ground: time *= 5.0
duration = hardness * (1.5 if can_harvest else 5.0) / speed
if in_water:
duration *= 5.0
if not on_ground:
duration *= 5.0
return time
# Vanilla advances breaking progress in 1/20-second ticks; clients cannot
# finish between ticks. Round up, while avoiding floating-point over-round.
ticks = max(1, ceil(duration / TICK - 1e-9))
return ticks * TICK
def search_2d(distance=0):
def get_neighbors(x,y,z):