-
-
Save rubenwardy/c36919f9f696a34666c2 to your computer and use it in GitHub Desktop.
YAMM example
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
-- grazing component | |
yamm.c("yamm:grazing",{ | |
depends = {"yamm:move"}, | |
on_spawn = function(entity) | |
print("[YAMM] Loading grazing module for "..entity.type) | |
entity.flag = "grazing" | |
entity.grazing = { | |
-- count | |
count = 0, | |
-- eaten | |
grass_hp = 0, | |
-- current grass | |
grass_pos = nil | |
} | |
end, | |
on_step=function(entity,dtime) | |
if entity.flag == "grazing" then | |
print("[YAMM] Grazing") | |
entity.grazing.count = entity.grazing.count + dtime | |
if entity.grazing.count > 1 then | |
entity.grazing.count=0 | |
if (not grass_pos) then | |
print("-- searching for food") | |
-- do grazing code here | |
local target = minetest.env:find_node_near(entity.object:getpos(), 10, entity.food) | |
if (not entity.move.path) and (target~=nil) and (entity.object:getpos()~=nil) then | |
grass_pos = { | |
x=target.x, | |
y=target.y, | |
z=target.z | |
} | |
grass_hp = 10 | |
target.y = target.y + 1 | |
print("-- found food, navigating") | |
yamm.types['yamm:move'].path_find(entity,target) | |
end | |
elseif (yamm.vector_distance(entity.object:getpos(),grass_pos)<2) then | |
if (grass_hp < 1) then | |
minetest.env:set_node(grass_pos,{name="default:dirt"}) | |
grass_pos = nil | |
return | |
end | |
print("-- eating") | |
grass_hp = grass_hp - 1 | |
print("grass_hp: "..grass_hp) | |
end | |
end | |
end | |
end | |
}) | |
yamm.e("yamm:sheep",{ | |
c = {"yamm:move","yamm:gravity","yamm:grazing"}, -- the components used | |
food = {"default:dirt_with_grass"}, -- what the sheep eats | |
hp_max = 1, -- the max health | |
-- looks | |
visual = "upright_sprite", -- type | |
visual_size = {x=1, y=2}, -- size | |
textures = {"mobs_dungeon_master.png", "mobs_dungeon_master_back.png"}, -- textures | |
-- physics | |
collisionbox = {-0.5,-1,-0.03, 0.5,1,0.03}, -- collision box for physics | |
physical = true, -- is mob physical | |
weight = 5 -- the weight of the mob | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment