Change everything to use mod storage through functions.

Also (re?) fixed problems with the TARDIS spawining into ungenerated chunks.
Fixed collision boxes for TARDIS and interior doors.
Made navigation formspec have default values based on current nav data.
Made things use functions rather than raw tables, which allowed the use of default values to make the game more stable.
Added .luacheckrc
entity
Benrob0329 2017-11-29 03:42:10 -05:00
parent 66d2ba8607
commit e32e097e62
6 changed files with 585 additions and 531 deletions

14
.luacheckrc Normal file
View File

@ -0,0 +1,14 @@
unused_args = false
allow_defined_top = true
read_globals = {
"DIR_DELIM",
"minetest", "core",
"dump",
"vector", "nodeupdate",
"VoxelManip", "VoxelArea",
"PseudoRandom", "ItemStack",
"intllib",
"default",
table = { fields = { "copy", "getn" } }
}

350
demat.lua
View File

@ -1,229 +1,231 @@
function tardis.demat (owner, name) function tardis.demat(name)
if owner ~= name then return false, "You don't own that TARDIS!" end local pos = tardis.get_exterior(name)
local pos = tardis.tardises [owner]["exterior"]
minetest.forceload_block(pos)
minetest.set_node (pos, {name = "tardis:tardis_demat"})
tardis.tardises [owner]["in_vortex"] = true if (minetest.forceload_block(pos)) then
minetest.set_node (pos, {name = "tardis:tardis_demat"})
minetest.sound_play ("tardis_demat", { tardis.set_vortex(true, name)
pos = pos ,
max_hear_distance = 100 , minetest.sound_play ("tardis_demat", {
gain = 10 , pos = pos,
}) max_hear_distance = 100,
return true gain = 10 ,
})
return true
else return false
end
end end
minetest.register_node ("tardis:tardis_demat", { minetest.register_node("tardis:tardis_demat", {
tiles = {"tardis_exterior.png^[opacity:255"} , tiles = {"tardis_exterior.png^[opacity:255"},
use_texture_alpha = true , use_texture_alpha = true,
drawtype = "mesh" , drawtype = "mesh",
mesh = "tardis_exterior.obj" , mesh = "tardis_exterior.obj",
paramtype = "light" , paramtype = "light",
is_ground_content = true , is_ground_content = true,
light_source = 5 , light_source = 5,
on_timer = function (pos) on_timer = function(pos)
minetest.set_node (pos, {name = "tardis:tardis_demat_1"}) minetest.set_node(pos, {name = "tardis:tardis_demat_1"})
end , end,
on_construct = function (pos) on_construct = function(pos)
minetest.get_node_timer (pos):start(7) minetest.get_node_timer(pos):start(7)
end , end,
}) })
minetest.register_node ("tardis:tardis_demat_1", { minetest.register_node("tardis:tardis_demat_1", {
tiles = {"tardis_exterior.png^[opacity:225"} , tiles = {"tardis_exterior.png^[opacity:225"},
use_texture_alpha = true , use_texture_alpha = true,
drawtype = "mesh" , drawtype = "mesh",
mesh = "tardis_exterior.obj" , mesh = "tardis_exterior.obj",
paramtype = "light" , paramtype = "light",
is_ground_content = true , is_ground_content = true,
light_source = 10 , light_source = 10,
on_timer = function (pos) on_timer = function(pos)
minetest.set_node (pos, {name = "tardis:tardis_demat_2"}) minetest.set_node(pos, {name = "tardis:tardis_demat_2"})
end , end,
on_construct = function (pos) on_construct = function(pos)
minetest.get_node_timer (pos):start(1) minetest.get_node_timer(pos):start(1)
end , end,
}) })
minetest.register_node ("tardis:tardis_demat_2", { minetest.register_node("tardis:tardis_demat_2", {
tiles = {"tardis_exterior.png^[opacity:200"} , tiles = {"tardis_exterior.png^[opacity:200"},
use_texture_alpha = true , use_texture_alpha = true,
drawtype = "mesh" , drawtype = "mesh",
mesh = "tardis_exterior.obj" , mesh = "tardis_exterior.obj",
paramtype = "light" , paramtype = "light",
is_ground_content = true , is_ground_content = true,
on_timer = function (pos) on_timer = function(pos)
minetest.set_node (pos, {name = "tardis:tardis_demat_3"}) minetest.set_node(pos, {name = "tardis:tardis_demat_3"})
end , end,
on_construct = function (pos) on_construct = function(pos)
minetest.get_node_timer (pos):start(1) minetest.get_node_timer(pos):start(1)
end , end,
}) })
minetest.register_node("tardis:tardis_demat_3", { minetest.register_node("tardis:tardis_demat_3", {
tiles = {"tardis_exterior.png^[opacity:175"} , tiles = {"tardis_exterior.png^[opacity:175"},
use_texture_alpha = true , use_texture_alpha = true,
drawtype = "mesh" , drawtype = "mesh",
mesh = "tardis_exterior.obj" , mesh = "tardis_exterior.obj",
paramtype = "light" , paramtype = "light",
is_ground_content = true , is_ground_content = true,
light_source = 10 , light_source = 10,
on_timer = function (pos) on_timer = function(pos)
minetest.set_node (pos, {name = "tardis:tardis_demat_4"}) minetest.set_node(pos, {name = "tardis:tardis_demat_4"})
end , end,
on_construct = function (pos) on_construct = function(pos)
minetest.get_node_timer (pos):start(1) minetest.get_node_timer(pos):start(1)
end , end,
}) })
minetest.register_node ("tardis:tardis_demat_4", { minetest.register_node("tardis:tardis_demat_4", {
tiles = {"tardis_exterior.png^[opacity:150"} , tiles = {"tardis_exterior.png^[opacity:150"},
use_texture_alpha = true , use_texture_alpha = true,
drawtype = "mesh" , drawtype = "mesh",
mesh = "tardis_exterior.obj" , mesh = "tardis_exterior.obj",
paramtype = "light" , paramtype = "light",
is_ground_content = true , is_ground_content = true,
on_timer = function (pos) on_timer = function(pos)
minetest.set_node (pos, {name = "tardis:tardis_demat_5"}) minetest.set_node(pos, {name = "tardis:tardis_demat_5"})
end , end,
on_construct = function (pos) on_construct = function(pos)
minetest.get_node_timer (pos):start(0.5) minetest.get_node_timer(pos):start(0.5)
end , end,
}) })
minetest.register_node ("tardis:tardis_demat_5", { minetest.register_node("tardis:tardis_demat_5", {
tiles = {"tardis_exterior.png^[opacity:125"} , tiles = {"tardis_exterior.png^[opacity:125"},
use_texture_alpha = true , use_texture_alpha = true,
drawtype = "mesh" , drawtype = "mesh",
mesh = "tardis_exterior.obj" , mesh = "tardis_exterior.obj",
paramtype = "light" , paramtype = "light",
is_ground_content = true , is_ground_content = true,
light_source = 10 , light_source = 10,
on_timer = function (pos) on_timer = function(pos)
minetest.set_node (pos, {name = "tardis:tardis_demat_6"}) minetest.set_node(pos, {name = "tardis:tardis_demat_6"})
end , end,
on_construct = function (pos) on_construct = function(pos)
minetest.get_node_timer (pos):start(1) minetest.get_node_timer(pos):start(1)
end , end,
}) })
minetest.register_node ("tardis:tardis_demat_6", { minetest.register_node("tardis:tardis_demat_6", {
tiles = {"tardis_exterior.png^[opacity:100"} , tiles = {"tardis_exterior.png^[opacity:100"},
use_texture_alpha = true , use_texture_alpha = true,
drawtype = "mesh" , drawtype = "mesh",
mesh = "tardis_exterior.obj" , mesh = "tardis_exterior.obj",
paramtype = "light" , paramtype = "light",
is_ground_content = true , is_ground_content = true,
on_timer = function (pos) on_timer = function(pos)
minetest.set_node (pos, {name = "tardis:tardis_demat_7"}) minetest.set_node(pos, {name = "tardis:tardis_demat_7"})
end , end,
on_construct = function (pos) on_construct = function(pos)
minetest.get_node_timer (pos):start(1) minetest.get_node_timer(pos):start(1)
end , end,
}) })
minetest.register_node ("tardis:tardis_demat_7", { minetest.register_node("tardis:tardis_demat_7", {
tiles = {"tardis_exterior.png^[opacity:75"} , tiles = {"tardis_exterior.png^[opacity:75"},
use_texture_alpha = true , use_texture_alpha = true,
drawtype = "mesh" , drawtype = "mesh",
mesh = "tardis_exterior.obj" , mesh = "tardis_exterior.obj",
paramtype = "light" , paramtype = "light",
light_source = 10 , light_source = 10,
on_timer = function (pos) on_timer = function(pos)
minetest.set_node (pos, {name = "tardis:tardis_demat_8"}) minetest.set_node(pos, {name = "tardis:tardis_demat_8"})
end , end,
on_construct = function (pos) on_construct = function(pos)
minetest.get_node_timer (pos):start(1) minetest.get_node_timer(pos):start(1)
end , end,
}) })
minetest.register_node ("tardis:tardis_demat_8", { minetest.register_node("tardis:tardis_demat_8", {
tiles = {"tardis_exterior.png^[opacity:50"} , tiles = {"tardis_exterior.png^[opacity:50"},
use_texture_alpha = true , use_texture_alpha = true,
drawtype = "mesh" , drawtype = "mesh",
mesh = "tardis_exterior.obj" , mesh = "tardis_exterior.obj",
paramtype = "light" , paramtype = "light",
is_ground_content = true , is_ground_content = true,
on_timer = function (pos) on_timer = function(pos)
minetest.set_node (pos, {name = "tardis:tardis_demat_9"}) minetest.set_node(pos, {name = "tardis:tardis_demat_9"})
end , end,
on_construct = function (pos) on_construct = function(pos)
minetest.get_node_timer (pos):start(1) minetest.get_node_timer(pos):start(1)
end , end,
}) })
minetest.register_node ("tardis:tardis_demat_9", { minetest.register_node("tardis:tardis_demat_9", {
tiles = {"tardis_exterior.png^[opacity:25"} , tiles = {"tardis_exterior.png^[opacity:25"},
use_texture_alpha = true , use_texture_alpha = true,
drawtype = "mesh" , drawtype = "mesh",
mesh = "tardis_exterior.obj" , mesh = "tardis_exterior.obj",
paramtype = "light" , paramtype = "light",
is_ground_content = true , is_ground_content = true,
light_source = 7 , light_source = 7,
on_timer = function (pos) on_timer = function(pos)
minetest.set_node (pos, {name = "tardis:tardis_demat_10"}) minetest.set_node(pos, {name = "tardis:tardis_demat_10"})
end , end,
on_construct = function (pos) on_construct = function(pos)
minetest.get_node_timer (pos):start(1) minetest.get_node_timer(pos):start(1)
end , end,
}) })
minetest.register_node ("tardis:tardis_demat_10", { minetest.register_node("tardis:tardis_demat_10", {
tiles = {"tardis_exterior.png^[opacity:10"} , tiles = {"tardis_exterior.png^[opacity:10"},
use_texture_alpha = true , use_texture_alpha = true,
drawtype = "mesh" , drawtype = "mesh",
mesh = "tardis_exterior.obj" , mesh = "tardis_exterior.obj",
paramtype = "light" , paramtype = "light",
is_ground_content = true , is_ground_content = true,
on_timer = function (pos) on_timer = function(pos)
minetest.set_node (pos, {name = "tardis:tardis_demat_11"}) minetest.set_node(pos, {name = "tardis:tardis_demat_11"})
end , end,
on_construct = function (pos) on_construct = function(pos)
minetest.get_node_timer (pos):start(0.5) minetest.get_node_timer(pos):start(0.5)
end , end,
}) })
minetest.register_node ("tardis:tardis_demat_11", { minetest.register_node("tardis:tardis_demat_11", {
tiles = {"tardis_exterior.png^[opacity:5"} , tiles = {"tardis_exterior.png^[opacity:5"} ,
use_texture_alpha = true , use_texture_alpha = true,
drawtype = "mesh" , drawtype = "mesh",
mesh = "tardis_exterior.obj" , mesh = "tardis_exterior.obj",
paramtype = "light" , paramtype = "light",
is_ground_content = true , is_ground_content = true,
light_source = 5 , light_source = 5,
on_timer = function (pos) on_timer = function(pos)
minetest.set_node (pos, {name = "air"}) minetest.set_node(pos, {name = "air"})
minetest.forceload_free_block (pos) minetest.forceload_free_block(pos)
end , end,
on_construct = function (pos) on_construct = function(pos)
minetest.get_node_timer (pos):start(1) minetest.get_node_timer(pos):start(1)
end , end,
}) })

