use of net.minecraft.core.particles.ItemParticleOption in project SpongeCommon by SpongePowered.
the class SpongeParticleHelper method getNamedPacket.
@SuppressWarnings({ "unchecked", "ConstantConditions" })
private static CachedParticlePacket getNamedPacket(final ParticleEffect effect, final net.minecraft.core.particles.ParticleType<?> internalType) {
// Named particles always support OFFSET and QUANTITY.
final Vector3f offset = effect.optionOrDefault(ParticleOptions.OFFSET).get().toFloat();
final int quantity = effect.optionOrDefault(ParticleOptions.QUANTITY).get();
final Vector3f velocity = effect.optionOrDefault(ParticleOptions.VELOCITY).orElse(Vector3d.ZERO).toFloat();
if (internalType instanceof SimpleParticleType) {
// Simple named particle without any additional supported options.
return new NamedCachedPacket((net.minecraft.core.particles.ParticleOptions) internalType, offset, quantity, velocity);
}
// If only mojang had some type akin to our ParticleEffect...
if (internalType.getDeserializer() == BlockParticleOption.DESERIALIZER) {
// This particle type supports a block state option.
final BlockState state = effect.optionOrDefault(ParticleOptions.BLOCK_STATE).get();
final BlockParticleOption particleData = new BlockParticleOption((net.minecraft.core.particles.ParticleType<BlockParticleOption>) internalType, (net.minecraft.world.level.block.state.BlockState) state);
return new NamedCachedPacket(particleData, offset, quantity, velocity);
} else if (internalType.getDeserializer() == ItemParticleOption.DESERIALIZER) {
// This particle type supports an item option.
final ItemStackSnapshot snapshot = effect.optionOrDefault(ParticleOptions.ITEM_STACK_SNAPSHOT).get();
final ItemParticleOption particleData = new ItemParticleOption((net.minecraft.core.particles.ParticleType<ItemParticleOption>) internalType, (net.minecraft.world.item.ItemStack) (Object) snapshot.createStack());
return new NamedCachedPacket(particleData, offset, quantity, velocity);
} else if (internalType.getDeserializer() == DustParticleOptions.DESERIALIZER) {
// This particle type supports a color option.
final Color color = effect.optionOrDefault(ParticleOptions.COLOR).get();
final double scale = effect.optionOrDefault(ParticleOptions.SCALE).get();
final DustParticleOptions particleData = new DustParticleOptions((float) color.red() / 255, (float) color.green() / 255, (float) color.blue() / 255, (float) scale);
return new NamedCachedPacket(particleData, offset, quantity, velocity);
}
// Otherwise, we don't really know how to get a valid IParticleData. Sorry mods!
return EmptyCachedPacket.INSTANCE;
}
Aggregations