diff options
Diffstat (limited to 'src/main/java/gregtech')
3 files changed, 54 insertions, 5 deletions
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<MTEBl blackHoleStatus = 1; blackHoleStability = 100; catalyzingCostModifier = 1; - rendererTileEntity = null; - destroyRenderBlock(); + if (rendererTileEntity != null) rendererTileEntity.startScaleChange(false); + collapseTimer = 40; return; } } @@ -574,6 +574,10 @@ public class MTEBlackHoleCompressor extends MTEExtendedPowerMultiBlockBase<MTEBl return super.onRunningTick(aStack); } + // Asynchronous timer to destroy render block after collapse animation is done playing. + // This might not sync perfectly to the renderer but this is very low stakes + private int collapseTimer = -1; + @Override public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { super.onPostTick(aBaseMetaTileEntity, aTick); @@ -581,6 +585,13 @@ public class MTEBlackHoleCompressor extends MTEExtendedPowerMultiBlockBase<MTEBl playBlackHoleSounds(); } + if (collapseTimer != -1) { + if (collapseTimer == 0) { + destroyRenderBlock(); + } + collapseTimer--; + } + // Run stability checks once per second if a black hole is open if (blackHoleStatus == 1 || aTick % 20 != 0) return; @@ -719,6 +730,7 @@ public class MTEBlackHoleCompressor extends MTEExtendedPowerMultiBlockBase<MTEBl rendererTileEntity = (TileEntityBlackhole) base.getWorld() .getTileEntity(base.getXCoord() + x, base.getYCoord() + y, base.getZCoord() + z); + rendererTileEntity.startScaleChange(true); rendererTileEntity.setStability(blackHoleStability / 100F); } diff --git a/src/main/java/gregtech/common/tileentities/render/TileEntityBlackhole.java b/src/main/java/gregtech/common/tileentities/render/TileEntityBlackhole.java index f15aa45eee..2f7114e405 100644 --- a/src/main/java/gregtech/common/tileentities/render/TileEntityBlackhole.java +++ b/src/main/java/gregtech/common/tileentities/render/TileEntityBlackhole.java @@ -10,12 +10,17 @@ public class TileEntityBlackhole extends TileEntity { // Should run from 0 to 1, >.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); |