|
|
|
local ipairs, ItemStack, vector, include, nodecore
|
|
|
|
= ipairs, ItemStack, vector, include, nodecore
|
|
|
|
|
|
|
|
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`.
|
|
|
|
|
|
|
|
-------------------------------------
|
|
|
|
-- 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 nodecore_filtered_lookup = nc_extended_rotating.utility.nodecore_filtered_lookup
|
|
|
|
local register_rotatable = nc_extended_rotating.registry.register_rotatable;
|
|
|
|
|
|
|
|
-- Register lenses.
|
|
|
|
local LENS_FILTERED_LOOKUP = nodecore_filtered_lookup(function(a, b)
|
|
|
|
return vector.equals(a.f, b.f) end)
|
|
|
|
for _, lens_state in ipairs({ "", "_on", "_glow", "_glow_start" }) do
|
|
|
|
register_rotatable("nc_optics:lens" .. lens_state, nil, LENS_FILTERED_LOOKUP) end
|
|
|
|
|
|
|
|
-- Register prisms.
|
|
|
|
local PRISM_FILTERED_LOOKUP = nodecore_filtered_lookup(function(a, b)
|
|
|
|
return vector.equals(a.f, b.r) and vector.equals(a.r, b.f) end)
|
|
|
|
for _, prism_state in ipairs({ "", "_on", "_gated" }) do
|
|
|
|
register_rotatable("nc_optics:prism" .. prism_state, nil, PRISM_FILTERED_LOOKUP) end
|
|
|
|
|
|
|
|
-- Register all existing and to-be-registered door panels.
|
|
|
|
local PANEL_FILTERED_LOOKUP = nodecore_filtered_lookup(function(a, b)
|
|
|
|
return vector.equals(a.f, b.r) and vector.equals(a.r, b.f) end)
|
|
|
|
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, PANEL_FILTERED_LOOKUP,
|
|
|
|
function(_, _, _, item_stack) return ItemStack(item_stack):get_name() == pin end)
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
})
|