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;
|
2024-03-02 21:23:08 +01:00
|
|
|
import com.mojang.blaze3d.vertex.PoseStack;
|
|
|
|
import com.mojang.blaze3d.vertex.VertexConsumer;
|
|
|
|
import com.mojang.math.Vector3f;
|
2016-12-27 17:40:27 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
|
2024-03-02 21:23:08 +01:00
|
|
|
import net.minecraft.Util;
|
|
|
|
import net.minecraft.client.Camera;
|
2016-12-27 17:40:27 +01:00
|
|
|
import net.minecraft.client.Minecraft;
|
2024-03-02 21:23:08 +01:00
|
|
|
import net.minecraft.client.multiplayer.ClientLevel;
|
2016-12-27 17:40:27 +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;
|
2023-01-19 16:27:56 +01:00
|
|
|
import net.minecraft.client.renderer.LightTexture;
|
2024-03-02 21:23:08 +01:00
|
|
|
import net.minecraft.client.renderer.MultiBufferSource;
|
2023-01-19 16:27:56 +01:00
|
|
|
import net.minecraft.client.renderer.texture.OverlayTexture;
|
2024-03-02 21:23:08 +01:00
|
|
|
import net.minecraft.core.BlockPos;
|
|
|
|
import net.minecraft.core.particles.ParticleOptions;
|
|
|
|
import net.minecraft.world.item.ItemStack;
|
|
|
|
import net.minecraft.world.level.LightLayer;
|
|
|
|
import net.minecraft.world.phys.Vec3;
|
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;
|
|
|
|
|
2024-03-02 21:23:08 +01:00
|
|
|
private ParticleLaserItem(ClientLevel 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);
|
|
|
|
}
|
|
|
|
|
2024-03-02 21:23:08 +01:00
|
|
|
public ParticleLaserItem(ClientLevel world, double posX, double posY, double posZ, ItemStack stack, double motionY, double otherX, double otherY, double otherZ) {
|
2021-08-22 17:09:06 +02:00
|
|
|
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;
|
|
|
|
|
2021-08-22 17:09:06 +02:00
|
|
|
this.xd = 0;
|
|
|
|
this.yd = motionY;
|
|
|
|
this.zd = 0;
|
2016-12-27 17:40:27 +01:00
|
|
|
|
2021-08-22 17:09:06 +02:00
|
|
|
this.lifetime = 10;
|
|
|
|
this.hasPhysics = false;
|
2016-12-27 17:40:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-08-22 17:09:06 +02:00
|
|
|
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
|
2024-03-02 21:23:08 +01:00
|
|
|
public void render(VertexConsumer vertexConsumer, Camera renderInfo, float partialTicks) {
|
2023-01-19 16:27:56 +01:00
|
|
|
Minecraft mc = Minecraft.getInstance();
|
2024-03-02 21:23:08 +01:00
|
|
|
MultiBufferSource.BufferSource renderBuffer = mc.renderBuffers().bufferSource();
|
|
|
|
Vec3 cam = renderInfo.getPosition();
|
2023-01-19 16:27:56 +01:00
|
|
|
|
2024-03-02 21:23:08 +01:00
|
|
|
// RenderSystem.pushMatrix();
|
|
|
|
// Lighting.turnBackOn();
|
|
|
|
PoseStack matrices = new PoseStack();
|
2023-01-19 16:27:56 +01:00
|
|
|
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
|
|
|
|
2021-08-22 17:09:06 +02: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
|
|
|
|
2024-03-02 21:23:08 +01:00
|
|
|
// RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F); TODO: See if this is needed
|
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
|
|
|
|
2021-08-22 17:09:06 +02: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;
|
2024-03-02 21:23:08 +01:00
|
|
|
// RenderSystem.blendColor(color, color, color, color); TODO: See if this is needed
|
2016-12-27 17:40:27 +01:00
|
|
|
|
2024-03-02 21:23:08 +01:00
|
|
|
int blockLight = level.getBrightness(LightLayer.BLOCK, new BlockPos(x, y, z));
|
|
|
|
int skyLight = level.getBrightness(LightLayer.SKY, new BlockPos(x, y, z));
|
2023-01-19 16:27:56 +01:00
|
|
|
AssetUtil.renderItemWithoutScrewingWithColors(this.stack, matrices, LightTexture.pack(blockLight, skyLight), OverlayTexture.NO_OVERLAY);
|
2016-12-27 17:40:27 +01:00
|
|
|
|
2024-03-02 21:23:08 +01:00
|
|
|
// Lighting.turnOff();
|
2023-01-19 16:27:56 +01:00
|
|
|
matrices.popPose();
|
2024-03-02 21:23:08 +01:00
|
|
|
// RenderSystem.popMatrix();
|
2023-01-19 16:27:56 +01:00
|
|
|
renderBuffer.endBatch();
|
2016-12-27 17:40:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2024-03-02 21:23:08 +01:00
|
|
|
public ParticleRenderType getRenderType() {
|
|
|
|
return ParticleRenderType.PARTICLE_SHEET_TRANSLUCENT;
|
2016-12-27 17:40:27 +01:00
|
|
|
}
|
2023-01-19 16:27:56 +01:00
|
|
|
|
2024-03-02 21:23:08 +01:00
|
|
|
public static class Factory implements ParticleProvider<LaserItemParticleData> {
|
|
|
|
public Factory(SpriteSet sprite) {
|
2023-01-19 16:27:56 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2024-03-02 21:23:08 +01:00
|
|
|
public Particle createParticle(LaserItemParticleData 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 ParticleLaserItem(worldIn, x, y, z, data.stack, ySpeed, data.outputX, data.outputY, data.outputZ);
|
|
|
|
}
|
|
|
|
|
2024-03-02 21:23:08 +01:00
|
|
|
public static ParticleOptions createData(ItemStack stack, double outputX, double outputY, double outputZ) {
|
2023-01-19 16:27:56 +01:00
|
|
|
return new LaserItemParticleData(stack, outputX, outputY, outputZ);
|
|
|
|
}
|
|
|
|
}
|
2016-12-27 17:40:27 +01:00
|
|
|
}
|