First steps to implement MC-like digging times
This involves MASSIVE hacks around the digging system in Minetest. Implemented so far: Hardness, nodes in mcl_core, digging for nodes diggable by pickaxe, shovel, axe. Not implemented: Nodes diggable by hand alone (except insta-dig), shears and sword.
This commit is contained in:
parent
d3b3c596bd
commit
4ecef7b411
3 changed files with 175 additions and 115 deletions
|
@ -1,17 +1,67 @@
|
|||
-- Automatically assign the “solid” group for solid nodes
|
||||
local overwrite = function()
|
||||
local materials = { "wood", "gold", "stone", "iron", "diamond" }
|
||||
local material_divisors = { 2, 12, 4, 6, 8 }
|
||||
local basegroups = { "pickaxey", "axey", "shovely" }
|
||||
local minigroups = { "handy", "shearsy", "swordy" }
|
||||
|
||||
for nname, ndef in pairs(minetest.registered_nodes) do
|
||||
if (nname ~= "ignore")
|
||||
and (ndef.walkable == nil or ndef.walkable == true)
|
||||
and (ndef.collision_box == nil or ndef.collision_box.type == "regular")
|
||||
and (ndef.node_box == nil or ndef.node_box.type == "regular")
|
||||
and (ndef.groups.falling_node == 0 or ndef.groups.falling_node == nil)
|
||||
and (ndef.groups.not_solid == 0 or ndef.groups.not_solid == nil) then
|
||||
local groups = table.copy(ndef.groups)
|
||||
groups.solid = 1
|
||||
minetest.override_item(nname, {
|
||||
groups = groups
|
||||
})
|
||||
local groups_changed = false
|
||||
local newgroups = table.copy(ndef.groups)
|
||||
if (nname ~= "ignore") then
|
||||
-- Automatically assign the “solid” group for solid nodes
|
||||
if (ndef.walkable == nil or ndef.walkable == true)
|
||||
and (ndef.collision_box == nil or ndef.collision_box.type == "regular")
|
||||
and (ndef.node_box == nil or ndef.node_box.type == "regular")
|
||||
and (ndef.groups.falling_node == 0 or ndef.groups.falling_node == nil)
|
||||
and (ndef.groups.not_solid == 0 or ndef.groups.not_solid == nil) then
|
||||
newgroups.solid = 1
|
||||
groups_changed = true
|
||||
end
|
||||
|
||||
-- Hack in digging times
|
||||
local hardness = ndef._mcl_hardness
|
||||
if not hardness then
|
||||
hardness = 0
|
||||
end
|
||||
-- Handle pickaxey, axey and shovely, and also handy indirectly
|
||||
for _, basegroup in pairs(basegroups) do
|
||||
if (hardness ~= -1 and ndef.groups[basegroup]) then
|
||||
for g=1,#materials do
|
||||
local diggroup = basegroup.."_dig_"..materials[g]
|
||||
local time, validity_factor
|
||||
if g >= ndef.groups[basegroup] then
|
||||
-- Valid tool
|
||||
validity_factor = 1.5
|
||||
else
|
||||
-- Wrong tool (higher digging time)
|
||||
validity_factor = 5
|
||||
end
|
||||
time = (hardness * validity_factor) / material_divisors[g]
|
||||
if time <= 0.05 then
|
||||
time = 1
|
||||
else
|
||||
time = math.ceil(time * 20)
|
||||
end
|
||||
newgroups[diggroup] = time
|
||||
groups_changed = true
|
||||
end
|
||||
if not ndef.groups.handy then
|
||||
local time = hardness * 5
|
||||
if time <= 0.05 then
|
||||
time = 1
|
||||
else
|
||||
time = math.ceil(time * 20)
|
||||
end
|
||||
newgroups.handy_dig = time
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if groups_changed then
|
||||
minetest.override_item(nname, {
|
||||
groups = newgroups
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue