]> git.lizzy.rs Git - Crafter.git/commitdiff
Add pig mob and various other improvements
authoroilboi <47129783+oilboi@users.noreply.github.com>
Tue, 18 Feb 2020 15:12:54 +0000 (10:12 -0500)
committeroilboi <47129783+oilboi@users.noreply.github.com>
Tue, 18 Feb 2020 15:12:54 +0000 (10:12 -0500)
18 files changed:
mods/main/mapgen.lua
mods/main/nodes.lua
mods/main/sounds/tool_break.ogg [new file with mode: 0644]
mods/main/tools.lua
mods/minecart/init.lua
mods/minecart/rail.lua
mods/mob/init.lua
mods/mob/items.lua [new file with mode: 0644]
mods/mob/models/pig.b3d [new file with mode: 0644]
mods/mob/models/zombie.b3d [new file with mode: 0644]
mods/mob/sounds/mob_die.ogg [new file with mode: 0644]
mods/mob/spawning.lua [new file with mode: 0644]
mods/mob/textures/cooked_porkchop.png [new file with mode: 0644]
mods/mob/textures/pig.png [new file with mode: 0644]
mods/mob/textures/raw_porkchop.png [new file with mode: 0644]
mods/mob/textures/zombie.png [new file with mode: 0644]
mods/tnt/init.lua
todo.txt

index 47de1ffa7d637872e660d8ef5f0c013cf3a8faa9..d464e825cc84069343591731c9e4fe8a89430283 100644 (file)
@@ -2,7 +2,7 @@ print("Initializing mapgen")
 minetest.register_alias("mapgen_stone", "main:stone")
 minetest.register_alias("mapgen_dirt", "main:dirt")
 minetest.register_alias("mapgen_dirt_with_grass", "main:grass")
-minetest.register_alias("mapgen_water_source", "main:waterSource")
+minetest.register_alias("mapgen_water_source", "main:water")
 minetest.register_alias("mapgen_sand", "main:sand")
 minetest.register_alias("mapgen_tree", "main:tree")
 minetest.register_alias("mapgen_leaves", "main:leaves")
