]> git.lizzy.rs Git - skycraft.git/commitdiff
Modularisation
authorElias Fleckenstein <eliasfleckenstein@web.de>
Sun, 7 Jun 2020 08:50:23 +0000 (10:50 +0200)
committerElias Fleckenstein <eliasfleckenstein@web.de>
Sun, 7 Jun 2020 08:50:23 +0000 (10:50 +0200)
flower_spread.lua [new file with mode: 0644]
init.lua
lava_cooling.lua [new file with mode: 0644]
map.lua [deleted file]
mapgen.lua [new file with mode: 0644]
money.lua
playerlist.lua [deleted file]
shop.lua [new file with mode: 0644]

diff --git a/flower_spread.lua b/flower_spread.lua
new file mode 100644 (file)
index 0000000..cf7bf22
--- /dev/null
@@ -0,0 +1,13 @@
+minetest.register_abm({
+       nodenames = {"mcl_core:dirt_with_grass"},
+       interval = 300,
+       chance = 100,
+       action = function(pos, node)
+               pos.y = pos.y + 1
+               local light = minetest.get_node_light(pos) or 0
+               if minetest.get_node(pos).name == "air" and light > 12 and not minetest.find_node_near(pos, 2, {"group:flora"}) then
+                       local flowers = {"mcl_flowers:blue_orchid", "mcl_flowers:azure_bluet", "mcl_flowers:allium", "mcl_flowers:tulip_white", "mcl_flowers:tulip_red", "mcl_flowers:tulip_pink", "mcl_flowers:tulip_orange", "mcl_flowers:oxeye_daisy", "mcl_flowers:dandelion", "mcl_flowers:poppy", "mcl_flowers:fern", "mcl_flowers:tallgrass", "mcl_flowers:double_tallgrass"}
+                       minetest.set_node(pos, {name = flowers[math.random(#flowers)]})
+               end
+       end
+}) 
index 886f41311767abc248de78cb962c82320a4cee2a..4b0d0070f8a9fce59c859027a3d561c6ade8e3c8 100755 (executable)
--- a/init.lua
+++ b/init.lua
@@ -45,7 +45,7 @@ end)
 
 do
        local modpath = minetest.get_modpath("skycraft")
-       local modules = {"random", "commands", "ranks", "plots", "spawns", "map", "request", "tpa", "trade", "lobby", "money", "lucky_block", "nether_portal"}
+       local modules = {"random", "commands", "ranks", "plots", "spawns", "mapgen", "request", "tpa", "trade", "lobby", "money", "lucky_block", "nether_portal", "lava_cooling", "flower_spread", "shop"}
        for _, m in pairs(modules) do
                dofile(modpath .. "/" .. m .. ".lua")
        end
diff --git a/lava_cooling.lua b/lava_cooling.lua
new file mode 100644 (file)
index 0000000..3494e38
--- /dev/null
@@ -0,0 +1,25 @@
+skycraft.ores = skycraft.random:new()
+skycraft.ores:add_choice("mcl_core:cobble", 1000)
+skycraft.ores:add_choice("mcl_core:stone", 200)
+skycraft.ores:add_choice("mcl_core:stone_with_coal", 31)
+skycraft.ores:add_choice("mcl_core:stone_with_iron", 25)
+skycraft.ores:add_choice("mcl_core:stone_with_gold", 10)
+skycraft.ores:add_choice("mcl_core:stone_with_lapis", 10)
+skycraft.ores:add_choice("mcl_core:stone_with_redstone", 10)
+skycraft.ores:add_choice("mcl_core:stone_with_diamond", 5)
+skycraft.ores:calc_csum() 
+
+minetest.register_on_mods_loaded(function()
+       for k, v in pairs(minetest.registered_abms) do
+               if v.label == "Lava cooling" then
+                       local old_func = v.action
+                       v.action = function(pos, node, active_object_count, active_object_count_wider)
+                               old_func(pos, node, active_object_count, active_object_count_wider)
+                               if minetest.get_node(pos).name == "mcl_core:cobble" then
+                                       minetest.set_node(pos, {name = skycraft.ores:choose()})
+                               end
+                       end
+                       break
+               end
+       end
+end)
diff --git a/map.lua b/map.lua
deleted file mode 100644 (file)
index bd31515..0000000
--- a/map.lua
+++ /dev/null
@@ -1,77 +0,0 @@
-skycraft.ores = skycraft.random:new()
-skycraft.ores:add_choice("mcl_core:cobble", 1000)
-skycraft.ores:add_choice("mcl_core:stone", 200)
-skycraft.ores:add_choice("mcl_core:stone_with_coal", 31)
-skycraft.ores:add_choice("mcl_core:stone_with_iron", 25)
-skycraft.ores:add_choice("mcl_core:stone_with_gold", 10)
-skycraft.ores:add_choice("mcl_core:stone_with_lapis", 10)
-skycraft.ores:add_choice("mcl_core:stone_with_redstone", 10)
-skycraft.ores:add_choice("mcl_core:stone_with_diamond", 5)
-skycraft.ores:calc_csum()
-
-minetest.register_abm({
-       nodenames = {"mcl_core:dirt_with_grass"},
-       interval = 300,
-       chance = 100,
-       action = function(pos, node)
-               pos.y = pos.y + 1
-               local light = minetest.get_node_light(pos) or 0
-               if minetest.get_node(pos).name == "air" and light > 12 and not minetest.find_node_near(pos, 2, {"group:flora"}) then
-                       local flowers = {"mcl_flowers:blue_orchid", "mcl_flowers:azure_bluet", "mcl_flowers:allium", "mcl_flowers:tulip_white", "mcl_flowers:tulip_red", "mcl_flowers:tulip_pink", "mcl_flowers:tulip_orange", "mcl_flowers:oxeye_daisy", "mcl_flowers:dandelion", "mcl_flowers:poppy", "mcl_flowers:fern", "mcl_flowers:tallgrass", "mcl_flowers:double_tallgrass"}
-                       minetest.set_node(pos, {name = flowers[math.random(#flowers)]})
-               end
-       end
-})
-
-minetest.register_on_generated(function(minp, maxp)
-       if maxp.y < 1000 or minp.y > 5000 then return end
-       local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
-       local data = vm:get_data()
-       local area = VoxelArea:new({MinEdge=emin, MaxEdge=emax})
-       local void_id = minetest.get_content_id("mcl_core:void")
-       local barrier_id = minetest.get_content_id("mcl_core:barrier")
-       for x = minp.x, maxp.x do
-               for z = minp.z, maxp.z do
-                       local barrier = (math.mod(x, 62) == 0 or math.mod(z, 62) == 0)
-                       local void = (maxp.y < 1500)
-                       if barrier or void then
-                               for y = minp.y, maxp.y do
-                                       local p_pos = area:index(x, y, z)
-                                       data[p_pos] = barrier and barrier_id or void_id
-                               end
-                       end
-               end
-       end
-       if maxp.y > 5000 then--or minp.y < 1000 then
-               for x = minp.x, maxp.x do
-                       for z = minp.z, maxp.z do
-                               local y = (maxp.y > 5000) and 1000 or 5000
-                               local p_pos = area:index(x, y, z)
-                               data[p_pos] = barrier_id
-                       end
-               end
-       end
-       vm:set_data(data)
-       vm:calc_lighting()
-       vm:update_liquids()
-       vm:write_to_map()
-end)
-
-minetest.register_on_mods_loaded(function()
-       function mcl_worlds.is_in_void(pos)
-               local res = minetest.get_node(vector.floor(pos)).name == "mcl_core:void"
-               return res, res
-       end
-       for k, v in pairs(minetest.registered_abms) do
-               if v.label == "Lava cooling" then
-                       local old_func = v.action
-                       v.action = function(pos, node, active_object_count, active_object_count_wider)
-                               old_func(pos, node, active_object_count, active_object_count_wider)
-                               if minetest.get_node(pos).name == "mcl_core:cobble" then
-                                       minetest.set_node(pos, {name = skycraft.ores:choose()})
-                               end
-                       end
-                       break
-               end
-       end
-end)
diff --git a/mapgen.lua b/mapgen.lua
new file mode 100644 (file)
index 0000000..fede7b7
--- /dev/null
@@ -0,0 +1,40 @@
+minetest.register_on_generated(function(minp, maxp)
+       if maxp.y < 1000 or minp.y > 5000 then return end
+       local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
+       local data = vm:get_data()
+       local area = VoxelArea:new({MinEdge=emin, MaxEdge=emax})
+       local void_id = minetest.get_content_id("mcl_core:void")
+       local barrier_id = minetest.get_content_id("mcl_core:barrier")
+       for x = minp.x, maxp.x do
+               for z = minp.z, maxp.z do
+                       local barrier = (math.mod(x, 62) == 0 or math.mod(z, 62) == 0)
+                       local void = (maxp.y < 1500)
+                       if barrier or void then
+                               for y = minp.y, maxp.y do
+                                       local p_pos = area:index(x, y, z)
+                                       data[p_pos] = barrier and barrier_id or void_id
+                               end
+                       end
+               end
+       end
+       if maxp.y > 5000 or minp.y < 1000 then
+               for x = minp.x, maxp.x do
+                       for z = minp.z, maxp.z do
+                               local y = (maxp.y > 5000) and 1000 or 5000
+                               local p_pos = area:index(x, y, z)
+                               data[p_pos] = barrier_id
+                       end
+               end
+       end
+       vm:set_data(data)
+       vm:calc_lighting()
+       vm:update_liquids()
+       vm:write_to_map()
+end)
+
+minetest.register_on_mods_loaded(function()
+       function mcl_worlds.is_in_void(pos)
+               local res = minetest.get_node(vector.floor(pos)).name == "mcl_core:void"
+               return res, res
+       end
+end)
index 4cca8cae9a52afe82b87140e1a3e695ff9ee4004..192ee11fa4df8725458a79e9a5208bb6ae365462 100644 (file)
--- a/money.lua
+++ b/money.lua
@@ -53,39 +53,3 @@ minetest.register_on_newplayer(function(player)
        skycraft.give_money(player, 200)
 end)
 
-minetest.register_on_mods_loaded(function()
-       for nodename, nodedef in pairs(minetest.registered_nodes) do
-               if nodename:find("mcl_signs:") then
-                       minetest.override_item(nodename, {
-                               on_rightclick = function(pos, node, player, itemstack, pointed_thing)
-                                       if pos.y < 5000 then return end
-                                       local text = minetest.get_meta(pos):get_string("text") or ""
-                                       local lines = text:split("\n")
-                                       local action, amount, price = lines[1], lines[2], lines[3]
-                                       print(action, amount, price)
-                                       if not (action and amount and price) then return end
-                                       price = string.gsub(price, "%$", "")
-                                       price = tonumber(price)
-                                       amount = string.gsub(amount, "x", "")
-                                       amount = tonumber(amount)
-                                       print(action, amount, price)
-                                       if not (amount and price) then return end
-                                       local func, frameoffset
-                                       if action == "Buy" then
-                                               func, frameoffset = skycraft.buy, -1
-                                       elseif action == "Sell" then
-                                               func, frameoffset = skycraft.sell, 1
-                                       else
-                                               return
-                                       end
-                                       local framepos = vector.add(pos, {x = 0, y = frameoffset, z = 0})
-                                       if minetest.get_node(framepos).name ~= "mcl_itemframes:item_frame" then return end
-                                       local inv = minetest.get_meta(framepos):get_inventory()
-                                       if inv:is_empty("main") then return end
-                                       local itemstack = inv:get_stack("main", 1)
-                                       func(player, itemstack:get_name() .. " " .. tostring(amount), price)
-                               end,
-                       })
-               end
-       end
-end)
diff --git a/playerlist.lua b/playerlist.lua
deleted file mode 100644 (file)
index 58718f4..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-skycraft.playerlist = {}
-controls.register_on_press(function(player, key)
-       if key == "sneak" then
-               local name = player:get_player_name()
-               local list = {}
-               local players = minetest.get_connected_players()
-               for i, p in pairs(players) do
-                       local n = p:get_player_name()
-                       local ping = math.max(1, math.ceil(4 - minetest.get_player_information(n).avg_rtt * 4))
-                       list[#list + 1] = player:hud_add({
-                               hud_elem_type = "text",
-                               position = {x = 1, y = 0},
-                               offset = {x = -50, y = 5 + (i - 1) * 18},
-                               text = n,
-                               alignment = {x = -1, y = 1},
-                               scale = {x = 100, y = 100},
-                               number = tonumber(skycraft.get_rank(n).color:gsub("#", ""), 16),
-                       })
-                       list[#list + 1] = player:hud_add({
-                               hud_elem_type = "image",
-                               position = {x = 1, y = 0},
-                               offset = {x = -5, y = (i - 1) * 18},
-                               text = "server_ping_" .. ping .. ".png",
-                               alignment = {x = -1, y = 1},
-                               scale = {x = 1.5, y = 1.5},
-                               number = 0xFFFFFF,
-                       })
-               end
-               skycraft.playerlist[name] = list
-       end
-end)
-controls.register_on_release(function(player, key)
-       if key == "sneak" then
-               for _, id in pairs(skycraft.playerlist[player:get_player_name()]) do
-                       player:hud_remove(id)
-               end
-       end
-end)
diff --git a/shop.lua b/shop.lua
new file mode 100644 (file)
index 0000000..3eb2a1a
--- /dev/null
+++ b/shop.lua
@@ -0,0 +1,36 @@
+minetest.register_on_mods_loaded(function()
+       for nodename, nodedef in pairs(minetest.registered_nodes) do
+               if nodename:find("mcl_signs:") then
+                       minetest.override_item(nodename, {
+                               on_rightclick = function(pos, node, player, itemstack, pointed_thing)
+                                       if pos.y < 5000 then return end
+                                       local text = minetest.get_meta(pos):get_string("text") or ""
+                                       local lines = text:split("\n")
+                                       local action, amount, price = lines[1], lines[2], lines[3]
+                                       print(action, amount, price)
+                                       if not (action and amount and price) then return end
+                                       price = string.gsub(price, "%$", "")
+                                       price = tonumber(price)
+                                       amount = string.gsub(amount, "x", "")
+                                       amount = tonumber(amount)
+                                       print(action, amount, price)
+                                       if not (amount and price) then return end
+                                       local func, frameoffset
+                                       if action == "Buy" then
+                                               func, frameoffset = skycraft.buy, -1
+                                       elseif action == "Sell" then
+                                               func, frameoffset = skycraft.sell, 1
+                                       else
+                                               return
+                                       end
+                                       local framepos = vector.add(pos, {x = 0, y = frameoffset, z = 0})
+                                       if minetest.get_node(framepos).name ~= "mcl_itemframes:item_frame" then return end
+                                       local inv = minetest.get_meta(framepos):get_inventory()
+                                       if inv:is_empty("main") then return end
+                                       local itemstack = inv:get_stack("main", 1)
+                                       func(player, itemstack:get_name() .. " " .. tostring(amount), price)
+                               end,
+                       })
+               end
+       end
+end)