Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/fabric-1.20.4' into fabric-1.20.4
Browse files Browse the repository at this point in the history
  • Loading branch information
SymoHTL committed Apr 21, 2024
2 parents bc7af66 + 5c43d3b commit 70166db
Showing 1 changed file with 24 additions and 19 deletions.
43 changes: 24 additions & 19 deletions src/client/java/dev/symo/finz/modules/impl/esp/BedESP.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

import java.awt.*;
import java.util.ArrayList;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.IntStream;

public class BedESP extends AModule implements TickListener, WorldRenderListener {
private final IntSetting _range = new IntSetting("Range", "Range to scan for blocks",
Expand Down Expand Up @@ -55,30 +58,32 @@ public void onTick() {
}
_tickDelay = 40;

// look for beds in range around player

var playerPos = mc.player.getBlockPos();
var playerX = playerPos.getX();
var playerY = playerPos.getY();
var playerZ = playerPos.getZ();

var range = _range.getValue();

for (int x = playerX - range; x < playerX + range; x++) {
for (int y = playerY - range; y < playerY + range; y++) {
for (int z = playerZ - range; z < playerZ + range; z++) {
var pos = new BlockPos(x, y, z);
var state = mc.world.getBlockState(pos);
var block = state.getBlock();
if (block instanceof BedBlock && !beds.contains(pos))
beds.add(pos);
}
}
}
Set<BlockPos> newBlocks = ConcurrentHashMap.newKeySet();

beds.removeIf(pos -> !(mc.world.getBlockState(pos).getBlock() instanceof BedBlock));
IntStream.rangeClosed(playerPos.getX() - range, playerPos.getX() + range).parallel().forEach(x -> {
IntStream.rangeClosed(playerPos.getY() - range, playerPos.getY() + range).forEach(y -> {
IntStream.rangeClosed(playerPos.getZ() - range, playerPos.getZ() + range).forEach(z -> {
BlockPos pos = new BlockPos(x, y, z);
var block = mc.world.getBlockState(pos).getBlock();
if (block instanceof BedBlock) {
newBlocks.add(pos);
}
});
});
});

beds.addAll(newBlocks);

beds.parallelStream().filter(block -> !inRange(block, playerPos, range) || !(mc.world.getBlockState(block).getBlock() instanceof BedBlock)).toList().forEach(beds::remove);
}

beds.removeIf(pos -> Math.abs(pos.getX() - playerX) > range + range / 2 || Math.abs(pos.getY() - playerY) > range + range / 2 || Math.abs(pos.getZ() - playerZ) > range + range / 2);
private boolean inRange(BlockPos pos, BlockPos playerPos, int range) {
return Math.abs(pos.getX() - playerPos.getX()) <= range &&
Math.abs(pos.getY() - playerPos.getY()) <= range &&
Math.abs(pos.getZ() - playerPos.getZ()) <= range;
}

public void onWorldRender(MatrixStack matrixStack, float partialTicks, WorldRenderContext context) {
Expand Down

0 comments on commit 70166db

Please sign in to comment.