]> git.lizzy.rs Git - Crafter.git/blobdiff - mods/player_api/init.lua
Added Seasons
[Crafter.git] / mods / player_api / init.lua
index b2559c212499f748db6f742801399874c038cb8f..432d20af5288f796f3792a41e1e912a2c7c4a93c 100644 (file)
@@ -12,7 +12,7 @@ local player_constant = {
                                                        "blank_skin.png",
                                                   },
        current_animation    = "stand",
-       --swimming             = false,
+       swimming             = false,
        collisionbox         = {-0.3, 0.0, -0.3, 0.3, 1.7, 0.3},
        old_controls         = {},
        stepheight           = 0.6  ,
@@ -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
@@ -187,15 +206,15 @@ end
 
 -- controls head bone
 local state
---local swimming
+local swimming
 local pitch
 local pitch_look = function(player,sneak)
        state = get_player_state(player)
-       --swimming = is_player_swimming(player)
+       swimming = is_player_swimming(player)
        pitch = degrees(player:get_look_vertical()) * -1
-       --if swimming then
-               --pitch = pitch + 90
-       if sneak then
+       if swimming then
+               pitch = pitch + 90
+       elseif sneak then
                pitch = pitch + 15
        end
 
@@ -307,10 +326,9 @@ local control_translation = function(player,control)
        temp_pool = pool[name]
 
        state = get_player_state(player)
-       --swimming = is_player_swimming(player)
+       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
@@ -323,33 +341,32 @@ local control_translation = function(player,control)
                set_animation(player, translated.animation, translated.speed)
                return
        else
-       ]]--
-       if control.sneak then
-               for k,i in pairs(control) do
-                       if i and translation_table.sneak.keys[k] then
-                               translated = translation_table.sneak.states[true][mouse]
-                               set_animation(player, translated.animation, translated.speed)
-                               return
-                       end
-               end
-               translated = translation_table.sneak.states[false][mouse]
-               set_animation(player, translated.animation, translated.speed)
-               return
-       else
-               for k,i in pairs(control) do
-                       if i and translation_table.walk.keys[k] then
-                               translated = translation_table.walk.states[mouse][state]
-                               if translated then
+               if control.sneak then
+                       for k,i in pairs(control) do
+                               if i and translation_table.sneak.keys[k] then
+                                       translated = translation_table.sneak.states[true][mouse]
                                        set_animation(player, translated.animation, translated.speed)
                                        return
                                end
                        end
+                       translated = translation_table.sneak.states[false][mouse]
+                       set_animation(player, translated.animation, translated.speed)
+                       return
+               else
+                       for k,i in pairs(control) do
+                               if i and translation_table.walk.keys[k] then
+                                       translated = translation_table.walk.states[mouse][state]
+                                       if translated then
+                                               set_animation(player, translated.animation, translated.speed)
+                                               return
+                                       end
+                               end
+                       end
                end
-       end
 
-       translated = translation_table.stand[mouse]
-       set_animation(player, translated.animation, translated.speed)
-       --end
+               translated = translation_table.stand[mouse]
+               set_animation(player, translated.animation, translated.speed)
+       end
 end
 
 -- translates player movement to animation
@@ -366,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)
@@ -405,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", {
@@ -438,4 +470,4 @@ minetest.register_entity("player_api:item", {
                        self.object:remove()
                end
        end,
-})
\ No newline at end of file
+})