Search in sources :

Example 1 with Vector3f

use of org.spongepowered.math.vector.Vector3f 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;
}
Also used : BlockParticleOption(net.minecraft.core.particles.BlockParticleOption) Color(org.spongepowered.api.util.Color) ParticleType(org.spongepowered.api.effect.particle.ParticleType) SimpleParticleType(net.minecraft.core.particles.SimpleParticleType) SimpleParticleType(net.minecraft.core.particles.SimpleParticleType) BlockState(org.spongepowered.api.block.BlockState) DustParticleOptions(net.minecraft.core.particles.DustParticleOptions) Vector3f(org.spongepowered.math.vector.Vector3f) ItemParticleOption(net.minecraft.core.particles.ItemParticleOption) ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot)

Aggregations

BlockParticleOption (net.minecraft.core.particles.BlockParticleOption)1 DustParticleOptions (net.minecraft.core.particles.DustParticleOptions)1 ItemParticleOption (net.minecraft.core.particles.ItemParticleOption)1 SimpleParticleType (net.minecraft.core.particles.SimpleParticleType)1 BlockState (org.spongepowered.api.block.BlockState)1 ParticleType (org.spongepowered.api.effect.particle.ParticleType)1 ItemStackSnapshot (org.spongepowered.api.item.inventory.ItemStackSnapshot)1 Color (org.spongepowered.api.util.Color)1 Vector3f (org.spongepowered.math.vector.Vector3f)1