Ores, tools, and wielditems
This commit is contained in:
parent
889aa531ba
commit
9e63d7fe3a
31 changed files with 268 additions and 12 deletions
|
|
@ -49,21 +49,22 @@ Player = {
|
|||
end,
|
||||
update_hp = function(m, hp)
|
||||
if not (m.health_display and m.health_display:is_valid()) then
|
||||
local pos = m.object:get_pos()
|
||||
if not pos then return end
|
||||
local pos = m.object:get_pos() or vector.zero()
|
||||
m.health_display = minetest.add_entity(pos, "rgt_player:health_display")
|
||||
m.health_display:set_attach(m.object, nil, vector.new(0, 22, 0))
|
||||
m.health_display:get_luaentity().owner = m
|
||||
end
|
||||
local tx = "[combine:90x90"
|
||||
for i = math.floor(hp /2), math.floor(m.props.hp_max /2) -1 do
|
||||
tx = tx..":"..(i *9)..",40=rgt_heart_empty.png"
|
||||
end
|
||||
for i = 0, math.floor(hp /2) -1 do
|
||||
tx = tx..":"..(i *9)..",40=rgt_heart.png"
|
||||
end
|
||||
if hp %2 ~= 0 then
|
||||
tx = tx..":"..((math.floor(hp /2)) *9)..",40=rgt_heart.png\\^[fill\\:5x9\\:4,0\\:#000\\^[makealpha\\:#000"
|
||||
if hp < m.props.hp_max then
|
||||
for i = math.floor(hp /2), math.floor(m.props.hp_max /2) -1 do
|
||||
tx = tx..":"..(i *9)..",40=rgt_heart_empty.png"
|
||||
end
|
||||
for i = 0, math.floor(hp /2) -1 do
|
||||
tx = tx..":"..(i *9)..",40=rgt_heart.png"
|
||||
end
|
||||
if hp %2 ~= 0 then
|
||||
tx = tx..":"..((math.floor(hp /2)) *9)..",40=rgt_heart.png\\^[fill\\:5x9\\:4,0\\:#000\\^[makealpha\\:#000"
|
||||
end
|
||||
end
|
||||
m.health_display:set_properties {
|
||||
visual = "sprite",
|
||||
|
|
@ -71,6 +72,44 @@ Player = {
|
|||
shaded = false
|
||||
}
|
||||
end,
|
||||
set_wielditem = function(m, def)
|
||||
if not def then def = {name = ""} end
|
||||
if not (m.wielditem_display and m.wielditem_display:is_valid()) then
|
||||
local mp = m.object:get_pos() or vector.zero()
|
||||
m.wielditem_display = minetest.add_entity(mp, "display")
|
||||
m.wielditem_display:set_properties {
|
||||
visual = "item"
|
||||
}
|
||||
local e = m.wielditem_display:get_luaentity()
|
||||
e.owner = m
|
||||
end
|
||||
local pos = def.type == "node" and vector.new(0.2, -6, 2) or vector.new(0.2, -5.5, 2.5)
|
||||
if def._wield_pos then
|
||||
pos = pos +def._wield_pos
|
||||
end
|
||||
local rot = def._wield_rot or def.type == "node" and vector.new(45, 40, 30) or (def.type == "tool" and vector.new(90, -45, 90) or vector.new(-90, -100, 90))
|
||||
local scale = def._wield_scale or vector.new(0.2, 0.2, 0.2)
|
||||
|
||||
if type(scale) == "number" then
|
||||
scale = vector.new(scale, scale, scale)
|
||||
end
|
||||
|
||||
if def.name == "air" or def.name == "" or not (def.tiles or def.wield_image or def.inventory_image) then
|
||||
m.wielditem_display:set_properties {
|
||||
visual = "sprite",
|
||||
textures = {"blank.png"}
|
||||
}
|
||||
m.wielditem_display:set_attach(m.object, "RightArm", pos, rot)
|
||||
return
|
||||
end
|
||||
|
||||
m.wielditem_display:set_properties {
|
||||
visual = "item",
|
||||
visual_size = scale,
|
||||
wield_item = def.name
|
||||
}
|
||||
m.wielditem_display:set_attach(m.object, "RightArm", pos, rot)
|
||||
end,
|
||||
tick = function(m, dtime)
|
||||
local time = minetest.get_us_time()
|
||||
local p = m.object
|
||||
|
|
@ -274,6 +313,7 @@ Player = {
|
|||
if onunselect then onunselect(m) end
|
||||
end
|
||||
m.prev_wielditem = wname
|
||||
m:set_wielditem(def)
|
||||
local onselect = def and def.on_wield
|
||||
if onselect then onselect(m, w) end
|
||||
end
|
||||
|
|
@ -370,3 +410,11 @@ minetest.register_chatcommand("hungerbar", {
|
|||
end
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_chatcommand("wi", {
|
||||
func = function(name, args)
|
||||
local m = rgt.players[name]
|
||||
local x, y, z = args:match "(%-?%d+)%s+(%-?%d+)%s+(%-?%d+)"
|
||||
m.wielditem_display:set_attach(m.object, "RightArm", vector.new(0.2, -5.5, 2.5), vector.new(tonumber(x), tonumber(y), tonumber(z)))
|
||||
end
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1,2 +1,2 @@
|
|||
name = rgt_player
|
||||
depends = rgt_base
|
||||
depends = rgt_entities
|
||||
Loading…
Add table
Add a link
Reference in a new issue