net.minecraft.client.particle.ParticleManager Java Examples

The following examples show how to use net.minecraft.client.particle.ParticleManager. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ParticleHandlerUtil.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static void addBlockLandingEffects(World worldObj, Vector3 entityPos, TextureAtlasSprite atlasSprite, int spriteColor, ParticleManager manager, int numParticles) {
    Vector3 start = entityPos.copy();
    Vector3 end = start.copy().add(Vector3.down.copy().multiply(4));
    RayTraceResult traceResult = worldObj.rayTraceBlocks(start.vec3(), end.vec3(), true, false, true);
    double speed = 0.15;
    Random randy = new Random();

    float red = (spriteColor >> 16 & 255) / 255.0F;
    float green = (spriteColor >> 8 & 255) / 255.0F;
    float blue = (spriteColor & 255) / 255.0F;

    if (traceResult != null && traceResult.typeOfHit == Type.BLOCK && numParticles != 0) {
        for (int i = 0; i < numParticles; i++) {
            double mX = randy.nextGaussian() * speed;
            double mY = randy.nextGaussian() * speed;
            double mZ = randy.nextGaussian() * speed;
            DigIconParticle digIconParticle = DigIconParticle.newLandingParticle(worldObj, entityPos.x, entityPos.y, entityPos.z, mX, mY, mZ, atlasSprite);
            digIconParticle.setRBGColorF(red, green, blue);
            manager.addEffect(digIconParticle);
        }
    }
}
 
Example #2
Source File: CustomParticleHandler.java    From CodeChickenLib with GNU Lesser General Public License v2.1 6 votes vote down vote up
@OnlyIn (Dist.CLIENT)
public static boolean handleRunningEffects(World world, BlockPos pos, BlockState state, Entity entity) {
    //Spoof a raytrace from the feet.
    BlockRayTraceResult traceResult = new BlockRayTraceResult(entity.getPositionVec().add(0, 1, 0), Direction.UP, pos, false);
    BlockModelShapes modelShapes = Minecraft.getInstance().getBlockRendererDispatcher().getBlockModelShapes();
    IBakedModel model = modelShapes.getModel(state);
    if (model instanceof IModelParticleProvider) {
        IModelData modelData = ModelDataManager.getModelData(world, pos);
        ParticleManager particleManager = Minecraft.getInstance().particles;
        List<TextureAtlasSprite> sprites = new ArrayList<>(((IModelParticleProvider) model).getHitEffects(traceResult, state, world, pos, modelData));
        TextureAtlasSprite rolledSprite = sprites.get(world.rand.nextInt(sprites.size()));
        double x = entity.getPosX() + (world.rand.nextFloat() - 0.5D) * entity.getWidth();
        double y = entity.getBoundingBox().minY + 0.1D;
        double z = entity.getPosZ() + (world.rand.nextFloat() - 0.5D) * entity.getWidth();
        particleManager.addEffect(new CustomBreakingParticle(world, x, y, z, -entity.getMotion().x * 4.0D, 1.5D, -entity.getMotion().z * 4.0D, rolledSprite));
        return true;
    }

    return false;
}
 
Example #3
Source File: GTTileEnergyTransmitter.java    From GT-Classic with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
@SideOnly(Side.CLIENT)
public void randomTickDisplay(IBlockState stateIn, World worldIn, BlockPos pos, Random rand) {
	if (this.isActive) {
		for (int k = 6; k > 0; --k) {
			ParticleManager er = Minecraft.getMinecraft().effectRenderer;
			float multPos = (float) (.1 * 2) + 0.9F;
			double x = (double) ((float) pos.getX() + 0.05F + rand.nextFloat() * multPos);
			double y = (double) ((float) pos.getY() + 1.0F + rand.nextFloat() * 0.2F);
			double z = (double) ((float) pos.getZ() + 0.05F + rand.nextFloat() * multPos);
			double[] velocity = new double[] { 0.0D, 7.6D, 0.0D };
			if (k < 4) {
				velocity[2] *= 0.55D;
			}
			float[] colour = new float[] { 0.0F, .5F + rand.nextFloat() * .5F, 1.0F };
			er.addEffect(new EntityChargePadAuraFX(this.world, x, y, z, 8, velocity, colour, false));
		}
	}
}
 
