From d46fc60f43d050f552afdb2aaa9564c5ecc89dac Mon Sep 17 00:00:00 2001 From: npx Date: Mon, 25 Apr 2016 22:06:02 +0200 Subject: [PATCH] Added new midas_ability --- icelamander.lua | 19 +---------------- mese_dragon.lua | 17 +--------------- nssm_api.lua | 54 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 34 deletions(-) diff --git a/icelamander.lua b/icelamander.lua index 84876c5..005418b 100644 --- a/icelamander.lua +++ b/icelamander.lua @@ -62,23 +62,6 @@ nssm:register_mob("nssm:icelamander", { dattack_end = 210, }, do_custom = function(self) - --Big_froster - local pos = self.object:getpos() - if minetest.is_protected(pos, "") then - return - end - local c=3 - local v = self.object:getvelocity() - for dx = -c*(math.abs(v.x))-1 , c*(math.abs(v.x))+1 do - for dy=-1,3 do - for dz = -c*(math.abs(v.z))-1 , c*(math.abs(v.z))+1 do - local p = {x=pos.x+dx, y=pos.y+dy, z=pos.z+dz} - local n = minetest.env:get_node(p).name - if (n~="air") and not minetest.is_protected(p, "") then - minetest.env:set_node(p, {name="default:ice"}) - end - end - end - end + nssm:midas_ability(self, "default:ice", self.run_velocity,1, 3) end, }) diff --git a/mese_dragon.lua b/mese_dragon.lua index 0ce29e5..0e4afba 100644 --- a/mese_dragon.lua +++ b/mese_dragon.lua @@ -60,22 +60,7 @@ nssm:register_mob("nssm:mese_dragon", { dattack_end = 160, }, do_custom = function(self) - --transform the blocks he touches in mese_blocks - local pos = self.object:getpos() - local c=2 - local v = self.object:getvelocity() - for dx = -c*(math.abs(v.x))-2 , c*(math.abs(v.x))+2 do - for dy=-1,10 do - for dz = -c*(math.abs(v.z))-2 , c*(math.abs(v.z))+2 do - local p = {x=pos.x+dx, y=pos.y+dy, z=pos.z+dz} - local t = {x=pos.x+dx, y=pos.y+dy, z=pos.z+dz} - local n = minetest.env:get_node(p).name - if (n~="air" and n~="nssm:mese_meteor" and n~="fire:basic_flame") then - minetest.env:set_node(t, {name="default:mese_block"}) - end - end - end - end + nssm:midas_ability(self, "default:mese_block", self.run_velocity,2, 3) end, custom_attack = function(self) diff --git a/nssm_api.lua b/nssm_api.lua index 6244720..2708926 100644 --- a/nssm_api.lua +++ b/nssm_api.lua @@ -310,3 +310,57 @@ function nssm:webber_ability( --puts randomly around the block defined as w_blo end end end + +function nssm:midas_ability( --ability to transform every blocks it touches in the m_block block + self, --the entity of the mob + m_block, + max_vel, --max velocity of the mob + mult, --multiplier of the dimensions of the area around that need the transformation + height --height of the mob + ) + + local v = self.object:getvelocity() + local pos = self.object:getpos() + + if minetest.is_protected(pos, "") then + return + end + + local max = 0 + local yaw = (self.object:getyaw() + self.rotate) or 0 + local x = math.sin(yaw)*-1 + local z = math.cos(yaw) + + local i = 1 + local i1 = -1 + local k = 1 + local k1 = -1 + + local multiplier = mult + + if x>0 then + i = nssm:round(x*max_vel)*multiplier + else + i1 = nssm:round(x*max_vel)*multiplier + end + + if z>0 then + k = nssm:round(z*max_vel)*multiplier + else + k1 = nssm:round(z*max_vel)*multiplier + end + + for dx = i1, i do + for dy = -1, height do + for dz = k1, k do + local p = {x=pos.x+dx, y=pos.y+dy, z=pos.z+dz} + local n = minetest.env:get_node(p).name + + if minetest.get_item_group(n, "unbreakable") == 1 or minetest.is_protected(p, "") or n=="air" then + else + minetest.env:set_node(p, {name=m_block}) + end + end + end + end +end