diff --git a/mods/CORE/mcl_mapgen/init.lua b/mods/CORE/mcl_mapgen/init.lua index 0edaffc38..cfd87d189 100644 --- a/mods/CORE/mcl_mapgen/init.lua +++ b/mods/CORE/mcl_mapgen/init.lua @@ -30,6 +30,7 @@ mcl_mapgen.LAST_BLOCK = mcl_mapgen.CS - 1 mcl_mapgen.LAST_NODE_IN_BLOCK = mcl_mapgen.BS - 1 mcl_mapgen.LAST_NODE_IN_CHUNK = mcl_mapgen.CS_NODES - 1 mcl_mapgen.HALF_CS_NODES = math_floor(mcl_mapgen.CS_NODES / 2) +mcl_mapgen.HALF_BS = math_floor(mcl_mapgen.BS / 2) mcl_mapgen.CS_3D = mcl_mapgen.CS^3 mcl_mapgen.CHUNK_WITH_SHELL = mcl_mapgen.CS + 2 mcl_mapgen.CHUNK_WITH_SHELL_3D = mcl_mapgen.CHUNK_WITH_SHELL^3 diff --git a/mods/ITEMS/mcl_amethyst/geode.lua b/mods/ITEMS/mcl_amethyst/geode.lua new file mode 100644 index 000000000..0c2110cf5 --- /dev/null +++ b/mods/ITEMS/mcl_amethyst/geode.lua @@ -0,0 +1,50 @@ +local radius_min = 3 +local radius_max = mcl_mapgen.HALF_BS +local layers = { + { + [100] = "mcl_core:andesite", + }, + { + [100] = "mcl_amethyst:calcite", + }, + { + [95] = "mcl_amethyst:amethyst_block", + [5] = "mcl_amethyst:budding_amethyst_block", + }, + { + [100] = "air", + } +} + +local function place(pos, rotation, pr) + local radius = pr:next(radius_min, radius_max) + local pos = vector.add(pos, radius) + for x = pos.x - radius, pos.x + radius do + for y = pos.y - radius, pos.y + radius do + for z = pos.z - radius, pos.z + radius do + local node_pos = vector.new(x, y, z) + local inverted_layer = vector.round(vector.distance(node_pos, pos)) + if inverted_layer <= radius then + local layer = math.max(radius - inverted_layer + 1, #layers) + local node_candidates = layers[layer] + local node_name + local chance_index = pr:next(1, 100) + local current_weight = 0 + for chance, node_name_iterated in pairs(node_candidates) do + if chance_index < current_weight + chance then + node_name = node_name_iterated + break + end + current_weight = current_weight + chance + end + minetest.swap_node(node_pos, {name = node_name}) + end + end + end + end +end + +mcl_structures.register_structure({ + name = "amethyst_geode", + place_function = place, +}) diff --git a/mods/ITEMS/mcl_amethyst/init.lua b/mods/ITEMS/mcl_amethyst/init.lua index 1406e5de6..64f63071f 100644 --- a/mods/ITEMS/mcl_amethyst/init.lua +++ b/mods/ITEMS/mcl_amethyst/init.lua @@ -1,4 +1,6 @@ local S = minetest.get_translator(minetest.get_current_modname()) +local modname = minetest.get_current_modname() +local modpath = minetest.get_modpath(modname) mcl_amethyst = {} -- Amethyst block @@ -208,5 +210,5 @@ if minetest.get_modpath("mcl_spyglass") then end end --- Amethyst Growing -dofile(minetest.get_modpath(minetest.get_current_modname()) .. "/grow.lua") +dofile(modpath .. "/grow.lua") +dofile(modpath .. "/geode.lua") diff --git a/mods/ITEMS/mcl_amethyst/mod.conf b/mods/ITEMS/mcl_amethyst/mod.conf index ccbcbb430..6c68342c8 100644 --- a/mods/ITEMS/mcl_amethyst/mod.conf +++ b/mods/ITEMS/mcl_amethyst/mod.conf @@ -1,5 +1,5 @@ name = mcl_amethyst author = Emojiminetest description = Amethyst related stuff for MCL5 -depends = mcl_init, mcl_core, mcl_wip +depends = mcl_init, mcl_core, mcl_wip, mcl_mapgen, mcl_structures optional_depends = mcl_spyglass, mcl_copper