1
0
mirror of https://github.com/HybridDog/nether-pack.git synced 2025-07-15 14:20:35 +02:00

Version MFF.

This commit is contained in:
sys4-fr
2018-09-08 14:10:05 +02:00
parent 163bd4a021
commit 71236002de
139 changed files with 350 additions and 839 deletions

143
nether/portal.lua Normal file → Executable file
View File

@ -11,6 +11,9 @@ minetest.after(5, function()
abm_allowed = true
end)
nether.spawn_point = minetest.string_to_pos(minetest.setting_get("nether_static_spawnpoint") or "")
-- If nil then we use random spawn points
table.icontains = table.icontains or function(t, v)
for _,i in ipairs(t) do
if i == v then
@ -20,7 +23,7 @@ table.icontains = table.icontains or function(t, v)
return false
end
local players_in_nether = {}
nether.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")
@ -28,14 +31,14 @@ if nether_prisons then
local contents = file:read('*all')
io.close(file)
if contents then
players_in_nether = string.split(contents, " ")
nether.players_in_nether = string.split(contents, " ")
end
end
end
local function save_nether_players()
local output = ''
for _,name in ipairs(players_in_nether) do
for _,name in ipairs(nether.players_in_nether) do
output = output..name..' '
end
local f = io.open(minetest.get_worldpath()..'/nether_players', "w")
@ -44,7 +47,7 @@ local function save_nether_players()
end
local update_background
if nether_prisons then
--if nether_prisons then
function update_background(player, down)
if down then
player:set_sky({r=15, g=0, b=0}, "plain")
@ -52,9 +55,9 @@ if nether_prisons then
player:set_sky(nil, "regular")
end
end
else
function update_background()end
end
--else
-- function update_background()end
--end
-- returns nodename if area is generated, else calls generation function
local function generated_or_generate(pos)
@ -77,6 +80,7 @@ local function get_player_died_target(player)
target.y = portal_target + math.random(4)
return target
end
nether.get_player_died_target = get_player_died_target
-- used for obsidian portal
local function obsidian_teleport(player, pname)
@ -86,39 +90,44 @@ local function obsidian_teleport(player, pname)
return true
end
if not mclike_portal then
-- Pick random for obsidian, poor people gotta suffer
local target = vector.round(get_player_died_target(player))
if generated_or_generate(target) then
player:moveto(target)
return true
end
return true
end
return false
end
-- teleports players to nether or helps it
local function player_to_nether(player, safe)
function nether.player_to_nether(player, safe)
local pname = player:get_player_name()
if table.icontains(players_in_nether, pname) then
if table.icontains(nether.players_in_nether, pname) then
return
end
players_in_nether[#players_in_nether+1] = pname
nether.players_in_nether[#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.")
player:set_hp(0)
if not nether_prisons then
player:moveto(get_player_died_target(player))
if nether.spawn_point then
player:moveto(nether.spawn_point)
else
player:moveto(get_player_died_target(player))
end
end
end
update_background(player, true)
end
local function player_from_nether(player)
function nether.player_from_nether(player)
local pname = player:get_player_name()
local changes
for n,i in ipairs(players_in_nether) do
for n,i in ipairs(nether.players_in_nether) do
if i == pname then
table.remove(players_in_nether, n)
table.remove(nether.players_in_nether, n)
changes = true
end
end
@ -138,7 +147,9 @@ local function player_exists(name)
return false
end
-- Chatcommands (edited) written by sss
-- Chatcommands removed
--[[ Chatcommands (edited) written by sss
minetest.register_chatcommand("to_hell", {
params = "[<player_name>]",
description = "Send someone to hell",
@ -176,20 +187,30 @@ minetest.register_chatcommand("from_hell", {
minetest.chat_send_player(pname, "You are free now")
player_from_nether(player)
local pos = player:getpos()
player:moveto({x=pos.x, y=100, z=pos.z})
local pos_togo = {x=pos.x, y=100, z=pos.z}
if minetest.setting_getbool("static_spawnpoint") ~= nil then
local stsp_conf = minetest.setting_get("static_spawnpoint")
pos_togo = {x = stsp_conf:split(",")[1]+0,y = stsp_conf:split(",")[2]+0,z = stsp_conf:split(",")[3]+0}
end
player:moveto(pos_togo)
return true, pname.." is now out of the nether."
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
if not table.icontains(nether.players_in_nether, pname) then
return
end
local target = get_player_died_target(player)
local target
if nether.spawn_point then
target = nether.spawn_point
else
target = get_player_died_target(player)
end
player:moveto(target)
minetest.after(0, function(pname, target)
-- fixes respawn bug
@ -206,7 +227,7 @@ if nether_prisons then
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
if table.icontains(nether.players_in_nether, pname) then
if ppos.y > nether.start then
player:moveto({x=ppos.x, y=portal_target, z=ppos.z})
update_background(player, true)
@ -225,15 +246,11 @@ if nether_prisons then
end
-- fix wrong player positions
local timer = 0 --doesn't work if the server lags
minetest.register_globalstep(function(dtime)
timer = timer + dtime;
if timer >= 2 then
--minetest.after(1, update_players)
update_players()
timer = 0
end
end)
local function tick()
update_players()
minetest.after(2, tick)
end
tick()
-- set background when player joins
minetest.register_on_joinplayer(function(player)
@ -247,15 +264,16 @@ else
-- test if player is in nether when he/she joins
minetest.register_on_joinplayer(function(player)
minetest.after(0, function(player)
local pname = player:get_player_name()
if player:getpos().y < nether.start then
if not table.icontains(players_in_nether, pname) then
players_in_nether[#players_in_nether+1] = pname
if not table.icontains(nether.players_in_nether, pname) then
nether.players_in_nether[#nether.players_in_nether+1] = pname
end
return
end
for i,name in pairs(players_in_nether) do
for i,name in pairs(nether.players_in_nether) do
if name == pname then
players_in_nether[i] = nil
nether.players_in_nether[i] = nil
return
end
end
@ -295,7 +313,7 @@ local particledef = {
-- teleports player to neter (obsidian portal)
local function obsi_teleport_player(player, pos, target)
local pname = player:get_player_name()
if table.icontains(players_in_nether, pname) then
if table.icontains(nether.players_in_nether, pname) then
return
end
@ -310,7 +328,7 @@ local function obsi_teleport_player(player, pos, target)
return
end
players_in_nether[#players_in_nether+1] = pname
nether.players_in_nether[#nether.players_in_nether+1] = pname
save_nether_players()
update_background(player, true)
@ -645,40 +663,49 @@ function nether_port(player, pos)
if not netherport(pos) then
return
end
minetest.sound_play("nether_teleporter", {to_player=player:get_player_name()}) --MFF crabman (5/09/2015) fix positional sound don't work to player
minetest.sound_play("nether_teleporter", {pos=pos})
local meta = minetest.get_meta({x=pos.x, y=pos.y-1, z=pos.z})
if pos.y < nether.start then
set_portal(known_portals_d, pos.z,pos.x, pos.y)
player_from_nether(player)
nether.player_from_nether(player)
local my = tonumber(meta:get_string("y"))
local y = get_portal(known_portals_u, pos.z,pos.x)
if y then
if y ~= my then
meta:set_string("y", y)
end
if minetest.setting_getbool("static_spawnpoint") then
local stsp_conf = minetest.setting_get("static_spawnpoint")
pos = minetest.string_to_pos(stsp_conf)
else
y = my or 100
local my = tonumber(meta:get_string("y"))
local y = get_portal(known_portals_u, pos.z,pos.x)
if y then
if y ~= my then
meta:set_string("y", y)
end
else
y = my or 100
end
pos.y = y
end
pos.y = y
player:moveto(pos)
else
set_portal(known_portals_u, pos.z,pos.x, pos.y)
local my = tonumber(meta:get_string("y"))
local y = get_portal(known_portals_d, pos.z,pos.x)
if y then
if y ~= my then
meta:set_string("y", y)
end
if nether.spawn_point then
pos = nether.spawn_point
else
y = my or portal_target+math.random(4)
end
pos.y = y
set_portal(known_portals_u, pos.z,pos.x, pos.y)
local my = tonumber(meta:get_string("y"))
local y = get_portal(known_portals_d, pos.z,pos.x)
if y then
if y ~= my then
meta:set_string("y", y)
end
else
y = my or portal_target+math.random(4)
end
pos.y = y
end
player:moveto(pos)
player_to_nether(player, true)
nether.player_to_nether(player, true)
end
minetest.sound_play("nether_teleporter", {pos=pos})
return true