@@ -72,7 +72,7 @@ minetest.register_biome({
                depth_filler = 3,
                node_riverbed = "main:sand",
                depth_riverbed = 2,
-               node_cave_liquid = "main:waterSource",
+               node_cave_liquid = "main:water",
                --node_dungeon = "main:cobble",
                --node_dungeon_alt = "default:mossycobble",
                --node_dungeon_stair = "stairs:stair_cobble",
index b576a564149df253be4923eeb11f90d330ebb3de..6d10f893dbbffb2ad4e303522a29c4ba94963873 100644 (file)
@@ -143,7 +143,7 @@ minetest.register_node("main:leaves", {
     },
 })
 
-minetest.register_node("main:waterSource", {
+minetest.register_node("main:water", {
        description = "Water Source",
        drawtype = "liquid",
        waving = 3,
@@ -179,15 +179,15 @@ minetest.register_node("main:waterSource", {
        drop = "",
        drowning = 1,
        liquidtype = "source",
-       liquid_alternative_flowing = "main:waterFlow",
-       liquid_alternative_source = "main:waterSource",
+       liquid_alternative_flowing = "main:waterflow",
+       liquid_alternative_source = "main:water",
        liquid_viscosity = 1,
        post_effect_color = {a = 103, r = 30, g = 60, b = 90},
        groups = {water = 1, liquid = 1, cools_lava = 1, bucket = 1, source = 1},
        --sounds = default.node_sound_water_defaults(),
 })
 
-minetest.register_node("main:waterFlow", {
+minetest.register_node("main:waterflow", {
        description = "Water Flow",
        drawtype = "flowingliquid",
        waving = 3,
@@ -225,8 +225,8 @@ minetest.register_node("main:waterFlow", {
        drop = "",
        drowning = 1,
        liquidtype = "flowing",
-       liquid_alternative_flowing = "main:waterFlow",
-       liquid_alternative_source = "main:waterSource",
+       liquid_alternative_flowing = "main:waterflow",
+       liquid_alternative_source = "main:water",
        liquid_viscosity = 1,
        post_effect_color = {a = 103, r = 30, g = 60, b = 90},
        groups = {water = 1, liquid = 1, notInCreative = 1, cools_lava = 1},
diff --git a/mods/main/sounds/tool_break.ogg b/mods/main/sounds/tool_break.ogg
new file mode 100644 (file)
index 0000000..0db0119
Binary files /dev/null and b/mods/main/sounds/tool_break.ogg differ
index 9df89d1bdaa08afede5fdff160b18728740cbf9b..31a14585b3b7a7504eac7472d31b455777c66a32 100644 (file)
@@ -9,13 +9,13 @@ for level,material in pairs(material) do
                --print(id,tool,level,material)
                local groupcaps
                if group[id] == "dirt" then
-                       groupcaps2={dirt = {times={[4]=4-level/2,[3]=3.5-level/2,[2]=3.0-level/2,[1]=2.8-level/2}, uses=level*20, maxlevel=level},}
+                       groupcaps2={dirt = {times={[4]=4-level/2,[3]=3.5-level/2,[2]=3.0-level/2,[1]=2.8-level/2}, uses=(level/2)*5, maxlevel=level},}
                end
                if group[id] == "wood" then
-                       groupcaps2={wood = {times={[4]=4-level/2,[3]=3.5-level/2,[2]=3.0-level/2,[1]=2.8-level/2}, uses=level*20, maxlevel=level},}
+                       groupcaps2={wood = {times={[4]=4-level/2,[3]=3.5-level/2,[2]=3.0-level/2,[1]=2.8-level/2}, uses=(level/2)*5, maxlevel=level},}
                end
                if group[id] == "stone" then
-                       groupcaps2={stone = {times={[4]=4-level/2,[3]=3.5-level/2,[2]=3.0-level/2,[1]=2.8-level/2}, uses=level*20, maxlevel=level},}
+                       groupcaps2={stone = {times={[4]=4-level/2,[3]=3.5-level/2,[2]=3.0-level/2,[1]=2.8-level/2}, uses=(level/2)*5, maxlevel=level},}
                end
                minetest.register_tool("main:"..material..tool, {
                        description = material:gsub("^%l", string.upper).." "..tool:gsub("^%l", string.upper),
@@ -26,7 +26,7 @@ for level,material in pairs(material) do
                                groupcaps=groupcaps2,
                                --damage_groups = {fleshy=2},
                        },
-                       sound = {breaks = "default_tool_breaks"}, -- change this
+                       sound = {breaks = {name="tool_break",gain=0.4}}, -- change this
                        groups = {flammable = 2, tool=1 }
                })
        end
@@ -40,7 +40,7 @@ for level,material in pairs(material) do
                        groupcaps={leaves = {times={[4]=0.7,[3]=0.7,[2]=0.7,[1]=0.7}, uses=level*20, maxlevel=4},},
                        damage_groups = {fleshy=3},
                },
-               sound = {breaks = "default_tool_breaks"}, -- change this
+               sound = {breaks = {name="tool_break",gain=0.4}}, -- change this
                groups = {weapon=1 }
        })
 end
index 3016b041330b4e0bf1145bad4ddec3fa195e42bf..87258cc666b9515e6d27a1e04730b6386784f3c6 100644 (file)
@@ -34,6 +34,7 @@ local minecart = {
                visual_size = {x=1, y=1},
                textures = {"minecart.png"},
                automatic_face_movement_dir = 90.0,
+               automatic_face_movement_max_rotation_per_sec = 600,
        },
 
        rider = nil,
index 1d5411283acd14810aad1848a9f38ffcac72d690..8e94f9bee57e494575bbd0647957cc25be63a009 100644 (file)
@@ -23,6 +23,7 @@ minetest.register_node("minecart:rail",{
                if minetest.registered_nodes[minetest.get_node({x=pos.x,y=pos.y-1,z=pos.z}).name].walkable then
                        minetest.set_node(pointed_thing.above, {name="minecart:rail"})
                        itemstack:take_item(1)
+                       print(minetest.get_node(pointed_thing.above).param1)
                        return(itemstack)
                end
        end,
index 7e3b48d4576e6beeeb8376e71f8967b8bc318e1e..768e5a0d8ae09e971f725e47759ca5c3214fdbac 100644 (file)
 --this is where mobs are defined
-local timer = 0
-minetest.register_globalstep(function(dtime)
-       timer = timer + dtime
-       if timer >= 0.5 then
-               timer = 0
-               --check through players
-               for _,player in ipairs(minetest.get_connected_players()) do
-                       --don't spawn near dead players
-                       if player:get_hp() > 0 then
-                       
-                               local mob_number = math.random(0,2)
-                       
-                               local pos = vector.floor(vector.add(player:getpos(),0.5))
-                               
-                               local checkpos = minetest.find_nodes_in_area_under_air(vector.new(pos.x-50,pos.y-50,pos.z-50), vector.new(pos.x+50,pos.y+50,pos.z+50), {"main:grass","main:sand"})
-                               
-                               
-                               --[[
-                               local block = vector.floor(vector.divide(pos,16))
-                               block = vector.multiply(block, 16) --get the chunk actual base
-                               for x = 0,15 do
-                               for y = 0,15 do
-                               for z = 0,15 do
-                                       
-                                       if minetest.get_node(vector.new(block.x+x,block.y+y-1,block.z+z)).name ~= "air" and minetest.get_node(vector.new(block.x+x,block.y+y,block.z+z)).name == "air" then
-                                       
-                                               minetest.add_particle({
-                                                       pos = vector.new(block.x+x,block.y+y,block.z+z),
-                                                       velocity = {x=0, y=0, z=0},
-                                                       acceleration = {x=0, y=0, z=0},
-                                                       -- Spawn particle at pos with velocity and acceleration
 
-                                                       expirationtime = 0.5,
-                                                       -- Disappears after expirationtime seconds
 
-                                                       size = 2,
-                                                       -- Scales the visual size of the particle texture.
+local path = minetest.get_modpath(minetest.get_current_modname())
 
-                                                       collisiondetection = false,
-                                                       -- If true collides with `walkable` nodes and, depending on the
-                                                       -- `object_collision` field, objects too.
+dofile(path.."/spawning.lua")
+dofile(path.."/items.lua")
 
-                                                       collision_removal = false,
-                                                       -- If true particle is removed when it collides.
-                                                       -- Requires collisiondetection = true to have any effect.
+local max_speed = 0.5
 
-                                                       object_collision = false,
-                                                       -- If true particle collides with objects that are defined as
-                                                       -- `physical = true,` and `collide_with_objects = true,`.
-                                                       -- Requires collisiondetection = true to have any effect.
+minetest.register_entity("mob:pig", {
+       initial_properties = {
+               hp_max = 1,
+               physical = true,
+               collide_with_objects = false,
+               collisionbox = {-0.45, -0.01, -0.45, 0.45, 0.865, 0.45},
+               visual = "mesh",
+               visual_size = {x = 3, y = 3},
+               mesh = "pig.b3d",
+               textures = {
+                       "nothing.png", -- baby
+                       "pig.png", -- base
+                       "nothing.png", -- saddle
+               },
+               is_visible = true,
+               pointable = true,
+               automatic_face_movement_dir = -90.0,
+               automatic_face_movement_max_rotation_per_sec = 300,
+       },
 
-                                                       vertical = false,
-                                                       -- If true faces player using y axis only
+       timer = 0,
+       hp = 5,
+       direction_timer = 0,
+       direction_timer_goal = 0,
+       direction_change = false,
+       change_direction = false,
+       speed = 0,
+       direction_goal = vector.new(0,0,0),
 
-                                                       texture = "dirt.png",
 
-                                               })
-                                       end
-                               end
-                               end
-                               end
-                               ]]--
+       get_staticdata = function(self)
+               return minetest.serialize({
+                       --range = self.range,
+                       hp = self.hp,           
+               })
+       end,
+       
+       on_activate = function(self, staticdata, dtime_s)
+               self.object:set_armor_groups({immortal = 1})
+               --self.object:set_velocity({x = math.random(-5,5), y = 5, z = math.random(-5,5)})
+               self.object:set_acceleration({x = 0, y = -9.81, z = 0})
+               if string.sub(staticdata, 1, string.len("return")) == "return" then
+                       local data = minetest.deserialize(staticdata)
+                       if data and type(data) == "table" then
+                               --self.range = data.range
+                               self.hp = data.hp
                        end
                end
-       end
-end)
+               self.object:set_animation({x=0,y=40}, 20, 0, true)
+               self.object:set_hp(self.hp)
+       end,
+               
+       on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, dir)
+               self.jump(self,true)
+               local hurt = tool_capabilities.damage_groups.fleshy
+               local hp = self.object:get_hp()
+               self.object:set_hp(hp-hurt)
+               if hp > 1 then
+                       minetest.sound_play("hurt", {object=self.object, gain = 1.0, max_hear_distance = 60,pitch = math.random(80,100)/100})
+               end
+               self.hp = hp-hurt
+       end,
+       
+       on_death = function(self, killer)
+               local pos = self.object:getpos()
+               pos.y = pos.y + 0.4
+               minetest.sound_play("mob_die", {pos = pos, gain = 1.0})
+               minetest.add_particlespawner({
+                       amount = 40,
+                       time = 0.001,
+                       minpos = pos,
+                       maxpos = pos,
+                       minvel = vector.new(-5,-5,-5),
+                       maxvel = vector.new(5,5,5),
+                       minacc = {x=0, y=0, z=0},
+                       maxacc = {x=0, y=0, z=0},
+                       minexptime = 1.1,
+                       maxexptime = 1.5,
+                       minsize = 1,
+                       maxsize = 2,
+                       collisiondetection = false,
+                       vertical = false,
+                       texture = "smoke.png",
+               })
+               local obj = minetest.add_item(pos,"mob:raw_porkchop")
+               obj:get_luaentity().collection_timer = 2
+       end,
+       
+       --this makes the mob change it's direction when aimlessly walking
+       direction = function(self,dtime)
+               self.direction_timer = self.direction_timer + dtime
+               
+               self.change_direction = false
+               
+               --change direction
+               if self.direction_timer >= self.direction_timer_goal then
+                       --print("changing direction")
+                       self.direction_timer = 0
+                       self.direction_timer_goal = math.random(2,4)
+                       self.change_direction = true
+               end
+       end,
+
+       --this sets a random direction and speed when walking
+       walk_random = function(self)
+               if self.change_direction == true then
+                       self.direction_goal = vector.new(math.random(-2,2),0,math.random(-2,2))
+                       self.speed = math.random(1,2)
+                       
+                       --print(dump(self.direction_goal))
+               end
+       end,
+       
+       
+       --This makes the mob walk at a certain speed
+       move = function(self)
+               local vel = self.object:getvelocity()
+               local goal = self.direction_goal
+               local acceleration = vector.new(goal.x-vel.x,0,goal.z-vel.z)
+               self.object:add_velocity(acceleration)
+       end,
+       
+       --make the mob jump
+       jump = function(self,punched)
+               local pos = self.object:getpos()
+               local ray = Raycast(pos, vector.add(pos,self.direction_goal), false, false)
+               local vel = self.object:getvelocity()
+               
+               if (punched or ray:next()) and minetest.get_node(vector.new(pos.x,pos.y-0.02,pos.z)).name ~= "air" and self.swimming == false then
+                       --print("jump")
+                       local vel = self.object:getvelocity()
+                       local goal = 5
+                       local acceleration = vector.new(0,goal-vel.y,0)
+                       self.object:add_velocity(acceleration)
+               end
+       end,
+
+       --makes the mob swim
+       swim = function(self)
+               local pos = self.object:getpos()
+               pos.y = pos.y + 0.4
+               local node = minetest.get_node(pos).name
+               local vel = self.object:getvelocity()
+               local goal = 1
+               local acceleration = vector.new(0,goal-vel.y,0)
+               self.swimming = false
+               
+               if node == ("main:water" or "main:water_flow") then
+                       self.swimming = true
+                       self.object:add_velocity(acceleration)
+               end
+       end,
+       
+       --sets the mob animation and speed
+       set_animation = function(self)
+               local distance = vector.distance(vector.new(0,0,0), self.direction_goal)
+               self.object:set_animation_frame_speed(distance*20)
+       end,
+
+       on_step = function(self, dtime)
+               self.direction(self,dtime)
+               if not self.path then
+                       self.walk_random(self)
+               end
+               
+               self.move(self)
+               self.swim(self)
+               self.jump(self,false)
+               self.set_animation(self)
+       end,
+})
diff --git a/mods/mob/items.lua b/mods/mob/items.lua
new file mode 100644 (file)
index 0000000..0dcd02b
--- /dev/null
@@ -0,0 +1,17 @@
+--items
+minetest.register_craftitem("mob:raw_porkchop", {
+       description = "Raw Porkchop",
+       inventory_image = "raw_porkchop.png",
+})
+minetest.register_craftitem("mob:cooked_porkchop", {
+       description = "Cooked Porkchop",
+       inventory_image = "cooked_porkchop.png",
+})
+
+--cooking
+minetest.register_craft({
+       type = "cooking",
+       output = "mob:cooked_porkchop",
+       recipe = "mob:raw_porkchop",
+       cooktime = 3,
+})
diff --git a/mods/mob/models/pig.b3d b/mods/mob/models/pig.b3d
new file mode 100644 (file)
index 0000000..8ba5b6a
Binary files /dev/null and b/mods/mob/models/pig.b3d differ
diff --git a/mods/mob/models/zombie.b3d b/mods/mob/models/zombie.b3d
new file mode 100644 (file)
index 0000000..f357f68
Binary files /dev/null and b/mods/mob/models/zombie.b3d differ
diff --git a/mods/mob/sounds/mob_die.ogg b/mods/mob/sounds/mob_die.ogg
new file mode 100644 (file)
index 0000000..2bdaa46
Binary files /dev/null and b/mods/mob/sounds/mob_die.ogg differ
diff --git a/mods/mob/spawning.lua b/mods/mob/spawning.lua
new file mode 100644 (file)
index 0000000..547ca37
--- /dev/null
@@ -0,0 +1,55 @@
+--this is where mob spawning is defined
+
+--spawn mob in a square doughnut shaped radius
+local chance = 20
+local tick = 0.2
+local timer = 0
+--inner and outer part of square donut radius
+local inner = 24
+local outer = 128
+
+minetest.register_globalstep(function(dtime)
+       timer = timer + dtime
+       if timer >= tick and math.random(1,chance) == chance then
+               print("ticking")
+               timer = 0
+               --check through players
+               for _,player in ipairs(minetest.get_connected_players()) do
+                       --don't spawn near dead players
+                       if player:get_hp() > 0 then
+                       
+                               --local mob_number = math.random(0,2)
+                               
+                               local int = {-1,1}
+                               local pos = vector.floor(vector.add(player:getpos(),0.5))
+                               
+                               local x,z
+                               
+                               --this is used to determine the axis buffer from the player
+                               local axis = math.random(0,1)
+                               
+                               --cast towards the direction
+                               if axis == 0 then --x
+                                       x = pos.x + math.random(inner,outer)*int[math.random(1,2)]
+                                       z = pos.z + math.random(-outer,outer)
+                               else --z
+                                       z = pos.z + math.random(inner,outer)*int[math.random(1,2)]
+                                       x = pos.x + math.random(-outer,outer)
+                               end
+                               
+                               
+                               local spawner = minetest.find_nodes_in_area_under_air(vector.new(x,pos.y-32,z), vector.new(x,pos.y+32,z), {"main:grass","main:sand","main:water"})
+                                                       
+                               --print(dump(spawner))
+                               if table.getn(spawner) > 0 then
+                                       local mob_pos = spawner[1]
+                                       mob_pos.y = mob_pos.y + 1
+                                       print("Spawning at: "..minetest.pos_to_string(mob_pos))
+                                       minetest.add_entity(mob_pos,"mob:pig")
+                               end
+                       end
+               end
+       elseif timer > tick then
+               timer = 0
+       end
+end)
diff --git a/mods/mob/textures/cooked_porkchop.png b/mods/mob/textures/cooked_porkchop.png
new file mode 100644 (file)
index 0000000..15683db
Binary files /dev/null and b/mods/mob/textures/cooked_porkchop.png differ
diff --git a/mods/mob/textures/pig.png b/mods/mob/textures/pig.png
new file mode 100644 (file)
index 0000000..715134b
Binary files /dev/null and b/mods/mob/textures/pig.png differ
diff --git a/mods/mob/textures/raw_porkchop.png b/mods/mob/textures/raw_porkchop.png
new file mode 100644 (file)
index 0000000..018702a
Binary files /dev/null and b/mods/mob/textures/raw_porkchop.png differ
diff --git a/mods/mob/textures/zombie.png b/mods/mob/textures/zombie.png
new file mode 100644 (file)
index 0000000..ef85701
Binary files /dev/null and b/mods/mob/textures/zombie.png differ
index add09c1b8e50e446dfe57335110a003323649988..183777fb063318afecbcb256cf83453d06e66214 100644 (file)
@@ -45,7 +45,7 @@ local function tnt(pos,range)
                                local obj = minetest.add_entity(vector.new(pos.x+x,pos.y+y,pos.z+z),"tnt:tnt")
                                obj:get_luaentity().range = 5
                                obj:get_luaentity().timer = math.random(1,10)*math.random()
-                               minetest.sound_play("tnt_ignite", {object=obj, gain = 1.0, max_hear_distance = range*range*range})
+                               --minetest.sound_play("tnt_ignite", {object=obj, gain = 1.0, max_hear_distance = range*range*range})
                        elseif n ~= "air" and n ~= "ignore" then
                                if math.random()>0.99 then
                                        local item = minetest.get_node_drops(n, "main:diamondpick")[1]
@@ -107,6 +107,7 @@ minetest.register_entity("tnt:tnt", {
        },
 
        timer = 5,
+       range = 7,
        
        get_staticdata = function(self)
                return minetest.serialize({
@@ -145,6 +146,7 @@ minetest.register_entity("tnt:tnt", {
                        texture = "smoke.png",
                        attached = self.object,
                })
+               minetest.sound_play("tnt_ignite", {object = self.object, gain = 1.0, max_hear_distance = self.range*self.range*self.range})
        end,
                
        on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, dir)
@@ -183,7 +185,6 @@ minetest.register_node("tnt:tnt", {
                local obj = minetest.add_entity(pos,"tnt:tnt")
                local range = 7
                obj:get_luaentity().range = range
-               minetest.sound_play("tnt_ignite", {object = obj, gain = 1.0, max_hear_distance = range*range*range})
                minetest.remove_node(pos)
     end,
 })
index f24f9b145ef3b5f10f7b71c7f4e17fe8c40627e5..46f8d50ed8c16ab982c04be8f9ea0d31cdc73e77 100644 (file)
--- a/todo.txt
+++ b/todo.txt
 --tnt throw player - and items
 --water flow faster
 --torches with particle
-ladders - only placeable on walls
 make a mob
+ladders - only placeable on walls
+fix torches not deleting particles when mounted node dug
 crafting bench
 fishing
 bows
 3d character
 boat
+shiftclick with tool tries to place torch