|
|
|
local ipairs, ItemStack, nodecore, include
|
|
|
|
= ipairs, ItemStack, nodecore, include
|
|
|
|
|
|
|
|
rawset(_G, "nc_extended_rotating", {})
|
|
|
|
nc_extended_rotating.hud = include("hud")
|
|
|
|
nc_extended_rotating.rotate = include("rotate")
|
|
|
|
nc_extended_rotating.utility = include("utility") -- Depends on `rotate`.
|
|
|
|
nc_extended_rotating.entity = include("entity") -- Depends on `utility`.
|
|
|
|
nc_extended_rotating.registry = include("registry") -- Depends on `rotate` and `state` (late).
|
|
|
|
nc_extended_rotating.state = include("state") -- Depends on `registry`, `rotate` and `utility`.
|
|
|
|
|
|
|
|
do
|
|
|
|
-- Do a quick check if we're using a compatible version of NodeCore.
|
|
|
|
local lens_def = minetest.registered_nodes["nc_optics:lens"]
|
|
|
|
if not lens_def.spindata then error("Requires NodeCore 966ed012 or later") end
|
|
|
|
end
|
|
|
|
|
|
|
|
-------------------------------------
|
|
|
|
-- Register Player Update Function --
|
|
|
|
-------------------------------------
|
|
|
|
|
|
|
|
local update_rotating_state = nc_extended_rotating.state.update_rotating_state
|
|
|
|
local update_player_hud = nc_extended_rotating.hud.update_player_hud
|
|
|
|
local update_entity_hint = nc_extended_rotating.entity.update_entity_hint
|
|
|
|
|
|
|
|
nodecore.register_playerstep({
|
|
|
|
label = "nc_extended_rotating:update",
|
|
|
|
action = function(player, data)
|
|
|
|
local state = update_rotating_state(player, data)
|
|
|
|
update_player_hud(player, state)
|
|
|
|
update_entity_hint(player, state)
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
|
|
|
---------------------------------------
|
|
|
|
-- Register Rotatable NodeCore Nodes --
|
|
|
|
---------------------------------------
|
|
|
|
|
|
|
|
local register_rotatable = nc_extended_rotating.registry.register_rotatable;
|
|
|
|
|
|
|
|
-- Register lenses.
|
|
|
|
for _, lens_state in ipairs({ "", "_on", "_glow", "_glow_start" }) do
|
|
|
|
register_rotatable("nc_optics:lens" .. lens_state) end
|
|
|
|
|
|
|
|
-- Register prisms.
|
|
|
|
for _, prism_state in ipairs({ "", "_on", "_gated" }) do
|
|
|
|
register_rotatable("nc_optics:prism" .. prism_state) end
|
|
|
|
|
|
|
|
-- Register all existing and to-be-registered door panels.
|
|
|
|
nodecore.register_on_register_item({
|
|
|
|
retroactive = true,
|
|
|
|
func = function(name, def)
|
|
|
|
-- This function is actually called BEFORE the item is registered with Minetest.
|
|
|
|
-- Because of this, looking up the node definition by name does not work.
|
|
|
|
-- Thankfully, the panel is registered before the door, and as such it already exists.
|
|
|
|
if def.groups and def.groups.door then
|
|
|
|
local panel = def.drop_in_place.name -- The panel version of the door.
|
|
|
|
local pin = def.drop_non_silktouch or def.drop -- Dropped item is the door's pin.
|
|
|
|
register_rotatable(panel, nil, function(_, _, _, item_stack)
|
|
|
|
return ItemStack(item_stack):get_name() == pin end)
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
})
|