View File

@ -1,6 +1,108 @@
local modname = minetest.get_current_modname() local modname = minetest.get_current_modname()
local modpath = minetest.get_modpath(modname) local modpath = minetest.get_modpath(modname)
local worldpath = minetest.get_worldpath() local mod_storage = minetest.get_mod_storage()
-- Functions are fairly self explanitory, get or set the specified value.
function tardis.set_nav(pos, name)
local pos_string = (minetest.pos_to_string(pos))
if (pos_string) then
if (mod_storage:set_string("tardis:"..name..":destination", pos_string)) then
return true
else return false
end
end
end
function tardis.get_nav(name)
local pos = minetest.string_to_pos(mod_storage:get_string("tardis:"..name..":destination"))
if (pos) then
return pos
elseif (tardis.get_exterior(name)) then
return tardis.get_exterior(name)
else return { x = 0, y = 0, z = 0 }
end
end
function tardis.set_exterior(pos, name)
local pos_string = (minetest.pos_to_string(pos))
if (pos_string) then
if (mod_storage:set_string("tardis:"..name..":exterior", pos_string)) then
return true
else return false
end
end
end
function tardis.get_exterior(name)
local pos = minetest.string_to_pos(mod_storage:get_string("tardis:"..name..":exterior"))
if (pos) then
return pos
else return false
end
end
function tardis.set_interior(pos, name)
local pos_string = (minetest.pos_to_string(pos))
if (pos_string) then
if (mod_storage:set_string("tardis:"..name..":interior", pos_string)) then
return true
else return false
end
end
end
function tardis.get_interior(name)
local pos = minetest.string_to_pos(mod_storage:get_string("tardis:"..name..":interior"))
if (pos) then
return pos
else return false
end
end
function tardis.add_count()
local current_count = tonumber(mod_storage:get_string("tardis:count"))
if (current_count) then
if (mod_storage:set_string("tardis:count", tostring(current_count+1))) then
return true
else return false
end
elseif (mod_storage:set_string("tardis:count", "1")) then
return true
else return false
end
end
function tardis.get_count()
local current_count = tonumber(mod_storage:get_string("tardis:count"))
if (current_count) then
return current_count
else return 0
end
end
function tardis.set_vortex(bool, name)
if (mod_storage:set_string("tardis:"..name..":vortex", tostring(bool))) then
return true
else return nil
end
end
function tardis.get_vortex(name)
if (mod_storage:get_string("tardis:"..name..":vortex") == "true") then
return true
else return false
end
end
-- Hacky node swap function since minetest.swap_node doesnt call any callbacks -- Hacky node swap function since minetest.swap_node doesnt call any callbacks
function tardis.swap_node (pos, name) function tardis.swap_node (pos, name)
@ -9,103 +111,102 @@ function tardis.swap_node (pos, name)
minetest.set_node (pos, name) minetest.set_node (pos, name)
local meta = minetest.get_meta (pos) meta = minetest.get_meta (pos)
meta:from_table (meta_old) meta:from_table (meta_old)
end end
-- Spawn a TARDIS and set the controls/doors meta with relative coordinates -- Spawn a TARDIS and set the controls/doors meta with relative coordinates
function tardis:spawn_interior (pos, owner) function tardis:spawn_interior (pos, name)
local place_pos = { local place_pos = {
x = tardis.count * 12, x = tardis.get_count() * 12,
y = 30000, y = 30000,
z = 0, z = 0,
} }
tardis.count = tardis.count + 1 tardis.add_count()
local interior_doors_pos = { local interior_doors_pos = {
x = (place_pos ["x"] + 5) , x = (place_pos["x"] + 5) ,
y = (place_pos ["y"] + 1) , y = (place_pos["y"] + 1) ,
z = (place_pos ["z"] + 1) , z = (place_pos["z"] + 1) ,
} }
local demat_lever_pos = { local demat_lever_pos = {
x = (place_pos ["x"] + 4) , x = (place_pos["x"] + 4) ,
y = (place_pos ["y"] + 2) , y = (place_pos["y"] + 2) ,
z = (place_pos ["z"] + 7) , z = (place_pos["z"] + 7) ,
} }
local nav_pos = { local nav_pos = {
x = (place_pos ["x"] + 4) , x = (place_pos["x"] + 4) ,
y = (place_pos ["y"] + 2) , y = (place_pos["y"] + 2) ,
z = (place_pos ["z"] + 8) , z = (place_pos["z"] + 8) ,
} }
minetest.place_schematic (place_pos, modpath .. "/schematics/tardis_interior.mts") minetest.place_schematic(place_pos, modpath .. "/schematics/tardis_interior.mts")
-- Add TARDIS to index -- Add TARDIS to index
tardis.tardises [owner] = {} tardis.set_exterior(pos, name)
tardis.tardises [owner]["exterior"] = pos tardis.set_interior(interior_doors_pos, name)
tardis.tardises [owner]["interior"] = interior_doors_pos tardis.set_vortex(false, name)
tardis.tardises [owner]["in_vortex"] = false
--Set meta --Set meta
local demat_meta = minetest.get_meta (demat_lever_pos) local demat_meta = minetest.get_meta(demat_lever_pos)
demat_meta:set_string ("owner", owner) demat_meta:set_string("owner", name)
local nav_meta = minetest.get_meta (nav_pos)
nav_meta:set_string ("owner", owner)
local interior_doors_meta = minetest.get_meta (interior_doors_pos) local nav_meta = minetest.get_meta(nav_pos)
interior_doors_meta:set_string ("owner", owner) nav_meta:set_string("owner", name)
minetest.log("info", minetest.pos_to_string (tardis.tardises [owner]["interior"] )) local interior_doors_meta = minetest.get_meta(interior_doors_pos)
interior_doors_meta:set_string("owner", name)
local count_file = io.open (worldpath .. "/tardis.tardises", "w+") minetest.log("info", minetest.pos_to_string(tardis.get_interior(name)))
count_file:write ( minetest.serialize (tardis.count) )
count_file:close()
local count_file = io.open(worldpath .. "/tardis.count", "w+")
count_file:write(minetest.serialize(tardis.count))
count_file:close()
end end
-- Set navigation, uses a formspec -- Set navigation, uses a formspec
function tardis.set_nav (player, owner) function tardis.show_nav_formspec(player_name, owner_name)
local player_name = player:get_player_name() if (player_name ~= owner_name) then
if player_name ~= owner then minetest.chat_send_player(player_name, "You don't own that TARDIS!"); return end minetest.chat_send_player(player_name, "You don't own that TARDIS!")
if tardis.tardises[owner]["in_vortex"] == false then minetest.chat_send_player(player_name, "You must dematerialize the TARDIS first!"); return end return false end
minetest.show_formspec (player_name, "tardis:remat_form", local pos = tardis.get_nav(owner_name)
"size[7,3]" ..
"field[1,1.5;2,1;x;X;]" ..
"field[3,1.5;2,1;y;Y;]" ..
"field[5,1.5;2,1;z;Z;]" ..
"button_exit[1,2;2,1;exit;Go!]")
minetest.register_on_player_receive_fields (function (player, formname, fields) if (pos) then
if formname ~= "tardis:remat_form" then minetest.show_formspec(player_name, "tardis:remat_form",
"size[7,3]" ..
"field[1,1.5;2,1;x;X;"..pos.x.."]" ..
"field[3,1.5;2,1;y;Y;"..pos.y.."]" ..
"field[5,1.5;2,1;z;Z;"..pos.z.."]" ..
"button_exit[1,2;2,1;exit;Go!]")
else return false end
minetest.register_on_player_receive_fields(function (player, formname, fields)
if (formname ~= "tardis:remat_form") then
return false return false
end end
local coords = {x = tonumber(fields.x), y = tonumber(fields.y), z = tonumber(fields.z)} pos = {x = tonumber(fields.x), y = tonumber(fields.y), z = tonumber(fields.z)}
if (coords == nil or coords.x == nil or coords.y == nil or coords.z == nil) then if (pos == nil or pos.x == nil or pos.y == nil or pos.z == nil) then
minetest.chat_send_player (player_name, "Please enter valid coordinates.") minetest.chat_send_player(player_name, "Please enter valid coordinates.")
else elseif (tardis.set_nav(pos, owner_name)) then
tardis.tardises [owner]["destination"] = coords
return true return true
else return false
end end
end) end)
end end
-- Make sure TARDISes places in ungenerated chunks exist and have meta set correctly.
-- When a player teleports into a previously generated mapblock with the TARDIS, we want it to appear.
minetest.register_on_generated(function(minp, maxp, blockseed) minetest.register_on_generated(function(minp, maxp, blockseed)
for owner,table in pairs(tardis.tardises) do local table = mod_storage:to_table()
local exterior = table["exterior"]
if exterior.x >= minp.x and exterior.y >= minp.y and exterior.z >= minp.z and for k, v in pairs(table.fields) do
exterior.x <= maxp.x and exterior.y <= maxp.y and exterior.z <= maxp.z then if ((k == string.match(k, "tardis:.+:exterior")) and
minetest.set_node(exterior, {name="tardis:tardis"}) (minetest.string_to_pos(v).x > minp.x) and (minetest.string_to_pos(v).y > minp.y) and (minetest.string_to_pos(v).z > minp.z) and
minetest.get_meta(exterior):set_string("owner", owner) (minetest.string_to_pos(v).x < maxp.x) and (minetest.string_to_pos(v).y < maxp.y) and (minetest.string_to_pos(v).z < maxp.z)) then
minetest.set_node(minetest.string_to_pos(v), {name = "tardis:tardis"})
local meta = minetest.get_meta(minetest.string_to_pos(v))
local owner = string.match(k, "tardis:(.+):exterior")
meta:set_string("owner", owner)
end end
end end
end) end)

