mirror of
https://codeberg.org/tenplus1/teleport_potion.git
synced 2025-07-17 19:56:36 -04:00
use moveresult, add switcharoo effect
This commit is contained in:
parent
355be56a2c
commit
37a84c6f71
2 changed files with 42 additions and 57 deletions
|
@ -7,6 +7,7 @@ https://forum.minetest.net/viewtopic.php?f=9&t=9234
|
||||||
|
|
||||||
Change log:
|
Change log:
|
||||||
|
|
||||||
|
- 1.5 - Use moveresult when throwing teleport potion, has switcharoo effect
|
||||||
- 1.4 - Change Pad texture so it's not as contrasting, check for attached player before tp.
|
- 1.4 - Change Pad texture so it's not as contrasting, check for attached player before tp.
|
||||||
- 1.3 - Added some formspec checks and switch to enable old teleport pad texture (thanks mazes 80)
|
- 1.3 - Added some formspec checks and switch to enable old teleport pad texture (thanks mazes 80)
|
||||||
- 1.2 - New teleport pad texture, code tweaks to work with minetest 5.x
|
- 1.2 - New teleport pad texture, code tweaks to work with minetest 5.x
|
||||||
|
|
68
init.lua
68
init.lua
|
@ -40,16 +40,14 @@ local function check_coordinates(str)
|
||||||
-- check coords
|
-- check coords
|
||||||
if x == nil or string.len(x) > 6
|
if x == nil or string.len(x) > 6
|
||||||
or y == nil or string.len(y) > 6
|
or y == nil or string.len(y) > 6
|
||||||
or z == nil or string.len(z) > 6 then
|
or z == nil or string.len(z) > 6 then return end
|
||||||
return nil
|
|
||||||
end
|
|
||||||
|
|
||||||
-- convert string coords to numbers
|
-- convert string coords to numbers
|
||||||
x = tonumber(x) ; y = tonumber(y) ; z = tonumber(z)
|
x = tonumber(x) ; y = tonumber(y) ; z = tonumber(z)
|
||||||
|
|
||||||
-- are coords in map range ?
|
-- are coords in map range ?
|
||||||
if x > dist or x < -dist or y > dist or y < -dist or z > dist or z < -dist then
|
if x > dist or x < -dist or y > dist or y < -dist or z > dist or z < -dist then
|
||||||
return nil
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- return ok coords
|
-- return ok coords
|
||||||
|
@ -141,12 +139,14 @@ core.register_node("teleport_potion:portal", {
|
||||||
|
|
||||||
local function throw_potion(itemstack, player)
|
local function throw_potion(itemstack, player)
|
||||||
|
|
||||||
local playerpos = player:get_pos()
|
local pos = player:get_pos()
|
||||||
|
local prop = player:get_properties()
|
||||||
|
local y_off = prop.eye_height or 1.5
|
||||||
|
|
||||||
local obj = core.add_entity({
|
local obj = core.add_entity({
|
||||||
x = playerpos.x,
|
x = pos.x,
|
||||||
y = playerpos.y + 1.5,
|
y = pos.y + y_off,
|
||||||
z = playerpos.z
|
z = pos.z
|
||||||
}, "teleport_potion:potion_entity")
|
}, "teleport_potion:potion_entity")
|
||||||
|
|
||||||
local dir = player:get_look_dir()
|
local dir = player:get_look_dir()
|
||||||
|
@ -163,68 +163,52 @@ end
|
||||||
local potion_entity = {
|
local potion_entity = {
|
||||||
|
|
||||||
initial_properties = {
|
initial_properties = {
|
||||||
physical = true,
|
physical = true, static_save = false, pointable = false,
|
||||||
visual = "sprite",
|
visual = "sprite",
|
||||||
visual_size = {x = 1.0, y = 1.0},
|
visual_size = {x = 1.0, y = 1.0},
|
||||||
textures = {"teleport_potion_potion.png"},
|
textures = {"teleport_potion_potion.png"},
|
||||||
collisionbox = {-0.1,-0.1,-0.1,0.1,0.1,0.1},
|
collisionbox = {-0.2,-0.2,-0.2,0.2,0.2,0.2},
|
||||||
},
|
},
|
||||||
lastpos = {},
|
|
||||||
player = ""
|
player = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
potion_entity.on_step = function(self, dtime)
|
potion_entity.on_step = function(self, dtime, moveresult)
|
||||||
|
|
||||||
if not self.player then
|
if not self.player or self.player == "" then
|
||||||
|
self.object:remove() ; return
|
||||||
self.object:remove()
|
|
||||||
|
|
||||||
return
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local pos = self.object:get_pos()
|
if moveresult.collides then
|
||||||
|
|
||||||
if self.lastpos.x ~= nil then
|
|
||||||
|
|
||||||
local vel = self.object:get_velocity()
|
|
||||||
|
|
||||||
-- only when potion hits something physical
|
|
||||||
if vel.x == 0 or vel.y == 0 or vel.z == 0 then
|
|
||||||
|
|
||||||
if self.player ~= "" then
|
|
||||||
|
|
||||||
-- round up coords to fix glitching through doors
|
-- round up coords to fix glitching through doors
|
||||||
self.lastpos = vector.round(self.lastpos)
|
local pos = vector.round(self.object:get_pos())
|
||||||
|
|
||||||
local oldpos = self.player:get_pos()
|
local oldpos = self.player:get_pos()
|
||||||
|
|
||||||
|
-- if we hit a player or mob then switch positions
|
||||||
|
local def = moveresult.collisions and moveresult.collisions[1]
|
||||||
|
|
||||||
|
if def.object then
|
||||||
|
def.object:set_pos(oldpos)
|
||||||
|
end
|
||||||
|
|
||||||
-- play sound and disappearing particle effect at current position
|
-- play sound and disappearing particle effect at current position
|
||||||
core.sound_play("portal_close", {
|
core.sound_play("portal_close", {
|
||||||
pos = oldpos, gain = 1.0, max_hear_distance = 5}, true)
|
pos = oldpos, gain = 1.0, max_hear_distance = 7}, true)
|
||||||
|
|
||||||
oldpos.y = oldpos.y + 1
|
|
||||||
|
|
||||||
effect(oldpos, 25, "teleport_potion_particle.png", 2, 2, 1, -10, 15)
|
effect(oldpos, 25, "teleport_potion_particle.png", 2, 2, 1, -10, 15)
|
||||||
|
|
||||||
-- teleport to new position, play sound and show appear effect
|
-- teleport to new position, play sound and show appear effect
|
||||||
self.player:set_pos(self.lastpos)
|
self.player:set_pos(pos)
|
||||||
|
|
||||||
core.sound_play("portal_close", {
|
core.sound_play("portal_close", {
|
||||||
pos = self.lastpos, gain = 1.0, max_hear_distance = 5}, true)
|
pos = pos, gain = 1.0, max_hear_distance = 7}, true)
|
||||||
|
|
||||||
effect(self.lastpos, 20, "teleport_potion_particle.png", 2, 2, 1, 10, 15)
|
effect(pos, 20, "teleport_potion_particle.png", 2, 2, 1, 10, 15)
|
||||||
end
|
|
||||||
|
|
||||||
self.object:remove()
|
self.object:remove()
|
||||||
|
|
||||||
return
|
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
self.lastpos = pos
|
|
||||||
end
|
|
||||||
|
|
||||||
core.register_entity("teleport_potion:potion_entity", potion_entity)
|
core.register_entity("teleport_potion:potion_entity", potion_entity)
|
||||||
|
|
||||||
--- Teleport potion
|
--- Teleport potion
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue