]> git.lizzy.rs Git - Crafter.git/commitdiff
push mobs broken for now
authoroilboi <47129783+oilboi@users.noreply.github.com>
Wed, 13 May 2020 13:57:06 +0000 (09:57 -0400)
committeroilboi <47129783+oilboi@users.noreply.github.com>
Wed, 13 May 2020 13:57:06 +0000 (09:57 -0400)
mods/mob/api/api_hook.lua
mods/mob/api/data_handling.lua
mods/mob/api/head_code.lua
mods/mob/api/interaction.lua
mods/mob/init.lua
mods/mob/models/creeper.b3d [new file with mode: 0644]
mods/mob/textures/creeper.png [new file with mode: 0644]

index 0376f11d7f9e40cf56ece3bfbdb7147640523f9f..d4913a4b81bdb92f46a99cedd782e7c42bc4e7fb 100644 (file)
@@ -45,6 +45,7 @@ if def.head_bone then
        mob_register.head_height_offset = def.head_height_offset
        mob_register.head_rotation_offset = def.head_rotation_offset
        mob_register.head_position_correction = def.head_position_correction
+       mob_register.head_coord = def.head_coord
 else
        print("create some other functions to turn mob " .. def.mobname)
 end
index a5795352e3c2264924c626af46a040b124248480..af424c75ab46454a3d955d765fb459f29f0bb5d7 100644 (file)
@@ -52,20 +52,19 @@ mobs.create_data_handling_functions = function(def,mob_register)
        mob_register.debug_nametag = function(self,dtime)
                --we're doing this to the child because the nametage breaks the
                --animation on the mob's body
-               if self.child then
-                       --we add in items we want to see in this list
-                       local debug_items = {"hostile_timer","hostile"}
-                       local text = ""
-                       for _,item in pairs(debug_items) do
-                               if self[item] ~= nil then
-                                       text = text..item..": "..tostring(self[item]).."\n"
-                               end
+               
+               --we add in items we want to see in this list
+               local debug_items = {"hostile_timer","hostile"}
+               local text = ""
+               for _,item in pairs(debug_items) do
+                       if self[item] ~= nil then
+                               text = text..item..": "..tostring(self[item]).."\n"
                        end
-                       self.child:set_nametag_attributes({
-                       color = "white",
-                       text = text
-                       })
                end
+               self.child:set_nametag_attributes({
+               color = "white",
+               text = text
+               })
        end
        return(mob_register)
 end
index 40cb1baf082b29af7c11ddcf9bb02595b6971383..edd6d4b10d8879929b5cb39a4165fb00cb142b44 100644 (file)
@@ -37,83 +37,185 @@ mobs.create_head_functions = function(def,mob_register)
        --a movement test to move the head
        mob_register.move_head = function(self,pos2,dtime)
                if self.head_bone then
