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) {
super(world, posX + (world.random.nextDouble() - 0.5) / 8, posY, posZ + (world.random.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.xd = 0;
this.yd = motionY;
this.zd = 0;
2016-12-27 17:40:27 +01:00
this.lifetime = 10;
this.hasPhysics = false;
2016-12-27 17:40:27 +01:00
}
@Override
public void remove() {
super.remove();
2016-12-27 17:40:27 +01:00
2019-05-02 09:10:29 +02:00
if (this.otherX != 0 || this.otherY != 0 || this.otherZ != 0) {
Particle fx = new ParticleLaserItem(this.level, this.otherX, this.otherY, this.otherZ, this.stack, -0.025);
Minecraft.getInstance().particleEngine.add(fx);
2016-12-27 17:40:27 +01:00
}
}
@Override
public void render(IVertexBuilder buffer, ActiveRenderInfo renderInfo, float partialTicks) {
2021-02-27 21:24:26 +01:00
RenderSystem.pushMatrix();
RenderHelper.turnBackOn();
2016-12-27 17:40:27 +01:00
Vector3d cam = renderInfo.getPosition();
RenderSystem.translated(this.x - cam.x(), this.y - cam.y(), this.z - cam.z());
2021-02-27 21:24:26 +01:00
RenderSystem.scalef(0.3F, 0.3F, 0.3F);
2016-12-27 17:40:27 +01:00
double boop = Util.getMillis() / 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.value, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA.value, GlStateManager.SourceFactor.ONE.value, GlStateManager.DestFactor.ZERO.value);
2016-12-27 17:40:27 +01:00
float ageRatio = (float) this.age / (float) this.lifetime;
float color = this.yd < 0
2021-02-26 22:15:48 +01:00
? 1F - ageRatio
: ageRatio;
2016-12-27 17:40:27 +01:00
GL14.glBlendColor(color, color, color, color);
AssetUtil.renderItemWithoutScrewingWithColors(this.stack);
RenderHelper.turnOff();
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
}
}