From dd64a256fbbe50a344680354c556baf84809f909 Mon Sep 17 00:00:00 2001 From: kuzuanpa Date: Tue, 12 Mar 2024 05:40:46 +0800 Subject: [PATCH] remove useless GLTranslate; add a border render to display pointed block --- .../client/WorldSceneRenderer.java | 13 +++++++++---- .../anime/DummyBlockAnimeOutlineGlowth.java | 6 +++--- .../render/dummyWorld/dummyWorldTileEntity.java | 1 - .../client/render/gui/button/DummyWorld.java | 14 +++++++++----- 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/main/java/blockrenderer6343/client/WorldSceneRenderer.java b/src/main/java/blockrenderer6343/client/WorldSceneRenderer.java index c018ff0..b506832 100644 --- a/src/main/java/blockrenderer6343/client/WorldSceneRenderer.java +++ b/src/main/java/blockrenderer6343/client/WorldSceneRenderer.java @@ -5,6 +5,7 @@ import java.util.List; import java.util.function.Consumer; +import cn.kuzuanpa.thinker.client.render.dummyWorld.anime.DummyBlockAnimeOutlineGlowth; import cn.kuzuanpa.thinker.client.render.dummyWorld.anime.IDummyBlockAnime; import cn.kuzuanpa.thinker.client.render.dummyWorld.anime.IDummyBlockAnimeDrawAdditionalQuads; import cn.kuzuanpa.thinker.client.render.dummyWorld.dummyWorldHandler; @@ -46,6 +47,7 @@ * @Description: Abstract class, and extend a lot of features compared with the original one. */ public abstract class WorldSceneRenderer { + public BlockPosition pointedBlock; public final World world; private Consumer beforeRender; @@ -113,10 +115,8 @@ public void render(int x, int y, int width, int height, int mouseX, int mouseY, // check lookingAt this.lastTraceResult = null; if (onLookingAt != null) { - GL11.glTranslatef(100,0,0); Vector3f hitPos = ProjectionUtils.unProject(mouseX, mouseY); MovingObjectPosition result = rayTrace(hitPos); - GL11.glTranslatef(-100,0,0); if (result != null) { this.lastTraceResult = result; onLookingAt.accept(result); @@ -247,7 +247,6 @@ protected void drawWorld() { dummyWorldHandler.dummyWorldBlocksHashMap.forEach((pos,block)->{ GL11.glPushMatrix(); List anime = dummyWorldHandler.dummyWorldBlocksHashMap.get(pos).animeList; - GL11.glTranslatef(100,0,0); if(anime!=null&&!anime.isEmpty())anime.forEach(a->{ if(a instanceof IDummyBlockAnimeDrawAdditionalQuads) ((IDummyBlockAnimeDrawAdditionalQuads) a).drawAdditionalQuads(initTime,this); GL11.glTranslatef(pos.x, pos.y, pos.z); @@ -270,6 +269,7 @@ protected void drawWorld() { GL11.glPopMatrix(); } }); + mc.gameSettings.ambientOcclusion = savedAo; RenderHelper.enableStandardItemLighting(); glEnable(GL_LIGHTING); @@ -283,7 +283,6 @@ protected void drawWorld() { GL11.glPushMatrix(); setDefaultPassRenderState(finalPass); if(t.tile.shouldRenderInPass(finalPass)){ - GL11.glTranslatef(100,0,0); GL11.glTranslatef(pos.x, pos.y, pos.z); List anime = dummyWorldHandler.dummyWorldTileEntityHashMap.get(pos).animeList; if(anime!=null&&!anime.isEmpty())anime.forEach(a->a.animeDraw(initTime,this)); @@ -298,6 +297,12 @@ protected void drawWorld() { GL11.glPopMatrix(); }); } + + //draw pointed block + GL11.glPushMatrix(); + if(pointedBlock!=null) DummyBlockAnimeOutlineGlowth.renderBlockOutlineAt(pointedBlock, 0xCCCCCC, 1F); + GL11.glPopMatrix(); + ForgeHooksClient.setRenderPass(-1); glEnable(GL_DEPTH_TEST); glDisable(GL_BLEND); diff --git a/src/main/java/cn/kuzuanpa/thinker/client/render/dummyWorld/anime/DummyBlockAnimeOutlineGlowth.java b/src/main/java/cn/kuzuanpa/thinker/client/render/dummyWorld/anime/DummyBlockAnimeOutlineGlowth.java index 42d42a2..3ea323f 100644 --- a/src/main/java/cn/kuzuanpa/thinker/client/render/dummyWorld/anime/DummyBlockAnimeOutlineGlowth.java +++ b/src/main/java/cn/kuzuanpa/thinker/client/render/dummyWorld/anime/DummyBlockAnimeOutlineGlowth.java @@ -36,7 +36,7 @@ public void updateButton(long initTime, WorldSceneRenderer renderer) { public String jsonName() { return "Block.OutlineGlowth"; } - public void renderBlockOutlineAt(BlockPosition pos, int color, float thickness) { + public static void renderBlockOutlineAt(BlockPosition pos, int color, float thickness) { GL11.glPushMatrix(); GL11.glPushAttrib(2896); GL11.glDisable(2929); @@ -48,7 +48,7 @@ public void renderBlockOutlineAt(BlockPosition pos, int color, float thickness) AxisAlignedBB axis= AxisAlignedBB.getBoundingBox(pos.x, pos.y, pos.z, pos.x + 1, pos.y + 1, pos.z + 1); GL11.glLineWidth(thickness); GL11.glColor4ub((byte)colorRGB.getRed(), (byte)colorRGB.getGreen(), (byte)colorRGB.getBlue(), (byte)255); - this.renderBlockOutline(axis); + renderBlockOutline(axis); GL11.glPopMatrix(); GL11.glEnable(2929); @@ -58,7 +58,7 @@ public void renderBlockOutlineAt(BlockPosition pos, int color, float thickness) GL11.glPopMatrix(); } /**Copied from Botania**/ - private void renderBlockOutline(AxisAlignedBB aabb) { + private static void renderBlockOutline(AxisAlignedBB aabb) { Tessellator tessellator = Tessellator.instance; double ix = aabb.minX; double iy = aabb.minY; diff --git a/src/main/java/cn/kuzuanpa/thinker/client/render/dummyWorld/dummyWorldTileEntity.java b/src/main/java/cn/kuzuanpa/thinker/client/render/dummyWorld/dummyWorldTileEntity.java index 6ee62de..9f9cef8 100644 --- a/src/main/java/cn/kuzuanpa/thinker/client/render/dummyWorld/dummyWorldTileEntity.java +++ b/src/main/java/cn/kuzuanpa/thinker/client/render/dummyWorld/dummyWorldTileEntity.java @@ -2,7 +2,6 @@ import blockrenderer6343.api.utils.BlockPosition; import cn.kuzuanpa.thinker.client.render.dummyWorld.anime.IDummyBlockAnime; -import jdk.nashorn.internal.ir.Block; import net.minecraft.tileentity.TileEntity; import java.util.ArrayList; diff --git a/src/main/java/cn/kuzuanpa/thinker/client/render/gui/button/DummyWorld.java b/src/main/java/cn/kuzuanpa/thinker/client/render/gui/button/DummyWorld.java index f2d2c2c..dd02e88 100644 --- a/src/main/java/cn/kuzuanpa/thinker/client/render/gui/button/DummyWorld.java +++ b/src/main/java/cn/kuzuanpa/thinker/client/render/gui/button/DummyWorld.java @@ -15,12 +15,14 @@ import blockrenderer6343.client.WorldSceneRenderer; import blockrenderer6343.world.TrackedDummyWorld; import cn.kuzuanpa.thinker.client.profileHandler; +import cn.kuzuanpa.thinker.client.render.dummyWorld.anime.DummyBlockAnimeOutlineGlowth; import codechicken.lib.gui.GuiDraw; import codechicken.lib.math.MathHelper; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.RenderBlocks; import net.minecraft.init.Blocks; +import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.IIcon; import net.minecraft.util.MovingObjectPosition; import org.lwjgl.input.Mouse; @@ -72,11 +74,9 @@ protected void initializeSceneRenderer(boolean resetCamera) { ((blockrenderer6343.world.DummyWorld) renderer.world).updateEntitiesForNEI(); renderer.setClearColor(0xC6C6C6); - lookAt.setX((float) (100)); - Vector3f size = ((TrackedDummyWorld) renderer.world).getSize(); Vector3f minPos = ((TrackedDummyWorld) renderer.world).getMinPos(); - center = new Vector3f((minPos.x + size.x / 2)+100, minPos.y + size.y / 2, minPos.z + size.z / 2); + center = new Vector3f((minPos.x + size.x / 2), minPos.y + size.y / 2, minPos.z + size.z / 2); renderer.setOnLookingAt(ray -> {}); @@ -120,7 +120,7 @@ private void resetCenter() { TrackedDummyWorld world = (TrackedDummyWorld) renderer.world; Vector3f size = world.getSize(); Vector3f minPos = world.getMinPos(); - center = new Vector3f((minPos.x + size.x / 2)+100, minPos.y + size.y / 2, minPos.z + size.z / 2); + center = new Vector3f((minPos.x + size.x / 2), minPos.y + size.y / 2, minPos.z + size.z / 2); renderer.setCameraLookAt(center, zoom, Math.toRadians(rotationPitch), Math.toRadians(rotationYaw)); } private void renderBlockOverLay(BlockPosition pos, IIcon icon) { @@ -193,7 +193,11 @@ public void drawButton(Minecraft mc, int mouseX, int mouseY) { && !renderer.world.isAirBlock(rayTraceResult.blockX, rayTraceResult.blockY, rayTraceResult.blockZ)) { Block block = renderer.world.getBlock(rayTraceResult.blockX, rayTraceResult.blockY, rayTraceResult.blockZ); } - if(rayTraceResult!=null)System.out.println(rayTraceResult.blockX+"/"+rayTraceResult.blockY+ rayTraceResult.blockZ); + if(rayTraceResult!=null) { + renderer.pointedBlock = new BlockPosition(rayTraceResult.blockX, rayTraceResult.blockY, rayTraceResult.blockZ); + }else { + renderer.pointedBlock = null; + } }