Add more things
This commit is contained in:
parent
be2262fa17
commit
d6662e8094
26 changed files with 565 additions and 26 deletions
|
|
@ -10,24 +10,274 @@ 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 {
|
||||
e.textures = {_textures = {}}
|
||||
setmetatable(e.textures, {
|
||||
__newindex = function(tbl, key, value)
|
||||
tbl._textures[idx] = value
|
||||
p:set_properties {
|
||||
textures = tbl._textures
|
||||
}
|
||||
end,
|
||||
__index = e.textures._textures
|
||||
})
|
||||
|
||||
e.hunger_bar = 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",
|
||||
text = "rgt_pumpkin_alt.png",
|
||||
number = 20,
|
||||
item = 20,
|
||||
text2 = "rgt_pumpkin_empty.png"
|
||||
}
|
||||
|
||||
e.props = p:get_properties()
|
||||
|
||||
e.eye_height = 1.6
|
||||
|
||||
|
||||
|
||||
e.health_display = minetest.add_entity(p:get_pos(), "display")
|
||||
e.health_display:set_attach(p, nil, vector.new(0, 17, 0))
|
||||
e:update_hp(p:get_hp())
|
||||
|
||||
return e
|
||||
end,
|
||||
update_hp = function(m, hp)
|
||||
if not (m.health_display and m.health_display:is_valid()) then
|
||||
m.health_display = minetest.add_entity(m.object:get_pos(), "display")
|
||||
m.health_display:set_attach(m.object, nil, vector.new(0, 17, 0))
|
||||
end
|
||||
local tx = "[combine:90x90"
|
||||
for i = math.floor(hp /2), math.floor(m.props.hp_max /2) -1 do
|
||||
tx = tx..":"..(i *9)..",0=rgt_heart_empty.png"
|
||||
end
|
||||
for i = 0, math.floor(hp /2) -1 do
|
||||
tx = tx..":"..(i *9)..",0=rgt_heart.png"
|
||||
end
|
||||
if hp %2 ~= 0 then
|
||||
tx = tx..":"..((math.floor(hp /2)) *9)..",0=rgt_heart.png\\^[fill\\:5x9\\:4,0\\:#000\\^[makealpha\\:#000"
|
||||
end
|
||||
m.health_display:set_properties {
|
||||
visual = "sprite",
|
||||
textures = {tx},
|
||||
shaded = false
|
||||
}
|
||||
end,
|
||||
tick = function(m, dtime)
|
||||
local time = minetest.get_us_time()
|
||||
local p = m.object
|
||||
if not p or not p:is_player() then
|
||||
return
|
||||
end
|
||||
local pitch = p:get_look_vertical()
|
||||
local yaw = p:get_look_horizontal()
|
||||
local dir = p:get_look_dir()
|
||||
local pos = p:get_pos()
|
||||
pos.y = pos.y +m.eye_height
|
||||
|
||||
-- Animation
|
||||
if not m.in_third_person then
|
||||
local c = p:get_player_control()
|
||||
local moving = c.up or c.down or c.left or c.right
|
||||
|
||||
if moving then
|
||||
m.moving = true
|
||||
if c.aux1 and c.up then
|
||||
if p:get_animation().y ~= 2 then p:set_animation({x=1, y=2}, 1.5, 0.2, true) end
|
||||
p:set_physics_override{
|
||||
speed = 1.5
|
||||
}
|
||||
else
|
||||
if p:get_animation().y ~= 1 then p:set_animation({x=0, y=1}, 1.5, 0.2, true) end
|
||||
p:set_physics_override{
|
||||
speed = 1
|
||||
}
|
||||
end
|
||||
else
|
||||
m.moving = false
|
||||
if p:get_animation().y ~= 0 then p:set_animation({x=0, y=0}) end
|
||||
end
|
||||
|
||||
if not m.rot then m.rot = 0 end
|
||||
if moving then
|
||||
local fac = 0
|
||||
if c.left then fac = 30 elseif c.right then fac = -30 end
|
||||
m.rot = yaw +math.rad(fac)
|
||||
elseif math.abs(yaw -m.rot) > math.rad(40) then
|
||||
m.rot = m.rot +(yaw -(m.yaw or 0))
|
||||
end
|
||||
m.rot = m.rot %math.rad(360)
|
||||
m.yaw = yaw
|
||||
|
||||
p:set_bone_override("Head", {
|
||||
rotation = {vec = vector.new(math.min(math.max(pitch, math.rad(-60)), math.rad(60)),-(yaw -m.rot),0), interpolation = 0.1, absolute = true}
|
||||
})
|
||||
|
||||
p:set_bone_override("root", {
|
||||
rotation = {vec = vector.new(0,yaw -m.rot,0), interpolation = 0.1, absolute = true}
|
||||
})
|
||||
m.ctl = c
|
||||
else -- Third-person camera
|
||||
local c = m.camera.ref
|
||||
local me = m.focus and m.focus.ref or false
|
||||
local ctl = p:get_player_control()
|
||||
-- local lv = p:get_look_vertical()
|
||||
-- local lh = p:get_look_horizontal()
|
||||
-- local ldir = p:get_look_dir()
|
||||
local ppos = c:get_pos()
|
||||
if not ppos then
|
||||
m:enter_third_person_view(m.third_person_focus, me ~= false)
|
||||
return
|
||||
end
|
||||
local dir = vector.new(0,0,1):rotate(vector.new(math.rad(-45),yaw,0))
|
||||
-- if lv < 0 then
|
||||
-- lv = 0
|
||||
-- p:set_look_vertical(0)
|
||||
-- end
|
||||
local radius = m.third_person_camera_radius or 10
|
||||
local t = (me and me:get_pos() or m.third_person_focus) +(-dir *radius)
|
||||
-- local standing_on = minetest.get_node(pos:offset(0, -0.05, 0))
|
||||
-- local can_jump = minetest.registered_nodes[standing_on.name].walkable
|
||||
local dist = math.min(radius *2, t:distance(ppos) ^2)
|
||||
local vel = t:direction(ppos) *dist
|
||||
local tvel = vector.zero()
|
||||
local was_moving = m.ctl.up or m.ctl.down or m.ctl.left or m.ctl.right or m.ctl.jump or m.ctl.sneak
|
||||
local moving = ctl.up or ctl.down or ctl.left or ctl.right
|
||||
-- if e.jumping == 0 and can_jump and ctl.jump then
|
||||
-- e.jumping = 10
|
||||
-- tvel = tvel +vector.new(0,5,0)
|
||||
-- end
|
||||
if ctl.jump then
|
||||
tvel.y = 3
|
||||
elseif ctl.sneak then
|
||||
tvel.y = -3
|
||||
end
|
||||
if moving then
|
||||
dir.y = 0
|
||||
v_normalize(dir)
|
||||
local rot = 0
|
||||
if ctl.up then
|
||||
if ctl.left then
|
||||
rot = math.rad(45)
|
||||
elseif ctl.right then
|
||||
rot = math.rad(-45)
|
||||
end
|
||||
elseif ctl.down then
|
||||
if ctl.left then
|
||||
rot = math.rad(180 -45)
|
||||
elseif ctl.right then
|
||||
rot = math.rad(180 +45)
|
||||
else
|
||||
rot = math.rad(180)
|
||||
end
|
||||
elseif ctl.left then
|
||||
rot = math.rad(90)
|
||||
elseif ctl.right then
|
||||
rot = math.rad(-90)
|
||||
end
|
||||
dir = dir:rotate(vector.new(0,rot,0))
|
||||
if me then me:set_velocity(tvel +(dir *5)) end
|
||||
vel = vel -(dir *5)
|
||||
-- if not was_moving then
|
||||
-- me:set_animation({x=0, y=1}, 1.5, 0.2, true)
|
||||
-- end
|
||||
-- me:set_bone_override("root", {
|
||||
-- rotation = {
|
||||
-- vec = -dir:dir_to_rotation(), interpolation = 0.07, absolute = true
|
||||
-- }
|
||||
-- })
|
||||
elseif was_moving and me then
|
||||
-- me:set_animation({x=0, y=0})
|
||||
me:set_velocity(tvel)
|
||||
end
|
||||
-- e.jumping = math.max(0, e.jumping -1)
|
||||
--vel.y = 0
|
||||
c:set_velocity(-vel)
|
||||
m.ctl = ctl
|
||||
end
|
||||
|
||||
-- Health regen
|
||||
-- TODO: Move to combat mod
|
||||
|
||||
if time -(m.last_time or 0) >= 10 *1000000 then
|
||||
local hp = p:get_hp()
|
||||
if hp < p:get_properties().hp_max then
|
||||
p:set_hp(hp +1)
|
||||
-- Make sure the health display is still loaded.
|
||||
elseif not (m.health_display and m.health_display:is_valid()) then
|
||||
m.health_display = minetest.add_entity(m.object:get_pos(), "display")
|
||||
m.health_display:set_attach(m.object, nil, vector.new(0, 17, 0))
|
||||
end
|
||||
|
||||
m.last_time = time
|
||||
end
|
||||
|
||||
-- Custom on-hover effects
|
||||
|
||||
m.pointed_node = nil
|
||||
|
||||
local pointed_found = false
|
||||
for pointed in minetest.raycast(pos, pos +(dir *7)) do -- TODO: Automatic range
|
||||
if pointed and pointed.type == "object" then
|
||||
local e = pointed.ref:get_luaentity()
|
||||
if e then
|
||||
local names_match = m.pointed_obj and (m.pointed_obj._name or m.pointed_obj.name) == (e._name or e.name)
|
||||
if m.pointed_obj and not names_match then
|
||||
if m.pointed_obj.on_unhover then
|
||||
m.pointed_obj:on_unhover(m)
|
||||
end
|
||||
m.hover_trigger_range = nil
|
||||
end
|
||||
if (m.pointed_obj and not names_match and e.on_hover) or not m.pointed_obj then
|
||||
if e.on_hover then
|
||||
m.hover_trigger_range = e:on_hover(m) or 8
|
||||
end
|
||||
pointed_found = true
|
||||
m.pointed_obj = e
|
||||
break
|
||||
elseif m.pointed_obj and names_match and e.on_hover then
|
||||
pointed_found = true
|
||||
break
|
||||
end
|
||||
end
|
||||
elseif pointed and pointed.type == "node" and not m.pointed_node then
|
||||
m.pointed_node = pointed
|
||||
end
|
||||
end
|
||||
if not pointed_found and m.pointed_obj then
|
||||
if m.pointed_obj.on_unhover then
|
||||
m.pointed_obj:on_unhover(m)
|
||||
end
|
||||
m.pointed_obj = nil
|
||||
m.hover_trigger_range = nil
|
||||
end
|
||||
|
||||
m.pos = pos
|
||||
|
||||
-- Run on_wield callbacks
|
||||
local w = p:get_wielded_item()
|
||||
local wname = w:get_name()
|
||||
local def = minetest.registered_items[wname]
|
||||
if m.prev_wielditem ~= wname then
|
||||
if m.prev_wielditem then
|
||||
local def = minetest.registered_items[m.prev_wielditem]
|
||||
local onunselect = def and def.on_unwield
|
||||
if onunselect then onunselect(m) end
|
||||
end
|
||||
m.prev_wielditem = wname
|
||||
local onselect = def and def.on_wield
|
||||
if onselect then onselect(m, w) end
|
||||
end
|
||||
|
||||
local while_wielded = def and def.while_wielded
|
||||
if while_wielded then while_wielded(m, w) end
|
||||
end,
|
||||
set_hotbar_size = function(m, slots)
|
||||
local p = m.object
|
||||
p:hud_set_hotbar_itemcount(slots)
|
||||
|
|
@ -68,3 +318,28 @@ minetest.hud_replace_builtin("health", {
|
|||
minetest.register_on_joinplayer(function(p)
|
||||
ns.players[p:get_player_name()] = Player(p)
|
||||
end)
|
||||
|
||||
minetest.register_on_leaveplayer(function(p)
|
||||
ns.players[p:get_player_name()] = nil
|
||||
end)
|
||||
|
||||
minetest.register_globalstep(function(time)
|
||||
for _, x in pairs(rgt.players) do
|
||||
x:tick(time)
|
||||
end
|
||||
end)
|
||||
|
||||
minetest.register_on_player_hpchange(function(p, hp_change)
|
||||
rgt.players[p:get_player_name()]:update_hp(p:get_hp() +hp_change)
|
||||
end)
|
||||
|
||||
minetest.register_chatcommand("hungerbar", {
|
||||
func = function(name, args)
|
||||
local m = rgt.players[name]
|
||||
if args == "pumpkin_alt" then
|
||||
m.object:hud_change(m.hunger_bar, "text", "rgt_"..args..".png")
|
||||
else
|
||||
m.object:hud_change(m.hunger_bar, "text", "rgt_pumpkin.png")
|
||||
end
|
||||
end
|
||||
})
|
||||
|
|
|
|||
1
mods/rgt_player/models/rgt_character.gltf
Normal file
1
mods/rgt_player/models/rgt_character.gltf
Normal file
File diff suppressed because one or more lines are too long
1
mods/rgt_player/models/rgt_hand.gltf
Normal file
1
mods/rgt_player/models/rgt_hand.gltf
Normal file
|
|
@ -0,0 +1 @@
|
|||
{"asset":{"version":"2.0","generator":"Blockbench 4.11.0 glTF exporter"},"scenes":[{"nodes":[3],"name":"blockbench_export"}],"scene":0,"nodes":[{"translation":[-7.341186189470692,-10.221666105894709,3.75],"name":"Right Arm","mesh":0},{"translation":[-7.341186189470692,-10.221666105894709,3.75],"name":"Right Arm Layer","mesh":1},{"rotation":[0.9829629131445342,0.12940952255126037,-0.017037086855465768,0.12940952255126018],"name":"RightArm","children":[0,1]},{"children":[2]}],"bufferViews":[{"buffer":0,"byteOffset":0,"byteLength":288,"target":34962,"byteStride":12},{"buffer":0,"byteOffset":288,"byteLength":288,"target":34962,"byteStride":12},{"buffer":0,"byteOffset":576,"byteLength":192,"target":34962,"byteStride":8},{"buffer":0,"byteOffset":768,"byteLength":72,"target":34963},{"buffer":0,"byteOffset":840,"byteLength":288,"target":34962,"byteStride":12},{"buffer":0,"byteOffset":1128,"byteLength":288,"target":34962,"byteStride":12},{"buffer":0,"byteOffset":1416,"byteLength":192,"target":34962,"byteStride":8},{"buffer":0,"byteOffset":1608,"byteLength":72,"target":34963}],"buffers":[{"byteLength":1680,"uri":"data:application/octet-stream;base64,AACMQAAAcEEAAHA/AACMQAAAcEEAAHC/AACMQAAA8EAAAHA/AACMQAAA8EAAAHC/AAAgQAAAcEEAAHC/AAAgQAAAcEEAAHA/AAAgQAAA8EAAAHC/AAAgQAAA8EAAAHA/AAAgQAAAcEEAAHC/AACMQAAAcEEAAHC/AAAgQAAAcEEAAHA/AACMQAAAcEEAAHA/AAAgQAAA8EAAAHA/AACMQAAA8EAAAHA/AAAgQAAA8EAAAHC/AACMQAAA8EAAAHC/AAAgQAAAcEEAAHA/AACMQAAAcEEAAHA/AAAgQAAA8EAAAHA/AACMQAAA8EAAAHA/AACMQAAAcEEAAHC/AAAgQAAAcEEAAHC/AACMQAAA8EAAAHC/AAAgQAAA8EAAAHC/AACAPwAAAAAAAAAAAACAPwAAAAAAAAAAAACAPwAAAAAAAAAAAACAPwAAAAAAAAAAAACAvwAAAAAAAAAAAACAvwAAAAAAAAAAAACAvwAAAAAAAAAAAACAvwAAAAAAAAAAAAAAAAAAgD8AAAAAAAAAAAAAgD8AAAAAAAAAAAAAgD8AAAAAAAAAAAAAgD8AAAAAAAAAAAAAgL8AAAAAAAAAAAAAgL8AAAAAAAAAAAAAgL8AAAAAAAAAAAAAgL8AAAAAAAAAAAAAAAAAAIA/AAAAAAAAAAAAAIA/AAAAAAAAAAAAAIA/AAAAAAAAAAAAAIA/AAAAAAAAAAAAAIC/AAAAAAAAAAAAAIC/AAAAAAAAAAAAAIC/AAAAAAAAAAAAAIC/ABAkPwAgoD4A8C8/ACCgPgAQJD8A4P8+APAvPwDg/z4AEDw/ACCgPgDwRz8AIKA+ABA8PwDg/z4A8Ec/AOD/PgDwOz8A4J8+ABAwPwDgnz4A8Ds/ACCIPgAQMD8AIIg+APBHPwAgiD4AEDw/ACCIPgDwRz8A4J8+ABA8PwDgnz4AEEg/ACCgPgDwUz8AI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AQPwAAWD8AABA/AABMPwAAQD8AAFg/AABAPwAAMD8AABA/AAA8PwAAED8AADA/AABAPwAAPD8AAEA/AAACAAEAAgADAAEABAAGAAUABgAHAAUACAAKAAkACgALAAkADAAOAA0ADgAPAA0AEAASABEAEgATABEAFAAWABUAFgAXABUA"}],"accessors":[{"bufferView":0,"componentType":5126,"count":24,"max":[4.375,15,0.9375],"min":[2.5,7.5,-0.9375],"type":"VEC3"},{"bufferView":1,"componentType":5126,"count":24,"max":[1,1,1],"min":[-1,-1,-1],"type":"VEC3"},{"bufferView":2,"componentType":5126,"count":24,"max":[0.827880859375,0.499755859375],"min":[0.640869140625,0.265869140625],"type":"VEC2"},{"bufferView":3,"componentType":5123,"count":36,"max":[23],"min":[0],"type":"SCALAR"},{"bufferView":4,"componentType":5126,"count":24,"max":[4.53125,15.15625,1.09375],"min":[2.34375,7.34375,-1.09375],"type":"VEC3"},{"bufferView":5,"componentType":5126,"count":24,"max":[1,1,1],"min":[-1,-1,-1],"type":"VEC3"},{"bufferView":6,"componentType":5126,"count":24,"max":[0.84375,0.75],"min":[0.640625,0.515625],"type":"VEC2"},{"bufferView":7,"componentType":5123,"count":36,"max":[23],"min":[0],"type":"SCALAR"}],"materials":[{"pbrMetallicRoughness":{"metallicFactor":0,"roughnessFactor":1,"baseColorTexture":{"index":0}},"alphaMode":"MASK","alphaCutoff":0.05,"doubleSided":true}],"textures":[{"sampler":0,"source":0,"name":"artifact_key.png"}],"samplers":[{"magFilter":9728,"minFilter":9728,"wrapS":33071,"wrapT":33071}],"images":[{"mimeType":"image/png"}],"meshes":[{"primitives":[{"mode":4,"attributes":{"POSITION":0,"NORMAL":1,"TEXCOORD_0":2},"indices":3,"material":0}]},{"primitives":[{"mode":4,"attributes":{"POSITION":4,"NORMAL":5,"TEXCOORD_0":6},"indices":7,"material":0}]}]}
|
||||
BIN
mods/rgt_player/textures/crosshair.png
Normal file
BIN
mods/rgt_player/textures/crosshair.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 117 B |
BIN
mods/rgt_player/textures/object_crosshair.png
Normal file
BIN
mods/rgt_player/textures/object_crosshair.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 117 B |
Binary file not shown.
|
Before Width: | Height: | Size: 214 B After Width: | Height: | Size: 203 B |
BIN
mods/rgt_player/textures/rgt_pumpkin_alt.png
Normal file
BIN
mods/rgt_player/textures/rgt_pumpkin_alt.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 233 B |
BIN
mods/rgt_player/textures/rgt_pumpkin_alt_empty.png
Normal file
BIN
mods/rgt_player/textures/rgt_pumpkin_alt_empty.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 205 B |
Loading…
Add table
Add a link
Reference in a new issue