From e763bd08b1ac3800ca259e1d16d63821b28e0067 Mon Sep 17 00:00:00 2001 From: kekzdealer Date: Mon, 18 May 2020 22:57:11 +0200 Subject: Implemented TESR for Space Elevator Capacitors. This allows me to change their colour saturation on the fly to sync it with the elevator charge state. - Added tooltip to the caps to tell players that the invisible top/bot faces are intended as a performance improvement --- .../tileentities/TE_SpaceElevatorCapacitor.java | 45 ++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/main/java/common/tileentities/TE_SpaceElevatorCapacitor.java (limited to 'src/main/java/common/tileentities/TE_SpaceElevatorCapacitor.java') diff --git a/src/main/java/common/tileentities/TE_SpaceElevatorCapacitor.java b/src/main/java/common/tileentities/TE_SpaceElevatorCapacitor.java new file mode 100644 index 0000000000..22a4954b0f --- /dev/null +++ b/src/main/java/common/tileentities/TE_SpaceElevatorCapacitor.java @@ -0,0 +1,45 @@ +package common.tileentities; + +import net.minecraft.tileentity.TileEntity; + +public class TE_SpaceElevatorCapacitor extends TileEntity { + + private float chargeLevel = 0.0F; + + /** + * Called by the space elevator controller while charging + * @param charge + * Current elevator charge + * @param maxCharge + * Charge level it is trying to reach + */ + public void updateChargeLevel(int charge, int maxCharge) { + chargeLevel = ((float) charge) / ((float) maxCharge); + } + + /** + * Called by this block's renderer to calculate the block's colour saturation + * @return + * Charge level from 0.0F to 1.0F + */ + public float getChargeLevel() { + return chargeLevel; + } + + /** + * Called by the space elevator in case of power loss + */ + public void resetChargeLevel() { + chargeLevel = 0.0F; + } + + long tickCounter = 0; + @Override + public void updateEntity() { + if(tickCounter == 20){ + chargeLevel = Float.compare(chargeLevel, 0.0F) == 0 ? 1.0F : 0.0F; + tickCounter = 0; + } + tickCounter++; + } +} -- cgit From 38253907f072735933c222690fc782ebcf3ffbda Mon Sep 17 00:00:00 2001 From: kekzdealer Date: Mon, 18 May 2020 23:14:49 +0200 Subject: trying out fancy jdoc links --- .../tileentities/TE_SpaceElevatorCapacitor.java | 31 ++++++++++++++-------- 1 file changed, 20 insertions(+), 11 deletions(-) (limited to 'src/main/java/common/tileentities/TE_SpaceElevatorCapacitor.java') diff --git a/src/main/java/common/tileentities/TE_SpaceElevatorCapacitor.java b/src/main/java/common/tileentities/TE_SpaceElevatorCapacitor.java index 22a4954b0f..758a7e576f 100644 --- a/src/main/java/common/tileentities/TE_SpaceElevatorCapacitor.java +++ b/src/main/java/common/tileentities/TE_SpaceElevatorCapacitor.java @@ -5,9 +5,10 @@ import net.minecraft.tileentity.TileEntity; public class TE_SpaceElevatorCapacitor extends TileEntity { private float chargeLevel = 0.0F; + private boolean isDamaged = false; /** - * Called by the space elevator controller while charging + * Called by {@link GTMTE_SpaceElevator} while charging * @param charge * Current elevator charge * @param maxCharge @@ -18,7 +19,7 @@ public class TE_SpaceElevatorCapacitor extends TileEntity { } /** - * Called by this block's renderer to calculate the block's colour saturation + * Called by {@link client.renderer.TESR_SECapacitor} to calculate the block's colour saturation * @return * Charge level from 0.0F to 1.0F */ @@ -27,19 +28,27 @@ public class TE_SpaceElevatorCapacitor extends TileEntity { } /** - * Called by the space elevator in case of power loss + * Called by {@link GTMTE_SpaceElevator} in case of power loss */ public void resetChargeLevel() { chargeLevel = 0.0F; } - long tickCounter = 0; - @Override - public void updateEntity() { - if(tickCounter == 20){ - chargeLevel = Float.compare(chargeLevel, 0.0F) == 0 ? 1.0F : 0.0F; - tickCounter = 0; - } - tickCounter++; + /** + * Called by {@link GTMTE_SpaceElevator} in case of maintenance issues + * @param isDamaged + * has maintenance issue + */ + public void setIsDamaged(boolean isDamaged) { + this.isDamaged = isDamaged; + } + + /** + * Called by {@link client.renderer.TESR_SECapacitor} to check whether the block should be rendered red + * @return + * should be rendered red + */ + public boolean isDamaged() { + return isDamaged; } } -- cgit From 1efc48cde1f27dabd6be1ca4220b8f81fa4b366e Mon Sep 17 00:00:00 2001 From: kekzdealer Date: Tue, 19 May 2020 00:05:52 +0200 Subject: capacitors pulse red on maintenance --- src/main/java/client/renderer/TESR_SECapacitor.java | 11 ++++++----- .../common/tileentities/TE_SpaceElevatorCapacitor.java | 2 +- .../blocks/SpaceElevatorCapacitor_side_renderbase.png | Bin 0 -> 171 bytes 3 files changed, 7 insertions(+), 6 deletions(-) create mode 100644 src/main/resources/assets/kekztech/textures/blocks/SpaceElevatorCapacitor_side_renderbase.png (limited to 'src/main/java/common/tileentities/TE_SpaceElevatorCapacitor.java') diff --git a/src/main/java/client/renderer/TESR_SECapacitor.java b/src/main/java/client/renderer/TESR_SECapacitor.java index 4a14ffa28b..16c820917d 100644 --- a/src/main/java/client/renderer/TESR_SECapacitor.java +++ b/src/main/java/client/renderer/TESR_SECapacitor.java @@ -9,14 +9,12 @@ import net.minecraft.util.ResourceLocation; public class TESR_SECapacitor extends TileEntitySpecialRenderer { - private static final ResourceLocation capSide = new ResourceLocation(KekzCore.MODID, "textures/blocks/SpaceElevatorCapacitor_side_fullbase.png"); + private static final ResourceLocation capSide = new ResourceLocation(KekzCore.MODID, "textures/blocks/SpaceElevatorCapacitor_side_renderbase.png"); @Override public void renderTileEntityAt(TileEntity te, double x, double y, double z, float partialTick) { final Tessellator tessellator = Tessellator.instance; final TE_SpaceElevatorCapacitor teCap = (TE_SpaceElevatorCapacitor) te; - // Scale saturation, rounding up - final int sat = (int) Math.ceil(teCap.getChargeLevel() * 255); // Setup vertices final double fbr_x = x + 1; final double fbr_z = z + 1; @@ -41,9 +39,12 @@ public class TESR_SECapacitor extends TileEntitySpecialRenderer { tessellator.startDrawingQuads(); // Render the caps as red if there are maintenance issues if(teCap.isDamaged()) { - tessellator.setColorRGBA(255, 0, 0, 255); + final float wave = (float) Math.abs(Math.sin((te.getWorldObj().getTotalWorldTime() + partialTick) / 20.0D)); + final int redSat = 64 + (int) Math.ceil(191 * wave); + tessellator.setColorRGBA(redSat, 0, 0, 255); } else { - tessellator.setColorRGBA(sat, sat, sat, 255); + final int sat = (int) Math.ceil(teCap.getChargeLevel() * 255); + tessellator.setColorRGBA(0, 0, sat, 255); } tessellator.setBrightness(255); // (DOWN and UP faces are not rendered as they will not ever be visible in the Space Elevator structure) diff --git a/src/main/java/common/tileentities/TE_SpaceElevatorCapacitor.java b/src/main/java/common/tileentities/TE_SpaceElevatorCapacitor.java index 758a7e576f..a8de775f98 100644 --- a/src/main/java/common/tileentities/TE_SpaceElevatorCapacitor.java +++ b/src/main/java/common/tileentities/TE_SpaceElevatorCapacitor.java @@ -5,7 +5,7 @@ import net.minecraft.tileentity.TileEntity; public class TE_SpaceElevatorCapacitor extends TileEntity { private float chargeLevel = 0.0F; - private boolean isDamaged = false; + private boolean isDamaged = true; /** * Called by {@link GTMTE_SpaceElevator} while charging diff --git a/src/main/resources/assets/kekztech/textures/blocks/SpaceElevatorCapacitor_side_renderbase.png b/src/main/resources/assets/kekztech/textures/blocks/SpaceElevatorCapacitor_side_renderbase.png new file mode 100644 index 0000000000..32aee141d9 Binary files /dev/null and b/src/main/resources/assets/kekztech/textures/blocks/SpaceElevatorCapacitor_side_renderbase.png differ -- cgit