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,16 +56,16 @@ 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
|
||||
|
||||
--[[
|
||||
|
@ -20,13 +20,16 @@ table.icontains = table.icontains or function(t, v)
|
||||
end
|
||||
|
||||
local players_in_nether = {}
|
||||
local file = io.open(minetest.get_worldpath()..'/nether_players', "r")
|
||||
if file then
|
||||
-- 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')
|
||||
io.close(file)
|
||||
if contents then
|
||||
players_in_nether = string.split(contents, " ")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function save_nether_players()
|
||||
@ -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,18 +87,17 @@ local function player_from_nether(player)
|
||||
end
|
||||
|
||||
|
||||
if nether_prisons then
|
||||
local function player_exists(name)
|
||||
local function player_exists(name)
|
||||
for _,player in pairs(minetest.get_connected_players()) do
|
||||
if player:get_player_name() == name then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
-- Chatcommands (edited) written by sss
|
||||
minetest.register_chatcommand("to_hell", {
|
||||
-- Chatcommands (edited) written by sss
|
||||
minetest.register_chatcommand("to_hell", {
|
||||
params = "[<player_name>]",
|
||||
description = "Send someone to hell",
|
||||
func = function(name, pname)
|
||||
@ -113,9 +115,9 @@ if nether_prisons then
|
||||
player_to_nether(player)
|
||||
return true, pname.." is now in the nether."
|
||||
end
|
||||
})
|
||||
})
|
||||
|
||||
minetest.register_chatcommand("from_hell", {
|
||||
minetest.register_chatcommand("from_hell", {
|
||||
params = "[<player_name>]",
|
||||
description = "Extract from hell",
|
||||
func = function(name, pname)
|
||||
@ -135,8 +137,11 @@ if nether_prisons then
|
||||
player:moveto({x=pos.x, y=100, z=pos.z})
|
||||
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
|
||||
@ -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,8 +201,29 @@ 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
|
||||
|
||||
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 y = -2,2 do
|
||||
for x = -1,1 do
|
||||
@ -205,22 +234,12 @@ if nether_prisons then
|
||||
end
|
||||
end
|
||||
end
|
||||
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,15 +268,35 @@ 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
|
||||
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 d = math.abs(max-p1[dir]) / (max-p1[dir])
|
||||
while p[dir] ~= max do
|
||||
@ -271,9 +306,9 @@ if nether_prisons then
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local function check_portal(p1, p2)
|
||||
local function check_portal(p1, p2)
|
||||
if p1.x ~= p2.x then
|
||||
if not move_check(p1, p2.x, "x") then
|
||||
return false
|
||||
@ -300,9 +335,10 @@ if nether_prisons then
|
||||
end
|
||||
|
||||
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 y=-4,4 do
|
||||
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
|
||||
|
||||
local function make_portal(pos)
|
||||
-- adds the violed portal essence
|
||||
local function make_portal(pos)
|
||||
local p1, p2 = is_portal(pos)
|
||||
if not p1
|
||||
or not p2 then
|
||||
@ -374,9 +411,10 @@ if nether_prisons then
|
||||
end
|
||||
print("[nether] construction accepted.")
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
minetest.override_item("default:obsidian", {
|
||||
-- destroy the portal when destroying obsidian
|
||||
minetest.override_item("default:obsidian", {
|
||||
on_destruct = function(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local p1 = minetest.string_to_pos(meta:get_string("p1"))
|
||||
@ -427,14 +465,15 @@ if nether_prisons then
|
||||
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", {
|
||||
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(
|
||||
@ -449,10 +488,10 @@ if nether_prisons then
|
||||
return stack
|
||||
end
|
||||
})
|
||||
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