diff --git a/src/main/java/crazypants/enderio/teleport/telepad/TelePadSpecialRenderer.java b/src/main/java/crazypants/enderio/teleport/telepad/TelePadSpecialRenderer.java index 4be567df..4b805a9e 100644 --- a/src/main/java/crazypants/enderio/teleport/telepad/TelePadSpecialRenderer.java +++ b/src/main/java/crazypants/enderio/teleport/telepad/TelePadSpecialRenderer.java @@ -1,6 +1,7 @@ package crazypants.enderio.teleport.telepad; import java.util.List; +import java.util.Random; import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; @@ -15,16 +16,15 @@ import crazypants.render.TechneUtil; public class TelePadSpecialRenderer extends TileEntitySpecialRenderer { - private static List blades = Lists.newArrayList(); - private static List glass = Lists.newArrayList(TelePadRenderer.all.get("glass")); - - static { - for (String s : TelePadRenderer.all.keySet()) { - if(s.contains("blade")) { - blades.add(TelePadRenderer.all.get(s)); - } - } - } + private static GroupObject blade1 = TelePadRenderer.all.get("blade1"); + private static GroupObject blade2 = TelePadRenderer.all.get("blade2"); + private static GroupObject blade3 = TelePadRenderer.all.get("blade3"); + // Reverse order for top to bottom + private static List blades = Lists.newArrayList(blade3, blade2, blade1); + + private static GroupObject glass = TelePadRenderer.all.get("glass"); + + private static Random rand = new Random(); @Override public void renderTileEntityAt(TileEntity te, double x, double y, double z, float p_147500_8_) { @@ -34,19 +34,22 @@ public class TelePadSpecialRenderer extends TileEntitySpecialRenderer { GL11.glTranslated(x + 0.5, y + 0.01, z + 0.5); Tessellator tes = Tessellator.instance; tes.setBrightness(0xF000F0); - // TODO spin the spinny thingies properly - float rot = te.getWorldObj().getTotalWorldTime() + p_147500_8_; - GL11.glRotatef(rot, 0, 1, 0); - render(blades, te, tes); + GL11.glDepthMask(true); + rand.setSeed(te.xCoord + te.yCoord + te.zCoord); + for (int i = 0; i < 3; i++) { + GL11.glPushMatrix(); + GL11.glRotatef(tp.bladeRots[i] + rand.nextInt(360) + (tp.spinSpeed * p_147500_8_ * (i + 20)), 0, 1, 0); + render(blades.get(i), te, tes); + GL11.glPopMatrix(); + } GL11.glEnable(GL11.GL_BLEND); - GL11.glRotatef(-rot, 0, 1, 0); render(glass, te, tes); GL11.glDisable(GL11.GL_BLEND); GL11.glPopMatrix(); } } - private void render(List model, TileEntity te, Tessellator tes) { + private void render(GroupObject model, TileEntity te, Tessellator tes) { tes.startDrawingQuads(); TechneUtil.renderWithIcon(model, te.getBlockType().getIcon(te.getWorldObj(), te.xCoord, te.yCoord, te.zCoord, 0), null, Tessellator.instance, te.getWorldObj(), 0, 0, 0, null, false); diff --git a/src/main/java/crazypants/enderio/teleport/telepad/TeleportEntityRenderHandler.java b/src/main/java/crazypants/enderio/teleport/telepad/TeleportEntityRenderHandler.java index 9f9739b8..cb79f9a7 100644 --- a/src/main/java/crazypants/enderio/teleport/telepad/TeleportEntityRenderHandler.java +++ b/src/main/java/crazypants/enderio/teleport/telepad/TeleportEntityRenderHandler.java @@ -107,10 +107,10 @@ public class TeleportEntityRenderHandler { } private void colorBot(Tessellator tes) { - tes.setColorRGBA(100, 100, 255, 100); + tes.setColorRGBA(175, 255, 255, 100); } private void colorTop(Tessellator tes) { - tes.setColorRGBA(150, 150, 255, 0); + tes.setColorRGBA(220, 255, 255, 0); } } diff --git a/src/main/java/crazypants/enderio/teleport/telepad/TileTelePad.java b/src/main/java/crazypants/enderio/teleport/telepad/TileTelePad.java index e473ab10..727f6667 100644 --- a/src/main/java/crazypants/enderio/teleport/telepad/TileTelePad.java +++ b/src/main/java/crazypants/enderio/teleport/telepad/TileTelePad.java @@ -15,6 +15,7 @@ import net.minecraft.network.play.server.S35PacketUpdateTileEntity; import net.minecraft.server.MinecraftServer; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.MathHelper; import net.minecraft.util.ResourceLocation; import net.minecraft.util.Vec3; import net.minecraft.world.WorldServer; @@ -73,7 +74,12 @@ public class TileTelePad extends TileTravelAnchor implements IInternalPowerRecei public static final String TELEPORTING_KEY = "eio:teleporting"; public static final String PROGRESS_KEY = "teleportprogress"; - + + // Clientside rendering data + public float[] bladeRots = new float[3]; + public float spinSpeed = 0; + public float speedMult = 2.5f; + @Override public void updateEntity() { super.updateEntity(); @@ -96,20 +102,23 @@ public class TileTelePad extends TileTravelAnchor implements IInternalPowerRecei } if(worldObj.isRemote) { + updateRotations(); + if(activeSound != null) { + activeSound.setPitch(MathHelper.clamp_float(0.5f + (spinSpeed / 1.5f), 0.5f, 2)); + } if(active()) { if(activeSound == null) { activeSound = new MachineSound(activeRes, xCoord, yCoord, zCoord, 0.01f, 1); playSound(); } - activeSound.setVolume(Math.min(activeSound.getVolume() + 0.1f, 0.5f)); - activeSound.setPitch(1 + getProgress()); + activeSound.setVolume(MathHelper.clamp_float(spinSpeed, 0.1f, 1)); updateQueuedEntities(); } else if(!active() && activeSound != null) { - if(activeSound.getVolume() > 0) { - activeSound.setVolume(activeSound.getVolume() - 0.1f); - } else { + if(activeSound.getVolume() <= 0.1f) { activeSound.endPlaying(); activeSound = null; + } else { + activeSound.setVolume(MathHelper.clamp_float(spinSpeed, 0.1f, 1)); } } } else { @@ -345,6 +354,18 @@ public class TileTelePad extends TileTravelAnchor implements IInternalPowerRecei return getBoundingBox(); } + public void updateRotations() { + if(active()) { + spinSpeed = getProgress() * 2; + } else { + spinSpeed = Math.max(0, spinSpeed - 0.01f); + } + + for (int i = 0; i < bladeRots.length; i++) { + bladeRots[i] += spinSpeed * ((i * 2) + 20); + } + } + /* IProgressTile */ @Override diff --git a/src/main/java/crazypants/render/TechneUtil.java b/src/main/java/crazypants/render/TechneUtil.java index 11ca9aa2..41cd697a 100644 --- a/src/main/java/crazypants/render/TechneUtil.java +++ b/src/main/java/crazypants/render/TechneUtil.java @@ -129,7 +129,6 @@ public class TechneUtil { Vector4f vec = new Vector4f(); List res = new ArrayList(); - for (ModelBox box : (List) model.cubeList) { GroupObject obj = new GroupObject("", GL11.GL_QUADS); @@ -153,7 +152,7 @@ public class TechneUtil { // Increase the interpolation scale by multiples of 2 while (pv.texturePositionX > uMult) { uMult *= 2; - } + } while (pv.texturePositionY > vMult) { vMult *= 2; } @@ -218,7 +217,7 @@ public class TechneUtil { TechneModel tm = (TechneModel) modelLoader.loadInstance(new ResourceLocation(EnderIO.MODID.toLowerCase(), modelPath + ".tcn")); return TechneUtil.bakeModel(tm, 1f / 16, new Matrix4f().scale(new Vector3f(-1, -1, 1))); } - + public static Collection getModelAll(String modelPath) { TechneModel tm = (TechneModel) modelLoader.loadInstance(new ResourceLocation(EnderIO.MODID.toLowerCase(), modelPath + ".tcn")); return TechneUtil.bakeModel(tm, 1f / 16, new Matrix4f().scale(new Vector3f(-1, -1, 1))).values(); @@ -236,72 +235,76 @@ public class TechneUtil { renderWithIcon(model, icon, override, tes, world, x, y, z, null); } - public static void renderWithIcon(Collection model, IIcon icon, IIcon override, Tessellator tes, IBlockAccess world, int x, int y, int z, VertexTransform vt) { renderWithIcon(model, icon, override, tes, world, x, y, z, vt, true); } - + public static void renderWithIcon(Collection model, IIcon icon, IIcon override, Tessellator tes, IBlockAccess world, int x, int y, int z, VertexTransform vt, boolean isbrh) { for (GroupObject go : model) { - for (Face f : go.faces) { - Vertex n = f.faceNormal; - tes.setNormal(n.x, n.y, n.z); - ForgeDirection normal = getNormalFor(n); - ForgeDirection right = normal.getRotation(ForgeDirection.DOWN); - if(normal == right) { - right = ForgeDirection.EAST; - } - ForgeDirection down = normal.getRotation(right.getOpposite()); + renderWithIcon(go, icon, override, tes, world, x, y, z, vt, isbrh); + } + } - if(isbrh && world != null && world.getBlock(x, y, z).getLightOpacity() > 0) { - int bx = x + normal.offsetX; - int by = y + normal.offsetY; - int bz = z + normal.offsetZ; - tes.setBrightness(world.getBlock(bx, by, bz).getMixedBrightnessForBlock(world, bx, by, bz)); + public static void renderWithIcon(GroupObject go, IIcon icon, IIcon override, Tessellator tes, IBlockAccess world, int x, int y, int z, VertexTransform vt, + boolean isbrh) { + for (Face f : go.faces) { + Vertex n = f.faceNormal; + tes.setNormal(n.x, n.y, n.z); + ForgeDirection normal = getNormalFor(n); + ForgeDirection right = normal.getRotation(ForgeDirection.DOWN); + if(normal == right) { + right = ForgeDirection.EAST; + } + ForgeDirection down = normal.getRotation(right.getOpposite()); + + if(isbrh && world != null && world.getBlock(x, y, z).getLightOpacity() > 0) { + int bx = x + normal.offsetX; + int by = y + normal.offsetY; + int bz = z + normal.offsetZ; + tes.setBrightness(world.getBlock(bx, by, bz).getMixedBrightnessForBlock(world, bx, by, bz)); + } + + for (int i = 0; i < f.vertices.length; i++) { + Vertex vert = f.vertices[i]; + Vector3d v = new Vector3d(vert); + Vector3d tv = new Vector3d(v); + tv.add(0.5, 0, 0.5); + if(vt != null) { + vt.apply(v); } - for (int i = 0; i < f.vertices.length; i++) { - Vertex vert = f.vertices[i]; - Vector3d v = new Vector3d(vert); - Vector3d tv = new Vector3d(v); - tv.add(0.5, 0, 0.5); - if(vt != null) { - vt.apply(v); + if(isbrh) { + float factor = normal.offsetX != 0 ? 0.6f : normal.offsetZ != 0 ? 0.8f : normal.offsetY < 0 ? 0.5f : 1; + int c = (int) (0xFF * factor); + + tes.setColorOpaque(c, c, c); + } + + if(override != null) { + + double interpX = Math.abs(tv.x * right.offsetX + tv.y * right.offsetY + tv.z * right.offsetZ); + double interpY = Math.abs(tv.x * down.offsetX + tv.y * down.offsetY + tv.z * down.offsetZ); + + // Handles verts outside block bounds. Modulo fails at 1.0. + while (interpX > 1) { + interpX--; + } + while (interpY > 1) { + interpY--; } - if(isbrh) { - float factor = normal.offsetX != 0 ? 0.6f : normal.offsetZ != 0 ? 0.8f : normal.offsetY < 0 ? 0.5f : 1; - int c = (int) (0xFF * factor); - - tes.setColorOpaque(c, c, c); + if(normal == ForgeDirection.SOUTH || normal == ForgeDirection.WEST) { + interpX = 1 - interpX; } - - if(override != null) { - - double interpX = Math.abs(tv.x * right.offsetX + tv.y * right.offsetY + tv.z * right.offsetZ); - double interpY = Math.abs(tv.x * down.offsetX + tv.y * down.offsetY + tv.z * down.offsetZ); - - // Handles verts outside block bounds. Modulo fails at 1.0. - while (interpX > 1) { - interpX--; - } - while (interpY > 1) { - interpY--; - } - - if(normal == ForgeDirection.SOUTH || normal == ForgeDirection.WEST) { - interpX = 1 - interpX; - } - if(normal != ForgeDirection.UP && normal != ForgeDirection.DOWN) { - interpY = 1 - interpY; - } - tes.addVertexWithUV(v.x, v.y, v.z, override.getInterpolatedU(interpX * 16), override.getInterpolatedV(interpY * 16)); - } else { - TextureCoordinate t = f.textureCoordinates[i]; - tes.addVertexWithUV(v.x, v.y, v.z, icon.getInterpolatedU(t.u * 16), icon.getInterpolatedV(t.v * 16)); + if(normal != ForgeDirection.UP && normal != ForgeDirection.DOWN) { + interpY = 1 - interpY; } + tes.addVertexWithUV(v.x, v.y, v.z, override.getInterpolatedU(interpX * 16), override.getInterpolatedV(interpY * 16)); + } else { + TextureCoordinate t = f.textureCoordinates[i]; + tes.addVertexWithUV(v.x, v.y, v.z, icon.getInterpolatedU(t.u * 16), icon.getInterpolatedV(t.v * 16)); } } }