2016-12-09 21:36:43 +01:00
|
|
|
/*
|
|
|
|
* This file ("ParticleBeam.java") is part of the Actually Additions mod for Minecraft.
|
|
|
|
* It is created and owned by Ellpeck and distributed
|
|
|
|
* under the Actually Additions License to be found at
|
|
|
|
* http://ellpeck.de/actaddlicense
|
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
*
|
2017-01-01 16:23:26 +01:00
|
|
|
* © 2015-2017 Ellpeck
|
2016-12-09 21:36:43 +01:00
|
|
|
*/
|
|
|
|
|
2016-12-27 17:40:27 +01:00
|
|
|
package de.ellpeck.actuallyadditions.mod.particle;
|
2016-12-09 21:36:43 +01:00
|
|
|
|
2024-03-02 21:23:08 +01:00
|
|
|
import com.mojang.blaze3d.vertex.VertexConsumer;
|
2016-12-09 21:36:43 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
|
2024-03-02 21:23:08 +01:00
|
|
|
import net.minecraft.client.Camera;
|
|
|
|
import net.minecraft.client.multiplayer.ClientLevel;
|
2016-12-09 21:36:43 +01:00
|
|
|
import net.minecraft.client.particle.Particle;
|
2024-03-02 21:23:08 +01:00
|
|
|
import net.minecraft.client.particle.ParticleProvider;
|
|
|
|
import net.minecraft.client.particle.ParticleRenderType;
|
|
|
|
import net.minecraft.client.particle.SpriteSet;
|
|
|
|
import net.minecraft.core.particles.ParticleOptions;
|
2016-12-09 21:36:43 +01:00
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
public class ParticleBeam extends Particle {
|
2016-12-09 21:36:43 +01:00
|
|
|
|
|
|
|
private final double endX;
|
|
|
|
private final double endY;
|
|
|
|
private final double endZ;
|
|
|
|
private final float[] color;
|
|
|
|
private final double rotationTime;
|
|
|
|
private final float size;
|
|
|
|
private final float alpha;
|
|
|
|
|
2024-03-02 21:23:08 +01:00
|
|
|
public ParticleBeam(ClientLevel world, double startX, double startY, double startZ, double endX, double endY, double endZ,
|
2023-01-19 16:27:56 +01:00
|
|
|
float[] color, float alpha, int maxAge, double rotationTime, float size) {
|
2016-12-09 21:36:43 +01:00
|
|
|
super(world, startX, startY, startZ);
|
|
|
|
this.endX = endX;
|
|
|
|
this.endY = endY;
|
|
|
|
this.endZ = endZ;
|
|
|
|
this.color = color;
|
|
|
|
this.rotationTime = rotationTime;
|
|
|
|
this.size = size;
|
2021-08-22 17:09:06 +02:00
|
|
|
this.lifetime = maxAge;
|
2016-12-09 21:36:43 +01:00
|
|
|
this.alpha = alpha;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2024-03-02 21:23:08 +01:00
|
|
|
public void render(VertexConsumer buffer, Camera renderInfo, float partialTicks) {
|
2021-08-22 17:09:06 +02:00
|
|
|
float ageRatio = (float) this.age / (float) this.lifetime;
|
2019-05-02 09:10:29 +02:00
|
|
|
float currAlpha = this.alpha - ageRatio * this.alpha;
|
2021-08-22 17:09:06 +02:00
|
|
|
AssetUtil.renderLaser(this.x + 0.5, this.y + 0.5, this.z + 0.5, this.endX + 0.5, this.endY + 0.5, this.endZ + 0.5, this.rotationTime, currAlpha, this.size, this.color);
|
2016-12-09 21:36:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2024-03-02 21:23:08 +01:00
|
|
|
public ParticleRenderType getRenderType() {
|
|
|
|
return ParticleRenderType.PARTICLE_SHEET_TRANSLUCENT;
|
2016-12-09 21:36:43 +01:00
|
|
|
}
|
2023-01-19 16:27:56 +01:00
|
|
|
|
|
|
|
|
2024-03-02 21:23:08 +01:00
|
|
|
public static class Factory implements ParticleProvider<BeamParticleData> {
|
|
|
|
public Factory(SpriteSet sprite) {
|
2023-01-19 16:27:56 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2024-03-02 21:23:08 +01:00
|
|
|
public Particle createParticle(BeamParticleData data, ClientLevel worldIn, double x, double y, double z, double xSpeed, double ySpeed, double zSpeed) {
|
2023-01-19 16:27:56 +01:00
|
|
|
return new ParticleBeam(worldIn, x, y, z, data.endX, data.endY, data.endZ, data.color, data.alpha, data.maxAge,
|
|
|
|
data.rotationTime, data.size);
|
|
|
|
}
|
|
|
|
|
2024-03-02 21:23:08 +01:00
|
|
|
public static ParticleOptions createData(double endX, double endY, double endZ, float[] color, float alpha,
|
2023-01-19 16:27:56 +01:00
|
|
|
int maxAge, double rotationTime, float size) {
|
|
|
|
return new BeamParticleData(endX, endY, endZ, color, alpha, maxAge, rotationTime, size);
|
|
|
|
}
|
|
|
|
}
|
2016-12-09 21:36:43 +01:00
|
|
|
}
|