Added particle effects to pummelling.

Similar to crack texture on digging, this gives visual feedback
that what the user is doing is working, and just needs more time.
This commit is contained in:
Aaron Suen 2018-11-04 23:30:06 -05:00
parent db302c8807
commit e6977e1a0a
4 changed files with 60 additions and 12 deletions

View File

@ -1,10 +1,35 @@
-- LUALOCALS < ---------------------------------------------------------
local minetest, nodecore
= minetest, nodecore
= minetest, nodecore
-- LUALOCALS > ---------------------------------------------------------
local pummeling = {}
local function particlefx(pname, pointed)
local a = pointed.above
local b = pointed.under
local vel = vector.subtract(a, b)
local mid = vector.multiply(vector.add(a, b), 0.5)
local p1 = {x = vel.y, y = vel.z, z = vel.x}
local p2 = {x = vel.z, y = vel.x, z = vel.y}
local s1 = vector.add(vector.add(mid, vector.multiply(p1, 0.5)), vector.multiply(p2, 0.5))
local s2 = vector.add(vector.add(mid, vector.multiply(p1, -0.5)), vector.multiply(p2, -0.5))
vel = vector.multiply(vel, 0.5)
return minetest.add_particlespawner({
amount = 5,
time = 1.5,
minpos = s1,
maxpos = s2,
minvel = vel,
maxvel = vel,
minexptime = 0.4,
maxexptime = 0.9,
scale = 0.05,
texture = "nc_api_pummel.png",
playername = pname
})
end
minetest.register_on_punchnode(function(pos, node, puncher, pointed)
if not puncher:is_player() then return end
local pname = puncher:get_player_name()
@ -37,7 +62,21 @@ minetest.register_on_punchnode(function(pos, node, puncher, pointed)
pum.duration = now - pum.start
pummeling[pname] = pum
if def.can_pummel then
pum.check = def.can_pummel(pos, node, pum)
if not pum.check then
pummeling[pname] = nil
return
end
end
if pum.count > 1 then
if pum.particles then minetest.delete_particlespawner(pum.particles) end
pum.particles = particlefx(pname, pointed)
end
if def.on_pummel(pos, node, pum) then
if pum.particles then minetest.delete_particlespawner(pum.particles) end
nodecore.player_knowledge_add(puncher, "pummel:" .. node.name)
pummeling[pname] = nil
end

View File

@ -1,6 +1,6 @@
-- LUALOCALS < ---------------------------------------------------------
local minetest, nodecore, pairs, type
= minetest, nodecore, pairs, type
= minetest, nodecore, pairs, type
-- LUALOCALS > ---------------------------------------------------------
--[[
@ -21,14 +21,16 @@ end
local looseimg = "^nc_api_loose.png"
local function can_repack(pos, node, stats)
local wield = stats.puncher:get_wielded_item()
if not wield then return end
local dg = wield:get_tool_capabilities().damage_groups
return dg and dg.slappy
end
function nodecore.pummel_repack_node(duration, replace)
if type(replace) ~= "table" then replace = {name = replace} end
return function (pos, node, stats)
if stats.duration < duration then return end
local wield = stats.puncher:get_wielded_item()
if not wield then return end
local dg = wield:get_tool_capabilities().damage_groups
if not dg or not dg.slappy then return end
minetest.set_node(pos, replace)
return true
end
@ -61,6 +63,7 @@ nodecore.register_on_register_node(function(name, def)
if loose.groups.crumbly and not loose.no_repack then
loose.on_pummel = loose.on_pummel
or nodecore.pummel_repack_node(3, name)
loose.can_pummel = loose.can_pummel or can_repack
end
loose.alternate_loose = nil

Binary file not shown.

After

Width:  |  Height:  |  Size: 564 B

View File

@ -1,6 +1,6 @@
-- LUALOCALS < ---------------------------------------------------------
local ItemStack, ipairs, minetest, nodecore
= ItemStack, ipairs, minetest, nodecore
= ItemStack, ipairs, minetest, nodecore
-- LUALOCALS > ---------------------------------------------------------
local modname = minetest.get_current_modname()
@ -15,16 +15,22 @@ minetest.register_node(plank, {
})
nodecore.extend_node("nc_tree:tree", function(copy, orig)
local op = orig.on_pummel or function() end
copy.on_pummel = function(pos, node, stats, ...)
if (stats.pointed.above.y - stats.pointed.under.y) ~= 1
or stats.duration < 5 then
return op(pos, node, stats, ...)
local oc = orig.can_pummel or function() end
copy.can_pummel = function(pos, node, stats, ...)
if (stats.pointed.above.y - stats.pointed.under.y) ~= 1 then
return oc(pos, node, stats)
end
local wielded = stats.puncher:get_wielded_item()
local caps = wielded:get_tool_capabilities()
local choppy = caps and caps.groupcaps and caps.groupcaps.choppy
if not choppy then
return oc(pos, node, stats, ...)
end
return "plank"
end
local op = orig.on_pummel or function() end
copy.on_pummel = function(pos, node, stats, ...)
if stats.check ~= "plank" or stats.duration < 5 then
return op(pos, node, stats, ...)
end
minetest.remove_node(pos)