Skip to content
This repository has been archived by the owner on May 24, 2024. It is now read-only.

Commit

Permalink
Optimise EOH Renderer and fix transparency bug (#258)
Browse files Browse the repository at this point in the history
* Clean up EOH rendering and fix transparency bug

* Optimise the renderer somewhat

* Lower poly count of space shell

* spotlessApply

* fix wci

* update bs+deps

* Change EOH render hitbox

* Imports + spotless

* Fix bounding box and culling

* Update src/main/java/com/github/technus/tectech/rendering/EOH/EOH_RenderingUtils.java

Co-authored-by: Raven Szewczyk <[email protected]>

* Update src/main/java/com/github/technus/tectech/rendering/EOH/EOH_RenderingUtils.java

Co-authored-by: Raven Szewczyk <[email protected]>

* Update src/main/java/com/github/technus/tectech/rendering/EOH/EOH_RenderingUtils.java

Co-authored-by: Raven Szewczyk <[email protected]>

* Add constant

* blendfunc

* Hitbox change

* Spotless

---------

Co-authored-by: GTNH-Colen <[email protected]>
Co-authored-by: GitHub GTNH Actions <unknown>
Co-authored-by: Martin Robertz <[email protected]>
Co-authored-by: Connor Colenso <colen@CONNORSPC>
Co-authored-by: Raven Szewczyk <[email protected]>
  • Loading branch information
5 people authored Dec 3, 2023
1 parent 7e0704c commit 7a4a430
Show file tree
Hide file tree
Showing 22 changed files with 11,786 additions and 81,189 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.github.technus.tectech.loader;

import static com.github.technus.tectech.TecTech.*;
import static com.github.technus.tectech.TecTech.LOGGER;
import static com.github.technus.tectech.TecTech.configTecTech;
import static com.github.technus.tectech.TecTech.creativeTabTecTech;
import static com.github.technus.tectech.TecTech.proxy;
import static com.github.technus.tectech.loader.TecTechConfig.DEBUG_MODE;
import static gregtech.api.enums.Mods.NewHorizonsCoreMod;
import static gregtech.api.enums.Mods.TwilightForest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,28 @@

import static com.github.technus.tectech.loader.recipe.BaseRecipeLoader.getItemContainer;
import static com.google.common.math.LongMath.pow;
import static gregtech.api.enums.Mods.*;
import static gregtech.api.enums.Mods.Avaritia;
import static gregtech.api.enums.Mods.AvaritiaAddons;
import static gregtech.api.enums.Mods.BartWorks;
import static gregtech.api.enums.Mods.BloodMagic;
import static gregtech.api.enums.Mods.DraconicEvolution;
import static gregtech.api.enums.Mods.EternalSingularity;
import static gregtech.api.enums.Mods.ExtraUtilities;
import static gregtech.api.enums.Mods.GTNHIntergalactic;
import static gregtech.api.enums.Mods.GTPlusPlus;
import static gregtech.api.enums.Mods.GTPlusPlusEverglades;
import static gregtech.api.enums.Mods.GalaxySpace;
import static gregtech.api.enums.Mods.GoodGenerator;
import static gregtech.api.enums.Mods.GraviSuite;
import static gregtech.api.enums.Mods.GregTech;
import static gregtech.api.enums.Mods.IndustrialCraft2;
import static gregtech.api.enums.Mods.KekzTech;
import static gregtech.api.enums.Mods.KubaTech;
import static gregtech.api.enums.Mods.NewHorizonsCoreMod;
import static gregtech.api.enums.Mods.SGCraft;
import static gregtech.api.enums.Mods.SuperSolarPanels;
import static gregtech.api.enums.Mods.Thaumcraft;
import static gregtech.api.enums.Mods.TinkersGregworks;
import static gregtech.api.util.GT_ModHandler.getModItem;
import static gregtech.api.util.GT_RecipeBuilder.MINUTES;
import static gregtech.api.util.GT_RecipeBuilder.SECONDS;
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
import net.minecraftforge.common.util.ForgeDirection;

import com.github.technus.tectech.Reference;
import com.github.technus.tectech.rendering.EOH.EOH_ItemRenderer;
import com.github.technus.tectech.rendering.EOH.EOH_TESR;
import com.github.technus.tectech.thing.block.QuantumGlassBlock;
import com.github.technus.tectech.thing.block.QuantumGlassRender;
import com.github.technus.tectech.thing.block.RenderEyeOfHarmony;
import com.github.technus.tectech.thing.block.TileEyeOfHarmony;
import com.github.technus.tectech.thing.item.RenderEyeOfHarmonyItem;
import com.gtnewhorizon.structurelib.entity.fx.WeightlessParticleFX;

import cpw.mods.fml.client.FMLClientHandler;
Expand All @@ -35,9 +35,9 @@ public void registerRenderInfo() {
RenderingRegistry.registerBlockHandler(QuantumGlassBlock.renderID, new QuantumGlassRender());

MinecraftForgeClient
.registerItemRenderer(Item.getItemFromBlock(eyeOfHarmonyRenderBlock), new RenderEyeOfHarmonyItem());
.registerItemRenderer(Item.getItemFromBlock(eyeOfHarmonyRenderBlock), new EOH_ItemRenderer());

ClientRegistry.bindTileEntitySpecialRenderer(TileEyeOfHarmony.class, new RenderEyeOfHarmony());
ClientRegistry.bindTileEntitySpecialRenderer(TileEyeOfHarmony.class, new EOH_TESR());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.github.technus.tectech.thing.item;
package com.github.technus.tectech.rendering.EOH;

import static com.github.technus.tectech.thing.block.RenderEyeOfHarmony.STAR_LAYER_0;
import static com.github.technus.tectech.thing.block.RenderEyeOfHarmony.STAR_LAYER_1;
import static com.github.technus.tectech.thing.block.RenderEyeOfHarmony.STAR_LAYER_2;
import static com.github.technus.tectech.thing.block.RenderEyeOfHarmony.starModel;
import static com.github.technus.tectech.rendering.EOH.EOH_TESR.STAR_LAYER_0;
import static com.github.technus.tectech.rendering.EOH.EOH_TESR.STAR_LAYER_1;
import static com.github.technus.tectech.rendering.EOH.EOH_TESR.STAR_LAYER_2;
import static com.github.technus.tectech.rendering.EOH.EOH_TESR.starModel;
import static java.lang.Math.pow;

import net.minecraft.item.ItemStack;
Expand All @@ -14,7 +14,7 @@

import cpw.mods.fml.client.FMLClientHandler;

public class RenderEyeOfHarmonyItem implements IItemRenderer {
public class EOH_ItemRenderer implements IItemRenderer {

@Override
public boolean handleRenderType(ItemStack item, ItemRenderType type) {
Expand Down Expand Up @@ -74,15 +74,9 @@ private void renderStarLayer(int layer, ResourceLocation texture, float alpha) {
GL11.glScalef(scale, scale, scale);

switch (layer) {
case 0:
GL11.glRotatef(130 + (System.currentTimeMillis() / 64) % 360, 0F, 1F, 1F);
break;
case 1:
GL11.glRotatef(-49 + (System.currentTimeMillis() / 64) % 360, 1F, 1F, 0F);
break;
case 2:
GL11.glRotatef(67 + (System.currentTimeMillis() / 64) % 360, 1F, 0F, 1F);
break;
case 0 -> GL11.glRotatef(130 + (System.currentTimeMillis() / 64) % 360, 0F, 1F, 1F);
case 1 -> GL11.glRotatef(-49 + (System.currentTimeMillis() / 64) % 360, 1F, 1F, 0F);
case 2 -> GL11.glRotatef(67 + (System.currentTimeMillis() / 64) % 360, 1F, 0F, 1F);
}

// Set colour and alpha (transparency) of the star layer.
Expand All @@ -93,6 +87,7 @@ private void renderStarLayer(int layer, ResourceLocation texture, float alpha) {
GL11.glDepthMask(true);
GL11.glEnable(GL11.GL_LIGHTING);

GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
// Finish animation.
GL11.glPopMatrix();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,265 @@
package com.github.technus.tectech.rendering.EOH;

import static com.github.technus.tectech.Reference.MODID;
import static com.github.technus.tectech.rendering.EOH.EOH_TESR.STAR_LAYER_0;
import static com.github.technus.tectech.rendering.EOH.EOH_TESR.STAR_LAYER_1;
import static com.github.technus.tectech.rendering.EOH.EOH_TESR.STAR_LAYER_2;
import static com.github.technus.tectech.rendering.EOH.EOH_TESR.spaceModel;
import static com.github.technus.tectech.rendering.EOH.EOH_TESR.starModel;
import static java.lang.Math.pow;

import java.awt.Color;

import net.minecraft.block.Block;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.util.IIcon;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.IItemRenderer;

import org.lwjgl.opengl.GL11;

import cpw.mods.fml.client.FMLClientHandler;

public abstract class EOH_RenderingUtils {

public static void renderStar(IItemRenderer.ItemRenderType type, Color color) {
GL11.glPushMatrix();

if (type == IItemRenderer.ItemRenderType.INVENTORY) GL11.glRotated(180, 0, 1, 0);
else if (type == IItemRenderer.ItemRenderType.EQUIPPED
|| type == IItemRenderer.ItemRenderType.EQUIPPED_FIRST_PERSON) {
GL11.glTranslated(0.5, 0.5, 0.5);
if (type == IItemRenderer.ItemRenderType.EQUIPPED) GL11.glRotated(90, 0, 1, 0);
}

// Render star stuff.
renderStarLayer(0, STAR_LAYER_0, color, 1.0f);
renderStarLayer(1, STAR_LAYER_1, color, 0.4f);
renderStarLayer(2, STAR_LAYER_2, color, 0.2f);

GL11.glPopMatrix();
}

public static void renderStar(IItemRenderer.ItemRenderType type) {
renderStar(type, new Color(1.0f, 0.4f, 0.05f, 1.0f));
}

private static void renderStarLayer(int layer, ResourceLocation texture, Color color, float alpha) {

// Begin animation.
GL11.glPushMatrix();

// OpenGL settings, not sure exactly what these do.

// Disables lighting, so star is always lit (I think).
GL11.glDisable(GL11.GL_LIGHTING);
// Culls triangles/quads facing away from the camera
GL11.glEnable(GL11.GL_CULL_FACE);
// Allows alpha blending to occur (transparency-based color mixing)
GL11.glEnable(GL11.GL_BLEND);
// ???
if (alpha < 1.0f) {
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE);
} else {
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
}

// Bind image to layer of star.
FMLClientHandler.instance().getClient().getTextureManager().bindTexture(texture);

// 0.01f magic number to shrink sphere obj down.
// Size obtained from the multis current recipe.
float scale = 0.01f;

// Put each subsequent layer further out.
scale *= pow(1.04f, layer);

// Scale the star up in the x, y and z directions.
GL11.glScalef(scale, scale, scale);

switch (layer) {
case 0 -> GL11.glRotatef(130 + (System.currentTimeMillis() / 64) % 360, 0F, 1F, 1F);
case 1 -> GL11.glRotatef(-49 + (System.currentTimeMillis() / 64) % 360, 1F, 1F, 0F);
case 2 -> GL11.glRotatef(67 + (System.currentTimeMillis() / 64) % 360, 1F, 0F, 1F);
}

// Set colour and alpha (transparency) of the star layer.
final float red = color.getRed() / 255.0f;
final float green = color.getGreen() / 255.0f;
final float blue = color.getBlue() / 255.0f;

GL11.glColor4f(red, green, blue, alpha);

starModel.renderAll();
GL11.glDisable(GL11.GL_BLEND);
GL11.glDepthMask(true);
GL11.glEnable(GL11.GL_LIGHTING);

GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
// Finish animation.
GL11.glPopMatrix();
}

public static void beginRenderingBlocksInWorld(final float blockSize) {
final Tessellator tes = Tessellator.instance;

GL11.glPushMatrix();
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);

GL11.glDisable(GL11.GL_LIGHTING);

tes.setColorOpaque_F(1f, 1f, 1f);
tes.startDrawingQuads();

GL11.glScalef(blockSize, blockSize, blockSize);
}

public static void endRenderingBlocksInWorld() {
Tessellator.instance.draw();

GL11.glPopAttrib();
GL11.glPopMatrix();
}

static final double[] BLOCK_X = { -0.5, -0.5, +0.5, +0.5, +0.5, +0.5, -0.5, -0.5 };
static final double[] BLOCK_Y = { +0.5, -0.5, -0.5, +0.5, +0.5, -0.5, -0.5, +0.5 };
static final double[] BLOCK_Z = { +0.5, +0.5, +0.5, +0.5, -0.5, -0.5, -0.5, -0.5 };

public static void addRenderedBlockInWorld(final Block block, final int meta, final double x, final double y,
final double z) {
final Tessellator tes = Tessellator.instance;

IIcon texture;

double minU;
double maxU;
double minV;
double maxV;

{
texture = block.getIcon(4, meta);

minU = texture.getMinU();
maxU = texture.getMaxU();
minV = texture.getMinV();
maxV = texture.getMaxV();

tes.addVertexWithUV(x + BLOCK_X[1], y + BLOCK_Y[1], z + BLOCK_Z[1], maxU, maxV);
tes.addVertexWithUV(x + BLOCK_X[0], y + BLOCK_Y[0], z + BLOCK_Z[0], maxU, minV);
tes.addVertexWithUV(x + BLOCK_X[7], y + BLOCK_Y[7], z + BLOCK_Z[7], minU, minV);
tes.addVertexWithUV(x + BLOCK_X[6], y + BLOCK_Y[6], z + BLOCK_Z[6], minU, maxV);
}

{
// Bottom face.
texture = block.getIcon(0, meta);

minU = texture.getMinU();
maxU = texture.getMaxU();
minV = texture.getMinV();
maxV = texture.getMaxV();

tes.addVertexWithUV(x + BLOCK_X[5], y + BLOCK_Y[5], z + BLOCK_Z[5], maxU, minV);
tes.addVertexWithUV(x + BLOCK_X[2], y + BLOCK_Y[2], z + BLOCK_Z[2], maxU, maxV);
tes.addVertexWithUV(x + BLOCK_X[1], y + BLOCK_Y[1], z + BLOCK_Z[1], minU, maxV);
tes.addVertexWithUV(x + BLOCK_X[6], y + BLOCK_Y[6], z + BLOCK_Z[6], minU, minV);
}

{
texture = block.getIcon(2, meta);

minU = texture.getMinU();
maxU = texture.getMaxU();
minV = texture.getMinV();
maxV = texture.getMaxV();

tes.addVertexWithUV(x + BLOCK_X[6], y + BLOCK_Y[6], z + BLOCK_Z[6], maxU, maxV);
tes.addVertexWithUV(x + BLOCK_X[7], y + BLOCK_Y[7], z + BLOCK_Z[7], maxU, minV);
tes.addVertexWithUV(x + BLOCK_X[4], y + BLOCK_Y[4], z + BLOCK_Z[4], minU, minV);
tes.addVertexWithUV(x + BLOCK_X[5], y + BLOCK_Y[5], z + BLOCK_Z[5], minU, maxV);
}

{
texture = block.getIcon(5, meta);

minU = texture.getMinU();
maxU = texture.getMaxU();
minV = texture.getMinV();
maxV = texture.getMaxV();

tes.addVertexWithUV(x + BLOCK_X[5], y + BLOCK_Y[5], z + BLOCK_Z[5], maxU, maxV);
tes.addVertexWithUV(x + BLOCK_X[4], y + BLOCK_Y[4], z + BLOCK_Z[4], maxU, minV);
tes.addVertexWithUV(x + BLOCK_X[3], y + BLOCK_Y[3], z + BLOCK_Z[3], minU, minV);
tes.addVertexWithUV(x + BLOCK_X[2], y + BLOCK_Y[2], z + BLOCK_Z[2], minU, maxV);
}

{
texture = block.getIcon(1, meta);

minU = texture.getMinU();
maxU = texture.getMaxU();
minV = texture.getMinV();
maxV = texture.getMaxV();

tes.addVertexWithUV(x + BLOCK_X[3], y + BLOCK_Y[3], z + BLOCK_Z[3], maxU, maxV);
tes.addVertexWithUV(x + BLOCK_X[4], y + BLOCK_Y[4], z + BLOCK_Z[4], maxU, minV);
tes.addVertexWithUV(x + BLOCK_X[7], y + BLOCK_Y[7], z + BLOCK_Z[7], minU, minV);
tes.addVertexWithUV(x + BLOCK_X[0], y + BLOCK_Y[0], z + BLOCK_Z[0], minU, maxV);
}

{
texture = block.getIcon(3, meta);

minU = texture.getMinU();
maxU = texture.getMaxU();
minV = texture.getMinV();
maxV = texture.getMaxV();

tes.addVertexWithUV(x + BLOCK_X[2], y + BLOCK_Y[2], z + BLOCK_Z[2], maxU, maxV);
tes.addVertexWithUV(x + BLOCK_X[3], y + BLOCK_Y[3], z + BLOCK_Z[3], maxU, minV);
tes.addVertexWithUV(x + BLOCK_X[0], y + BLOCK_Y[0], z + BLOCK_Z[0], minU, minV);
tes.addVertexWithUV(x + BLOCK_X[1], y + BLOCK_Y[1], z + BLOCK_Z[1], minU, maxV);
}
}

public static void renderBlockInWorld(final Block block, final int meta, final float blockSize) {
beginRenderingBlocksInWorld(blockSize);

addRenderedBlockInWorld(block, meta, 0, 0, 0);

endRenderingBlocksInWorld();
}

public static void renderOuterSpaceShell() {

// Save current OpenGL state.
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);

// Begin animation.
GL11.glPushMatrix();

// Disables lighting, so star is always lit.
GL11.glDisable(GL11.GL_LIGHTING);
// Merges colors of the various layers of the star.
// GL11.glEnable(GL11.GL_BLEND);

// Bind animation to layer of star.
FMLClientHandler.instance().getClient().getTextureManager()
.bindTexture(new ResourceLocation(MODID, "models/spaceLayer.png"));

final float scale = 0.01f * 17.5f;
// Scale the star up in the x, y and z directions.
GL11.glScalef(scale, scale, scale);

GL11.glColor4f(1, 1, 1, 1);

spaceModel.renderAll();

// Finish animation.
GL11.glPopMatrix();

// Restore previous OpenGL state.
GL11.glPopAttrib();
}

}
Loading

0 comments on commit 7a4a430

Please sign in to comment.