Calculate the correct block breaking time
This commit is contained in:
@@ -1,5 +1,11 @@
|
||||
import importlib
|
||||
from math import floor, ceil
|
||||
|
||||
import blocks
|
||||
importlib.reload(blocks)
|
||||
|
||||
TICK = 0.05
|
||||
|
||||
def padd(p1, p2):
|
||||
return (p1[0] + p2[0], p1[1] + p2[1], p1[2] + p2[2])
|
||||
|
||||
@@ -25,3 +31,29 @@ def cap(x, amount):
|
||||
sign = 1 if x >= 0 else -1
|
||||
return sign * min(abs(x), amount)
|
||||
|
||||
def break_time(block_id, held_item=0, in_water=False, on_ground=True, enchantments=[], effects={}):
|
||||
# from PrismarineJS/prismarine-block
|
||||
data = blocks.get(block_id)
|
||||
|
||||
can_harvest = 'harvestTools' not in data or str(held_item) in data['harvestTools']
|
||||
tool_multipliers = blocks.mcd.materials.get(data['material'], [])
|
||||
is_best_tool = held_item in tool_multipliers
|
||||
time = data['hardness']
|
||||
|
||||
if can_harvest:
|
||||
time *= 1.5
|
||||
else:
|
||||
time *= 5.0
|
||||
|
||||
if is_best_tool:
|
||||
speed_multiplier = tool_multipliers[held_item]
|
||||
# TODO: calc efficiency, haste, mining fatigue
|
||||
else:
|
||||
speed_multiplier = 1.0
|
||||
|
||||
time /= speed_multiplier
|
||||
if in_water: time *= 5.0
|
||||
if not on_ground: time *= 5.0
|
||||
|
||||
return time
|
||||
|
||||
|
||||
Reference in New Issue
Block a user