1
0
mirror of https://github.com/sys4-fr/server-nalc.git synced 2024-11-17 15:58:26 +01:00

Added cow dung - O_o?

This commit is contained in:
LeMagnesium 2015-05-18 18:49:26 +02:00
parent 8fd91ad8c2
commit 75da167428
4 changed files with 94 additions and 45 deletions

View File

@ -61,10 +61,7 @@ lifetimer = def.lifetimer or 600,
blood_texture = def.blood_texture or "mobs_blood.png", blood_texture = def.blood_texture or "mobs_blood.png",
shoot_offset = def.shoot_offset or 0, shoot_offset = def.shoot_offset or 0,
floats = def.floats or 1, -- floats in water by default floats = def.floats or 1, -- floats in water by default
replace_rate = def.replace_rate, replacements = def.replacements or {},
replace_what = def.replace_what,
replace_with = def.replace_with,
replace_offset = def.replace_offset or 0,
timer = 0, timer = 0,
env_damage_timer = 0, -- only if state = "attack" env_damage_timer = 0, -- only if state = "attack"
attack = {player=nil, dist=nil}, attack = {player=nil, dist=nil},
@ -86,7 +83,7 @@ lifetimer = def.lifetimer or 600,
self.attack.dist = dist self.attack.dist = dist
end end
end, end,
set_velocity = function(self, v) set_velocity = function(self, v)
if not v then v = 0 end if not v then v = 0 end
if def.drawtype and def.drawtype == "side" then self.rotate = 1.5 end if def.drawtype and def.drawtype == "side" then self.rotate = 1.5 end
@ -95,7 +92,7 @@ lifetimer = def.lifetimer or 600,
local z = math.cos(yaw) * v local z = math.cos(yaw) * v
self.object:setvelocity({x=x, y=self.object:getvelocity().y, z=z}) self.object:setvelocity({x=x, y=self.object:getvelocity().y, z=z})
end, end,
get_velocity = function(self) get_velocity = function(self)
local v = self.object:getvelocity() local v = self.object:getvelocity()
return (v.x^2 + v.z^2)^(0.5) return (v.x^2 + v.z^2)^(0.5)
@ -110,11 +107,11 @@ lifetimer = def.lifetimer or 600,
local ps = math.sqrt(pos.x^2 + pos.z^2) local ps = math.sqrt(pos.x^2 + pos.z^2)
local d = { x = vx / ds, z = vz / ds } local d = { x = vx / ds, z = vz / ds }
local p = { x = pos.x / ps, z = pos.z / ps } local p = { x = pos.x / ps, z = pos.z / ps }
local an = ( d.x * p.x ) + ( d.z * p.z ) local an = ( d.x * p.x ) + ( d.z * p.z )
a = math.deg( math.acos( an ) ) a = math.deg( math.acos( an ) )
if a > ( self.fov / 2 ) then if a > ( self.fov / 2 ) then
return false return false
else else
@ -155,7 +152,7 @@ lifetimer = def.lifetimer or 600,
end end
end end
end, end,
on_step = function(self, dtime) on_step = function(self, dtime)
local yaw = 0 local yaw = 0
@ -180,16 +177,28 @@ lifetimer = def.lifetimer or 600,
end end
-- check for mob drop/replace (used for chicken egg and sheep eating grass/wheat) -- check for mob drop/replace (used for chicken egg and sheep eating grass/wheat)
if self.replace_rate --[[
and math.random(1,self.replace_rate) == 1 old fields :
and self.child == false then replace_rate = def.replace_rate,
local pos = self.object:getpos() replace_what = def.replace_what,
pos.y = pos.y + self.replace_offset replace_with = def.replace_with,
if #minetest.find_nodes_in_area(pos,pos,self.replace_what) > 0 replace_offset = def.replace_offset or 0,
and self.object:getvelocity().y == 0 ]]--
and self.replace_what then for _, fields in pairs(self.replacements) do
--and self.state == "stand" then
minetest.set_node(pos, {name = self.replace_with}) if fields.replace_rate
and math.random(1,fields.replace_rate) == 1
and self.child == false then
fields.replace_offset = fields.replace_offset or 0
local pos = self.object:getpos()
pos.y = pos.y + fields.replace_offset
if #minetest.find_nodes_in_area(pos,pos,fields.replace_what) > 0
and self.object:getvelocity().y == 0
and fields.replace_what then
minetest.set_node(pos, {name = fields.replace_with})
end
end end
end end
@ -221,7 +230,7 @@ lifetimer = def.lifetimer or 600,
end end
self.old_y = self.object:getpos().y self.old_y = self.object:getpos().y
end end
-- knockback timer -- knockback timer
if self.pause_timer > 0 then if self.pause_timer > 0 then
self.pause_timer = self.pause_timer - dtime self.pause_timer = self.pause_timer - dtime
@ -230,7 +239,7 @@ lifetimer = def.lifetimer or 600,
end end
return return
end end
-- attack timer -- attack timer
self.timer = self.timer + dtime self.timer = self.timer + dtime
if self.state ~= "attack" then if self.state ~= "attack" then
@ -243,7 +252,7 @@ lifetimer = def.lifetimer or 600,
if self.sounds.random and math.random(1, 100) <= 1 then if self.sounds.random and math.random(1, 100) <= 1 then
minetest.sound_play(self.sounds.random, {object = self.object}) minetest.sound_play(self.sounds.random, {object = self.object})
end end
local do_env_damage = function(self) local do_env_damage = function(self)
local pos = self.object:getpos() local pos = self.object:getpos()
@ -264,7 +273,7 @@ lifetimer = def.lifetimer or 600,
self.object:set_hp(self.object:get_hp()-self.water_damage) self.object:set_hp(self.object:get_hp()-self.water_damage)
effect(pos, 5, "bubble.png") effect(pos, 5, "bubble.png")
end end
if self.lava_damage and self.lava_damage ~= 0 if self.lava_damage and self.lava_damage ~= 0
and minetest.get_item_group(n.name, "lava") ~= 0 then and minetest.get_item_group(n.name, "lava") ~= 0 then
self.object:set_hp(self.object:get_hp()-self.lava_damage) self.object:set_hp(self.object:get_hp()-self.lava_damage)
@ -273,7 +282,7 @@ lifetimer = def.lifetimer or 600,
check_for_death(self) check_for_death(self)
end end
local do_jump = function(self) local do_jump = function(self)
local pos = self.object:getpos() local pos = self.object:getpos()
pos.y = pos.y - (-self.collisionbox[2] + self.collisionbox[5]) pos.y = pos.y - (-self.collisionbox[2] + self.collisionbox[5])
@ -298,7 +307,7 @@ lifetimer = def.lifetimer or 600,
end end
end end
end end
-- environmental damage timer -- environmental damage timer
self.env_damage_timer = self.env_damage_timer + dtime self.env_damage_timer = self.env_damage_timer + dtime
if self.state == "attack" and self.env_damage_timer > 1 then if self.state == "attack" and self.env_damage_timer > 1 then
@ -307,7 +316,7 @@ lifetimer = def.lifetimer or 600,
elseif self.state ~= "attack" then elseif self.state ~= "attack" then
do_env_damage(self) do_env_damage(self)
end end
-- find someone to attack -- find someone to attack
if self.type == "monster" and damage_enabled and self.state ~= "attack" then if self.type == "monster" and damage_enabled and self.state ~= "attack" then
@ -331,7 +340,7 @@ lifetimer = def.lifetimer or 600,
type = obj.type type = obj.type
end end
end end
if type == "player" or type == "npc" then if type == "player" or type == "npc" then
local s = self.object:getpos() local s = self.object:getpos()
local p = player:getpos() local p = player:getpos()
@ -354,7 +363,7 @@ lifetimer = def.lifetimer or 600,
self.do_attack(self, min_player, min_dist) self.do_attack(self, min_player, min_dist)
end end
end end
-- npc, find closest monster to attack -- npc, find closest monster to attack
local min_dist = self.view_range + 1 local min_dist = self.view_range + 1
local min_player = nil local min_player = nil
@ -517,7 +526,7 @@ lifetimer = def.lifetimer or 600,
if self.type == "npc" then if self.type == "npc" then
local o = minetest.get_objects_inside_radius(self.object:getpos(), 3) local o = minetest.get_objects_inside_radius(self.object:getpos(), 3)
local yaw = 0 local yaw = 0
for _,o in ipairs(o) do for _,o in ipairs(o) do
if o:is_player() then if o:is_player() then
@ -533,7 +542,7 @@ lifetimer = def.lifetimer or 600,
if lp.x > s.x then if lp.x > s.x then
yaw = yaw+math.pi yaw = yaw+math.pi
end end
else else
yaw = self.object:getyaw()+((math.random(0,360)-180)/180*math.pi) yaw = self.object:getyaw()+((math.random(0,360)-180)/180*math.pi)
end end
self.object:setyaw(yaw) self.object:setyaw(yaw)
@ -567,7 +576,7 @@ lifetimer = def.lifetimer or 600,
local s = self.object:getpos() local s = self.object:getpos()
-- if there is water nearby, try to avoid it -- if there is water nearby, try to avoid it
local lp = minetest.find_node_near(s, 2, {"group:water"}) local lp = minetest.find_node_near(s, 2, {"group:water"})
if lp ~= nil then if lp ~= nil then
local vec = {x=lp.x-s.x, y=lp.y-s.y, z=lp.z-s.z} local vec = {x=lp.x-s.x, y=lp.y-s.y, z=lp.z-s.z}
yaw = math.atan(vec.z/vec.x) + 3*math.pi / 2 + self.rotate yaw = math.atan(vec.z/vec.x) + 3*math.pi / 2 + self.rotate
@ -594,7 +603,7 @@ lifetimer = def.lifetimer or 600,
end end
-- exploding mobs -- exploding mobs
elseif self.state == "attack" and self.attack_type == "explode" then elseif self.state == "attack" and self.attack_type == "explode" then
if not self.attack.player or not self.attack.player:is_player() then if not self.attack.player or not self.attack.player:is_player() then
self.state = "stand" self.state = "stand"
self:set_animation("stand") self:set_animation("stand")
@ -618,7 +627,7 @@ lifetimer = def.lifetimer or 600,
self:set_animation("walk") self:set_animation("walk")
self.attack.dist = dist self.attack.dist = dist
end end
local vec = {x = p.x -s.x, y = p.y -s.y, z = p.z -s.z} local vec = {x = p.x -s.x, y = p.y -s.y, z = p.z -s.z}
local yaw = math.atan(vec.z/vec.x)+math.pi/2 + self.rotate local yaw = math.atan(vec.z/vec.x)+math.pi/2 + self.rotate
if p.x > s.x then if p.x > s.x then
@ -694,7 +703,7 @@ lifetimer = def.lifetimer or 600,
else else
self.attack.dist = dist self.attack.dist = dist
end end
local vec = {x=p.x-s.x, y=p.y-s.y, z=p.z-s.z} local vec = {x=p.x-s.x, y=p.y-s.y, z=p.z-s.z}
local yaw = (math.atan(vec.z/vec.x)+math.pi/2) + self.rotate local yaw = (math.atan(vec.z/vec.x)+math.pi/2) + self.rotate
if p.x > s.x then if p.x > s.x then
@ -759,7 +768,7 @@ lifetimer = def.lifetimer or 600,
else else
self.attack.dist = dist self.attack.dist = dist
end end
local vec = {x=p.x-s.x, y=p.y-s.y, z=p.z-s.z} local vec = {x=p.x-s.x, y=p.y-s.y, z=p.z-s.z}
local yaw = (math.atan(vec.z/vec.x)+math.pi/2) + self.rotate local yaw = (math.atan(vec.z/vec.x)+math.pi/2) + self.rotate
if p.x > s.x then if p.x > s.x then
@ -767,7 +776,7 @@ lifetimer = def.lifetimer or 600,
end end
self.object:setyaw(yaw) self.object:setyaw(yaw)
self.set_velocity(self, 0) self.set_velocity(self, 0)
if self.shoot_interval and self.timer > self.shoot_interval and math.random(1, 100) <= 60 then if self.shoot_interval and self.timer > self.shoot_interval and math.random(1, 100) <= 60 then
self.timer = 0 self.timer = 0
@ -913,7 +922,7 @@ lifetimer = def.lifetimer or 600,
kb = kb * ( tflp / tool_capabilities.full_punch_interval ) kb = kb * ( tflp / tool_capabilities.full_punch_interval )
r = r * ( tflp / tool_capabilities.full_punch_interval ) r = r * ( tflp / tool_capabilities.full_punch_interval )
end end
if v.y ~= 0 then ykb = 0 end if v.y ~= 0 then ykb = 0 end
self.object:setvelocity({x=dir.x*kb,y=ykb,z=dir.z*kb}) self.object:setvelocity({x=dir.x*kb,y=ykb,z=dir.z*kb})
self.pause_timer = r self.pause_timer = r
@ -949,7 +958,7 @@ function mobs:spawn_specific(name, nodes, neighbors, min_light, max_light, inter
action = function(pos, node, _, active_object_count_wider) action = function(pos, node, _, active_object_count_wider)
-- do not spawn if too many active in area -- do not spawn if too many active in area
if active_object_count_wider > active_object_count if active_object_count_wider > active_object_count
or not mobs.spawning_mobs[name] or not mobs.spawning_mobs[name]
or not pos then or not pos then
return return
end end

View File

@ -56,9 +56,13 @@ mobs:register_mob("mobs:chicken", {
follow = "farming:seed_wheat", follow = "farming:seed_wheat",
view_range = 8, view_range = 8,
-- replace air with egg (lay) -- replace air with egg (lay)
replace_rate = 2000, replacements = {
replace_what = {"air"}, {
replace_with = "mobs:egg", replace_rate = 2000,
replace_what = {"air"},
replace_with = "mobs:egg",
}
},
-- right click to pick up chicken -- right click to pick up chicken
on_rightclick = function(self, clicker) on_rightclick = function(self, clicker)
local tool = clicker:get_wielded_item() local tool = clicker:get_wielded_item()

View File

@ -53,9 +53,19 @@ mobs:register_mob("mobs:cow", {
-- follows wheat -- follows wheat
follow = "farming:wheat", view_range = 8, follow = "farming:wheat", view_range = 8,
-- replace grass/wheat with air (eat) -- replace grass/wheat with air (eat)
replace_rate = 50, replacements = {
replace_what = {"default:grass_3", "default:grass_4", "default:grass_5", "farming:wheat_8"}, {
replace_with = "air", replace_rate = 50,
replace_what = {"default:grass_3", "default:grass_4",
"default:grass_5", "farming:wheat_8"},
replace_with = "air",
},
{
replace_rate = 2000,
replace_what = {"air"},
replace_with = "mobs:dung",
}
},
-- right-click cow with empty bucket to get milk, then feed 8 wheat to replenish milk -- right-click cow with empty bucket to get milk, then feed 8 wheat to replenish milk
on_rightclick = function(self, clicker) on_rightclick = function(self, clicker)
local tool = clicker:get_wielded_item() local tool = clicker:get_wielded_item()
@ -169,3 +179,29 @@ minetest.register_craft({
{'mobs:cheeseblock'}, {'mobs:cheeseblock'},
} }
}) })
-- Dung
-- O_o?
minetest.register_node("mobs:dung", {
description = "Cow dung",
tiles = {"mobs_dung.png"},
inventory_image = "mobs_dung.png",
visual_scale = 0.7,
drawtype = "plantlike",
wield_image = "mobs_dung.png",
paramtype = "light",
walkable = false,
is_ground_content = true,
sunlight_propagates = true,
selection_box = {
type = "fixed",
fixed = {-0.2, -0.5, -0.2, 0.2, 0, 0.2}
},
groups = {snappy=2, dig_immediate=3},
after_place_node = function(pos, placer, itemstack)
if placer:is_player() then
minetest.set_node(pos, {name="mobs:dung", param2=1})
end
end
})

Binary file not shown.

After

Width:  |  Height:  |  Size: 635 B