Example #4
Source File: NetworkHandler.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
@SideOnly(Side.CLIENT)
private static void initClient() {
    registerClientExecutor(PacketUIOpen.class, (packet, handler) -> {
        UIFactory<?> uiFactory = UIFactory.FACTORY_REGISTRY.getObjectById(packet.uiFactoryId);
        if (uiFactory == null) {
            GTLog.logger.warn("Couldn't find UI Factory with id '{}'", packet.uiFactoryId);
        } else {
            uiFactory.initClientUI(packet.serializedHolder, packet.windowId, packet.initialWidgetUpdates);
        }
    });
    registerClientExecutor(PacketUIWidgetUpdate.class, (packet, handler) -> {
        GuiScreen currentScreen = Minecraft.getMinecraft().currentScreen;
        if(currentScreen instanceof ModularUIGui) {
            ((ModularUIGui) currentScreen).handleWidgetUpdate(packet);
        }
    });

    registerClientExecutor(PacketBlockParticle.class, (packet, handler) -> {
        World world = Minecraft.getMinecraft().world;
        IBlockState blockState = world.getBlockState(packet.blockPos);
        ParticleManager particleManager = Minecraft.getMinecraft().effectRenderer;
        ((ICustomParticleBlock) blockState.getBlock()).handleCustomParticle(world, packet.blockPos, particleManager, packet.entityPos, packet.particlesAmount);
    });
}
 
Example #5
Source File: CustomParticleHandler.java    From CodeChickenLib with GNU Lesser General Public License v2.1 6 votes vote down vote up
@OnlyIn (Dist.CLIENT)
public static void addLandingEffects(World world, BlockPos pos, BlockState state, Vector3 entityPos, int numParticles) {
    //Spoof a raytrace from the feet.
    BlockRayTraceResult traceResult = new BlockRayTraceResult(new Vec3d(entityPos.x, pos.getY() + 1, entityPos.z), Direction.UP, pos, false);
    ParticleManager manager = Minecraft.getInstance().particles;
    Random randy = new Random();
    BlockModelShapes modelShapes = Minecraft.getInstance().getBlockRendererDispatcher().getBlockModelShapes();
    IBakedModel model = modelShapes.getModel(state);
    if (model instanceof IModelParticleProvider) {
        IModelData modelData = ModelDataManager.getModelData(world, pos);
        List<TextureAtlasSprite> sprites = new ArrayList<>(((IModelParticleProvider) model).getHitEffects(traceResult, state, world, pos, modelData));

        double speed = 0.15000000596046448D;
        if (numParticles != 0) {
            for (int i = 0; i < numParticles; i++) {
                double mX = randy.nextGaussian() * speed;
                double mY = randy.nextGaussian() * speed;
                double mZ = randy.nextGaussian() * speed;
                manager.addEffect(CustomBreakingParticle.newLandingParticle(world, entityPos.x, entityPos.y, entityPos.z, mX, mY, mZ, sprites.get(randy.nextInt(sprites.size()))));
            }
        }
    }
}
 
Example #6
Source File: BlockCustomParticle.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
@SideOnly(Side.CLIENT)
public boolean addHitEffects(IBlockState state, World worldObj, RayTraceResult target, ParticleManager manager) {
    Pair<TextureAtlasSprite, Integer> atlasSprite = getParticleTexture(worldObj, target.getBlockPos());
    ParticleHandlerUtil.addHitEffects(state, worldObj, target, atlasSprite.getLeft(), atlasSprite.getRight(), manager);
    return true;
}
 
Example #7
Source File: BlockCustomParticle.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
@SideOnly(Side.CLIENT)
public boolean addDestroyEffects(World world, BlockPos pos, ParticleManager manager) {
    Pair<TextureAtlasSprite, Integer> atlasSprite = getParticleTexture(world, pos);
    ParticleHandlerUtil.addBlockDestroyEffects(world.getBlockState(pos), world, pos, atlasSprite.getLeft(), atlasSprite.getRight(), manager);
    return true;
}
 
Example #8
Source File: ParticleHandlerUtil.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void addBlockRunningEffects(World worldObj, Entity entity, TextureAtlasSprite atlasSprite, int spriteColor) {
    Random rand = new Random();
    double posX = entity.posX + (rand.nextFloat() - 0.5) * entity.width;
    double posY = entity.getEntityBoundingBox().minY + 0.1;
    double posZ = entity.posZ + (rand.nextFloat() - 0.5) * entity.width;
    ParticleManager manager = Minecraft.getMinecraft().effectRenderer;

    float red = (spriteColor >> 16 & 255) / 255.0F;
    float green = (spriteColor >> 8 & 255) / 255.0F;
    float blue = (spriteColor & 255) / 255.0F;

    DigIconParticle digIconParticle = new DigIconParticle(worldObj, posX, posY, posZ, -entity.motionX * 4.0, 1.5, -entity.motionZ * 4.0, atlasSprite);
    digIconParticle.setRBGColorF(red, green, blue);
    manager.addEffect(digIconParticle);
}
 