View File

@ -1,54 +1,11 @@
-- Define global table and TARDIS index -- Define global table
tardis = {} tardis = {}
tardis.count = 0 tardis.done = {}
tardis.tardises = {}
local modname = minetest.get_current_modname() local modname = minetest.get_current_modname()
local modpath = minetest.get_modpath (modname) local modpath = minetest.get_modpath(modname)
local worldpath = minetest.get_worldpath()
dofile (modpath .. "/remat.lua") dofile(modpath .. "/remat.lua")
dofile (modpath .. "/demat.lua") dofile(modpath .. "/demat.lua")
dofile (modpath .. "/functions.lua") dofile(modpath .. "/functions.lua")
dofile (modpath .. "/nodes.lua") dofile(modpath .. "/nodes.lua")
-- Open TARDIS index from file
local file = io.open (worldpath .. "/tardis.tardises", "r")
local count_file = io.open (worldpath .. "/tardis.count", "r")
-- If file exists, write into current index
if file then
tardis.tardises = minetest.deserialize (file:read("*all"))
file:close()
end
if count_file then
tardis.count = minetest.deserialize (count_file:read("*all"))
count_file:close()
end
-- Register chatcommand to set navigation, return a help message if user doe not own a TARDIS
minetest.register_chatcommand ("set_nav", {
description = "Sets the navigation coordinates for your TARDIS.",
func = function (name, param)
if (tardis.tardises [name] == nil) then
minetest.chat_send_player (name, "Must be owner!")
else
local owner = name
local player = minetest.get_player_by_name (name)
tardis.set_nav (player, owner)
end
end
})
-- Save index on shutdown
minetest.register_on_shutdown( function()
local file = io.open (worldpath .. "/tardis.tardises", "w+")
file:write(minetest.serialize (tardis.tardises) )
file:close()
local count_file = io.open(worldpath .. "/tardis.count", "w+")
count_file:write(minetest.serialize(tardis.count))
count_file:close()
end )

