red_glazed_terracotta/mods/rgt_player/init.lua
2025-09-16 02:20:35 -04:00

70 lines
1.9 KiB
Lua

local ns = rgt
ns.players = {}
Player = {
new = function(p)
local e = setmetatable({
name = p:get_player_name(),
object = p
}, {__index = Player})
local inv = p:get_inventory()
inv:set_size("hand", 1)
inv:set_stack("hand", 1, ItemStack("red_glazed_terracotta:hand"))
e:set_hotbar_size(8)
p:hud_add {
type = "statbar",
position = {x=0.5,y=1},
offset = {x=10,y=-96},
scale = {x=4,y=4},
alignment = {x=-1, y=-1},
size = {x=27,y=27},
text = "rgt_pumpkin.png",
number = 20,
item = 20,
text2 = "rgt_pumpkin_empty.png"
}
return e
end,
set_hotbar_size = function(m, slots)
local p = m.object
p:hud_set_hotbar_itemcount(slots)
local list = ""
for i = 0, slots do
list = list..":"..(21*i)..",0=rgt_hotbar.png"
end
p:hud_set_hotbar_image("[combine:"..(21 *slots +1).."x22"..list)
p:hud_set_hotbar_selected_image("rgt_hotbar_selected.png")
end
}
setmetatable(Player, {
__call = function(_, ...) return Player.new(...) end
})
minetest.register_craftitem(":red_glazed_terracotta:hand", {
inventory_image = "rgt_dirt.png",
tool_capabilities = {
groupcaps = {
hand_breakable = {times = {[3] = 0.7}, uses = 0, maxlevel = 1}
}
}
})
minetest.register_alias("hand", "red_glazed_terracotta:hand")
-- TODO: Replace builtin health system with custom health system
minetest.hud_replace_builtin("health", {
type = "statbar",
position = {x=0.5,y=1},
offset = {x=-27 *10 -10,y=-96},
scale = {x=4,y=4},
alignment = {x=-1, y=-1},
size = {x=27,y=27},
text = "rgt_heart.png",
text2 = "rgt_heart_empty.png"
})
minetest.register_on_joinplayer(function(p)
ns.players[p:get_player_name()] = Player(p)
end)