Search in sources :

Example 1 with SpongeFireworkEffectBuilder

use of org.spongepowered.common.item.SpongeFireworkEffectBuilder in project SpongeCommon by SpongePowered.

the class FireworkUtil method fromCompound.

public static FireworkEffect fromCompound(final CompoundTag compound) {
    final FireworkEffect.Builder builder = new SpongeFireworkEffectBuilder();
    if (compound.contains(Constants.Item.Fireworks.FLICKER)) {
        builder.flicker(compound.getBoolean(Constants.Item.Fireworks.FLICKER));
    }
    if (compound.contains(Constants.Item.Fireworks.TRAIL)) {
        builder.trail(compound.getBoolean(Constants.Item.Fireworks.TRAIL));
    }
    if (compound.contains(Constants.Item.Fireworks.SHAPE_TYPE)) {
        final byte type = compound.getByte(Constants.Item.Fireworks.SHAPE_TYPE);
        final MappedRegistry<FireworkShape> registry = (MappedRegistry<FireworkShape>) (Object) Sponge.game().registry(RegistryTypes.FIREWORK_SHAPE);
        @Nullable final FireworkShape shape = registry.byId(type);
        if (shape != null) {
            builder.shape(shape);
        }
    }
    if (compound.contains(Constants.Item.Fireworks.COLORS)) {
        final List<Color> colors = Lists.newArrayList();
        final int[] colorsRaw = compound.getIntArray(Constants.Item.Fireworks.COLORS);
        for (final int color : colorsRaw) {
            colors.add(Color.ofRgb(color));
        }
        builder.colors(colors);
    }
    if (compound.contains(Constants.Item.Fireworks.FADE_COLORS)) {
        final List<Color> fades = Lists.newArrayList();
        final int[] fadesRaw = compound.getIntArray(Constants.Item.Fireworks.FADE_COLORS);
        for (final int fade : fadesRaw) {
            fades.add(Color.ofRgb(fade));
        }
        builder.fades(fades);
    }
    return builder.build();
}
Also used : SpongeFireworkEffectBuilder(org.spongepowered.common.item.SpongeFireworkEffectBuilder) Color(org.spongepowered.api.util.Color) FireworkShape(org.spongepowered.api.item.FireworkShape) FireworkEffect(org.spongepowered.api.item.FireworkEffect) MappedRegistry(net.minecraft.core.MappedRegistry) Nullable(org.checkerframework.checker.nullness.qual.Nullable)

Example 2 with SpongeFireworkEffectBuilder

use of org.spongepowered.common.item.SpongeFireworkEffectBuilder in project SpongeCommon by SpongePowered.

the class ConfigurateDataViewTest method testFireworkEffectData.

@Test
void testFireworkEffectData() throws IOException {
    final Color color = Color.ofRgb(0x66, 0xCC, 0xFF);
    final FireworkEffect fe = new SpongeFireworkEffectBuilder().colors(color, color, color).build();
    final DataContainer container = fe.toContainer();
    final String s = ConfigurateDataViewTest.HOCON.write(container);
    final DataContainer dc = ConfigurateDataViewTest.HOCON.read(s);
    assertEquals(container, dc);
}
Also used : DataContainer(org.spongepowered.api.data.persistence.DataContainer) SpongeFireworkEffectBuilder(org.spongepowered.common.item.SpongeFireworkEffectBuilder) Color(org.spongepowered.api.util.Color) FireworkEffect(org.spongepowered.api.item.FireworkEffect) Test(org.junit.jupiter.api.Test)

Aggregations

FireworkEffect (org.spongepowered.api.item.FireworkEffect)2 Color (org.spongepowered.api.util.Color)2 SpongeFireworkEffectBuilder (org.spongepowered.common.item.SpongeFireworkEffectBuilder)2 MappedRegistry (net.minecraft.core.MappedRegistry)1 Nullable (org.checkerframework.checker.nullness.qual.Nullable)1 Test (org.junit.jupiter.api.Test)1 DataContainer (org.spongepowered.api.data.persistence.DataContainer)1 FireworkShape (org.spongepowered.api.item.FireworkShape)1