]> git.lizzy.rs Git - Crafter.git/blobdiff - mods/player_api/init.lua
Added Seasons
[Crafter.git] / mods / player_api / init.lua
index 9219167a8fa56526102d3233a128e95cec1e8849..432d20af5288f796f3792a41e1e912a2c7c4a93c 100644 (file)
@@ -48,7 +48,7 @@ local update_wield_item = function(player)
                        
                        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
@@ -84,6 +84,7 @@ local set_all_properties = function(player)
        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
 
@@ -151,6 +152,24 @@ player_is_attached = function(player,truth)
        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
@@ -364,7 +383,7 @@ local do_animations = function(player)
 
        if player:get_hp() <= 0 then
                set_animation(player,"die",40,false)
-       elseif not temp_pool.attached or not player:get_attach() then
+       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)
@@ -403,12 +422,27 @@ local set_item = function(self, item)
        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", {
@@ -436,4 +470,4 @@ minetest.register_entity("player_api:item", {
                        self.object:remove()
                end
        end,
-})
\ No newline at end of file
+})