From 55ded7e5698589ef4bc8d9f7080b5833106c3911 Mon Sep 17 00:00:00 2001 From: Jude Melton-Houghton Date: Wed, 11 May 2022 18:41:28 -0400 Subject: [PATCH] Make tubes opaque when entities are not used (#29) * Make tubes opaque when entities are not used --- decorative_tubes.lua | 13 +++++++------ init.lua | 23 +++++++++++++++++++++++ routing_tubes.lua | 8 ++++++-- settingtypes.txt | 1 + tube_registration.lua | 4 ++++ 5 files changed, 41 insertions(+), 8 deletions(-) diff --git a/decorative_tubes.lua b/decorative_tubes.lua index d79f8af..910ea91 100644 --- a/decorative_tubes.lua +++ b/decorative_tubes.lua @@ -49,12 +49,13 @@ minetest.register_node("pipeworks:steel_pane_embedded_tube", { drawtype = "nodebox", description = S("Airtight panel embedded tube"), tiles = { - "pipeworks_pane_embedded_tube_sides.png^[transformR90", - "pipeworks_pane_embedded_tube_sides.png^[transformR90", - "pipeworks_pane_embedded_tube_sides.png", - "pipeworks_pane_embedded_tube_sides.png", - "pipeworks_pane_embedded_tube_ends.png", "pipeworks_pane_embedded_tube_ends.png", - }, + pipeworks.make_tube_tile("pipeworks_pane_embedded_tube_sides.png^[transformR90"), + pipeworks.make_tube_tile("pipeworks_pane_embedded_tube_sides.png^[transformR90"), + pipeworks.make_tube_tile("pipeworks_pane_embedded_tube_sides.png"), + pipeworks.make_tube_tile("pipeworks_pane_embedded_tube_sides.png"), + pipeworks.make_tube_tile("pipeworks_pane_embedded_tube_ends.png"), + pipeworks.make_tube_tile("pipeworks_pane_embedded_tube_ends.png"), + }, use_texture_alpha = texture_alpha_mode, node_box = pane_box, selection_box = pane_box, diff --git a/init.lua b/init.lua index 8fb0b31..65de26a 100644 --- a/init.lua +++ b/init.lua @@ -69,6 +69,29 @@ function pipeworks.fix_image_names(table, replacement) return outtable end +local function overlay_tube_texture(texture) + -- The texture appears the first time to be colorized as the opaque background. + return ("(%s)^[noalpha^[colorize:#dadada^(%s)"):format(texture, texture) +end + +function pipeworks.make_tube_tile(tile) + if pipeworks.use_real_entities then + return tile + elseif type(tile) == "string" then + return overlay_tube_texture(tile) + else + tile = table.copy(tile) + if tile.color then + -- Won't work 100% of the time, but good enough. + tile.name = tile.name .. "^[multiply:" .. minetest.colorspec_to_colorstring(tile.color) + tile.color = nil + end + tile.name = overlay_tube_texture(tile.name) + tile.backface_culling = nil -- The texture is opaque + return tile + end +end + function pipeworks.add_node_box(t, b) if not t or not b then return end for i in ipairs(b) diff --git a/routing_tubes.lua b/routing_tubes.lua index 5e5fe0a..5fc1d82 100644 --- a/routing_tubes.lua +++ b/routing_tubes.lua @@ -143,10 +143,14 @@ local texture_alpha_mode = minetest.features.use_texture_alpha_string_modes and "clip" or true if pipeworks.enable_one_way_tube then + local tiles = {"pipeworks_one_way_tube_top.png", "pipeworks_one_way_tube_top.png", "pipeworks_one_way_tube_output.png", + "pipeworks_one_way_tube_input.png", "pipeworks_one_way_tube_side.png", "pipeworks_one_way_tube_top.png"} + for i, tile in ipairs(tiles) do + tiles[i] = pipeworks.make_tube_tile(tile) + end minetest.register_node("pipeworks:one_way_tube", { description = S("One way tube"), - tiles = {"pipeworks_one_way_tube_top.png", "pipeworks_one_way_tube_top.png", "pipeworks_one_way_tube_output.png", - "pipeworks_one_way_tube_input.png", "pipeworks_one_way_tube_side.png", "pipeworks_one_way_tube_top.png"}, + tiles = tiles, use_texture_alpha = texture_alpha_mode, paramtype2 = "facedir", drawtype = "nodebox", diff --git a/settingtypes.txt b/settingtypes.txt index bfe7735..3a6cbf4 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -77,4 +77,5 @@ pipeworks_drop_on_routing_fail (Drop On Routing Fail) bool false pipeworks_delete_item_on_clearobject (Delete Item On Clearobject) bool true #Use real visible entities in tubes within active areas. +#When disabled, tubes are made opaque. pipeworks_use_real_entities (Use real entities) bool true diff --git a/tube_registration.lua b/tube_registration.lua index c621cd8..edb9f5e 100644 --- a/tube_registration.lua +++ b/tube_registration.lua @@ -80,6 +80,10 @@ local register_one_tube = function(name, tname, dropname, desc, plain, noctrs, e wscale = {x = 1, y = 1, z = 0.01} end + for i, tile in ipairs(outimgs) do + outimgs[i] = pipeworks.make_tube_tile(tile) + end + local rname = string.format("%s_%s", name, tname) table.insert(tubenodes, rname)