entity.wielder = name
- object:set_attach(player, "Right_Hand", vector.new(0,0,0), vector.new(0,0,0))
+ object:set_attach(player, "Right_Hand", vector.new(0,0,0), vector.new(0, 0, 0))
temp_pool.wield_item = object
end
entity = object:get_luaentity()
object_string = entity.itemstring
-
+
if object_string ~= item then
entity.itemstring = item
entity.set_item(entity,item)
temp_pool.eye_height = player_constant.eye_height
temp_pool.stepheight = player_constant.stepheight
temp_pool.visual_size = player_constant.visual_size
-
+ temp_pool.attached = false
+ temp_pool.sleeping = false
player:set_properties(temp_pool)
end
pool[name].force_update = true
end
+-- allows other mods to set animations per player
+set_player_animation = function(player,animation,speed,loop)
+ set_animation(player, animation, speed, loop)
+end
+
+local name
+player_is_attached = function(player,truth)
+ name = player:get_player_name()
+ pool[name].attached = truth
+end
+
+local name
+get_if_player_attached = function(player)
+ name = player:get_player_name()
+ return(pool[name].attached)
+end
+
+
+local name
+player_is_sleeping = function(player,truth)
+ name = player:get_player_name()
+ pool[name].sleeping = truth
+end
+
+local name
+get_if_player_sleeping = function(player)
+ name = player:get_player_name()
+ return(pool[name].sleeping)
+end
+
-- toggles nametag visibility
local opacity
local name
local temp_pool
local state
-local swimming
+--local swimming
local mouse
local translated
local control_translation = function(player,control)
swimming = is_player_swimming(player)
mouse = (control.LMB or control.RMB)
-
if swimming then
for k,i in pairs(control) do
if i and translation_table.swim.keys[k] then
-- translates player movement to animation
local control_table
local update
+local name
+local temp_pool
local do_animations = function(player)
+ name = player:get_player_name()
+ temp_pool = pool[name]
+
control_table = player:get_player_control()
- update = control_check(player,control_table)
pitch_look(player,control_table.sneak)
- update_wield_item(player)
- if update and player:get_hp() > 0 then
- control_translation(player,control_table)
- elseif player:get_hp() <= 0 then
+
+ if player:get_hp() <= 0 then
set_animation(player,"die",40,false)
+ elseif not temp_pool.sleeping and (not temp_pool.attached or not player:get_attach()) then
+ temp_pool.attached = false
+ update = control_check(player,control_table)
+ update_wield_item(player)
+ if update and player:get_hp() > 0 then
+ control_translation(player,control_table)
+ end
end
end
end)
+local stack
+local itemname
+local def
+local set_item = function(self, item)
+ stack = ItemStack(item or self.itemstring)
+ self.itemstring = stack:to_string()
+ itemname = stack:is_known() and stack:get_name() or "unknown"
+
+ def = minetest.registered_nodes[itemname]
+ local tooldef = minetest.registered_tools[itemname]
+
+ self.object:set_properties({
+ textures = {itemname},
+ wield_item = self.itemstring,
+ glow = def and def.light_source,
+ })
+
+ local parent, bone, offset, rotation, forced_visible = self.object:get_attach()
+
+ if not parent then
+ return
+ end
+
+ if tooldef then
+ rotation = vector.new(90, 45, 90)
+ else
+ rotation = vector.new(0, 0, 0)
+ end
+
+ self.object:set_attach(parent, bone, offset, rotation, forced_visible)
+end
minetest.register_entity("player_api:item", {
initial_properties = {
- hp_max = 1,
- physical = true,
+ hp_max = 1,
+ visual = "wielditem",
+ physical = false,
+ textures = {""},
+ automatic_rotate = 1.5,
+ is_visible = true,
+ pointable = false,
+
collide_with_objects = false,
- collisionbox = {0, 0, 0, 0, 0, 0},
- visual = "wielditem",
- visual_size = {x = 0.21, y = 0.21},
- textures = {""},
- spritediv = {x = 1, y = 1},
- initial_sprite_basepos = {x = 0, y = 0},
- is_visible = true,
- pointable = false,
+ collisionbox = {-0.21, -0.21, -0.21, 0.21, 0.21, 0.21},
+ selectionbox = {-0.21, -0.21, -0.21, 0.21, 0.21, 0.21},
+ visual_size = {x = 0.21, y = 0.21},
},
itemstring = "",
- set_item = function(self, item)
- local stack = ItemStack(item or self.itemstring)
-
- self.itemstring = stack:to_string()
-
-
- -- Backwards compatibility: old clients use the texture
- -- to get the type of the item
- local itemname = stack:is_known() and stack:get_name() or "unknown"
-
- local max_count = stack:get_stack_max()
- local count = math.min(stack:get_count(), max_count)
-
- local size = 0.21
- local coll_height = size * 0.75
- local def = minetest.registered_nodes[itemname]
- local glow = def and def.light_source
-
- local is_visible = true
- if self.itemstring == "" then
- -- item not yet known
- is_visible = false
- end
-
- self.object:set_properties({
- is_visible = is_visible,
- visual = "wielditem",
- textures = {itemname},
- visual_size = {x = size, y = size},
- collisionbox = {-size, -0.21, -size,
- size, coll_height, size},
- selectionbox = {-size, -size, -size, size, size, size},
- --automatic_rotate = math.pi * 0.5 * 0.2 / size,
- wield_item = self.itemstring,
- glow = glow,
- })
- end,
+ set_item = set_item,
on_step = function(self, dtime)
if not self.wielder or (self.wielder and not minetest.get_player_by_name(self.wielder)) then
self.object:remove()
end
end,
-})
\ No newline at end of file
+})