Skip to content

Commit

Permalink
Move tree rendering code to Tree class
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander01998 committed Nov 5, 2023
1 parent d2f50ac commit cefa68a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 42 deletions.
38 changes: 1 addition & 37 deletions src/main/java/net/wurstclient/hacks/TreeBotHack.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,8 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.joml.Matrix4f;
import org.lwjgl.opengl.GL11;

import com.mojang.blaze3d.systems.RenderSystem;

import net.minecraft.client.gl.ShaderProgram;
import net.minecraft.client.gl.VertexBuffer;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.render.GameRenderer;
import net.minecraft.client.util.math.MatrixStack;
Expand Down Expand Up @@ -49,7 +44,6 @@
import net.wurstclient.util.BlockBreaker.BlockBreakingParams;
import net.wurstclient.util.BlockUtils;
import net.wurstclient.util.OverlayRenderer;
import net.wurstclient.util.RenderUtils;

@SearchTags({"tree bot"})
@DontSaveState
Expand Down Expand Up @@ -280,42 +274,12 @@ public void onRender(MatrixStack matrixStack, float partialTicks)
angleFinder.renderPath(matrixStack, pathCmd.isDebugMode(),
pathCmd.isDepthTest());

// GL settings
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glEnable(GL11.GL_CULL_FACE);
GL11.glDisable(GL11.GL_DEPTH_TEST);

if(tree != null)
drawTree(matrixStack);

// GL resets
RenderSystem.setShaderColor(1, 1, 1, 1);
GL11.glEnable(GL11.GL_DEPTH_TEST);
GL11.glDisable(GL11.GL_BLEND);
tree.draw(matrixStack);

overlay.render(matrixStack, partialTicks, currentBlock);
}

private void drawTree(MatrixStack matrixStack)
{
RenderSystem.setShaderColor(0, 1, 0, 0.5F);

matrixStack.push();
RenderUtils.applyRegionalRenderOffset(matrixStack,
MC.world.getChunk(tree.getStump()));

Matrix4f viewMatrix = matrixStack.peek().getPositionMatrix();
Matrix4f projMatrix = RenderSystem.getProjectionMatrix();
ShaderProgram shader = RenderSystem.getShader();

tree.getVertexBuffer().bind();
tree.getVertexBuffer().draw(viewMatrix, projMatrix, shader);
VertexBuffer.unbind();

matrixStack.pop();
}

private ArrayList<BlockPos> getNeighbors(BlockPos pos)
{
return BlockUtils
Expand Down
43 changes: 38 additions & 5 deletions src/main/java/net/wurstclient/hacks/treebot/Tree.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,19 @@

import java.util.ArrayList;

import org.joml.Matrix4f;
import org.lwjgl.opengl.GL11;

import com.mojang.blaze3d.systems.RenderSystem;

import net.minecraft.client.gl.ShaderProgram;
import net.minecraft.client.gl.VertexBuffer;
import net.minecraft.client.render.BufferBuilder;
import net.minecraft.client.render.BufferBuilder.BuiltBuffer;
import net.minecraft.client.render.Tessellator;
import net.minecraft.client.render.VertexFormat;
import net.minecraft.client.render.VertexFormats;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.Vec3d;
Expand Down Expand Up @@ -65,10 +70,43 @@ public void compileBuffer()
VertexBuffer.unbind();
}

public void draw(MatrixStack matrixStack)
{
if(vertexBuffer == null)
return;

// GL settings
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glEnable(GL11.GL_CULL_FACE);
GL11.glDisable(GL11.GL_DEPTH_TEST);

RenderSystem.setShaderColor(0, 1, 0, 0.5F);

matrixStack.push();
RenderUtils.applyRegionalRenderOffset(matrixStack, RegionPos.of(stump));

Matrix4f viewMatrix = matrixStack.peek().getPositionMatrix();
Matrix4f projMatrix = RenderSystem.getProjectionMatrix();
ShaderProgram shader = RenderSystem.getShader();

vertexBuffer.bind();
vertexBuffer.draw(viewMatrix, projMatrix, shader);
VertexBuffer.unbind();

matrixStack.pop();

// GL resets
RenderSystem.setShaderColor(1, 1, 1, 1);
GL11.glEnable(GL11.GL_DEPTH_TEST);
GL11.glDisable(GL11.GL_BLEND);
}

@Override
public void close()
{
vertexBuffer.close();
vertexBuffer = null;
}

public BlockPos getStump()
Expand All @@ -80,9 +118,4 @@ public ArrayList<BlockPos> getLogs()
{
return logs;
}

public VertexBuffer getVertexBuffer()
{
return vertexBuffer;
}
}

0 comments on commit cefa68a

Please sign in to comment.