Extra error checking.
This commit is contained in:
parent
aa999e2ed5
commit
bf26b8bee1
25 changed files with 897 additions and 314 deletions
|
@ -1,61 +1,66 @@
|
|||
local function register_liquid_wood(source, itemname, inventory_image, name, groups)
|
||||
if itemname ~= nil then
|
||||
if inventory_image then
|
||||
inventory_image = inventory_image..'^fun_caves_wood_bucket_overlay.png'
|
||||
end
|
||||
minetest.register_craftitem(itemname, {
|
||||
description = name,
|
||||
inventory_image = inventory_image,
|
||||
stack_max = 1,
|
||||
liquids_pointable = true,
|
||||
groups = groups,
|
||||
|
||||
on_place = function(itemstack, user, pointed_thing)
|
||||
-- Must be pointing to node
|
||||
if pointed_thing.type ~= "node" then
|
||||
return
|
||||
end
|
||||
|
||||
local node = minetest.get_node_or_nil(pointed_thing.under)
|
||||
local ndef = node and minetest.registered_nodes[node.name]
|
||||
|
||||
-- Call on_rightclick if the pointed node defines it
|
||||
if ndef and ndef.on_rightclick and
|
||||
user and not user:get_player_control().sneak then
|
||||
return ndef.on_rightclick(
|
||||
pointed_thing.under,
|
||||
node, user,
|
||||
itemstack)
|
||||
end
|
||||
|
||||
local lpos
|
||||
|
||||
-- Check if pointing to a buildable node
|
||||
if ndef and ndef.buildable_to then
|
||||
-- buildable; replace the node
|
||||
lpos = pointed_thing.under
|
||||
else
|
||||
-- not buildable to; place the liquid above
|
||||
-- check if the node above can be replaced
|
||||
lpos = pointed_thing.above
|
||||
local node = minetest.get_node_or_nil(lpos)
|
||||
local above_ndef = node and minetest.registered_nodes[node.name]
|
||||
|
||||
if not above_ndef or not above_ndef.buildable_to then
|
||||
-- do not remove the bucket with the liquid
|
||||
return itemstack
|
||||
end
|
||||
end
|
||||
|
||||
if minetest.is_protected(lpos, user and user:get_player_name() or "") then
|
||||
return
|
||||
end
|
||||
|
||||
minetest.set_node(lpos, {name = source})
|
||||
return ItemStack("fun_caves:bucket_wood_empty")
|
||||
end
|
||||
})
|
||||
if not (source and itemname and inventory_image and name and type(source) == 'string' and type(itemname) == 'string' and type(inventory_image) == 'string') then
|
||||
return
|
||||
end
|
||||
|
||||
inventory_image = inventory_image..'^fun_caves_wood_bucket_overlay.png'
|
||||
minetest.register_craftitem(itemname, {
|
||||
description = name,
|
||||
inventory_image = inventory_image,
|
||||
stack_max = 1,
|
||||
liquids_pointable = true,
|
||||
groups = groups,
|
||||
|
||||
on_place = function(itemstack, user, pointed_thing)
|
||||
if not (user and pointed_thing) then
|
||||
return
|
||||
end
|
||||
|
||||
-- Must be pointing to node
|
||||
if pointed_thing.type ~= "node" then
|
||||
return
|
||||
end
|
||||
|
||||
local node = minetest.get_node_or_nil(pointed_thing.under)
|
||||
local ndef = node and minetest.registered_nodes[node.name]
|
||||
|
||||
-- Call on_rightclick if the pointed node defines it
|
||||
if ndef and ndef.on_rightclick and
|
||||
user and not user:get_player_control().sneak then
|
||||
return ndef.on_rightclick(pointed_thing.under, node, user, itemstack)
|
||||
end
|
||||
|
||||
local lpos
|
||||
|
||||
-- Check if pointing to a buildable node
|
||||
if ndef and ndef.buildable_to then
|
||||
-- buildable; replace the node
|
||||
lpos = pointed_thing.under
|
||||
else
|
||||
-- not buildable to; place the liquid above
|
||||
-- check if the node above can be replaced
|
||||
lpos = pointed_thing.above
|
||||
local node = minetest.get_node_or_nil(lpos)
|
||||
if not node then
|
||||
return
|
||||
end
|
||||
|
||||
local above_ndef = node and minetest.registered_nodes[node.name]
|
||||
|
||||
if not above_ndef or not above_ndef.buildable_to then
|
||||
-- do not remove the bucket with the liquid
|
||||
return itemstack
|
||||
end
|
||||
end
|
||||
|
||||
if minetest.is_protected(lpos, user and user:get_player_name() or "") then
|
||||
return
|
||||
end
|
||||
|
||||
minetest.set_node(lpos, {name = source})
|
||||
return ItemStack("fun_caves:bucket_wood_empty")
|
||||
end
|
||||
})
|
||||
end
|
||||
|
||||
for fluid, def in pairs(bucket.liquids) do
|
||||
|
@ -86,11 +91,16 @@ minetest.register_craftitem("fun_caves:bucket_wood_empty", {
|
|||
liquids_pointable = true,
|
||||
on_use = function(itemstack, user, pointed_thing)
|
||||
-- Must be pointing to node
|
||||
if pointed_thing.type ~= "node" then
|
||||
if not (user and pointed_thing and pointed_thing.type == "node") then
|
||||
return
|
||||
end
|
||||
|
||||
-- Check if pointing to a liquid source
|
||||
local node = minetest.get_node(pointed_thing.under)
|
||||
if not node then
|
||||
return
|
||||
end
|
||||
|
||||
local liquiddef = bucket.liquids[node.name]
|
||||
if node.name ~= liquiddef.source then
|
||||
return
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue