Update init.lua

This commit is contained in:
The4codeblocks 2023-07-14 18:26:05 +02:00 committed by GitHub
parent 5d9ea0186d
commit 9da1b004fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7,28 +7,28 @@ maxlvl = tonumber(core.settings:get("max_compression_level") or 10)
--Main --Main
table.copy = function(tbl) table.copy = function(tbl)
local copy local copy
if type(tbl) == "table" then if type(tbl) == "table" then
copy = {} copy = {}
for orig_key, orig_value in next, tbl, nil do for orig_key, orig_value in next, tbl, nil do
copy[table.copy(orig_key)] = table.copy(orig_value) copy[table.copy(orig_key)] = table.copy(orig_value)
end end
setmetatable(copy, table.copy(getmetatable(tbl))) setmetatable(copy, table.copy(getmetatable(tbl)))
else else
copy = tbl copy = tbl
end end
return copy return copy
end end
compression.darken_tiles = function(tiles, count) compression.darken_tiles = function(tiles, count)
if count>0 then if count>0 then
for key, tile in pairs(tiles) do for key, tile in pairs(tiles) do
if type(tile) == "table" then if type(tile) == "table" then
tile = darken_tiles(tile, count) tile = compression.darken_tiles(tile, count)
else else
for _=1, count, 1 do for _=1, count, 1 do
if _ <= tonumber(1 or 5) then if _ <= tonumber(1 or 5) then
tile = tile.."^compression_darken.png" if type(tile) == "string" then tile = tile.."^compression_darken.png" end
end end
end end
end end
@ -37,11 +37,11 @@ compression.darken_tiles = function(tiles, count)
return tiles return tiles
end end
end end
register_compressed = function(node, new_node) register_compressed = function(new_node)
core.register_node(new_node.info.name, table.copy(new_node.def)) core.register_node(new_node.info.name, table.copy(new_node.def))
core.register_craft({ core.register_craft({
type = "shapeless", type = "shapeless",
recipe = {}, recipe = {new_node.info.name},
output = new_node.info.subordinate.." 9", output = new_node.info.subordinate.." 9",
}) })
core.register_craft({ core.register_craft({
@ -62,12 +62,11 @@ register_compressed = function(node, new_node)
end end
compression.register_compressed_tiers = function(node) compression.register_compressed_tiers = function(node)
new_node.info.name = nil
new_node.def = table.copy(core.registered_nodes[node]) new_node.def = table.copy(core.registered_nodes[node])
new_node.info.initial_compression = new_node.def.groups.compressed or 0 new_node.info.initial_compression = new_node.def.groups.compressed or 0
new_node.info.original_description = new_node.def.description new_node.info.original_description = new_node.def.description
for level = new_node.info.initial_compression+1, maxlvl, 1 do for level = new_node.info.initial_compression+1, maxlvl, 1 do
if node ~= prior_node then new_node.info.name = nil end
local prior_node = node
if new_node.info.initial_compression == 0 then new_node.def.description = "Compressed "..new_node.def.description end if new_node.info.initial_compression == 0 then new_node.def.description = "Compressed "..new_node.def.description end
new_node.info.subordinate = new_node.info.name or node new_node.info.subordinate = new_node.info.name or node
new_node.info.name = "compression:"..(node:gsub(":","_")) new_node.info.name = "compression:"..(node:gsub(":","_"))
@ -79,8 +78,8 @@ compression.register_compressed_tiers = function(node)
new_node.def.groups.compressed = level new_node.def.groups.compressed = level
new_node.def.description = new_node.info.original_description.." (Level "..level..") (x"..(9^level)..")" new_node.def.description = new_node.info.original_description.." (Level "..level..") (x"..(9^level)..")"
new_node.def.tiles = compression.darken_tiles(new_node.def.tiles, level-new_node.info.initial_compression) new_node.def.tiles = compression.darken_tiles(new_node.def.tiles, level-new_node.info.initial_compression)
new_node.def.drop = node new_node.def.drop = new_node.info.name
register_compressed(node, new_node) register_compressed(new_node)
end end
end end