mirror of
https://codeberg.org/tenplus1/mobs_redo.git
synced 2024-12-24 01:30:22 +01:00
Updated replace function with new tables
This commit is contained in:
parent
c1c17a6849
commit
1fbf0ff331
47
api.lua
47
api.lua
@ -1,5 +1,5 @@
|
||||
|
||||
-- Mobs Api (6th March 2017)
|
||||
-- Mobs Api (7th March 2017)
|
||||
|
||||
mobs = {}
|
||||
mobs.mod = "redo"
|
||||
@ -850,28 +850,41 @@ end
|
||||
-- find and replace what mob is looking for (grass, wheat etc.)
|
||||
function replace(self, pos)
|
||||
|
||||
if self.replace_rate
|
||||
and self.child == false
|
||||
and random(1, self.replace_rate) == 1 then
|
||||
if not self.replace_rate
|
||||
or not self.replace_what
|
||||
or self.child == true
|
||||
or self.object:getvelocity().y ~= 0
|
||||
or random(1, self.replace_rate) > 1 then
|
||||
return
|
||||
end
|
||||
|
||||
local pos = self.object:getpos()
|
||||
local what, with, y_offset
|
||||
|
||||
pos.y = pos.y + self.replace_offset
|
||||
if type(self.replace_what[1]) == "table" then
|
||||
|
||||
local num = random(#self.replace_what)
|
||||
|
||||
what = self.replace_what[num][1] or ""
|
||||
with = self.replace_what[num][2] or ""
|
||||
y_offset = self.replace_what[num][3] or 0
|
||||
else
|
||||
what = self.replace_what
|
||||
with = self.replace_with or ""
|
||||
y_offset = self.replace_offset or 0
|
||||
end
|
||||
|
||||
pos.y = pos.y + y_offset
|
||||
|
||||
if #minetest.find_nodes_in_area(pos, pos, what) > 0 then
|
||||
|
||||
-- print ("replace node = ".. minetest.get_node(pos).name, pos.y)
|
||||
|
||||
if self.replace_what
|
||||
and self.replace_with
|
||||
and self.object:getvelocity().y == 0
|
||||
and #minetest.find_nodes_in_area(pos, pos, self.replace_what) > 0 then
|
||||
minetest.set_node(pos, {name = with})
|
||||
|
||||
minetest.set_node(pos, {name = self.replace_with})
|
||||
|
||||
-- when cow/sheep eats grass, replace wool and milk
|
||||
if self.gotten == true then
|
||||
self.gotten = false
|
||||
self.object:set_properties(self)
|
||||
end
|
||||
-- when cow/sheep eats grass, replace wool and milk
|
||||
if self.gotten == true then
|
||||
self.gotten = false
|
||||
self.object:set_properties(self)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
9
api.txt
9
api.txt
@ -1,5 +1,5 @@
|
||||
|
||||
MOB API (6th March 2017)
|
||||
MOB API (7th March 2017)
|
||||
|
||||
The mob api is a function that can be called on by other mods to add new animals or monsters into minetest.
|
||||
|
||||
@ -102,11 +102,18 @@ This functions registers a new mob as a Minetest entity.
|
||||
'jump' sound when jumping
|
||||
'explode' sound when exploding
|
||||
'distance' maximum distance sounds are heard from (default is 10)
|
||||
|
||||
Mobs can look for specific nodes as they walk and replace them to mimic eating
|
||||
|
||||
'replace_what' group if items to replace e.g. {"farming:wheat_8", "farming:carrot_8"}
|
||||
'replace_with' replace with what e.g. "air" or in chickens case "mobs:egg"
|
||||
'replace_rate' how random should the replace rate be (typically 10)
|
||||
'replace_offset' +/- value to check specific node to replace
|
||||
|
||||
The 'replace_what' has been updated to use tables for what, with and y_offset e.g.
|
||||
|
||||
replace_what = { {"group:grass", "air", 0}, {"default:dirt_with_grass", "default:dirt", -1} }
|
||||
|
||||
Mob animation comes in three parts, start_frame, end_frame and frame_speed which
|
||||
can be added to the mob definition under pre-defined mob animation names like:
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user