No idea.
This commit is contained in:
parent
c82a868de0
commit
2017eb52b2
85
init.lua
85
init.lua
@ -1,7 +1,61 @@
|
||||
local statedir = minetest.get_worldpath() .. '/' .. minetest.get_current_modname() .. "/"
|
||||
local oldprint=print
|
||||
local function print(...)
|
||||
for k,v in ipairs({...}) do
|
||||
oldprint("[Test3D] "..tostring(v))
|
||||
end
|
||||
end
|
||||
print("Test3D loading.")
|
||||
print("State directory: "..statedir)
|
||||
if not digiline then
|
||||
print("Digilines not found.")
|
||||
return
|
||||
end
|
||||
local function t21_digiline_receive(pos, node, channel, msg)
|
||||
print(pos,node,channel,msg)
|
||||
end
|
||||
print("Created T21 digiline function")
|
||||
|
||||
print("Loading/creating states")
|
||||
_G.test3d = {}
|
||||
_G.test3d.states={}
|
||||
-- states:
|
||||
--[[
|
||||
{
|
||||
mem = {4096 ints}
|
||||
nodes = int
|
||||
pc = int
|
||||
}
|
||||
]]--
|
||||
function _G.test3d.save()
|
||||
local f = io.open(statedir.."/states.txt","wb")
|
||||
for k,v in pairs(test3d.states) do
|
||||
f:write(tostring(k).."\n")
|
||||
local g=io.open(statedir.."/"..tostring(k))
|
||||
for l,m in ipairs(test3d.states[k]) do
|
||||
g:write(tostring(m).."\n")
|
||||
end
|
||||
g:close()
|
||||
end
|
||||
f:close()
|
||||
end
|
||||
_G.test3d.laststate=0
|
||||
_G.test3d.genstate = {}
|
||||
local statetab={}
|
||||
os.execute("mkdir "..statedir) -- just in case, 50/50 this kills minetest on some platforms
|
||||
local f=io.open(statedir.."/states.txt","rb")
|
||||
local statetab={}
|
||||
if f ~= nil then
|
||||
f:close()
|
||||
for l in io.lines(statedir.."/states.txt") do
|
||||
print("State: "..l)
|
||||
end
|
||||
end
|
||||
print("Creating T21 formspec")
|
||||
local function t21_set_meta(pos)
|
||||
minetest.get_meta(pos):set_string("formspec", "field[channel;Channel;${channel}]\nfield[statename;State;${statename}]")
|
||||
end
|
||||
minetest.register_on_shutdown(test3d.save)
|
||||
minetest.register_node("test3d:t21", {
|
||||
description = "T21 Execution Node",
|
||||
tiles = {
|
||||
@ -16,6 +70,7 @@ minetest.register_node("test3d:t21", {
|
||||
},
|
||||
},
|
||||
},
|
||||
on_construct = t21_set_meta,
|
||||
on_punch = function(pos, _, _, _)
|
||||
local meta=minetest.get_meta(pos)
|
||||
local cbeep = meta:get_int("test3d_running")
|
||||
@ -34,8 +89,17 @@ minetest.register_node("test3d:t21", {
|
||||
effector = {
|
||||
action = t21_digiline_receive
|
||||
}
|
||||
}
|
||||
},
|
||||
on_receive_fields = function(pos,_,fields,sender)
|
||||
local meta = minetest.get_meta(pos)
|
||||
_G.test3d.states[meta:get_string("statename")].nodes=_G.test3d.states[meta:get_string("statename")].nodes-1 -- decrement node counter
|
||||
meta:set_string("statename",fields.statename)
|
||||
meta:set_string("channel",fields.channel) -- channel the thing listens for commands on
|
||||
_G.test3d.states[meta:get_string("statename")].nodes=_G.test3d.states[meta:get_string("statename")].nodes+1 -- increment new node counter
|
||||
end
|
||||
})
|
||||
print("T21 node registered")
|
||||
|
||||
minetest.register_abm({
|
||||
nodenames={"test3d:t21"},
|
||||
interval=1,
|
||||
@ -46,12 +110,25 @@ minetest.register_abm({
|
||||
local beepState = meta:get_int("test3d_running")
|
||||
if beepState == nil then beepState=1 end
|
||||
-- print(beepState)
|
||||
if beepState == 1 then
|
||||
minetest.sound_play("default_break_glass",{
|
||||
if beepState == 1 and meta:get_string("statename") ~= nil and meta:get_string("statename") ~= "" then
|
||||
--[[ minetest.sound_play("default_break_glass",{
|
||||
pos=pos,
|
||||
max_hear_distance=100
|
||||
})
|
||||
]]--
|
||||
print("Running T21 node with instance "..tostring(meta:get_string("statename")).." at position "..tostring(pos.x)..","..tostring(pos.y)..","..tostring(pos.z))
|
||||
end
|
||||
end,
|
||||
})
|
||||
print("Test3D loaded.")
|
||||
print("T21 ABMs registered")
|
||||
|
||||
minetest.register_chatcommand("lua", { -- I'm a terrible person
|
||||
params = "<text>",
|
||||
description = "Execute some Lua code",
|
||||
privs = {talk = true},
|
||||
func = function( _ , text)
|
||||
e,lstr = pcall(loadstring(text))
|
||||
minetest.chat_send_all(tostring(lstr))
|
||||
end,
|
||||
})
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user