mirror of
https://github.com/ElCeejo/animalia.git
synced 2025-03-21 15:21:22 +00:00
Code Cleanup
This commit is contained in:
parent
21ad5faf7d
commit
6863359cf6
6 changed files with 80 additions and 89 deletions
|
@ -58,9 +58,10 @@ if farming_enabled then
|
||||||
for name, def in pairs(minetest.registered_nodes) do
|
for name, def in pairs(minetest.registered_nodes) do
|
||||||
local item_string = name:sub(1, #name - 2)
|
local item_string = name:sub(1, #name - 2)
|
||||||
local item_name = item_string:split(":")[2]
|
local item_name = item_string:split(":")[2]
|
||||||
|
local growth_stage = tonumber(name:sub(-1)) or 1
|
||||||
if farming.registered_plants[item_string]
|
if farming.registered_plants[item_string]
|
||||||
or farming.registered_plants[item_name] then
|
or farming.registered_plants[item_name] then
|
||||||
def.groups.crop = 2
|
def.groups.crop = growth_stage
|
||||||
end
|
end
|
||||||
minetest.register_node(":" .. name, def)
|
minetest.register_node(":" .. name, def)
|
||||||
end
|
end
|
||||||
|
@ -1032,7 +1033,7 @@ creatura.register_utility("animalia:follow_player", function(self, player, force
|
||||||
end)
|
end)
|
||||||
|
|
||||||
creatura.register_utility("animalia:flee_from_target", function(self, target)
|
creatura.register_utility("animalia:flee_from_target", function(self, target)
|
||||||
local los_timeout = 3
|
local los_timeout = 5
|
||||||
local function func(_self)
|
local function func(_self)
|
||||||
local pos = _self.object:get_pos()
|
local pos = _self.object:get_pos()
|
||||||
if not pos then return end
|
if not pos then return end
|
||||||
|
@ -1041,16 +1042,16 @@ creatura.register_utility("animalia:flee_from_target", function(self, target)
|
||||||
if not los then
|
if not los then
|
||||||
los_timeout = los_timeout - _self.dtime
|
los_timeout = los_timeout - _self.dtime
|
||||||
else
|
else
|
||||||
los_timeout = 3
|
los_timeout = 5
|
||||||
end
|
end
|
||||||
if los_timeout <= 0 then self._puncher = nil return true end
|
if los_timeout <= 0 then self._puncher = nil return true end
|
||||||
local dist = vec_dist(pos, tgt_pos)
|
local dist = vec_dist(pos, tgt_pos)
|
||||||
if dist > _self.tracking_range then self._puncher = nil return true end
|
if dist > _self.tracking_range then self._puncher = nil return true end
|
||||||
if not _self:get_action() then
|
if not _self:get_action() then
|
||||||
local flee_dir = vec_dir(tgt_pos, pos)
|
local flee_dir = vec_dir(tgt_pos, pos)
|
||||||
local pos2 = _self:get_wander_pos(2, 3, flee_dir)
|
local pos2 = _self:get_wander_pos(1, 2, flee_dir)
|
||||||
local anim = (_self.animations["run"] and "run") or "walk"
|
local anim = (_self.animations["run"] and "run") or "walk"
|
||||||
creatura.action_move(_self, pos2, 2, "creatura:context_based_steering", 1, anim)
|
creatura.action_move(_self, pos2, 1, "creatura:context_based_steering", 1, anim)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
self:set_utility(func)
|
self:set_utility(func)
|
||||||
|
@ -1560,7 +1561,7 @@ creatura.register_utility("animalia:mount_horse", function(self, player)
|
||||||
and vel.y < 1 then
|
and vel.y < 1 then
|
||||||
_self.object:add_velocity({
|
_self.object:add_velocity({
|
||||||
x = 0,
|
x = 0,
|
||||||
y = _self.jump_power,
|
y = _self.jump_power * 2,
|
||||||
z = 0
|
z = 0
|
||||||
})
|
})
|
||||||
elseif not _self.touching_ground then
|
elseif not _self.touching_ground then
|
||||||
|
|
|
@ -36,6 +36,7 @@ minetest.register_entity("animalia:lasso_entity", {
|
||||||
if not pos or not parent or not point_to then self.object:remove() return end
|
if not pos or not parent or not point_to then self.object:remove() return end
|
||||||
if type(parent) == "string" then
|
if type(parent) == "string" then
|
||||||
parent = minetest.get_player_by_name(parent)
|
parent = minetest.get_player_by_name(parent)
|
||||||
|
if not parent then self.object:remove() return end
|
||||||
local tgt_pos = parent:get_pos()
|
local tgt_pos = parent:get_pos()
|
||||||
tgt_pos.y = tgt_pos.y + 1
|
tgt_pos.y = tgt_pos.y + 1
|
||||||
point_to.y = point_to.y + pointed_ent.height * 0.5
|
point_to.y = point_to.y + pointed_ent.height * 0.5
|
||||||
|
@ -126,7 +127,7 @@ local function add_lasso(self, origin)
|
||||||
-- Attachment point of entity
|
-- Attachment point of entity
|
||||||
ent._attached = origin
|
ent._attached = origin
|
||||||
if type(origin) == "string" then
|
if type(origin) == "string" then
|
||||||
local player = minetest.get_player_by_name(origin)
|
--local player = minetest.get_player_by_name(origin)
|
||||||
--object:set_attach(player)
|
--object:set_attach(player)
|
||||||
else
|
else
|
||||||
object:set_pos(origin)
|
object:set_pos(origin)
|
||||||
|
@ -171,22 +172,24 @@ function animalia.update_lasso_effects(self)
|
||||||
using_lasso[lasso] = self
|
using_lasso[lasso] = self
|
||||||
local name = lasso
|
local name = lasso
|
||||||
lasso = minetest.get_player_by_name(lasso)
|
lasso = minetest.get_player_by_name(lasso)
|
||||||
if lasso:get_wielded_item():get_name() ~= "animalia:lasso" then
|
if lasso then
|
||||||
using_lasso[name] = nil
|
if lasso:get_wielded_item():get_name() ~= "animalia:lasso" then
|
||||||
self._lasso_ent:remove()
|
using_lasso[name] = nil
|
||||||
self._lasso_ent = nil
|
self._lasso_ent:remove()
|
||||||
self._lassod_to = nil
|
self._lasso_ent = nil
|
||||||
self:forget("_lassod_to")
|
self._lassod_to = nil
|
||||||
|
self:forget("_lassod_to")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local lasso_pos = lasso:get_pos()
|
||||||
|
local dist = vec_dist(pos, lasso_pos)
|
||||||
|
local vel = self.object:get_velocity()
|
||||||
|
if not vel or dist < 8 and self.touching_ground then return end
|
||||||
|
if vec_len(vel) < 8 then
|
||||||
|
self.object:add_velocity(get_rope_velocity(pos, lasso_pos, dist))
|
||||||
|
end
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local lasso_pos = lasso:get_pos()
|
|
||||||
local dist = vec_dist(pos, lasso_pos)
|
|
||||||
local vel = self.object:get_velocity()
|
|
||||||
if not vel or dist < 8 and self.touching_ground then return end
|
|
||||||
if vec_len(vel) < 8 then
|
|
||||||
self.object:add_velocity(get_rope_velocity(pos, lasso_pos, dist))
|
|
||||||
end
|
|
||||||
return
|
|
||||||
elseif type(lasso) == "table" then
|
elseif type(lasso) == "table" then
|
||||||
local dist = vec_dist(pos, lasso)
|
local dist = vec_dist(pos, lasso)
|
||||||
local vel = self.object:get_velocity()
|
local vel = self.object:get_velocity()
|
||||||
|
|
|
@ -4,20 +4,10 @@
|
||||||
|
|
||||||
local random = math.random
|
local random = math.random
|
||||||
|
|
||||||
local walkable_nodes = {}
|
local vec_add, vec_sub = vector.add, vector.subtract
|
||||||
|
|
||||||
local color = minetest.colorize
|
local color = minetest.colorize
|
||||||
|
|
||||||
minetest.register_on_mods_loaded(function()
|
|
||||||
for name in pairs(minetest.registered_nodes) do
|
|
||||||
if name ~= "air" and name ~= "ignore" then
|
|
||||||
if minetest.registered_nodes[name].walkable then
|
|
||||||
table.insert(walkable_nodes, name)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
local function correct_name(str)
|
local function correct_name(str)
|
||||||
if str then
|
if str then
|
||||||
if str:match(":") then str = str:split(":")[2] end
|
if str:match(":") then str = str:split(":")[2] end
|
||||||
|
@ -288,7 +278,7 @@ minetest.register_craftitem("animalia:venison_raw", {
|
||||||
groups = {flammable = 2, meat = 1, food_meat = 1},
|
groups = {flammable = 2, meat = 1, food_meat = 1},
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_craftitem("animalia:venison_raw_cooked", {
|
minetest.register_craftitem("animalia:venison_cooked", {
|
||||||
description = "Venison Steak",
|
description = "Venison Steak",
|
||||||
inventory_image = "animalia_venison_cooked.png",
|
inventory_image = "animalia_venison_cooked.png",
|
||||||
on_use = minetest.item_eat(10),
|
on_use = minetest.item_eat(10),
|
||||||
|
@ -388,45 +378,38 @@ minetest.register_craftitem("animalia:bucket_guano", {
|
||||||
inventory_image = "animalia_guano_bucket.png",
|
inventory_image = "animalia_guano_bucket.png",
|
||||||
stack_max = 1,
|
stack_max = 1,
|
||||||
groups = {flammable = 3},
|
groups = {flammable = 3},
|
||||||
on_place = function(itemstack, placer, pointed_thing)
|
on_place = function(itemstack, placer, pointed)
|
||||||
local pos = pointed_thing.above
|
local pos = pointed.under
|
||||||
if pos then
|
local node = minetest.get_node(pos)
|
||||||
local under = minetest.get_node(pointed_thing.under)
|
if node
|
||||||
local node = minetest.registered_nodes[under.name]
|
and node.on_rightclick then
|
||||||
if node and node.on_rightclick then
|
return node.on_rightclick(pointed_thing.under, under, placer, itemstack)
|
||||||
return node.on_rightclick(pointed_thing.under, under, placer,
|
end
|
||||||
itemstack)
|
if minetest.is_protected(pos, placer:get_player_name()) then
|
||||||
end
|
return
|
||||||
if pos
|
end
|
||||||
and not minetest.is_protected(pos, placer:get_player_name()) then
|
local crops = minetest.find_nodes_in_area_under_air(
|
||||||
if guano_fert then
|
vec_sub(pos, 5),
|
||||||
local nodes = minetest.find_nodes_in_area_under_air(
|
vec_add(pos, 5),
|
||||||
vector.subtract(pos, 5),
|
{"group:grass", "group:plant", "group:flora", "group:crop"}
|
||||||
vector.add(pos, 5),
|
) or {}
|
||||||
{"group:grass", "group:plant", "group:flora"}
|
local crops_grown = 0
|
||||||
)
|
for _, crop in ipairs(crops) do
|
||||||
if #nodes > 0 then
|
local crop_name = minetest.get_node(crop).name
|
||||||
for n = 1, #nodes do
|
local growth_stage = tonumber(crop_name:sub(-1)) or 1
|
||||||
grow_crops(nodes[n], minetest.get_node(nodes[n]).name)
|
local new_name = crop_name:sub(1, #crop_name - 1) .. (growth_stage + 1)
|
||||||
end
|
local new_def = minetest.registered_nodes[new_name]
|
||||||
local replace = itemstack:get_meta():get_string("original_item")
|
if new_def then
|
||||||
if not replace
|
local p2 = new_def.place_param2 or 1
|
||||||
or replace == "" then
|
minetest.set_node(crop, {name = new_name, param2 = p2})
|
||||||
replace = "bucket:bucket_empty"
|
crops_grown = crops_grown + 1
|
||||||
end
|
|
||||||
itemstack:set_name(replace)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
minetest.set_node(pos, {name = "animalia:guano"})
|
|
||||||
local replace = itemstack:get_meta():get_string("original_item")
|
|
||||||
if not replace
|
|
||||||
or replace == "" then
|
|
||||||
replace = "bucket:bucket_empty"
|
|
||||||
end
|
|
||||||
itemstack:set_name(replace)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
if crops_grown < 1 then minetest.set_node(pointed.above, {name = "animalia:guano"}) end
|
||||||
|
local meta = itemstack:get_meta()
|
||||||
|
local og_item = meta:get_string("original_item")
|
||||||
|
if og_item == "" then og_item = "bucket:bucket_empty" end
|
||||||
|
itemstack:replace(ItemStack(og_item))
|
||||||
return itemstack
|
return itemstack
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
@ -591,12 +574,16 @@ minetest.register_node("animalia:guano", {
|
||||||
},
|
},
|
||||||
groups = {crumbly = 3, falling_node = 1, not_in_creative_inventory = 1},
|
groups = {crumbly = 3, falling_node = 1, not_in_creative_inventory = 1},
|
||||||
on_punch = function(pos, _, player)
|
on_punch = function(pos, _, player)
|
||||||
local item_name = player:get_wielded_item():get_name()
|
local inv = player:get_inventory()
|
||||||
if item_name:find("bucket")
|
local stack = ItemStack("animalia:bucket_guano")
|
||||||
and item_name:find("empty") then
|
if not inv:room_for_item("main", stack) then return end
|
||||||
local stack = ItemStack("animalia:bucket_guano")
|
local item = player:get_wielded_item()
|
||||||
|
local item_name = item:get_name()
|
||||||
|
if item_name:match("bucket_empty") then
|
||||||
|
item:take_item()
|
||||||
stack:get_meta():set_string("original_item", item_name)
|
stack:get_meta():set_string("original_item", item_name)
|
||||||
player:set_wielded_item(stack)
|
inv:add_item("main", stack)
|
||||||
|
player:set_wielded_item(item)
|
||||||
minetest.remove_node(pos)
|
minetest.remove_node(pos)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
19
init.lua
19
init.lua
|
@ -79,18 +79,13 @@ minetest.register_on_mods_loaded(function()
|
||||||
local on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, dir, damage)
|
local on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, dir, damage)
|
||||||
old_punch(self, puncher, time_from_last_punch, tool_capabilities, dir, damage)
|
old_punch(self, puncher, time_from_last_punch, tool_capabilities, dir, damage)
|
||||||
local pos = self.object:get_pos()
|
local pos = self.object:get_pos()
|
||||||
if not pos then
|
if not pos then return end
|
||||||
return
|
local name = puncher:is_player() and puncher:get_player_name()
|
||||||
end
|
local pets = (name and animalia.pets[name]) or {}
|
||||||
if puncher:is_player()
|
for _, obj in ipairs(pets) do
|
||||||
and animalia.pets[puncher:get_player_name()] then
|
local ent = obj and obj:get_luaentity()
|
||||||
local pets = animalia.pets[puncher:get_player_name()]
|
if ent.assist_owner then
|
||||||
if #pets < 1 then return end
|
ent.owner_target = self
|
||||||
for i = 1, #pets do
|
|
||||||
local ent = pets[i]:get_luaentity()
|
|
||||||
if ent.assist_owner then
|
|
||||||
ent.owner_target = self
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -201,4 +201,9 @@ creatura.register_mob("animalia:bat", {
|
||||||
on_punch = animalia.punch
|
on_punch = animalia.punch
|
||||||
})
|
})
|
||||||
|
|
||||||
creatura.register_spawn_egg("animalia:bat", "392517", "321b0b")
|
creatura.register_spawn_egg("animalia:bat", "392517", "321b0b")
|
||||||
|
|
||||||
|
creatura.register_spawn_item("animalia:bat", {
|
||||||
|
col1 = "392517",
|
||||||
|
col2 = "321b0b"
|
||||||
|
})
|
|
@ -28,7 +28,7 @@ creatura.register_mob("animalia:bird", {
|
||||||
-- Entity Physics
|
-- Entity Physics
|
||||||
stepheight = 1.1,
|
stepheight = 1.1,
|
||||||
max_fall = 0,
|
max_fall = 0,
|
||||||
turn_rate = 6,
|
turn_rate = 3,
|
||||||
boid_seperation = 0.4,
|
boid_seperation = 0.4,
|
||||||
-- Visuals
|
-- Visuals
|
||||||
mesh = "animalia_bird.b3d",
|
mesh = "animalia_bird.b3d",
|
||||||
|
|
Loading…
Add table
Reference in a new issue