Skip to content

Commit

Permalink
Move chunk area settings into a separate class
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander01998 committed Sep 4, 2023
1 parent 1369c14 commit 9b097f5
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 230 deletions.
95 changes: 13 additions & 82 deletions src/main/java/net/wurstclient/hacks/CaveFinderHack.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.mojang.blaze3d.systems.RenderSystem;

import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.client.gl.ShaderProgram;
import net.minecraft.client.gl.VertexBuffer;
import net.minecraft.client.network.ClientPlayerEntity;
Expand All @@ -47,18 +48,16 @@
import net.minecraft.util.math.ChunkPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.EmptyChunk;
import net.wurstclient.Category;
import net.wurstclient.SearchTags;
import net.wurstclient.events.PacketInputListener;
import net.wurstclient.events.RenderListener;
import net.wurstclient.events.UpdateListener;
import net.wurstclient.hack.Hack;
import net.wurstclient.settings.ChunkAreaSetting;
import net.wurstclient.settings.ColorSetting;
import net.wurstclient.settings.EnumSetting;
import net.wurstclient.settings.SliderSetting;
import net.wurstclient.settings.SliderSetting.ValueDisplay;
import net.wurstclient.util.BlockUtils;
import net.wurstclient.util.BlockVertexCompiler;
import net.wurstclient.util.ChatUtils;
import net.wurstclient.util.ChunkSearcher;
Expand All @@ -70,10 +69,9 @@
public final class CaveFinderHack extends Hack
implements UpdateListener, PacketInputListener, RenderListener
{
private final EnumSetting<Area> area = new EnumSetting<>("Area",
private final ChunkAreaSetting area = new ChunkAreaSetting("Area",
"The area around the player to search in.\n"
+ "Higher values require a faster computer.",
Area.values(), Area.D11);
+ "Higher values require a faster computer.");

private final SliderSetting limit = new SliderSetting("Limit",
"The maximum number of blocks to display.\n"
Expand Down Expand Up @@ -181,17 +179,14 @@ public void onReceivedPacket(PacketInputEvent event)
@Override
public void onUpdate()
{
Block currentBlock = BlockUtils.getBlockFromName("minecraft:cave_air");
Block blockToFind = Blocks.CAVE_AIR;
BlockPos eyesPos = BlockPos.ofFloored(RotationUtils.getEyesPos());

ChunkPos center = getPlayerChunkPos(eyesPos);
int range = area.getSelected().chunkRange;
int dimensionId = MC.world.getRegistryKey().toString().hashCode();

addSearchersInRange(center, range, currentBlock, dimensionId);
removeSearchersOutOfRange(center, range);
replaceSearchersWithDifferences(currentBlock, dimensionId);
replaceSearchersWithChunkUpdate(currentBlock, dimensionId);
addSearchersInRange(blockToFind, dimensionId);
removeSearchersOutOfRange();
replaceSearchersWithDifferences(blockToFind, dimensionId);
replaceSearchersWithChunkUpdate(blockToFind, dimensionId);

if(!areAllChunkSearchersDone())
return;
Expand Down Expand Up @@ -255,19 +250,9 @@ public void onRender(MatrixStack matrixStack, float partialTicks)
GL11.glDisable(GL11.GL_BLEND);
}

private ChunkPos getPlayerChunkPos(BlockPos eyesPos)
{
int chunkX = eyesPos.getX() >> 4;
int chunkZ = eyesPos.getZ() >> 4;
return MC.world.getChunk(chunkX, chunkZ).getPos();
}

private void addSearchersInRange(ChunkPos center, int chunkRange,
Block block, int dimensionId)
private void addSearchersInRange(Block block, int dimensionId)
{
ArrayList<Chunk> chunksInRange = getChunksInRange(center, chunkRange);

for(Chunk chunk : chunksInRange)
for(Chunk chunk : area.getSelected().getChunksInRange())
{
if(searchers.containsKey(chunk))
continue;
Expand All @@ -276,31 +261,12 @@ private void addSearchersInRange(ChunkPos center, int chunkRange,
}
}

private ArrayList<Chunk> getChunksInRange(ChunkPos center, int chunkRange)
{
ArrayList<Chunk> chunksInRange = new ArrayList<>();

for(int x = center.x - chunkRange; x <= center.x + chunkRange; x++)
for(int z = center.z - chunkRange; z <= center.z + chunkRange; z++)
{
Chunk chunk = MC.world.getChunk(x, z);
if(chunk instanceof EmptyChunk)
continue;

chunksInRange.add(chunk);
}

return chunksInRange;
}

private void removeSearchersOutOfRange(ChunkPos center, int chunkRange)
private void removeSearchersOutOfRange()
{
for(ChunkSearcher searcher : new ArrayList<>(searchers.values()))
{
ChunkPos searcherPos = searcher.getChunk().getPos();

if(Math.abs(searcherPos.x - center.x) <= chunkRange
&& Math.abs(searcherPos.z - center.z) <= chunkRange)
if(area.getSelected().isInRange(searcherPos))
continue;

removeSearcher(searcher);
Expand Down Expand Up @@ -490,39 +456,4 @@ public ArrayList<int[]> getVerticesFromTask()
throw new RuntimeException(e);
}
}

private enum Area
{
D3("3x3 chunks", 1),
D5("5x5 chunks", 2),
D7("7x7 chunks", 3),
D9("9x9 chunks", 4),
D11("11x11 chunks", 5),
D13("13x13 chunks", 6),
D15("15x15 chunks", 7),
D17("17x17 chunks", 8),
D19("19x19 chunks", 9),
D21("21x21 chunks", 10),
D23("23x23 chunks", 11),
D25("25x25 chunks", 12),
D27("27x27 chunks", 13),
D29("29x29 chunks", 14),
D31("31x31 chunks", 15),
D33("33x33 chunks", 16);

private final String name;
private final int chunkRange;

private Area(String name, int chunkRange)
{
this.name = name;
this.chunkRange = chunkRange;
}

@Override
public String toString()
{
return name;
}
}
}
76 changes: 18 additions & 58 deletions src/main/java/net/wurstclient/hacks/MobSpawnEspHack.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import net.minecraft.network.packet.s2c.play.ChunkDataS2CPacket;
import net.minecraft.network.packet.s2c.play.ChunkDeltaUpdateS2CPacket;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.LightType;
import net.minecraft.world.chunk.Chunk;
import net.wurstclient.Category;
Expand All @@ -44,20 +45,21 @@
import net.wurstclient.events.UpdateListener;
import net.wurstclient.hack.Hack;
import net.wurstclient.settings.CheckboxSetting;
import net.wurstclient.settings.EnumSetting;
import net.wurstclient.settings.ChunkAreaSetting;
import net.wurstclient.settings.ChunkAreaSetting.ChunkArea;
import net.wurstclient.settings.SliderSetting;
import net.wurstclient.settings.SliderSetting.ValueDisplay;
import net.wurstclient.util.ChunkUtils;
import net.wurstclient.util.MinPriorityThreadFactory;
import net.wurstclient.util.RenderUtils;
import net.wurstclient.util.RotationUtils;

@SearchTags({"mob spawn esp", "LightLevelESP", "light level esp",
"LightLevelOverlay", "light level overlay"})
public final class MobSpawnEspHack extends Hack
implements UpdateListener, PacketInputListener, RenderListener
{
private final EnumSetting<DrawDistance> drawDistance = new EnumSetting<>(
"Draw distance", DrawDistance.values(), DrawDistance.D9);
private final ChunkAreaSetting drawDistance =
new ChunkAreaSetting("Draw distance", "", ChunkArea.A9);

private final SliderSetting loadingSpeed = new SliderSetting(
"Loading speed", 1, 1, 5, 1, ValueDisplay.INTEGER.withSuffix("x"));
Expand Down Expand Up @@ -108,20 +110,10 @@ public void onDisable()
@Override
public void onUpdate()
{
ClientWorld world = MC.world;

BlockPos eyesBlock = BlockPos.ofFloored(RotationUtils.getEyesPos());
int chunkX = eyesBlock.getX() >> 4;
int chunkZ = eyesBlock.getZ() >> 4;
int chunkRange = drawDistance.getSelected().chunkRange;
ChunkArea area = drawDistance.getSelected();

ArrayList<Chunk> chunks = new ArrayList<>();
for(int x = chunkX - chunkRange; x <= chunkX + chunkRange; x++)
for(int z = chunkZ - chunkRange; z <= chunkZ + chunkRange; z++)
chunks.add(world.getChunk(x, z));

// create & start scanners for new chunks
for(Chunk chunk : chunks)
for(Chunk chunk : area.getChunksInRange())
{
if(scanners.containsKey(chunk))
continue;
Expand All @@ -134,8 +126,7 @@ public void onUpdate()
// remove old scanners that are out of range
for(ChunkScanner scanner : new ArrayList<>(scanners.values()))
{
if(Math.abs(scanner.chunk.getPos().x - chunkX) <= chunkRange
&& Math.abs(scanner.chunk.getPos().z - chunkZ) <= chunkRange)
if(area.isInRange(scanner.chunk.getPos()))
continue;

if(!scanner.doneCompiling)
Expand All @@ -151,9 +142,9 @@ public void onUpdate()
}

// generate vertex buffers
Comparator<ChunkScanner> c =
Comparator.comparingInt(s -> Math.abs(s.chunk.getPos().x - chunkX)
+ Math.abs(s.chunk.getPos().z - chunkZ));
ChunkPos center = MC.player.getChunkPos();
Comparator<ChunkScanner> c = Comparator.comparingInt(
s -> ChunkUtils.getManhattanDistance(center, s.chunk.getPos()));
List<ChunkScanner> sortedScanners = scanners.values().stream()
.filter(s -> s.doneScanning).filter(s -> !s.doneCompiling).sorted(c)
.limit(loadingSpeed.getValueI()).collect(Collectors.toList());
Expand Down Expand Up @@ -223,15 +214,14 @@ public void onReceivedPacket(PacketInputEvent event)
@Override
public void onRender(MatrixStack matrixStack, float partialTicks)
{
// Avoid inconsistent GL state if setting changed mid-onRender
boolean depthTest = this.depthTest.isChecked();

// 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);

boolean depthTest = this.depthTest.isChecked();
if(!depthTest)
GL11.glDisable(GL11.GL_DEPTH_TEST);
GL11.glEnable(GL11.GL_CULL_FACE);

RenderSystem.setShaderColor(1, 1, 1, 1);
RenderSystem.setShader(GameRenderer::getPositionColorProgram);
Expand All @@ -254,10 +244,11 @@ public void onRender(MatrixStack matrixStack, float partialTicks)
matrixStack.pop();
}

// GL resets
RenderSystem.setShaderColor(1, 1, 1, 1);
if(!depthTest)
GL11.glEnable(GL11.GL_DEPTH_TEST);

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

Expand Down Expand Up @@ -396,35 +387,4 @@ private void reset()
doneCompiling = false;
}
}

private enum DrawDistance
{
D3("3x3 chunks", 1),
D5("5x5 chunks", 2),
D7("7x7 chunks", 3),
D9("9x9 chunks", 4),
D11("11x11 chunks", 5),
D13("13x13 chunks", 6),
D15("15x15 chunks", 7),
D17("17x17 chunks", 8),
D19("19x19 chunks", 9),
D21("21x21 chunks", 10),
D23("23x23 chunks", 11),
D25("25x25 chunks", 12);

private final String name;
private final int chunkRange;

private DrawDistance(String name, int chunkRange)
{
this.name = name;
this.chunkRange = chunkRange;
}

@Override
public String toString()
{
return name;
}
}
}
26 changes: 9 additions & 17 deletions src/main/java/net/wurstclient/hacks/SearchHack.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,8 @@
import net.wurstclient.events.RenderListener;
import net.wurstclient.events.UpdateListener;
import net.wurstclient.hack.Hack;
import net.wurstclient.hacks.search.SearchArea;
import net.wurstclient.settings.BlockSetting;
import net.wurstclient.settings.EnumSetting;
import net.wurstclient.settings.ChunkAreaSetting;
import net.wurstclient.settings.SliderSetting;
import net.wurstclient.settings.SliderSetting.ValueDisplay;
import net.wurstclient.util.BlockVertexCompiler;
Expand All @@ -68,10 +67,9 @@ public final class SearchHack extends Hack
private final BlockSetting block = new BlockSetting("Block",
"The type of block to search for.", "minecraft:diamond_ore", false);

private final EnumSetting<SearchArea> area = new EnumSetting<>("Area",
private final ChunkAreaSetting area = new ChunkAreaSetting("Area",
"The area around the player to search in.\n"
+ "Higher values require a faster computer.",
SearchArea.values(), SearchArea.D11);
+ "Higher values require a faster computer.");

private final SliderSetting limit = new SliderSetting("Limit",
"The maximum number of blocks to display.\n"
Expand Down Expand Up @@ -182,12 +180,10 @@ public void onUpdate()
{
Block currentBlock = block.getBlock();
BlockPos eyesPos = BlockPos.ofFloored(RotationUtils.getEyesPos());

ChunkPos center = MC.player.getChunkPos();
int dimensionId = MC.world.getRegistryKey().toString().hashCode();

addSearchersInRange(center, currentBlock, dimensionId);
removeSearchersOutOfRange(center);
addSearchersInRange(currentBlock, dimensionId);
removeSearchersOutOfRange();
replaceSearchersWithDifferences(currentBlock, dimensionId);
replaceSearchersWithChunkUpdate(currentBlock, dimensionId);

Expand Down Expand Up @@ -247,13 +243,9 @@ public void onRender(MatrixStack matrixStack, float partialTicks)
GL11.glDisable(GL11.GL_BLEND);
}

private void addSearchersInRange(ChunkPos center, Block block,
int dimensionId)
private void addSearchersInRange(Block block, int dimensionId)
{
ArrayList<Chunk> chunksInRange =
area.getSelected().getChunksInRange(center);

for(Chunk chunk : chunksInRange)
for(Chunk chunk : area.getSelected().getChunksInRange())
{
if(searchers.containsKey(chunk))
continue;
Expand All @@ -262,12 +254,12 @@ private void addSearchersInRange(ChunkPos center, Block block,
}
}

private void removeSearchersOutOfRange(ChunkPos center)
private void removeSearchersOutOfRange()
{
for(ChunkSearcher searcher : new ArrayList<>(searchers.values()))
{
ChunkPos searcherPos = searcher.getChunk().getPos();
if(area.getSelected().isInRange(searcherPos, center))
if(area.getSelected().isInRange(searcherPos))
continue;

removeSearcher(searcher);
Expand Down
Loading

0 comments on commit 9b097f5

Please sign in to comment.