diff --git a/mods/ITEMS/mcl_beds/init.lua b/mods/ITEMS/mcl_beds/init.lua index 4c25b5390..ad9dbdded 100644 --- a/mods/ITEMS/mcl_beds/init.lua +++ b/mods/ITEMS/mcl_beds/init.lua @@ -10,3 +10,4 @@ local modpath = minetest.get_modpath("mcl_beds") dofile(modpath .. "/functions.lua") dofile(modpath .. "/api.lua") dofile(modpath .. "/beds.lua") +dofile(modpath .. "/respawn_anchor.lua") \ No newline at end of file diff --git a/mods/ITEMS/mcl_beds/mod.conf b/mods/ITEMS/mcl_beds/mod.conf index c3378d1f0..cc3f3ff18 100644 --- a/mods/ITEMS/mcl_beds/mod.conf +++ b/mods/ITEMS/mcl_beds/mod.conf @@ -2,4 +2,4 @@ name = mcl_beds author = BlockMen description = depends = playerphysics -optional_depends = mcl_sounds, mcl_worlds, mcl_wool, mcl_dye, mcl_explosions, mcl_weather, mcl_spawn, doc +optional_depends = mcl_sounds, mcl_worlds, mcl_wool, mcl_dye, mcl_explosions, mcl_weather, mcl_spawn, doc, mcl_nether \ No newline at end of file diff --git a/mods/ITEMS/mcl_beds/respawn_anchor.lua b/mods/ITEMS/mcl_beds/respawn_anchor.lua new file mode 100644 index 000000000..61e32144a --- /dev/null +++ b/mods/ITEMS/mcl_beds/respawn_anchor.lua @@ -0,0 +1,168 @@ +--TODO: Add sounds for the respawn anchor + +--Nether ends at y -29077 +--Nether roof at y -28933 + + +minetest.register_node("mcl_beds:respawn_anchor",{ + description="respawn anchor", + tiles = { + "respawn_anchor_top_off.png", + "respawn_anchor_bottom.png", + "respawn_anchor_side0.png" + }, + drawtype = "nodebox", + node_box= { --Reused the composter nodebox, since it is basicly the same + type = "fixed", + fixed = { + {-0.5, -0.5, -0.5, -0.375, 0.5, 0.5}, -- Left wall + { 0.375, -0.5, -0.5, 0.5, 0.5, 0.5}, -- Right wall + {-0.375, -0.5, 0.375, 0.375, 0.5, 0.5}, -- Back wall + {-0.375, -0.5, -0.5, 0.375, 0.5, -0.375}, -- Front wall + {-0.5, -0.5, -0.5, 0.5, -0.47, 0.5}, -- Bottom level, -0.47 because -0.5 is so low that you can see the texture of the block below through + } + }, + on_rightclick = function(pos, node, player, itemstack) + if itemstack.get_name(itemstack) == "mcl_nether:glowstone" then + minetest.set_node(pos, {name="mcl_beds:respawn_anchor_charged_1"}) + else + if pos.y < -29077 or pos.y > -28933 then + mcl_explosions.explode(pos, 5, {drop_chance = 0, fire = true}) + end + end + end, + groups = {pickaxey=1, material_stone=1}, + _mcl_hardness = 22.5 +}) +minetest.register_node("mcl_beds:respawn_anchor_charged_1",{ + description="respawn anchor", + tiles = { + "portal.png", + "respawn_anchor_bottom.png", + "respawn_anchor_side1.png" + }, + drawtype = "nodebox", + node_box= { --Reused the composter nodebox, since it is basicly the same + type = "fixed", + fixed = { + {-0.5, -0.5, -0.5, -0.375, 0.5, 0.5}, -- Left wall + { 0.375, -0.5, -0.5, 0.5, 0.5, 0.5}, -- Right wall + {-0.375, -0.5, 0.375, 0.375, 0.5, 0.5}, -- Back wall + {-0.375, -0.5, -0.5, 0.375, 0.5, -0.375}, -- Front wall + {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, -- Bottom level + } + }, + on_rightclick = function(pos, node, player, itemstack) + if itemstack.get_name(itemstack) == "mcl_nether:glowstone" then + minetest.set_node(pos, {name="mcl_beds:respawn_anchor_charged_2"}) + else + if pos.y < -29077 or pos.y > -28933 then + mcl_explosions.explode(pos, 5, {drop_chance = 0, fire = true}) + else + mcl_spawn.set_spawn_pos(player, pos, nil) + end + end + end, + groups = {pickaxey=1, material_stone=1, not_in_creative_inventory=1}, + _mcl_hardness = 22.5 +}) + +minetest.register_node("mcl_beds:respawn_anchor_charged_2",{ + description="respawn anchor", + tiles = { + "portal.png", + "respawn_anchor_bottom.png", + "respawn_anchor_side2.png" + }, + drawtype = "nodebox", + node_box= { --Reused the composter nodebox, since it is basicly the same + type = "fixed", + fixed = { + {-0.5, -0.5, -0.5, -0.375, 0.5, 0.5}, -- Left wall + { 0.375, -0.5, -0.5, 0.5, 0.5, 0.5}, -- Right wall + {-0.375, -0.5, 0.375, 0.375, 0.5, 0.5}, -- Back wall + {-0.375, -0.5, -0.5, 0.375, 0.5, -0.375}, -- Front wall + {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, -- Bottom level + } + }, + on_rightclick = function(pos, node, player, itemstack) + if itemstack.get_name(itemstack) == "mcl_nether:glowstone" then + minetest.set_node(pos, {name="mcl_beds:respawn_anchor_charged_3"}) + else + if pos.y < -29077 or pos.y > -28933 then + mcl_explosions.explode(pos, 5, {drop_chance = 0, fire = true}) + else + mcl_spawn.set_spawn_pos(player, pos, nil) + end + end + end, + groups = {pickaxey=1, material_stone=1, not_in_creative_inventory=1}, + _mcl_hardness = 22.5 +}) + +minetest.register_node("mcl_beds:respawn_anchor_charged_3",{ + description="respawn anchor", + tiles = { + "portal.png", + "respawn_anchor_bottom.png", + "respawn_anchor_side3.png" + }, + drawtype = "nodebox", + node_box= { --Reused the composter nodebox, since it is basicly the same + type = "fixed", + fixed = { + {-0.5, -0.5, -0.5, -0.375, 0.5, 0.5}, -- Left wall + { 0.375, -0.5, -0.5, 0.5, 0.5, 0.5}, -- Right wall + {-0.375, -0.5, 0.375, 0.375, 0.5, 0.5}, -- Back wall + {-0.375, -0.5, -0.5, 0.375, 0.5, -0.375}, -- Front wall + {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, -- Bottom level + } + }, + on_rightclick = function(pos, node, player, itemstack) + if itemstack.get_name(itemstack) == "mcl_nether:glowstone" then + minetest.set_node(pos, {name="mcl_beds:respawn_anchor_charged_4"}) + else + if pos.y < -29077 or pos.y > -28933 then + mcl_explosions.explode(pos, 5, {drop_chance = 0, fire = true}) + else + mcl_spawn.set_spawn_pos(player, pos, nil) + end + end + end, + groups = {pickaxey=1, material_stone=1, not_in_creative_inventory=1}, + _mcl_hardness = 22.5 +}) + +minetest.register_node("mcl_beds:respawn_anchor_charged_4",{ + description="respawn anchor", + tiles = { + "portal.png", + "respawn_anchor_bottom.png", + "respawn_anchor_side4.png" + }, + drawtype = "nodebox", + node_box= { --Reused the composter nodebox, since it is basicly the same + type = "fixed", + fixed = { + {-0.5, -0.5, -0.5, -0.375, 0.5, 0.5}, -- Left wall + { 0.375, -0.5, -0.5, 0.5, 0.5, 0.5}, -- Right wall + {-0.375, -0.5, 0.375, 0.375, 0.5, 0.5}, -- Back wall + {-0.375, -0.5, -0.5, 0.375, 0.5, -0.375}, -- Front wall + {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, -- Bottom level + } + }, + on_rightclick = function(pos, node, player, itemstack) + if pos.y < -29077 or pos.y > -28933 then + mcl_explosions.explode(pos, 5, {drop_chance = 0, fire = true}) + else + mcl_spawn.set_spawn_pos(player, pos, nil) + end + end, + groups = {pickaxey=1, material_stone=1, not_in_creative_inventory=1}, + _mcl_hardness = 22.5 +}) + +minetest.register_craft({ output = "mcl_beds:respawn_anchor", + recipe = { {"mcl_core:crying_obsidian", "mcl_core:crying_obsidian", "mcl_core:crying_obsidian"}, + {"mcl_nether:glowstone", "mcl_nether:glowstone", "mcl_nether:glowstone"}, + {"mcl_core:crying_obsidian", "mcl_core:crying_obsidian", "mcl_core:crying_obsidian"} } }) \ No newline at end of file diff --git a/mods/ITEMS/mcl_beds/textures/portal.png b/mods/ITEMS/mcl_beds/textures/portal.png new file mode 100644 index 000000000..160ad95f3 Binary files /dev/null and b/mods/ITEMS/mcl_beds/textures/portal.png differ diff --git a/mods/ITEMS/mcl_beds/textures/respawn_anchor_bottom.png b/mods/ITEMS/mcl_beds/textures/respawn_anchor_bottom.png new file mode 100644 index 000000000..d5d332c15 Binary files /dev/null and b/mods/ITEMS/mcl_beds/textures/respawn_anchor_bottom.png differ diff --git a/mods/ITEMS/mcl_beds/textures/respawn_anchor_side0.png b/mods/ITEMS/mcl_beds/textures/respawn_anchor_side0.png new file mode 100644 index 000000000..31a6e58f3 Binary files /dev/null and b/mods/ITEMS/mcl_beds/textures/respawn_anchor_side0.png differ diff --git a/mods/ITEMS/mcl_beds/textures/respawn_anchor_side1.png b/mods/ITEMS/mcl_beds/textures/respawn_anchor_side1.png new file mode 100644 index 000000000..ed4667a2e Binary files /dev/null and b/mods/ITEMS/mcl_beds/textures/respawn_anchor_side1.png differ diff --git a/mods/ITEMS/mcl_beds/textures/respawn_anchor_side2.png b/mods/ITEMS/mcl_beds/textures/respawn_anchor_side2.png new file mode 100644 index 000000000..996042015 Binary files /dev/null and b/mods/ITEMS/mcl_beds/textures/respawn_anchor_side2.png differ diff --git a/mods/ITEMS/mcl_beds/textures/respawn_anchor_side3.png b/mods/ITEMS/mcl_beds/textures/respawn_anchor_side3.png new file mode 100644 index 000000000..f0728943c Binary files /dev/null and b/mods/ITEMS/mcl_beds/textures/respawn_anchor_side3.png differ diff --git a/mods/ITEMS/mcl_beds/textures/respawn_anchor_side4.png b/mods/ITEMS/mcl_beds/textures/respawn_anchor_side4.png new file mode 100644 index 000000000..e9bea5371 Binary files /dev/null and b/mods/ITEMS/mcl_beds/textures/respawn_anchor_side4.png differ diff --git a/mods/ITEMS/mcl_beds/textures/respawn_anchor_top_off.png b/mods/ITEMS/mcl_beds/textures/respawn_anchor_top_off.png new file mode 100644 index 000000000..a180e96e7 Binary files /dev/null and b/mods/ITEMS/mcl_beds/textures/respawn_anchor_top_off.png differ diff --git a/mods/PLAYER/mcl_spawn/init.lua b/mods/PLAYER/mcl_spawn/init.lua index de4db5094..ca6aa97b1 100644 --- a/mods/PLAYER/mcl_spawn/init.lua +++ b/mods/PLAYER/mcl_spawn/init.lua @@ -452,10 +452,60 @@ function mcl_spawn.get_player_spawn_pos(player) if bgroup ~= 1 and bgroup ~= 2 then -- Bed is destroyed: if player and player:is_player() then - player:get_meta():set_string("mcl_beds:spawn", "") + + local function split(s, delimiter) --this is just a common function to split strings, since it is way harder to do in lua like in python, java etc. + result = {}; + for match in (s..delimiter):gmatch("(.-)"..delimiter) do + table.insert(result, match); + end + return result; + end + s = split(player:get_meta():get_string("mcl_beds:spawn"), ",") + x = nil + y = nil + z = nil + for key, value in pairs(s) do + if key == 1 then + value = value:sub(2) + x = tonumber(value) + else + if key == 2 then + y = tonumber(value) + else + if key == 3 then + value = value:sub(1, -2) + z = tonumber(value) + end + end + end + end + + checkblock = {x = x, y = y, z = z} + + if minetest.get_node(checkblock).name == "mcl_beds:respawn_anchor_charged_1" then + minetest.set_node(checkblock, {name="mcl_beds:respawn_anchor"}) + player:set_pos(checkblock) + else + if minetest.get_node(checkblock).name == "mcl_beds:respawn_anchor_charged_2" then + minetest.set_node(checkblock, {name="mcl_beds:respawn_anchor_charged_1"}) + player:set_pos(checkblock) + else + if minetest.get_node(checkblock).name == "mcl_beds:respawn_anchor_charged_3" then + minetest.set_node(checkblock, {name="mcl_beds:respawn_anchor_charged_2"}) + player:set_pos(checkblock) + else + if minetest.get_node(checkblock).name == "mcl_beds:respawn_anchor_charged_4" then + minetest.set_node(checkblock, {name="mcl_beds:respawn_anchor_charged_3"}) + player:set_pos(checkblock) + else + player:get_meta():set_string("mcl_beds:spawn", "") + minetest.chat_send_player(player:get_player_name(), S("Your spawn bed was missing or blocked, and you had no charged respawn anchor")) + return mcl_spawn.get_world_spawn_pos(), false + end + end + end + end end - minetest.chat_send_player(player:get_player_name(), S("Your spawn bed was missing or blocked.")) - return mcl_spawn.get_world_spawn_pos(), false end -- Find spawning position on/near the bed free of solid or damaging blocks iterating a square spiral 15x15: @@ -531,4 +581,4 @@ minetest.after(respawn_search_initial_delay, function() storage:set_int("mcl_spawn_dir_step", dir_step) storage:set_int("mcl_spawn_dir_ind", dir_ind) end) -end) +end) \ No newline at end of file