Java源码示例:net.minecraft.particle.ParticleEffect

示例1
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);
	}
}
 
示例2
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;
}
 
示例3
@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)
            );
        }
    };
}
 
示例4
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);
}
 
示例5
@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
        );
    };
}
 
示例6
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;
}
 
示例7
@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));
}
 
示例8
@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));
}
 
示例9
private static ParticleEffect parseParticle(String name)
{
    try
    {
        return ParticleArgumentType.readParameters(new StringReader(name));
    }
    catch (CommandSyntaxException e)
    {
        throw new RuntimeException("No such particle: "+name);
    }
}
 
示例10
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);
}
 
示例11
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);
    }
}
 
示例12
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);
}
 
示例13
@Environment(EnvType.CLIENT)
public ParticleEffect getParticle() {
    return GalacticraftParticles.DRIPPING_CRUDE_OIL_PARTICLE;
}
 
示例14
@Environment(EnvType.CLIENT)
public ParticleEffect getParticle() {
    return GalacticraftParticles.DRIPPING_FUEL_PARTICLE;
}
 
示例15
@Override
@Environment(EnvType.CLIENT)
public ParticleEffect getParticle() {
	return ParticleTypes.DRIPPING_WATER;
}
 
示例16
@Override
@Environment(EnvType.CLIENT)
public ParticleEffect getParticle() {
	return ParticleTypes.DRIPPING_WATER;
}
 
示例17
<T extends ParticleEffect> void multiconnect_registerSpriteAwareFactory(ParticleType<T> type,
Function<SpriteProvider, ParticleFactory<T>> spriteAwareFactory);
 
示例18
@Accessor("PARTICLE_ID")
static TrackedData<ParticleEffect> getParticleId() {
    return MixinHelper.fakeInstance();
}
 
示例19
@Override
public <T extends ParticleEffect> void multiconnect_registerFactory(ParticleType<T> type, ParticleFactory<T> factory) {
    customFactories.put(Registry.PARTICLE_TYPE.getId(type), factory);
}
 
示例20
<T extends ParticleEffect> void multiconnect_registerFactory(ParticleType<T> type, ParticleFactory<T> factory);