optimisations

This commit is contained in:
chmodsayshello 2022-07-31 13:38:07 +02:00 committed by cora
parent 022fa1d794
commit b9cb3a4d70
2 changed files with 66 additions and 46 deletions

View File

@ -9,51 +9,48 @@ Valid strings:
]]-- ]]--
local color_list = {"cdf4e9","f9fcfb","7c5e3d","1826c9","16f4f4","f483fc","9712bc","ea1212","adadad","535454","19e52a","549159","ef8813","ebf704","000000","e502d6","e8e3e3"} --local color_list = {"cdf4e9","f9fcfb","7c5e3d","1826c9","16f4f4","f483fc","9712bc","ea1212","adadad","535454","19e52a","549159","ef8813","ebf704","000000","e502d6","e8e3e3"}
local function get_beacon_beam(glass_nodename) local function get_beacon_beam(glass_nodename)
if string.match(glass_nodename, "cyan") then if string.match(glass_nodename, "cyan") then
return "mcl_beacons:beacon_beam_cdf4e9" return 1
elseif string.match(glass_nodename,"white") then elseif string.match(glass_nodename,"white") then
return "mcl_beacons:beacon_beam_f9fcfb" return 2
elseif string.match(glass_nodename,"brown") then elseif string.match(glass_nodename,"brown") then
return "mcl_beacons:beacon_beam_7c5e3d" return 3
elseif string.match(glass_nodename,"blue") and not string.match(glass_nodename, "light") then elseif string.match(glass_nodename,"blue") and not string.match(glass_nodename, "light") then
return "mcl_beacons:beacon_beam_1826c9" return 4
elseif string.match(glass_nodename,"light_blue") then elseif string.match(glass_nodename,"light_blue") then
return "mcl_beacons:beacon_beam_16f4f4" return 5
elseif string.match(glass_nodename,"pink") then elseif string.match(glass_nodename,"pink") then
return "mcl_beacons:beacon_beam_f483fc" return 6
elseif string.match(glass_nodename, "purple") then elseif string.match(glass_nodename, "purple") then
return "mcl_beacons:beacon_beam_9712bc" return 7
elseif string.match(glass_nodename, "red") then elseif string.match(glass_nodename, "red") then
return "mcl_beacons:beacon_beam_ea1212" return 8
elseif string.match(glass_nodename, "silver") then elseif string.match(glass_nodename, "silver") then
return "mcl_beacons:beacon_beam_adadad" return 9
elseif string.match(glass_nodename, "gray") then elseif string.match(glass_nodename, "gray") then
return "mcl_beacons:beacon_beam_535454" return 10
elseif string.match(glass_nodename, "lime") then elseif string.match(glass_nodename, "lime") then
return "mcl_beacons:beacon_beam_19e52a" return 11
elseif string.match(glass_nodename, "green") then elseif string.match(glass_nodename, "green") then
return "mcl_beacons:beacon_beam_549159" return 12
elseif string.match(glass_nodename, "orange") then elseif string.match(glass_nodename, "orange") then
return "mcl_beacons:beacon_beam_ef8813" return 13
elseif string.match(glass_nodename, "yellow") then elseif string.match(glass_nodename, "yellow") then
return "mcl_beacons:beacon_beam_ebf704" return 14
elseif string.match(glass_nodename, "black") then elseif string.match(glass_nodename, "black") then
return "mcl_beacons:beacon_beam_000000" return 15
elseif string.match(glass_nodename, "magenta") then elseif string.match(glass_nodename, "magenta") then
return "mcl_beacons:beacon_beam_e502d6" return 16
else else
return "mcl_beacons:beacon_beam_e8e3e3" return 0
end end
end end
minetest.register_node("mcl_beacons:beacon_beam", {
tiles = {"^[colorize:#b8bab9"},
for _, color in ipairs(color_list) do
minetest.register_node("mcl_beacons:beacon_beam_"..color, {
tiles = {"^[colorize:#"..color},
drawtype = "nodebox", drawtype = "nodebox",
node_box = { node_box = {
type = "fixed", type = "fixed",
@ -61,14 +58,18 @@ for _, color in ipairs(color_list) do
{-0.1250, -0.5000, -0.1250, 0.1250, 0.5000, 0.1250} {-0.1250, -0.5000, -0.1250, 0.1250, 0.5000, 0.1250}
} }
}, },
pointable= false,
light_source = 15, light_source = 15,
walkable = false, walkable = false,
groups = {not_in_creative_inventory=1}, groups = {not_in_creative_inventory=1},
_mcl_blast_resistance = 1200, _mcl_blast_resistance = 1200,
}) paramtype2 = "color",
mesecon.register_mvps_stopper("mcl_beacons:beacon_beam_"..color) palette = "beacon_beam_palette.png",
end palette_index = 0,
buildable_to = true,
})
mesecon.register_mvps_stopper("mcl_beacons:beacon_beam")
local formspec_string= local formspec_string=
"size[11,14]".. "size[11,14]"..
@ -101,7 +102,7 @@ local formspec_string=
"list[current_player;main;1,12.5;9,1;]" "list[current_player;main;1,12.5;9,1;]"
local function remove_beacon_beam(pos) local function remove_beacon_beam(pos)
for y=pos.y+1, pos.y+401 do for y=pos.y, pos.y+301 do
local node = minetest.get_node({x=pos.x,y=y,z=pos.z}) local node = minetest.get_node({x=pos.x,y=y,z=pos.z})
if node.name ~= "air" and node.name ~= "mcl_core:bedrock" and node.name ~= "mcl_core:void" then if node.name ~= "air" and node.name ~= "mcl_core:bedrock" and node.name ~= "mcl_core:void" then
if node.name == "ignore" then if node.name == "ignore" then
@ -109,7 +110,7 @@ local function remove_beacon_beam(pos)
node = minetest.get_node({x=pos.x,y=y,z=pos.z}) node = minetest.get_node({x=pos.x,y=y,z=pos.z})
end end
if string.match(node.name,"mcl_beacons:beacon_beam_") then if node.name == "mcl_beacons:beacon_beam" then
minetest.remove_node({x=pos.x,y=y,z=pos.z}) minetest.remove_node({x=pos.x,y=y,z=pos.z})
end end
end end
@ -159,11 +160,13 @@ local function globalstep_function(pos,player)
if meta:get_int("effect_level") == 2 and power_level < 4 then if meta:get_int("effect_level") == 2 and power_level < 4 then
return return
else else
local colorblock = minetest.get_node({x=pos.x,y=pos.y+1,z=pos.z})
local obstructed = false local obstructed = false
for y=pos.y+1, pos.y+301 do for y=pos.y+1, pos.y+200 do
local nodename = minetest.get_node({x=pos.x,y=y, z = pos.z}).name local nodename = minetest.get_node({x=pos.x,y=y, z = pos.z}).name
if nodename ~= "mcl_core:bedrock" and nodename ~= "air" and nodename ~= "ignore" and nodename ~= "mcl_core:void" then --ignore means not loaded, let's just assume that's air if nodename ~= "mcl_core:bedrock" and nodename ~= "air" and nodename ~= "mcl_core:void" and nodename ~= "ignore" then --ignore means not loaded, let's just assume that's air
if not string.match(nodename,"mcl_beacons:beacon_beam_") then if nodename ~="mcl_beacons:beacon_beam" then
if minetest.get_item_group(nodename,"glass") == 0 then if minetest.get_item_group(nodename,"glass") == 0 then
obstructed = true obstructed = true
remove_beacon_beam(pos) remove_beacon_beam(pos)
@ -270,9 +273,9 @@ minetest.register_node("mcl_beacons:beacon", {
input:take_item() input:take_item()
inv:set_stack("input",1,input) inv:set_stack("input",1,input)
local beam_itemstring = "mcl_beacons:beacon_beam_e8e3e3" local beam_palette_index = 0
remove_beacon_beam(pos) remove_beacon_beam(pos)
for y = pos.y +1, pos.y + 401 do for y = pos.y +1, pos.y + 201 do
local node = minetest.get_node({x=pos.x,y=y,z=pos.z}) local node = minetest.get_node({x=pos.x,y=y,z=pos.z})
if node.name == ignore then if node.name == ignore then
minetest.get_voxel_manip():read_from_map({x=pos.x,y=y,z=pos.z}, {x=pos.x,y=y,z=pos.z}) minetest.get_voxel_manip():read_from_map({x=pos.x,y=y,z=pos.z}, {x=pos.x,y=y,z=pos.z})
@ -282,12 +285,12 @@ minetest.register_node("mcl_beacons:beacon", {
if y == pos.y+1 then if y == pos.y+1 then
if minetest.get_item_group(node.name, "glass") ~= 0 then if minetest.get_item_group(node.name, "glass") ~= 0 then
beam_itemstring = get_beacon_beam(node.name) beam_palette_index = get_beacon_beam(node.name)
end end
end end
if node.name == "air" then if node.name == "air" then
minetest.set_node({x=pos.x,y=y,z=pos.z},{name=beam_itemstring}) minetest.set_node({x=pos.x,y=y,z=pos.z},{name="mcl_beacons:beacon_beam",param2=beam_palette_index})
end end
end end
globalstep_function(pos,sender)--call it once outside the globalstep so the player gets the effect right after selecting it globalstep_function(pos,sender)--call it once outside the globalstep so the player gets the effect right after selecting it
@ -331,6 +334,23 @@ minetest.register_globalstep(function(dtime)
end end
end) end)
minetest.register_abm{
label="update beacon beam",
nodenames = {"mcl_beacons:beacon_beam"},
interval = 1,
chance = 1,
action = function(pos)
local node_below = minetest.get_node({x=pos.x,y=pos.y-1,z=pos.z})
local node_above = minetest.get_node({x=pos.x,y=pos.y+1,z=pos.z})
if node_below.name == "air" then
remove_beacon_beam(pos)
elseif node_above.name == "air" then
minetest.set_node({x=pos.x,y=pos.y+1,z=pos.z},{name="mcl_beacons:beacon_beam",param2=node_above.param2})
end
end,
}
minetest.register_craft({ minetest.register_craft({
output = "mcl_beacons:beacon", output = "mcl_beacons:beacon",
recipe = { recipe = {

Binary file not shown.

After

Width:  |  Height:  |  Size: 613 B