diff options
Diffstat (limited to 'src/main/java/tectech/rendering')
3 files changed, 456 insertions, 0 deletions
diff --git a/src/main/java/tectech/rendering/EOH/EOHItemRenderer.java b/src/main/java/tectech/rendering/EOH/EOHItemRenderer.java new file mode 100644 index 0000000000..b8650eb4c4 --- /dev/null +++ b/src/main/java/tectech/rendering/EOH/EOHItemRenderer.java @@ -0,0 +1,94 @@ +package tectech.rendering.EOH; + +import static java.lang.Math.pow; + +import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.client.IItemRenderer; + +import org.lwjgl.opengl.GL11; + +import cpw.mods.fml.client.FMLClientHandler; + +public class EOHItemRenderer implements IItemRenderer { + + @Override + public boolean handleRenderType(ItemStack item, ItemRenderType type) { + return true; + } + + @Override + public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper) { + return true; + } + + @Override + public void renderItem(ItemRenderType type, ItemStack item, Object... data) { + GL11.glPushMatrix(); + + if (type == ItemRenderType.INVENTORY) GL11.glRotated(180, 0, 1, 0); + else if (type == ItemRenderType.EQUIPPED || type == ItemRenderType.EQUIPPED_FIRST_PERSON) { + GL11.glTranslated(0.5, 0.5, 0.5); + if (type == ItemRenderType.EQUIPPED) GL11.glRotated(90, 0, 1, 0); + } + + // Render star stuff. + renderStarLayer(0, EOHTileEntitySR.STAR_LAYER_0, 1.0f); + renderStarLayer(1, EOHTileEntitySR.STAR_LAYER_1, 0.4f); + renderStarLayer(2, EOHTileEntitySR.STAR_LAYER_2, 0.2f); + + GL11.glPopMatrix(); + } + + private void renderStarLayer(int layer, ResourceLocation texture, 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 things out of line of sight? + GL11.glEnable(GL11.GL_CULL_FACE); + // Merges colours of the various layers of the star? + GL11.glEnable(GL11.GL_BLEND); + // ??? + GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + + // Bind animation 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. + GL11.glColor4f(1, 1, 1, alpha); + + EOHTileEntitySR.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(); + } + +} diff --git a/src/main/java/tectech/rendering/EOH/EOHRenderingUtils.java b/src/main/java/tectech/rendering/EOH/EOHRenderingUtils.java new file mode 100644 index 0000000000..7dec8ac62f --- /dev/null +++ b/src/main/java/tectech/rendering/EOH/EOHRenderingUtils.java @@ -0,0 +1,270 @@ +package tectech.rendering.EOH; + +import static java.lang.Math.pow; +import static tectech.Reference.MODID; +import static tectech.rendering.EOH.EOHTileEntitySR.STAR_LAYER_0; +import static tectech.rendering.EOH.EOHTileEntitySR.STAR_LAYER_1; +import static tectech.rendering.EOH.EOHTileEntitySR.STAR_LAYER_2; +import static tectech.rendering.EOH.EOHTileEntitySR.spaceModel; +import static tectech.rendering.EOH.EOHTileEntitySR.starModel; + +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 EOHRenderingUtils { + + public static void renderStar(IItemRenderer.ItemRenderType type, Color color, int size) { + 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, size); + renderStarLayer(1, STAR_LAYER_1, color, 0.4f, size); + renderStarLayer(2, STAR_LAYER_2, color, 0.2f, size); + + GL11.glPopMatrix(); + } + + public static void renderStar(IItemRenderer.ItemRenderType type, int size) { + renderStar(type, new Color(1.0f, 0.4f, 0.05f, 1.0f), size); + } + + public static void renderStarLayer(int layer, ResourceLocation texture, Color color, float alpha, int size) { + + // 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 * size; + + // 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(); + } + +} diff --git a/src/main/java/tectech/rendering/EOH/EOHTileEntitySR.java b/src/main/java/tectech/rendering/EOH/EOHTileEntitySR.java new file mode 100644 index 0000000000..5c8b4f6d94 --- /dev/null +++ b/src/main/java/tectech/rendering/EOH/EOHTileEntitySR.java @@ -0,0 +1,92 @@ +package tectech.rendering.EOH; + +import static tectech.rendering.EOH.EOHRenderingUtils.renderBlockInWorld; +import static tectech.rendering.EOH.EOHRenderingUtils.renderOuterSpaceShell; +import static tectech.rendering.EOH.EOHRenderingUtils.renderStar; + +import net.minecraft.client.renderer.texture.TextureMap; +import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.client.IItemRenderer; +import net.minecraftforge.client.model.AdvancedModelLoader; +import net.minecraftforge.client.model.IModelCustom; + +import org.lwjgl.opengl.GL11; + +import tectech.Reference; +import tectech.thing.block.TileEntityEyeOfHarmony; + +public class EOHTileEntitySR extends TileEntitySpecialRenderer { + + public static final ResourceLocation STAR_LAYER_0 = new ResourceLocation(Reference.MODID, "models/StarLayer0.png"); + public static final ResourceLocation STAR_LAYER_1 = new ResourceLocation(Reference.MODID, "models/StarLayer1.png"); + public static final ResourceLocation STAR_LAYER_2 = new ResourceLocation(Reference.MODID, "models/StarLayer2.png"); + public static IModelCustom starModel; + public static IModelCustom spaceModel; + + public EOHTileEntitySR() { + starModel = AdvancedModelLoader.loadModel(new ResourceLocation(Reference.MODID, "models/Star.obj")); + spaceModel = AdvancedModelLoader.loadModel(new ResourceLocation(Reference.MODID, "models/Space.obj")); + } + + @Override + public void renderTileEntityAt(TileEntity tile, double x, double y, double z, float timeSinceLastTick) { + if (!(tile instanceof TileEntityEyeOfHarmony EOHRenderTile)) return; + + GL11.glPushMatrix(); + // Required to centre the render to the middle of the block. + GL11.glTranslated(x + 0.5, y + 0.5, z + 0.5); + + GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS); + GL11.glDisable(GL11.GL_LIGHTING); + GL11.glDisable(GL11.GL_BLEND); + + // Space shell. + renderOuterSpaceShell(); + + // Render the planets. + renderOrbitObjects(EOHRenderTile); + + // Render the star itself. + renderStar(IItemRenderer.ItemRenderType.INVENTORY, 1); + GL11.glPopAttrib(); + + GL11.glPopMatrix(); + } + + private void renderOrbitObjects(final TileEntityEyeOfHarmony EOHRenderTile) { + + if (EOHRenderTile.getOrbitingObjects() != null) { + + if (EOHRenderTile.getOrbitingObjects() + .size() == 0) { + EOHRenderTile.generateImportantInfo(); + } + + for (TileEntityEyeOfHarmony.OrbitingObject t : EOHRenderTile.getOrbitingObjects()) { + renderOrbit(EOHRenderTile, t); + } + } + } + + void renderOrbit(final TileEntityEyeOfHarmony EOHRenderTile, + final TileEntityEyeOfHarmony.OrbitingObject orbitingObject) { + // Render orbiting body. + GL11.glPushMatrix(); + + GL11.glRotatef(orbitingObject.zAngle, 0, 0, 1); + GL11.glRotatef(orbitingObject.xAngle, 1, 0, 0); + GL11.glRotatef((orbitingObject.rotationSpeed * 0.1f * EOHRenderTile.angle) % 360.0f, 0F, 1F, 0F); + GL11.glTranslated(-0.2 - orbitingObject.distance - STAR_RESCALE * EOHRenderTile.getSize(), 0, 0); + GL11.glRotatef((orbitingObject.orbitSpeed * 0.1f * EOHRenderTile.angle) % 360.0f, 0F, 1F, 0F); + + this.bindTexture(TextureMap.locationBlocksTexture); + renderBlockInWorld(orbitingObject.block, 0, orbitingObject.scale); + + GL11.glPopMatrix(); + } + + private static final float STAR_RESCALE = 0.2f; + +} |