1
0
Fork 0

Teleport inside plants and vines w/ ender pearl

This commit is contained in:
Wuzzy 2017-05-26 18:12:35 +02:00
parent 75fbf7f95e
commit 16d018b406
1 changed files with 36 additions and 30 deletions

View File

@ -169,17 +169,23 @@ local pearl_on_step = function(self, dtime)
-- Destroy when hitting a solid node -- Destroy when hitting a solid node
if self._lastpos.x~=nil then if self._lastpos.x~=nil then
local walkable = (def and def.walkable)
-- No teleport for hitting ignore for now. Otherwise the player could get stuck. -- No teleport for hitting ignore for now. Otherwise the player could get stuck.
-- FIXME: This also means the player loses an ender pearl for throwing into unloaded areas -- FIXME: This also means the player loses an ender pearl for throwing into unloaded areas
if node.name == "ignore" then if node.name == "ignore" then
self.object:remove() self.object:remove()
-- Activate when hitting a solid node or a plant -- Activate when hitting a solid node or a plant
elseif nn == "mcl_core:vine" or nn == "mcl_core:deadbush" or minetest.get_item_group(nn, "flower") ~= 0 or minetest.get_item_group(nn, "sapling") ~= 0 or minetest.get_item_group(nn, "plant") ~= 0 or minetest.get_item_group(nn, "mushroom") ~= 0 or (def and def.walkable) or not def then elseif walkable or nn == "mcl_core:vine" or nn == "mcl_core:deadbush" or minetest.get_item_group(nn, "flower") ~= 0 or minetest.get_item_group(nn, "sapling") ~= 0 or minetest.get_item_group(nn, "plant") ~= 0 or minetest.get_item_group(nn, "mushroom") ~= 0 or not def then
local player = minetest.get_player_by_name(self._thrower) local player = minetest.get_player_by_name(self._thrower)
if player then if player then
-- Teleport and hurt player -- Teleport and hurt player
-- But first determine good teleport position -- First determine good teleport position
local dir = {x=0, y=0, z=0}
if walkable then
-- Node is walkable, we have to find a place somewhere outside of that node
local v = self.object:getvelocity() local v = self.object:getvelocity()
v = vector.normalize(v) v = vector.normalize(v)
@ -198,8 +204,6 @@ local pearl_on_step = function(self, dtime)
if ld ~= "z" then v.z = 0 end if ld ~= "z" then v.z = 0 end
-- Final tweaks to the teleporting pos, based on direction -- Final tweaks to the teleporting pos, based on direction
local dir = {x=0, y=0, z=0}
-- Impact from the side -- Impact from the side
dir.x = v.x * -1 dir.x = v.x * -1
dir.z = v.z * -1 dir.z = v.z * -1
@ -212,6 +216,8 @@ local pearl_on_step = function(self, dtime)
-- Standing on top -- Standing on top
dir.y = 0.5 dir.y = 0.5
end end
end
-- If node was not walkable, no modification to pos is made.
-- Final teleportation position -- Final teleportation position
local telepos = vector.add(pos, dir) local telepos = vector.add(pos, dir)