#11 Fix various amethyst errors, write better seed function

This commit is contained in:
kay27 2022-02-05 20:49:45 +04:00
parent adbde60b10
commit 22351ca1d8
6 changed files with 86 additions and 63 deletions

View File

@ -167,40 +167,38 @@ local function is_chunk_finished(minp)
return true
end
local function unsigned(v)
if v < 0 then
v = 0x100000000 - (math.abs(v) % 0x100000000)
end
local function uint32_t(v)
if v >= 0 then
return v % 0x100000000
end
return 0x100000000 - (math.abs(v) % 0x100000000)
end
local function bitwise_xor_32(a, b)
local a = unsigned(a)
local b = unsigned(b)
local c = 0
for n = 31, 0, -1 do
local mask = math.floor(2^n)
if (a >= mask) ~= (b >= mask) then
c = c + mask
end
a = a % mask
b = b % mask
end
return c
local function get_block_seed(pos, current_seed)
local current_seed = current_seed or uint32_t(tonumber(seed))
return uint32_t(uint32_t(23 * pos.x) + uint32_t(42123 * pos.y) + uint32_t(38134234 * pos.z) + current_seed)
end
local function getBlockSeed2(pos, seed)
local seed = seed or mcl_mapgen.seed
local n = unsigned(unsigned(1619 * pos.x) + unsigned(31337 * pos.y) + unsigned(52591 * pos.z) + unsigned(1013 * seed))
n = bitwise_xor_32(math.floor(n / 0x2000), n)
return unsigned((n * unsigned(n * n * 60493 + 19990303) + 1376312589))
local function get_block_seed2(pos, current_seed)
local current_seed = current_seed or uint32_t(tonumber(seed))
local n = uint32_t(uint32_t(1619 * pos.x) + uint32_t(31337 * pos.y) + uint32_t(52591 * pos.z) + uint32_t(1013 * current_seed))
n = bit.bxor(bit.rshift(n, 13), n)
local seed = uint32_t((n * uint32_t(n * n * 60493 + 19990303) + 1376312589))
return seed
end
local function get_block_seed3(pos, current_seed)
local current_seed = uint32_t(current_seed or uint32_t(tonumber(seed)))
local x = uint32_t((pos.x + 32768) * 13)
local y = uint32_t((pos.y + 32767) * 13873)
local z = uint32_t((pos.z + 76705) * 115249)
local seed = uint32_t(bit.bxor(current_seed, x, y, z))
return seed
end
minetest.register_on_generated(function(minp, maxp, chunkseed)
local minp, maxp, chunkseed = minp, maxp, chunkseed
local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
minetest_log("action", "[mcl_mapgen] New_chunk=" .. minetest_pos_to_string(minp) .. "..." .. minetest_pos_to_string(maxp) .. ", shell=" .. minetest_pos_to_string(emin) .. "..." .. minetest_pos_to_string(emax) .. ", chunkseed=" .. tostring(chunkseed))
data = vm:get_data(lvm_buffer)
area = VoxelArea:new({MinEdge=emin, MaxEdge=emax})
vm_context = {
@ -257,10 +255,10 @@ minetest.register_on_generated(function(minp, maxp, chunkseed)
end
local number_of_blocks = 0
for k, offset in pairs(ready_blocks) do
if queue_blocks_lvm_counter > 0 then
if queue_blocks_lvm_counter > 0 or nodes_block > 0 then
local block_minp = p0 + vector.multiply(offset, BS)
local block_maxp = vector.add(block_minp, LAST_NODE_IN_BLOCK)
local blockseed = getBlockSeed2(block_minp)
local blockseed = get_block_seed3(block_minp)
vm_context.minp, vm_context.maxp, vm_context.blockseed = block_minp, block_maxp, blockseed
-- --
-- mcl_mapgen.register_mapgen_block_lvm(function(vm_context), order_number) --
@ -269,7 +267,7 @@ minetest.register_on_generated(function(minp, maxp, chunkseed)
v.callback_function(vm_context)
end
if nodes_block > 0 then
current_blocks[#current_blocks + 1] = { minp = block_minp, maxp = block_maxp, seed = blockseed }
current_blocks[#current_blocks + 1] = { minp = block_minp, maxp = block_maxp, blockseed = blockseed }
end
end
number_of_blocks = number_of_blocks + 1
@ -307,7 +305,7 @@ minetest.register_on_generated(function(minp, maxp, chunkseed)
for i, chunk_minp in pairs(current_chunks) do
local chunk_maxp = vector.add(chunk_minp, LAST_NODE_IN_CHUNK)
local chunkseed = getBlockSeed2(chunk_minp)
local current_chunk_seed = get_block_seed3(vector.subtract(chunk_minp, BS))
area = VoxelArea:new({MinEdge=minp, MaxEdge=maxp})
vm_context = {
data = data,
@ -321,7 +319,7 @@ minetest.register_on_generated(function(minp, maxp, chunkseed)
emax = chunk_maxp,
minp = chunk_minp,
maxp = chunk_maxp,
chunkseed = chunkseedseed,
chunkseed = current_chunk_seed,
}
-- --
-- mcl_mapgen.register_mapgen_lvm(function(vm_context), order_number) --
@ -333,7 +331,7 @@ minetest.register_on_generated(function(minp, maxp, chunkseed)
-- mcl_mapgen.register_mapgen(function(minp, maxp, chunkseed, vm_context), order_number) --
-- --
for _, v in pairs(queue_chunks_nodes) do
v.f(chunk_minp, chunk_maxp, chunkseed, vm_context)
v.f(chunk_minp, chunk_maxp, current_chunk_seed, vm_context)
end
if vm_context.write or vm_context.write_param2 or vm_context.write_light then
if vm_context.write then
@ -354,12 +352,12 @@ minetest.register_on_generated(function(minp, maxp, chunkseed)
end
end
for i, b in pairs(current_blocks) do
for _, b in pairs(current_blocks) do
-- --
-- mcl_mapgen.register_mapgen_block(function(minp, maxp, blockseed), order_number) --
-- --
for _, v in pairs(queue_blocks_nodes) do
v.f(b.minp, b.maxp, b.seed)
v.f(b.minp, b.maxp, b.blockseed)
end
end
end)

View File

@ -2,7 +2,8 @@ local radius_min = 3
local radius_max = mcl_mapgen.HALF_BS
local layers = {
{
[100] = "mcl_blackstone:basalt_polished",
[8] = "mcl_blackstone:basalt_polished",
[92] = "mcl_deepslate:deepslate",
},
{
[100] = "mcl_amethyst:calcite",
@ -80,9 +81,10 @@ mcl_structures.register_structure({
local decrease_scan_area = 1
local mapblock_opacity_placement_threshold = 0.98
local threshold = math.floor(((mcl_mapgen.BS - 2 * decrease_scan_area)^3) * mapblock_opacity_placement_threshold)
local upper_than = mcl_mapgen.overworld.bedrock_max
mcl_mapgen.register_mapgen_block(function(minp, maxp, blockseed)
local y = minp.y
if y < 0 then return end
if y <= upper_than then return end
local pr = PseudoRandom(blockseed + 143)
if pr:next(1, 120) ~= 54 then return end
local opacity_counter = #minetest.find_nodes_in_area(vector.add(minp, decrease_scan_area), vector.subtract(maxp, decrease_scan_area), "group:opaque")

View File

@ -16,7 +16,7 @@ minetest.register_node("mcl_amethyst:amethyst_block",{
sounds = mcl_sounds.node_sound_glass_defaults(),
is_ground_content = true,
stack_max = 64,
_doc_items_longdesc = S("The Block of Amethyst is a decoration block creft from amethyst shards."),
_doc_items_longdesc = S("The Block of Amethyst is a decoration block crafted from amethyst shards."),
})
-- Budding Amethyst block
@ -86,18 +86,40 @@ minetest.register_node("mcl_amethyst:tinted_glass",{
-- Amethyst Cluster
local bud_def = {
{"small","Small","mcl_amethyst:medium_amethyst_bud"},
{"medium","Medium","mcl_amethyst:large_amethyst_bud"},
{"large","Large","mcl_amethyst:amethyst_cluster"},
{
size = "small",
description = S("Small Amethyst Bud"),
long_desc = S("Small Amethyst Bud is the first growth of amethyst bud."),
light_source = 3,
next_stage = "mcl_amethyst:medium_amethyst_bud",
},
{
size = "medium",
description = S("Medium Amethyst Bud"),
long_desc = S("Medium Amethyst Bud is the second growth of amethyst bud."),
light_source = 4,
next_stage = "mcl_amethyst:large_amethyst_bud",
},
{
size = "large",
description = S("Large Amethyst Bud"),
long_desc = S("Large Amethyst Bud is the third growth of amethyst bud."),
light_source = 5,
next_stage = "mcl_amethyst:amethyst_cluster",
},
}
for x,y in pairs(bud_def) do
minetest.register_node("mcl_amethyst:" .. y[1] .. "_amethyst_bud",{
description = y[2] .. " Amethyst Bud",
for _, def in pairs(bud_def) do
local size = def.size
local name = "mcl_amethyst:" .. size .. "_amethyst_bud"
local tile = size .. "_amethyst_bud.png"
local inventory_image = size .. "_amethyst_bud.png"
minetest.register_node(name, {
description = def.description,
_mcl_hardness = 1.5,
_mcl_blast_resistance = 1.5,
drop = "",
tiles = {y[1] .. "_amethyst_bud.png",},
inventory_image = y[1] .. "_amethyst_bud.png",
tiles = {tile},
inventory_image = inventory_image,
paramtype1 = "light",
paramtype2 = "wallmounted",
drawtype = "plantlike",
@ -114,17 +136,15 @@ for x,y in pairs(bud_def) do
},
selection_box = {
type = "fixed",
-- fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
fixed = { -7/16, -8/16, -7/16, 7/16, -7/16, 7/16 },
},
collision_box = {
type = "fixed",
-- fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
fixed = { -7/16, -8/16, -7/16, 7/16, -7/16, 7/16 },
},
_mcl_silk_touch_drop = true,
_mcl_amethyst_next_grade = y[3],
_doc_items_longdesc = S("@1 Amethyst Bud is the @2 grouth of amethyst bud.", y[2], y[1]),
_mcl_amethyst_next_grade = def.next_stage,
_doc_items_longdesc = def.longdesc,
})
end
@ -132,7 +152,7 @@ minetest.register_node("mcl_amethyst:amethyst_cluster",{
description = "Amethyst Cluster",
_mcl_hardness = 1.5,
_mcl_blast_resistance = 1.5,
_doc_items_longdesc = S("Amethyst Cluster is the final grouth of amethyst bud."),
_doc_items_longdesc = S("Amethyst Cluster is the final growth of amethyst bud."),
drop = {
max_items = 1,
items = {
@ -152,6 +172,7 @@ minetest.register_node("mcl_amethyst:amethyst_cluster",{
paramtype1 = "light",
use_texture_alpha = "clip",
sunlight_propagates = true,
light_source = 7,
groups = {
dig_by_water = 1,
destroy_by_lava_flow = 1,
@ -162,12 +183,10 @@ minetest.register_node("mcl_amethyst:amethyst_cluster",{
},
selection_box = {
type = "fixed",
-- fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
fixed = { -7/16, -8/16, -7/16, 7/16, -7/16, 7/16 },
},
collision_box = {
type = "fixed",
-- fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
fixed = { -7/16, -8/16, -7/16, 7/16, -7/16, 7/16 },
},
_mcl_silk_touch_drop = true,

View File

@ -1,17 +1,19 @@
# textdomain: mcl_amethyst
@1 Amethyst Bud is the @2 grouth of amethyst bud.=@1 Аметистовый Бутон - это @2-я стадия роста аместистового бутона.
Amethyst Cluster=Аметистовая друза
Amethyst Cluster is the final grouth of amethyst bud.=Аметистовая друза - это последняя 4-я стадия роста аметистового бутона.
Amethyst Growing Tool=Выращиватель аметиста
Amethyst Cluster is the final growth of amethyst bud.=Аметистовая друза - это последняя 4-я стадия роста аметистового бутона.
Amethyst Shard=Осколок аметиста
An amethyst shard is a crystalline mineral.=Осколок аметиста - это кристаллический минерал, получаемый в результате разрушения кластеров аметиста.
Block of Amethyst=Аметистовый блок
Budding Amethyst=Растущий аметист
Calcite=Кальцит
Calcite can be found as part of amethyst geodes.=Кальцит можно найти в составе аметистовых жеод.
Growing Failed=Выращивание не удалось
Not allowed to use Amethyst Growing Tool in a protected area!=Выращиватель аметиста нельзя использовать в защищённых частях мира
The Block of Amethyst is a decoration block creft from amethyst shards.=Блок аметиста - декоративный блок, скрафченный из осколков аметиста.
Large Amethyst Bud=Большой росток аметиста
Large Amethyst Bud is the third growth of amethyst bud.=Большой росток - третья стадия роста аметиста.
Medium Amethyst Bud=Средний росток аметиста
Medium Amethyst Bud is the second growth of amethyst bud.=Средний росток - вторая стадия роста аметиста.
Small Amethyst Bud=Маленький росток аметиста
Small Amethyst Bud is the first growth of amethyst bud.=Маленький росток - первая стадия роста аметиста.
The Block of Amethyst is a decoration block crafted from amethyst shards.=Блок аметиста - декоративный блок, скрафченный из осколков аметиста.
The Budding Amethyst can grow amethyst=Растущий аметист может вырастить аметист
Tinted Glass=Тонированное стекло
Tinted Glass is a type of glass which blocks lights while it is visually transparent.=Тонированное стекло блокирует свет, но визуально прозрачно.

View File

@ -1,17 +1,19 @@
# textdomain: mcl_amethyst
@1 Amethyst Bud is the @2 grouth of amethyst bud.=
Amethyst Cluster=
Amethyst Cluster is the final grouth of amethyst bud.=
Amethyst Growing Tool=
Amethyst Cluster is the final growth of amethyst bud.=
Amethyst Shard=
An amethyst shard is a crystalline mineral.=
Block of Amethyst=
Budding Amethyst=
Calcite=
Calcite can be found as part of amethyst geodes.=
Growing Failed=
Not allowed to use Amethyst Growing Tool in a protected area!=
The Block of Amethyst is a decoration block creft from amethyst shards.=
Large Amethyst Bud=
Large Amethyst Bud is the third growth of amethyst bud.=
Medium Amethyst Bud=
Medium Amethyst Bud is the second growth of amethyst bud.=
Small Amethyst Bud=
Small Amethyst Bud is the first growth of amethyst bud.=
The Block of Amethyst is a decoration block crafted from amethyst shards.=
The Budding Amethyst can grow amethyst=
Tinted Glass=
Tinted Glass is a type of glass which blocks lights while it is visually transparent.=

View File

@ -1,5 +1,5 @@
name = mcl_amethyst
author = Emojiminetest, kay27
description = Amethyst related stuff for MCL5
depends = mcl_init, mcl_core, mcl_wip, mcl_mapgen, mcl_structures, mcl_blackstone
depends = mcl_init, mcl_core, mcl_wip, mcl_mapgen, mcl_structures, mcl_blackstone, mcl_deepslate
optional_depends = mcl_spyglass, mcl_copper