Example #9
Source File: CustomParticleHandler.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
@OnlyIn (Dist.CLIENT)
public static void addBlockHitEffects(World world, Cuboid6 bounds, Direction side, TextureAtlasSprite icon, ParticleManager particleManager) {
    float border = 0.1F;
    Vector3 diff = bounds.max.copy().subtract(bounds.min).add(-2 * border);
    diff.x *= world.rand.nextDouble();
    diff.y *= world.rand.nextDouble();
    diff.z *= world.rand.nextDouble();
    Vector3 pos = diff.add(bounds.min).add(border);

    if (side == Direction.DOWN) {
        diff.y = bounds.min.y - border;
    }
    if (side == Direction.UP) {
        diff.y = bounds.max.y + border;
    }
    if (side == Direction.NORTH) {
        diff.z = bounds.min.z - border;
    }
    if (side == Direction.SOUTH) {
        diff.z = bounds.max.z + border;
    }
    if (side == Direction.WEST) {
        diff.x = bounds.min.x - border;
    }
    if (side == Direction.EAST) {
        diff.x = bounds.max.x + border;
    }

    particleManager.addEffect(new CustomBreakingParticle(world, pos.x, pos.y, pos.z, 0, 0, 0, icon).multiplyVelocity(0.2F).multipleParticleScaleBy(0.6F));
}
 
