From 25f01262c6de6a25078ca97822de2b068b23c212 Mon Sep 17 00:00:00 2001 From: Mary <33456283+FourIsTheNumber@users.noreply.github.com> Date: Sun, 20 Oct 2024 09:08:15 -0400 Subject: Blackhole render enhancement (#3390) Co-authored-by: Martin Robertz --- .../gregtech/common/render/BlackholeRenderer.java | 18 +++++++++++++--- .../multi/compressor/MTEBlackHoleCompressor.java | 16 ++++++++++++-- .../tileentities/render/TileEntityBlackhole.java | 25 ++++++++++++++++++++++ 3 files changed, 54 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/main/java/gregtech/common/render/BlackholeRenderer.java b/src/main/java/gregtech/common/render/BlackholeRenderer.java index 2693844708..78432fbc6d 100644 --- a/src/main/java/gregtech/common/render/BlackholeRenderer.java +++ b/src/main/java/gregtech/common/render/BlackholeRenderer.java @@ -7,6 +7,7 @@ import java.nio.FloatBuffer; import net.minecraft.client.renderer.ActiveRenderInfo; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.MathHelper; import net.minecraft.util.ResourceLocation; import net.minecraftforge.client.model.AdvancedModelLoader; @@ -118,10 +119,21 @@ public class BlackholeRenderer extends TileEntitySpecialRenderer { } private void renderBlackHole(TileEntityBlackhole tile, double x, double y, double z, float timer) { - blackholeProgram.use(); bindTexture(blackholeTexture); GL20.glUniform1f(u_Stability, tile.getStability()); + + float startTime = tile.getStartTime(); + float scaleF = timer - startTime; + // If this is false we're shrinking, so subtract from 40 to translate to reversed scaling + if (!tile.getScaling()) { + scaleF = 40 - scaleF; + } + scaleF = MathHelper.clamp_float(scaleF / 40, 0, 1) * modelScale; + // Smootherstep function to make it scale nicer + scaleF = scaleF * scaleF * scaleF * (scaleF * (6.0f * scaleF - 15.0f) + 10.0f); + GL20.glUniform1f(u_Scale, scaleF); + modelMatrixStack.clear(); float xLocal = ((float) x + .5f); @@ -206,7 +218,7 @@ public class BlackholeRenderer extends TileEntitySpecialRenderer { y, z, tile.getWorldObj() - .getWorldTime() + timeSinceLastTick); + .getTotalWorldTime() + timeSinceLastTick); } renderBlackHole( @@ -215,7 +227,7 @@ public class BlackholeRenderer extends TileEntitySpecialRenderer { y, z, tile.getWorldObj() - .getWorldTime() + timeSinceLastTick); + .getTotalWorldTime() + timeSinceLastTick); } diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/compressor/MTEBlackHoleCompressor.java b/src/main/java/gregtech/common/tileentities/machines/multi/compressor/MTEBlackHoleCompressor.java index 7b444c6573..2d84f032af 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/compressor/MTEBlackHoleCompressor.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/compressor/MTEBlackHoleCompressor.java @@ -496,8 +496,8 @@ public class MTEBlackHoleCompressor extends MTEExtendedPowerMultiBlockBase.5 starts showing changes private float stability = 1; + // true = growing, false = shrinking + private boolean scaling = true; + private long startTime = 0; private float laserR = 0.318f, laserG = 0.157f, laserB = 0.533f; private boolean laserRender = false; private static final String NBT_TAG = "BLACKHOLE"; private static final String STABILITY_NBT_TAG = NBT_TAG + "STABILITY"; + private static final String START_TIME_NBT_TAG = NBT_TAG + "START_TIME"; + private static final String SCALING_NBT_TAG = NBT_TAG + "SCALING"; private static final String COLOR_RED_NBT_TAG = NBT_TAG + "COLOR_RED"; private static final String COLOR_GREEN_NBT_TAG = NBT_TAG + "COLOR_GREEN"; private static final String COLOR_BLUE_NBT_TAG = NBT_TAG + "COLOR_BLUE"; @@ -53,6 +58,22 @@ public class TileEntityBlackhole extends TileEntity { return laserRender; } + public void startScaleChange(boolean scaling) { + if (!worldObj.isRemote) { + this.startTime = worldObj.getTotalWorldTime(); + this.scaling = scaling; + updateToClient(); + } + } + + public long getStartTime() { + return startTime; + } + + public boolean getScaling() { + return scaling; + } + public void setStability(float stability) { // Can probably be simplified, maps stability > .5 as 1, and stability <.5 from 0 to 1 if (!worldObj.isRemote) { @@ -68,6 +89,8 @@ public class TileEntityBlackhole extends TileEntity { public void writeToNBT(NBTTagCompound compound) { super.writeToNBT(compound); compound.setFloat(STABILITY_NBT_TAG, stability); + compound.setBoolean(SCALING_NBT_TAG, scaling); + compound.setLong(START_TIME_NBT_TAG, startTime); compound.setFloat(COLOR_RED_NBT_TAG, laserR); compound.setFloat(COLOR_GREEN_NBT_TAG, laserG); compound.setFloat(COLOR_BLUE_NBT_TAG, laserB); @@ -77,6 +100,8 @@ public class TileEntityBlackhole extends TileEntity { @Override public void readFromNBT(NBTTagCompound compound) { stability = compound.getFloat(STABILITY_NBT_TAG); + scaling = compound.getBoolean(SCALING_NBT_TAG); + startTime = compound.getLong(START_TIME_NBT_TAG); laserR = compound.getFloat(COLOR_RED_NBT_TAG); laserG = compound.getFloat(COLOR_GREEN_NBT_TAG); laserB = compound.getFloat(COLOR_BLUE_NBT_TAG); -- cgit