was/init.lua

279 lines
8.2 KiB
Lua
Raw Normal View History

2019-01-03 13:57:48 -08:00
was={
functions={},
2019-01-09 05:58:12 -08:00
function_list={},
2019-01-04 02:32:59 -08:00
function_packed={},
2019-01-09 00:29:35 -08:00
info={},
2019-01-03 13:57:48 -08:00
privs={},
user={},
userdata={},
2019-01-09 00:29:35 -08:00
symbols={},
2019-01-12 01:35:39 -08:00
wire_signals={},
symbols_characters=".#@=?!&{}%*+-/$<>|~^",
2019-01-03 13:57:48 -08:00
}
dofile(minetest.get_modpath("was") .. "/api.lua")
2019-01-04 02:32:59 -08:00
dofile(minetest.get_modpath("was") .. "/register.lua")
2019-01-08 13:56:48 -08:00
dofile(minetest.get_modpath("was") .. "/gui.lua")
2019-01-07 13:06:01 -08:00
--minetest.register_chatcommand("was", {
-- description = "World action script gui",
-- func = function(name, param)
-- was.gui(name)
-- return true
-- end,
--})
2019-01-03 13:57:48 -08:00
2019-01-08 13:56:48 -08:00
minetest.register_privilege("was", {
description = "Full access to functions",
give_to_singleplayer= false,
})
2019-01-12 01:35:39 -08:00
was.get_node=function(pos)
local n=minetest.get_node(pos).name
if n=="ignore" then
local vox=minetest.get_voxel_manip()
local min, max=vox:read_from_map(pos, pos)
local area=VoxelArea:new({MinEdge = min, MaxEdge = max})
local data=vox:get_data()
local i=area:indexp(pos)
n=minetest.get_name_from_content_id(data[i])
end
return n
end
was.wire_leading=function()
local counts=0
local po={{0,0,0},{-1,0,0},{1,0,0},{0,0,-1},{0,0,1},{0,-1,0},{0,1,0}}
for i, a in pairs(was.wire_signals) do
local c=0
for xyz, pos in pairs(a.jobs) do
for ii, p in pairs(po) do
local n={x=pos.x+p[1],y=pos.y+p[2],z=pos.z+p[3]}
local s=n.x .. "." .. n.y .."." ..n.z
local na=was.get_node(n)
if not a.jobs[s] and minetest.get_item_group(na,"was_wire")>0 then
a.jobs[s]=n
c=c+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)
a.jobs[s]=n
c=c+1
end
end
end
if c==0 then
was.wire_signals[i]=nil
else
counts=counts+c
end
end
if counts>0 then
minetest.after(0, function()
was.wire_leading()
end)
else
was.wire_signals={}
end
end
minetest.register_node("was:wire", {
description = "was wire",
2019-01-09 12:16:30 -08:00
tiles = {
2019-01-12 01:35:39 -08:00
"was_guibg.png^[colorize:#FFFFFF",
2019-01-09 12:16:30 -08:00
},
drawtype="nodebox",
paramtype = "light",
2019-01-12 01:35:39 -08:00
sunlight_propagates=true,
walkable=false,
2019-01-09 12:16:30 -08:00
node_box = {
2019-01-12 01:35:39 -08:00
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.05, -0.5, -0.05, 0.05, -0.45, 0.05},
2019-01-09 12:16:30 -08:00
},
2019-01-12 01:35:39 -08:00
connects_to={"group:was_wire","group:was_unit"},
groups = {dig_immediate = 3,was_wire=1},
on_construct = function(pos)
if minetest.get_item_group(minetest.get_node({x=pos.x,y=pos.y+1,z=pos.z}).name,"was_wire")>0 then
-- minetest.swap_node(pos,{name="was:wire_up"})
elseif minetest.get_item_group(minetest.get_node({x=pos.x,y=pos.y-1,z=pos.z}).name,"was_wire")>0 then
-- minetest.swap_node(pos,{name="was:wire_down"})
2019-01-09 12:16:30 -08:00
end
end,
2019-01-12 01:35:39 -08:00
on_destruct = function(pos)
--minetest.check_for_falling(pos)
end
2019-01-09 12:16:30 -08:00
})
2019-01-04 11:47:35 -08:00
minetest.register_node("was:computer", {
description = "Computer",
2019-01-09 12:16:30 -08:00
tiles = {
"was_pc_board.png",
"was_pc_outside.png",
"was_pc_screen.png",
"was_pc_outside.png",
"was_pc_outside.png",
"was_pc_screen.png",
},
drawtype="nodebox",
paramtype = "light",
paramtype2="facedir",
node_box = {
type = "fixed",
fixed = {
{-0.5, -0.5, -0.3, 0.5, -0.43, 0.5},
{-0.5, -0.5, 0.48, 0.5, 0.3, 0.5},
}
},
2019-01-12 01:35:39 -08:00
groups = {oddly_breakable_by_hand = 3,was_unit=1,tubedevice = 1, tubedevice_receiver = 1},
2019-01-09 12:16:30 -08:00
on_punch = function(pos, node, player, pointed_thing)
2019-01-09 12:39:49 -08:00
minetest.swap_node(pos,{name="was:computer_closed",param2=node.param2})
2019-01-09 12:16:30 -08:00
end,
2019-01-04 11:47:35 -08:00
after_place_node = function(pos, placer)
local meta = minetest.get_meta(pos)
meta:set_string("owner",placer:get_player_name() or "")
2019-01-07 06:16:06 -08:00
meta:get_inventory():set_size("storage", 50)
2019-01-12 01:35:39 -08:00
meta:set_string("channel", pos.x .." " ..pos.y .." " ..pos.z)
2019-01-09 12:39:49 -08:00
minetest.swap_node(pos,{name="was:computer_closed",param2=minetest.get_node(pos).param2})
2019-01-04 11:47:35 -08:00
end,
on_rightclick = function(pos, node, player, itemstack, pointed_thing)
local meta=minetest.get_meta(pos)
local name=player:get_player_name() or ""
if meta:get_string("owner")==name or minetest.check_player_privs(name, {protection_bypass=true}) then
2019-01-04 15:30:48 -08:00
if meta:get_string("owner")=="" then
return
end
2019-01-09 12:39:49 -08:00
minetest.swap_node(pos,{name="was:computer",param2=node.param2})
2019-01-12 01:35:39 -08:00
was.user[name]={
nodepos=pos,
channel=meta:get_string("channel"),
text=minetest.deserialize(meta:get_string("text")),
id=pos.x .." " .. pos.y .." " ..pos.z,
}
2019-01-09 12:16:30 -08:00
was.gui(name)
2019-01-04 11:47:35 -08:00
end
end,
can_dig = function(pos, player)
local meta=minetest.get_meta(pos)
local name=player:get_player_name() or ""
2019-01-07 06:16:06 -08:00
if meta:get_inventory():is_empty("storage") and (meta:get_string("owner")==name or minetest.check_player_privs(name, {protection_bypass=true})) then
2019-01-04 11:47:35 -08:00
return true
end
end,
2019-01-12 01:35:39 -08:00
on_timer = function (pos, elapsed)
local meta=minetest.get_meta(pos)
was.compiler(minetest.deserialize(meta:get_string("text")),{
user=meta:get_string("owner"),
pos=pos,
event={type="timer"}
})
return true
end,
on_waswire=function(pos,channel,from_channel,msg)
local meta=minetest.get_meta(pos)
local user=meta:get_string("owner")
if user~="" and channel==meta:get_string("channel") then
was.compiler(minetest.deserialize(meta:get_string("text")),{
user=user,
pos=pos,
event={type="wire",channel=channel,from_channel=from_channel,msg=msg}
})
end
end,
mesecons = {
receptor = {state = "off"},
effector = {
action_on = function (pos, node)
local meta=minetest.get_meta(pos)
local user=meta:get_string("owner")
was.compiler(minetest.deserialize(meta:get_string("text")),{
user=meta:get_string("owner"),
pos=pos,
event={type="mesecon on"}
})
end,
action_off = function (pos, node)
local meta=minetest.get_meta(pos)
local user=meta:get_string("owner")
was.compiler(minetest.deserialize(meta:get_string("text")),{
user=user,
pos=pos,
event={type="mesecon off"}
})
end
}
},
digiline = {
receptor={},
effector = {
action = function (pos,node,channel,msg)
local meta=minetest.get_meta(pos)
if meta:get_string("channel")==channel then
local user=meta:get_string("owner")
was.compiler(minetest.deserialize(meta:get_string("text")),{
user=meta:get_string("owner"),
pos=pos,
event={type="digiline",channel=channel,msg=msg}
})
end
end,
}
},
tube = {insert_object = function(pos, node, stack, direction)
local meta = minetest.get_meta(pos)
local user=meta:get_string("owner")
local text=minetest.deserialize(meta:get_string("text"))
local n=stack:get_name()
local c=stack:get_count()
minetest.after(0, function(text,user,pos,n,c)
was.compiler(text,{
user=user,
pos=pos,
event={type="pipeworks",msg={item=n,count=c}}
})
end, text,user,pos,n,c)
return meta:get_inventory():add_item("storage", stack)
end,
can_insert = function(pos, node, stack, direction)
return minetest.get_meta(pos):get_inventory():room_for_item("storage", stack)
end,
input_inventory = "storage",
connect_sides = {left=0,right=0,front=0,top=0,back=1,bottom=1}
},
})
minetest.register_node("was:computer_closed", {
description = "Computer",
drop="was:computer",
tiles = {
"was_pc_outside.png",
},
drawtype="nodebox",
paramtype = "light",
paramtype2="facedir",
node_box = {
type = "fixed",
fixed = {
{-0.5, -0.5, -0.3, 0.5, -0.43, 0.5},
}
},
groups = {oddly_breakable_by_hand = 3,was_unit=1,not_in_creative_inventory=1},
on_punch = function(pos, node, player, pointed_thing)
local name=player:get_player_name() or ""
if minetest.get_meta(pos):get_string("owner")==name or minetest.check_player_privs(name, {protection_bypass=true}) then
minetest.swap_node(pos,{name="was:computer",param2=node.param2})
end
end,
on_rightclick = function(pos, node, player, itemstack, pointed_thing)
minetest.registered_nodes["was:computer"].on_rightclick(pos, node, player, itemstack, pointed_thing)
end,
can_dig = function(pos, player)
return minetest.registered_nodes["was:computer"].can_dig(pos, player)
end,
2019-01-08 13:56:48 -08:00
})