Skip to content

Commit

Permalink
Fix errors caused by right-clicking unknown nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
SmallJoker committed Oct 18, 2023
1 parent aca720d commit d6d43a4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
29 changes: 17 additions & 12 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -106,21 +106,26 @@ if lavastuff.enable_tool_fire == true and lavastuff.fire_node then
function lavastuff.tool_fire_func(itemstack, user, pointed)
local name = user:get_player_name()

if pointed.type == "node" then
local node = minetest.get_node(pointed.under)
local def = minetest.registered_nodes[node.name]
if pointed.type ~= "node" then
return
end

if def.on_rightclick then
return def.on_rightclick(pointed.under, node, user, itemstack, pointed)
end
local node = minetest.get_node(pointed.under)
local def = minetest.registered_nodes[node.name]
if not def then
return -- Unknown node
end

if minetest.is_protected(pointed.under, name) then return end
if def.on_rightclick then
return def.on_rightclick(pointed.under, node, user, itemstack, pointed)
end

-- Only allow fire every 1+ second(s)
if not COOLDOWN:get(user) then
activate_func(user, node.name, def, pointed)
COOLDOWN:set(user, 1)
end
if minetest.is_protected(pointed.under, name) then return end

-- Only allow fire every 1+ second(s)
if not COOLDOWN:get(user) then
activate_func(user, node.name, def, pointed)
COOLDOWN:set(user, 1)
end
end
end
Expand Down
3 changes: 3 additions & 0 deletions items/nodecore.lua
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ minetest.override_item("lavastuff:shovel", {

local node = minetest.get_node(pointed_thing.under)
local def = minetest.registered_nodes[node.name]
if not def then
return -- Unknown node
end

if not cooldown:get(user) and (def.groups.sand or (def.groups.silica_molten and def.liquidtype == "source")) then
cooldown:set(user, 0)
Expand Down

0 comments on commit d6d43a4

Please sign in to comment.