1
0
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:
HybridDog 2016-01-04 10:55:39 +01:00
parent 6b57e60e1b
commit cacfae9502
2 changed files with 355 additions and 315 deletions

View File

@ -56,16 +56,16 @@ 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
return false
end end
--[[ --[[

View File

@ -20,13 +20,16 @@ table.icontains = table.icontains or function(t, v)
end end
local players_in_nether = {} local players_in_nether = {}
local file = io.open(minetest.get_worldpath()..'/nether_players', "r") -- only get info from file if nether prisons
if file then if nether_prisons then
local file = io.open(minetest.get_worldpath()..'/nether_players', "r")
if file then
local contents = file:read('*all') local contents = file:read('*all')
io.close(file) io.close(file)
if contents then if contents 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()
@ -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,18 +87,17 @@ 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
return true return true
end end
end end
return false return false
end end
-- Chatcommands (edited) written by sss -- Chatcommands (edited) written by sss
minetest.register_chatcommand("to_hell", { minetest.register_chatcommand("to_hell", {
params = "[<player_name>]", params = "[<player_name>]",
description = "Send someone to hell", description = "Send someone to hell",
func = function(name, pname) func = function(name, pname)
@ -113,9 +115,9 @@ if nether_prisons then
player_to_nether(player) player_to_nether(player)
return true, pname.." is now in the nether." return true, pname.." is now in the nether."
end end
}) })
minetest.register_chatcommand("from_hell", { minetest.register_chatcommand("from_hell", {
params = "[<player_name>]", params = "[<player_name>]",
description = "Extract from hell", description = "Extract from hell",
func = function(name, pname) func = function(name, pname)
@ -135,8 +137,11 @@ if nether_prisons then
player:moveto({x=pos.x, y=100, z=pos.z}) player:moveto({x=pos.x, y=100, z=pos.z})
return true, pname.." is now out of the nether." return true, pname.." is now out of the nether."
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,8 +201,29 @@ 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
local function remove_portal_essence(pos) -- removes the violet stuff from the obsidian portal
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
for x = -1,1 do for x = -1,1 do
@ -205,22 +234,12 @@ if nether_prisons then
end end
end end
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,15 +268,35 @@ 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
end, end,
}) })
local function move_check(p1, max, dir) local function move_check(p1, max, dir)
local p = {x=p1.x, y=p1.y, z=p1.z} local p = {x=p1.x, y=p1.y, z=p1.z}
local d = math.abs(max-p1[dir]) / (max-p1[dir]) local d = math.abs(max-p1[dir]) / (max-p1[dir])
while p[dir] ~= max do while p[dir] ~= max do
@ -271,9 +306,9 @@ if nether_prisons then
end end
end end
return true return true
end end
local function check_portal(p1, p2) local function check_portal(p1, p2)
if p1.x ~= p2.x then if p1.x ~= p2.x then
if not move_check(p1, p2.x, "x") then if not move_check(p1, p2.x, "x") then
return false return false
@ -300,9 +335,10 @@ if nether_prisons then
end end
return true return true
end end
local function is_portal(pos) -- tests if it's an obsidian portal
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
local px = {x=pos.x+d, y=pos.y+y, z=pos.z} local px = {x=pos.x+d, y=pos.y+y, z=pos.z}
@ -315,9 +351,10 @@ if nether_prisons then
end end
end end
end end
end end
local function make_portal(pos) -- adds the violed portal essence
local function make_portal(pos)
local p1, p2 = is_portal(pos) local p1, p2 = is_portal(pos)
if not p1 if not p1
or not p2 then or not p2 then
@ -374,9 +411,10 @@ if nether_prisons then
end end
print("[nether] construction accepted.") print("[nether] construction accepted.")
return true return true
end end
minetest.override_item("default:obsidian", { -- destroy the portal when destroying 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)
local p1 = minetest.string_to_pos(meta:get_string("p1")) local p1 = minetest.string_to_pos(meta:get_string("p1"))
@ -427,14 +465,15 @@ if nether_prisons then
end end
end end
end end
}) })
minetest.after(0.1, function() -- override mese crystal fragment for making an obsidian portal
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(
@ -449,10 +488,10 @@ if nether_prisons then
return stack return stack
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