From 7d87c9ae97b64e0f3f63aea2d9cf2389f0d978fa Mon Sep 17 00:00:00 2001 From: Vasco Lavos Date: Sun, 2 Feb 2014 19:04:10 +0000 Subject: [PATCH] Yay, reusing renders. --- .../client/core/proxy/ClientProxy.java | 3 + .../client/model/ModelSpinningCubes.java | 88 +++++++++++++++++++ .../render/tile/RenderTileRuneAltar.java | 35 ++++++++ 3 files changed, 126 insertions(+) create mode 100644 MODSRC/vazkii/botania/client/model/ModelSpinningCubes.java create mode 100644 MODSRC/vazkii/botania/client/render/tile/RenderTileRuneAltar.java diff --git a/MODSRC/vazkii/botania/client/core/proxy/ClientProxy.java b/MODSRC/vazkii/botania/client/core/proxy/ClientProxy.java index 94cf3d24f..5cc690fd3 100644 --- a/MODSRC/vazkii/botania/client/core/proxy/ClientProxy.java +++ b/MODSRC/vazkii/botania/client/core/proxy/ClientProxy.java @@ -32,9 +32,11 @@ import vazkii.botania.client.render.block.RenderSpreader; import vazkii.botania.client.render.item.RenderLens; import vazkii.botania.client.render.tile.RenderTileAltar; import vazkii.botania.client.render.tile.RenderTilePool; +import vazkii.botania.client.render.tile.RenderTileRuneAltar; import vazkii.botania.client.render.tile.RenderTileSpreader; import vazkii.botania.common.block.tile.TileAltar; import vazkii.botania.common.block.tile.TilePool; +import vazkii.botania.common.block.tile.TileRuneAltar; import vazkii.botania.common.block.tile.TileSpreader; import vazkii.botania.common.core.handler.ManaNetworkHandler; import vazkii.botania.common.core.proxy.CommonProxy; @@ -71,6 +73,7 @@ public class ClientProxy extends CommonProxy { ClientRegistry.bindTileEntitySpecialRenderer(TileAltar.class, new RenderTileAltar()); ClientRegistry.bindTileEntitySpecialRenderer(TileSpreader.class, new RenderTileSpreader()); ClientRegistry.bindTileEntitySpecialRenderer(TilePool.class, new RenderTilePool()); + ClientRegistry.bindTileEntitySpecialRenderer(TileRuneAltar.class, new RenderTileRuneAltar()); } @Override diff --git a/MODSRC/vazkii/botania/client/model/ModelSpinningCubes.java b/MODSRC/vazkii/botania/client/model/ModelSpinningCubes.java new file mode 100644 index 000000000..22a2811da --- /dev/null +++ b/MODSRC/vazkii/botania/client/model/ModelSpinningCubes.java @@ -0,0 +1,88 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under a + * Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License + * (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB) + * + * File Created @ [Feb 2, 2014, 6:37:00 PM (GMT)] + */ +package vazkii.botania.client.model; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.model.ModelBase; +import net.minecraft.client.model.ModelRenderer; +import net.minecraft.client.renderer.OpenGlHelper; + +import org.lwjgl.opengl.GL11; + +public class ModelSpinningCubes extends ModelBase { + + ModelRenderer spinningCube; + + public ModelSpinningCubes() { + spinningCube = new ModelRenderer(this, 42, 0); + spinningCube.addBox(0F, 0F, 0F, 1, 1, 1); + spinningCube.setRotationPoint(0F, 0F, 0F); + spinningCube.setTextureSize(64, 64); + } + + public void renderSpinningCubes(int cubes, int repeat, int origRepeat) { + GL11.glDisable(GL11.GL_TEXTURE_2D); + + final float modifier = 6F; + final float rotationModifier = 0.2F; + final float radiusBase = 0.35F; + final float radiusMod = 0.05F; + + double ticks = Minecraft.getMinecraft().thePlayer.ticksExisted - 1.3 * (origRepeat - repeat); + float offsetPerCube = 360 / cubes; + + GL11.glPushMatrix(); + GL11.glTranslatef(-0.025F, 0.85F, -0.025F); + for(int i = 0; i < cubes; i++) { + float offset = offsetPerCube * i; + float deg = (int) (ticks / rotationModifier % 360F + offset); + float rad = deg * (float) Math.PI / 180F; + float radiusX = (float) (radiusBase + radiusMod * Math.sin(ticks / modifier)); + float radiusZ = (float) (radiusBase + radiusMod * Math.cos(ticks / modifier)); + float x = (float) (radiusX * Math.cos(rad)); + float z = (float) (radiusZ * Math.sin(rad)); + float y = (float) Math.cos((ticks + 50 * i) / 5F) / 10F; + + GL11.glPushMatrix(); + GL11.glTranslatef(x, y, z); + float xRotate = (float) Math.sin(ticks * rotationModifier) / 2F; + float yRotate = (float) Math.max(0.6F, Math.sin(ticks * 0.1F) / 2F + 0.5F); + float zRotate = (float) Math.cos(ticks * rotationModifier) / 2F; + + GL11.glRotatef(deg, xRotate, yRotate, zRotate); + if(repeat < origRepeat) { + GL11.glColor4f(1F, 1F, 1F, 0.2F); + GL11.glEnable(GL11.GL_BLEND); + GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + } else GL11.glColor4f(1F, 1F, 1F, 1F); + + int light = 15728880; + int lightmapX = light % 65536; + int lightmapY = light / 65536; + + OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, lightmapX, lightmapY); + spinningCube.render(1F / 16F); + + if(repeat < origRepeat) + GL11.glDisable(GL11.GL_BLEND); + + GL11.glPopMatrix(); + } + GL11.glPopMatrix(); + + GL11.glEnable(GL11.GL_TEXTURE_2D); + + if(repeat != 0) + renderSpinningCubes(cubes, repeat - 1, origRepeat); + } + +} diff --git a/MODSRC/vazkii/botania/client/render/tile/RenderTileRuneAltar.java b/MODSRC/vazkii/botania/client/render/tile/RenderTileRuneAltar.java new file mode 100644 index 000000000..35e085b36 --- /dev/null +++ b/MODSRC/vazkii/botania/client/render/tile/RenderTileRuneAltar.java @@ -0,0 +1,35 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under a + * Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License + * (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB) + * + * File Created @ [Feb 2, 2014, 6:34:45 PM (GMT)] + */ +package vazkii.botania.client.render.tile; + +import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; +import net.minecraft.tileentity.TileEntity; + +import org.lwjgl.opengl.GL11; + +import vazkii.botania.client.model.ModelSpinningCubes; + +public class RenderTileRuneAltar extends TileEntitySpecialRenderer { + + ModelSpinningCubes cubes = new ModelSpinningCubes(); + + @Override + public void renderTileEntityAt(TileEntity tileentity, double x, double y, double z, float f) { + GL11.glPushMatrix(); + GL11.glColor4f(1F, 1F, 1F, 1F); + GL11.glTranslated(x + 0.5, y + 1.8, z + 0.5); + GL11.glRotatef(180F, 1F, 0F, 1F); + int repeat = 15; + cubes.renderSpinningCubes(2, repeat, repeat); + GL11.glPopMatrix(); + } +}