use of org.spongepowered.common.util.FireworkUtil in project SpongeCommon by SpongePowered.
the class FireworkRocketData method register.
// @formatter:off
public static void register(final DataProviderRegistrator registrator) {
registrator.asMutable(FireworkRocketEntity.class).create(Keys.FIREWORK_EFFECTS).get(h -> FireworkUtil.getFireworkEffects(h).orElse(null)).set(FireworkUtil::setFireworkEffects).resetOnDelete(ImmutableList.of()).create(Keys.FIREWORK_FLIGHT_MODIFIER).get(h -> {
final ItemStack item = FireworkUtil.getItem(h);
final CompoundTag fireworks = item.getOrCreateTagElement(Constants.Item.Fireworks.FIREWORKS);
if (fireworks.contains(Constants.Item.Fireworks.FLIGHT)) {
return new SpongeTicks(fireworks.getByte(Constants.Item.Fireworks.FLIGHT));
}
return null;
}).setAnd((h, v) -> {
final int ticks = (int) v.ticks();
if (ticks < 0 || ticks > Byte.MAX_VALUE) {
return false;
}
final ItemStack item = FireworkUtil.getItem(h);
final CompoundTag fireworks = item.getOrCreateTagElement(Constants.Item.Fireworks.FIREWORKS);
fireworks.putByte(Constants.Item.Fireworks.FLIGHT, (byte) ticks);
((FireworkRocketEntityAccessor) h).accessor$lifetime(10 * ticks + ((EntityAccessor) h).accessor$random().nextInt(6) + ((EntityAccessor) h).accessor$random().nextInt(7));
return true;
});
}
Aggregations