184
nodes.lua
View File

@ -1,70 +1,71 @@
minetest.register_node ("tardis:tardis", { minetest.register_node("tardis:tardis", {
decription = "Time And Relative Dimension In Space" , decription = "Time And Relative Dimension In Space",
tiles = { "tardis_exterior.png" } , tiles = { "tardis_exterior.png" },
use_texture_alpha = true , use_texture_alpha = true,
drawtype = "mesh" , drawtype = "mesh",
mesh = "tardis_exterior.obj" , mesh = "tardis_exterior.obj",
paramtype = "light" , paramtype = "light",
is_ground_content = true , selection_box = {type = "fixed", fixed = {-0.5, -0.5, -0.5, 0.5, 1.5, 0.5}},
collision_box = {type = "fixed", fixed = {-0.5, -0.5, -0.5, 0.5, 1.5, 0.5}},
-- Setup Meta, clone meta if not placed by a player -- Setup Meta, clone meta if not placed by a player
on_place = function (itemstack, placer, pointed_thing) on_place = function(itemstack, placer, pointed_thing)
local pos = pointed_thing.above local pos = pointed_thing.above
local player = placer:get_player_name() local name = placer:get_player_name()
tardis.swap_node (pos, {name = "tardis:tardis"}) tardis.swap_node(pos, {name = "tardis:tardis"})
if (player == nil) then if (name) then
local meta = minetest.get_meta (pos) tardis:spawn_interior (pos, name)
local player = meta:get_string ("owner")
tardis.tardises [player]["exterior"] = pos
elseif (tardis.tardises [player] == nil) then
tardis:spawn_interior (pos, player)
else else
tardis.tardises [player]["exterior"] = pos local meta = minetest.get_meta(pos)
local owner = meta:get_string("owner")
if (tardis.get_interior(owner)) then
tardis.set_exerior(pos, owner)
else tardis.set_exterior(pos, name)
end
end end
local meta = minetest.get_meta (pos) local meta = minetest.get_meta(pos)
meta:set_string ("owner", player) meta:set_string ("owner", name)
itemstack:take_item() itemstack:take_item()
return itemstack return itemstack
end , end,
-- Teleport Player -- Teleport Player
on_rightclick = function (pos, node, player, itemstack, pointed_thing) on_rightclick = function(pos, node, player, itemstack, pointed_thing)
local meta = minetest.get_meta (pos) local meta = minetest.get_meta(pos)
local owner = meta:get_string ("owner") local name = meta:get_string("owner")
local teleport = { x = tardis.tardises[owner]["interior"]["x"], y = tardis.tardises[owner]["interior"]["y"], z = tardis.tardises[owner]["interior"]["z"] + 1 } local teleport = tardis.get_interior(name)
teleport.z = teleport.z + 1
player.setpos (player, teleport) player.setpos(player, teleport)
--player.set_look_horizontal(0) end,
end ,
}) })
-- Initialize materialization, fail if nav is not set, then swap node to off pos -- Initialize materialization, fail if nav is not set, then swap node to off pos
minetest.register_node ("tardis:demat_lever_on", { minetest.register_node("tardis:demat_lever_on", {
tiles = {"tardis_demat.png"} , tiles = {"tardis_demat.png"},
drawtype = "mesh" , drawtype = "mesh",
mesh = "tardis_demat_on.obj" , mesh = "tardis_demat_on.obj",
paramtype = "light" , paramtype = "light",
is_ground_content = true ,
on_rightclick = function (pos, node, player, itemstack, pointed_thing) on_rightclick = function(pos, node, player, itemstack, pointed_thing)
local player_name = player:get_player_name() local name = player:get_player_name()
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local owner = meta:get_string("owner") local owner = meta:get_string("owner")
local rematted, msg = tardis.remat (owner, player:get_player_name()) if (tardis.remat(owner)) then
if (rematted == false) then
minetest.chat_send_player (player_name, msg)
else
minetest.sound_play ("tardis_remat", { minetest.sound_play ("tardis_remat", {
pos = pos , pos = pos ,
max_hear_distance = 100 , max_hear_distance = 100 ,
gain = 10 , gain = 10 ,
}) })
minetest.swap_node (pos, {name = "tardis:demat_lever_off"}) minetest.swap_node(pos, {name = "tardis:demat_lever_off"})
else
minetest.chat_send_player(name, "Failed to remat")
end end
end end
}) })
@ -72,20 +73,17 @@ minetest.register_node ("tardis:demat_lever_on", {
-- Initialize dematerialization, then set lever to on pos -- Initialize dematerialization, then set lever to on pos
minetest.register_node ("tardis:demat_lever_off", { minetest.register_node ("tardis:demat_lever_off", {
groups = {crumbly = 1} , tiles = {"tardis_demat.png"},
tiles = {"tardis_demat.png"} , drawtype = "mesh",
drawtype = "mesh" , mesh = "tardis_demat_off.obj",
mesh = "tardis_demat_off.obj" , paramtype = "light",
paramtype = "light" ,
is_ground_content = true ,
on_rightclick = function (pos, node, player, itemstack, pointed_thing) on_rightclick = function(pos, node, player, itemstack, pointed_thing)
local name = player:get_player_name()
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local owner = meta:get_string("owner") local owner = meta:get_string("owner")
local dematted, msg = tardis.demat (owner, player:get_player_name())
if dematted then if (tardis.demat(owner)) then
minetest.sound_play ("tardis_demat", { minetest.sound_play ("tardis_demat", {
pos = pos , pos = pos ,
max_hear_distance = 10 , max_hear_distance = 10 ,
@ -94,63 +92,59 @@ minetest.register_node ("tardis:demat_lever_off", {
minetest.swap_node (pos, {name = "tardis:demat_lever_on"}) minetest.swap_node (pos, {name = "tardis:demat_lever_on"})
else else
minetest.chat_send_player(player:get_player_name(), msg) minetest.chat_send_player(name, "Failed to demat")
end end
end , end
}) })
minetest.register_node ("tardis:navigator", { minetest.register_node("tardis:navigator", {
groups = {crumbly = 1} , tiles = {"tardis_navigator.png"},
tiles = {"tardis_navigator.png"} , drawtype = "signlike",
drawtype = "signlike" , paramtype = "light",
paramtype = "light" , paramtype2 = "wallmounted",
paramtype2 = "wallmounted" ,
is_ground_content = true ,
on_rightclick = function (pos, node, player, itemstack, pointed_thing) on_rightclick = function(pos, node, player, itemstack, pointed_thing)
local name = player:get_player_name()
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local owner = meta:get_string("owner") local owner = meta:get_string("owner")
tardis.set_nav(player, owner) tardis.show_nav_formspec(name, owner)
end , end
}) })
-- Teleports player to exterior is in_vortex is set to false -- Teleports player to exterior is in_vortex is set to false
minetest.register_node ("tardis:interior_doors", { minetest.register_node("tardis:interior_doors", {
tiles = {"tardis_doors.png"} , tiles = {"tardis_doors.png"},
use_texture_alpha = true , use_texture_alpha = true,
drawtype = "mesh" , drawtype = "mesh",
mesh = "tardis_interior_doors.obj" , mesh = "tardis_interior_doors.obj",
paramtype = "light" , paramtype = "light",
is_ground_content = true , selection_box = {type = "fixed", fixed = {-0.5, -0.5, -0.5, 0.5, 1.5, 0.5}},
collision_box = {type = "fixed", fixed = {-0.5, -0.5, -0.5, 0.5, 1.5, 0.5}},
on_rightclick = function (pos, node, player, itemstack, pointed_thing) on_rightclick = function(pos, node, player, itemstack, pointed_thing)
local meta = minetest.get_meta (pos) local name = player:get_player_name()
local owner = meta:get_string ("owner") local meta = minetest.get_meta(pos)
local owner = meta:get_string("owner")
if (tardis.tardises == nil) or if (tardis.get_vortex(owner)) then
(tardis.tardises [owner] == nil) or minetest.chat_send_player (name, "The TARDIS is in the Vortex - the doors have been locked automatically.")
(tardis.tardises [owner]["in_vortex"] == nil) then
minetest.log ("error", "in_vortex not initialised for " .. owner)
return
end
if (tardis.tardises [owner]["in_vortex"] == false) then
local teleport = { x = tardis.tardises[owner]["exterior"]["x"], y = tardis.tardises[owner]["exterior"]["y"], z = tardis.tardises[owner]["exterior"]["z"] - 1 }
player:setpos (teleport)
else else
player_name = player:get_player_name() local teleport = tardis.get_exterior(owner)
minetest.chat_send_player (player_name, "The TARDIS is in the Vortex - the doors have been locked automatically.") teleport["z"] = teleport["z"] - 1
player:setpos(teleport)
end end
end, end,
on_timer = function (pos) on_timer = function(pos)
local meta = minetest.get_meta (pos) local meta = minetest.get_meta(pos)
local owner = meta:get_string ("owner") local owner = meta:get_string("owner")
if tardis.tardises[owner]["in_vortex"] then -- If we're in a vortex, we must have been activated from the remat function. if (tardis.get_vortex(owner)) then -- If we're in a vortex, we must have been activated from the remat function.
tardis.tardises[owner]["in_vortex"] = false -- exit it. tardis.set_vortex(false, owner) -- exit it.
tardis.swap_node((tardis.get_exterior(owner)), {name = "tardis:tardis"})
end end
end end
}) })

288
remat.lua
View File

@ -1,197 +1,183 @@
function tardis.remat (owner, name) function tardis.remat(name)
if owner ~= name then return false, "You don't own that TARDIS!" end local pos = tardis.get_nav(name)
if (tardis.tardises [owner]["destination"] == nil) then
return false, "Coordinates haven't been set yet!"
else
local pos = tardis.tardises [owner]["destination"]
minetest.set_node (pos, {name = "tardis:tardis_remat"}) if (minetest.forceload_block(pos)) then
minetest.set_node(pos, {name = "tardis:tardis_remat"})
local meta = minetest.get_meta (pos) tardis.set_exterior(pos, name)
meta:set_string ("owner", owner)
minetest.get_node_timer(tardis.tardises [owner]["interior"]):start(22.5)
tardis.tardises [owner]["exterior"] = pos local meta = minetest.get_meta(pos)
meta:set_string("owner", name)
minetest.get_node_timer(tardis.get_interior(name)):start(21)
return true return true
else return false
end end
end end
minetest.register_node("tardis:tardis_remat", {
tiles = {"tardis_exterior.png^[opacity:1"},
use_texture_alpha = true,
drawtype = "mesh",
mesh = "tardis_exterior.obj",
paramtype = "light",
minetest.register_node ("tardis:tardis_remat", { on_timer = function(pos)
tiles = {"tardis_exterior.png^[opacity:1"} , tardis.swap_node(pos, {name = "tardis:tardis_remat_1"})
use_texture_alpha = true , end,
drawtype = "mesh" ,
mesh = "tardis_exterior.obj" ,
paramtype = "light" ,
is_ground_content = true ,
on_timer = function (pos) on_construct = function(pos)
tardis.swap_node (pos, {name = "tardis:tardis_remat_1"}) minetest.get_node_timer(pos):start(11)
end , end,
on_construct = function (pos)
minetest.get_node_timer (pos):start(11)
end ,
}) })
minetest.register_node ("tardis:tardis_remat_1", { minetest.register_node("tardis:tardis_remat_1", {
tiles = {"tardis_exterior.png^[opacity:25"} , tiles = {"tardis_exterior.png^[opacity:25"},
use_texture_alpha = true , use_texture_alpha = true,
drawtype = "mesh" , drawtype = "mesh",
mesh = "tardis_exterior.obj" , mesh = "tardis_exterior.obj",
paramtype = "light" , paramtype = "light",
is_ground_content = true , light_source = 7,
light_source = 7 ,
on_timer = function(pos)
tardis.swap_node(pos, {name = "tardis:tardis_remat_2"})
end,
on_timer = function (pos) on_construct = function(pos)
tardis.swap_node (pos, {name = "tardis:tardis_remat_2"}) minetest.get_node_timer(pos):start(1.5)
end , end,
on_construct = function (pos)
minetest.get_node_timer (pos):start(1.5)
end ,
}) })
minetest.register_node ("tardis:tardis_remat_2", { minetest.register_node("tardis:tardis_remat_2", {
tiles = {"tardis_exterior.png^[opacity:50"} , tiles = {"tardis_exterior.png^[opacity:50"},
use_texture_alpha = true , use_texture_alpha = true,
drawtype = "mesh" , drawtype = "mesh",
mesh = "tardis_exterior.obj" , mesh = "tardis_exterior.obj",
paramtype = "light" , paramtype = "light",
is_ground_content = true ,
on_timer = function (pos) on_timer = function(pos)
tardis.swap_node (pos, {name = "tardis:tardis_remat_3"}) tardis.swap_node(pos, {name = "tardis:tardis_remat_3"})
end , end,
on_construct = function (pos) on_construct = function(pos)
minetest.get_node_timer (pos):start(1) minetest.get_node_timer(pos):start(1)
end , end,
}) })
minetest.register_node ("tardis:tardis_remat_3", { minetest.register_node("tardis:tardis_remat_3", {
tiles = {"tardis_exterior.png^[opacity:75"} , tiles = {"tardis_exterior.png^[opacity:75"},
use_texture_alpha = true , use_texture_alpha = true,
drawtype = "mesh" , drawtype = "mesh",
mesh = "tardis_exterior.obj" , mesh = "tardis_exterior.obj",
paramtype = "light" , paramtype = "light",
is_ground_content = true , light_source = 10,
light_source = 10 ,
on_timer = function (pos) on_timer = function(pos)
tardis.swap_node (pos, {name = "tardis:tardis_remat_4"}) tardis.swap_node(pos, {name = "tardis:tardis_remat_4"})
end , end,
on_construct = function (pos) on_construct = function(pos)
minetest.get_node_timer (pos):start(1) minetest.get_node_timer(pos):start(1)
end , end,
}) })
minetest.register_node ("tardis:tardis_remat_4", { minetest.register_node("tardis:tardis_remat_4", {
tiles = {"tardis_exterior.png^[opacity:100"} , tiles = {"tardis_exterior.png^[opacity:100"},
use_texture_alpha = true , use_texture_alpha = true,
drawtype = "mesh" , drawtype = "mesh",
mesh = "tardis_exterior.obj" , mesh = "tardis_exterior.obj",
paramtype = "light" , paramtype = "light",
is_ground_content = true ,
on_timer = function (pos) on_timer = function(pos)
tardis.swap_node (pos, {name = "tardis:tardis_remat_5"}) tardis.swap_node(pos, {name = "tardis:tardis_remat_5"})
end , end,
on_construct = function (pos) on_construct = function(pos)
minetest.get_node_timer (pos):start(0.5) minetest.get_node_timer(pos):start(0.5)
end , end,
}) })
minetest.register_node ("tardis:tardis_remat_5", { minetest.register_node("tardis:tardis_remat_5", {
tiles = {"tardis_exterior.png^[opacity:125"} , tiles = {"tardis_exterior.png^[opacity:125"},
use_texture_alpha = true , use_texture_alpha = true,
drawtype = "mesh" , drawtype = "mesh",
mesh = "tardis_exterior.obj" , mesh = "tardis_exterior.obj",
paramtype = "light" , paramtype = "light",
is_ground_content = true , light_source = 10,
light_source = 10 ,
on_timer = function (pos) on_timer = function(pos)
tardis.swap_node (pos, {name = "tardis:tardis_remat_6"}) tardis.swap_node(pos, {name = "tardis:tardis_remat_6"})
end , end,
on_construct = function (pos) on_construct = function(pos)
minetest.get_node_timer (pos):start(1) minetest.get_node_timer(pos):start(1)
end , end,
}) })
minetest.register_node ("tardis:tardis_remat_6", { minetest.register_node("tardis:tardis_remat_6", {
tiles = {"tardis_exterior.png^[opacity:150"} , tiles = {"tardis_exterior.png^[opacity:150"},
use_texture_alpha = true , use_texture_alpha = true,
drawtype = "mesh" , drawtype = "mesh",
mesh = "tardis_exterior.obj" , mesh = "tardis_exterior.obj",
paramtype = "light" , paramtype = "light",
is_ground_content = true ,
on_timer = function (pos) on_timer = function(pos)
tardis.swap_node (pos, {name = "tardis:tardis_remat_7"}) tardis.swap_node(pos, {name = "tardis:tardis_remat_7"})
end , end,
on_construct = function (pos) on_construct = function(pos)
minetest.get_node_timer (pos):start(1) minetest.get_node_timer(pos):start(1)
end , end,
}) })
minetest.register_node ("tardis:tardis_remat_7", { minetest.register_node("tardis:tardis_remat_7", {
tiles = {"tardis_exterior.png^[opacity:175"} , tiles = {"tardis_exterior.png^[opacity:175"},
use_texture_alpha = true , use_texture_alpha = true,
drawtype = "mesh" , drawtype = "mesh",
mesh = "tardis_exterior.obj" , mesh = "tardis_exterior.obj",
paramtype = "light" , paramtype = "light",
light_source = 10 , light_source = 10,
on_timer = function (pos) on_timer = function(pos)
tardis.swap_node (pos, {name = "tardis:tardis_remat_8"}) tardis.swap_node(pos, {name = "tardis:tardis_remat_8"})
end , end,
on_construct = function (pos) on_construct = function(pos)
minetest.get_node_timer (pos):start(1) minetest.get_node_timer(pos):start(1)
end , end,
}) })
minetest.register_node ("tardis:tardis_remat_8", { minetest.register_node("tardis:tardis_remat_8", {
tiles = {"tardis_exterior.png^[opacity:200"} , tiles = {"tardis_exterior.png^[opacity:200"},
use_texture_alpha = true , use_texture_alpha = true,
drawtype = "mesh" , drawtype = "mesh",
mesh = "tardis_exterior.obj" , mesh = "tardis_exterior.obj",
paramtype = "light" , paramtype = "light",
is_ground_content = true ,
on_timer = function (pos) on_timer = function(pos)
tardis.swap_node (pos, {name = "tardis:tardis_remat_9"}) tardis.swap_node(pos, {name = "tardis:tardis_remat_9"})
end , end,
on_construct = function (pos) on_construct = function(pos)
minetest.get_node_timer (pos):start(0.5) minetest.get_node_timer(pos):start(0.5)
end , end,
}) })
minetest.register_node ("tardis:tardis_remat_9", { minetest.register_node("tardis:tardis_remat_9", {
tiles = {"tardis_exterior.png^[opacity:225"} , tiles = {"tardis_exterior.png^[opacity:225"},
use_texture_alpha = true , use_texture_alpha = true,
drawtype = "mesh" , drawtype = "mesh",
mesh = "tardis_exterior.obj" , mesh = "tardis_exterior.obj",
paramtype = "light" , paramtype = "light",
is_ground_content = true , light_source = 10,
light_source = 10 ,
on_timer = function (pos) on_timer = function(pos)
tardis.swap_node (pos, {name = "tardis:tardis"}) tardis.swap_node(pos, {name = "tardis:tardis"})
minetest.forceload_free_block(pos)
end,
local meta = minetest.get_meta (pos) on_construct = function(pos)
owner = meta:get_string ("owner") minetest.get_node_timer(pos):start(1)
end , end,
on_construct = function (pos)
minetest.get_node_timer (pos):start(1)
end ,
}) })