mesecon emitter

This commit is contained in:
NatureFreshMilk 2019-09-30 15:34:56 +02:00
parent 032979a057
commit f5b2e516fe
5 changed files with 88 additions and 7 deletions

View File

@ -14,6 +14,7 @@ read_globals = {
"dump", "VoxelArea",
-- deps
"screwdriver"
"screwdriver",
"mesecon"
}

74
blocks/mesecon_emit.lua Normal file
View File

@ -0,0 +1,74 @@
local update_formspec = function(meta, pos)
local delay = meta:get_int("delay")
meta:set_string("infotext", "Mesecons emit block: " .. delay .. " seconds")
meta:set_string("formspec", "size[8,2;]" ..
-- col 1
"field[0.2,0.5;8,1;delay;Delay (seconds);" .. delay .. "]" ..
-- col 2
"button_exit[0.1,1.5;8,1;save;Save]" ..
"")
end
minetest.register_node("epic:delay", {
description = "Epic delay block",
tiles = {
"epic_node_bg.png",
"epic_node_bg.png",
"epic_node_bg.png",
"epic_node_bg.png",
"epic_node_bg.png",
"epic_node_bg.png",
},
paramtype2 = "facedir",
groups = {cracky=3,oddly_breakable_by_hand=3,epic=1,mesecon_needs_receiver=1},
on_rotate = screwdriver.rotate_simple,
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_int("delay", 1)
update_formspec(meta, pos)
end,
on_receive_fields = function(pos, formname, fields, sender)
local meta = minetest.get_meta(pos);
if not sender or minetest.is_protected(pos, sender:get_player_name()) then
-- not allowed
return
end
if fields.save then
local delay = tonumber(fields.delay) or 1
if delay < 0 then
delay = 1
end
meta:set_int("delay", delay)
update_formspec(meta, pos)
end
end,
epic = {
on_enter = function(pos, meta, player, ctx)
ctx.data.delay_start = minetest.get_us_time()
mesecon.receptor_on(pos)
end,
on_check = function(pos, meta, player, ctx)
local now = minetest.get_us_time()
local start = ctx.data.delay_start
local delay_micros = meta:get_int("delay")*1000*1000
local diff = now - start
if diff > delay_micros then
ctx.next()
end
end
on_exit = function(pos)
mesecon.receptor_off(pos)
end
}
})

View File

@ -21,3 +21,7 @@ dofile(MP.."/blocks/branch.lua")
if minetest.get_modpath("mobs") then
dofile(MP.."/blocks/spawn_mob.lua")
end
if minetest.get_modpath("mesecons") then
dofile(MP.."/blocks/mesecons_emit.lua")
end

View File

@ -1,4 +1,4 @@
name = epic
description = Enhanced Programmer for Ingame Control
depends = screwdriver,default
optional_depends = mobs
optional_depends = mobs,mesecons

View File

@ -10,19 +10,21 @@ WIP
### MVP
* [x] Chat-message
* [x] Delay
* [x] Delay (conditional)
* [x] No-Op
* [x] Waypoint
* [x] Waypoint (conditional)
* [x] Teleport
* [x] Mob
* [x] Command
* [x] Branch-multiple
* [ ] Call function
* [x] Call function
* [x] Mesecon emitter
* [ ] Epic: main-function
* [ ] Epic: timeout-function
### TODO
* [ ] Mesecon receiver (conditional)
* [ ] Place node
* [ ] Remove node
* [ ] Add item
@ -31,13 +33,13 @@ WIP
* [ ] Stash inventory
* [ ] Unstash inventory
* [ ] HUD vignette
* [ ] Check priv
* [ ] Check priv (conditional)
* [ ] Set gravity
* [ ] Set skybox
* [ ] Collision box
* [ ] Formspec message
* [ ] Set counter (dig, place, kill)
* [ ] Check counter
* [ ] Check counter (conditional)
# Licenses