gates overheat

This commit is contained in:
Kyle 2012-09-01 16:10:23 -07:00
parent b44f443fb2
commit efd06143b1

@ -21,10 +21,12 @@ for g in ipairs(gates) do gate = gates[g]
onoff = "on" onoff = "on"
groups = {dig_immediate=2, not_in_creative_inventory=1, mesecon = 3} groups = {dig_immediate=2, not_in_creative_inventory=1, mesecon = 3}
drop = "mesecons_gates:"..gate.."_off" drop = "mesecons_gates:"..gate.."_off"
description = "You hacker you!"
else else
onoff = "off" onoff = "off"
groups = {dig_immediate=2, mesecon = 3} groups = {dig_immediate=2, mesecon = 3}
drop = nodename drop = nodename
description = gate.." Gate"
end end
nodename = "mesecons_gates:"..gate.."_"..onoff nodename = "mesecons_gates:"..gate.."_"..onoff
@ -35,7 +37,7 @@ for g in ipairs(gates) do gate = gates[g]
} }
minetest.register_node(nodename, { minetest.register_node(nodename, {
description = gate.." Gate", description = description,
paramtype = "light", paramtype = "light",
drawtype = "nodebox", drawtype = "nodebox",
tiles = { tiles = {
@ -47,6 +49,8 @@ for g in ipairs(gates) do gate = gates[g]
node_box = node_box, node_box = node_box,
walkable = true, walkable = true,
on_construct = function(pos) on_construct = function(pos)
local meta = minetest.env:get_meta(pos)
meta:set_int("heat", 0)
update_gate(pos) update_gate(pos)
end, end,
groups = groups, groups = groups,
@ -69,28 +73,50 @@ end
function gate_state(pos) function gate_state(pos)
name = minetest.env:get_node(pos).name name = minetest.env:get_node(pos).name
if string.find(name, "off")~=nil then return string.find(name, "off") == nil
return false
else
return true
end end
function pop_gate(pos)
gate = get_gate(pos)
minetest.env:remove_node(pos)
minetest.after(0.2, yc_overheat_off, pos)
minetest.env:add_item(pos, "mesecons_gates:"..gate.."_off")
end end
function set_gate(pos, on) function set_gate(pos, on)
gate = get_gate(pos) gate = get_gate(pos)
local meta = minetest.env:get_meta(pos)
local rules = {{x=1, y=0, z=0}} local rules = {{x=1, y=0, z=0}}
if on then if on then
if not gate_state(pos) then if not gate_state(pos) then
yc_heat(meta)
minetest.after(0.5, yc_cool, meta)
if yc_overheat(meta) then
pop_gate(pos)
else
heat = meta:get_int("heat")
minetest.env:add_node(pos, {name="mesecons_gates:"..gate.."_on"}) minetest.env:add_node(pos, {name="mesecons_gates:"..gate.."_on"})
local meta2 = minetest.env:get_meta(pos)
meta2:set_int("heat", heat)
mesecon:receptor_on(pos, rules) mesecon:receptor_on(pos, rules)
end end
end
else else
if gate_state(pos) then if gate_state(pos) then
yc_heat(meta)
minetest.after(0.5, yc_cool, meta)
if yc_overheat(meta) then
pop_gate(pos)
else
heat = meta:get_int("heat")
minetest.env:add_node(pos, {name="mesecons_gates:"..gate.."_off"}) minetest.env:add_node(pos, {name="mesecons_gates:"..gate.."_off"})
local meta2 = minetest.env:get_meta(pos)
meta2:set_int("heat", heat)
mesecon:receptor_off(pos, rules) mesecon:receptor_off(pos, rules)
end end
end end
end end
end
function update_gate(pos) function update_gate(pos)
gate = get_gate(pos) gate = get_gate(pos)