Skip to content

Commit

Permalink
remove useless GLTranslate; add a border render to display pointed block
Browse files Browse the repository at this point in the history
  • Loading branch information
kuzuanpa committed Mar 11, 2024
1 parent 525c8fd commit dd64a25
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 13 deletions.
13 changes: 9 additions & 4 deletions src/main/java/blockrenderer6343/client/WorldSceneRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<WorldSceneRenderer> beforeRender;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -247,7 +247,6 @@ protected void drawWorld() {
dummyWorldHandler.dummyWorldBlocksHashMap.forEach((pos,block)->{
GL11.glPushMatrix();
List<IDummyBlockAnime> 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);
Expand All @@ -270,6 +269,7 @@ protected void drawWorld() {
GL11.glPopMatrix();
}
});

mc.gameSettings.ambientOcclusion = savedAo;
RenderHelper.enableStandardItemLighting();
glEnable(GL_LIGHTING);
Expand All @@ -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<IDummyBlockAnime> anime = dummyWorldHandler.dummyWorldTileEntityHashMap.get(pos).animeList;
if(anime!=null&&!anime.isEmpty())anime.forEach(a->a.animeDraw(initTime,this));
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 -> {});

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}

}

Expand Down

0 comments on commit dd64a25

Please sign in to comment.