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

net.minestom.server.item.metadata.FireworkMeta Maven / Gradle / Ivy

package net.minestom.server.item.metadata;

import net.minestom.server.item.ItemMetaView;
import net.minestom.server.item.firework.FireworkEffect;
import net.minestom.server.tag.Tag;
import net.minestom.server.tag.TagHandler;
import net.minestom.server.tag.TagReadable;
import net.minestom.server.tag.TagSerializer;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.UnknownNullability;

import java.util.List;

public record FireworkMeta(TagReadable readable) implements ItemMetaView {
    private static final Tag> EFFECTS = Tag.Structure("Explosions",
                    TagSerializer.fromCompound(FireworkEffect::fromCompound, FireworkEffect::asCompound))
            .path("Fireworks").list().defaultValue(List.of());
    private static final Tag FLIGHT_DURATION = Tag.Byte("Flight").path("Fireworks");

    public @NotNull List getEffects() {
        return getTag(EFFECTS);
    }

    public @Nullable Byte getFlightDuration() {
        return getTag(FLIGHT_DURATION);
    }

    @Override
    public  @UnknownNullability T getTag(@NotNull Tag tag) {
        return readable.getTag(tag);
    }

    public record Builder(TagHandler tagHandler) implements ItemMetaView.Builder {
        public Builder() {
            this(TagHandler.newHandler());
        }

        public Builder effects(List effects) {
            setTag(EFFECTS, effects);
            return this;
        }

        public Builder flightDuration(byte flightDuration) {
            setTag(FLIGHT_DURATION, flightDuration);
            return this;
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy