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

net.minestom.server.item.component.ArmorTrim Maven / Gradle / Ivy

There is a newer version: 7320437640
Show newest version
package net.minestom.server.item.component;

import net.kyori.adventure.nbt.CompoundBinaryTag;
import net.minestom.server.item.armor.TrimMaterial;
import net.minestom.server.item.armor.TrimPattern;
import net.minestom.server.network.NetworkBuffer;
import net.minestom.server.network.NetworkBufferTemplate;
import net.minestom.server.registry.DynamicRegistry;
import net.minestom.server.utils.nbt.BinaryTagSerializer;
import org.jetbrains.annotations.NotNull;

public record ArmorTrim(@NotNull DynamicRegistry.Key material,
                        @NotNull DynamicRegistry.Key pattern, boolean showInTooltip) {

    public static final NetworkBuffer.Type NETWORK_TYPE = NetworkBufferTemplate.template(
            TrimMaterial.NETWORK_TYPE, ArmorTrim::material,
            TrimPattern.NETWORK_TYPE, ArmorTrim::pattern,
            NetworkBuffer.BOOLEAN, ArmorTrim::showInTooltip,
            ArmorTrim::new
    );

    public static final BinaryTagSerializer NBT_TYPE = BinaryTagSerializer.COMPOUND.map(
            tag -> {
                DynamicRegistry.Key material = TrimMaterial.NBT_TYPE.read(tag.get("material"));
                DynamicRegistry.Key pattern = TrimPattern.NBT_TYPE.read(tag.get("pattern"));
                boolean showInTooltip = tag.getBoolean("show_in_tooltip", true);
                return new ArmorTrim(material, pattern, showInTooltip);
            },
            value -> CompoundBinaryTag.builder()
                    .put("material", TrimMaterial.NBT_TYPE.write(value.material))
                    .putString("pattern", value.pattern.name())
                    .putBoolean("show_in_tooltip", value.showInTooltip)
                    .build()
    );

    public @NotNull ArmorTrim withTooltip(boolean showInTooltip) {
        return new ArmorTrim(material, pattern, showInTooltip);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy