Spawn eggs added for admin, Api tweaked

This commit is contained in:
tenplus1 2015-02-07 12:29:23 +00:00
parent 35a2fb14b1
commit 7df63b717e
17 changed files with 175 additions and 99 deletions

View File

@ -28,6 +28,7 @@ This mod contains the following additions:
Changelog:
0.9 - Spawn eggs added for all mobs (admin only, cannot be placed in protected areas)... Api tweaked
0.8 - Added sounds to monster mobs (thanks Cyberpangolin for the sfx) and also chicken sound
0.7 - mobs.protected switch added to api.lua, when set to 1 mobs no longer spawn in protected areas, also bug fixes
0.6 - Api now supports multi-textured mobs, e.g oerkki, dungeon master, rats and chickens have random skins when spawning (sheep fix TODO), also new Honey block

102
api.lua
View File

@ -45,7 +45,7 @@ function mobs:register_mob(name, def)
recovery_time = def.recovery_time or 0.5,
knock_back = def.knock_back or 3,
blood_offset = def.blood_offset or 0,
blood_amount = def.blood_amount or 5, -- 15
blood_amount = def.blood_amount or 5,
blood_texture = def.blood_texture or "mobs_blood.png",
rewards = def.rewards or nil,
animaltype = def.animaltype,
@ -590,7 +590,7 @@ local yaw = 0
local obj = minetest.add_entity(p, self.arrow)
local amount = (vec.x^2+vec.y^2+vec.z^2)^0.5
local v = obj:get_luaentity().velocity
vec.y = vec.y + self.shoot_offset -- was +1, this way shoot aim is accurate
vec.y = vec.y + self.shoot_offset -- this makes shoot aim accurate
vec.x = vec.x*v/amount
vec.y = vec.y*v/amount
vec.z = vec.z*v/amount
@ -602,10 +602,7 @@ local yaw = 0
on_activate = function(self, staticdata, dtime_s)
-- reset HP
local pos = self.object:getpos()
local distance_rating = ( ( get_distance({x=0,y=0,z=0},pos) ) / 20000 )
local newHP = self.hp_min + math.floor( self.hp_max * distance_rating )
self.object:set_hp( newHP )
self.object:set_hp( math.random(self.hp_min, self.hp_max) )
self.object:set_armor_groups({fleshy=self.armor})
self.object:setacceleration({x=0, y=-10, z=0})
self.state = "stand"
@ -666,49 +663,6 @@ local yaw = 0
-- minetest.sound_play(self.sounds.death,{
-- object = self.object,
-- })
-- end
-- if minetest.get_modpath("skills") and minetest.get_modpath("experience") then
-- -- DROP experience
-- local distance_rating = ( ( get_distance({x=0,y=0,z=0},pos) ) / ( skills.get_player_level(hitter:get_player_name()).level * 1000 ) )
-- local emax = math.floor( self.exp_min + ( distance_rating * self.exp_max ) )
-- local expGained = math.random(self.exp_min, emax)
-- skills.add_exp(hitter:get_player_name(),expGained)
-- local expStack = experience.exp_to_items(expGained)
-- for _,stack in ipairs(expStack) do
-- default.drop_item(pos,stack)
-- end
-- end
-- -- see if there are any NPCs to shower you with rewards
-- if self.type ~= "npc" then
-- local inradius = minetest.get_objects_inside_radius(hitter:getpos(),10)
-- for _, oir in pairs(inradius) do
-- local obj = oir:get_luaentity()
-- if obj then
-- if obj.type == "npc" and obj.rewards ~= nil then
-- local yaw = nil
-- local lp = hitter:getpos()
-- local s = obj.object:getpos()
-- local vec = {x=lp.x-s.x, y=1, z=lp.z-s.z}
-- yaw = math.atan(vec.z/vec.x)+math.pi/2
-- if self.drawtype == "side" then
-- yaw = yaw+(math.pi/2)
-- end
-- if lp.x > s.x then
-- yaw = yaw+math.pi
-- end
-- obj.object:setyaw(yaw)
-- local x = math.sin(yaw) * -2
-- local z = math.cos(yaw) * 2
-- acc = {x=x, y=-5, z=z}
-- for _, r in pairs(obj.rewards) do
-- if math.random(0,100) < r.chance then
-- default.drop_item(obj.object:getpos(),r.item, vec, acc)
-- end
-- end
-- end
-- end
-- end
-- end
end
@ -780,7 +734,7 @@ local yaw = 0
end
mobs.spawning_mobs = {}
function mobs:register_spawn(name, nodes, max_light, min_light, chance, active_object_count, max_height, min_dist, max_dist, spawn_func)
function mobs:register_spawn(name, nodes, max_light, min_light, chance, active_object_count, max_height)
mobs.spawning_mobs[name] = true
minetest.register_abm({
nodenames = nodes,
@ -795,8 +749,8 @@ function mobs:register_spawn(name, nodes, max_light, min_light, chance, active_o
return
end
-- Check if protected area using bogus name so mobs will not spawn
if mobs.protected == 1 and minetest.is_protected(pos, "-") then
-- Check if protected area mobs will not spawn
if mobs.protected == 1 and minetest.is_protected(pos, "") then
return
end
@ -809,48 +763,24 @@ function mobs:register_spawn(name, nodes, max_light, min_light, chance, active_o
return
end
if not minetest.registered_nodes[minetest.get_node(pos).name]
or minetest.registered_nodes[minetest.get_node(pos).name].walkable then
return
end
if minetest.registered_nodes[minetest.get_node(pos).name].walkable then return end
pos.y = pos.y+1
if not minetest.registered_nodes[minetest.get_node(pos).name]
or minetest.registered_nodes[minetest.get_node(pos).name].walkable then
return
end
if minetest.registered_nodes[minetest.get_node(pos).name].walkable then return end
pos.y = pos.y-1
if min_dist == nil then
min_dist = {x=-1,z=-1}
end
if max_dist == nil then
max_dist = {x=33000,z=33000}
end
if math.abs(pos.x) < min_dist.x or math.abs(pos.z) < min_dist.z
or math.abs(pos.x) > max_dist.x or math.abs(pos.z) > max_dist.z then
return
end
if spawn_func and not spawn_func(pos, node) then
return
end
if minetest.setting_getbool("display_mob_spawn") then
minetest.chat_send_all("[mobs] Add "..name.." at "..minetest.pos_to_string(pos))
end
local mob = minetest.add_entity(pos, name)
-- setup the hp, armor, drops, etc... for this specific mob
local distance_rating = ( ( get_distance({x=0,y=0,z=0},pos) ) / 15000 )
-- set mob hp
if mob then
mob = mob:get_luaentity()
local newHP = mob.hp_min + math.floor( mob.hp_max * distance_rating )
mob.object:set_hp( newHP )
mob.object:set_hp( math.random(mob.hp_min, mob.hp_max) )
end
end
})
@ -869,14 +799,13 @@ function mobs:register_arrow(name, def)
on_step = function(self, dtime)
local pos = self.object:getpos()
--if minetest.get_node(self.object:getpos()).name ~= "air" then
local node = minetest.get_node(self.object:getpos()).name
if minetest.registered_nodes[node].walkable then
self.hit_node(self, pos, node)
self.object:remove()
return
end
-- pos.y = pos.y-1.0
for _,player in pairs(minetest.get_objects_inside_radius(pos, 1)) do
if player:is_player() then
self.hit_player(self, player)
@ -888,14 +817,6 @@ function mobs:register_arrow(name, def)
})
end
function get_distance(pos1,pos2)
if ( pos1 ~= nil and pos2 ~= nil ) then
return math.abs(math.floor(math.sqrt( (pos1.x - pos2.x)^2 + (pos1.z - pos2.z)^2 )))
else
return 0
end
end
function process_weapon(player, time_from_last_punch, tool_capabilities)
local weapon = player:get_wielded_item()
if tool_capabilities ~= nil then
@ -915,4 +836,3 @@ local weapon = player:get_wielded_item()
-- })
-- end
end