Example #10
Source File: CustomParticleHandler.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * {@link Block#addHitEffects}
 * Provided the model bound is an instance of IModelParticleProvider, you will have landing particles just handled for you.
 * Use the default PerspectiveModel implementations inside CCL, Destroy effects will just be handled for you.
 *
 * @param world   The world.
 * @param pos     The position of the block.
 * @param manager The ParticleManager.
 * @return True if particles were added, basically just return the result of this method inside {@link Block#addHitEffects}
 */
@OnlyIn (Dist.CLIENT)
public static boolean handleDestroyEffects(World world, BlockPos pos, BlockState state, ParticleManager manager) {
    BlockModelShapes modelShapes = Minecraft.getInstance().getBlockRendererDispatcher().getBlockModelShapes();
    IBakedModel model = modelShapes.getModel(state);
    if (model instanceof IModelParticleProvider) {
        IModelData modelData = ModelDataManager.getModelData(world, pos);
        Cuboid6 bounds = new Cuboid6(state.getShape(world, pos).getBoundingBox());
        addBlockDestroyEffects(world, bounds.add(pos), new ArrayList<>(((IModelParticleProvider) model).getDestroyEffects(state, world, pos, modelData)), manager);
        return true;
    }
    return false;
}
 
Example #11
Source File: MixinParticleManager.java    From multiconnect with MIT License 5 votes vote down vote up
@Override
public <T extends ParticleEffect> void multiconnect_registerSpriteAwareFactory(ParticleType<T> type,
                                                                               Function<SpriteProvider, ParticleFactory<T>> spriteAwareFactory) {
    // https://stackoverflow.com/questions/26775676/explicit-use-of-lambdametafactory
    SpriteProvider spriteProvider;
    try {
        spriteProvider = (SpriteProvider) SSP_CTOR.newInstance((ParticleManager) (Object) this);
    } catch (Throwable e) {
        throw new AssertionError(e);
    }

    Identifier id = Registry.PARTICLE_TYPE.getId(type);
    spriteAwareFactories.put(id, spriteProvider);
    customFactories.put(id, spriteAwareFactory.apply(spriteProvider));
}
 
Example #12
Source File: ParticleHandlerUtil.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void addBlockHitEffects(World world, Cuboid6 bounds, EnumFacing side, TextureAtlasSprite icon, int spriteColor, ParticleManager particleManager) {
    float border = 0.1F;
    Vector3 diff = bounds.max.copy().subtract(bounds.min).add(-2 * border);
    diff.x *= world.rand.nextDouble();
    diff.y *= world.rand.nextDouble();
    diff.z *= world.rand.nextDouble();
    Vector3 pos = diff.add(bounds.min).add(border);

    float red = (spriteColor >> 16 & 255) / 255.0F;
    float green = (spriteColor >> 8 & 255) / 255.0F;
    float blue = (spriteColor & 255) / 255.0F;

    if (side == EnumFacing.DOWN) {
        diff.y = bounds.min.y - border;
    }
    if (side == EnumFacing.UP) {
        diff.y = bounds.max.y + border;
    }
    if (side == EnumFacing.NORTH) {
        diff.z = bounds.min.z - border;
    }
    if (side == EnumFacing.SOUTH) {
        diff.z = bounds.max.z + border;
    }
    if (side == EnumFacing.WEST) {
        diff.x = bounds.min.x - border;
    }
    if (side == EnumFacing.EAST) {
        diff.x = bounds.max.x + border;
    }

    DigIconParticle digIconParticle = new DigIconParticle(world, pos.x, pos.y, pos.z, 0, 0, 0, icon);
    digIconParticle.multiplyVelocity(0.2F);
    digIconParticle.multipleParticleScaleBy(0.6F);
    digIconParticle.setRBGColorF(red, green, blue);
    particleManager.addEffect(digIconParticle);
}
 
Example #13
Source File: GTTileMagicEnergyAbsorber.java    From GT-Classic with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SideOnly(Side.CLIENT)
@Override
public void randomTickDisplay(IBlockState stateIn, World worldIn, BlockPos pos, Random rand) {
	if (this.isActive && this.portalMode
			&& worldIn.getBlockState(this.pos.offset(EnumFacing.DOWN)).getBlock() == Blocks.END_PORTAL) {
		for (EnumFacing facing : EnumFacing.HORIZONTALS) {
			BlockPos sidePos = pos.offset(facing);
			if (world.getBlockState(sidePos).isFullBlock()) {
				continue;
			}
			for (int k = 3; k > 0; --k) {
				ParticleManager er = Minecraft.getMinecraft().effectRenderer;
				float multPos = (float) (.1 * 2) + 0.9F;
				double x = (double) ((float) sidePos.getX() + 0.05F + rand.nextFloat() * multPos);
				double y = (double) ((float) sidePos.getY() + 0.0F + rand.nextFloat() * 0.5F);
				double z = (double) ((float) sidePos.getZ() + 0.05F + rand.nextFloat() * multPos);
				double[] velocity = new double[] { 0.0D, 7.6D, 0.0D };
				if (k < 4) {
					velocity[2] *= 0.55D;
				}
				float foo = rand.nextFloat() * .25F;
				float[] colour = new float[] { 0.0F, foo, foo };
				er.addEffect(new EntityChargePadAuraFX(this.world, x, y, z, 8, velocity, colour, false));
			}
		}
	}
}
 
Example #14
Source File: ICustomParticleBlock.java    From CodeChickenLib with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
@OnlyIn (Dist.CLIENT)
default boolean addDestroyEffects(BlockState state, World world, BlockPos pos, ParticleManager manager) {
    return CustomParticleHandler.handleDestroyEffects(world, pos, state, manager);
}
 
Example #15
Source File: ICustomParticleBlock.java    From CodeChickenLib with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
@OnlyIn (Dist.CLIENT)
default boolean addHitEffects(BlockState state, World worldObj, RayTraceResult target, ParticleManager manager) {
    return CustomParticleHandler.handleHitEffects(state, worldObj, target, manager);
}
 
Example #16
Source File: ParticleHandlerUtil.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static void addHitEffects(IBlockState blockState, World worldObj, RayTraceResult target, TextureAtlasSprite atlasSprite, int spriteColor, ParticleManager manager) {
    Cuboid6 cuboid6 = getBoundingBox(blockState, worldObj, target);
    addBlockHitEffects(worldObj, cuboid6, target.sideHit, atlasSprite, spriteColor, manager);
}
 
Example #17
Source File: BlockCrop.java    From AgriCraft with MIT License 4 votes vote down vote up
/**
 * Renders the hit effects, such as the flying particles when the block is hit.
 *
 * @return false - the block is one-shot and needs no hit particles.
 */
@Override
@SideOnly(value = Side.CLIENT)
public boolean addHitEffects(IBlockState state, World worldObj, RayTraceResult target, ParticleManager manager) {
    return false;
}
 
Example #18
Source File: BlockCrop.java    From AgriCraft with MIT License 4 votes vote down vote up
/**
 * Tells Minecraft if there should be destroy effects, such as particles.
 *
 * @return false - there are no destroy particles.
 */
@Override
@SideOnly(value = Side.CLIENT)
public boolean addDestroyEffects(World world, BlockPos pos, ParticleManager manager) {
    return false;
}
 
Example #19
Source File: BlockSeedAnalyzer.java    From AgriCraft with MIT License 4 votes vote down vote up
@Override
public boolean addHitEffects(IBlockState state, World worldObj, RayTraceResult target, ParticleManager manager) {
    return false;
}
 
Example #20
Source File: BlockSeedAnalyzer.java    From AgriCraft with MIT License 4 votes vote down vote up
@Override
public boolean addDestroyEffects(World world, BlockPos pos, ParticleManager manager) {
    return false;
}
 
Example #21
Source File: ParticleHandlerUtil.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static void addHitEffects(World worldObj, CuboidRayTraceResult result, TextureAtlasSprite atlasSprite, int spriteColor, ParticleManager manager) {
    addBlockHitEffects(worldObj, result.cuboid6, result.sideHit, atlasSprite, spriteColor, manager);
}
 
Example #22
Source File: ParticleHandlerUtil.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static void addBlockDestroyEffects(IBlockState blockState, World worldObj, BlockPos blockPos, TextureAtlasSprite atlasSprite, int spriteColor, ParticleManager manager) {
    Cuboid6 cuboid6 = new Cuboid6(blockState.getBoundingBox(worldObj, blockPos)).add(blockPos);
    addBlockDestroyEffects(worldObj, cuboid6, atlasSprite, spriteColor, manager);
}
 
Example #23
Source File: ParticleHandlerUtil.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static void addBlockDestroyEffects(World worldObj, CuboidRayTraceResult result, TextureAtlasSprite atlasSprite, int spriteColor, ParticleManager manager) {
    addBlockDestroyEffects(worldObj, result.cuboid6, atlasSprite, spriteColor, manager);
}
 
Example #24
Source File: BlockCustomParticle.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
@SideOnly(Side.CLIENT)
public void handleCustomParticle(World worldObj, BlockPos blockPos, ParticleManager particleManager, Vector3 entityPos, int numberOfParticles) {
    Pair<TextureAtlasSprite, Integer> atlasSprite = getParticleTexture(worldObj, blockPos);
    ParticleHandlerUtil.addBlockLandingEffects(worldObj, entityPos, atlasSprite.getLeft(), atlasSprite.getRight(), particleManager, numberOfParticles);
}
 
Example #25
Source File: IForgeBlock.java    From patchwork-api with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Spawn particles for when the block is destroyed. Due to the nature
 * of how this is invoked, the x/y/z locations are not always guaranteed
 * to host your block. So be sure to do proper sanity checks before assuming
 * that the location is this block.
 *
 * @param state   This block's state
 * @param world   The current world
 * @param pos     Position to spawn the particle
 * @param manager A reference to the current particle manager.
 * @return True to prevent vanilla break particles from spawning.
 */
@Environment(EnvType.CLIENT)
default boolean addDestroyEffects(BlockState state, World world, BlockPos pos, ParticleManager manager) {
	return false;
}
 
Example #26
Source File: IForgeBlock.java    From patchwork-api with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Spawn a digging particle effect in the world, this is a wrapper
 * around {@link ParticleManager.addBlockBreakParticles} to allow the block more
 * control over the particles.
 *
 * @param state   The current state
 * @param world   The current world
 * @param target  The target the player is looking at {x/y/z/side/sub}
 * @param manager A reference to the current particle manager.
 * @return True to prevent vanilla digging particles form spawning.
 */
@Environment(EnvType.CLIENT)
default boolean addHitEffects(BlockState state, World worldObj, HitResult target, ParticleManager manager) {
	return false;
}
 
Example #27
Source File: IForgeBlockState.java    From patchwork-api with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Spawn particles for when the block is destroyed. Due to the nature
 * of how this is invoked, the x/y/z locations are not always guaranteed
 * to host your block. So be sure to do proper sanity checks before assuming
 * that the location is this block.
 *
 * @param world   The current world
 * @param pos     Position to spawn the particle
 * @param manager A reference to the current particle manager.
 * @return True to prevent vanilla break particles from spawning.
 */
@Environment(EnvType.CLIENT)
default boolean addDestroyEffects(World world, BlockPos pos, ParticleManager manager) {
	return patchwork$getForgeBlock().addDestroyEffects(getBlockState(), world, pos, manager);
}
 
Example #28
Source File: IForgeBlockState.java    From patchwork-api with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Spawn a digging particle effect in the world, this is a wrapper
 * around {@link ParticleManager.addBlockBreakParticles} to allow the block more
 * control over the particles.
 *
 * @param world   The current world
 * @param target  The target the player is looking at {x/y/z/side/sub}
 * @param manager A reference to the current particle manager.
 * @return True to prevent vanilla digging particles form spawning.
 */
@Environment(EnvType.CLIENT)
default boolean addHitEffects(World world, HitResult target, ParticleManager manager) {
	return patchwork$getForgeBlock().addHitEffects(getBlockState(), world, target, manager);
}
 
Example #29
Source File: ICustomParticleBlock.java    From GregTech with GNU Lesser General Public License v3.0 votes vote down vote up
void handleCustomParticle(World worldObj, BlockPos blockPos, ParticleManager particleManager, Vector3 entityPos, int numberOfParticles);