Merge pull request #82 from DS-Minetest/hopper_fix1

hopper: fix crash
This commit is contained in:
D00Med 2017-04-21 18:59:49 +10:00 committed by GitHub
commit f74da0509b

View File

@ -5,9 +5,9 @@ minetest.register_node("stm_nodes:reactor", {
"stm_nodes_reactor.png", "stm_nodes_reactor.png",
}, },
on_rightclick = function(pos, node) on_rightclick = function(pos, node)
minetest.set_node(pos, {name="stm_nodes:reactor_active"}) minetest.set_node(pos, {name = "stm_nodes:reactor_active"})
end, end,
groups = {cracky=1, electric=1}, groups = {cracky = 1, electric = 1},
sounds = default.node_sound_metal_defaults(), sounds = default.node_sound_metal_defaults(),
}) })
@ -16,12 +16,12 @@ minetest.register_node("stm_nodes:reactor_active", {
"stm_nodes_reactor_active.png", "stm_nodes_reactor_active.png",
}, },
on_rightclick = function(pos, node) on_rightclick = function(pos, node)
minetest.set_node(pos, {name="stm_nodes:reactor"}) minetest.set_node(pos, {name = "stm_nodes:reactor"})
end, end,
paramtype = "light", paramtype = "light",
light_source = 10, light_source = 10,
drop = "stm_nodes:reactor", drop = "stm_nodes:reactor",
groups = {cracky=1, electric=1}, groups = {cracky = 1, electric = 1},
sounds = default.node_sound_metal_defaults(), sounds = default.node_sound_metal_defaults(),
}) })
@ -58,7 +58,7 @@ minetest.register_node("stm_nodes:hopper", {
{-0.375, -0.125, 0.3125, 0.375, 0.5, 0.375}, -- NodeBox19 {-0.375, -0.125, 0.3125, 0.375, 0.5, 0.375}, -- NodeBox19
} }
}, },
groups = {cracky=1}, groups = {cracky = 1},
sounds = default.node_sound_metal_defaults(), sounds = default.node_sound_metal_defaults(),
on_rightclick = function(pos, node, clicker, itemstack) on_rightclick = function(pos, node, clicker, itemstack)
minetest.add_item({x=pos.x, y=pos.y+0.5, z=pos.z}, itemstack) minetest.add_item({x=pos.x, y=pos.y+0.5, z=pos.z}, itemstack)
@ -201,9 +201,7 @@ minetest.register_node("stm_nodes:tank2", {
minetest.register_node("stm_nodes:stand", { minetest.register_node("stm_nodes:stand", {
description = "Tin Machinery Stand", description = "Tin Machinery Stand",
tiles = { tiles = {"stm_nodes_tin2.png"},
"stm_nodes_tin2.png",
},
drawtype = "nodebox", drawtype = "nodebox",
paramtype = "light", paramtype = "light",
node_box = { node_box = {
@ -221,15 +219,13 @@ minetest.register_node("stm_nodes:stand", {
{-0.4375, 0.375, -0.4375, 0.4375, 0.4375, 0.4375}, -- NodeBox10 {-0.4375, 0.375, -0.4375, 0.4375, 0.4375, 0.4375}, -- NodeBox10
} }
}, },
groups = {cracky=1,}, groups = {cracky = 1},
sounds = default.node_sound_metal_defaults() sounds = default.node_sound_metal_defaults()
}) })
minetest.register_node("stm_nodes:stand2", { minetest.register_node("stm_nodes:stand2", {
description = "Copper Machinery Stand", description = "Copper Machinery Stand",
tiles = { tiles = {"stm_nodes_copper2.png"},
"stm_nodes_copper2.png",
},
drawtype = "nodebox", drawtype = "nodebox",
paramtype = "light", paramtype = "light",
node_box = { node_box = {
@ -247,7 +243,7 @@ minetest.register_node("stm_nodes:stand2", {
{-0.4375, 0.375, -0.4375, 0.4375, 0.4375, 0.4375}, -- NodeBox10 {-0.4375, 0.375, -0.4375, 0.4375, 0.4375, 0.4375}, -- NodeBox10
} }
}, },
groups = {cracky=1,}, groups = {cracky = 1},
sounds = default.node_sound_metal_defaults() sounds = default.node_sound_metal_defaults()
}) })
@ -259,7 +255,7 @@ minetest.register_node("stm_nodes:pipe", {
"stm_nodes_pipe.png", "stm_nodes_pipe.png",
}, },
paramtype2 = "facedir", paramtype2 = "facedir",
groups = {cracky=1, ventilation=1,}, groups = {cracky = 1, ventilation = 1,},
on_place = minetest.rotate_node, on_place = minetest.rotate_node,
sounds = default.node_sound_metal_defaults() sounds = default.node_sound_metal_defaults()
}) })
@ -282,18 +278,24 @@ minetest.register_abm({
interval = 1, interval = 1,
chance = 1, chance = 1,
action = function(pos, node) action = function(pos, node)
local steam_source = minetest.find_node_near(pos, 1, {"default:furnace_active2", "stm_nodes:pipe_active", "stm_nodes:reactor_active"}) local steam_source = minetest.find_node_near(pos, 1, {
"default:furnace_active2",
"stm_nodes:pipe_active",
"stm_nodes:reactor_active"
})
if steam_source then if steam_source then
minetest.set_node(pos, {name="stm_nodes:pipe_active", param2=node.param2}) minetest.set_node(pos, {name="stm_nodes:pipe_active", param2=node.param2})
end end
local boiler_output = minetest.find_node_near(pos, 1, {"stm_nodes:boiler_output"}) local boiler_output = minetest.find_node_near(pos, 1, {"stm_nodes:boiler_output"})
if boiler_output and minetest.get_item_group(minetest.get_node({x=boiler_output.x, y=boiler_output.y-1, z=boiler_output.z}).name, "boiler") ~= 0 then if not boiler_output or minetest.get_item_group(minetest.get_node(vector.add(boiler_output, {x=0,y=-1,z=0})).name, "boiler") == 0 then
local heat = minetest.find_node_near({x=boiler_output.x, y=boiler_output.y-2, z=boiler_output.z}, 1, {"stm_nodes:furnace_active", "default:furnace_active2"}) return
end
local heat = minetest.find_node_near(vector.add(boiler_output, {x=0,y=-2,z=0}),
1, {"stm_nodes:furnace_active", "default:furnace_active2"})
if heat then if heat then
minetest.set_node(pos, {name="stm_nodes:pipe_active", param2=node.param2}) minetest.set_node(pos, {name="stm_nodes:pipe_active", param2=node.param2})
end end
end end
end
}) })
minetest.register_abm({ minetest.register_abm({
@ -301,7 +303,7 @@ minetest.register_abm({
interval = 5, interval = 5,
chance = 1, chance = 1,
action = function(pos, node) action = function(pos, node)
minetest.set_node(pos, {name="stm_nodes:pipe", param2=node.param2}) minetest.set_node(pos, {name = "stm_nodes:pipe", param2 = node.param2})
end end
}) })
@ -310,8 +312,7 @@ minetest.register_abm({
interval = 1, interval = 1,
chance = 1, chance = 1,
action = function(pos, node) action = function(pos, node)
local furnace = minetest.find_node_near(pos, 1, {"default:furnace_active2"}) if minetest.find_node_near(pos, 1, {"default:furnace_active2"}) then
if furnace then
minetest.set_node(pos, {name="stm_nodes:pipe_active", param2=node.param2}) minetest.set_node(pos, {name="stm_nodes:pipe_active", param2=node.param2})
end end
end end
@ -387,11 +388,11 @@ minetest.register_node("stm_nodes:output_tray", {
node_box = { node_box = {
type = "fixed", type = "fixed",
fixed = { fixed = {
{-0.5, -0.5, -0.5, 0.5, -0.4375, 0.5}, -- NodeBox21 {-0.5, -0.5, -0.5, 0.5, -0.4375, 0.5}, -- NodeBox1
{-0.5, -0.5, 0.4375, 0.5, -0.125, 0.5}, -- NodeBox22 {-0.5, -0.5, 0.4375, 0.5, -0.125, 0.5}, -- NodeBox2
{-0.5, -0.5, -0.5, 0.5, -0.125, -0.4375}, -- NodeBox23 {-0.5, -0.5, -0.5, 0.5, -0.125, -0.4375}, -- NodeBox3
{0.4375, -0.5, -0.5, 0.5, -0.125, 0.5}, -- NodeBox24 {0.4375, -0.5, -0.5, 0.5, -0.125, 0.5}, -- NodeBox4
{-0.5, -0.5, -0.5, -0.4375, -0.125, 0.5}, -- NodeBox25 {-0.5, -0.5, -0.5, -0.4375, -0.125, 0.5}, -- NodeBox5
} }
}, },
groups = {cracky=1}, groups = {cracky=1},
@ -404,12 +405,10 @@ minetest.register_abm({
chance = 1, chance = 1,
action = function(pos, node) action = function(pos, node)
local steam_source = minetest.find_node_near(pos, 1, {"stm_nodes:pipe_active", "default:furnace_active2"}) local steam_source = minetest.find_node_near(pos, 1, {"stm_nodes:pipe_active", "default:furnace_active2"})
local input_pos = {x=pos.x, y=pos.y+1, z=pos.z}
if steam_source == nil then if not steam_source or minetest.get_node(input_pos).name ~= "stm_nodes:hopper" then
return return
end end
local input_pos = {x=pos.x, y=pos.y+1, z=pos.z}
local output_pos = minetest.find_node_near(pos, 1.5, {"stm_nodes:output_tray"}) local output_pos = minetest.find_node_near(pos, 1.5, {"stm_nodes:output_tray"})
local n = { local n = {
{x=pos.x+1, y=pos.y, z=pos.z}, {x=pos.x+1, y=pos.y, z=pos.z},
@ -418,23 +417,27 @@ minetest.register_abm({
{x=pos.x, y=pos.y, z=pos.z-1}, {x=pos.x, y=pos.y, z=pos.z-1},
{x=pos.x, y=pos.y+1, z=pos.z}, {x=pos.x, y=pos.y+1, z=pos.z},
} }
local vent_pos = nil local vent_pos
for _, position in ipairs(n) do for _, position in ipairs(n) do
local item = minetest.get_node(position).name local item = minetest.get_node(position).name
if minetest.get_item_group(item, "ventilation") ~= 0 then if minetest.get_item_group(item, "ventilation") ~= 0 then
vent_pos = position vent_pos = position
break
end end
end end
if vent_pos ~= nil then if not vent_pos then
if minetest.get_node(input_pos).name == "stm_nodes:hopper" then return
end
local objects = minetest.get_objects_inside_radius(input_pos, 0.5) local objects = minetest.get_objects_inside_radius(input_pos, 0.5)
for _, obj in ipairs(objects) do for _, obj in ipairs(objects) do
if obj:get_luaentity().name == "__builtin:item" then if not obj:is_player() and obj:get_luaentity().name == "__builtin:item" then
local input_item = obj:get_luaentity().itemstring local input_item = obj:get_luaentity().itemstring
local itemname = ItemStack(input_item):get_name() local itemname = ItemStack(input_item):get_name()
local itemcount = ItemStack(input_item):get_count() local itemcount = ItemStack(input_item):get_count()
if minetest.get_item_group(itemname, "cracky") ~= 0 then if minetest.get_item_group(itemname, "cracky") == 0 then
return
end
obj:remove() obj:remove()
minetest.add_particlespawner({ minetest.add_particlespawner({
amount = 4, amount = 4,
@ -455,14 +458,15 @@ minetest.register_abm({
}) })
minetest.after(itemcount/2, function() minetest.after(itemcount/2, function()
minetest.add_item(output_pos, "default:gravel "..itemcount) minetest.add_item(output_pos, "default:gravel "..itemcount)
minetest.sound_play("default_place_node_metal", {pos = pos, gain = 0.3, max_hear_distance = 16}) minetest.sound_play("default_place_node_metal", {
pos = pos,
gain = 0.3,
max_hear_distance = 16
})
end) end)
end end
end end
end end
end
end
end
}) })
minetest.register_node("stm_nodes:compressor_open", { minetest.register_node("stm_nodes:compressor_open", {
@ -506,9 +510,13 @@ minetest.register_node("stm_nodes:compressor_open", {
local compressor_function = function(pos) local compressor_function = function(pos)
minetest.after(0.5, function() minetest.after(0.5, function()
local steam_source = minetest.find_node_near(pos, 1, "stm_nodes:pipe_active") local steam_source = minetest.find_node_near(pos, 1, "stm_nodes:pipe_active")
if steam_source ~= nil then if steam_source then
minetest.set_node(pos, {name="stm_nodes:compressor_closed"}) minetest.set_node(pos, {name="stm_nodes:compressor_closed"})
minetest.sound_play("default_place_node_metal", {pos = pos, gain = 0.3, max_hear_distance = 16}) minetest.sound_play("default_place_node_metal", {
pos = pos,
gain = 0.3,
max_hear_distance = 16
})
end end
end) end)
end end
@ -525,14 +533,12 @@ local closed_compressor_function = function(pos)
minetest.after(1, function() minetest.after(1, function()
minetest.add_item(pos, "default:paper "..itemcount) minetest.add_item(pos, "default:paper "..itemcount)
end) end)
end elseif itemname == "default:gravel" then
if itemname == "default:gravel" then
obj:remove() obj:remove()
minetest.after(1, function() minetest.after(1, function()
minetest.add_item(pos, "default:stone "..itemcount) minetest.add_item(pos, "default:stone "..itemcount)
end) end)
end elseif itemname == "default:dirt" then
if itemname == "default:dirt" then
obj:remove() obj:remove()
minetest.after(1, function() minetest.after(1, function()
minetest.add_item(pos, "mapgen:coarse_dirt "..itemcount) minetest.add_item(pos, "mapgen:coarse_dirt "..itemcount)
@ -542,7 +548,11 @@ local closed_compressor_function = function(pos)
end end
minetest.after(1, function() minetest.after(1, function()
minetest.set_node(pos, {name="stm_nodes:compressor_open"}) minetest.set_node(pos, {name="stm_nodes:compressor_open"})
minetest.sound_play("default_metal_footstep", {pos = pos, gain = 0.3, max_hear_distance = 16}) minetest.sound_play("default_metal_footstep", {
pos = pos,
gain = 0.3,
max_hear_distance = 16
})
end) end)
end end
@ -652,7 +662,7 @@ minetest.register_node("stm_nodes:lever_closed", {
on_rightclick = function(pos, node) on_rightclick = function(pos, node)
minetest.set_node(pos, {name="stm_nodes:lever_open", param2=node.param2}) minetest.set_node(pos, {name="stm_nodes:lever_open", param2=node.param2})
end, end,
groups = {cracky=1,}, groups = {cracky = 1},
sounds = default.node_sound_metal_defaults(), sounds = default.node_sound_metal_defaults(),
}) })
@ -691,9 +701,7 @@ minetest.register_node("stm_nodes:cable", {
}) })
minetest.register_node("stm_nodes:cable_active", { minetest.register_node("stm_nodes:cable_active", {
tiles = { tiles = {"stm_nodes_cable.png"},
"stm_nodes_cable.png",
},
drawtype = "nodebox", drawtype = "nodebox",
paramtype = "light", paramtype = "light",
paramtype2 = "facedir", paramtype2 = "facedir",
@ -726,9 +734,7 @@ minetest.register_node("stm_nodes:cable_active", {
minetest.register_node("stm_nodes:cable_ceiling", { minetest.register_node("stm_nodes:cable_ceiling", {
description = "Ceiling Cable", description = "Ceiling Cable",
tiles = { tiles = {"stm_nodes_cable.png"},
"stm_nodes_cable.png",
},
drawtype = "nodebox", drawtype = "nodebox",
paramtype = "light", paramtype = "light",
paramtype2 = "facedir", paramtype2 = "facedir",
@ -865,9 +871,7 @@ minetest.register_node("stm_nodes:big_vent", {
minetest.register_node("stm_nodes:coal_feed", { minetest.register_node("stm_nodes:coal_feed", {
description = "Coal Feeder", description = "Coal Feeder",
tiles = { tiles = {"stm_nodes_block.png"},
"stm_nodes_block.png",
},
drawtype = "nodebox", drawtype = "nodebox",
paramtype = "light", paramtype = "light",
node_box = { node_box = {
@ -912,7 +916,7 @@ minetest.register_node("stm_nodes:machinery_base", {
tiles = { tiles = {
"stm_nodes_block.png", "stm_nodes_block.png",
}, },
groups = {cracky=1}, groups = {cracky = 1},
sounds = default.node_sound_metal_defaults() sounds = default.node_sound_metal_defaults()
}) })
@ -923,7 +927,7 @@ minetest.register_node("stm_nodes:furnace_active", {
}}, }},
paramtype = "light", paramtype = "light",
light_source = 12, light_source = 12,
groups = {cracky=1}, groups = {cracky = 1},
damage_per_second = 1, damage_per_second = 1,
drop = "stm_nodes:furnace", drop = "stm_nodes:furnace",
sounds = default.node_sound_metal_defaults() sounds = default.node_sound_metal_defaults()
@ -943,7 +947,8 @@ minetest.register_abm({
interval = 3, interval = 3,
chance = 1, chance = 1,
action = function(pos, node) action = function(pos, node)
local ventilation = minetest.find_node_near(pos, 1, {"stm_nodes:chimney", "stm_nodes:chimney2", "stm_nodes:big_vent"}) local ventilation = minetest.find_node_near(pos, 1,
{"stm_nodes:chimney", "stm_nodes:chimney2", "stm_nodes:big_vent"})
local fuel = minetest.find_node_near(pos, 1, {"stm_nodes:coal_feed"}) local fuel = minetest.find_node_near(pos, 1, {"stm_nodes:coal_feed"})
if ventilation and fuel and check_for_coal(fuel) then if ventilation and fuel and check_for_coal(fuel) then
minetest.set_node(pos, {name="stm_nodes:furnace_active", param2=node.param2}) minetest.set_node(pos, {name="stm_nodes:furnace_active", param2=node.param2})
@ -974,14 +979,17 @@ minetest.register_abm({
chance = 1, chance = 1,
action = function(pos, node) action = function(pos, node)
local ventilation = minetest.find_node_near(pos, 1, {"stm_nodes:chimney", "stm_nodes:chimney2", "stm_nodes:big_vent"}) local ventilation = minetest.find_node_near(pos, 1, {"stm_nodes:chimney", "stm_nodes:chimney2", "stm_nodes:big_vent"})
local base = minetest.find_node_near({x=pos.x, y=pos.y-1, z=pos.z}, 1, {"stm_nodes:machinery_base", "stm_nodes:stand", "stm_nodes:stand2", "default:steelblock", "default:bronzeblock"}) local base = minetest.find_node_near({x=pos.x, y=pos.y-1, z=pos.z}, 1, {
"stm_nodes:machinery_base", "stm_nodes:stand", "stm_nodes:stand2",
"default:steelblock", "default:bronzeblock"
})
local fuel = minetest.find_node_near(pos, 1, {"stm_nodes:coal_feed"}) local fuel = minetest.find_node_near(pos, 1, {"stm_nodes:coal_feed"})
if ventilation then if ventilation then
minetest.add_particlespawner({ minetest.add_particlespawner({
amount = 4, amount = 4,
time = 2, time = 2,
minpos = {x=ventilation.x-0.1, y=ventilation.y+0.8, z=ventilation.z-0.1}, minpos = vector.add(ventilation, {x=-0.1, y=0.8, z=-0.1}),
maxpos = {x=ventilation.x+0.1, y=ventilation.y+1, z=ventilation.z+0.1}, maxpos = vector.add(ventilation, {x=0.1, y=1, z=0.1}),
minvel = {x=-0.2, y=1, z=-0.2}, minvel = {x=-0.2, y=1, z=-0.2},
maxvel = {x=0.2, y=3, z=0.2}, maxvel = {x=0.2, y=3, z=0.2},
minacc = {x=0, y=0.1, z=0}, minacc = {x=0, y=0.1, z=0},
@ -996,7 +1004,8 @@ minetest.register_abm({
}) })
end end
if not base or not ventilation then if not base or not ventilation then
tnt.boom(pos, {damage_radius=3,radius=2,ignore_protection=false, disable_playerdamage=false}) tnt.boom(pos, {damage_radius = 3, radius = 2,
ignore_protection = false, disable_playerdamage = false})
end end
if not ventilation or not fuel or not check_for_coal(fuel) then if not ventilation or not fuel or not check_for_coal(fuel) then
minetest.set_node(pos, {name="stm_nodes:furnace", param2=node.param2}) minetest.set_node(pos, {name="stm_nodes:furnace", param2=node.param2})
@ -1095,9 +1104,7 @@ minetest.register_node("stm_nodes:boiler_output", {
minetest.register_node("stm_nodes:plate", { minetest.register_node("stm_nodes:plate", {
description = "Metal Plate", description = "Metal Plate",
tiles = { tiles = {"stm_nodes_plate.png"},
"stm_nodes_plate.png",
},
drawtype = "nodebox", drawtype = "nodebox",
paramtype = "light", paramtype = "light",
paramtype2 = "facedir", paramtype2 = "facedir",
@ -1256,16 +1263,15 @@ minetest.register_node("stm_nodes:bulb", {
}, },
sounds = default.node_sound_glass_defaults(), sounds = default.node_sound_glass_defaults(),
on_rightclick = function(pos, node) on_rightclick = function(pos, node)
if minetest.find_node_near(pos, 1, {"stm_nodes:cable_active", "stm_nodes:cable_ceiling_active"}) ~= nil then if minetest.find_node_near(pos, 1,
{"stm_nodes:cable_active", "stm_nodes:cable_ceiling_active"}) then
minetest.set_node(pos, {name="stm_nodes:bulb_active", param2=node.param2}) minetest.set_node(pos, {name="stm_nodes:bulb_active", param2=node.param2})
end end
end, end,
}) })
minetest.register_node("stm_nodes:bulb_active", { minetest.register_node("stm_nodes:bulb_active", {
tiles = { tiles = {"stm_nodes_bulb_active.png"},
"stm_nodes_bulb_active.png",
},
drawtype = "plantlike", drawtype = "plantlike",
paramtype = "light", paramtype = "light",
light_source = 8, light_source = 8,
@ -1312,5 +1318,5 @@ minetest.register_node("stm_nodes:conveyor", {
{-0.5, -0.5, -0.125, 0.5, -0.25, 0.125}, -- NodeBox4 {-0.5, -0.5, -0.125, 0.5, -0.25, 0.125}, -- NodeBox4
} }
}, },
groups = {cracky=1,} groups = {cracky=1}
}) })