]> git.lizzy.rs Git - dragonfireclient.git/commitdiff
Fix some textures not being sent correctly to older clients
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Sat, 23 Apr 2022 16:04:38 +0000 (18:04 +0200)
committersfan5 <sfan5@live.de>
Sun, 24 Apr 2022 19:10:23 +0000 (21:10 +0200)
Since b2eb44afc50976dc0954c868977b5829f3ff8a19, a texture defined as
`[combine:16x512:0,0=some_file.png;etc`
will not be sent correctly from a 5.5 server to a 5.4 client due to the
overeager detection of unsupported base modifier `[` introducing a
spurious `blank.png^` before the modifier.

Fix this by whitelisting which base modifiers can be passed through
unchanged to the client, and prefix `blank.png` for the others
(which at the moment is just [png:, but the list may grow larger
as new base modifiers are added.)

src/nodedef.cpp

index c4a4f4461d1c1c2f284a9d73d2f9162a848a3fd6..8d63870b3c368b5fe87baa950396deadd070a872 100644 (file)
@@ -33,6 +33,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "nameidmapping.h"
 #include "util/numeric.h"
 #include "util/serialize.h"
+#include "util/string.h"
 #include "exceptions.h"
 #include "debug.h"
 #include "gamedef.h"
@@ -213,10 +214,21 @@ void TileDef::serialize(std::ostream &os, u16 protocol_version) const
                // Before f018737, TextureSource::getTextureAverageColor did not handle
                // missing textures. "[png" can be used as base texture, but is not known
                // on older clients. Hence use "blank.png" to avoid this problem.
-               if (!name.empty() && name[0] == '[')
-                       os << serializeString16("blank.png^" + name);
-               else
+               // To be forward-compatible with future base textures/modifiers,
+               // we apply the same prefix to any texture beginning with [,
+               // except for the ones that are supported on older clients.
+               bool pass_through = true;
+
+               if (!name.empty() && name[0] == '[') {
+                       pass_through = str_starts_with(name, "[combine:") ||
+                               str_starts_with(name, "[inventorycube{") ||
+                               str_starts_with(name, "[lowpart:");
+               }
+
+               if (pass_through)
                        os << serializeString16(name);
+               else
+                       os << serializeString16("blank.png^" + name);
        }
        animation.serialize(os, version);
        bool has_scale = scale > 0;