All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.minestom.server.instance.block.banner.BannerPatternImpl Maven / Gradle / Ivy

There is a newer version: 7320437640
Show newest version
package net.minestom.server.instance.block.banner;

import net.kyori.adventure.nbt.CompoundBinaryTag;
import net.minestom.server.registry.Registry;
import net.minestom.server.utils.NamespaceID;
import net.minestom.server.utils.nbt.BinaryTagSerializer;
import net.minestom.server.utils.validate.Check;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

record BannerPatternImpl(
        @NotNull NamespaceID assetId,
        @NotNull String translationKey,
        @Nullable Registry.BannerPatternEntry registry
) implements BannerPattern {

    static final BinaryTagSerializer REGISTRY_NBT_TYPE = BinaryTagSerializer.COMPOUND.map(
            tag -> {
                throw new UnsupportedOperationException("BannerPattern is read-only");
            },
            bannerPattern -> CompoundBinaryTag.builder()
                    .putString("asset_id", bannerPattern.assetId().asString())
                    .putString("translation_key", bannerPattern.translationKey())
                    .build()
    );

    @SuppressWarnings("ConstantValue") // The builder can violate the nullability constraints
    BannerPatternImpl {
        Check.argCondition(assetId == null, "missing asset id");
        Check.argCondition(translationKey == null || translationKey.isEmpty(), "missing translation key");
    }

    BannerPatternImpl(@NotNull Registry.BannerPatternEntry registry) {
        this(registry.assetId(), registry.translationKey(), registry);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy