From b2c09c8ba058aaa7b9f4a2295925f1cc11b62fb6 Mon Sep 17 00:00:00 2001 From: Elias Fleckenstein Date: Wed, 7 Apr 2021 09:17:13 +0200 Subject: [PATCH] Add gateway portals --- mods/ITEMS/mcl_portals/portal_gateway.lua | 70 +++++++++++++++++- mods/MAPGEN/mcl_structures/init.lua | 4 +- .../mcl_structures_end_exit_portal.mts | Bin 193 -> 222 bytes .../mcl_structures_end_exit_portal_open.mts | Bin 222 -> 0 bytes 4 files changed, 71 insertions(+), 3 deletions(-) delete mode 100644 mods/MAPGEN/mcl_structures/schematics/mcl_structures_end_exit_portal_open.mts diff --git a/mods/ITEMS/mcl_portals/portal_gateway.lua b/mods/ITEMS/mcl_portals/portal_gateway.lua index cae6fce43e..6d491433cd 100644 --- a/mods/ITEMS/mcl_portals/portal_gateway.lua +++ b/mods/ITEMS/mcl_portals/portal_gateway.lua @@ -24,12 +24,21 @@ local gateway_positions = { {x = 91, y = -26925, z = -29}, } +local function spawn_gateway_portal(pos, dest_str) + local path = minetest.get_modpath("mcl_structures").."/schematics/mcl_structures_end_gateway_portal.mts" + return mcl_structures.place_schematic(vector.add(pos, vector.new(-1, -2, -1)), path, "0", nil, true, dest_str and function() + minetest.get_voxel_manip():read_from_map(pos, pos) + minetest.get_meta(pos):set_string("mcl_portals:gateway_destination", dest_str) + print(dest_str) + end) +end + function mcl_portals.spawn_gateway_portal() local id = storage:get_int("gateway_last_id") + 1 local pos = gateway_positions[id] if not pos then return end storage:set_int("gateway_last_id", id) - mcl_structures.call_struct(vector.add(pos, vector.new(-1, -2, -1)), "end_gateway_portal") + spawn_gateway_portal(pos) end local gateway_def = table.copy(minetest.registered_nodes["mcl_portals:portal_end"]) @@ -43,3 +52,62 @@ gateway_def.node_box = nil gateway_def.walkable = true gateway_def.tiles[3] = nil minetest.register_node("mcl_portals:portal_gateway", gateway_def) + +local function find_destination_pos(minp, maxp) + for y = maxp.y, minp.y, -1 do + for x = maxp.x, minp.x, -1 do + for z = maxp.z, minp.z, -1 do + local pos = vector.new(x, y, z) + local nn = minetest.get_node(pos).name + if nn ~= "ignore" and nn ~= "mcl_portals:portal_gateway" and nn ~= "mcl_core:bedrock" then + local def = minetest.registered_nodes[nn] + if def and def.walkable then + return vector.add(pos, vector.new(0, 1.5, 0)) + end + end + end + end + end +end + +local preparing = {} + +local function teleport(pos, obj) + local meta = minetest.get_meta(pos) + local dest_portal + local dest_str = meta:get_string("mcl_portals:gateway_destination") + local pos_str = minetest.pos_to_string(pos) + if dest_str == "" then + dest_portal = vector.multiply(vector.direction(vector.new(0, pos.y, 0), pos), math.random(768, 1024)) + dest_portal.y = -26970 + spawn_gateway_portal(dest_portal, pos_str) + meta:set_string("mcl_portals:gateway_destination", minetest.pos_to_string(dest_portal)) + else + dest_portal = minetest.string_to_pos(dest_str) + end + local minp = vector.subtract(dest_portal, vector.new(5, 40, 5)) + local maxp = vector.add(dest_portal, vector.new(5, 10, 5)) + preparing[pos_str] = true + minetest.emerge_area(minp, maxp, function() + if obj:is_player() or obj:get_luaentity() then + obj:set_pos(find_destination_pos(minp, maxp) or vector.add(dest_portal, vector.new(0, 3.5, 0))) + end + preparing[pos_str] = false + end) +end + +minetest.register_abm({ + label = "End gateway portal teleportation", + nodenames = {"mcl_portals:portal_gateway"}, + interval = 0.1, + chance = 1, + action = function(pos) + if preparing[minetest.pos_to_string(pos)] then return end + for _, obj in pairs(minetest.get_objects_inside_radius(pos, 1)) do + if obj:get_hp() > 0 then + teleport(pos, obj) + return + end + end + end, +}) diff --git a/mods/MAPGEN/mcl_structures/init.lua b/mods/MAPGEN/mcl_structures/init.lua index 00efeca145..4ba369e011 100644 --- a/mods/MAPGEN/mcl_structures/init.lua +++ b/mods/MAPGEN/mcl_structures/init.lua @@ -318,11 +318,11 @@ end mcl_structures.generate_end_exit_portal = function(pos, rot) local path = minetest.get_modpath("mcl_structures").."/schematics/mcl_structures_end_exit_portal.mts" - return mcl_structures.place_schematic(pos, path, rot or "0", nil, true) + return mcl_structures.place_schematic(pos, path, rot or "0", {["mcl_portals:portal_end"] = "air"}, true) end mcl_structures.generate_end_exit_portal_open = function(pos, rot) - local path = minetest.get_modpath("mcl_structures").."/schematics/mcl_structures_end_exit_portal_open.mts" + local path = minetest.get_modpath("mcl_structures").."/schematics/mcl_structures_end_exit_portal.mts" return mcl_structures.place_schematic(pos, path, rot or "0", nil, true) end diff --git a/mods/MAPGEN/mcl_structures/schematics/mcl_structures_end_exit_portal.mts b/mods/MAPGEN/mcl_structures/schematics/mcl_structures_end_exit_portal.mts index 30d145bd7fdc822259191c918696b74769628d72..bc24f800a6de0e4265fdbe08808c9720061b8490 100644 GIT binary patch delta 161 zcmX@ec#l!oHze4XfrWvcft7*19t0RzCkh(~733F{B<2)bLFo9@yp)NyQu%u)-Q_x< zz|k6fyLf*1{0PUO)hWr(V>%M#|4o_Hb;dWRuj`fdDjvh*7QKNMy&uns)}uDrD>;&p_i$xlx^$sU)L+^RXm2rEqVhjdOw~yd0eDy%Dic&uPyg1I8yyH zO~3W?FE<7=#tl0-et5I*%~5yCuvOaK+coXSeq%5FGkVh6GdgztnH3o08erZh5UT|M Dl|EWe