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();
}
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);
}
Aggregations