Java 类net.minecraft.client.particle.ParticleBlockDust 实例源码

项目:MobTotems    文件:CarvingKnife.java   
@SideOnly(Side.CLIENT)
private void spawnParticles(ItemStack stack, World world, EntityPlayer player) {
    long worldTime = world.getWorldTime();

    if (spawnParticles) {
        IParticleFactory particleFactory = new ParticleBlockDust.Factory();

        Vec3d posEyes = player.getPositionEyes(1.0f);
        RayTraceResult rayTraceResult = world.rayTraceBlocks(posEyes, posEyes.add(player.getLookVec().scale(3f)));

        if (rayTraceResult != null) {
            BlockPos pos = rayTraceResult.getBlockPos();
            Block targetBlock = BlockUtils.getBlock(world, pos);

            if (targetBlock != null
                    && targetBlock instanceof TotemWoodBlock) {
                IBlockState state = world.getBlockState(pos);
                int i = 4;

                for (int j = 0; j < 4; ++j) {
                    for (int k = 0; k < 4; ++k) {
                        for (int l = 0; l < 4; ++l) {
                            double d0 = ((double) j + 0.5D) / 4.0D;
                            double d1 = ((double) k + 0.5D) / 4.0D;
                            double d2 = ((double) l + 0.5D) / 4.0D;

                            double speedX = d0 - 0.5D;
                            double speedY = d1 - 0.5D;
                            double speedZ = d2 - 0.5D;
                            speedX *= 0.2;
                            speedY *= 0.2;
                            speedZ *= 0.2;
                            Minecraft.getMinecraft().effectRenderer.addEffect(
                                    particleFactory.createParticle(EnumParticleTypes.BLOCK_DUST.getParticleID(),
                                            world,
                                            (double) pos.getX() + d0,
                                            (double) pos.getY() + d1,
                                            (double) pos.getZ() + d2,
                                            speedX,
                                            speedY,
                                            speedZ,
                                            new int[]{Block.getStateId(state)}));
                        }
                    }
                }
            }
        }
        spawnParticles = false;
    }
}