Files
last-hearth/mods/hearth/init.lua
T
2026-11-01 19:35:46 -05:00

52 lines
2.2 KiB
Lua
Executable File

hearth = {players = {}, sessions = {}}
local path = core.get_modpath("hearth")
hearth.model = dofile(path .. "/model.lua")
-- Original texture generation: no downloaded assets or asset licensing ambiguity.
function hearth.texture(color)
return "hearth_" .. color:sub(2):lower() .. ".png"
end
function hearth.notify(player, message)
if player then core.chat_send_player(player:get_player_name(), message) end
end
local storage = core.get_mod_storage()
hearth.storage = storage
-- A small claim registry is persisted in mod storage; never deserialize code.
local claim_data = storage:get_string("claims")
local claims = claim_data ~= "" and core.parse_json(claim_data) or {}
function hearth.claim_allowed(pos, name)
for owner, p in pairs(claims) do
if owner ~= name and math.abs(pos.x - p.x) <= 12 and math.abs(pos.z - p.z) <= 12
and math.abs(pos.y - p.y) <= 24 then return false end
end
return true
end
local old_protected = core.is_protected
core.is_protected = function(pos, name)
return not hearth.claim_allowed(pos, name) or old_protected(pos, name)
end
core.register_chatcommand("claim", {
description = "Protect a 25 x 25 homestead here (one per player). /claim remove to release.",
func = function(name, param)
local player = core.get_player_by_name(name)
if not player then return false, "Join the world first." end
if param == "remove" then
claims[name] = nil
elseif param == "" then
local p = vector.round(player:get_pos())
if claims[name] then return false, "Release your existing claim before moving it." end
for _, other in pairs(claims) do
if math.abs(p.x - other.x) <= 25 and math.abs(p.z - other.z) <= 25 then
return false, "Too close to another homestead. Move at least 26 blocks away."
end
end
claims[name] = {x = p.x, y = p.y, z = p.z}
else return false, "Use /claim or /claim remove." end
storage:set_string("claims", core.write_json(claims))
return true, param == "remove" and "Homestead released." or "Homestead protected. Others cannot build or harvest here."
end,
})
dofile(path .. "/content.lua")
dofile(path .. "/interface.lua")
dofile(path .. "/runtime.lua")
dofile(path .. "/encounters.lua")