diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/combat/AnchorAura.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/combat/AnchorAura.java index 93c84ed52e..fe02576006 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/combat/AnchorAura.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/combat/AnchorAura.java @@ -302,6 +302,7 @@ private void doAnchorAura() { // Find best positions to place new anchors or break existing anchors int iteratorRange = (int) Math.ceil(Math.max(placeRange.get(), breakRange.get())); + if (place.get()) BlockIterator.iCareAboutAirBlocks(); BlockIterator.register(iteratorRange, iteratorRange, (blockPos, blockState) -> { boolean isPlacing = blockState.getBlock() != Blocks.RESPAWN_ANCHOR; diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/render/LightOverlay.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/render/LightOverlay.java index 9095abe34f..bba40f99ea 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/render/LightOverlay.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/render/LightOverlay.java @@ -88,6 +88,7 @@ private void onTick(TickEvent.Pre event) { crossPool.freeAll(crosses); crosses.clear(); + BlockIterator.iCareAboutAirBlocks(); BlockIterator.register(horizontalRange.get(), verticalRange.get(), (blockPos, blockState) -> { switch (BlockUtils.isValidMobSpawn(blockPos, blockState, lightLevel.get())) { case Potential -> crosses.add(crossPool.get().set(blockPos, true)); diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/world/SpawnProofer.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/world/SpawnProofer.java index a3fb13c7a7..c4a721738c 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/world/SpawnProofer.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/world/SpawnProofer.java @@ -118,6 +118,7 @@ private void onTickPre(TickEvent.Pre event) { spawnPool.freeAll(spawns); spawns.clear(); + BlockIterator.iCareAboutAirBlocks(); BlockIterator.register((int) Math.ceil(placeRange.get()), (int) Math.ceil(placeRange.get()), (blockPos, blockState) -> { BlockUtils.MobSpawn spawn = BlockUtils.isValidMobSpawn(blockPos, blockState, lightLevel.get()); diff --git a/src/main/java/meteordevelopment/meteorclient/utils/world/BlockIterator.java b/src/main/java/meteordevelopment/meteorclient/utils/world/BlockIterator.java index cc71feb711..9e011ba4c8 100644 --- a/src/main/java/meteordevelopment/meteorclient/utils/world/BlockIterator.java +++ b/src/main/java/meteordevelopment/meteorclient/utils/world/BlockIterator.java @@ -14,7 +14,10 @@ import meteordevelopment.orbit.EventHandler; import meteordevelopment.orbit.EventPriority; import net.minecraft.core.BlockPos; +import net.minecraft.core.SectionPos; import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.chunk.LevelChunk; +import net.minecraft.world.level.chunk.LevelChunkSection; import java.util.Iterator; import java.util.List; @@ -31,6 +34,7 @@ public class BlockIterator { private static final BlockPos.MutableBlockPos blockPos = new BlockPos.MutableBlockPos(); private static int hRadius, vRadius; + private static boolean iCareAboutAirBlocks; private static boolean disableCurrent; private BlockIterator() { @@ -53,6 +57,7 @@ private static void onTick(TickEvent.Pre event) { hRadius = 0; vRadius = 0; + iCareAboutAirBlocks = false; callbackPool.freeAll(callbacks); callbacks.clear(); @@ -62,30 +67,69 @@ private static void onTick(TickEvent.Pre event) { } private static void scan(int px, int py, int pz) { - for (int x = px - hRadius; x <= px + hRadius; x++) { - for (int z = pz - hRadius; z <= pz + hRadius; z++) { - for (int y = Math.max(mc.level.getMinY(), py - vRadius); y <= py + vRadius; y++) { - if (callbacks.isEmpty()) return; - if (y >= mc.level.getMaxY()) break; - - blockPos.set(x, y, z); - BlockState blockState = mc.level.getBlockState(blockPos); - - int dx = Math.abs(x - px); - int dy = Math.abs(y - py); - int dz = Math.abs(z - pz); - - Iterator iterator = callbacks.iterator(); - while (iterator.hasNext()) { - Callback callback = iterator.next(); - - if (dx <= callback.hRadius && dy <= callback.vRadius && dz <= callback.hRadius) { - disableCurrent = false; - callback.function.accept(blockPos, blockState); - - if (disableCurrent) { - iterator.remove(); - callbackPool.free(callback); + int x1 = px - hRadius; + int x2 = px + hRadius; + int z1 = pz - hRadius; + int z2 = pz + hRadius; + int y1 = Math.max(mc.level.getMinY(), py - vRadius); + int y2 = Math.min(mc.level.getMaxY(), py + vRadius); + + int cx1 = SectionPos.blockToSectionCoord(x1); + int cx2 = SectionPos.blockToSectionCoord(x2); + int cz1 = SectionPos.blockToSectionCoord(z1); + int cz2 = SectionPos.blockToSectionCoord(z2); + int sy1 = mc.level.getSectionIndex(y1); + int sy2 = mc.level.getSectionIndex(y2); + + for (int cx = cx1; cx <= cx2; cx++) { + for (int cz = cz1; cz <= cz2; cz++) { + LevelChunk chunk = mc.level.getChunk(cx, cz); + if (chunk.isEmpty()) continue; + + int ox = SectionPos.sectionToBlockCoord(cx); + int oz = SectionPos.sectionToBlockCoord(cz); + + int ix1 = SectionPos.sectionRelative(Math.max(x1, ox)); + int ix2 = SectionPos.sectionRelative(Math.min(x2, ox + 15)); + int iz1 = SectionPos.sectionRelative(Math.max(z1, oz)); + int iz2 = SectionPos.sectionRelative(Math.min(z2, oz + 15)); + + for (int sy = sy1; sy <= sy2; sy++) { + LevelChunkSection section = chunk.getSection(sy); + if (!iCareAboutAirBlocks && section.hasOnlyAir()) continue; + + int oy = SectionPos.sectionToBlockCoord(mc.level.getSectionYFromSectionIndex(sy)); + + int iy1 = SectionPos.sectionRelative(Math.max(y1, oy)); + int iy2 = SectionPos.sectionRelative(Math.min(y2, oy + 15)); + + for (int y = iy1; y <= iy2; y++) { + for (int z = iz1; z <= iz2; z++) { + for (int x = ix1; x <= ix2; x++) { + blockPos.set(ox + x, oy + y, oz + z); + BlockState state = section.getBlockState(x, y, z); + + int dx = Math.abs(ox + x - px); + int dy = Math.abs(oy + y - py); + int dz = Math.abs(oz + z - pz); + + for (Iterator it = callbacks.iterator(); it.hasNext();) { + Callback callback = it.next(); + + if (dx <= callback.hRadius && dy <= callback.vRadius && dz <= callback.hRadius) { + disableCurrent = false; + callback.function.accept(blockPos, state); + + if (disableCurrent) { + it.remove(); + callbackPool.free(callback); + + if (callbacks.isEmpty()) { + return; + } + } + } + } } } } @@ -107,6 +151,10 @@ public static void register(int horizontalRadius, int verticalRadius, BiConsumer callbacks.add(callback); } + public static void iCareAboutAirBlocks() { + iCareAboutAirBlocks = true; + } + public static void disableCurrent() { disableCurrent = true; }