Extra error checking.

This commit is contained in:
Duane 2016-07-15 02:58:33 -05:00
parent aa999e2ed5
commit bf26b8bee1
25 changed files with 897 additions and 314 deletions

View file

@ -1,9 +1,17 @@
local function disintigrate(pos, radius, node_name, user_name, dropped)
if not (pos and radius and node_name and user_name and type(radius) == 'number' and type(user_name) == 'string') then
return
end
local node_id = minetest.get_content_id(node_name)
local air = minetest.get_content_id('air')
local minp = vector.subtract(pos, radius)
local maxp = vector.add(pos, radius)
local vm = minetest.get_voxel_manip()
if not vm then
return
end
local emin, emax = vm:read_from_map(minp, maxp)
local area = VoxelArea:new({MinEdge = emin, MaxEdge = emax})
local data = vm:get_data()
@ -50,6 +58,10 @@ end
local function floor(pos, blocks, node_name, user_name)
if not (pos and blocks and node_name and user_name and type(blocks) == 'number' and type(node_name) == 'string' and type(user_name) == 'string') then
return
end
local p = {y = pos.y}
local count = 0
for r = 1, blocks do
@ -90,14 +102,21 @@ for _, node in pairs(nodes) do
newnode.inventory_image = '[inventorycube{tnt_top.png{'..node_texture..'{tnt_side.png'
newnode.drop = bomb_name
newnode.on_punch = function(pos, node, puncher, pointed_thing)
if puncher:get_wielded_item():get_name() ~= "default:torch" then
if not (pos and puncher) then
return
end
local wield = puncher:get_wielded_item()
if not wield or wield:get_name() ~= "default:torch" then
return
end
minetest.after(5, function()
local pos_node = minetest.get_node_or_nil(pos)
if pos_node.name ~= bomb_name then
if not (pos_node and pos_node.name == bomb_name) then
return
end
disintigrate(pos, 5, node_name, puncher:get_player_name(), comp)
minetest.remove_node(pos)
end)
@ -137,14 +156,21 @@ for _, node in pairs(nodes) do
newnode.inventory_image = '[inventorycube{'..node_texture..'{'..node_texture..'{'..node_texture..'^fun_caves_expand.png'
newnode.drop = bomb_name
newnode.on_punch = function(pos, node, puncher, pointed_thing)
if puncher:get_wielded_item():get_name() ~= "default:torch" then
if not (pos and puncher) then
return
end
local wield = puncher:get_wielded_item()
if not wield or wield:get_name() ~= "default:torch" then
return
end
minetest.after(5, function()
local pos_node = minetest.get_node_or_nil(pos)
if pos_node.name ~= bomb_name then
if not (pos_node and pos_node.name == bomb_name) then
return
end
floor(pos, 100, node_name, puncher:get_player_name())
minetest.set_node(pos, {name = node_name})
end)
@ -217,6 +243,10 @@ local function power(player, pos, tool_type, max)
local air = minetest.get_content_id('air')
local vm = minetest.get_voxel_manip()
if not vm then
return
end
local emin, emax = vm:read_from_map(minp, maxp)
local area = VoxelArea:new({MinEdge = emin, MaxEdge = emax})
local data = vm:get_data()
@ -270,7 +300,10 @@ local function power(player, pos, tool_type, max)
local tp = tool:get_tool_capabilities()
local def = ItemStack({name=names[id]}):get_definition()
local dp = minetest.get_dig_params(def.groups, tp)
print(dp.wear)
if not dp then
return
end
tool:add_wear(dp.wear * number)
end
@ -289,11 +322,16 @@ minetest.register_tool("fun_caves:chainsaw", {
damage_groups = {fleshy=4},
},
on_use = function(itemstack, user, pointed_thing)
if not (user and pointed_thing) then
return
end
minetest.sound_play('chainsaw', {
object = user,
gain = 0.1,
max_hear_distance = 30
})
return power(user, pointed_thing.under, 'axe')
end,
})
@ -310,11 +348,16 @@ minetest.register_tool("fun_caves:jackhammer", {
damage_groups = {fleshy=4},
},
on_use = function(itemstack, user, pointed_thing)
if not (user and pointed_thing) then
return
end
minetest.sound_play('jackhammer', {
object = user,
gain = 0.1,
max_hear_distance = 30
})
return power(user, pointed_thing.under, 'pick')
end,
})