X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=skyblock.lua;h=4ea990ab32cad608bc66e8fb53b74e84b2e75bfa;hb=ca57da96a808ec181fcd2cb7b481736499b12714;hp=6af12e4bcb0e097b82a30b0aac56c350ccd06f73;hpb=91631c2a142ef9d4d7fd7b44f3c741bfe505aac7;p=elidragon.git diff --git a/skyblock.lua b/skyblock.lua index 6af12e4..4ea990a 100755 --- a/skyblock.lua +++ b/skyblock.lua @@ -32,24 +32,6 @@ end -- start positions -function elidragon.skyblock.load_legacy_start_positions() - local file = io.open(minetest.get_worldpath() .. "/skyblock.start_positions", "r") - if file then - local start_positions = {} - while true do - local x = file:read("*n") - if x == nil then - break - end - local y = file:read("*n") - local z = file:read("*n") - table.insert(start_positions, {x = x, y = y, z = z}) - end - file:close() - return start_positions - end -end - function elidragon.skyblock.load_start_positions() local file = io.open(minetest.get_worldpath() .. "/start_positions", "r") if file then @@ -77,45 +59,36 @@ end elidragon.skyblock.start_positions = elidragon.skyblock.load_start_positions() if not elidragon.skyblock.start_positions then - elidragon.skyblock.start_positions = elidragon.skyblock.load_legacy_start_positions() or elidragon.skyblock.generate_start_positions() + elidragon.skyblock.start_positions = elidragon.skyblock.generate_start_positions() elidragon.skyblock.save_start_positions(elidragon.skyblock.start_positions) end -function elidragon.skyblock.load_legacy_last_start_id() - local file = io.open(minetest.get_worldpath() .. "/skyblock.last_start_id", "r") - if file then - local last_start_id = tonumber(file:read()) - file:close() - return last_start_id - end -end - -elidragon.savedata.last_start_id = elidragon.savedata.last_start_id or elidragon.skyblock.load_legacy_last_start_id() or 0 +elidragon.savedata.last_start_id = elidragon.savedata.last_start_id or 0 -- spawns -function elidragon.skyblock.get_spawn(name) - return elidragon.savedata.spawns[name] +function elidragon.skyblock.get_spawn(player) + return minetest.string_to_pos(player:get_meta():get_string("elidragon:spawn")) end -function elidragon.skyblock.set_spawn(name, pos) - elidragon.savedata.spawns[name] = pos +function elidragon.skyblock.set_spawn(player, pos) + player:get_meta():set_string("elidragon:spawn", minetest.pos_to_string(pos)) end function elidragon.skyblock.spawn_player(player) if not player then return end - local name = player:get_player_name() - local spawn = elidragon.skyblock.get_spawn(name) or elidragon.skyblock.new_spawn(name) + local spawn = elidragon.skyblock.get_spawn(player) or elidragon.skyblock.new_spawn(player) player:set_pos({x = spawn.x + 2, y = spawn.y + 2, z = spawn.z + 2}) end -function elidragon.skyblock.new_spawn(name) +function elidragon.skyblock.new_spawn(player) + local name = player:get_player_name() local spawn repeat elidragon.savedata.last_start_id = elidragon.savedata.last_start_id + 1 spawn = elidragon.skyblock.start_positions[elidragon.savedata.last_start_id] until not minetest.is_protected(spawn, name) - elidragon.skyblock.set_spawn(name, spawn) + elidragon.skyblock.set_spawn(player, spawn) local file = io.open(minetest.get_modpath("elidragon") .. "/schems/island.we", "r") local schem = file:read() file:close() @@ -123,47 +96,6 @@ function elidragon.skyblock.new_spawn(name) return spawn end -function elidragon.skyblock.load_legacy_spawns() - local file = io.open(minetest.get_worldpath() .. "/skyblock.spawn", "r") - if file then - local spawns = {} - while true do - local x = file:read("*n") - if x == nil then - break - end - local y = file:read("*n") - local z = file:read("*n") - local name = file:read("*l") - spawns[name:sub(2)] = {x = x, y = y, z = z} - end - file:close() - return spawns - end -end - -elidragon.savedata.spawns = elidragon.savedata.spawns or elidragon.skyblock.load_legacy_spawns() or {} - - --- level ---[[ -minetest.register_chatcommand("level", { - description = "Get/set the current level of a player", - params = " []", - func = function(name, param) - local target = param:split(" ")[1] - local level = tonumber(param:split(" ")[2]) - if not level then - minetest.chat_send_player(name, target .. " is on level " .. elidragon.skyblock.get_level(target)) - elseif minetest.check_player_privs(name, {server = true}) and elidragon.skyblock.set_level(target, level) then - minetest.chat_send_player(name, target .. " has been set to level " .. level) - else - minetest.chat_send_player(name, "Cannot change " .. target .. " to level " .. level) - end - end, -}) -]]-- - -- node minetest.register_node("elidragon:skyblock", { @@ -219,33 +151,33 @@ minetest.after(0, function() local node if oldnode.name == "default:lava_source" then node = "default:obsidian" - elseif math.random() < 0.001 then + elseif math.random() < 0.0001 then node = "moreores:mineral_mithril" - elseif math.random() < 0.003 then + elseif math.random() < 0.0003 then node = "default:stone_with_diamond" - elseif math.random() < 0.005 then + elseif math.random() < 0.0005 then node = "default:stone_with_mese" - elseif math.random() < 0.01 then + elseif math.random() < 0.001 then node = "default:stone_with_gold" - elseif math.random() < 0.01 then + elseif math.random() < 0.001 then node = "technic:mineral_chromium" - elseif math.random() < 0.01 then + elseif math.random() < 0.001 then node = "technic:mineral_zinc" - elseif math.random() < 0.012 then + elseif math.random() < 0.0012 then node = "technic:mineral_uranium" - elseif math.random() < 0.015 then + elseif math.random() < 0.0015 then node = "default:stone_with_tin" - elseif math.random() < 0.02 then + elseif math.random() < 0.002 then node = "default:stone_with_copper" - elseif math.random() < 0.025 then + elseif math.random() < 0.0025 then node = "technic:mineral_sulfur" - elseif math.random() < 0.033 then + elseif math.random() < 0.0033 then node = "default:stone_with_iron" - elseif math.random() < 0.04 then + elseif math.random() < 0.004 then node = "moreores:mineral_silver" - elseif math.random() < 0.045 then + elseif math.random() < 0.0045 then node = "technic:mineral_lead" - elseif math.random() < 0.05 then + elseif math.random() < 0.005 then node = "default:stone_with_coal" else node = "default:stone" @@ -271,14 +203,13 @@ minetest.after(0, function() if stree ~= tree then items[#items + 1] = { items = {stree .. "sapling"}, - rarity = 1000, + rarity = 10000, } end end items[#items + 1] = { items = {tree .. "leaves"}, } - print(tree) minetest.registered_nodes[tree .. "leaves"].drop = {max_items = 1, items = items} end end) @@ -377,27 +308,29 @@ minetest.register_craft({ -- commands -minetest.register_chatcommand("set_skyblock_spawn", { - param = " ", - desc = "Change the skyblocks spawn of a player", - privs = {server = true}, - func = function(admin, param) - local name = param:split(" ")[1] - local x = tonumber(param:split(" ")[2]) - local y = tonumber(param:split(" ")[3]) - local z = tonumber(param:split(" ")[4]) - if name and x and y and z then - elidragon.skyblock.set_spawn(name, {x = x, y = y, z = z}) - else - minetest.chat_send_player(admin, "Invalid usage.") - end - end -}) - minetest.register_chatcommand("island", { params = "", description = "Teleport to your Island", func = function(name, param) - elidragon.skyblock.spawn_player(minetest.get_player_by_name(name)) + local player = minetest.get_player_by_name(name) + if not player then return end + elidragon.skyblock.spawn_player(player) + end, +}) + +minetest.register_chatcommand("set_skyblock_spawn", { + params = " ", + description = "Set new skyblock spawn for ", + privs = {server = true}, + func = function(sender, param) + local name = param:split(" ")[1] + local x = tonumber(param:split(" ")[2]) + local y = tonumber(param:split(" ")[3]) + local z = tonumber(param:split(" ")[4]) + if name and x and y and z and minetest.get_player_by_name(name) then + elidragon.skyblock.set_spawn(minetest.get_player_by_name(name), {x = x, y = y, z = z}) + else + minetest.chat_send_player(sender, "Invalid usage or player not online") + end end, })