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

130 lines
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;
2023-01-19 16:27:56 +01:00
import com.mojang.blaze3d.matrix.MatrixStack;
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;
2023-01-19 16:27:56 +01:00
import net.minecraft.client.particle.IAnimatedSprite;
import net.minecraft.client.particle.IParticleFactory;
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;
2023-01-19 16:27:56 +01:00
import net.minecraft.client.renderer.IRenderTypeBuffer;
import net.minecraft.client.renderer.LightTexture;
2016-12-27 17:40:27 +01:00
import net.minecraft.client.renderer.RenderHelper;
2023-01-19 16:27:56 +01:00
import net.minecraft.client.renderer.texture.OverlayTexture;
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;
2023-01-19 16:27:56 +01:00
import net.minecraft.particles.IParticleData;
2021-02-27 21:24:26 +01:00
import net.minecraft.util.Util;
2023-01-19 16:27:56 +01:00
import net.minecraft.util.math.BlockPos;
2021-02-27 21:24:26 +01:00
import net.minecraft.util.math.vector.Vector3d;
2023-01-19 16:27:56 +01:00
import net.minecraft.util.math.vector.Vector3f;
import net.minecraft.world.LightType;
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) {
2023-01-19 16:27:56 +01:00
this.level.addParticle(Factory.createData(this.stack, 0, 0, 0),
this.otherX, this.otherY, this.otherZ, 0, -0.025, 0);
2016-12-27 17:40:27 +01:00
}
}
@Override
public void render(IVertexBuilder buffer, ActiveRenderInfo renderInfo, float partialTicks) {
2023-01-19 16:27:56 +01:00
Minecraft mc = Minecraft.getInstance();
IRenderTypeBuffer.Impl renderBuffer = mc.renderBuffers().bufferSource();
Vector3d cam = renderInfo.getPosition();
2021-02-27 21:24:26 +01:00
RenderSystem.pushMatrix();
RenderHelper.turnBackOn();
2023-01-19 16:27:56 +01:00
MatrixStack matrices = new MatrixStack();
matrices.pushPose();
2016-12-27 17:40:27 +01:00
2023-01-19 16:27:56 +01:00
matrices.translate(x - cam.x, y - cam.y, z - cam.z);
matrices.scale(0.3F, 0.3F, 0.3F);
2016-12-27 17:40:27 +01:00
double boop = Util.getMillis() / 600D;
2023-01-19 16:27:56 +01:00
matrices.mulPose(Vector3f.YP.rotationDegrees((float) (boop * 40D % 360)));
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);
2023-01-19 16:27:56 +01:00
RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA,
GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
2016-12-27 17:40:27 +01:00
float ageRatio = (float) this.age / (float) this.lifetime;
float color = this.yd < 0
2023-01-19 16:27:56 +01:00
? 1F - ageRatio
: ageRatio;
RenderSystem.blendColor(color, color, color, color);
2016-12-27 17:40:27 +01:00
2023-01-19 16:27:56 +01:00
int blockLight = level.getBrightness(LightType.BLOCK, new BlockPos(x, y, z));
int skyLight = level.getBrightness(LightType.SKY, new BlockPos(x, y, z));
AssetUtil.renderItemWithoutScrewingWithColors(this.stack, matrices, LightTexture.pack(blockLight, skyLight), OverlayTexture.NO_OVERLAY);
2016-12-27 17:40:27 +01:00
RenderHelper.turnOff();
2023-01-19 16:27:56 +01:00
matrices.popPose();
2021-02-27 21:24:26 +01:00
RenderSystem.popMatrix();
2023-01-19 16:27:56 +01:00
renderBuffer.endBatch();
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
}
2023-01-19 16:27:56 +01:00
public static class Factory implements IParticleFactory<LaserItemParticleData> {
public Factory(IAnimatedSprite sprite) {
}
@Override
public Particle createParticle(LaserItemParticleData data, ClientWorld worldIn, double x, double y, double z, double xSpeed, double ySpeed, double zSpeed) {
return new ParticleLaserItem(worldIn, x, y, z, data.stack, ySpeed, data.outputX, data.outputY, data.outputZ);
}
public static IParticleData createData(ItemStack stack, double outputX, double outputY, double outputZ) {
return new LaserItemParticleData(stack, outputX, outputY, outputZ);
}
}
2016-12-27 17:40:27 +01:00
}