diff --git a/src/main/java/gregtech/client/particle/GTLaserBeamParticle.java b/src/main/java/gregtech/client/particle/GTLaserBeamParticle.java index d57f40af1df..f269bef42c2 100644 --- a/src/main/java/gregtech/client/particle/GTLaserBeamParticle.java +++ b/src/main/java/gregtech/client/particle/GTLaserBeamParticle.java @@ -13,6 +13,7 @@ import net.minecraft.client.renderer.texture.SimpleTexture; import net.minecraft.client.renderer.texture.TextureManager; import net.minecraft.util.ResourceLocation; +import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; import codechicken.lib.vec.Vector3; @@ -34,11 +35,20 @@ public class GTLaserBeamParticle extends GTParticle { private float emit; private boolean doubleVertical; + private int activeTime; + private final int fadeInTime; + public GTLaserBeamParticle(@Nullable MetaTileEntity mte, @NotNull Vector3 startPos, @NotNull Vector3 endPos) { + this(mte, startPos, endPos, 0); + } + + public GTLaserBeamParticle(@Nullable MetaTileEntity mte, @NotNull Vector3 startPos, @NotNull Vector3 endPos, + int fadeInTime) { super(startPos.x, startPos.y, startPos.z); this.mte = mte; this.direction = endPos.copy().subtract(startPos); this.setRenderRange(64); + this.fadeInTime = fadeInTime; } @Override @@ -99,6 +109,15 @@ public float getAlpha() { return this.alpha; } + public float getAlpha(float partialTicks) { + if (this.fadeInTime > this.activeTime) { + return (float) (this.alpha * MathHelper.clampedLerp( + (double) this.activeTime / this.fadeInTime, + (double) (this.activeTime + 1) / this.fadeInTime, partialTicks)); + } + return this.alpha; + } + /** * Set emit speed. * @@ -131,9 +150,8 @@ public void onUpdate() { if (mte == null || mte.isValid() && mte.getWorld().isBlockLoaded(mte.getPos(), false) && mte.getWorld().getTileEntity(mte.getPos()) == mte.getHolder()) { - return; - } - setExpired(); + this.activeTime++; + } else setExpired(); } @Override @@ -169,7 +187,7 @@ public void renderParticle(@NotNull BufferBuilder buffer, @NotNull EffectRenderC bodyTexture.getGlTextureId(), headTexture == null ? -1 : headTexture.getGlTextureId(), - direction, cameraDirection, beamHeight, headWidth, alpha, offset); + direction, cameraDirection, beamHeight, headWidth, this.getAlpha(context.partialTicks()), offset); GlStateManager.translate(context.cameraX() - posX, context.cameraY() - posY, context.cameraZ() - posZ); } diff --git a/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityAssemblyLine.java b/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityAssemblyLine.java index 4432cd61a21..fb2de88df33 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityAssemblyLine.java +++ b/src/main/java/gregtech/common/metatileentities/multi/electric/MetaTileEntityAssemblyLine.java @@ -65,6 +65,7 @@ public class MetaTileEntityAssemblyLine extends RecipeMapMultiblockController { @SideOnly(Side.CLIENT) private GTLaserBeamParticle[][] beamParticles; private int beamCount; + private int beamTime; public MetaTileEntityAssemblyLine(ResourceLocation metaTileEntityId) { super(metaTileEntityId, RecipeMaps.ASSEMBLY_LINE_RECIPES); @@ -189,14 +190,22 @@ public void update() { // beams and the maximum progress in the recipe. int beamTime = Math.max(1, maxProgress / maxBeams); - int currentBeamCount = Math.min(maxBeams, getRecipeMapWorkable().getProgress() / beamTime); + int beamCount = Math.min(maxBeams, getRecipeMapWorkable().getProgress() / beamTime + 1); - if (currentBeamCount != beamCount) { - beamCount = currentBeamCount; + if (beamCount != this.beamCount) { + if (beamCount < this.beamCount) { + // if beam count decreases, the last beam in the queue needs to be removed for the sake of fade + // time. + this.beamCount = Math.max(0, beamCount - 1); + writeCustomData(GregtechDataCodes.UPDATE_PARTICLE, this::writeParticles); + } + this.beamTime = beamTime; + this.beamCount = beamCount; writeCustomData(GregtechDataCodes.UPDATE_PARTICLE, this::writeParticles); } } else if (beamCount != 0) { - beamCount = 0; + this.beamTime = 0; + this.beamCount = 0; writeCustomData(GregtechDataCodes.UPDATE_PARTICLE, this::writeParticles); } } @@ -239,11 +248,13 @@ public void onRemoval() { private void writeParticles(@NotNull PacketBuffer buf) { buf.writeVarInt(beamCount); + buf.writeVarInt(beamTime); } @SideOnly(Side.CLIENT) private void readParticles(@NotNull PacketBuffer buf) { beamCount = buf.readVarInt(); + beamTime = buf.readVarInt(); if (beamParticles == null) { beamParticles = new GTLaserBeamParticle[17][2]; } @@ -306,7 +317,7 @@ private void readParticles(@NotNull PacketBuffer buf) { @NotNull @SideOnly(Side.CLIENT) private GTLaserBeamParticle createALParticles(Vector3 startPos, Vector3 endPos) { - return new GTLaserBeamParticle(this, startPos, endPos) + return new GTLaserBeamParticle(this, startPos, endPos, beamTime) .setBody(LASER_LOCATION) .setBeamHeight(0.125f) // Try commenting or adjusting on the next four lines to see what happens