-                       --print(self.head_bone)
-                       local head_position,head_rotation = self.object:get_bone_position(self.head_bone)
-                       --[[ debug
-                       if rotation then
-                               --print("--------------------------------")
-                               --rotation.x = rotation.x + 1
-                               rotation.z = rotation.z + 1
-                               rotation.y = 0
-                               
-                               if rotation.x > 90 then
-                                        rotation.x = -90
+                       if self.head_coord == "horizontal" then
+                               --print(self.head_bone)
+                               local head_position,head_rotation = self.object:get_bone_position(self.head_bone)
+                               --[[ debug
+                               if rotation then
+                                       --print("--------------------------------")
+                                       --rotation.x = rotation.x + 1
+                                       rotation.z = rotation.z + 1
+                                       rotation.y = 0
+                                       
+                                       if rotation.x > 90 then
+                                                rotation.x = -90
+                                       end
+                                       if rotation.z > 90 then
+                                                rotation.z = -90
+                                       end
+                                       
+                                       --print(rotation.x)
+                                       self.object:set_bone_position(self.head_bone, head_position, rotation)
                                end
-                               if rotation.z > 90 then
-                                        rotation.z = -90
+                               ]]--
+                               
+                               --print(self.head_rotation.y)
+                               --if passed a direction to look
+                               local pos = self.object:get_pos()
+                               local body_yaw = self.object:get_yaw()
+                               
+                               if not body_yaw then
+                                       return
                                end
                                
-                               --print(rotation.x)
-                               self.object:set_bone_position(self.head_bone, head_position, rotation)
-                       end
-                       ]]--
-                       
-                       --print(self.head_rotation.y)
-                       --if passed a direction to look
-                       local pos = self.object:get_pos()
-                       local body_yaw = self.object:get_yaw()
-                       if not body_yaw then
-                               return
-                       end
-                       
-                       local dir = vector.multiply(minetest.yaw_to_dir(body_yaw+self.head_rotation_offset),self.head_directional_offset)
-                       
-                       
-                       local body_yaw = minetest.dir_to_yaw(dir)
-                       
-                       --pos is where the head actually is
-                       pos = vector.add(pos,dir)
-                       pos.y = pos.y + self.head_height_offset
-                       
-                       --use this to literally look around
-                       self.head_pos = pos
-                       
-                       if self.debug_head_pos == true then
-                               minetest.add_particle({
-                                       pos = pos,
-                                       velocity = {x=0, y=0, z=0},
-                                       acceleration = {x=0, y=0, z=0},
-                                       expirationtime = 0.2,
-                                       size = 1,
-                                       texture = "dirt.png",
-                               })
-                       end
-                       
-                       --if the function was given a pos
-                       if pos2 then
-                               --compare the head yaw to the body
-                               local head_yaw = minetest.dir_to_yaw(vector.direction(pos,pos2))
-                               
-                               local goal_yaw = body_yaw-head_yaw
-                               
-                               --if within range then do calculations
-                               if goal_yaw <= math.pi/2 and goal_yaw >= -math.pi/2 then
-                                       ---begin pitch calculation
-                                       --feed a 2D coordinate flipped into dir to yaw to calculate pitch
-                                       head_rotation.x = degrees(minetest.dir_to_yaw(vector.new(vector.distance(vector.new(pos.x,0,pos.z),vector.new(pos2.x,0,pos2.z)),0,pos.y-pos2.y))+(math.pi/2))
-                                       head_rotation.z = degrees(-goal_yaw)
-                                       self.object:set_bone_position(self.head_bone, head_position, head_rotation)
-                                       return(true)
-                               --nothing to look at
-                               else--dofile(path.."movement.lua")
+                               local dir = vector.multiply(minetest.yaw_to_dir(body_yaw+self.head_rotation_offset),self.head_directional_offset)
+                               
+                               
+                               local body_yaw = minetest.dir_to_yaw(dir)
+                               
+                               --pos is where the head actually is
+                               pos = vector.add(pos,dir)
+                               pos.y = pos.y + self.head_height_offset
+                               
+                               --use this to literally look around
+                               self.head_pos = pos
+                               
+                               if self.debug_head_pos == true then
+                                       minetest.add_particle({
+                                               pos = pos,
+                                               velocity = {x=0, y=0, z=0},
+                                               acceleration = {x=0, y=0, z=0},
+                                               expirationtime = 0.2,
+                                               size = 1,
+                                               texture = "dirt.png",
+                                       })
+                               end
+                               
+                               --if the function was given a pos
+                               if pos2 then
+                                       --compare the head yaw to the body
+                                       
+                                       local head_yaw = minetest.dir_to_yaw(vector.direction(pos,pos2))
+                                       
+                                       local goal_yaw = body_yaw-head_yaw
+                                       
+                                       print(goal_yaw)
+                                       
+                                       --if within range then do calculations
+                                       if goal_yaw <= math.pi/2 and goal_yaw >= -math.pi/2 then
+                                               ---begin pitch calculation
+                                               --feed a 2D coordinate flipped into dir to yaw to calculate pitch
+                                               head_rotation.x = degrees(minetest.dir_to_yaw(vector.new(vector.distance(vector.new(pos.x,0,pos.z),vector.new(pos2.x,0,pos2.z)),0,pos.y-pos2.y))+(math.pi/2))
+                                               head_rotation.z = degrees(-goal_yaw)
+                                               self.object:set_bone_position(self.head_bone, head_position, head_rotation)
+                                               return(true)
+                                       --nothing to look at
+                                       else--dofile(path.."movement.lua")
+                                               self.return_head_to_origin(self,dtime)
+                                               return(false)
+                                       end
+                                       
+                               --if nothing to look at
+                               else
                                        self.return_head_to_origin(self,dtime)
                                        return(false)
                                end
