Interior door changes to support extra doors

This commit is contained in:
Skivling 2024-06-16 16:30:18 +12:00
parent 97316504e4
commit 44f9df3bc5
6 changed files with 155 additions and 67 deletions

70
api.lua
View File

@ -66,26 +66,42 @@ function _drwho_tardis:place_tardis_interior(player, type, pos)
if type == "custom" then
-- Assume that the given pos is where the door is going to be
data:set_string(player.."type", type) -- Save the fact their interior is custom
data:set_string(player.."door_0_offset", minetest.serialize({x=0,y=0,z=0})) -- door offset is 0
data:set_string(player.."door_pos_table", minetest.serialize({door_0 = pos})) -- Remember the door position
data:set_string(player.."door_offset_table", minetest.serialize({door_0={x=0,y=0,z=0}})) -- door offset is 0
data:set_string(player.."in_pos", minetest.serialize(pos)) -- save new interior position
return true, "", pos -- success, message, doorpos
return true, "", {door_0 = pos} -- success, message, door_pos_table
end
pos.y = _drwho_tardis.interiorDepth -- set the y pos of the interior
local door_0_offset = {x=0,y=0,z=0}
local door_offset_table = {}
local door_pos_table = {}
if _drwho_tardis.rooms[type] then
minetest.place_schematic(pos, _drwho_tardis.rooms[type].path) --minetest.get_modpath("drwho_tardis") .. "/schems/console_room.mts"
door_0_offset = _drwho_tardis.rooms[type].door_0_offset -- = {x=7,y=2,z=16}
pos.x = pos.x + door_0_offset.x -- Schematic adjustments so that the player
pos.y = pos.y + door_0_offset.y -- gets teleported right in front of the door
pos.z = pos.z + door_0_offset.z
else
local d0_pos = vector.add(pos, door_0_offset) -- Schematic adjustments so that the player gets teleported right in front of the door
door_pos_table = { door_0 = d0_pos, door_1=nil, door_2=nil }
door_offset_table = { door_0 = door_0_offset, door_1=nil, door_2=nil }
if _drwho_tardis.rooms[type].door_1_offset then
local d1_pos = vector.add(pos, _drwho_tardis.rooms[type].door_1_offset)
door_offset_table.door_1 = _drwho_tardis.rooms[type].door_1_offset
door_pos_table.door_1 = d1_pos
end
if _drwho_tardis.rooms[type].door_2_offset then
local d2_pos = vector.add(pos, _drwho_tardis.rooms[type].door_2_offset)
door_offset_table.door_1 = _drwho_tardis.rooms[type].door_1_offset
door_pos_table.door_2 = d2_pos
end
else
return false, "Invalid interior room type! Use /tardis_int to change it.", type -- success, errmsg, int_type
end
data:set_string(player.."type", type) -- Save what type of interior they have
data:set_string(player.."door_0_offset", minetest.serialize(door_0_offset)) -- Remember the door offset
data:set_string(player.."in_pos", minetest.serialize(pos)) -- save new interior position
return true, "", pos -- success, message, doorpos
data:set_string(player.."door_pos_table", minetest.serialize(door_pos_table)) -- Remember the door positions
data:set_string(player.."door_offset_table", minetest.serialize(door_offset_table)) -- Remember the door offsets
data:set_string(player.."console_place_pos", minetest.serialize(pos)) -- Remember the door offsets
data:set_string(player.."in_pos", minetest.serialize(door_pos_table.door_0)) -- save new interior position
minetest.log(minetest.serialize(door_pos_table))
return true, "", door_pos_table -- success, message, door_pos_table
end
end
@ -94,8 +110,8 @@ end
function _drwho_tardis:rebuild_tardis_interior(player)
local type = data:get_string(player.."type")
local door_0_offset = minetest.deserialize(data:get_string(player.."door_0_offset"))
if type=="" or type==nil then type = "old" end -- defaults
local door_0_offset = minetest.deserialize(data:get_string(player.."door_0_offset"))
if type=="" or type==nil then type = "default" end -- defaults
if door_0_offset=="" or door_0_offset==nil then door_0_offset = {x=7,y=2,z=16} end -- defaults
local in_pos = minetest.deserialize(data:get_string(player.."in_pos"))
if in_pos == "" or in_pos == nil then
@ -106,19 +122,35 @@ function _drwho_tardis:rebuild_tardis_interior(player)
anchor_pos.x = in_pos.x - door_0_offset.x
anchor_pos.y = in_pos.y - door_0_offset.y -- This ensures that the old and new line up properly
anchor_pos.z = in_pos.z - door_0_offset.z
local success, msg, doorpos = _drwho_tardis:place_tardis_interior(player, type, anchor_pos)
local success, msg, door_pos_table = _drwho_tardis:place_tardis_interior(player, type, anchor_pos)
if success == false then
return false, msg, doorpos -- doorpos is actually the type in this situation
return false, msg, door_pos_table -- door_pos_table is actually the type in this situation
end
-- Interior door stuff
local dtimer = minetest.get_node_timer(doorpos)
local dmeta = minetest.get_meta(doorpos)
dtimer:start(0.2) -- start door timer (in case it doesn't start on construct)
dmeta:set_string("id", player) -- set door id
local d0meta = minetest.get_meta(door_pos_table['door_0'])
local d0timer = minetest.get_node_timer(door_pos_table['door_0'])
d0timer:start(0.2) --start door timer (in case it doesn't start on construct)
d0meta:set_string("id", player) --set door id
d0meta:set_string("type", "exit") -- set door type
-- Some interiors have extra doors
if door_pos_table.door_1 then
local d1meta = minetest.get_meta(door_pos_table.door_1)
local d1timer = minetest.get_node_timer(door_pos_table.door_1)
d1meta:set_string("id", player)
d1meta:set_string("type", "door_1")
d1timer:start(0.2)
end
if door_pos_table.door_2 then
local d2meta = minetest.get_meta(door_pos_table.door_2)
local d2timer = minetest.get_node_timer(door_pos_table.door_2)
d2meta:set_string("id", player)
d2meta:set_string("type", "door_2")
d2timer:start(0.2)
end
return true, "" -- success!
return true, "", door_pos_table -- success!
end
-- Starts/stops time rotor animation

View File

@ -57,7 +57,7 @@ end
--Data (11) : in_pos, out_pos, y_dest, x_dest, z_dest, factor, look, r_pos, waypoint1, waypoint2, waypoint3, biome_pos, type, door_0_offset
-- This is going to be reworked in v1.3.0
data = minetest.get_mod_storage()
local data = minetest.get_mod_storage()
--
-- CHAT COMMANDS
@ -177,7 +177,7 @@ minetest.register_chatcommand("rebuild_tardis", {
privs = {},
func = function(name)
-- This uses a private API function
local success, errmsg = _drwho_tardis:rebuild_tardis_interior(name)
local success, errmsg, door_pos_table = _drwho_tardis:rebuild_tardis_interior(name)
local _, __, pos = drwho_tardis.get:tardis_ext_position(name) -- public function
local in_pos = minetest.deserialize(data:get_string(name.."in_pos"))
@ -186,7 +186,10 @@ minetest.register_chatcommand("rebuild_tardis", {
minetest.chat_send_player(name, S("type: @1", data:get_string(name.."type")))
minetest.chat_send_player(name, S("owner: @1", name))
minetest.chat_send_player(name, S("exterior location: @1, @2, @3 [X,Y,Z]", pos.x, pos.y, pos.z))
minetest.chat_send_player(name, S("interior door location: @1, @2, @3 [X,Y,Z]", in_pos.x, in_pos.y, in_pos.z))
minetest.chat_send_player(name, S("interior door 0 (exit) location: @1, @2, @3 [X,Y,Z]", in_pos.x, in_pos.y, in_pos.z))
minetest.chat_send_player(name, S("interior door 0 (exit) location, according to door_pos_table: @1, @2, @3 [X,Y,Z]", door_pos_table.door_0.x, door_pos_table.door_0.y, door_pos_table.door_0.z))
minetest.chat_send_player(name, S("interior door 1 location: @1, @2, @3 [X,Y,Z]", door_pos_table.door_1.x, door_pos_table.door_1.y, door_pos_table.door_1.z))
minetest.chat_send_player(name, S("interior door 2 location: @1, @2, @3 [X,Y,Z]", door_pos_table.door_2.x, door_pos_table.door_2.y, door_pos_table.door_2.z))
else minetest.chat_send_player(name, S("Error message: @1", errmsg)) end
end
})

View File

@ -1,6 +1,6 @@
# Blender v2.91.2 OBJ File: 'untitled.blend'
# Blender v2.91.2 OBJ File: 'tardis.blend'
# www.blender.org
mtllib tardis_2.mtl
mtllib tardis.mtl
o Cube
v 0.500000 1.500000 -0.500000
v 0.500000 -0.500000 -0.500000

View File

@ -20,11 +20,27 @@ local function tardis_on_place(pos, placer, itemstack, pointed_thing)
data:set_string(name.."out_pos", minetest.serialize(pos)) -- set exterior position
local room = minetest.settings:get('drwho_tardis.default_interior')
if _drwho_tardis.rooms[room] then room = room else room = "default" end
local _, msg, doorpos = _drwho_tardis:place_tardis_interior(name, room, pos)
local ometa = minetest.get_meta(doorpos)
local otimer = minetest.get_node_timer(doorpos)
otimer:start(0.2) --start door timer (in case it doesn't start on construct)
ometa:set_string("id", name) --set door id
local _, msg, door_pos_table = _drwho_tardis:place_tardis_interior(name, room, pos)
local d0meta = minetest.get_meta(door_pos_table['door_0'])
local d0timer = minetest.get_node_timer(door_pos_table['door_0'])
d0meta:set_string("id", name) --set door id
d0meta:set_string("type", "exit") -- set door type
d0timer:start(0.2) --start door timer (in case it doesn't start on construct)
-- Some interiors have extra doors
if door_pos_table.door_1 then
local d1meta = minetest.get_meta(door_pos_table.door_1)
local d1timer = minetest.get_node_timer(door_pos_table.door_1)
d1meta:set_string("id", name)
d1meta:set_string("type", "door_1")
d1timer:start(0.2)
end
if door_pos_table.door_2 then
local d2meta = minetest.get_meta(door_pos_table.door_2)
local d2timer = minetest.get_node_timer(door_pos_table.door_2)
d2meta:set_string("id", name)
d2meta:set_string("type", "door_2")
d2timer:start(0.2)
end
meta:set_string("id", name) -- set exterior id
-- "in_pos" is set by the place_tardis_interior() function
data:set_int(name.."power", 3) --set power
@ -102,8 +118,9 @@ function drwho_tardis:register_tardis_exterior(def)
minetest.register_node("drwho_tardis:tardis"..name, {
description = description,
tiles = {texture},
use_texture_alpha = "clip",
drawtype = drawtype,
mesh = "tardis_2.obj", -- Only used when drawtype == "mesh"
mesh = "tardis.obj", -- Only used when drawtype == "mesh"
node_box = {type = "fixed", fixed = { { -0.5, -0.5, -0.5, 0.5, 1.5, 0.5 } }}, -- Only used when drawtype == "nodebox"
selection_box = {type = "fixed", fixed = { { -0.5, -0.5, -0.5, 0.5, 1.5, 0.5 } }},
collision_box = {type = "fixed", fixed = { { 0.48, -0.5,-0.5, 0.5, 1.5, 0.5}, {-0.5 , -0.5, 0.48, 0.48, 1.5, 0.5}, {-0.5, -0.5,-0.5 ,-0.48, 1.5, 0.5}, { -0.8,-0.6,-0.8,0.8,-0.48, 0.8} }},
@ -117,8 +134,9 @@ function drwho_tardis:register_tardis_exterior(def)
minetest.register_node("drwho_tardis:tardis"..name.."_locked", {
description = description.." (locked)",
tiles = {texture},
use_texture_alpha = "clip",
drawtype = drawtype,
mesh = "tardis_2.obj", -- Only used when drawtype == "mesh"
mesh = "tardis.obj", -- Only used when drawtype == "mesh"
node_box = {type = "fixed", fixed = { { -0.5, -0.5, -0.5, 0.5, 1.5, 0.5 } }}, -- Only used when drawtype == "nodebox"
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 } }},

View File

@ -17,7 +17,8 @@ minetest.register_node("drwho_tardis:in_door", {
description = S("Tardis Interior Door"),
tiles = {"inside_door.png"},
drawtype = "mesh",
mesh = "tardis_2.obj",
use_texture_alpha = "clip",
mesh = "tardis.obj",
paramtype2 = "4dir",
selection_box = {
type = "fixed",
@ -37,54 +38,88 @@ minetest.register_node("drwho_tardis:in_door", {
sunlight_propagates = true,
groups = {not_in_creative_inventory = 1, cracky=2},
diggable = false,
on_timer = function(pos)
on_timer = function(pos)
local meta = minetest.get_meta(pos)
local type = meta:get_string("type") or "exit"
local objs = minetest.get_objects_inside_radius(pos, 0.9)
if objs[1] == nil then return true else
if objs[1]:is_player() then
local pmeta = objs[1]:get_meta()
local meta = minetest.get_meta(pos)
local id = meta:get_string("id")
local go_pos = minetest.deserialize(data:get_string(id.."out_pos"))
if type == "exit" then
if objs[1] == nil then return true else
if objs[1]:is_player() then
go_pos.z = go_pos.z-2
objs[1]:set_pos(go_pos)
objs[1]:set_look_horizontal( math.rad( 180 ))
objs[1]:set_look_vertical( math.rad( 0 ))
if pmeta:get_string("vortex") == "yes" then
go_pos.z = go_pos.z-2
objs[1]:set_pos(go_pos)
objs[1]:set_hp(0)
end
minetest.after(1, function()
local pmeta = objs[1]:get_meta()
local meta = minetest.get_meta(pos)
local id = meta:get_string("id")
local go_pos = minetest.deserialize(data:get_string(id.."out_pos"))
local look = data:get_string(id.."look")
minetest.set_node(go_pos, {name=look})
local ometa = minetest.get_meta(go_pos)
ometa:set_string("id", id)
local timer = minetest.get_node_timer(go_pos)
timer:start(0.2)
end)
else
local meta = minetest.get_meta(pos)
local id = meta:get_string("id")
local go_pos = minetest.deserialize(data:get_string(id.."out_pos"))
go_pos.z = go_pos.z-2
objs[1]:set_pos(go_pos)
go_pos.z = go_pos.z-2
objs[1]:set_pos(go_pos)
objs[1]:set_look_horizontal( math.rad( 180 ))
objs[1]:set_look_vertical( math.rad( 0 ))
if pmeta:get_string("vortex") == "yes" then
go_pos.z = go_pos.z-2
objs[1]:set_pos(go_pos)
objs[1]:set_hp(0)
end
minetest.after(1, function()
local meta = minetest.get_meta(pos)
local id = meta:get_string("id")
local go_pos = minetest.deserialize(data:get_string(id.."out_pos"))
local look = data:get_string(id.."look")
minetest.set_node(go_pos, {name=look})
local ometa = minetest.get_meta(go_pos)
ometa:set_string("id", id)
local timer = minetest.get_node_timer(go_pos)
timer:start(0.2)
end)
else
local meta = minetest.get_meta(pos)
local id = meta:get_string("id")
local go_pos = minetest.deserialize(data:get_string(id.."out_pos"))
go_pos.z = go_pos.z-2
objs[1]:set_pos(go_pos)
end
end
return true
else -- it is door_1 or door_2
if objs[1] == nil then return true else
if objs[1]:is_player() then
local pmeta = objs[1]:get_meta()
local meta = minetest.get_meta(pos)
local id = meta:get_string("id")
local name = pmeta:get_name()
minetest.after(1, function()
--[[
local meta = minetest.get_meta(pos)
local id = meta:get_string("id")
local go_pos = minetest.deserialize(data:get_string(id.."out_pos"))
local look = data:get_string(id.."look")
minetest.set_node(go_pos, {name=look})
local ometa = minetest.get_meta(go_pos)
ometa:set_string("id", id)
local timer = minetest.get_node_timer(go_pos)
timer:start(0.2)--]]
minetest.chat_send_player(name, S("This door ("..type.."), does not go anywhere yet. Next update it will be able to go to extra rooms and/or corridors."))
end)
else
...
end
end
return true
end
return true
end
})
minetest.register_node("drwho_tardis:in_door_locked", {
description = S("Locked Tardis Interior Door"),
tiles = {"inside_door.png"},
drawtype = "mesh",
mesh = "tardis_2.obj",
use_texture_alpha = "clip",
mesh = "tardis.obj",
selection_box = {
type = "fixed",
fixed = {