-
-
Save xyzz/4c37e2b3dfe568b2e04d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
do | |
local _parent_0 = Mob | |
local _base_0 = { | |
name = "mobs:rat", | |
interval = 5, | |
step = function(self) | |
local x = math.random() - 0.5 | |
local z = math.random() - 0.5 | |
local y = 0 | |
if math.random() > 0.8 then | |
y = 5 | |
end | |
return self:velocity({ | |
x = x, | |
y = y, | |
z = z | |
}) | |
end | |
} | |
_base_0.__index = _base_0 | |
setmetatable(_base_0, _parent_0.__base) | |
local _class_0 = setmetatable({ | |
__init = function(self, ...) | |
return _parent_0.__init(self, ...) | |
end, | |
__base = _base_0, | |
__name = "Rat", | |
__parent = _parent_0 | |
}, { | |
__index = function(cls, name) | |
local val = rawget(_base_0, name) | |
if val == nil then | |
return _parent_0[name] | |
else | |
return val | |
end | |
end, | |
__call = function(cls, ...) | |
local _self_0 = setmetatable({}, _base_0) | |
cls.__init(_self_0, ...) | |
return _self_0 | |
end | |
}) | |
_base_0.__class = _class_0 | |
if _parent_0.__inherited then | |
_parent_0.__inherited(_parent_0, _class_0) | |
end | |
Rat = _class_0 | |
end | |
Rat:register() | |
return minetest.register_abm({ | |
nodenames = { | |
"default:tree", | |
"default:jungletree", | |
"group:tree" | |
}, | |
interval = 10, | |
chance = 200, | |
action = function(pos, node, active_object_count, active_object_count_wider) | |
if active_object_count_wider ~= 0 then | |
return | |
end | |
local p1 = vector.add(pos, { | |
x = math.random(-2, 2), | |
y = 0, | |
z = math.random(-2, 2) | |
}) | |
local n1 = minetest.get_node(p1) | |
local n1b = minetest.get_node(vector.add(p1, { | |
x = 0, | |
y = -1, | |
z = 0 | |
})) | |
if n1.name == "air" and (function() | |
return (n1b.name == "default:dirt_with_grass" or minetest.get_item_group(n1b.name, "grass")) | |
end)() then | |
return Rat(p1) | |
end | |
end | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment