net.minecraft.particle.ParticleEffect Java Examples

The following examples show how to use net.minecraft.particle.ParticleEffect. 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: ShapeDispatcher.java    From fabric-carpet with MIT License 6 votes vote down vote up
public static int drawParticleLine(List<ServerPlayerEntity> players, ParticleEffect particle, Vec3d from, Vec3d to, double density)
{
    if (isStraight(from, to, density)) return drawOptimizedParticleLine(players, particle, from, to, density);
    double lineLengthSq = from.squaredDistanceTo(to);
    if (lineLengthSq == 0) return 0;
    Vec3d incvec = to.subtract(from).multiply(2*density/MathHelper.sqrt(lineLengthSq));
    int pcount = 0;
    for (Vec3d delta = new Vec3d(0.0,0.0,0.0);
         delta.lengthSquared()<lineLengthSq;
         delta = delta.add(incvec.multiply(Expression.randomizer.nextFloat())))
    {
        for (ServerPlayerEntity player : players)
        {
            player.getServerWorld().spawnParticles(player, particle, true,
                    delta.x+from.x, delta.y+from.y, delta.z+from.z, 1,
                    0.0, 0.0, 0.0, 0.0);
            pcount ++;
        }
    }
    return pcount;
}
 
Example #2
Source File: HallowedTreasureChestEntity.java    From the-hallow with MIT License 6 votes vote down vote up
private void spawnDeathParticles() {
	ParticleEffect particle = ParticleTypes.WITCH;
	double velX = 0;
	double velY = 1;
	double velZ = 0;
	
	double startX = getX() - .275f;
	double startY = getY();
	double startZ = getZ() - .275f;
	
	for (int i = 0; i < 10; i++) {
		double frontX = .5f * random.nextDouble();
		world.addParticle(particle, startX + frontX, startY + random.nextDouble() * .5, startZ + .5f, velX, velY, velZ);
		
		double backX = .5f * random.nextDouble();
		world.addParticle(particle, startX + backX, startY + random.nextDouble() * .5, startZ, velX, velY, velZ);
		
		double leftZ = .5f * random.nextDouble();
		world.addParticle(particle, startX, startY + random.nextDouble() * .5, startZ + leftZ, velX, velY, velZ);
		
		double rightZ = .5f * random.nextDouble();
		world.addParticle(particle, startX + .5f, startY + random.nextDouble() * .5, startZ + rightZ, velX, velY, velZ);
	}
}
 
Example #3
Source File: ShapeDispatcher.java    From fabric-carpet with MIT License 6 votes vote down vote up
@Override
public Consumer<ServerPlayerEntity> alternative()
{
    ParticleEffect particle = replacementParticle();
    double density = Math.max(2.0, from.distanceTo(to) /50) / (a+0.1);
    return p ->
    {
        if (p.dimension == shapeDimension) drawParticleLine(
                Collections.singletonList(p),
                particle,
                relativiseRender(p.getServerWorld(), from, 0),
                relativiseRender(p.getServerWorld(), to, 0),
                density
        );
    };
}
 
Example #4
Source File: ShapeDispatcher.java    From fabric-carpet with MIT License 6 votes vote down vote up
public static int particleMesh(List<ServerPlayerEntity> playerList, ParticleEffect particle, double density,
                               Vec3d from, Vec3d to)
{
    double x1 = from.x;
    double y1 = from.y;
    double z1 = from.z;
    double x2 = to.x;
    double y2 = to.y;
    double z2 = to.z;
    return
    drawParticleLine(playerList, particle, new Vec3d(x1, y1, z1), new Vec3d(x1, y2, z1), density)+
    drawParticleLine(playerList, particle, new Vec3d(x1, y2, z1), new Vec3d(x2, y2, z1), density)+
    drawParticleLine(playerList, particle, new Vec3d(x2, y2, z1), new Vec3d(x2, y1, z1), density)+
    drawParticleLine(playerList, particle, new Vec3d(x2, y1, z1), new Vec3d(x1, y1, z1), density)+

    drawParticleLine(playerList, particle, new Vec3d(x1, y1, z2), new Vec3d(x1, y2, z2), density)+
    drawParticleLine(playerList, particle, new Vec3d(x1, y2, z2), new Vec3d(x2, y2, z2), density)+
    drawParticleLine(playerList, particle, new Vec3d(x2, y2, z2), new Vec3d(x2, y1, z2), density)+
    drawParticleLine(playerList, particle, new Vec3d(x2, y1, z2), new Vec3d(x1, y1, z2), density)+

    drawParticleLine(playerList, particle, new Vec3d(x1, y1, z1), new Vec3d(x1, y1, z2), density)+
    drawParticleLine(playerList, particle, new Vec3d(x1, y2, z1), new Vec3d(x1, y2, z2), density)+
    drawParticleLine(playerList, particle, new Vec3d(x2, y2, z1), new Vec3d(x2, y2, z2), density)+
    drawParticleLine(playerList, particle, new Vec3d(x2, y1, z1), new Vec3d(x2, y1, z2), density);
}
 
Example #5
Source File: ShapeDispatcher.java    From fabric-carpet with MIT License 6 votes vote down vote up
@Override
public Consumer<ServerPlayerEntity> alternative()
{
    ParticleEffect particle = replacementParticle();
    double density = Math.max(2.0, from.distanceTo(to) /50) / (a+0.1);
    return p ->
    {
        if (p.dimension == shapeDimension)
        {
            particleMesh(
                    Collections.singletonList(p),
                    particle,
                    density,
                    relativiseRender(p.getServerWorld(), from, 0),
                    relativiseRender(p.getServerWorld(), to, 0)
            );
        }
    };
}
 
Example #6
Source File: ShapeDispatcher.java    From fabric-carpet with MIT License 6 votes vote down vote up
public static ParticleEffect getParticleData(String name)
{
    ParticleEffect particle = particleCache.get(name);
    if (particle != null)
        return particle;
    try
    {
        particle = ParticleArgumentType.readParameters(new StringReader(name));
    }
    catch (CommandSyntaxException e)
    {
        throw new InternalExpressionException("No such particle: "+name);
    }
    particleCache.put(name, particle);
    return particle;
}
 
Example #7
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 #8
Source File: ShapeDispatcher.java    From fabric-carpet with MIT License 5 votes vote down vote up
protected ParticleEffect replacementParticle()
{
    String particleName = fa ==0 ?
            String.format(Locale.ROOT , "dust %.1f %.1f %.1f 1.0", r, g, b):
            String.format(Locale.ROOT , "dust %.1f %.1f %.1f 1.0", fr, fg, fb);
    return getParticleData(particleName);
}
 
Example #9
Source File: ParticleDisplay.java    From fabric-carpet with MIT License 5 votes vote down vote up
public static void drawParticleLine(ServerPlayerEntity player, Vec3d from, Vec3d to, String main, String accent, int count, double spread)
{
    ParticleEffect accentParticle = getEffect(accent);
    ParticleEffect mainParticle = getEffect(main);

    if (accentParticle != null) ((ServerWorld)player.world).spawnParticles(
            player,
            accentParticle,
            true,
            to.x, to.y, to.z, count,
            spread, spread, spread, 0.0);

    double lineLengthSq = from.squaredDistanceTo(to);
    if (lineLengthSq == 0) return;

    Vec3d incvec = to.subtract(from).normalize();//    multiply(50/sqrt(lineLengthSq));
    int pcount = 0;
    for (Vec3d delta = new Vec3d(0.0,0.0,0.0);
         delta.lengthSquared()<lineLengthSq;
         delta = delta.add(incvec.multiply(player.world.random.nextFloat())))
    {
        ((ServerWorld)player.world).spawnParticles(
                player,
                mainParticle,
                true,
                delta.x+from.x, delta.y+from.y, delta.z+from.z, 1,
                0.0, 0.0, 0.0, 0.0);
    }
}
 
