Add files via upload
parent
b0367a0886
commit
2dccd49f8a
32
api.lua
32
api.lua
|
@ -60,17 +60,37 @@ was.compiler=function(input_text,def)
|
|||
|
||||
if def.type=="node" then
|
||||
local meta=minetest.get_meta(def.pos)
|
||||
local t=meta:get_int("was.compiler_last_run")
|
||||
local runs=meta:get_int("was.compiler_runs")
|
||||
local sec=was.time("sec",t)
|
||||
local t=meta:get_int("last_run")
|
||||
local runs=meta:get_int("runs")
|
||||
local sec=was.time("sec",os.time())
|
||||
|
||||
if sec<1 then
|
||||
meta:set_int("was.compiler_runs",runs+1)
|
||||
meta:set_int("runs",runs+1)
|
||||
if runs>10 then
|
||||
return
|
||||
end
|
||||
elseif sec>1 then
|
||||
meta:set_int("was.compiler_runs",1)
|
||||
meta:set_int("was.compiler_last_run", was.time("gettime"))
|
||||
meta:set_int("runs",1)
|
||||
meta:set_int("last_run", was.time("gettime"))
|
||||
end
|
||||
|
||||
local intensity=meta:get_int("intensity")+1
|
||||
local last_intensity_check=meta:get_int("last_intensity_check")
|
||||
meta:set_int("intensity",intensity)
|
||||
|
||||
if was.time("min",last_intensity_check)>1 then
|
||||
meta:set_int("last_intensity_check",os.time())
|
||||
meta:set_int("intensity",0)
|
||||
if intensity>120 then
|
||||
if minetest.get_node(def.pos).name=="was:computer" then
|
||||
if was.user[def.user] and was.user[def.user].gui then
|
||||
minetest.close_formspec(def.user,"gui")
|
||||
was.user[def.user]=nil
|
||||
end
|
||||
minetest.swap_node(def.pos,{name="was:computer_closed"})
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
19
craft.lua
19
craft.lua
|
@ -17,6 +17,25 @@ minetest.register_craft({
|
|||
}
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = "was:sender",
|
||||
recipe = {
|
||||
{"was:plastic_piece","was:plastic_piece",""},
|
||||
{"was:plastic_piece","default:mese_crystal",""},
|
||||
{"was:plastic_piece","was:wire",""},
|
||||
}
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = "was:receiver",
|
||||
recipe = {
|
||||
{"was:plastic_piece","was:wire",""},
|
||||
{"was:plastic_piece","default:mese_crystal",""},
|
||||
{"was:plastic_piece","was:plastic_piece",""},
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
minetest.register_craft({
|
||||
output = "was:computer",
|
||||
recipe = {
|
||||
|
|
|
@ -1,14 +1,16 @@
|
|||
was.time=function(a,c)
|
||||
if a=="gettime" then
|
||||
return os.time()
|
||||
elseif a=="sec" and was.is_number(c) then
|
||||
return os.difftime(os.time(), c)
|
||||
elseif a=="min" and was.is_number(c) then
|
||||
return os.difftime(os.time(), c) / 60
|
||||
elseif a=="hour" and was.is_number(c) then
|
||||
return os.difftime(os.time(), c) / (60 * 60)
|
||||
elseif a=="day" and was.is_number(c) then
|
||||
return os.difftime(os.time(), c) / (24 * 60 * 60)
|
||||
else
|
||||
if a=="sec" then
|
||||
return os.difftime(os.time(), c)
|
||||
elseif a=="min" then
|
||||
return os.difftime(os.time(), c) / 60
|
||||
elseif a=="hour" then
|
||||
return os.difftime(os.time(), c) / (60 * 60)
|
||||
elseif a=="day" then
|
||||
return os.difftime(os.time(), c) / (24 * 60 * 60)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -35,6 +37,17 @@ end
|
|||
was.send=function(pos,channel,msg,from_channel)
|
||||
local na=pos.x .."." .. pos.y .."." ..pos.z
|
||||
if not was.wire_signals[na] then
|
||||
local t=os.time()
|
||||
if os.difftime(t, was.wire_sends.last)>1 then
|
||||
was.wire_sends.last=t
|
||||
was.wire_sends.times=0
|
||||
else
|
||||
was.wire_sends.times=was.wire_sends.times+1
|
||||
if was.wire_sends.times>50 then
|
||||
return
|
||||
end
|
||||
|
||||
end
|
||||
was.wire_signals[na]={jobs={[na]=pos},msg=msg,channel=channel,from_channel=from_channel}
|
||||
minetest.after(0, function()
|
||||
was.wire_leading()
|
||||
|
@ -67,7 +80,10 @@ was.wire_leading=function()
|
|||
if not a.jobs[s] and minetest.get_item_group(na,"was_wire")>0 then
|
||||
a.jobs[s]=n
|
||||
c=c+1
|
||||
minetest.set_node(n,{name="was:wire",param2=3})
|
||||
if minetest.registered_nodes[na].on_waswire then
|
||||
minetest.registered_nodes[na].on_waswire(n,a.channel,a.from_channel,a.msg)
|
||||
end
|
||||
minetest.swap_node(n,{name=na,param2=3})
|
||||
minetest.get_node_timer(n):start(0.1)
|
||||
elseif not a.jobs[s] and minetest.get_item_group(na,"was_unit")>0 and minetest.registered_nodes[na].on_waswire then
|
||||
minetest.registered_nodes[na].on_waswire(n,a.channel,a.from_channel,a.msg)
|
||||
|
|
2
gui.lua
2
gui.lua
|
@ -76,6 +76,8 @@ minetest.register_on_player_receive_fields(function(user, form, pressed)
|
|||
was.user[name].text=nil
|
||||
was.user[name].funcs=nil
|
||||
was.user[name].channel=nil
|
||||
was.user[name].id=nil
|
||||
was.user[name].gui=nil
|
||||
end
|
||||
return
|
||||
end
|
||||
|
|
1
init.lua
1
init.lua
|
@ -10,6 +10,7 @@ was={
|
|||
wire_signals={},
|
||||
symbols_characters=".#@=?!&{}%*+-/$<>|~^",
|
||||
wire_rules={{0,0,0},{-1,0,0},{1,0,0},{0,0,-1},{0,0,1},{0,-1,0},{0,1,0}},
|
||||
wire_sends={last=os.time(),times=0},
|
||||
}
|
||||
|
||||
dofile(minetest.get_modpath("was") .. "/api.lua")
|
||||
|
|
97
items.lua
97
items.lua
|
@ -40,6 +40,7 @@ minetest.register_node("was:computer", {
|
|||
meta:set_string("owner",placer:get_player_name() or "")
|
||||
meta:get_inventory():set_size("storage", 50)
|
||||
meta:set_string("channel", pos.x .." " ..pos.y .." " ..pos.z)
|
||||
meta:set_string("last_intensity_check",os.time())
|
||||
minetest.swap_node(pos,{name="was:computer_closed",param2=minetest.get_node(pos).param2})
|
||||
end,
|
||||
on_rightclick = function(pos, node, player, itemstack, pointed_thing)
|
||||
|
@ -57,6 +58,7 @@ minetest.register_node("was:computer", {
|
|||
text=minetest.deserialize(meta:get_string("text")),
|
||||
id=pos.x .." " .. pos.y .." " ..pos.z,
|
||||
punchpos=punchpos,
|
||||
gui=true,
|
||||
}
|
||||
was.gui(name)
|
||||
end
|
||||
|
@ -74,7 +76,8 @@ minetest.register_node("was:computer", {
|
|||
type="node",
|
||||
user=meta:get_string("owner"),
|
||||
pos=pos,
|
||||
event={type="timer"}
|
||||
event={type="timer"},
|
||||
print=true,
|
||||
})
|
||||
return true
|
||||
end,
|
||||
|
@ -86,7 +89,8 @@ minetest.register_node("was:computer", {
|
|||
type="node",
|
||||
user=user,
|
||||
pos=pos,
|
||||
event={type="wire",channel=channel,from_channel=from_channel,msg=msg}
|
||||
event={type="wire",channel=channel,from_channel=from_channel,msg=msg},
|
||||
print=true,
|
||||
})
|
||||
end
|
||||
end,
|
||||
|
@ -100,7 +104,8 @@ minetest.register_node("was:computer", {
|
|||
type="node",
|
||||
user=meta:get_string("owner"),
|
||||
pos=pos,
|
||||
event={type="mesecon on"}
|
||||
event={type="mesecon on"},
|
||||
print=true,
|
||||
})
|
||||
end,
|
||||
action_off = function (pos, node)
|
||||
|
@ -110,7 +115,8 @@ minetest.register_node("was:computer", {
|
|||
type="node",
|
||||
user=user,
|
||||
pos=pos,
|
||||
event={type="mesecon off"}
|
||||
event={type="mesecon off"},
|
||||
print=true,
|
||||
})
|
||||
end
|
||||
}
|
||||
|
@ -126,7 +132,8 @@ minetest.register_node("was:computer", {
|
|||
type="node",
|
||||
user=meta:get_string("owner"),
|
||||
pos=pos,
|
||||
event={type="digiline",channel=channel,msg=msg}
|
||||
event={type="digiline",channel=channel,msg=msg},
|
||||
print=true,
|
||||
})
|
||||
end
|
||||
end,
|
||||
|
@ -143,7 +150,8 @@ minetest.register_node("was:computer", {
|
|||
type="node",
|
||||
user=user,
|
||||
pos=pos,
|
||||
event={type="pipeworks",msg={item=n,count=c}}
|
||||
event={type="pipeworks",msg={item=n,count=c}},
|
||||
print=true,
|
||||
})
|
||||
end, text,user,pos,n,c)
|
||||
return meta:get_inventory():add_item("storage", stack)
|
||||
|
@ -273,17 +281,24 @@ minetest.register_node("was:router", {
|
|||
paramtype = "light",
|
||||
paramtype2="facedir",
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
--type = "fixed",
|
||||
type = "connected",
|
||||
connect_back={-0.05,-0.5,0, 0.05,-0.45,0.5},
|
||||
connect_front={-0.05,-0.5,-0.5, 0.05,-0.45,0},
|
||||
connect_left={-0.5,-0.5,-0.05, 0.05,-0.45,0.05},
|
||||
connect_right={0,-0.5,-0.05, 0.5,-0.45,0.05},
|
||||
connect_top = {-0.05, -0.5, -0.05, 0.05, 0.5, 0.05},
|
||||
fixed = {
|
||||
{-0.37, -0.5, -0.25, 0.37, -0.37, 0.25},
|
||||
{-0.37, -0.37, 0.18, -0.31, -0.125, 0.25},
|
||||
{0.31, -0.5, 0.18, 0.37, -0.12, 0.25}
|
||||
}
|
||||
},
|
||||
connects_to={"group:was_wire","group:was_unit"},
|
||||
groups = {oddly_breakable_by_hand = 3,was_unit=1},
|
||||
on_waswire=function(pos,channel,from_channel,msg)
|
||||
for _,p in pairs(minetest.find_nodes_in_area(vector.add(pos,10),vector.subtract(pos,10),"group:was_unit")) do
|
||||
if not vector.equals(pos,p) then
|
||||
if was.get_node(p)~="was:router" then
|
||||
was.send(p,channel,msg,from_channel)
|
||||
end
|
||||
end
|
||||
|
@ -291,4 +306,70 @@ minetest.register_node("was:router", {
|
|||
on_timer = function (pos, elapsed)
|
||||
minetest.swap_node(pos,{name="was:wire",param2=135})
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_node("was:sender", {
|
||||
description = "Wireless sender",
|
||||
tiles = {{name="was_wire.png"}},
|
||||
drop="was:sender",
|
||||
drawtype="nodebox",
|
||||
paramtype = "light",
|
||||
palette="was_palette.png",
|
||||
paramtype2="colorwallmounted",
|
||||
node_box = {
|
||||
type = "connected",
|
||||
connect_back={-0.05,-0.5,0, 0.05,-0.45,0.5},
|
||||
connect_front={-0.05,-0.5,-0.5, 0.05,-0.45,0},
|
||||
connect_left={-0.5,-0.5,-0.05, 0.05,-0.45,0.05},
|
||||
connect_right={0,-0.5,-0.05, 0.5,-0.45,0.05},
|
||||
connect_top = {-0.05, -0.5, -0.05, 0.05, 0.5, 0.05},
|
||||
fixed = {
|
||||
{-0.25, -0.5, -0.25, 0.25, -0.3, 0.25},
|
||||
}
|
||||
},
|
||||
connects_to={"group:was_wire","group:was_unit"},
|
||||
groups = {oddly_breakable_by_hand = 3,was_wire=1},
|
||||
on_waswire=function(pos,channel,from_channel,msg)
|
||||
for _,p in pairs(minetest.find_nodes_in_area(vector.add(pos,10),vector.subtract(pos,10),"was:receiver")) do
|
||||
was.send(p,channel,msg,from_channel)
|
||||
minetest.swap_node(p,{name="was:receiver",param2=3})
|
||||
minetest.get_node_timer(p):start(0.1)
|
||||
end
|
||||
end,
|
||||
on_timer = function (pos, elapsed)
|
||||
minetest.swap_node(pos,{name="was:sender",param2=135})
|
||||
end,
|
||||
after_place_node = function(pos, placer)
|
||||
minetest.set_node(pos,{name="was:sender",param2=135})
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_node("was:receiver", {
|
||||
description = "Wireless receiver",
|
||||
tiles = {{name="was_wire.png"}},
|
||||
drawtype="nodebox",
|
||||
drop="was:receiver",
|
||||
paramtype = "light",
|
||||
palette="was_palette.png",
|
||||
paramtype2="colorwallmounted",
|
||||
node_box = {
|
||||
type = "connected",
|
||||
connect_back={-0.05,-0.5,0, 0.05,-0.45,0.5},
|
||||
connect_front={-0.05,-0.5,-0.5, 0.05,-0.45,0},
|
||||
connect_left={-0.5,-0.5,-0.05, 0.05,-0.45,0.05},
|
||||
connect_right={0,-0.5,-0.05, 0.5,-0.45,0.05},
|
||||
connect_top = {-0.05, -0.5, -0.05, 0.05, 0.5, 0.05},
|
||||
fixed = {
|
||||
{-0.25, -0.5, -0.25, 0.25, -0.3, 0.25},
|
||||
{-0.02, -0.3, -0.02, 0.02, -0.1, 0.02},
|
||||
}
|
||||
},
|
||||
connects_to={"group:was_wire","group:was_unit"},
|
||||
groups = {oddly_breakable_by_hand = 3,was_wire=1},
|
||||
on_timer = function (pos, elapsed)
|
||||
minetest.swap_node(pos,{name="was:receiver",param2=135})
|
||||
end,
|
||||
after_place_node = function(pos, placer)
|
||||
minetest.set_node(pos,{name="was:sender",param2=135})
|
||||
end,
|
||||
})
|
25
register.lua
25
register.lua
|
@ -129,6 +129,7 @@ was.register_function("math.pi",{
|
|||
end
|
||||
})
|
||||
|
||||
|
||||
was.register_function("math",{
|
||||
info="Math + - * ^ / ('-' 1 2 67...)",
|
||||
packed=true,
|
||||
|
@ -723,7 +724,19 @@ was.register_function("print",{
|
|||
if was.is_string(v) or was.is_number(v) then
|
||||
s=s .. v .. " "
|
||||
elseif was.is_table(v) then
|
||||
s=s .. "table "
|
||||
local t=""
|
||||
for ind,val in pairs(v) do
|
||||
t=t .. ind .."="
|
||||
if was.is_number(val) then
|
||||
t=t .. val .." "
|
||||
elseif was.is_string(val) then
|
||||
t=t .. '"' .. val ..'" '
|
||||
else
|
||||
t=t .. "table "
|
||||
end
|
||||
end
|
||||
|
||||
s=s .. t
|
||||
elseif type(v)=="boolean" then
|
||||
if v==true then
|
||||
s=s .."true "
|
||||
|
@ -748,6 +761,7 @@ was.register_function("print",{
|
|||
ud.console_text=ud.console_text:sub(ud.console_text:find("\n")+1,ud.console_text:len())
|
||||
ud.console_lines=27
|
||||
end
|
||||
was.gui(was.userdata.name)
|
||||
elseif minetest.check_player_privs(was.userdata.name,{server=true}) then
|
||||
print(unpack(a))
|
||||
end
|
||||
|
@ -770,6 +784,15 @@ was.register_function("get.pos",{
|
|||
end
|
||||
})
|
||||
|
||||
was.register_function("time",{
|
||||
info='Get/compare time ("type" time_number) type "gettime" to return currently time, or "sec","min","hour","day" to compare the time ',
|
||||
action=function(a,c)
|
||||
if was.is_string(a) and was.is_number(c) then
|
||||
return was.time(a,c)
|
||||
end
|
||||
end
|
||||
})
|
||||
|
||||
was.register_function("was.send",{
|
||||
info="Send data through wires (string_channel data)",
|
||||
action=function(channel,msg)
|
||||
|
|
Loading…
Reference in New Issue