fix painting variants (#2490)

* fix: painting variants are now ordered and sent to the client correctly

* fix: use equals() to compare Strings

Co-authored-by: mudkip <mudkip@mudkip.dev>

* chore: add comment explaining painting variant check

* chore: improve explanation for painting variant exception

Proper support for "holder" types like this one should be added later.

---------

Co-authored-by: mudkip <mudkip@mudkip.dev>
This commit is contained in:
surv 2024-11-30 15:17:57 -05:00 committed by GitHub
parent f67112a584
commit afa8f4e96a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 2 deletions

View File

@ -18,6 +18,7 @@ import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Comparator;
public class PaintingMeta extends EntityMeta implements ObjectDataProvider {
public static final byte OFFSET = EntityMeta.MAX_OFFSET;
@ -104,7 +105,8 @@ public class PaintingMeta extends EntityMeta implements ObjectDataProvider {
static @NotNull DynamicRegistry<Variant> createDefaultRegistry() {
return DynamicRegistry.create(
"minecraft:painting_variant", VariantImpl.REGISTRY_NBT_TYPE, Registry.Resource.PAINTING_VARIANTS,
(namespace, props) -> new VariantImpl(Registry.paintingVariant(namespace, props))
(namespace, props) -> new VariantImpl(Registry.paintingVariant(namespace, props)),
Comparator.naturalOrder()
);
}

View File

@ -631,7 +631,9 @@ interface NetworkBufferTypeImpl<T> extends NetworkBuffer.Type<T> {
public void write(@NotNull NetworkBuffer buffer, DynamicRegistry.Key<T> value) {
Check.stateCondition(buffer.registries == null, "Buffer does not have registries");
final DynamicRegistry<T> registry = selector.apply(buffer.registries);
final int id = registry.getId(value);
// Painting variants may be sent in their entirety rather than a registry reference so the ID is offset by 1 to indicate this.
// FIXME: Support sending the entire registry object instead of an ID reference.
final int id = registry.id().equals("minecraft:painting_variant")?registry.getId(value)+1:registry.getId(value);
Check.argCondition(id == -1, "Key is not registered: {0} > {1}", registry, value);
buffer.write(VAR_INT, id);
}