1
0
mirror of https://github.com/mt-mods/homedecor_modpack.git synced 2024-11-09 11:50:22 +01:00
homedecor_modpack/computer/init.lua

100 lines
2.9 KiB
Lua
Raw Normal View History

2015-05-15 10:45:21 +02:00
computer = {}
screwdriver = screwdriver or {}
2014-07-19 01:33:01 +02:00
2015-05-08 12:48:05 +02:00
computer.register = function (name, def)
if (name:sub(1, 1) == ":") then name = name:sub(2) end
local modname, basename = name:match("^([^:]+):(.*)")
local TEXPFX = modname.."_"..basename.."_"
local ONSTATE = modname..":"..basename
local OFFSTATE = modname..":"..basename.."_off"
local cdef = table.copy(def)
minetest.register_node(ONSTATE, {
2015-05-08 12:48:05 +02:00
drawtype = "nodebox",
paramtype = "light",
paramtype2 = "facedir",
description = cdef.description,
inventory_image = cdef.inventory_image,
2015-05-08 12:48:05 +02:00
groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2},
tiles = {
TEXPFX.."tp.png",
TEXPFX.."bt.png",
TEXPFX.."rt.png",
TEXPFX.."lt.png",
TEXPFX.."bk.png",
2015-05-08 12:48:05 +02:00
TEXPFX.."ft.png"
},
node_box = cdef.node_box,
selection_box = cdef.node_box,
2015-05-08 12:48:05 +02:00
on_rightclick = function (pos, node, clicker, itemstack)
if cdef.on_turn_off and cdef.on_turn_off(pos, node, clicker, itemstack) then
return itemstack
end
2015-05-08 12:48:05 +02:00
node.name = OFFSTATE
minetest.set_node(pos, node)
return itemstack
2015-05-08 12:48:05 +02:00
end
})
minetest.register_node(OFFSTATE, {
2015-05-08 12:48:05 +02:00
drawtype = "nodebox",
paramtype = "light",
paramtype2 = "facedir",
groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2, not_in_creative_inventory=1},
tiles = {
(TEXPFX.."tp"..(cdef.tiles_off.top and "_off" or "")..".png"),
(TEXPFX.."bt"..(cdef.tiles_off.bottom and "_off" or "")..".png"),
(TEXPFX.."rt"..(cdef.tiles_off.right and "_off" or "")..".png"),
(TEXPFX.."lt"..(cdef.tiles_off.left and "_off" or "")..".png"),
(TEXPFX.."bk"..(cdef.tiles_off.back and "_off" or "")..".png"),
(TEXPFX.."ft"..(cdef.tiles_off.front and "_off" or "")..".png")
2015-05-08 12:48:05 +02:00
},
node_box = cdef.node_box_off or cdef.node_box,
selection_box = cdef.node_box_off or cdef.node_box,
2015-05-08 12:48:05 +02:00
on_rightclick = function (pos, node, clicker, itemstack)
if cdef.on_turn_on and cdef.on_turn_on(pos, node, clicker, itemstack) then
return itemstack
end
2015-05-08 12:48:05 +02:00
node.name = ONSTATE
minetest.set_node(pos, node)
return itemstack
2015-05-08 12:48:05 +02:00
end,
drop = ONSTATE
})
2014-07-19 01:33:01 +02:00
end
2015-05-08 12:48:05 +02:00
computer.register_handheld = function (name, def)
if (name:sub(1, 1) == ":") then name = name:sub(2) end
local modname, basename = name:match("^([^:]+):(.*)")
local TEXPFX = modname.."_"..basename.."_inv"
local ONSTATE = modname..":"..basename
minetest.register_craftitem(ONSTATE, {
2015-05-08 12:48:05 +02:00
description = def.description,
inventory_image = TEXPFX..".png",
wield_image = TEXPFX..".png"
})
2014-07-19 01:33:01 +02:00
end
2015-05-08 12:48:05 +02:00
computer.pixelnodebox = function (size, boxes)
local fixed = { }
for _, box in ipairs(boxes) do
2015-05-08 12:48:05 +02:00
local x, y, z, w, h, l = unpack(box)
fixed[#fixed + 1] = {
(x / size) - 0.5,
(y / size) - 0.5,
(z / size) - 0.5,
((x + w) / size) - 0.5,
((y + h) / size) - 0.5,
2015-05-08 12:48:05 +02:00
((z + l) / size) - 0.5
}
end
return {
2015-05-08 12:48:05 +02:00
type = "fixed",
fixed = fixed
}
2014-07-19 01:33:01 +02:00
end
2015-05-08 12:48:05 +02:00
local MODPATH = minetest.get_modpath("computer")
dofile(MODPATH.."/computers.lua")
dofile(MODPATH.."/miscitems.lua")
dofile(MODPATH.."/recipes.lua")
dofile(MODPATH.."/tetris.lua")