mirror of
https://github.com/HybridDog/nether-pack.git
synced 2024-12-27 03:00:24 +01:00
add comments and begin making obsidian portal always work
This commit is contained in:
parent
6b57e60e1b
commit
cacfae9502
@ -56,17 +56,17 @@ end
|
|||||||
|
|
||||||
-- teleports the player there if there's free space
|
-- teleports the player there if there's free space
|
||||||
local function teleport_player(pos, player)
|
local function teleport_player(pos, player)
|
||||||
local nd2 = is_soft(pos)
|
if not is_soft(pos) then
|
||||||
pos.y = pos.y+1
|
return false
|
||||||
local nd3 = is_soft(pos)
|
end
|
||||||
if nd2
|
if not is_soft({x=pos.x, y=pos.y+1, z=pos.z})
|
||||||
and nd3 then
|
and not is_soft({x=pos.x, y=pos.y-1, z=pos.z}) then
|
||||||
pos.y = pos.y-1.4
|
return false
|
||||||
|
end
|
||||||
|
pos.y = pos.y+0.05
|
||||||
player:moveto(pos)
|
player:moveto(pos)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
local dg_ps = {}
|
local dg_ps = {}
|
||||||
|
@ -20,6 +20,8 @@ table.icontains = table.icontains or function(t, v)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local players_in_nether = {}
|
local players_in_nether = {}
|
||||||
|
-- only get info from file if nether prisons
|
||||||
|
if nether_prisons then
|
||||||
local file = io.open(minetest.get_worldpath()..'/nether_players', "r")
|
local file = io.open(minetest.get_worldpath()..'/nether_players', "r")
|
||||||
if file then
|
if file then
|
||||||
local contents = file:read('*all')
|
local contents = file:read('*all')
|
||||||
@ -28,6 +30,7 @@ if file then
|
|||||||
players_in_nether = string.split(contents, " ")
|
players_in_nether = string.split(contents, " ")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local function save_nether_players()
|
local function save_nether_players()
|
||||||
local output = ''
|
local output = ''
|
||||||
@ -57,7 +60,7 @@ local function player_to_nether(player, safe)
|
|||||||
if table.icontains(players_in_nether, pname) then
|
if table.icontains(players_in_nether, pname) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
table.insert(players_in_nether, pname)
|
players_in_nether[#players_in_nether+1] = pname
|
||||||
save_nether_players()
|
save_nether_players()
|
||||||
if not safe then
|
if not safe then
|
||||||
minetest.chat_send_player(pname, "For any reason you arrived here. Type /nether_help to find out things like craft recipes.")
|
minetest.chat_send_player(pname, "For any reason you arrived here. Type /nether_help to find out things like craft recipes.")
|
||||||
@ -84,7 +87,6 @@ local function player_from_nether(player)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
if nether_prisons then
|
|
||||||
local function player_exists(name)
|
local function player_exists(name)
|
||||||
for _,player in pairs(minetest.get_connected_players()) do
|
for _,player in pairs(minetest.get_connected_players()) do
|
||||||
if player:get_player_name() == name then
|
if player:get_player_name() == name then
|
||||||
@ -137,6 +139,9 @@ if nether_prisons then
|
|||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
if nether_prisons then
|
||||||
|
-- randomly set player position when he/she dies in nether
|
||||||
minetest.register_on_respawnplayer(function(player)
|
minetest.register_on_respawnplayer(function(player)
|
||||||
local pname = player:get_player_name()
|
local pname = player:get_player_name()
|
||||||
if not table.icontains(players_in_nether, pname) then
|
if not table.icontains(players_in_nether, pname) then
|
||||||
@ -154,8 +159,9 @@ if nether_prisons then
|
|||||||
return true
|
return true
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
-- function for teleporting players where they belong to
|
||||||
local function update_players()
|
local function update_players()
|
||||||
for _,player in ipairs(minetest.get_connected_players()) do
|
for _,player in pairs(minetest.get_connected_players()) do
|
||||||
local pname = player:get_player_name()
|
local pname = player:get_player_name()
|
||||||
local ppos = player:getpos()
|
local ppos = player:getpos()
|
||||||
if table.icontains(players_in_nether, pname) then
|
if table.icontains(players_in_nether, pname) then
|
||||||
@ -176,6 +182,7 @@ if nether_prisons then
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- fix wrong player positions
|
||||||
local timer = 0 --doesn't work if the server lags
|
local timer = 0 --doesn't work if the server lags
|
||||||
minetest.register_globalstep(function(dtime)
|
minetest.register_globalstep(function(dtime)
|
||||||
timer = timer + dtime;
|
timer = timer + dtime;
|
||||||
@ -186,6 +193,7 @@ if nether_prisons then
|
|||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
-- set background when player joins
|
||||||
minetest.register_on_joinplayer(function(player)
|
minetest.register_on_joinplayer(function(player)
|
||||||
minetest.after(0, function(player)
|
minetest.after(0, function(player)
|
||||||
if player:getpos().y < nether.start then
|
if player:getpos().y < nether.start then
|
||||||
@ -193,7 +201,28 @@ if nether_prisons then
|
|||||||
end
|
end
|
||||||
end, player)
|
end, player)
|
||||||
end)
|
end)
|
||||||
|
else
|
||||||
|
-- test if player is in nether when he/she joins
|
||||||
|
minetest.register_on_joinplayer(function(player)
|
||||||
|
minetest.after(0, function(player)
|
||||||
|
if player:getpos().y < nether.start then
|
||||||
|
if table.icontains(players_in_nether, pname) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
players_in_nether[#players_in_nether+1] = pname
|
||||||
|
return
|
||||||
|
end
|
||||||
|
for i,name in pairs(players_in_nether) do
|
||||||
|
if name == pname then
|
||||||
|
players_in_nether[i] = nil
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end, player)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- removes the violet stuff from the obsidian portal
|
||||||
local function remove_portal_essence(pos)
|
local function remove_portal_essence(pos)
|
||||||
for z = -1,1 do
|
for z = -1,1 do
|
||||||
for y = -2,2 do
|
for y = -2,2 do
|
||||||
@ -207,20 +236,10 @@ if nether_prisons then
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_abm({
|
-- change parts of the particledefinition instead of recreating it every time
|
||||||
nodenames = {"nether:portal"},
|
local particledef = {
|
||||||
interval = 1,
|
|
||||||
chance = 2,
|
|
||||||
catch_up = false,
|
|
||||||
action = function(pos, node)
|
|
||||||
if not abm_allowed then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
minetest.add_particlespawner({
|
|
||||||
amount = 32,
|
amount = 32,
|
||||||
time = 4,
|
time = 4,
|
||||||
minpos = {x=pos.x-0.25, y=pos.y-0.5, z=pos.z-0.25},
|
|
||||||
maxpos = {x=pos.x+0.25, y=pos.y+0.34, z=pos.z+0.25},
|
|
||||||
minvel = {x=0, y=1, z=0},
|
minvel = {x=0, y=1, z=0},
|
||||||
maxvel = {x=0, y=2, z=0},
|
maxvel = {x=0, y=2, z=0},
|
||||||
minacc = {x=-0.5,y=-3,z=-0.3},
|
minacc = {x=-0.5,y=-3,z=-0.3},
|
||||||
@ -230,14 +249,10 @@ if nether_prisons then
|
|||||||
minsize = 0.4,
|
minsize = 0.4,
|
||||||
maxsize = 3,
|
maxsize = 3,
|
||||||
collisiondetection = true,
|
collisiondetection = true,
|
||||||
texture = "nether_portal_particle.png^[transform"..math.random(0,7),
|
}
|
||||||
})
|
|
||||||
for _,obj in pairs(minetest.get_objects_inside_radius(pos, 1)) do
|
-- teleports player to neter (obsidian portal)
|
||||||
if obj:is_player() then
|
local function obsi_teleport_player(obj, pos, target)
|
||||||
local meta = minetest.get_meta(pos)
|
|
||||||
local target = minetest.string_to_pos(meta:get_string("target"))
|
|
||||||
if target then
|
|
||||||
minetest.after(3, function(obj, pos, target)
|
|
||||||
local pname = obj:get_player_name()
|
local pname = obj:get_player_name()
|
||||||
if table.icontains(players_in_nether, pname) then
|
if table.icontains(players_in_nether, pname) then
|
||||||
return
|
return
|
||||||
@ -253,8 +268,28 @@ if nether_prisons then
|
|||||||
minetest.sound_play("nether_portal_usual", {to_player=pname, gain=1})
|
minetest.sound_play("nether_portal_usual", {to_player=pname, gain=1})
|
||||||
player_to_nether(obj)
|
player_to_nether(obj)
|
||||||
--obj:setpos(target)
|
--obj:setpos(target)
|
||||||
|
end
|
||||||
|
|
||||||
end, obj, pos, target)
|
-- abm for particles of the obsidian portal essence and for teleporting
|
||||||
|
minetest.register_abm({
|
||||||
|
nodenames = {"nether:portal"},
|
||||||
|
interval = 1,
|
||||||
|
chance = 2,
|
||||||
|
catch_up = false,
|
||||||
|
action = function(pos, node)
|
||||||
|
if not abm_allowed then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
particledef.minpos = {x=pos.x-0.25, y=pos.y-0.5, z=pos.z-0.25}
|
||||||
|
particledef.maxpos = {x=pos.x+0.25, y=pos.y+0.34, z=pos.z+0.25}
|
||||||
|
particledef.texture = "nether_portal_particle.png^[transform"..math.random(0,7)
|
||||||
|
minetest.add_particlespawner(particledef)
|
||||||
|
for _,obj in pairs(minetest.get_objects_inside_radius(pos, 1)) do
|
||||||
|
if obj:is_player() then
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
local target = minetest.string_to_pos(meta:get_string("target"))
|
||||||
|
if target then
|
||||||
|
minetest.after(3, obsi_teleport_player, obj, pos, target)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -302,6 +337,7 @@ if nether_prisons then
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- tests if it's an obsidian portal
|
||||||
local function is_portal(pos)
|
local function is_portal(pos)
|
||||||
for d=-3,3 do
|
for d=-3,3 do
|
||||||
for y=-4,4 do
|
for y=-4,4 do
|
||||||
@ -317,6 +353,7 @@ if nether_prisons then
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- adds the violed portal essence
|
||||||
local function make_portal(pos)
|
local function make_portal(pos)
|
||||||
local p1, p2 = is_portal(pos)
|
local p1, p2 = is_portal(pos)
|
||||||
if not p1
|
if not p1
|
||||||
@ -376,6 +413,7 @@ if nether_prisons then
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- destroy the portal when destroying obsidian
|
||||||
minetest.override_item("default:obsidian", {
|
minetest.override_item("default:obsidian", {
|
||||||
on_destruct = function(pos)
|
on_destruct = function(pos)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
@ -429,12 +467,13 @@ if nether_prisons then
|
|||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
|
-- override mese crystal fragment for making an obsidian portal
|
||||||
minetest.after(0.1, function()
|
minetest.after(0.1, function()
|
||||||
minetest.override_item("default:mese_crystal_fragment", {
|
minetest.override_item("default:mese_crystal_fragment", {
|
||||||
on_place = function(stack, player, pt)
|
on_place = function(stack, player, pt)
|
||||||
if pt.under
|
if pt.under
|
||||||
and minetest.get_node(pt.under).name == "default:obsidian" then
|
and minetest.get_node(pt.under).name == "default:obsidian" then
|
||||||
print("[nether] tries to enable a portal")
|
--print("[nether] tries to enable a portal")
|
||||||
local done = make_portal(pt.under)
|
local done = make_portal(pt.under)
|
||||||
if done then
|
if done then
|
||||||
minetest.chat_send_player(
|
minetest.chat_send_player(
|
||||||
@ -450,9 +489,9 @@ if nether_prisons then
|
|||||||
end
|
end
|
||||||
})
|
})
|
||||||
end)
|
end)
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
|
-- a not filled square
|
||||||
vector.square = vector.square or
|
vector.square = vector.square or
|
||||||
function(r)
|
function(r)
|
||||||
local tab, n = {}, 1
|
local tab, n = {}, 1
|
||||||
@ -467,6 +506,7 @@ function(r)
|
|||||||
return tab
|
return tab
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- detects if it's a portal
|
||||||
local function netherport(pos)
|
local function netherport(pos)
|
||||||
local x, y, z = pos.x, pos.y, pos.z
|
local x, y, z = pos.x, pos.y, pos.z
|
||||||
for _,i in ipairs({-1, 3}) do
|
for _,i in ipairs({-1, 3}) do
|
||||||
|
Loading…
Reference in New Issue
Block a user