Skip to content

Commit

Permalink
fix: adds the mod alpha_workaround
Browse files Browse the repository at this point in the history
This fixes some issues with the texture alpha property
that requires quite some changes in order to be properly fixed
in all sort of mods we currently have.

This gives us almost the same behavior of the previous API.
  • Loading branch information
ronoaldo committed Jan 15, 2025
1 parent 3baaa96 commit 1a6c27b
Show file tree
Hide file tree
Showing 7 changed files with 623 additions and 0 deletions.
41 changes: 41 additions & 0 deletions mods/alpha_workaround/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Compiled Lua sources
luac.out

# luarocks build files
*.src.rock
*.zip
*.tar.gz

# Object files
*.o
*.os
*.ko
*.obj
*.elf

# Precompiled Headers
*.gch
*.pch

# Libraries
*.lib
*.a
*.la
*.lo
*.def
*.exp

# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib

# Executables
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex

504 changes: 504 additions & 0 deletions mods/alpha_workaround/LICENSE

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions mods/alpha_workaround/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# `use_texture_alpha` workaround

This mod converts boolean `use_texture_alpha` values to string on the server, allowing MT5.9+ clients to join.
67 changes: 67 additions & 0 deletions mods/alpha_workaround/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
-- alpha_workaround/init.lua
-- Fix rendering issues on client 5.9 caused by boolean values of use_texture_alpha
--[[
Copyright (C) 2024 1F616EMO
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
]]

if not minetest.features.use_texture_alpha_string_modes then
error("[alpha_workaround] This version of Minetest Engine does not support string mode alpha.")
end

-- According to https://github.com/minetest/minetest/pull/10819
local value_map = {}

value_map.normal = { "clip", "opaque" }
value_map.other = { "blend", "clip" }
value_map.nodebox = { "blend", "opaque" }
value_map.mesh = value_map.nodebox

local defaults = {
normal = "opaque",
other = "clip",
nodebox = "clip", -- Adopting old client value
mesh = "clip",
liquid = "opaque",
flowingliquid = "opaque"
}

minetest.register_on_mods_loaded(function()
for name, def in pairs(minetest.registered_nodes) do
local alpha_type = type(def.use_texture_alpha)
if alpha_type ~= "string" then
local drawtype = def.drawtype or "normal"
local alpha

if alpha_type == "boolean" then
alpha = (value_map[drawtype] or value_map.other)[def.use_texture_alpha and 1 or 2]
minetest.log("warning", "[alpha_workaround] Node " .. name .. " is using boolean use_texture_alpha, " ..
"assuming use_texture_alpha = " .. alpha)
elseif (drawtype == "liquid" or drawtype == "flowingliquid") and def.alpha then
alpha = def.alpha == 255 and "opaque" or "blend"
minetest.log("warning", "[alpha_workaround] Node " .. name .. " is using the alpha field, " ..
"assuming use_texture_alpha = " .. alpha)
else
-- DAMN, we cannot detect texture transparency
-- So we apply defaults no matter what
alpha = defaults[drawtype] or defaults.other
end

minetest.override_item(name, {
use_texture_alpha = alpha
})
end
end
end)
7 changes: 7 additions & 0 deletions mods/alpha_workaround/mod.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name = alpha_workaround
title = use_texture_alpha workaround
description = Fix boolean use_texture_alpha on MT5.9+
min_minetest_version = 5.4
author = Emojiminetest
release = 23246

Binary file added mods/alpha_workaround/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions world.mt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ load_mod_3d_armor_ui = true
load_mod_abriglass = true
load_mod_accountmgr = true
load_mod_airutils = true
load_mod_alpha_workaround = true
load_mod_animalia = true
load_mod_anvil = true
load_mod_areas = true
Expand Down

0 comments on commit 1a6c27b

Please sign in to comment.