mirror of
https://github.com/Minestom/Minestom.git
synced 2025-02-14 03:11:25 +01:00
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:
parent
f67112a584
commit
afa8f4e96a
@ -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()
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user