Skip to content

Commit

Permalink
added a way to completely destroy a pocket - no delete/undelete. Made…
Browse files Browse the repository at this point in the history
… it dramatic, just for fun.
  • Loading branch information
FaceDeer committed Jan 7, 2021
1 parent a1675cf commit 743054f
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 10 deletions.
36 changes: 27 additions & 9 deletions api.lua
Expand Up @@ -85,6 +85,8 @@ local save_data = function()
file:close()
end

pocket_dimensions.save_data = save_data

load_data()


Expand Down Expand Up @@ -258,12 +260,20 @@ end
-- returns a place to put players if they have no origin recorded
local get_fallback_origin = function()
local spawnpoint = minetest.setting_get_pos("static_spawnpoint")
if not spawnpoint then
local count = 0
spawnpoint = {}
while not spawnpoint.y and count < 20 do
local x = math.random()*1000 - 500
local z = math.random()*1000 - 500
local y =minetest.get_spawn_level(x,z)
local y = minetest.get_spawn_level(x,z) -- returns nil when unsuitable
spawnpoint = {x=x,y=y,z=z}
count = count + 1
end
if not spawnpoint.y then
minetest.log("error", "[pocket_dimensions] Unable to find a fallback origin point to teleport the player, to sending them to 0,0,0")
return {x=0,y=0,z=0}
end
return spawnpoint
end

