Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.block.state.BlockState;

import java.util.Iterator;
import java.util.List;
import java.util.function.BiConsumer;

Expand Down Expand Up @@ -48,10 +49,24 @@ private static void onTick(TickEvent.Pre event) {
int py = mc.player.getBlockY();
int pz = mc.player.getBlockZ();

scan(px, py, pz);

hRadius = 0;
vRadius = 0;

callbackPool.freeAll(callbacks);
callbacks.clear();

for (Runnable callback : afterCallbacks) callback.run();
afterCallbacks.clear();
}

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 (y > mc.level.getHeight()) break;
if (callbacks.isEmpty()) return;
if (y >= mc.level.getMaxY()) break;

blockPos.set(x, y, z);
BlockState blockState = mc.level.getBlockState(blockPos);
Expand All @@ -60,26 +75,23 @@ private static void onTick(TickEvent.Pre event) {
int dy = Math.abs(y - py);
int dz = Math.abs(z - pz);

callbacks.removeIf(callback -> {
Iterator<Callback> 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);
return disableCurrent;

if (disableCurrent) {
iterator.remove();
callbackPool.free(callback);
}
}
return false;
});
}
}
}
}

hRadius = 0;
vRadius = 0;

callbackPool.freeAll(callbacks);
callbacks.clear();

for (Runnable callback : afterCallbacks) callback.run();
afterCallbacks.clear();
}

public static void register(int horizontalRadius, int verticalRadius, BiConsumer<BlockPos, BlockState> function) {
Expand Down
Loading