mirror of
https://github.com/stujones11/wield3d.git
synced 2024-08-19 21:14:04 +02:00
Add Blitz 3D player model and some code optimization
This commit is contained in:
parent
ec8e765638
commit
d918855e07
60
init.lua
60
init.lua
@ -2,7 +2,7 @@ dofile(minetest.get_modpath(minetest.get_current_modname()).."/location.lua")
|
|||||||
|
|
||||||
local update_time = 2 -- number of seconds between wielditem updates
|
local update_time = 2 -- number of seconds between wielditem updates
|
||||||
local location = {
|
local location = {
|
||||||
"Armature_Arm_Right", -- default bone
|
"Arm_Right", -- default bone
|
||||||
{x=0.2, y=5.5, z=3}, -- default position
|
{x=0.2, y=5.5, z=3}, -- default position
|
||||||
{x=-100, y=225, z=90}, -- default rotation
|
{x=-100, y=225, z=90}, -- default rotation
|
||||||
}
|
}
|
||||||
@ -10,20 +10,19 @@ local player_wielding = {}
|
|||||||
local timer = 0
|
local timer = 0
|
||||||
|
|
||||||
local function add_wield_entity(player)
|
local function add_wield_entity(player)
|
||||||
player:set_properties({
|
local name = player:get_player_name()
|
||||||
visual = "mesh",
|
|
||||||
mesh = "wield3d_character.x",
|
|
||||||
visual_size = {x=1, y=1},
|
|
||||||
})
|
|
||||||
local pos = player:getpos()
|
local pos = player:getpos()
|
||||||
if pos then
|
local inv = player:get_inventory()
|
||||||
|
if name and pos and inv then
|
||||||
local object = minetest.add_entity(pos, "wield3d:wield_entity")
|
local object = minetest.add_entity(pos, "wield3d:wield_entity")
|
||||||
if object then
|
if object then
|
||||||
object:set_attach(player, location[1], location[2], location[3])
|
object:set_attach(player, location[1], location[2], location[3])
|
||||||
local luaentity = object:get_luaentity()
|
local entity = object:get_luaentity()
|
||||||
if luaentity then
|
if entity then
|
||||||
luaentity.player = player
|
entity.player = player
|
||||||
return 1
|
player_wielding[name] = 1
|
||||||
|
else
|
||||||
|
object:remove()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -43,10 +42,10 @@ minetest.register_entity("wield3d:wield_entity", {
|
|||||||
player = nil,
|
player = nil,
|
||||||
item = nil,
|
item = nil,
|
||||||
timer = 0,
|
timer = 0,
|
||||||
location = location,
|
location = {location[1], location[2], location[3]},
|
||||||
on_step = function(self, dtime)
|
on_step = function(self, dtime)
|
||||||
self.timer = self.timer + dtime
|
self.timer = self.timer + dtime
|
||||||
if self.timer > update_time then
|
if self.timer < update_time then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
self.timer = 0
|
self.timer = 0
|
||||||
@ -70,7 +69,7 @@ minetest.register_entity("wield3d:wield_entity", {
|
|||||||
self.object:setpos(pos)
|
self.object:setpos(pos)
|
||||||
self.object:set_detach()
|
self.object:set_detach()
|
||||||
self.object:set_attach(player, loc[1], loc[2], loc[3])
|
self.object:set_attach(player, loc[1], loc[2], loc[3])
|
||||||
self.location = loc
|
self.location = {loc[1], loc[2], loc[3]}
|
||||||
end
|
end
|
||||||
self.object:set_properties({textures={item}})
|
self.object:set_properties({textures={item}})
|
||||||
return
|
return
|
||||||
@ -82,12 +81,14 @@ minetest.register_entity("wield3d:wield_entity", {
|
|||||||
|
|
||||||
minetest.register_globalstep(function(dtime)
|
minetest.register_globalstep(function(dtime)
|
||||||
timer = timer + dtime
|
timer = timer + dtime
|
||||||
if timer > update_time then
|
if timer > 10 then
|
||||||
for _,player in ipairs(minetest.get_connected_players()) do
|
for name, state in pairs(player_wielding) do
|
||||||
local name = player:get_player_name()
|
if state == 0 then
|
||||||
if name then
|
local player = minetest.get_player_by_name(name)
|
||||||
if not player_wielding[name] then
|
if player then
|
||||||
player_wielding[name] = add_wield_entity(player)
|
add_wield_entity(player)
|
||||||
|
else
|
||||||
|
player_wielding[name] = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -102,3 +103,22 @@ minetest.register_on_leaveplayer(function(player)
|
|||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
minetest.register_on_joinplayer(function(player)
|
||||||
|
default.player_set_model(player, "wield3d_character.b3d")
|
||||||
|
player_wielding[player:get_player_name()] = 0
|
||||||
|
minetest.after(1, add_wield_entity, player)
|
||||||
|
end)
|
||||||
|
|
||||||
|
default.player_register_model("wield3d_character.b3d", {
|
||||||
|
animation_speed = 30,
|
||||||
|
textures = {"character.png"},
|
||||||
|
animations = {
|
||||||
|
stand = {x=0, y=79},
|
||||||
|
lay = {x=162, y=166},
|
||||||
|
walk = {x=168, y=187},
|
||||||
|
mine = {x=189, y=198},
|
||||||
|
walk_mine = {x=200, y=219},
|
||||||
|
sit = {x=81, y=160},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
BIN
models/wield3d_character.b3d
Normal file
BIN
models/wield3d_character.b3d
Normal file
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user