+                       --[[
+                       elseif self.head_coord == "vertical" then
+                               
+                               --print(self.head_bone)
+                               local head_position,head_rotation = self.object:get_bone_position(self.head_bone)
+                               
+                               -- debug
+                               if head_rotation then
+                                       print("test")
+                                       --print("--------------------------------")
+                                       --head_rotation.x = head_rotation.x + 1
+                                       head_rotation.y = head_rotation.y + 1
+                                       head_rotation.z = 0
+                                       
+                                       if head_rotation.x > 90 then
+                                                head_rotation.x = -90
+                                       end
+                                       if head_rotation.z > 90 then
+                                                head_rotation.z = -90
+                                       end
+                                       if head_rotation.y > 90 then
+                                                head_rotation.y = -90
+                                       end
+                                       
+                                       --print(rotation.x)
+                                       self.object:set_bone_position(self.head_bone, head_position, head_rotation)
+                               end
+                               
+                               
+                               --print(self.head_rotation.y)
+                               --if passed a direction to look
+                               
+                               local pos = self.object:get_pos()
+                               local body_yaw = self.object:get_yaw()
+                               if not body_yaw then
+                                       return
+                               end
+                               
+                               local dir = vector.multiply(minetest.yaw_to_dir(body_yaw+self.head_rotation_offset),self.head_directional_offset)
+                               
+                               
+                               local body_yaw = minetest.dir_to_yaw(dir)
+                               
+                               --pos is where the head actually is
+                               pos = vector.add(pos,dir)
+                               pos.y = pos.y + self.head_height_offset
+                               
+                               --use this to literally look around
+                               self.head_pos = pos
+                               
+                               if self.debug_head_pos == true then
+                                       minetest.add_particle({
+                                               pos = pos,
+                                               velocity = {x=0, y=0, z=0},
+                                               acceleration = {x=0, y=0, z=0},
+                                               expirationtime = 0.2,
+                                               size = 1,
+                                               texture = "dirt.png",
+                                       })
+                               end
                                
-                       --if nothing to look at
-                       else
-                               self.return_head_to_origin(self,dtime)
-                               return(false)
+                               --if the function was given a pos
+                               if pos2 then
+                                       --compare the head yaw to the body
+                                       local head_yaw = minetest.dir_to_yaw(vector.direction(pos,pos2))
+                                       
+                                       local goal_yaw = body_yaw-head_yaw
+                                       
+                                       if goal_yaw < -math.pi then
+                                               goal_yaw = goal_yaw + math.pi
+                                       elseif goal_yaw > math.pi then
+                                               goal_yaw = goal_yaw - math.pi
+                                       end
+                                       
+                                       print("goal_yaw="..goal_yaw,"body_yaw="..body_yaw,"head_yaw="..head_yaw)
+                                       
+                                       --if within range then do calculations
+                                       if goal_yaw <= math.pi/2 and goal_yaw >= -math.pi/2 then
+                                               ---begin pitch calculation
+                                               --feed a 2D coordinate flipped into dir to yaw to calculate pitch
+                                               head_rotation.x = degrees(minetest.dir_to_yaw(vector.new(vector.distance(vector.new(pos.x,0,pos.z),vector.new(pos2.x,0,pos2.z)),0,pos.y-pos2.y))+(math.pi/2))
+                                               head_rotation.y = degrees(goal_yaw)
+                                               self.object:set_bone_position(self.head_bone, head_position, head_rotation)
+                                               return(true)
+                                       --nothing to look at
+                                       else--dofile(path.."movement.lua")
+                                               self.return_head_to_origin(self,dtime)
+                                               return(false)
+                                       end
+                                       
+                               --if nothing to look at
+                               else
+                                       self.return_head_to_origin(self,dtime)
+                                       return(false)
+                               end
+                               ]]--
                        end
                end
        end
