From b9cb3a4d70661b186d8416b4e36d688c28428e9f Mon Sep 17 00:00:00 2001 From: chmodsayshello Date: Sun, 31 Jul 2022 13:38:07 +0200 Subject: [PATCH] optimisations --- mods/ITEMS/mcl_beacons/init.lua | 112 +++++++++++------- .../textures/beacon_beam_palette.png | Bin 0 -> 613 bytes 2 files changed, 66 insertions(+), 46 deletions(-) create mode 100644 mods/ITEMS/mcl_beacons/textures/beacon_beam_palette.png diff --git a/mods/ITEMS/mcl_beacons/init.lua b/mods/ITEMS/mcl_beacons/init.lua index cb349839d..332c05215 100644 --- a/mods/ITEMS/mcl_beacons/init.lua +++ b/mods/ITEMS/mcl_beacons/init.lua @@ -9,66 +9,67 @@ 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) if string.match(glass_nodename, "cyan") then - return "mcl_beacons:beacon_beam_cdf4e9" + return 1 elseif string.match(glass_nodename,"white") then - return "mcl_beacons:beacon_beam_f9fcfb" + return 2 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 - return "mcl_beacons:beacon_beam_1826c9" + return 4 elseif string.match(glass_nodename,"light_blue") then - return "mcl_beacons:beacon_beam_16f4f4" + return 5 elseif string.match(glass_nodename,"pink") then - return "mcl_beacons:beacon_beam_f483fc" + return 6 elseif string.match(glass_nodename, "purple") then - return "mcl_beacons:beacon_beam_9712bc" + return 7 elseif string.match(glass_nodename, "red") then - return "mcl_beacons:beacon_beam_ea1212" + return 8 elseif string.match(glass_nodename, "silver") then - return "mcl_beacons:beacon_beam_adadad" + return 9 elseif string.match(glass_nodename, "gray") then - return "mcl_beacons:beacon_beam_535454" + return 10 elseif string.match(glass_nodename, "lime") then - return "mcl_beacons:beacon_beam_19e52a" + return 11 elseif string.match(glass_nodename, "green") then - return "mcl_beacons:beacon_beam_549159" + return 12 elseif string.match(glass_nodename, "orange") then - return "mcl_beacons:beacon_beam_ef8813" + return 13 elseif string.match(glass_nodename, "yellow") then - return "mcl_beacons:beacon_beam_ebf704" + return 14 elseif string.match(glass_nodename, "black") then - return "mcl_beacons:beacon_beam_000000" + return 15 elseif string.match(glass_nodename, "magenta") then - return "mcl_beacons:beacon_beam_e502d6" + return 16 else - return "mcl_beacons:beacon_beam_e8e3e3" + return 0 end end +minetest.register_node("mcl_beacons:beacon_beam", { + tiles = {"^[colorize:#b8bab9"}, + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = { + {-0.1250, -0.5000, -0.1250, 0.1250, 0.5000, 0.1250} + } + }, + pointable= false, + light_source = 15, + walkable = false, + groups = {not_in_creative_inventory=1}, + _mcl_blast_resistance = 1200, + paramtype2 = "color", + palette = "beacon_beam_palette.png", + palette_index = 0, + buildable_to = true, +}) - -for _, color in ipairs(color_list) do - minetest.register_node("mcl_beacons:beacon_beam_"..color, { - tiles = {"^[colorize:#"..color}, - drawtype = "nodebox", - node_box = { - type = "fixed", - fixed = { - {-0.1250, -0.5000, -0.1250, 0.1250, 0.5000, 0.1250} - } - }, - light_source = 15, - walkable = false, - groups = {not_in_creative_inventory=1}, - _mcl_blast_resistance = 1200, - }) - mesecon.register_mvps_stopper("mcl_beacons:beacon_beam_"..color) -end - +mesecon.register_mvps_stopper("mcl_beacons:beacon_beam") local formspec_string= "size[11,14]".. @@ -101,7 +102,7 @@ local formspec_string= "list[current_player;main;1,12.5;9,1;]" 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}) if node.name ~= "air" and node.name ~= "mcl_core:bedrock" and node.name ~= "mcl_core:void" 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}) 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}) end end @@ -159,11 +160,13 @@ local function globalstep_function(pos,player) if meta:get_int("effect_level") == 2 and power_level < 4 then return else + local colorblock = minetest.get_node({x=pos.x,y=pos.y+1,z=pos.z}) 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 - 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 not string.match(nodename,"mcl_beacons:beacon_beam_") then + 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 nodename ~="mcl_beacons:beacon_beam" then if minetest.get_item_group(nodename,"glass") == 0 then obstructed = true remove_beacon_beam(pos) @@ -270,9 +273,9 @@ minetest.register_node("mcl_beacons:beacon", { input:take_item() inv:set_stack("input",1,input) - local beam_itemstring = "mcl_beacons:beacon_beam_e8e3e3" + local beam_palette_index = 0 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}) 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}) @@ -282,12 +285,12 @@ minetest.register_node("mcl_beacons:beacon", { if y == pos.y+1 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 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 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) +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({ output = "mcl_beacons:beacon", recipe = { diff --git a/mods/ITEMS/mcl_beacons/textures/beacon_beam_palette.png b/mods/ITEMS/mcl_beacons/textures/beacon_beam_palette.png new file mode 100644 index 0000000000000000000000000000000000000000..099c85e4b67d7844562b1b9095bd8e1816a7aa52 GIT binary patch literal 613 zcmV-r0-F7aP)EX>4Tx04R}tkv&MmKpe$iQ>9WW4t5Yx%ut;yNELC^DionYs1;guFuC*#nlvOS zE{=k0!NHHks)LKOt`4q(Aou~|=;Wm6A|?JWEwqU7;J6>}?mh0_0YbgZG^=X@&~)2O zCE{WxyDA1=5x@w77)DHHmN6$uNqCO0d-(Wz7v)*r=l&eMYR+PSPb8jYhG`RT5KnK~ z2Iqa^Fe}O`@j3ChNf#u3x%kia6AAVGwJDoQBBMwC{a6bmWZk9+tBUB5&wg=bb;{@gF