ActuallyAdditions/src/main/java/de/ellpeck/actuallyadditions/mod/particle/ParticleLaserItem.java

96 lines
3.5 KiB
Java
Raw Normal View History

2016-12-27 17:40:27 +01:00
/*
* This file ("ParticleLaserItem.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-27 17:40:27 +01:00
*/
package de.ellpeck.actuallyadditions.mod.particle;
2021-02-27 21:24:26 +01:00
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.IVertexBuilder;
2016-12-27 17:40:27 +01:00
import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
import net.minecraft.client.Minecraft;
2021-02-27 21:24:26 +01:00
import net.minecraft.client.particle.IParticleRenderType;
2016-12-27 17:40:27 +01:00
import net.minecraft.client.particle.Particle;
2021-02-27 21:24:26 +01:00
import net.minecraft.client.renderer.ActiveRenderInfo;
2016-12-27 17:40:27 +01:00
import net.minecraft.client.renderer.RenderHelper;
2021-02-27 21:24:26 +01:00
import net.minecraft.client.world.ClientWorld;
2016-12-27 17:40:27 +01:00
import net.minecraft.item.ItemStack;
2021-02-27 21:24:26 +01:00
import net.minecraft.util.Util;
import net.minecraft.util.math.vector.Vector3d;
2021-02-26 22:15:48 +01:00
import org.lwjgl.opengl.GL14;
2016-12-27 17:40:27 +01:00
2019-05-02 09:10:29 +02:00
public class ParticleLaserItem extends Particle {
2016-12-27 17:40:27 +01:00
private final double otherX;
private final double otherY;
private final double otherZ;
private final ItemStack stack;
2021-02-27 21:24:26 +01:00
private ParticleLaserItem(ClientWorld world, double posX, double posY, double posZ, ItemStack stack, double motionY) {
2016-12-27 17:40:27 +01:00
this(world, posX, posY, posZ, stack, motionY, 0, 0, 0);
}
2021-02-27 21:24:26 +01:00
public ParticleLaserItem(ClientWorld world, double posX, double posY, double posZ, ItemStack stack, double motionY, double otherX, double otherY, double otherZ) {
2019-05-02 09:10:29 +02:00
super(world, posX + (world.rand.nextDouble() - 0.5) / 8, posY, posZ + (world.rand.nextDouble() - 0.5) / 8);
2016-12-27 17:40:27 +01:00
this.stack = stack;
this.otherX = otherX;
this.otherY = otherY;
this.otherZ = otherZ;
this.motionX = 0;
this.motionY = motionY;
this.motionZ = 0;
2021-02-27 21:24:26 +01:00
this.maxAge = 10;
2016-12-27 17:40:27 +01:00
this.canCollide = false;
}
@Override
2019-05-02 09:10:29 +02:00
public void setExpired() {
2016-12-27 17:40:27 +01:00
super.setExpired();
2019-05-02 09:10:29 +02:00
if (this.otherX != 0 || this.otherY != 0 || this.otherZ != 0) {
2016-12-27 17:40:27 +01:00
Particle fx = new ParticleLaserItem(this.world, this.otherX, this.otherY, this.otherZ, this.stack, -0.025);
2021-02-27 21:24:26 +01:00
Minecraft.getInstance().particles.addEffect(fx);
2016-12-27 17:40:27 +01:00
}
}
@Override
2021-02-27 21:24:26 +01:00
public void renderParticle(IVertexBuilder buffer, ActiveRenderInfo renderInfo, float partialTicks) {
RenderSystem.pushMatrix();
2016-12-27 17:40:27 +01:00
RenderHelper.enableStandardItemLighting();
2021-02-27 21:24:26 +01:00
Vector3d cam = renderInfo.getProjectedView();
RenderSystem.translated(this.posX - cam.getX(), this.posY - cam.getY(), this.posZ - cam.getZ());
RenderSystem.scalef(0.3F, 0.3F, 0.3F);
2016-12-27 17:40:27 +01:00
double boop = Util.milliTime() / 600D;
2021-02-27 21:24:26 +01:00
RenderSystem.rotatef((float) (boop * 40D % 360), 0, 1, 0);
2016-12-27 17:40:27 +01:00
2021-02-27 21:24:26 +01:00
RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA.param, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA.param, GlStateManager.SourceFactor.ONE.param, GlStateManager.DestFactor.ZERO.param);
2016-12-27 17:40:27 +01:00
2021-02-27 21:24:26 +01:00
float ageRatio = (float) this.age / (float) this.maxAge;
2021-02-26 22:15:48 +01:00
float color = this.motionY < 0
? 1F - ageRatio
: ageRatio;
2016-12-27 17:40:27 +01:00
GL14.glBlendColor(color, color, color, color);
AssetUtil.renderItemWithoutScrewingWithColors(this.stack);
RenderHelper.disableStandardItemLighting();
2021-02-27 21:24:26 +01:00
RenderSystem.popMatrix();
2016-12-27 17:40:27 +01:00
}
@Override
2021-02-27 21:24:26 +01:00
public IParticleRenderType getRenderType() {
return IParticleRenderType.PARTICLE_SHEET_TRANSLUCENT;
2016-12-27 17:40:27 +01:00
}
}