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

net.minestom.server.item.component.Unbreakable 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.network.NetworkBuffer;
import net.minestom.server.utils.nbt.BinaryTagSerializer;
import org.jetbrains.annotations.NotNull;

public record Unbreakable(boolean showInTooltip) {
    public static final Unbreakable DEFAULT = new Unbreakable();

    public static final NetworkBuffer.Type NETWORK_TYPE = new NetworkBuffer.Type() {
        @Override
        public void write(@NotNull NetworkBuffer buffer, Unbreakable value) {
            buffer.write(NetworkBuffer.BOOLEAN, value.showInTooltip());
        }

        @Override
        public Unbreakable read(@NotNull NetworkBuffer buffer) {
            return new Unbreakable(buffer.read(NetworkBuffer.BOOLEAN));
        }
    };

    public Unbreakable() {
        this(true);
    }

    public static final BinaryTagSerializer NBT_TYPE = BinaryTagSerializer.COMPOUND.map(
            tag -> new Unbreakable(tag.getBoolean("showInTooltip", true)),
            unbreakable -> CompoundBinaryTag.builder().putBoolean("showInTooltip", unbreakable.showInTooltip()).build()
    );

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy