diff --git a/src/main/java/anticope/rejects/modules/OreSim.java b/src/main/java/anticope/rejects/modules/OreSim.java index 3d0bbd24..d8f2e55a 100755 --- a/src/main/java/anticope/rejects/modules/OreSim.java +++ b/src/main/java/anticope/rejects/modules/OreSim.java @@ -8,14 +8,15 @@ import anticope.rejects.utils.seeds.Seeds; import baritone.api.BaritoneAPI; import meteordevelopment.meteorclient.events.render.Render3DEvent; +import meteordevelopment.meteorclient.events.world.BlockUpdateEvent; import meteordevelopment.meteorclient.events.world.ChunkDataEvent; import meteordevelopment.meteorclient.events.world.TickEvent; +import meteordevelopment.meteorclient.pathing.BaritoneUtils; import meteordevelopment.meteorclient.settings.*; import meteordevelopment.meteorclient.systems.modules.Module; +import meteordevelopment.meteorclient.utils.Utils; import meteordevelopment.meteorclient.utils.player.PlayerUtils; import meteordevelopment.orbit.EventHandler; -import net.minecraft.block.BlockState; -import net.minecraft.block.Blocks; import net.minecraft.client.world.ClientWorld; import net.minecraft.registry.RegistryKey; import net.minecraft.util.math.*; @@ -36,7 +37,6 @@ public class OreSim extends Module { private Seed worldSeed = null; private Map, List> oreConfig; public List oreGoals = new ArrayList<>(); - private ChunkPos prevOffset = new ChunkPos(0, 0); public enum AirCheck { ON_LOAD, @@ -45,7 +45,6 @@ public enum AirCheck { } private final SettingGroup sgGeneral = settings.getDefaultGroup(); - private final SettingGroup sgOres = settings.createGroup("Ores"); private final Setting horizontalRadius = sgGeneral.add(new IntSetting.Builder() .name("chunk-range") @@ -73,11 +72,12 @@ public enum AirCheck { public OreSim() { super(MeteorRejectsAddon.CATEGORY, "ore-sim", "Xray on crack."); + SettingGroup sgOres = settings.createGroup("Ores"); Ore.oreSettings.forEach(sgOres::add); } public boolean baritone() { - return isActive() && baritone.get(); + return isActive() && baritone.get() && BaritoneUtils.IS_AVAILABLE; } @EventHandler @@ -119,47 +119,23 @@ private void renderChunk(int x, int z, Render3DEvent event) { } @EventHandler - private void onTick(TickEvent.Pre event) { - if (mc.player == null || mc.world == null || oreConfig == null) return; + private void onBlockUpdate(BlockUpdateEvent event) { + if (airCheck.get() != AirCheck.RECHECK || event.newState.isOpaque()) return; - if (airCheck.get() == AirCheck.RECHECK) { - int chunkX = mc.player.getChunkPos().x; - int chunkZ = mc.player.getChunkPos().z; - ClientWorld world = mc.world; - int renderdistance = mc.options.getViewDistance().getValue(); - - //maybe another config option? But its already crowded - int chunkCounter = 5; - - loop: - while (true) { - for (int offsetX = prevOffset.x; offsetX <= renderdistance; offsetX++) { - for (int offsetZ = prevOffset.z; offsetZ <= renderdistance; offsetZ++) { - prevOffset = new ChunkPos(offsetX, offsetZ); - if (chunkCounter <= 0) { - break loop; - } - long chunkKey = ChunkPos.toLong(chunkX + offsetX, chunkZ + offsetZ); - - Chunk chunk = world.getChunk(chunkX + offsetX, chunkZ + offsetZ, ChunkStatus.FULL, false); - if (chunk != null && chunkRenderers.containsKey(chunkKey)) { - chunkRenderers.get(chunkKey).values().forEach(oreSet -> - oreSet.removeIf(ore -> { - BlockState state = world.getBlockState(new BlockPos((int) ore.x, (int) ore.y, (int) ore.z)); - return state.isOpaque() && !state.isOf(Blocks.VOID_AIR); - }) - ); - } - - chunkCounter--; - } - prevOffset = new ChunkPos(offsetX, -renderdistance); - } - prevOffset = new ChunkPos(-renderdistance, -renderdistance); + long chunkKey = ChunkPos.toLong(event.pos); + if (chunkRenderers.containsKey(chunkKey)) { + Vec3d pos = Vec3d.of(event.pos); + for (var ore : chunkRenderers.get(chunkKey).values()) { + ore.remove(pos); } } + } - if (baritone.get() && BaritoneAPI.getProvider().getPrimaryBaritone().getMineProcess().isActive()) { + @EventHandler + private void onTick(TickEvent.Pre event) { + if (mc.player == null || mc.world == null || oreConfig == null) return; + + if (baritone() && BaritoneAPI.getProvider().getPrimaryBaritone().getMineProcess().isActive()) { oreGoals.clear(); var chunkPos = mc.player.getChunkPos(); int rangeVal = 4; @@ -199,7 +175,7 @@ public void onActivate() { @Override public void onDeactivate() { this.chunkRenderers.clear(); - this.oreConfig.clear(); + this.oreConfig = null; } @EventHandler @@ -213,18 +189,12 @@ private void onPlayerRespawn(PlayerRespawnEvent event) { } private void loadVisibleChunks() { - int renderdistance = mc.options.getViewDistance().getValue()+2; - if (mc.player == null) { return; } - int playerChunkX = mc.player.getChunkPos().x; - int playerChunkZ = mc.player.getChunkPos().z; - for (int i = playerChunkX - renderdistance; i < playerChunkX + renderdistance; i++) { - for (int j = playerChunkZ - renderdistance; j < playerChunkZ + renderdistance; j++) { - doMathOnChunk(i, j); - } + for (Chunk chunk : Utils.chunks(false)) { + doMathOnChunk(chunk); } } @@ -242,11 +212,13 @@ private void reload() { @EventHandler public void onChunkData(ChunkDataEvent event) { - doMathOnChunk(event.chunk.getPos().x, event.chunk.getPos().z); + doMathOnChunk(event.chunk); + ChunkDataEvent.returnChunkDataEvent(event); } - private void doMathOnChunk(int chunkX, int chunkZ) { - var chunkPos = new ChunkPos(chunkX, chunkZ); + private void doMathOnChunk(Chunk chunk) { + + var chunkPos = chunk.getPos(); long chunkKey = chunkPos.toLong(); ClientWorld world = mc.world; @@ -255,12 +227,6 @@ private void doMathOnChunk(int chunkX, int chunkZ) { return; } - Chunk chunk = world.getChunk(chunkX, chunkZ, ChunkStatus.FULL, false); - - if (chunk == null) { - return; - } - Set> biomes = new HashSet<>(); ChunkPos.stream(chunkPos, 1).forEach(chunkPosx -> { Chunk chunkxx = world.getChunk(chunkPosx.x, chunkPosx.z, ChunkStatus.BIOMES, false); @@ -272,8 +238,8 @@ private void doMathOnChunk(int chunkX, int chunkZ) { }); Set oreSet = biomes.stream().flatMap(b -> getDefaultOres(b).stream()).collect(Collectors.toSet()); - chunkX = chunkX << 4; - chunkZ = chunkZ << 4; + int chunkX = chunkPos.x << 4; + int chunkZ = chunkPos.z << 4; ChunkRandom random = new ChunkRandom(ChunkRandom.RandomProvider.XOROSHIRO.create(0)); long populationSeed = random.setPopulationSeed(worldSeed.seed, chunkX, chunkZ); @@ -289,7 +255,7 @@ private void doMathOnChunk(int chunkX, int chunkZ) { for (int i = 0; i < repeat; i++) { - if (ore.rarity != 1F && random.nextFloat() >= ore.rarity) { + if (ore.rarity != 1F && random.nextFloat() >= 1/ore.rarity) { continue; }