diff --git a/dependencies.gradle b/dependencies.gradle index bd2d03a..142baeb 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -2,6 +2,6 @@ dependencies { api("com.github.GTNewHorizons:ForgeMultipart:1.5.0:dev") - api("com.github.GTNewHorizons:CodeChickenCore:1.2.1:dev") + api("com.github.GTNewHorizons:CodeChickenCore:1.3.8:dev") implementation("com.github.GTNewHorizons:CodeChickenLib:1.3.0:dev") } diff --git a/src/main/java/codechicken/wirelessredstone/addons/RenderTracker.java b/src/main/java/codechicken/wirelessredstone/addons/RenderTracker.java index 49b5fba..162427d 100644 --- a/src/main/java/codechicken/wirelessredstone/addons/RenderTracker.java +++ b/src/main/java/codechicken/wirelessredstone/addons/RenderTracker.java @@ -28,7 +28,8 @@ public class RenderTracker extends RenderEntity implements IItemRenderer { - private static CCModel model; + private static final CCModel model; + private static final Vector3 Y_AXIS = new Vector3(0, 1, 0); static { model = CCModel.parseObjModels(new ResourceLocation("wrcbe_addons", "models/tracker.obj"), 7, new SwapYZ()) @@ -46,22 +47,24 @@ public void renderTracker(int freq) { TextureUtils.bindAtlas(0); final CCRenderState state = CCRenderState.instance(); - state.reset(); - state.startDrawing(7); - state.setColour(0xFFFFFFFF); + state.resetInstance(); + state.startDrawingInstance(7); + state.setColourInstance(0xFFFFFFFF); model.render(new IconTransformation(Blocks.obsidian.getIcon(0, 0))); - state.draw(); + state.drawInstance(); Matrix4 pearlMat = CCModelLibrary.getRenderMatrix( - new Vector3(0, 0.44 + RedstoneEther.getSineWave(ClientUtils.getRenderTime(), 7) * 0.02, 0), - new Rotation(RedstoneEther.getRotation(ClientUtils.getRenderTime(), freq), new Vector3(0, 1, 0)), + 0, + 0.44 + RedstoneEther.getSineWave(ClientUtils.getRenderTime(), 7) * 0.02, + 0, + new Rotation(RedstoneEther.getRotation(ClientUtils.getRenderTime(), freq), Y_AXIS), 0.04); - state.changeTexture("wrcbe_core:textures/hedronmap.png"); - state.startDrawing(4); - state.setColour(freq == 0 ? 0xC0C0C0FF : 0xFFFFFFFF); + CCRenderState.changeTexture("wrcbe_core:textures/hedronmap.png"); + state.startDrawingInstance(4); + state.setColourInstance(freq == 0 ? 0xC0C0C0FF : 0xFFFFFFFF); CCModelLibrary.icosahedron4.render(pearlMat); - state.draw(); + state.drawInstance(); GL11.glEnable(GL11.GL_LIGHTING); } @@ -69,35 +72,42 @@ public void renderTracker(int freq) { @Override public void doRender(Entity entity, double x, double y, double z, float f, float f1) { GL11.glPushMatrix(); - GL11.glTranslated(x, y + 0.2, z); EntityWirelessTracker tracker = (EntityWirelessTracker) entity; if (tracker.isAttachedToEntity()) { - Vector3 relVec = tracker.getRotatedAttachment(); - - Vector3 yAxis = new Vector3(0, 1, 0); - Vector3 axis = relVec.copy().crossProduct(yAxis); - double angle = -(relVec.angle(yAxis) * todeg); - - GL11.glTranslated(-x, -y - 0.2, -z); // undo translation - Vector3 pos = new Vector3( - tracker.attachedEntity.lastTickPosX - + (tracker.attachedEntity.posX - tracker.attachedEntity.lastTickPosX) * f1, - tracker.attachedEntity.lastTickPosY - + (tracker.attachedEntity.posY - tracker.attachedEntity.lastTickPosY) * f1 - + tracker.attachedEntity.height / 2 - - tracker.attachedEntity.yOffset - - tracker.height, - tracker.attachedEntity.lastTickPosZ - + (tracker.attachedEntity.posZ - tracker.attachedEntity.lastTickPosZ) * f1); - - pos.add(relVec).add(-RenderManager.renderPosX, -RenderManager.renderPosY, -RenderManager.renderPosZ); + Vector3 relVec = tracker.getRotatedAttachment(); - GL11.glTranslated(pos.x, pos.y, pos.z); + final double posX = tracker.attachedEntity.lastTickPosX + + (tracker.attachedEntity.posX - tracker.attachedEntity.lastTickPosX) * f1 + + relVec.x + - RenderManager.renderPosX; + final double posY = tracker.attachedEntity.lastTickPosY + + (tracker.attachedEntity.posY - tracker.attachedEntity.lastTickPosY) * f1 + + tracker.attachedEntity.height / 2 + - tracker.attachedEntity.yOffset + - tracker.height + + relVec.y + - RenderManager.renderPosY; + final double posZ = tracker.attachedEntity.lastTickPosZ + + (tracker.attachedEntity.posZ - tracker.attachedEntity.lastTickPosZ) * f1 + + relVec.z + - RenderManager.renderPosZ; + + GL11.glTranslated(posX, posY, posZ); + + final double axisX = -relVec.z; + final double axisY = 0; + final double axisZ = relVec.x; + // leaving this code commented for understand, + // but it can be simplified to what is below for speed + // Vector3 yAxis = new Vector3(0, 1, 0); + // double angle = -(relVec.angle(yAxis) * todeg); + final double angle = -(Math.acos(relVec.normalize().y) * todeg); + GL11.glRotatef((float) angle, (float) axisX, (float) axisY, (float) axisZ); - GL11.glRotatef((float) angle, (float) axis.x, (float) axis.y, (float) axis.z); } else if (tracker.item) { + GL11.glTranslated(x, y + 0.2, z); double bob = sin(ClientUtils.getRenderTime() / 10) * 0.1; double rotate = ClientUtils.getRenderTime() / 20 * todeg; diff --git a/src/main/java/codechicken/wirelessredstone/core/RenderWirelessBolt.java b/src/main/java/codechicken/wirelessredstone/core/RenderWirelessBolt.java index 43fe3af..a418f34 100644 --- a/src/main/java/codechicken/wirelessredstone/core/RenderWirelessBolt.java +++ b/src/main/java/codechicken/wirelessredstone/core/RenderWirelessBolt.java @@ -1,9 +1,6 @@ package codechicken.wirelessredstone.core; -import java.util.Iterator; - import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.ActiveRenderInfo; import net.minecraft.client.renderer.Tessellator; import net.minecraft.entity.Entity; @@ -11,19 +8,10 @@ import codechicken.lib.render.CCRenderState; import codechicken.lib.render.RenderUtils; -import codechicken.lib.vec.Vector3; import codechicken.wirelessredstone.core.WirelessBolt.Segment; public class RenderWirelessBolt { - private static Vector3 getRelativeViewVector(Vector3 pos) { - Entity renderentity = Minecraft.getMinecraft().renderViewEntity; - return new Vector3( - (float) renderentity.posX - pos.x, - (float) renderentity.posY + renderentity.getEyeHeight() - pos.y, - (float) renderentity.posZ - pos.z); - } - public static void render(float frame, Entity entity) { GL11.glPushMatrix(); RenderUtils.translateToWorldCoords(entity, frame); @@ -33,31 +21,17 @@ public static void render(float frame, Entity entity) { GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); final CCRenderState state = CCRenderState.instance(); - state.reset(); - state.setBrightness(0xF000F0); - state.changeTexture("wrcbe_core:textures/lightning_glowstone.png"); - state.startDrawing(7); - for (WirelessBolt bolt : WirelessBolt.clientboltlist) renderBolt( - bolt, - frame, - ActiveRenderInfo.rotationX, - ActiveRenderInfo.rotationXZ, - ActiveRenderInfo.rotationZ, - ActiveRenderInfo.rotationXY, - 0); - state.draw(); - - state.changeTexture("wrcbe_core:textures/lightning_redstone.png"); - state.startDrawing(7); - for (WirelessBolt bolt : WirelessBolt.clientboltlist) renderBolt( - bolt, - frame, - ActiveRenderInfo.rotationX, - ActiveRenderInfo.rotationXZ, - ActiveRenderInfo.rotationZ, - ActiveRenderInfo.rotationXY, - 1); - state.draw(); + state.resetInstance(); + state.setBrightnessInstance(0xF000F0); + CCRenderState.changeTexture("wrcbe_core:textures/lightning_glowstone.png"); + state.startDrawingInstance(7); + for (WirelessBolt bolt : WirelessBolt.clientboltlist) renderBolt(bolt, 0); + state.drawInstance(); + + CCRenderState.changeTexture("wrcbe_core:textures/lightning_redstone.png"); + state.startDrawingInstance(7); + for (WirelessBolt bolt : WirelessBolt.clientboltlist) renderBolt(bolt, 1); + state.drawInstance(); GL11.glDisable(GL11.GL_BLEND); GL11.glDepthMask(true); @@ -65,11 +39,10 @@ public static void render(float frame, Entity entity) { GL11.glPopMatrix(); } - private static void renderBolt(WirelessBolt bolt, float partialframe, float cosyaw, float cospitch, float sinyaw, - float cossinpitch, int pass) { + private static void renderBolt(WirelessBolt bolt, int pass) { Tessellator t = Tessellator.instance; float boltage = bolt.particleAge < 0 ? 0 : (float) bolt.particleAge / (float) bolt.particleMaxAge; - float mainalpha = 1; + float mainalpha; if (pass == 0) mainalpha = (1 - boltage) * 0.4F; else mainalpha = 1 - boltage * 0.5F; @@ -78,48 +51,102 @@ private static void renderBolt(WirelessBolt bolt, float partialframe, float cosy * bolt.numsegments0); int renderend = (int) ((bolt.particleAge + expandTime) / (float) expandTime * bolt.numsegments0); - for (Iterator iterator = bolt.segments.iterator(); iterator.hasNext();) { - Segment rendersegment = iterator.next(); - + for (Segment rendersegment : bolt.segments) { if (rendersegment.segmentno < renderstart || rendersegment.segmentno > renderend) continue; - Vector3 playervec = getRelativeViewVector(rendersegment.startpoint.point).negate(); - - double width = 0.025F * (playervec.mag() / 5 + 1) * (1 + rendersegment.light) * 0.5F; - - Vector3 diff1 = playervec.copy().crossProduct(rendersegment.prevdiff).normalize() - .multiply(width / rendersegment.sinprev); - Vector3 diff2 = playervec.copy().crossProduct(rendersegment.nextdiff).normalize() - .multiply(width / rendersegment.sinnext); - - Vector3 startvec = rendersegment.startpoint.point; - Vector3 endvec = rendersegment.endpoint.point; + Entity viewEntity = Minecraft.getMinecraft().renderViewEntity; + double startX = rendersegment.startpoint.point.x; + double startY = rendersegment.startpoint.point.y; + double startZ = rendersegment.startpoint.point.z; + + double playerX = viewEntity.posX - startX; + double playerY = viewEntity.posY + viewEntity.getEyeHeight() - startY; + double playerZ = viewEntity.posZ - startZ; + + double playerMag = Math.sqrt(playerX * playerX + playerY * playerY + playerZ * playerZ); + double width = 0.025F * (playerMag / 5 + 1) * (1 + rendersegment.light) * 0.5F; + + double prevDiffX = rendersegment.prevdiff.x; + double prevDiffY = rendersegment.prevdiff.y; + double prevDiffZ = rendersegment.prevdiff.z; + + double nextDiffX = rendersegment.nextdiff.x; + double nextDiffY = rendersegment.nextdiff.y; + double nextDiffZ = rendersegment.nextdiff.z; + + double crossPrevX = playerY * prevDiffZ - playerZ * prevDiffY; + double crossPrevY = playerZ * prevDiffX - playerX * prevDiffZ; + double crossPrevZ = playerX * prevDiffY - playerY * prevDiffX; + double crossPrevMag = Math + .sqrt(crossPrevX * crossPrevX + crossPrevY * crossPrevY + crossPrevZ * crossPrevZ); + crossPrevX /= crossPrevMag; + crossPrevY /= crossPrevMag; + crossPrevZ /= crossPrevMag; + + crossPrevX *= width / rendersegment.sinprev; + crossPrevY *= width / rendersegment.sinprev; + crossPrevZ *= width / rendersegment.sinprev; + + double crossNextX = playerY * nextDiffZ - playerZ * nextDiffY; + double crossNextY = playerZ * nextDiffX - playerX * nextDiffZ; + double crossNextZ = playerX * nextDiffY - playerY * nextDiffX; + double crossNextMag = Math + .sqrt(crossNextX * crossNextX + crossNextY * crossNextY + crossNextZ * crossNextZ); + crossNextX /= crossNextMag; + crossNextY /= crossNextMag; + crossNextZ /= crossNextMag; + + crossNextX *= width / rendersegment.sinnext; + crossNextY *= width / rendersegment.sinnext; + crossNextZ *= width / rendersegment.sinnext; + + double endX = rendersegment.endpoint.point.x; + double endY = rendersegment.endpoint.point.y; + double endZ = rendersegment.endpoint.point.z; t.setColorRGBA_F(1, 1, 1, mainalpha * rendersegment.light); - t.addVertexWithUV(endvec.x - diff2.x, endvec.y - diff2.y, endvec.z - diff2.z, 0.5, 0); - t.addVertexWithUV(startvec.x - diff1.x, startvec.y - diff1.y, startvec.z - diff1.z, 0.5, 0); - t.addVertexWithUV(startvec.x + diff1.x, startvec.y + diff1.y, startvec.z + diff1.z, 0.5, 1); - t.addVertexWithUV(endvec.x + diff2.x, endvec.y + diff2.y, endvec.z + diff2.z, 0.5, 1); + t.addVertexWithUV(endX - crossNextX, endY - crossNextY, endZ - crossNextZ, 0.5, 0); + t.addVertexWithUV(startX - crossPrevX, startY - crossPrevY, startZ - crossPrevZ, 0.5, 0); + t.addVertexWithUV(startX + crossPrevX, startY + crossPrevY, startZ + crossPrevZ, 0.5, 1); + t.addVertexWithUV(endX + crossNextX, endY + crossNextY, endZ + crossNextZ, 0.5, 1); if (rendersegment.next == null) { - Vector3 roundend = rendersegment.endpoint.point.copy() - .add(rendersegment.diff.copy().normalize().multiply(width)); - - t.addVertexWithUV(roundend.x - diff2.x, roundend.y - diff2.y, roundend.z - diff2.z, 0, 0); - t.addVertexWithUV(endvec.x - diff2.x, endvec.y - diff2.y, endvec.z - diff2.z, 0.5, 0); - t.addVertexWithUV(endvec.x + diff2.x, endvec.y + diff2.y, endvec.z + diff2.z, 0.5, 1); - t.addVertexWithUV(roundend.x + diff2.x, roundend.y + diff2.y, roundend.z + diff2.z, 0, 1); + double diffX = rendersegment.diff.x; + double diffY = rendersegment.diff.y; + double diffZ = rendersegment.diff.z; + double diffMag = Math.sqrt(diffX * diffX + diffY * diffY + diffZ * diffZ); + diffX /= diffMag; + diffY /= diffMag; + diffZ /= diffMag; + + double roundEndX = endX + diffX * width; + double roundEndY = endY + diffY * width; + double roundEndZ = endZ + diffZ * width; + + t.addVertexWithUV(roundEndX - crossNextX, roundEndY - crossNextY, roundEndZ - crossNextZ, 0, 0); + t.addVertexWithUV(endX - crossNextX, endY - crossNextY, endZ - crossNextZ, 0.5, 0); + t.addVertexWithUV(endX + crossNextX, endY + crossNextY, endZ + crossNextZ, 0.5, 1); + t.addVertexWithUV(roundEndX + crossNextX, roundEndY + crossNextY, roundEndZ + crossNextZ, 0, 1); } if (rendersegment.prev == null) { - Vector3 roundend = rendersegment.startpoint.point.copy() - .subtract(rendersegment.diff.copy().normalize().multiply(width)); - - t.addVertexWithUV(startvec.x - diff1.x, startvec.y - diff1.y, startvec.z - diff1.z, 0.5, 0); - t.addVertexWithUV(roundend.x - diff1.x, roundend.y - diff1.y, roundend.z - diff1.z, 0, 0); - t.addVertexWithUV(roundend.x + diff1.x, roundend.y + diff1.y, roundend.z + diff1.z, 0, 1); - t.addVertexWithUV(startvec.x + diff1.x, startvec.y + diff1.y, startvec.z + diff1.z, 0.5, 1); + double diffX = rendersegment.diff.x; + double diffY = rendersegment.diff.y; + double diffZ = rendersegment.diff.z; + double diffMag = Math.sqrt(diffX * diffX + diffY * diffY + diffZ * diffZ); + diffX /= diffMag; + diffY /= diffMag; + diffZ /= diffMag; + + double roundEndX = startX - diffX * width; + double roundEndY = startY - diffY * width; + double roundEndZ = startZ - diffZ * width; + + t.addVertexWithUV(startX - crossPrevX, startY - crossPrevY, startZ - crossPrevZ, 0.5, 0); + t.addVertexWithUV(roundEndX - crossPrevX, roundEndY - crossPrevY, roundEndZ - crossPrevZ, 0, 0); + t.addVertexWithUV(roundEndX + crossPrevX, roundEndY + crossPrevY, roundEndZ + crossPrevZ, 0, 1); + t.addVertexWithUV(startX + crossPrevX, startY + crossPrevY, startZ + crossPrevZ, 0.5, 1); } } } diff --git a/src/main/java/codechicken/wirelessredstone/logic/RenderWireless.java b/src/main/java/codechicken/wirelessredstone/logic/RenderWireless.java index e64013d..27362bf 100644 --- a/src/main/java/codechicken/wirelessredstone/logic/RenderWireless.java +++ b/src/main/java/codechicken/wirelessredstone/logic/RenderWireless.java @@ -15,7 +15,6 @@ import org.lwjgl.opengl.GL11; -import codechicken.lib.colour.ColourRGBA; import codechicken.lib.lighting.LightModel; import codechicken.lib.lighting.LightModel.Light; import codechicken.lib.lighting.PlanarLightModel; @@ -26,7 +25,6 @@ import codechicken.lib.render.CCRenderState; import codechicken.lib.render.Vertex5; import codechicken.lib.render.uv.MultiIconTransformation; -import codechicken.lib.vec.Scale; import codechicken.lib.vec.Transformation; import codechicken.lib.vec.Translation; import codechicken.lib.vec.Vector3; @@ -86,24 +84,24 @@ public static void loadIcons(IIconRegister r) { public static void renderInv(WirelessPart p) { final CCRenderState state = CCRenderState.instance(); - state.reset(); + state.resetInstance(); state.useNormals = true; - state.pushLightmap(); - state.startDrawing(7); - state.setPipeline(base_icont[0]); + state.pushLightmapInstance(); + state.startDrawingInstance(7); + state.setPipelineInstance(base_icont[0]); BlockRenderer.renderCuboid(WirelessPart.baseBounds(0), 0); models[p.modelId()][0].render(model_icont); - state.draw(); + state.drawInstance(); renderPearl(zero, p); } public static void renderWorld(WirelessPart p) { final CCRenderState state = CCRenderState.instance(); - state.setBrightness(p.world(), p.x(), p.y(), p.z()); + state.setBrightnessInstance(p.world(), p.x(), p.y(), p.z()); Transformation t = new Translation(p.x(), p.y(), p.z()); - state.setPipeline(p.rotationT().at(center).with(t), base_icont[p.textureSet()], rlm); + state.setPipelineInstance(p.rotationT().at(center).with(t), base_icont[p.textureSet()], rlm); BlockRenderer.renderCuboid(p.baseRenderBounds, p.baseRenderMask); models[p.modelId()][p.side() << 2 | p.rotation()].render(t, model_icont); } @@ -111,7 +109,7 @@ public static void renderWorld(WirelessPart p) { public static void renderFreq(Vector3 pos, TransceiverPart p) { GL11.glPushMatrix(); - pos.copy().add(center).translation().glApply(); + GL11.glTranslated(pos.x + center.x, pos.y + center.y, pos.z + center.z); p.rotationT().glApply(); renderFreq(p.getFreq()); @@ -142,11 +140,13 @@ private static void renderFreq(int freq) { public static void renderPearl(Vector3 pos, WirelessPart p) { GL11.glPushMatrix(); - pos.translation().glApply(); + GL11.glTranslated(pos.x, pos.y, pos.z); p.rotationT().at(center).glApply(); - p.getPearlPos().translation().glApply(); + final Vector3 pearlPos = p.getPearlPos(); + GL11.glTranslated(pearlPos.x, pearlPos.y, pearlPos.z); p.getPearlRotation().glApply(); - new Scale(p.getPearlScale()).glApply(); + final double pearlScale = p.getPearlScale(); + GL11.glScaled(pearlScale, pearlScale, pearlScale); float light = 1; if (p.tile() != null) { GL11.glRotatef((float) (p.getPearlSpin() * MathHelper.todeg), 0, 1, 0); @@ -155,13 +155,18 @@ public static void renderPearl(Vector3 pos, WirelessPart p) { GL11.glDisable(GL11.GL_LIGHTING); final CCRenderState state = CCRenderState.instance(); - state.reset(); - state.changeTexture("wrcbe_core:textures/hedronmap.png"); - state.pushLightmap(); - state.setColour(new ColourRGBA(light, light, light, 1).rgba()); - state.startDrawing(4); + state.resetInstance(); + CCRenderState.changeTexture("wrcbe_core:textures/hedronmap.png"); + state.pushLightmapInstance(); + final byte lightByte = (byte) (0xFF * light); + final byte alpha = (byte) 0xFF; + final int colorI = (lightByte & 0xFF) << 24 | (lightByte & 0xFF) << 16 + | (lightByte & 0xFF) << 8 + | (alpha & 0xFF); + state.setColourInstance(colorI); + state.startDrawingInstance(4); CCModelLibrary.icosahedron4.render(); - state.draw(); + state.drawInstance(); GL11.glEnable(GL11.GL_LIGHTING); GL11.glPopMatrix();