@@ -122,30 +224,55 @@ mobs.create_head_functions = function(def,mob_register)
        --this sets the mob to move it's head back to pointing forwards
 
        mob_register.return_head_to_origin = function(self,dtime)
-               local head_position,head_rotation = self.object:get_bone_position(self.head_bone)               
-               --make the head yaw move back
-               if head_rotation.x > 0 then
-                       head_rotation.x = head_rotation.x - (dtime*100)
-               elseif head_rotation.x < 0 then
-                       head_rotation.x = head_rotation.x + (dtime*100)
-               end
-               
-               if math.abs(head_rotation.x) < (dtime*100) then
-                       head_rotation.x = 0
-               end
-               
+               local head_position,head_rotation = self.object:get_bone_position(self.head_bone)
                
-               --move up down (pitch) back to center
-               if head_rotation.z > 0 then
-                       head_rotation.z = head_rotation.z - (dtime*100)
-               elseif head_rotation.z < 0 then
-                       head_rotation.z = head_rotation.z + (dtime*100)
-               end
-               
-               if math.abs(head_rotation.z) < (dtime*100) then
-                       head_rotation.z = 0
+               if self.head_coord == "horizontal" then 
+                       --make the head yaw move back
+                       if head_rotation.x > 0 then
+                               head_rotation.x = head_rotation.x - (dtime*100)
+                       elseif head_rotation.x < 0 then
+                               head_rotation.x = head_rotation.x + (dtime*100)
+                       end
+                       
+                       if math.abs(head_rotation.x) < (dtime*100) then
+                               head_rotation.x = 0
+                       end
+                       
+                       
+                       --move up down (pitch) back to center
+                       if head_rotation.z > 0 then
+                               head_rotation.z = head_rotation.z - (dtime*100)
+                       elseif head_rotation.z < 0 then
+                               head_rotation.z = head_rotation.z + (dtime*100)
+                       end
+                       
+                       if math.abs(head_rotation.z) < (dtime*100) then
+                               head_rotation.z = 0
+                       end
+               elseif self.head_coord == "vertical" then
+                       --make the head yaw move back
+                       if head_rotation.x > 0 then
+                               head_rotation.x = head_rotation.x - (dtime*100)
+                       elseif head_rotation.x < 0 then
+                               head_rotation.x = head_rotation.x + (dtime*100)
+                       end
+                       
+                       if math.abs(head_rotation.x) < (dtime*100) then
+                               head_rotation.x = 0
+                       end
+                       
+                       
+                       --move up down (pitch) back to center
+                       if head_rotation.y > 0 then
+                               head_rotation.y = head_rotation.y - (dtime*100)
+                       elseif head_rotation.y < 0 then
+                               head_rotation.y = head_rotation.y + (dtime*100)
+                       end
+                       
+                       if math.abs(head_rotation.y) < (dtime*100) then
+                               head_rotation.y = 0
+                       end
                end
-               
                self.object:set_bone_position(self.head_bone, head_position, head_rotation)
        end
        return(mob_register)
index e6a154e67ad0bbdc487fb6fa2141bb2c3b063a67..d658fc6a438ef86a40c4183121ff7ffa585dd2bc 100644 (file)
@@ -257,7 +257,7 @@ mobs.create_interaction_functions = function(def,mob_register)
                                
                                if self.hostile == true then
                                        
-                                       self.direction = vector.direction(vector.new(pos.x,0,pos.z),vector.new(pos2.x,0,pos2.z))
+                                       
                                        local distance = vector.distance(pos,pos2)
                                        
                                        
@@ -298,10 +298,8 @@ mobs.create_interaction_functions = function(def,mob_register)
                                                        end
                                                end
                                        end
