Make compass API more practical to use from mods

This commit is contained in:
cora 2024-12-05 22:40:18 +01:00 committed by ryvnf
parent 7b75d32f96
commit d2c17d4dd5

View File

@ -51,6 +51,7 @@ local function get_compass_angle(pos, target, dir)
local angle_relative = (angle_north - angle_dir + 180) % 360 local angle_relative = (angle_north - angle_dir + 180) % 360
return math.floor((angle_relative/11.25) + 0.5) % compass_frames return math.floor((angle_relative/11.25) + 0.5) % compass_frames
end end
mcl_compass.get_compass_angle = get_compass_angle
--- Get compass image frame. --- Get compass image frame.
-- Returns the compass image frame with the needle direction matching the -- Returns the compass image frame with the needle direction matching the
@ -170,11 +171,13 @@ end)
mcl_compass.registered_compasses = {} mcl_compass.registered_compasses = {}
function mcl_compass.register_compass(name, def) function mcl_compass.register_compass(name, def)
mcl_compass.registered_compasses[name] = def mcl_compass.registered_compasses[name] = def
core.register_craftitem("mcl_compass:"..(def.name or name), table.merge({}, def.overrides or {}, { core.register_craftitem(":mcl_compass:"..(def.name or name), table.merge({}, def.overrides or {}, {
groups = table.merge({tool = 1, disable_repair = 1}, def.overrides.groups) groups = table.merge({tool = 1, disable_repair = 1, compass = 1}, def.overrides.groups)
})) }))
for i = 0, compass_frames - 1 do if def.name_fmt then
core.register_alias(string.format(def.name_fmt, i), "mcl_compass"..(def.name or name)) for i = 0, compass_frames - 1 do
core.register_alias(string.format(def.name_fmt, i), "mcl_compass"..(def.name or name))
end
end end
end end