From d8300b6fc6d60289c5fbff57c60756d94ad5cd6b Mon Sep 17 00:00:00 2001 From: cale Date: Sun, 23 Oct 2016 11:07:47 +0200 Subject: [PATCH] added teleport component --- mods/mobs/api.lua | 4 ++-- mods/mobs/components.lua | 25 +++++++++++++++++++++++++ mods/mobs/mobs.lua | 2 +- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/mods/mobs/api.lua b/mods/mobs/api.lua index 4fadf64..b75c67f 100644 --- a/mods/mobs/api.lua +++ b/mods/mobs/api.lua @@ -41,8 +41,8 @@ function mobs.register_mob(name, def) def.behaviour = def.behaviour or { { name = "walk", - speed = 3, - distance = 3 + speed = 4, + distance = 3, }, { name = "attack" }, { diff --git a/mods/mobs/components.lua b/mods/mobs/components.lua index 237add5..e65b091 100644 --- a/mods/mobs/components.lua +++ b/mods/mobs/components.lua @@ -33,6 +33,31 @@ mobs.register_component("walk", { end }) +mobs.register_component("teleport", { + action = function(self, params, def) + if self.destination then + local destination = self.destination + if self.destination and self.destination.is_player and self.destination:is_player() then + destination = self.destination:getpos() + end + if not(destination) then + return 0 + end + + local pos = self.object:getpos() + local distance = (params.distance or 0) + if vector.distance(pos,destination) > distance then + local x = vector.new(math.random(-3, 3),2,math.random(-3, 3)) + self.object:setpos(vector.add(destination, x)) + return 3 + else + return 0 + end + end + return 0 + end +}) + mobs.register_component("find_player", { action = function(self, params, def) local all_objects = minetest.get_objects_inside_radius(self.object:getpos(), params.range or def.range or 10) diff --git a/mods/mobs/mobs.lua b/mods/mobs/mobs.lua index efd9e35..b596007 100644 --- a/mods/mobs/mobs.lua +++ b/mods/mobs/mobs.lua @@ -12,7 +12,7 @@ mobs.register_mob("mobs:slime", { }, collisionbox = {-0.4, -0.5, -0.4, 0.4, 0.5, 0.4}, description = "Slime", - range = 3, + range = 3 }) mobs.register_mob("mobs:big_slime", {