Add copper, and the beginnings of a machine system.
This commit is contained in:
parent
30ba6e5385
commit
1e897665bb
69 changed files with 976 additions and 135 deletions
|
|
@ -36,8 +36,39 @@ function say(msg)
|
|||
minetest.chat_send_all("# Server: "..msg)
|
||||
end
|
||||
|
||||
EventTarget = {
|
||||
init = function()
|
||||
local e = {
|
||||
listeners = {}
|
||||
}
|
||||
return setmetatable(e, {__index = EventTarget})
|
||||
end,
|
||||
listen = function(e, channel, fn)
|
||||
if not e.listeners[channel] then e.listeners[channel] = {} end
|
||||
local l = e.listeners[channel]
|
||||
l[#l +1] = fn
|
||||
end,
|
||||
unlisten = function(e, channel, fn)
|
||||
if not e.listeners[channel] then return end
|
||||
local l = e.listeners[channel]
|
||||
local idx = table.indexof(l, fn)
|
||||
if idx < 0 then return end
|
||||
table.remove(l, idx)
|
||||
end,
|
||||
dispatch = function(e, channel, ...)
|
||||
local l = e.listeners[channel]
|
||||
if not l then return end
|
||||
for i = 1, #l do
|
||||
l[i](...)
|
||||
end
|
||||
end
|
||||
}
|
||||
setmetatable(EventTarget, {
|
||||
__call = function(_, ...) return EventTarget.init(...) end
|
||||
})
|
||||
|
||||
rgt = {
|
||||
horizontal_neighbor_offests = {
|
||||
adjacent_neighbor_offests = {
|
||||
vector.new(0,0,1),
|
||||
vector.new(0,0,-1),
|
||||
vector.new(1,0,0),
|
||||
|
|
@ -52,7 +83,9 @@ rgt = {
|
|||
vector.new(0,0,-1),
|
||||
vector.new(1,0,0),
|
||||
vector.new(-1,0,0),
|
||||
}
|
||||
},
|
||||
nodes_to_content_ids = {},
|
||||
content_ids_to_nodes = {}
|
||||
}
|
||||
local ns = rgt
|
||||
|
||||
|
|
@ -80,6 +113,9 @@ function ns.register_node(name, def)
|
|||
end
|
||||
end
|
||||
minetest.register_node(":"..name, def)
|
||||
local cid = minetest.get_content_id(name)
|
||||
ns.nodes_to_content_ids[name] = cid
|
||||
ns.content_ids_to_nodes[cid] = name
|
||||
if alias then
|
||||
minetest.register_alias(alias, name)
|
||||
end
|
||||
|
|
@ -111,6 +147,26 @@ function ns.register_tool(name, def)
|
|||
end
|
||||
end
|
||||
|
||||
function ns.register_entity(name, def)
|
||||
minetest.register_entity(name, def)
|
||||
end
|
||||
|
||||
-- Out-of-line node metadata, allowing meta for a node to be accessed even when its containing mapblock is not loaded.
|
||||
local db = minetest.get_mod_storage()
|
||||
local NodeMetaRef = {
|
||||
set = function(e, key, value)
|
||||
return db:set_string(e._pos.."_"..key, value)
|
||||
end,
|
||||
get = function(e, key)
|
||||
return db:get(e._pos.."_"..key)
|
||||
end,
|
||||
}
|
||||
NodeMetaRef.__index = NodeMetaRef
|
||||
|
||||
function ns.get_node_meta(pos)
|
||||
return setmetatable({_pos = tostring(minetest.hash_node_position(pos))}, NodeMetaRef)
|
||||
end
|
||||
|
||||
-- Allow nodes to provide a callback to run on activation without
|
||||
-- needing to register a bunch of mostly identical LBMs.
|
||||
minetest.register_lbm {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue