Skip to content

Commit 682cf34

Browse files
committedMay 16, 2013
Add burnt luacontroller (so you don't lose your program after an overheat) and prevent interrupts from piling up (fixes #101, metadata trashing). Idea for burnt luacontroller comes from ShadowNinja.
1 parent 6f83f4c commit 682cf34

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed
 

‎mesecons_luacontroller/init.lua

+44-4
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,17 @@ local getinterrupt = function(pos)
149149
local iid = iid or math.random()
150150
local meta = minetest.env:get_meta(pos)
151151
local interrupts = minetest.deserialize(meta:get_string("lc_interrupts")) or {}
152-
table.insert (interrupts, iid)
153-
meta:set_string("lc_interrupts", minetest.serialize(interrupts))
152+
local found = false
153+
for _, i in ipairs(interrupts) do
154+
if minetest.serialize(i) == minetest.serialize(event.iid) then
155+
found = true
156+
break
157+
end
158+
end
159+
if not found then
160+
table.insert(interrupts, iid)
161+
meta:set_string("lc_interrupts", minetest.serialize(interrupts))
162+
end
154163
minetest.after(time, interrupt, {pos=pos, iid = iid})
155164
end
156165
return interrupt
@@ -251,9 +260,9 @@ local do_overheat = function (pos, meta)
251260
heat(meta)
252261
minetest.after(0.5, cool, meta)
253262
if overheat(meta) then
254-
minetest.env:remove_node(pos)
263+
mesecon:swap_node(pos, BASENAME.."_burnt")
264+
minetest.env:get_meta(pos):set_string("lc_interrupts", "")
255265
minetest.after(0.2, overheat_off, pos) -- wait for pending operations
256-
minetest.env:add_item(pos, BASENAME.."0000")
257266
return true
258267
end
259268
end
@@ -479,6 +488,37 @@ end
479488
end
480489
end
481490

491+
--overheated luacontroller
492+
minetest.register_node(BASENAME .. "_burnt", {
493+
drawtype = "nodebox",
494+
tiles = {
495+
"jeija_luacontroller_burnt_top.png",
496+
"jeija_microcontroller_bottom.png",
497+
"jeija_microcontroller_sides.png",
498+
"jeija_microcontroller_sides.png",
499+
"jeija_microcontroller_sides.png",
500+
"jeija_microcontroller_sides.png"
501+
},
502+
inventory_image = "jeija_luacontroller_burnt_top.png",
503+
paramtype = "light",
504+
groups = {dig_immediate=2, not_in_creative_inventory=1},
505+
drop = BASENAME.."0000",
506+
sunlight_propagates = true,
507+
selection_box = selectionbox,
508+
node_box = nodebox,
509+
on_construct = reset_meta,
510+
on_receive_fields = function(pos, formname, fields)
511+
reset(pos)
512+
reset_meta(pos, fields.code)
513+
local err = lc_update(pos, {type="program"})
514+
if err then print(err) end
515+
reset_meta(pos, fields.code, err)
516+
end,
517+
sounds = default.node_sound_stone_defaults(),
518+
is_luacontroller = true,
519+
virtual_portstates = {a = false, b = false, c = false, d = false},
520+
})
521+
482522
------------------------
483523
-- Craft Registration --
484524
------------------------
Loading

0 commit comments

Comments
 (0)
Please sign in to comment.