From 3126d067a1bfe7f4f98e391d596fd05948a0e6e4 Mon Sep 17 00:00:00 2001 From: Treer Date: Thu, 4 Jul 2019 23:58:37 +1000 Subject: [PATCH] Dynamic/hardware portal colouring Currently proof of concept: Removes wormhole colour from .png texture and specifies it through MT API instead. The post_effect_color may call for registering a separate node per portal colour. Palette 0 will have to be the traditional portal magenta (instead of 0 being black) for map compatibility with mod when colour was in the texture and not param2. --- init.lua | 29 ++++++++++++++++++++++------- textures/nether_particle.png | Bin 226 -> 149 bytes textures/nether_portal.png | Bin 382 -> 282 bytes textures/portal_palette.png | Bin 0 -> 875 bytes 4 files changed, 22 insertions(+), 7 deletions(-) create mode 100644 textures/portal_palette.png diff --git a/init.lua b/init.lua index 9b42c2b..be5542a 100644 --- a/init.lua +++ b/init.lua @@ -22,10 +22,10 @@ -- Parameters +local DEBUG = false local NETHER_DEPTH = -5000 local TCAVE = 0.6 local BLEND = 128 -local DEBUG = false -- 3D noise @@ -284,11 +284,25 @@ local function get_timerPos_from_p1_and_p2(p1, p2) end -- orientation is the rotation degrees passed to place_schematic: 0, 90, 180, or 270 -local function get_param2_from_orientation(param2, orientation) - return orientation / 90 +-- color is a value from 0 to 7 corresponding to the pixels in portal_palette.png +local function get_param2_from_color_and_orientation(color, orientation) + assert(orientation, "no orientation passed") + + -- wormhole nodes have a paramtype2 of colorfacedir, which means the + -- high 3 bits are palette, followed by 3 direction bits and 2 rotation bits. + -- We set the palette bits and rotation + return (orientation / 90) + color * 32 end local function get_orientation_from_param2(param2) + -- Strip off the top 6 bits, unfortunately MT lua has no bitwise '&' + -- (high 3 bits are palette, followed by 3 direction bits then 2 rotation bits) + if param2 >= 128 then param2 = param2 - 128 end + if param2 >= 64 then param2 = param2 - 64 end + if param2 >= 32 then param2 = param2 - 32 end + if param2 >= 16 then param2 = param2 - 16 end + if param2 >= 8 then param2 = param2 - 8 end + return param2 * 90 end @@ -336,7 +350,7 @@ local function set_portal_metadata(portal_definition, anchorPos, orientation, de -- they define the bounding volume for the portal. local p1, p2 = portal_definition.shape:get_p1_and_p2_from_anchorPos(anchorPos, orientation) local p1_string, p2_string = minetest.pos_to_string(p1), minetest.pos_to_string(p2) - local param2 = get_param2_from_orientation(0, orientation) + local param2 = get_param2_from_color_and_orientation(portal_definition.wormhole_node_color, orientation) local update_aborted-- using closures to allow the updateFunc to return extra information - by setting this variable @@ -863,7 +877,7 @@ function run_wormhole(pos, time_elapsed) minsize = 0.5, maxsize = 1.5, collisiondetection = false, - texture = "nether_particle.png", + texture = "nether_particle.png^[colorize:#808:alpha", glow = 5 }) end @@ -975,7 +989,9 @@ minetest.register_node("nether:portal", { }, drawtype = "nodebox", paramtype = "light", - paramtype2 = "facedir", + paramtype2 = "colorfacedir", + palette = "portal_palette.png", + post_effect_color = {a = 180, r = 128, g = 0, b = 128}, sunlight_propagates = true, use_texture_alpha = true, walkable = false, @@ -985,7 +1001,6 @@ minetest.register_node("nether:portal", { is_ground_content = false, drop = "", light_source = 5, - post_effect_color = {a = 180, r = 128, g = 0, b = 128}, alpha = 192, node_box = { type = "fixed", diff --git a/textures/nether_particle.png b/textures/nether_particle.png index 56a5b78c42392a3cac53daffe6ace26f490de837..61713051eff87d77d1d88a00c70592755fbf997f 100644 GIT binary patch delta 131 zcmaFFIF)gNWDN@g14ABL8IWY)EbxddW?jF zz9{Z;P~+vz`j-3Y6Fo|nafm#4_GGf^_8)2W5f4(FHDzOU9nJ5#dM~t&Ve^}K%4eyO fa*F0^x8L{grJPjw_OGn`8pt9~S3j3^P6&6h2cL4F4((#@76+HF_h50n6MiVCj9K2RQ1I5_n7rm@pUvlj7@1cENIEqfPIubVW>WS{ctu{9 n=re`OIjOTNsskimJm}XusVVcnZrPGVpgjzpu6{1-oD!M}Fs;z4TtlGN!v<~?}?;0h`2R-(8KRE7?%m4rY07*qoM6N<$f{T5a=>Px# diff --git a/textures/portal_palette.png b/textures/portal_palette.png new file mode 100644 index 0000000000000000000000000000000000000000..8cc6f305f2c6363278863fbe9ec1124787e12943 GIT binary patch literal 875 zcmeAS@N?(olHy`uVBq!ia0vp^96-#-!3-p?+>