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
+76
-27
@@ -121,48 +121,97 @@ def diffrange(n):
|
||||
sign = 1 if n >= 0 else -1
|
||||
return range(0, n+sign, sign)
|
||||
|
||||
def _enchantment_level(enchantments, *names):
|
||||
if isinstance(enchantments, dict):
|
||||
for name in names:
|
||||
value = enchantments.get(name)
|
||||
if value is None:
|
||||
continue
|
||||
if isinstance(value, dict):
|
||||
value = value.get('level', value.get('lvl', 0))
|
||||
return int(value or 0)
|
||||
else:
|
||||
for enchantment in enchantments or ():
|
||||
if not isinstance(enchantment, dict):
|
||||
continue
|
||||
name = enchantment.get('name')
|
||||
if isinstance(name, dict):
|
||||
name = name.get('id', name.get('name'))
|
||||
if any(str(name).endswith(candidate) for candidate in names):
|
||||
return int(enchantment.get(
|
||||
'level', enchantment.get('lvl', 0)) or 0)
|
||||
return 0
|
||||
|
||||
|
||||
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."""
|
||||
enchantments=None, effects=None, creative=False):
|
||||
"""Return Mineflayer-style vanilla dig time in seconds."""
|
||||
if creative:
|
||||
return 0.0
|
||||
|
||||
held_item = str(held_item)
|
||||
block_data = blocks.get(block_id)
|
||||
hardness = block_data.get('hardness', 0)
|
||||
if hardness < 0:
|
||||
return float('inf')
|
||||
if hardness == 0:
|
||||
return 0.0
|
||||
|
||||
can_harvest = (
|
||||
'harvestTools' not in block_data or
|
||||
held_item in block_data['harvestTools'])
|
||||
harvest_tools = block_data.get('harvestTools')
|
||||
can_harvest = (not harvest_tools or
|
||||
held_item in harvest_tools)
|
||||
material = block_data.get('material', 'n/a')
|
||||
tool_multipliers = mcdata.mcd.materials.get(material, {})
|
||||
speed = tool_multipliers.get(held_item, 1.0)
|
||||
speed = tool_multipliers.get(held_item, 1.0) or 1.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
|
||||
efficiency = _enchantment_level(
|
||||
enchantments, 'efficiency', 'minecraft:efficiency')
|
||||
if efficiency > 0 and speed > 1.0:
|
||||
speed += efficiency * efficiency + 1
|
||||
|
||||
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)]
|
||||
|
||||
duration = hardness * (1.5 if can_harvest else 5.0) / speed
|
||||
if in_water:
|
||||
duration *= 5.0
|
||||
def effect_level(*names):
|
||||
for name in names:
|
||||
value = effects.get(name)
|
||||
if value is None:
|
||||
continue
|
||||
if isinstance(value, dict):
|
||||
amplifier = value.get('amplifier')
|
||||
if amplifier is not None:
|
||||
return int(amplifier) + 1
|
||||
return int(value.get('level', 0) or 0)
|
||||
# Runtime effect dictionaries use zero-based amplifiers.
|
||||
return int(value) + 1
|
||||
return 0
|
||||
|
||||
haste = max(effect_level('haste', 'minecraft:haste'),
|
||||
effect_level('conduit_power', 'minecraft:conduit_power'))
|
||||
if haste > 0:
|
||||
speed *= 1 + 0.2 * haste
|
||||
|
||||
fatigue = effect_level(
|
||||
'mining_fatigue', 'minecraft:mining_fatigue')
|
||||
if fatigue > 0:
|
||||
speed *= (0.3, 0.09, 0.0027, 0.00081, 0.000243)[
|
||||
min(fatigue, 4) - 1]
|
||||
|
||||
if speed <= 0:
|
||||
return float('inf')
|
||||
|
||||
aqua_affinity = _enchantment_level(
|
||||
enchantments, 'aqua_affinity', 'minecraft:aqua_affinity')
|
||||
if in_water and aqua_affinity == 0:
|
||||
speed /= 5.0
|
||||
if not on_ground:
|
||||
duration *= 5.0
|
||||
speed /= 5.0
|
||||
|
||||
# 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
|
||||
delta = speed / hardness / (30.0 if can_harvest else 100.0)
|
||||
if delta <= 0:
|
||||
return float('inf')
|
||||
if delta >= 1.0:
|
||||
return 0.0
|
||||
return ceil(1.0 / delta) * TICK
|
||||
|
||||
def search_2d(distance=0):
|
||||
def get_neighbors(x,y,z):
|
||||
|
||||
Reference in new issue
Block a user