commit
0772634283
11
api.lua
11
api.lua
|
@ -78,7 +78,14 @@ function mobs_goblins:register_mob(name, def)
|
|||
replace_what = def.replace_what,
|
||||
replace_with = def.replace_with,
|
||||
-- or maybe something different?
|
||||
replace_rate_secondary = def.replace_rate_secondary or 0,
|
||||
--
|
||||
-- Zero is a BAD default, as random will not take a 1,0 range.
|
||||
-- The mod fails with an error in the current master.
|
||||
-- I recommend replacing with an unreasonably large number, or
|
||||
-- nil (and changing the random call to check for nil).
|
||||
-- replace_rate_secondary = def.replace_rate_secondary or 0,
|
||||
replace_rate_secondary = def.replace_rate_secondary or 1000000,
|
||||
--
|
||||
replace_with_secondary = def.replace_with_secondary or def.replace_with,
|
||||
timer = 0,
|
||||
env_damage_timer = 0, -- only if state = "attack"
|
||||
|
@ -1731,4 +1738,4 @@ function mobs_goblins:feed_tame(self, clicker, feed_count, breed)
|
|||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
99
goblins.lua
99
goblins.lua
|
@ -1,6 +1,96 @@
|
|||
|
||||
-- Npc by TenPlus1 converted for FLG Goblins :D
|
||||
|
||||
mobs_goblins.goblin_tunneling = function(self, type)
|
||||
-- Types are available for fine-tuning.
|
||||
if type == nil then
|
||||
type = "digger"
|
||||
end
|
||||
|
||||
-- He destroys everything diggable in his path. It's too much trouble
|
||||
-- to fudge around with particulars. Besides, I don't want them to
|
||||
-- mine for me.
|
||||
local diggable_nodes = {"group:stone", "group:sand", "group:soil", "group:cracky", "group:crumbly", "group:choppy", "group:plant"}
|
||||
-- This translates yaw into vectors.
|
||||
local cardinals = {{x=0,y=0,z=0.75}, {x=-0.75,y=0,z=0}, {x=0,y=0,z=-0.75}, {x=0.75,y=0,z=0}}
|
||||
local pos = self.object:getpos()
|
||||
|
||||
if self.state == "tunnel" then
|
||||
-- Yaw is stored as one of the four cardinal directions.
|
||||
if not self.digging_dir then
|
||||
self.digging_dir = math.random(0,3)
|
||||
end
|
||||
|
||||
-- Turn him roughly in the right direction.
|
||||
-- self.object:setyaw(self.digging_dir * math.pi * 0.5 + math.random() * 0.5 - 0.25)
|
||||
self.object:setyaw(self.digging_dir * math.pi * 0.5)
|
||||
|
||||
-- Get a pair of coordinates that should cover what's in front of him.
|
||||
local p = vector.add(pos, cardinals[self.digging_dir+1])
|
||||
p.y = p.y - 0.5 -- What's this about?
|
||||
local p1 = vector.add(p, -0.3)
|
||||
local p2 = vector.add(p, 0.3)
|
||||
|
||||
-- Get any diggable nodes in that area.
|
||||
local np_list = minetest.find_nodes_in_area(p1, p2, diggable_nodes)
|
||||
|
||||
if #np_list > 0 then
|
||||
-- Dig it.
|
||||
for _, np in pairs(np_list) do
|
||||
minetest.remove_node(np)
|
||||
end
|
||||
end
|
||||
|
||||
if math.random() < 0.2 then
|
||||
local d = {-1,1}
|
||||
self.digging_dir = (self.digging_dir + d[math.random(2)]) % 4
|
||||
end
|
||||
|
||||
self:set_animation("walk")
|
||||
self.set_velocity(self, self.walk_velocity)
|
||||
elseif self.state == "room" then -- Dig a room.
|
||||
if not self.room_radius then
|
||||
self.room_radius = 1
|
||||
end
|
||||
|
||||
self:set_animation("stand")
|
||||
self.set_velocity(self, 0)
|
||||
|
||||
-- Work from the inside, out.
|
||||
for r = 1,self.room_radius do
|
||||
-- Get a pair of coordinates that form a room.
|
||||
local p1 = vector.add(pos, -r)
|
||||
local p2 = vector.add(pos, r)
|
||||
-- But not below him.
|
||||
p1.y = pos.y
|
||||
|
||||
local np_list = minetest.find_nodes_in_area(p1, p2, diggable_nodes)
|
||||
|
||||
-- I wanted to leave the outer layer incomplete, but this
|
||||
-- actually tends to make it look worse.
|
||||
if r >= self.room_radius and #np_list == 0 then
|
||||
self.room_radius = math.random(1,2) + math.random(0,1)
|
||||
self.state = "stand"
|
||||
break
|
||||
end
|
||||
|
||||
if #np_list > 0 then
|
||||
-- Dig it.
|
||||
minetest.remove_node(np_list[math.random(#np_list)])
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if self.state == "stand" and math.random() < 0.05 then
|
||||
self.state = "tunnel"
|
||||
elseif self.state == "tunnel" and math.random() < 0.05 then
|
||||
self.state = "room"
|
||||
elseif self.state == "tunnel" and math.random() < 0.1 then
|
||||
self.state = "stand"
|
||||
end
|
||||
end
|
||||
|
||||
mobs_goblins.goblin_drops = {
|
||||
"default:pick_steel", "default:sword_steel",
|
||||
"default:shovel_steel", "farming:bread", "bucket:bucket_water"
|
||||
|
@ -179,7 +269,7 @@ mobs_goblins:register_mob("mobs_goblins:goblin_digger", {
|
|||
search_offset_below = 1.1,
|
||||
search_offset_above = 1,
|
||||
replace_rate = 4,
|
||||
replace_what = {"group:soil","group:sand","default:gravel","default:stone","default:desert_stone","default:torch"},
|
||||
replace_what = {"default:torch"},
|
||||
replace_with = "air",
|
||||
|
||||
view_range = 15,
|
||||
|
@ -246,6 +336,13 @@ mobs_goblins:register_mob("mobs_goblins:goblin_digger", {
|
|||
mobs_goblins:capture_mob(self, clicker, 0, 5, 80, false, nil)
|
||||
end,
|
||||
|
||||
do_custom = function(self)
|
||||
mobs_goblins.goblin_tunneling(self, "digger")
|
||||
|
||||
-- mobs_goblins.search_replace(self.object:getpos(), 5, {"default:torch"}, "air")
|
||||
-- mobs_goblins.search_replace(self.object:getpos(), 10, {"group:stone"}, "default:mossycobble")
|
||||
-- mobs_goblins.search_replace(self.object:getpos(), 50, {"group:stone"}, "mobs_goblins:mossycobble_trap")
|
||||
end,
|
||||
})
|
||||
|
||||
mobs_goblins:register_mob("mobs_goblins:goblin_coal", {
|
||||
|
|
Loading…
Reference in New Issue