-                                       --self.speed = distance * 4
-                                       --if self.speed > self.max_speed then
+                                       self.direction = vector.direction(vector.new(pos.x,0,pos.z),vector.new(pos2.x,0,pos2.z))
                                        self.speed = self.max_speed
-                                       --end
                                        self.following = true
                                end
                                --only look at one player
index 0ac3bf99cfc5c534b70b93fa5b76930b40edfb76..d5cf551ae20af5885b19d902aed8090518ebba98 100644 (file)
@@ -34,7 +34,8 @@ mobs.register_mob(
         head_height_offset = 0.8, --added to the base y position
         head_rotation_offset = math.pi,
         --use this to correct the head position initially because it becomes severly offset - look at your blender model to get this perfect
-        head_position_correction = vector.new(0,3,-0.5), 
+        head_position_correction = vector.new(0,3,-0.5),
+        head_coord = "horizontal",
         -----
         
         is_visible = true,
@@ -283,45 +284,52 @@ mobs.register_mob(
        }
 )
 
-
+]]--
 
 mobs.register_mob(
        {
-        mobname = "exploder",
+        mobname = "creeper",
         physical = true,
         collide_with_objects = false,
-        collisionbox = {-0.37, -0.4, -0.37, 0.37, 0.5, 0.37},
+        collisionbox = {-0.37,0, -0.37, 0.37, 0.5, 0.37},
         visual = "mesh",
-        visual_size = {x = 3, y = 3},
-        mesh = "exploder.b3d",
+        visual_size = {x = 3.2, y = 3.2},
+        mesh = "creeper.b3d",
         textures = {
-               "creepig_body.png","creepig_leg.png","creepig_leg.png","creepig_leg.png","creepig_leg.png"
+               "creeper.png"
        },
         is_visible = true,
         pointable = true,
-        automatic_face_movement_dir = 0,
         automatic_face_movement_max_rotation_per_sec = 300,
         makes_footstep_sound = false,
         hp = 10,
         gravity = {x = 0, y = -9.81, z = 0},
         movement_type = "walk",
-        max_speed = 4,
+        max_speed = 0.1,
         hostile = false,
         state = 0,
         view_distance = 20,
         item_drop = "mob:cooked_porkchop",
          
-        standing_frame = {x=5,y=5},
-        moving_frame = {x=0,y=20},
-        animation_multiplier = 10,
+        standing_frame = {x=0,y=0},
+        moving_frame = {x=0,y=40},
+        animation_multiplier = 20,
         ----
+        
+        
+        --these are used to anchor a point to the head position
+        -----
+        automatic_face_movement_dir = -90,
+        head_bone = "head",
+        debug_head_pos = true,
+        head_directional_offset = 2, --used in vector.multiply(minetest.yaw_to_dir(body_yaw),head_offset)
+        head_height_offset = 1.45, --added to the base y position
+        head_rotation_offset = 0,
+        --use this to correct the head position initially because it becomes severly offset - look at your blender model to get this perfect
+        head_position_correction = vector.new(0,2.4,0),
+        head_coord = "vertical",
+        -----
          
-        has_head = false, --remove this when mesh based head rotation is implemented
-        --head_visual = "mesh",
-        --head_visual_size = {x = 1, y = 1},
-        --head_mesh = "pig_head.x",
-        --head_textures ={"creepig_head.png","creepig_nose.png"},
-        --head_mount = vector.new(0,1.2,1.9),
         
         death_rotation = "x",
         
@@ -340,4 +348,4 @@ mobs.register_mob(
         --die_in_light_level = 12,
        }
 )
-]]--
+
diff --git a/mods/mob/models/creeper.b3d b/mods/mob/models/creeper.b3d
new file mode 100644 (file)
index 0000000..487410e
Binary files /dev/null and b/mods/mob/models/creeper.b3d differ
diff --git a/mods/mob/textures/creeper.png b/mods/mob/textures/creeper.png
new file mode 100644 (file)
index 0000000..5526f91
Binary files /dev/null and b/mods/mob/textures/creeper.png differ