Example #10
Source File: ParticleDisplay.java    From fabric-carpet with MIT License 5 votes vote down vote up
public static ParticleEffect getEffect(String name)
{
    if (name == null) return null;
    ParticleEffect res = particleCache.get(name);
    if (res != null) return res;
    particleCache.put(name, parseParticle(name));
    return particleCache.get(name);
}
 
Example #11
Source File: ParticleDisplay.java    From fabric-carpet with MIT License 5 votes vote down vote up
private static ParticleEffect parseParticle(String name)
{
    try
    {
        return ParticleArgumentType.readParameters(new StringReader(name));
    }
    catch (CommandSyntaxException e)
    {
        throw new RuntimeException("No such particle: "+name);
    }
}
 
Example #12
Source File: MixinParticleManager.java    From multiconnect with MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Inject(method = "createParticle", at = @At("HEAD"), cancellable = true)
private <T extends ParticleEffect> void onCreateParticle(T effect, double x, double y, double z, double xSpeed, double ySpeed, double zSpeed, CallbackInfoReturnable<Particle> ci) {
    ParticleFactory<T> customFactory = (ParticleFactory<T>) customFactories.get(Registry.PARTICLE_TYPE.getId(effect.getType()));
    if (customFactory != null)
        ci.setReturnValue(customFactory.createParticle(effect, world, x, y, z, xSpeed, ySpeed, zSpeed));
}
 
Example #13
Source File: CrudeOilFluid.java    From Galacticraft-Rewoven with MIT License 4 votes vote down vote up
@Environment(EnvType.CLIENT)
public ParticleEffect getParticle() {
    return GalacticraftParticles.DRIPPING_CRUDE_OIL_PARTICLE;
}
 
Example #14
Source File: MixinParticleManager.java    From multiconnect with MIT License 4 votes vote down vote up
@Override
public <T extends ParticleEffect> void multiconnect_registerFactory(ParticleType<T> type, ParticleFactory<T> factory) {
    customFactories.put(Registry.PARTICLE_TYPE.getId(type), factory);
}
 
Example #15
Source File: AreaEffectCloudEntityAccessor.java    From multiconnect with MIT License 4 votes vote down vote up
@Accessor("PARTICLE_ID")
static TrackedData<ParticleEffect> getParticleId() {
    return MixinHelper.fakeInstance();
}
 
Example #16
Source File: IParticleManager.java    From multiconnect with MIT License 4 votes vote down vote up
<T extends ParticleEffect> void multiconnect_registerSpriteAwareFactory(ParticleType<T> type,
Function<SpriteProvider, ParticleFactory<T>> spriteAwareFactory);
 
Example #17
Source File: BloodFluid.java    From the-hallow with MIT License 4 votes vote down vote up
@Override
@Environment(EnvType.CLIENT)
public ParticleEffect getParticle() {
	return ParticleTypes.DRIPPING_WATER;
}
 
Example #18
Source File: WitchWaterFluid.java    From the-hallow with MIT License 4 votes vote down vote up
@Override
@Environment(EnvType.CLIENT)
public ParticleEffect getParticle() {
	return ParticleTypes.DRIPPING_WATER;
}
 
Example #19
Source File: FuelFluid.java    From Galacticraft-Rewoven with MIT License 4 votes vote down vote up
@Environment(EnvType.CLIENT)
public ParticleEffect getParticle() {
    return GalacticraftParticles.DRIPPING_FUEL_PARTICLE;
}
 
Example #20
Source File: IParticleManager.java    From multiconnect with MIT License votes vote down vote up
<T extends ParticleEffect> void multiconnect_registerFactory(ParticleType<T> type, ParticleFactory<T> factory);