This commit is contained in:
Xeno333 2024-08-13 20:52:27 -05:00
parent 2a48941618
commit 4cfbe4f500
4 changed files with 94 additions and 9 deletions

View File

@ -1,5 +1,6 @@
mcl_better_end = {}
mcl_better_end.api = {}
mcl_better_end.api.consts = {}
mcl_better_end.mapgen = {}
mcl_better_end.mapgen.ores = {}
@ -16,7 +17,7 @@ dofile(mcl_better_end.code_loc .. "/nodes/nodes_night.lua")
dofile(mcl_better_end.code_loc .. "/nodes/nodes_ender_sea.lua")
dofile(mcl_better_end.code_loc .. "/mapgen/biome.lua")
dofile(mcl_better_end.code_loc .. "/mapgen/mapgen.lua")
dofile(mcl_better_end.code_loc .. "/items/items.lua")

BIN
schems/end_sub.mts Normal file

Binary file not shown.

View File

@ -0,0 +1,80 @@
-- Define items to add to the chest with their max count and chance
local items_to_add = {
{i = "mcl_better_end:ender_shard", c = 1, x = 5},
{i = "mcl_better_end:end_glow_berry", c = 16, x = 3},
{i = "mcl_end:crystal", c = 32, x = 20},
{i = "mcl_throwing:ender_pearl", c = 4, x = 3},
{i = "mcl_throwing:ender_pearl", c = 16, x = 10},
{i = "mcl_armor:elytra", c = 1, x = 100},
}
-- Function to place a schematic and a chest, then fill the chest with items
local function make_sub(pos, pr)
-- Place the schematic
minetest.place_schematic(pos, mcl_better_end.schematic_loc .. "/end_sub.mts", "0", nil, true)
-- Define chest position
local chest_pos = {x = pos.x + 4, y = pos.y + 1, z = pos.z + 4}
-- Place the chest
minetest.set_node(chest_pos, {name = "mcl_chests:chest"})
-- Get chest metadata and inventory
local meta = minetest.get_meta(chest_pos)
local inv = meta:get_inventory()
inv:set_size("main", 16) -- Initialize inventory
local slots_used_c = 0
local slots_used = {}
-- Fill the chest with items
while slots_used_c < 6 do
for _, item in ipairs(items_to_add) do
local item_name = item.i
local quantity = item.c
-- Determine if the item should be included based on chance
if pr:next(1, item.x) == item.x then
-- Select a random slot
local slot = pr:next(1, 16)
while slots_used[slot] do
slot = pr:next(1, 16)
end
inv:set_stack("main", slot, item_name .. " " .. pr:next(1, quantity))
slots_used[slot] = true
slots_used_c = slots_used_c + 1
if slots_used_c == 16 then
return
end
end
end
end
end
mcl_better_end.api.register_biome({
type = "sea",
dec = function(pr, x, y, z, perlin)
if pr:next(1, 4000) == 5 then
if perlin:get_3d({x = x, y = y, z = z}) < (mcl_better_end.api.consts.sea_ends + 0.00001) then
make_sub({x=x,y=y,z=z}, pr)
end
end
end,
noise_high = 1,
noise_low = 0
})
minetest.register_chatcommand("spawn_endsub", {
params = "<radius>",
description = "Check if the area around you is empty within a certain radius",
func = function(player_name, param)
-- Get the player's position
local player = minetest.get_player_by_name(player_name)
local pos = player:get_pos()
make_sub(pos, PseudoRandom(math.random(1, 1000)))
end,
})

View File

@ -35,6 +35,10 @@ end
mcl_better_end.api.consts.sea_starts = -0.5
mcl_better_end.api.consts.sea_ends = -1
mcl_better_end.api.is_cave = function(x, y, z)
local noise = get_perlin_noise(perlin_l, x, y, z)
return (noise >= 0.8) or (get_perlin_noise(perlin_l, x, y + 1, z) >= 0.8)
@ -46,7 +50,7 @@ mcl_better_end.api.is_island = function(x, y, z)
end
mcl_better_end.api.is_sea = function(x, y, z)
return get_perlin_noise(perlin_l, x, y, z) < -0.5
return get_perlin_noise(perlin_l, x, y, z) < mcl_better_end.api.consts.sea_starts
end
mcl_better_end.api.is_free = function(x, y, z)
@ -112,12 +116,12 @@ function mcl_better_end.mapgen.gen(minp, maxp, seed)
if mcl_better_end.api.is_island(x, y, z) then
data[vi] = mcl_better_end.mapgen.registered_nodes.end_stone
for _, f in pairs(mcl_better_end.mapgen.ores) do
f(data, vi, area, pr, x, y, z)
f(data, vi, area, pr, x, y, z, perlin_l)
end
if mcl_better_end.api.is_free(x, y + 1, z) then
for _, p in pairs(mcl_better_end.biomes) do
if p.type == "island" and p.gen and noise_center >= p.noise_low and noise_center <= p.noise_high then
p.gen(data, vi, area, pr, x, y, z)
p.gen(data, vi, area, pr, x, y, z, perlin_l)
end
end
end
@ -128,7 +132,7 @@ function mcl_better_end.mapgen.gen(minp, maxp, seed)
if mcl_better_end.api.is_cave(x, y + 1, z) then
for _, p in pairs(mcl_better_end.biomes) do
if p.type == "cave" and p.gen and noise_center >= p.noise_low and noise_center <= p.noise_high then
p.gen(data, vi, area, pr, x, y, z)
p.gen(data, vi, area, pr, x, y, z, perlin_l)
end
end
end
@ -137,7 +141,7 @@ function mcl_better_end.mapgen.gen(minp, maxp, seed)
data[vi] = mcl_better_end.mapgen.registered_nodes.sea
for _, p in pairs(mcl_better_end.biomes) do
if p.type == "sea" and p.gen and noise_center >= p.noise_low and noise_center <= p.noise_high then
p.gen(data, vi, area, pr, x, y, z)
p.gen(data, vi, area, pr, x, y, z, perlin_l)
end
end
goto keepitup
@ -173,7 +177,7 @@ function mcl_better_end.mapgen.dec(minp, maxp, seed)
if mcl_better_end.api.is_free(x, y + 1, z) then
for _, p in pairs(mcl_better_end.biomes) do
if p.type == "island" and p.dec and noise_center >= p.noise_low and noise_center <= p.noise_high then
p.dec(pr, x, y, z)
p.dec(pr, x, y, z, perlin_l)
end
end
end
@ -183,7 +187,7 @@ function mcl_better_end.mapgen.dec(minp, maxp, seed)
local vi = area:index(x, y, z)
for _, p in pairs(mcl_better_end.biomes) do
if p.type == "cave" and p.dec and noise_center >= p.noise_low and noise_center <= p.noise_high then
p.dec(pr, x, y, z)
p.dec(pr, x, y, z, perlin_l)
end
end
goto keepitup
@ -191,7 +195,7 @@ function mcl_better_end.mapgen.dec(minp, maxp, seed)
elseif mcl_better_end.api.is_sea(x, y, z) then
for _, p in pairs(mcl_better_end.biomes) do
if p.type == "sea" and p.dec and noise_center >= p.noise_low and noise_center <= p.noise_high then
p.dec(pr, x, y, z)
p.dec(pr, x, y, z, perlin_l)
end
end
goto keepitup