aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorkekzdealer <kekzdealer@gmail.com>2020-05-18 22:57:11 +0200
committerkekzdealer <kekzdealer@gmail.com>2020-05-18 22:57:11 +0200
commite763bd08b1ac3800ca259e1d16d63821b28e0067 (patch)
treefce8bf7aeda3b53ff094e50d34b87e5dc3fafb18 /src/main
parenta785ef53e7e135fe59a95d3412b73a3a6a31da38 (diff)
downloadGT5-Unofficial-e763bd08b1ac3800ca259e1d16d63821b28e0067.tar.gz
GT5-Unofficial-e763bd08b1ac3800ca259e1d16d63821b28e0067.tar.bz2
GT5-Unofficial-e763bd08b1ac3800ca259e1d16d63821b28e0067.zip
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
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/client/renderer/ConduitRenderer.java4
-rw-r--r--src/main/java/client/renderer/TESR_SECapacitor.java69
-rw-r--r--src/main/java/client/renderer/TESR_SETether.java (renamed from src/main/java/client/renderer/TetherRenderer.java)38
-rw-r--r--src/main/java/common/itemBlocks/IB_SpaceElevatorCapacitor.java22
-rw-r--r--src/main/java/common/tileentities/TE_SpaceElevatorCapacitor.java45
-rw-r--r--src/main/java/kekztech/KekzCore.java6
-rw-r--r--src/main/resources/assets/kekztech/lang/en_US.lang1
7 files changed, 161 insertions, 24 deletions
diff --git a/src/main/java/client/renderer/ConduitRenderer.java b/src/main/java/client/renderer/ConduitRenderer.java
index 9619a73241..9266d22f55 100644
--- a/src/main/java/client/renderer/ConduitRenderer.java
+++ b/src/main/java/client/renderer/ConduitRenderer.java
@@ -12,14 +12,14 @@ import net.minecraftforge.common.util.ForgeDirection;
public class ConduitRenderer implements ISimpleBlockRenderingHandler {
public static final int RID = RenderingRegistry.getNextAvailableRenderId();
- private static final ConduitRenderer instance = new ConduitRenderer();
+ private static final ConduitRenderer INSTANCE = new ConduitRenderer();
private ConduitRenderer() {
}
public static ConduitRenderer getInstance() {
- return instance;
+ return INSTANCE;
}
@Override
diff --git a/src/main/java/client/renderer/TESR_SECapacitor.java b/src/main/java/client/renderer/TESR_SECapacitor.java
new file mode 100644
index 0000000000..b34e46faff
--- /dev/null
+++ b/src/main/java/client/renderer/TESR_SECapacitor.java
@@ -0,0 +1,69 @@
+package client.renderer;
+
+import common.tileentities.TE_SpaceElevatorCapacitor;
+import kekztech.KekzCore;
+import net.minecraft.client.renderer.Tessellator;
+import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
+import net.minecraft.tileentity.TileEntity;
+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");
+
+ @Override
+ public void renderTileEntityAt(TileEntity te, double x, double y, double z, float partialTick) {
+ final Tessellator tessellator = Tessellator.instance;
+ // Clamp saturation to a minimum of 40% and scale, rounding up
+ final int sat = (int) Math.ceil(
+ 255 * Math.max(((TE_SpaceElevatorCapacitor) te).getChargeLevel(), 0.4F)
+ );
+ // Setup vertices
+ final double fbr_x = x + 1;
+ final double fbr_z = z + 1;
+
+ final double ftr_y = y + 1;
+
+ final double uv_a_u = 1.0D;
+ final double uv_a_v = 1.0D;
+
+ final double uv_b_u = 1.0D;
+ final double uv_b_v = 0.0D;
+
+ final double uv_c_u = 0.0D;
+ final double uv_c_v = 0.0D;
+
+ final double uv_d_u = 0.0D;
+ final double uv_d_v = 1.0D;
+ // Render sides
+ super.bindTexture(capSide);
+
+ // Prepare Tessellator
+ tessellator.startDrawingQuads();
+ tessellator.setColorRGBA(sat, sat, sat, 255);
+ tessellator.setBrightness(255);
+ // (DOWN and UP faces are not rendered as they will not ever be visible in the Space Elevator structure)
+ // NORTH
+ tessellator.addVertexWithUV(x, y, z, uv_a_u, uv_a_v);
+ tessellator.addVertexWithUV(x, ftr_y, z, uv_b_u, uv_b_v);
+ tessellator.addVertexWithUV(fbr_x, ftr_y, z, uv_c_u, uv_c_v);
+ tessellator.addVertexWithUV(fbr_x, y, z, uv_d_u, uv_d_v);
+ // SOUTH
+ tessellator.addVertexWithUV(fbr_x, y, fbr_z, uv_a_u, uv_a_v);
+ tessellator.addVertexWithUV(fbr_x, ftr_y, fbr_z, uv_b_u, uv_b_v);
+ tessellator.addVertexWithUV(x, ftr_y, fbr_z, uv_c_u, uv_c_v);
+ tessellator.addVertexWithUV(x, y, fbr_z, uv_d_u, uv_d_v);
+ // WEST
+ tessellator.addVertexWithUV(x, y, fbr_z, uv_a_u, uv_a_v);
+ tessellator.addVertexWithUV(x, ftr_y, fbr_z, uv_b_u, uv_b_v);
+ tessellator.addVertexWithUV(x, ftr_y, z, uv_c_u, uv_c_v);
+ tessellator.addVertexWithUV(x, y, z, uv_d_u, uv_d_v);
+ // EAST
+ tessellator.addVertexWithUV(fbr_x, y, z, uv_a_u, uv_a_v);
+ tessellator.addVertexWithUV(fbr_x, ftr_y, z, uv_b_u, uv_b_v);
+ tessellator.addVertexWithUV(fbr_x, ftr_y, fbr_z, uv_c_u, uv_c_v);
+ tessellator.addVertexWithUV(fbr_x, y, fbr_z, uv_d_u, uv_d_v);
+ // Draw!
+ tessellator.draw();
+ }
+}
diff --git a/src/main/java/client/renderer/TetherRenderer.java b/src/main/java/client/renderer/TESR_SETether.java
index 7e69122846..890d25fdb2 100644
--- a/src/main/java/client/renderer/TetherRenderer.java
+++ b/src/main/java/client/renderer/TESR_SETether.java
@@ -1,5 +1,6 @@
package client.renderer;
+import common.tileentities.TE_SpaceElevatorCapacitor;
import common.tileentities.TE_SpaceElevatorTether;
import kekztech.KekzCore;
import net.minecraft.client.renderer.OpenGlHelper;
@@ -9,11 +10,12 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
-public class TetherRenderer extends TileEntitySpecialRenderer {
+public class TESR_SETether extends TileEntitySpecialRenderer {
private static final ResourceLocation tetherBeamTexture = new ResourceLocation(KekzCore.MODID, "textures/effects/Tether_beam.png");
- public void renderTileEntityAt(TE_SpaceElevatorTether teTether, double x, double y, double z, float partialTick) {
+ @Override
+ public void renderTileEntityAt(TileEntity te, double x, double y, double z, float partialTick) {
float beamLengthScale = 1.0F; // [0.0F, 1.0F] -> linear scale from 0 to 256
GL11.glAlphaFunc(GL11.GL_GREATER, 0.1F);
@@ -33,20 +35,20 @@ public class TetherRenderer extends TileEntitySpecialRenderer {
tessellator.startDrawingQuads();
tessellator.setColorRGBA(255, 255, 255, 32);
// Variables stuff II
- double halfBeamWidth = 0.38D;
- double d_rot1 = 0.5D + Math.cos(2.356194490192345D) * halfBeamWidth; // rotates the beam...
- double d_rot2 = 0.5D + Math.sin(2.356194490192345D) * halfBeamWidth;
- double d_rot3 = 0.5D + Math.cos((Math.PI / 4D)) * halfBeamWidth;
- double d_rot4 = 0.5D + Math.sin((Math.PI / 4D)) * halfBeamWidth;
- double d_rot5 = 0.5D + Math.cos(3.9269908169872414D) * halfBeamWidth;
- double d_rot6 = 0.5D + Math.sin(3.9269908169872414D) * halfBeamWidth;
- double d_rot7 = 0.5D + Math.cos(5.497787143782138D) * halfBeamWidth;
- double d_rot8 = 0.5D + Math.sin(5.497787143782138D) * halfBeamWidth; // ...until here
- double height = 256.0F * beamLengthScale;
- double uv_x1 = 0.0D;
- double uv_x2 = 1.0D;
- double uv_y1 = -1.0D; // This makes the beam stream upwards if you add a time sensitive number to it
- double uv_y2 = (double)(256.0F * beamLengthScale) * (0.5D / halfBeamWidth) + uv_y1;
+ final double halfBeamWidth = 0.38D;
+ final double d_rot1 = 0.5D + Math.cos(2.356194490192345D) * halfBeamWidth; // rotates the beam...
+ final double d_rot2 = 0.5D + Math.sin(2.356194490192345D) * halfBeamWidth;
+ final double d_rot3 = 0.5D + Math.cos((Math.PI / 4D)) * halfBeamWidth;
+ final double d_rot4 = 0.5D + Math.sin((Math.PI / 4D)) * halfBeamWidth;
+ final double d_rot5 = 0.5D + Math.cos(3.9269908169872414D) * halfBeamWidth;
+ final double d_rot6 = 0.5D + Math.sin(3.9269908169872414D) * halfBeamWidth;
+ final double d_rot7 = 0.5D + Math.cos(5.497787143782138D) * halfBeamWidth;
+ final double d_rot8 = 0.5D + Math.sin(5.497787143782138D) * halfBeamWidth; // ...until here
+ final double height = 256.0F * beamLengthScale;
+ final double uv_x1 = 0.0D;
+ final double uv_x2 = 1.0D;
+ final double uv_y1 = -1.0D; // This makes the beam stream upwards if you add a time sensitive number to it
+ final double uv_y2 = (double)(256.0F * beamLengthScale) * (0.5D / halfBeamWidth) + uv_y1;
// Construct mesh with texture
tessellator.addVertexWithUV(x + d_rot1, y + height, z + d_rot2, uv_x2, uv_y2);
tessellator.addVertexWithUV(x + d_rot1, y, z + d_rot2, uv_x2, uv_y1);
@@ -73,8 +75,4 @@ public class TetherRenderer extends TileEntitySpecialRenderer {
GL11.glDepthMask(true);
}
- @Override
- public void renderTileEntityAt(TileEntity te, double p_147500_2_, double p_147500_4_, double p_147500_6_, float p_147500_8_) {
- this.renderTileEntityAt((TE_SpaceElevatorTether) te, p_147500_2_, p_147500_4_, p_147500_6_, p_147500_8_);
- }
}
diff --git a/src/main/java/common/itemBlocks/IB_SpaceElevatorCapacitor.java b/src/main/java/common/itemBlocks/IB_SpaceElevatorCapacitor.java
new file mode 100644
index 0000000000..053cb2c567
--- /dev/null
+++ b/src/main/java/common/itemBlocks/IB_SpaceElevatorCapacitor.java
@@ -0,0 +1,22 @@
+package common.itemBlocks;
+
+import net.minecraft.block.Block;
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.item.ItemBlock;
+import net.minecraft.item.ItemStack;
+import net.minecraft.util.StatCollector;
+
+import java.util.List;
+
+public class IB_SpaceElevatorCapacitor extends ItemBlock {
+
+ public IB_SpaceElevatorCapacitor(Block block) {
+ super(block);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public void addInformation(ItemStack stack, EntityPlayer player, List lines, boolean advancedTooltips) {
+ lines.add(StatCollector.translateToLocal("tile.kekztech_spaceelevatorcapacitor_block.desc"));
+ }
+}
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++;
+ }
+}
diff --git a/src/main/java/kekztech/KekzCore.java b/src/main/java/kekztech/KekzCore.java
index a160c3b7e7..7574c1f399 100644
--- a/src/main/java/kekztech/KekzCore.java
+++ b/src/main/java/kekztech/KekzCore.java
@@ -1,6 +1,7 @@
package kekztech;
-import client.renderer.TetherRenderer;
+import client.renderer.TESR_SECapacitor;
+import client.renderer.TESR_SETether;
import common.Blocks;
import common.Recipes;
import common.Researches;
@@ -76,7 +77,8 @@ public class KekzCore {
NetworkRegistry.INSTANCE.registerGuiHandler(instance, new GuiHandler());
// Register TESR
- ClientRegistry.bindTileEntitySpecialRenderer(TE_SpaceElevatorTether.class, new TetherRenderer());
+ ClientRegistry.bindTileEntitySpecialRenderer(TE_SpaceElevatorTether.class, new TESR_SETether());
+ ClientRegistry.bindTileEntitySpecialRenderer(TE_SpaceElevatorCapacitor.class, new TESR_SECapacitor());
Researches.preInit();
}
diff --git a/src/main/resources/assets/kekztech/lang/en_US.lang b/src/main/resources/assets/kekztech/lang/en_US.lang
index f922219b1c..b86fe84543 100644
--- a/src/main/resources/assets/kekztech/lang/en_US.lang
+++ b/src/main/resources/assets/kekztech/lang/en_US.lang
@@ -181,4 +181,5 @@ tile.kekztech_spaceelevator_block.0.name=Space Elevator Base
tile.kekztech_spaceelevator_block.1.name=Space Elevator Coil Holder
tile.kekztech_spaceelevator_block.desc=Part of the Space Elevator Base Station
tile.kekztech_spaceelevatorcapacitor_block.name=Space Elevator Capacitor
+tile.kekztech_spaceelevatorcapacitor_block.desc=The see-through is good for your FPS!
tile.kekztech_spaceelevatortether_block.name=Space Elevator Tether \ No newline at end of file