View File

@ -49,12 +49,13 @@ passive = true,
})
mobs:register_spawn("mobs:bee", {"group:flower"}, 20, 4, 5000, 1, 31000)
-- Spawn Egg
minetest.register_craftitem("mobs:bee", {
description = "bee",
inventory_image = "mobs_bee_inv.png",
on_place = function(itemstack, placer, pointed_thing)
if pointed_thing.above then
if pointed_thing.above and not minetest.is_protected(pointed_thing.above, "") then
minetest.env:add_entity(pointed_thing.above, "mobs:bee")
itemstack:take_item()
end

View File

@ -58,14 +58,13 @@ mobs:register_mob("mobs:chicken", {
mobs:register_spawn("mobs:chicken", {"default:dirt_with_grass", "ethereal:bamboo_dirt"}, 20, 8, 9000, 1, 31000)
-- Chicken (right-click chicken to place in inventory)
-- Chicken (right-click to place chicken)
minetest.register_craftitem("mobs:chicken", {
description = "Chicken",
inventory_image = "mobs_chicken_inv.png",
on_place = function(itemstack, placer, pointed_thing)
if pointed_thing.above then
if pointed_thing.above and not minetest.is_protected(pointed_thing.above, "") then
minetest.env:add_entity(pointed_thing.above, "mobs:chicken")
itemstack:take_item()
end

13
cow.lua
View File

@ -133,3 +133,16 @@ minetest.register_craft({
{'mobs:cheeseblock'},
}
})
-- Spawn Egg
minetest.register_craftitem("mobs:cow", {
description = "Cow Spawn Egg",
inventory_image = "default_grass.png^mobs_chicken_egg.png",
on_place = function(itemstack, placer, pointed_thing)
if pointed_thing.above and not minetest.is_protected(pointed_thing.above, "") then
minetest.env:add_entity(pointed_thing.above, "mobs:cow")
itemstack:take_item()
end
return itemstack
end,
})

View File

@ -51,3 +51,16 @@ mobs:register_mob("mobs:dirt_monster", {
blood_texture = "default_dirt.png",
})
mobs:register_spawn("mobs:dirt_monster", {"default:dirt_with_grass", "ethereal:gray_dirt_top"}, 3, -1, 7000, 1, 31000)
-- Spawn Egg
minetest.register_craftitem("mobs:dirt_monster", {
description = "Dirt Monster Egg",
inventory_image = "default_dirt.png^mobs_chicken_egg.png",
on_place = function(itemstack, placer, pointed_thing)
if pointed_thing.above and not minetest.is_protected(pointed_thing.above, "") then
minetest.env:add_entity(pointed_thing.above, "mobs:dirt_monster")
itemstack:take_item()
end
return itemstack
end,
})

View File

@ -109,3 +109,16 @@ mobs:register_arrow("mobs:fireball", {
end
end
})
-- Spawn Egg
minetest.register_craftitem("mobs:dungeon_master", {
description = "Dungeon Master Egg",
inventory_image = "fire_basic_flame.png^mobs_chicken_egg.png",
on_place = function(itemstack, placer, pointed_thing)
if pointed_thing.above and not minetest.is_protected(pointed_thing.above, "") then
minetest.env:add_entity(pointed_thing.above, "mobs:dungeon_master")
itemstack:take_item()
end
return itemstack
end,
})

View File

@ -61,3 +61,16 @@ mobs:register_mob("mobs:lava_flan", {
blood_texture = "fire_basic_flame.png",
})
mobs:register_spawn("mobs:lava_flan", {"default:lava_source"}, 15, -1, 1000, 3, 0)
-- Spawn Egg
minetest.register_craftitem("mobs:lava_flan", {
description = "Lava Flan Egg",
inventory_image = "default_lava.png^mobs_chicken_egg.png",
on_place = function(itemstack, placer, pointed_thing)
if pointed_thing.above and not minetest.is_protected(pointed_thing.above, "") then
minetest.env:add_entity(pointed_thing.above, "mobs:lava_flan")
itemstack:take_item()
end
return itemstack
end,
})

View File

@ -92,3 +92,16 @@ mobs:register_arrow("mobs:mese_arrow", {
hit_node = function(self, pos, node)
end
})
-- Spawn Egg
minetest.register_craftitem("mobs:mese_monster", {
description = "Mese Monster Egg",
inventory_image = "default_mese_block.png^mobs_chicken_egg.png",
on_place = function(itemstack, placer, pointed_thing)
if pointed_thing.above and not minetest.is_protected(pointed_thing.above, "") then
minetest.env:add_entity(pointed_thing.above, "mobs:mese_monster")
itemstack:take_item()
end
return itemstack
end,
})

View File

@ -53,3 +53,16 @@ mobs:register_mob("mobs:oerkki", {
blood_texture = "mobs_blood.png",
})
mobs:register_spawn("mobs:oerkki", {"default:stone"}, 2, -1, 7000, 1, -10)
-- Spawn Egg
minetest.register_craftitem("mobs:oerkki", {
description = "Oerkki Egg",
inventory_image = "default_obsidian.png^mobs_chicken_egg.png",
on_place = function(itemstack, placer, pointed_thing)
if pointed_thing.above and not minetest.is_protected(pointed_thing.above, "") then
minetest.env:add_entity(pointed_thing.above, "mobs:oerkki")
itemstack:take_item()
end
return itemstack
end,
})

View File

@ -38,14 +38,13 @@ passive = true,
})
mobs:register_spawn("mobs:rat", {"default:stone"}, 20, -1, 7000, 1, 31000)
-- Can Right-click Rat to Pick Up
-- Spawn Egg
minetest.register_craftitem("mobs:rat", {
description = "Rat",
inventory_image = "mobs_rat_inventory.png",
on_place = function(itemstack, placer, pointed_thing)
if pointed_thing.above then
if pointed_thing.above and not minetest.is_protected(pointed_thing.above, "") then
minetest.env:add_entity(pointed_thing.above, "mobs:rat")
itemstack:take_item()
end

View File

@ -52,3 +52,16 @@ mobs:register_mob("mobs:sand_monster", {
blood_texture = "mobs_blood.png",
})
mobs:register_spawn("mobs:sand_monster", {"default:desert_sand"}, 20, -1, 7000, 1, 31000)
-- Spawn Egg
minetest.register_craftitem("mobs:sand_monster", {
description = "Sand Monster Egg",
inventory_image = "default_desert_sand.png^mobs_chicken_egg.png",
on_place = function(itemstack, placer, pointed_thing)
if pointed_thing.above and not minetest.is_protected(pointed_thing.above, "") then
minetest.env:add_entity(pointed_thing.above, "mobs:sand_monster")
itemstack:take_item()
end
return itemstack
end,
})

View File

@ -75,3 +75,16 @@ mobs:register_mob("mobs:sheep", {
end,
})
mobs:register_spawn("mobs:sheep", {"default:dirt_with_grass", "ethereal:green_dirt_top"}, 20, 8, 9000, 1, 31000)
-- Spawn Egg
minetest.register_craftitem("mobs:sheep", {
description = "Sheep Spawn Egg",
inventory_image = "wool_white.png^mobs_chicken_egg.png",
on_place = function(itemstack, placer, pointed_thing)
if pointed_thing.above and not minetest.is_protected(pointed_thing.above, "") then
minetest.env:add_entity(pointed_thing.above, "mobs:sheep")
itemstack:take_item()
end
return itemstack
end,
})

View File

@ -94,3 +94,16 @@ minetest.register_craft({
{"farming:string", "farming:string", "farming:string"},
}
})
-- Spawn Egg
minetest.register_craftitem("mobs:spider", {
description = "Spider Egg",
inventory_image = "mobs_cobweb.png^mobs_chicken_egg.png",
on_place = function(itemstack, placer, pointed_thing)
if pointed_thing.above and not minetest.is_protected(pointed_thing.above, "") then
minetest.env:add_entity(pointed_thing.above, "mobs:spider")
itemstack:take_item()
end
return itemstack
end,
})

View File

@ -60,3 +60,16 @@ mobs:register_mob("mobs:stone_monster", {
blood_texture = "mobs_blood.png",
})
mobs:register_spawn("mobs:stone_monster", {"default:stone"}, 3, -1, 7000, 1, 0)
-- Spawn Egg
minetest.register_craftitem("mobs:stone_monster", {
description = "Stone Monster Egg",
inventory_image = "default_stone.png^mobs_chicken_egg.png",
on_place = function(itemstack, placer, pointed_thing)
if pointed_thing.above and not minetest.is_protected(pointed_thing.above, "") then
minetest.env:add_entity(pointed_thing.above, "mobs:stone_monster")
itemstack:take_item()
end
return itemstack
end,
})

View File

@ -69,3 +69,16 @@ if not minetest.get_modpath("ethereal") then
minetest.register_alias("ethereal:tree_sapling", "default:sapling")
minetest.register_alias("ethereal:jungle_tree_sapling", "default:junglesapling")
end
-- Spawn Egg
minetest.register_craftitem("mobs:tree_monster", {
description = "Tree Monster Egg",
inventory_image = "default_tree_top.png^mobs_chicken_egg.png",
on_place = function(itemstack, placer, pointed_thing)
if pointed_thing.above and not minetest.is_protected(pointed_thing.above, "") then
minetest.env:add_entity(pointed_thing.above, "mobs:tree_monster")
itemstack:take_item()
end
return itemstack
end,
})

View File

@ -81,3 +81,16 @@ minetest.register_craft({
recipe = "mobs:pork_raw",
cooktime = 5,
})
-- Spawn Egg
minetest.register_craftitem("mobs:warthog", {
description = "Warthog Egg",
inventory_image = "wool_pink.png^mobs_chicken_egg.png",
on_place = function(itemstack, placer, pointed_thing)
if pointed_thing.above and not minetest.is_protected(pointed_thing.above, "") then
minetest.env:add_entity(pointed_thing.above, "mobs:pumba")
itemstack:take_item()
end
return itemstack
end,
})