pocket_dimensions.return_player_to_origin = function(player_name)
Expand All @@ -277,10 +287,10 @@ pocket_dimensions.return_player_to_origin = function(player_name)
end
-- If the player's lost their origin data somehow, dump them somewhere using the spawn system to find an adequate place.
local spawnpoint = get_fallback_origin()
minetest.log("error", "[pocket_dimensions] Somehow "..name.." was at "..minetest.pos_to_string(clicker:get_pos())..
minetest.log("error", "[pocket_dimensions] Somehow "..player_name.." was at "..minetest.pos_to_string(player:get_pos())..
" inside a pocket dimension but they had no origin point recorded when they tried to leave. Sending them to "..
minetest.pos_to_string(spawnpoint).." as a fallback.")
teleport_player(clicker, spawnpoint)
teleport_player(player, spawnpoint)
end

-------------------------------------------------------------------------------------
Expand Down Expand Up @@ -341,10 +351,16 @@ pocket_dimensions.create_pocket = function(pocket_name, pocket_data_override)
return false, S("Failed to find a new location for this pocket dimension.")
end

pocket_dimensions.delete_pocket = function(pocket_data)
pocket_dimensions.delete_pocket = function(pocket_data, permanent)
local pocket_name_lower = string.lower(pocket_data.name)
local pocket_hash = minetest.hash_node_position(pocket_data.minp)
pockets_deleted[pocket_hash] = pocket_data
if not permanent then
pockets_deleted[pocket_hash] = pocket_data
else
-- you can permanently delete a pocket that's already been deleted
-- this removes it from the undelete cache
pockets_deleted[pocket_hash] = nil
end
pockets_by_name[pocket_name_lower] = nil
for name, personal_pocket_data in pairs(personal_pockets) do
if pocket_data == personal_pocket_data then
Expand All @@ -355,8 +371,10 @@ pocket_dimensions.delete_pocket = function(pocket_data)
end
save_data()

minetest.log("action", "[pocket_dimensions] Deleted the pocket dimension " .. pocket_data.name .. " at " .. minetest.pos_to_string(pocket_data.minp))
return true, S("Deleted pocket dimension @1 at @2. Note that this doesn't affect the map, just moves this pocket dimension out of regular access and into the deleted list.", pocket_data.name, minetest.pos_to_string(pocket_data.minp))
local permanency_log = function(permanent) if permanent then return " Deletion was permanent." else return "" end end
local permanency_message = function(permanent) if permanent then return " " .. S("Deletion was permanent.") else return "" end end
minetest.log("action", "[pocket_dimensions] Deleted the pocket dimension " .. pocket_data.name .. " at " .. minetest.pos_to_string(pocket_data.minp).. "." .. permanency_log())
return true, S("Deleted pocket dimension @1 at @2. Note that this doesn't affect the map.", pocket_data.name, minetest.pos_to_string(pocket_data.minp)) .. permanency_message()
end

pocket_dimensions.undelete_pocket = function(pocket_data)
Expand Down Expand Up @@ -401,4 +419,4 @@ end
pocket_dimensions.set_owner = function(pocket_data, player_name)
pocket_data.owner = player_name
save_data()
end
end
85 changes: 84 additions & 1 deletion mapgen.lua
Expand Up @@ -36,7 +36,7 @@ end
local get_border_def = function(override)
local def = {
description = S("Boundary of a pocket dimension"),
groups = {not_in_creative_inventory = 1},
groups = {not_in_creative_inventory = 1, dimensional_boundary = 1},
is_ground_content = false, -- If false, the cave generator and dungeon generator will not carve through this node.
diggable = false, -- If false, can never be dug
sounds = {
Expand Down Expand Up @@ -216,3 +216,86 @@ end

register_pocket_type("cave", cave_mapgen)


-----------------------------------------------------------------------------------------------------

minetest.register_node("pocket_dimensions:border_collapsing", get_border_def({
light_source = minetest.LIGHT_MAX,
paramtype = "light",
tiles = {{name="pocket_dimensions_pit_plasma.png",
animation = {
type = "vertical_frames",
aspect_w = 32,
aspect_h = 32,
length = 1.0,
},
tileable_vertical=true,
tileable_horizontal=true,
align_style="world",
scale=2,
}},
damage_per_second = 100,
}))

local c_border_collapsing = minetest.get_content_id("pocket_dimensions:border_collapsing")

function collapse_pocket(pocket_data)
local collapse = pocket_data.collapse
if not collapse then
return
end
local tick = collapse.tick
if tick >= pocket_size/2 then
-- done
minetest.delete_area(pocket_data.minp, vector.add(pocket_data.minp, pocket_size))
pocket_dimensions.delete_pocket(pocket_data, true)
return
end
local minp = vector.add(pocket_data.minp, tick)
local maxp = vector.add(minp, pocket_size-tick*2)
local vm = minetest.get_voxel_manip(minp, maxp)
local emin, emax = vm:get_emerged_area()
local data = vm:get_data()
local area = VoxelArea:new{MinEdge = emin, MaxEdge = emax}
for vi, x, y, z in area:iterp_xyz(minp, maxp) do
if x == minp.x or x == maxp.x or y == minp.y or y == maxp.y or z == minp.z or z == maxp.z then
data[vi] = c_border_collapsing
end
end
vm:set_data(data)
vm:write_to_map()

collapse.tick = tick + 1
pocket_dimensions.save_data()
minetest.after(collapse.seconds_per_tick, collapse_pocket, pocket_data)
end

local destroy_pocket_dramatically = function(pocket_data, seconds_per_tick)
pocket_data.collapse = {seconds_per_tick = seconds_per_tick, tick = 0}
pocket_dimensions.save_data()
collapse_pocket(pocket_data)
end

minetest.register_chatcommand("pocket_destroy", {
params = "pocketname",
privs = {server=true},
description = S("Destroy a named pocket dramatically"),
func = function(player_name, param)
local pocket_data = pocket_dimensions.get_pocket(param)
if not pocket_data then
minetest.chat_send_player(player_name, S("Unable to find a pocket dimension with that name."))
return
end
destroy_pocket_dramatically(pocket_data, 10)
end
})

local test_collapse = function()
for _, def in pairs(pocket_dimensions.get_all_pockets()) do
if def.collapse then
collapse_pocket(def)
end
end
end

minetest.after(1, test_collapse)
Binary file added textures/pocket_dimensions_pit_plasma.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 743054f

Please sign in to comment.