mirror of
https://github.com/HybridDog/nether-pack.git
synced 2024-12-26 10:40: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
|
||||
local function teleport_player(pos, player)
|
||||
local nd2 = is_soft(pos)
|
||||
pos.y = pos.y+1
|
||||
local nd3 = is_soft(pos)
|
||||
if nd2
|
||||
and nd3 then
|
||||
pos.y = pos.y-1.4
|
||||
if not is_soft(pos) then
|
||||
return false
|
||||
end
|
||||
if not is_soft({x=pos.x, y=pos.y+1, z=pos.z})
|
||||
and not is_soft({x=pos.x, y=pos.y-1, z=pos.z}) then
|
||||
return false
|
||||
end
|
||||
pos.y = pos.y+0.05
|
||||
player:moveto(pos)
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
--[[
|
||||
local dg_ps = {}
|
||||
|
@ -20,6 +20,8 @@ table.icontains = table.icontains or function(t, v)
|
||||
end
|
||||
|
||||
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")
|
||||
if file then
|
||||
local contents = file:read('*all')
|
||||
@ -28,6 +30,7 @@ if file then
|
||||
players_in_nether = string.split(contents, " ")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function save_nether_players()
|
||||
local output = ''
|
||||
@ -57,7 +60,7 @@ local function player_to_nether(player, safe)
|
||||
if table.icontains(players_in_nether, pname) then
|
||||
return
|
||||
end
|
||||
table.insert(players_in_nether, pname)
|
||||
players_in_nether[#players_in_nether+1] = pname
|
||||
save_nether_players()
|
||||
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.")
|
||||
@ -84,7 +87,6 @@ local function player_from_nether(player)
|
||||
end
|
||||
|
||||
|
||||
if nether_prisons then
|
||||
local function player_exists(name)
|
||||
for _,player in pairs(minetest.get_connected_players()) do
|
||||
if player:get_player_name() == name then
|
||||
@ -137,6 +139,9 @@ if nether_prisons then
|
||||
end
|
||||
})
|
||||
|
||||
|
||||
if nether_prisons then
|
||||
-- randomly set player position when he/she dies in nether
|
||||
minetest.register_on_respawnplayer(function(player)
|
||||
local pname = player:get_player_name()
|
||||
if not table.icontains(players_in_nether, pname) then
|
||||
@ -154,8 +159,9 @@ if nether_prisons then
|
||||
return true
|
||||
end)
|
||||
|
||||
-- function for teleporting players where they belong to
|
||||
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 ppos = player:getpos()
|
||||
if table.icontains(players_in_nether, pname) then
|
||||
@ -176,6 +182,7 @@ if nether_prisons then
|
||||
end
|
||||
end
|
||||
|
||||
-- fix wrong player positions
|
||||
local timer = 0 --doesn't work if the server lags
|
||||
minetest.register_globalstep(function(dtime)
|
||||
timer = timer + dtime;
|
||||
@ -186,6 +193,7 @@ if nether_prisons then
|
||||
end
|
||||
end)
|
||||
|
||||
-- set background when player joins
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
minetest.after(0, function(player)
|
||||
if player:getpos().y < nether.start then
|
||||
@ -193,7 +201,28 @@ if nether_prisons then
|
||||
end
|
||||
end, player)
|
||||
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)
|
||||
for z = -1,1 do
|
||||
for y = -2,2 do
|
||||
@ -207,20 +236,10 @@ if nether_prisons then
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_abm({
|
||||
nodenames = {"nether:portal"},
|
||||
interval = 1,
|
||||
chance = 2,
|
||||
catch_up = false,
|
||||
action = function(pos, node)
|
||||
if not abm_allowed then
|
||||
return
|
||||
end
|
||||
minetest.add_particlespawner({
|
||||
-- change parts of the particledefinition instead of recreating it every time
|
||||
local particledef = {
|
||||
amount = 32,
|
||||
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},
|
||||
maxvel = {x=0, y=2, z=0},
|
||||
minacc = {x=-0.5,y=-3,z=-0.3},
|
||||
@ -230,14 +249,10 @@ if nether_prisons then
|
||||
minsize = 0.4,
|
||||
maxsize = 3,
|
||||
collisiondetection = true,
|
||||
texture = "nether_portal_particle.png^[transform"..math.random(0,7),
|
||||
})
|
||||
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, function(obj, pos, target)
|
||||
}
|
||||
|
||||
-- teleports player to neter (obsidian portal)
|
||||
local function obsi_teleport_player(obj, pos, target)
|
||||
local pname = obj:get_player_name()
|
||||
if table.icontains(players_in_nether, pname) then
|
||||
return
|
||||
@ -253,8 +268,28 @@ if nether_prisons then
|
||||
minetest.sound_play("nether_portal_usual", {to_player=pname, gain=1})
|
||||
player_to_nether(obj)
|
||||
--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
|
||||
@ -302,6 +337,7 @@ if nether_prisons then
|
||||
return true
|
||||
end
|
||||
|
||||
-- tests if it's an obsidian portal
|
||||
local function is_portal(pos)
|
||||
for d=-3,3 do
|
||||
for y=-4,4 do
|
||||
@ -317,6 +353,7 @@ if nether_prisons then
|
||||
end
|
||||
end
|
||||
|
||||
-- adds the violed portal essence
|
||||
local function make_portal(pos)
|
||||
local p1, p2 = is_portal(pos)
|
||||
if not p1
|
||||
@ -376,6 +413,7 @@ if nether_prisons then
|
||||
return true
|
||||
end
|
||||
|
||||
-- destroy the portal when destroying obsidian
|
||||
minetest.override_item("default:obsidian", {
|
||||
on_destruct = function(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
@ -429,12 +467,13 @@ if nether_prisons then
|
||||
end
|
||||
})
|
||||
|
||||
-- override mese crystal fragment for making an obsidian portal
|
||||
minetest.after(0.1, function()
|
||||
minetest.override_item("default:mese_crystal_fragment", {
|
||||
on_place = function(stack, player, pt)
|
||||
if pt.under
|
||||
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)
|
||||
if done then
|
||||
minetest.chat_send_player(
|
||||
@ -450,9 +489,9 @@ if nether_prisons then
|
||||
end
|
||||
})
|
||||
end)
|
||||
end
|
||||
|
||||
|
||||
-- a not filled square
|
||||
vector.square = vector.square or
|
||||
function(r)
|
||||
local tab, n = {}, 1
|
||||
@ -467,6 +506,7 @@ function(r)
|
||||
return tab
|
||||
end
|
||||
|
||||
-- detects if it's a portal
|
||||
local function netherport(pos)
|
||||
local x, y, z = pos.x, pos.y, pos.z
|
||||
for _,i in ipairs({-1, 3}) do
|
||||
|
Loading…
Reference in New Issue
Block a user