From 03d4cde51a53c246057f8374e62815de0ce91828 Mon Sep 17 00:00:00 2001 From: misterx Date: Fri, 17 Nov 2023 22:02:08 +0100 Subject: [PATCH 1/2] Oresim update --- .../mixin/CountPlacementModifierAccessor.java | 12 + .../rejects/mixin/HeightContextMixin.java | 22 ++ .../HeightRangePlacementModifierAccessor.java | 13 + ...RarityFilterPlacementModifierAccessor.java | 11 + .../java/anticope/rejects/modules/OreSim.java | 192 +++++------ src/main/java/anticope/rejects/utils/Ore.java | 324 +++++++----------- src/main/resources/meteor-rejects.mixins.json | 4 + 7 files changed, 288 insertions(+), 290 deletions(-) create mode 100644 src/main/java/anticope/rejects/mixin/CountPlacementModifierAccessor.java create mode 100644 src/main/java/anticope/rejects/mixin/HeightContextMixin.java create mode 100644 src/main/java/anticope/rejects/mixin/HeightRangePlacementModifierAccessor.java create mode 100644 src/main/java/anticope/rejects/mixin/RarityFilterPlacementModifierAccessor.java diff --git a/src/main/java/anticope/rejects/mixin/CountPlacementModifierAccessor.java b/src/main/java/anticope/rejects/mixin/CountPlacementModifierAccessor.java new file mode 100644 index 00000000..02cb6d46 --- /dev/null +++ b/src/main/java/anticope/rejects/mixin/CountPlacementModifierAccessor.java @@ -0,0 +1,12 @@ +package anticope.rejects.mixin; + +import net.minecraft.util.math.intprovider.IntProvider; +import net.minecraft.world.gen.placementmodifier.CountPlacementModifier; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +@Mixin(CountPlacementModifier.class) +public interface CountPlacementModifierAccessor { + @Accessor + IntProvider getCount(); +} diff --git a/src/main/java/anticope/rejects/mixin/HeightContextMixin.java b/src/main/java/anticope/rejects/mixin/HeightContextMixin.java new file mode 100644 index 00000000..18a50726 --- /dev/null +++ b/src/main/java/anticope/rejects/mixin/HeightContextMixin.java @@ -0,0 +1,22 @@ +package anticope.rejects.mixin; + +import net.minecraft.world.gen.HeightContext; +import net.minecraft.world.gen.chunk.ChunkGenerator; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Mixin(HeightContext.class) +public abstract class HeightContextMixin { + + @Redirect(method = "", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/gen/chunk/ChunkGenerator;getMinimumY()I")) + private int onMinY(ChunkGenerator instance) { + return instance == null ? -9999999 : instance.getMinimumY(); + } + + + @Redirect(method = "", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/gen/chunk/ChunkGenerator;getWorldHeight()I")) + private int onHeight(ChunkGenerator instance) { + return instance == null ? 100000000 : instance.getWorldHeight(); + } +} diff --git a/src/main/java/anticope/rejects/mixin/HeightRangePlacementModifierAccessor.java b/src/main/java/anticope/rejects/mixin/HeightRangePlacementModifierAccessor.java new file mode 100644 index 00000000..fe261f7c --- /dev/null +++ b/src/main/java/anticope/rejects/mixin/HeightRangePlacementModifierAccessor.java @@ -0,0 +1,13 @@ +package anticope.rejects.mixin; + +import net.minecraft.world.gen.heightprovider.HeightProvider; +import net.minecraft.world.gen.placementmodifier.HeightRangePlacementModifier; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +@Mixin(HeightRangePlacementModifier.class) +public interface HeightRangePlacementModifierAccessor { + + @Accessor + HeightProvider getHeight(); +} diff --git a/src/main/java/anticope/rejects/mixin/RarityFilterPlacementModifierAccessor.java b/src/main/java/anticope/rejects/mixin/RarityFilterPlacementModifierAccessor.java new file mode 100644 index 00000000..43537958 --- /dev/null +++ b/src/main/java/anticope/rejects/mixin/RarityFilterPlacementModifierAccessor.java @@ -0,0 +1,11 @@ +package anticope.rejects.mixin; + +import net.minecraft.world.gen.placementmodifier.RarityFilterPlacementModifier; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +@Mixin(RarityFilterPlacementModifier.class) +public interface RarityFilterPlacementModifierAccessor { + @Accessor + int getChance(); +} diff --git a/src/main/java/anticope/rejects/modules/OreSim.java b/src/main/java/anticope/rejects/modules/OreSim.java index c62e3be6..3d0bbd24 100755 --- a/src/main/java/anticope/rejects/modules/OreSim.java +++ b/src/main/java/anticope/rejects/modules/OreSim.java @@ -7,29 +7,35 @@ import anticope.rejects.utils.seeds.Seed; import anticope.rejects.utils.seeds.Seeds; import baritone.api.BaritoneAPI; -import com.seedfinding.mccore.version.MCVersion; import meteordevelopment.meteorclient.events.render.Render3DEvent; import meteordevelopment.meteorclient.events.world.ChunkDataEvent; import meteordevelopment.meteorclient.events.world.TickEvent; import meteordevelopment.meteorclient.settings.*; import meteordevelopment.meteorclient.systems.modules.Module; +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.RegistryKeys; -import net.minecraft.util.Identifier; +import net.minecraft.registry.RegistryKey; import net.minecraft.util.math.*; import net.minecraft.util.math.random.ChunkRandom; import net.minecraft.world.Heightmap; +import net.minecraft.world.biome.Biome; +import net.minecraft.world.chunk.Chunk; +import net.minecraft.world.chunk.ChunkSection; import net.minecraft.world.chunk.ChunkStatus; import java.util.*; +import java.util.concurrent.ConcurrentHashMap; +import java.util.stream.Collectors; public class OreSim extends Module { - private final HashMap>> chunkRenderers = new HashMap<>(); + private final Map>> chunkRenderers = new ConcurrentHashMap<>(); private Seed worldSeed = null; - private List oreConfig; - public ArrayList oreGoals = new ArrayList<>(); + private Map, List> oreConfig; + public List oreGoals = new ArrayList<>(); private ChunkPos prevOffset = new ChunkPos(0, 0); public enum AirCheck { @@ -97,16 +103,15 @@ private void onRender(Render3DEvent event) { } private void renderChunk(int x, int z, Render3DEvent event) { - long chunkKey = (long) x + ((long) z << 32); + long chunkKey = ChunkPos.toLong(x,z); if (chunkRenderers.containsKey(chunkKey)) { - for (Ore ore : oreConfig) { - if (ore.enabled.get()) { - if (!chunkRenderers.get(chunkKey).containsKey(ore)) { - continue; - } - for (Vec3d pos : chunkRenderers.get(chunkKey).get(ore)) { - event.renderer.boxLines(pos.x, pos.y, pos.z, pos.x + 1, pos.y + 1, pos.z + 1, ore.color, 0); + Map> chunk = chunkRenderers.get(chunkKey); + + for (Map.Entry> oreRenders : chunk.entrySet()) { + if (oreRenders.getKey().active.get()) { + for (Vec3d pos : oreRenders.getValue()) { + event.renderer.boxLines(pos.x, pos.y, pos.z, pos.x + 1, pos.y + 1, pos.z + 1, oreRenders.getKey().color, 0); } } } @@ -118,8 +123,8 @@ private void onTick(TickEvent.Pre event) { if (mc.player == null || mc.world == null || oreConfig == null) return; if (airCheck.get() == AirCheck.RECHECK) { - long chunkX = mc.player.getChunkPos().x; - long chunkZ = mc.player.getChunkPos().z; + int chunkX = mc.player.getChunkPos().x; + int chunkZ = mc.player.getChunkPos().z; ClientWorld world = mc.world; int renderdistance = mc.options.getViewDistance().getValue(); @@ -128,20 +133,27 @@ private void onTick(TickEvent.Pre event) { loop: while (true) { - for (long offsetX = prevOffset.x; offsetX <= renderdistance; offsetX++) { - for (long offsetZ = prevOffset.z; offsetZ <= renderdistance; offsetZ++) { - prevOffset = new ChunkPos((int) offsetX, (int) offsetZ); + 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 = (chunkX + offsetX) + ((chunkZ + offsetZ) << 32); - - if (chunkRenderers.containsKey(chunkKey)) { - chunkRenderers.get(chunkKey).values().forEach(oreSet -> oreSet.removeIf(ore -> !world.getBlockState(new BlockPos((int) ore.x, (int) ore.y, (int) ore.z)).isOpaque())); + 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((int) offsetX, -renderdistance); + prevOffset = new ChunkPos(offsetX, -renderdistance); } prevOffset = new ChunkPos(-renderdistance, -renderdistance); } @@ -164,18 +176,15 @@ private void onTick(TickEvent.Pre event) { private ArrayList addToBaritone(int chunkX, int chunkZ) { ArrayList baritoneGoals = new ArrayList<>(); - long chunkKey = (long) chunkX + ((long) chunkZ << 32); - if (!this.chunkRenderers.containsKey(chunkKey)) { - return baritoneGoals; - } else { - this.oreConfig.stream().filter((config) -> config.enabled.get()).forEach((ore) -> chunkRenderers - .get(chunkKey) - .getOrDefault(ore, new HashSet<>()) - .stream() + long chunkKey = ChunkPos.toLong(chunkX, chunkZ); + if (this.chunkRenderers.containsKey(chunkKey)) { + this.chunkRenderers.get(chunkKey).entrySet().stream() + .filter(entry -> entry.getKey().active.get()) + .flatMap(entry -> entry.getValue().stream()) .map(BlockPos::ofFloored) - .forEach(baritoneGoals::add)); - return baritoneGoals; + .forEach(baritoneGoals::add); } + return baritoneGoals; } @Override @@ -187,6 +196,12 @@ public void onActivate() { reload(); } + @Override + public void onDeactivate() { + this.chunkRenderers.clear(); + this.oreConfig.clear(); + } + @EventHandler private void onSeedChanged(SeedChangedEvent event) { reload(); @@ -198,7 +213,7 @@ private void onPlayerRespawn(PlayerRespawnEvent event) { } private void loadVisibleChunks() { - int renderdistance = mc.options.getViewDistance().getValue(); + int renderdistance = mc.options.getViewDistance().getValue()+2; if (mc.player == null) { return; @@ -217,12 +232,7 @@ private void reload() { Seed seed = Seeds.get().getSeed(); if (seed == null) return; worldSeed = seed; - oreConfig = Ore.getConfig(Seeds.get().getSeed().version); - if (oreConfig == null) { - error("Ore Sim only works with seeds from version 1.14 or higher. (Current seed is from version " + Seeds.get().getSeed().version.toString() + ")"); - this.toggle(); - return; - } + oreConfig = Ore.getRegistry(PlayerUtils.getDimension()); chunkRenderers.clear(); if (mc.world != null && worldSeed != null) { @@ -236,7 +246,8 @@ public void onChunkData(ChunkDataEvent event) { } private void doMathOnChunk(int chunkX, int chunkZ) { - long chunkKey = (long) chunkX + ((long) chunkZ << 32); + var chunkPos = new ChunkPos(chunkX, chunkZ); + long chunkKey = chunkPos.toLong(); ClientWorld world = mc.world; @@ -244,84 +255,59 @@ private void doMathOnChunk(int chunkX, int chunkZ) { return; } - if (world.getChunkManager().getChunk(chunkX, chunkZ, ChunkStatus.FULL, false) == null) { + Chunk chunk = world.getChunk(chunkX, chunkZ, ChunkStatus.FULL, false); + + if (chunk == null) { return; } - chunkX = chunkX << 4; - chunkZ = chunkZ << 4; - - - ChunkRandom random = new ChunkRandom(ChunkRandom.RandomProvider.LEGACY.create(0)); + Set> biomes = new HashSet<>(); + ChunkPos.stream(chunkPos, 1).forEach(chunkPosx -> { + Chunk chunkxx = world.getChunk(chunkPosx.x, chunkPosx.z, ChunkStatus.BIOMES, false); + if (chunkxx == null) return; - if (worldSeed.version.isNewerOrEqualTo(MCVersion.v1_18)) { //1.18 and above - random = new ChunkRandom(ChunkRandom.RandomProvider.XOROSHIRO.create(0)); - } + for(ChunkSection chunkSection : chunkxx.getSectionArray()) { + chunkSection.getBiomeContainer().forEachValue(entry -> biomes.add(entry.getKey().get())); + } + }); + Set oreSet = biomes.stream().flatMap(b -> getDefaultOres(b).stream()).collect(Collectors.toSet()); - HashMap> h = new HashMap<>(); + chunkX = chunkX << 4; + chunkZ = chunkZ << 4; + ChunkRandom random = new ChunkRandom(ChunkRandom.RandomProvider.XOROSHIRO.create(0)); long populationSeed = random.setPopulationSeed(worldSeed.seed, chunkX, chunkZ); + HashMap> h = new HashMap<>(); - var optional = world.getBiomeAccess().getBiomeForNoiseGen(new BlockPos(chunkX, 0, chunkZ)).getKeyOrValue(); - Identifier id = (optional.right().isPresent()) ? world.getRegistryManager().get(RegistryKeys.BIOME).getId(optional.right().get()) : optional.left().get().getValue(); - if (id == null) { - error("Something went wrong, you may have some mods that mess with world generation"); - toggle(); - return; - } - String biomeName = id.getPath(); - Identifier dimensionName = world.getDimension().effects(); - - for (Ore ore : oreConfig) { - - if (!dimensionName.getPath().equals(ore.dimension.getPath())) { - continue; - } + for (Ore ore : oreSet) { HashSet ores = new HashSet<>(); - int index; - if (ore.index.containsKey(biomeName)) { - index = ore.index.get(biomeName); - } else { - index = ore.index.get("default"); - } - if (index < 0) { - continue; - } - - random.setDecoratorSeed(populationSeed, index, ore.step); + random.setDecoratorSeed(populationSeed, ore.index, ore.step); int repeat = ore.count.get(random); for (int i = 0; i < repeat; i++) { - if (ore.chance != 1F && random.nextFloat() >= ore.chance) { + if (ore.rarity != 1F && random.nextFloat() >= ore.rarity) { continue; } int x = random.nextInt(16) + chunkX; - int z; - int y; - if (worldSeed.version.isBetween(MCVersion.v1_14, MCVersion.v1_14_4)) { - y = ore.depthAverage ? random.nextInt(ore.maxY) + random.nextInt(ore.maxY) - ore.maxY : random.nextInt(ore.maxY - ore.minY); - z = random.nextInt(16) + chunkZ; - } else { - z = random.nextInt(16) + chunkZ; - y = ore.depthAverage ? random.nextInt(ore.maxY) + random.nextInt(ore.maxY) - ore.maxY : random.nextInt(ore.maxY - ore.minY); + int z = random.nextInt(16) + chunkZ; + int y = ore.heightProvider.get(random, ore.heightContext); + BlockPos origin = new BlockPos(x,y,z); + + RegistryKey biome = chunk.getBiomeForNoiseGen(x,y,z).getKey().get(); + + if (!getDefaultOres(biome).contains(ore)) { + continue; } - y += ore.minY; - - switch (ore.generator) { - case DEFAULT -> - ores.addAll(generateNormal(world, random, new BlockPos(x, y, z), ore.size, ore.discardOnAir)); - case EMERALD -> { - if (airCheck.get() == AirCheck.OFF || world.getBlockState(new BlockPos(x, y, z)).isOpaque()) { - ores.add(new Vec3d(x, y, z)); - } - } - case NO_SURFACE -> ores.addAll(generateHidden(world, random, new BlockPos(x, y, z), ore.size)); - default -> System.out.println(ore.type + " has some unknown generator. Fix it!"); + + if (ore.scattered) { + ores.addAll(generateHidden(world, random, origin, ore.size)); + } else { + ores.addAll(generateNormal(world, random, origin, ore.size, ore.discardOnAirChance)); } } if (!ores.isEmpty()) { @@ -331,6 +317,14 @@ private void doMathOnChunk(int chunkX, int chunkZ) { chunkRenderers.put(chunkKey, h); } + private List getDefaultOres(RegistryKey biomeRegistryKey) { + if (oreConfig.containsKey(biomeRegistryKey)) { + return oreConfig.get(biomeRegistryKey); + } else { + return this.oreConfig.values().stream().findAny().get(); + } + } + // ==================================== // Mojang code // ==================================== diff --git a/src/main/java/anticope/rejects/utils/Ore.java b/src/main/java/anticope/rejects/utils/Ore.java index d2ef6265..762679bb 100755 --- a/src/main/java/anticope/rejects/utils/Ore.java +++ b/src/main/java/anticope/rejects/utils/Ore.java @@ -1,16 +1,36 @@ package anticope.rejects.utils; +import anticope.rejects.mixin.CountPlacementModifierAccessor; +import anticope.rejects.mixin.HeightRangePlacementModifierAccessor; +import anticope.rejects.mixin.RarityFilterPlacementModifierAccessor; import meteordevelopment.meteorclient.settings.BoolSetting; import meteordevelopment.meteorclient.settings.Setting; import meteordevelopment.meteorclient.utils.render.color.Color; -import com.seedfinding.mccore.version.MCVersion; -import net.minecraft.util.Identifier; +import meteordevelopment.meteorclient.utils.world.Dimension; +import net.minecraft.client.MinecraftClient; +import net.minecraft.registry.*; +import net.minecraft.registry.entry.RegistryEntry; + +import net.minecraft.registry.entry.RegistryEntryList; import net.minecraft.util.math.intprovider.ConstantIntProvider; import net.minecraft.util.math.intprovider.IntProvider; -import net.minecraft.util.math.intprovider.UniformIntProvider; -import net.minecraft.world.dimension.DimensionTypes; + +import net.minecraft.world.HeightLimitView; +import net.minecraft.world.biome.Biome; +import net.minecraft.world.dimension.DimensionOptions; +import net.minecraft.world.gen.HeightContext; +import net.minecraft.world.gen.WorldPresets; +import net.minecraft.world.gen.feature.*; +import net.minecraft.world.gen.feature.util.PlacedFeatureIndexer; +import net.minecraft.world.gen.heightprovider.HeightProvider; +import net.minecraft.world.gen.placementmodifier.CountPlacementModifier; +import net.minecraft.world.gen.placementmodifier.HeightRangePlacementModifier; +import net.minecraft.world.gen.placementmodifier.PlacementModifier; +import net.minecraft.world.gen.placementmodifier.RarityFilterPlacementModifier; + import java.util.*; + public class Ore { private static final Setting coal = new BoolSetting.Builder().name("Coal").build(); @@ -24,210 +44,132 @@ public class Ore { private static final Setting quartz = new BoolSetting.Builder().name("Quartz").build(); private static final Setting debris = new BoolSetting.Builder().name("Ancient Debris").build(); public static final List> oreSettings = new ArrayList<>(Arrays.asList(coal, iron, gold, redstone, diamond, lapis, copper, emerald, quartz, debris)); - public final Type type; - public final Identifier dimension; - public final Map index; - public final boolean depthAverage; - public final Generator generator; - public final int size; - public final Setting enabled; - public final Color color; - public int step; - public IntProvider count; - public int minY; - public int maxY; - public float discardOnAir; - public float chance; - - Ore(Type type, Identifier dimension, Map index, int step, IntProvider count, float chance, boolean depthAverage, int minY, int maxY, Generator generator, int size, float discardOnAir, Setting enabled, Color color) { - this.type = type; - this.dimension = dimension; - this.index = index; - this.step = step; - this.count = count; - this.depthAverage = depthAverage; - this.minY = minY; - this.maxY = maxY; - this.generator = generator; - this.size = size; - this.enabled = enabled; - this.color = color; - this.discardOnAir = discardOnAir; - this.chance = chance; - } - - Ore(Type type, Identifier dimension, int index, int step, IntProvider count, float chance, boolean depthAverage, int minY, int maxY, Generator generator, int size, float discardOnAir, Setting enabled, Color color) { - this(type, dimension, indexToMap(index), step, count, chance, depthAverage, minY, maxY, generator, size, discardOnAir, enabled, color); - } - Ore(Type type, Identifier dimension, int index, int step, IntProvider count, boolean depthAverage, int minY, int maxY, - @SuppressWarnings("SameParameterValue") Generator generator, int size, Setting enabled, Color color) { - this(type, dimension, indexToMap(index), step, count, 1F, depthAverage, minY, maxY, generator, size, 0F, enabled, color); + public static Map, List> getRegistry(Dimension dimension) { + + RegistryWrapper.WrapperLookup registry = BuiltinRegistries.createWrapperLookup(); + RegistryWrapper.Impl features = registry.getWrapperOrThrow(RegistryKeys.PLACED_FEATURE); + var reg = registry.getWrapperOrThrow(RegistryKeys.WORLD_PRESET).getOrThrow(WorldPresets.DEFAULT).value().createDimensionsRegistryHolder().dimensions(); + + var dim = switch (dimension) { + case Overworld -> reg.get(DimensionOptions.OVERWORLD); + case Nether -> reg.get(DimensionOptions.NETHER); + case End -> reg.get(DimensionOptions.END); + }; + + var biomes = dim.chunkGenerator().getBiomeSource().getBiomes(); + var biomes1 = biomes.stream().toList(); + + List indexer = PlacedFeatureIndexer.collectIndexedFeatures( + biomes1, biomeEntry -> biomeEntry.value().getGenerationSettings().getFeatures(), true + ); + + + Map featureToOre = new HashMap<>(); + registerOre(featureToOre, indexer, features, OrePlacedFeatures.ORE_COAL_LOWER, 6, coal, new Color(47, 44, 54)); + registerOre(featureToOre, indexer, features, OrePlacedFeatures.ORE_COAL_UPPER, 6, coal, new Color(47, 44, 54)); + registerOre(featureToOre, indexer, features, OrePlacedFeatures.ORE_IRON_MIDDLE, 6, iron, new Color(236, 173, 119)); + registerOre(featureToOre, indexer, features, OrePlacedFeatures.ORE_IRON_SMALL, 6, iron, new Color(236, 173, 119)); + registerOre(featureToOre, indexer, features, OrePlacedFeatures.ORE_IRON_UPPER, 6, iron, new Color(236, 173, 119)); + registerOre(featureToOre, indexer, features, OrePlacedFeatures.ORE_GOLD, 6, gold, new Color(247, 229, 30)); + registerOre(featureToOre, indexer, features, OrePlacedFeatures.ORE_GOLD_LOWER, 6, gold, new Color(247, 229, 30)); + registerOre(featureToOre, indexer, features, OrePlacedFeatures.ORE_GOLD_EXTRA, 6, gold, new Color(247, 229, 30)); + registerOre(featureToOre, indexer, features, OrePlacedFeatures.ORE_GOLD_NETHER, 7, gold, new Color(247, 229, 30)); + registerOre(featureToOre, indexer, features, OrePlacedFeatures.ORE_GOLD_DELTAS, 7, gold, new Color(247, 229, 30)); + registerOre(featureToOre, indexer, features, OrePlacedFeatures.ORE_REDSTONE, 6, redstone, new Color(245, 7, 23)); + registerOre(featureToOre, indexer, features, OrePlacedFeatures.ORE_REDSTONE_LOWER, 6, redstone, new Color(245, 7, 23)); + registerOre(featureToOre, indexer, features, OrePlacedFeatures.ORE_DIAMOND, 6, diamond, new Color(33, 244, 255)); + registerOre(featureToOre, indexer, features, OrePlacedFeatures.ORE_DIAMOND_BURIED, 6, diamond, new Color(33, 244, 255)); + registerOre(featureToOre, indexer, features, OrePlacedFeatures.ORE_DIAMOND_LARGE, 6, diamond, new Color(33, 244, 255)); + registerOre(featureToOre, indexer, features, OrePlacedFeatures.ORE_DIAMOND_MEDIUM, 6, diamond, new Color(33, 244, 255)); + registerOre(featureToOre, indexer, features, OrePlacedFeatures.ORE_LAPIS, 6, lapis, new Color(8, 26, 189)); + registerOre(featureToOre, indexer, features, OrePlacedFeatures.ORE_LAPIS_BURIED, 6, lapis, new Color(8, 26, 189)); + registerOre(featureToOre, indexer, features, OrePlacedFeatures.ORE_COPPER, 6, copper, new Color(239, 151, 0)); + registerOre(featureToOre, indexer, features, OrePlacedFeatures.ORE_COPPER_LARGE, 6, copper, new Color(239, 151, 0)); + registerOre(featureToOre, indexer, features, OrePlacedFeatures.ORE_EMERALD, 6, emerald, new Color(27, 209, 45)); + registerOre(featureToOre, indexer, features, OrePlacedFeatures.ORE_QUARTZ_NETHER, 7, quartz, new Color(205, 205, 205)); + registerOre(featureToOre, indexer, features, OrePlacedFeatures.ORE_QUARTZ_DELTAS, 7, quartz, new Color(205, 205, 205)); + registerOre(featureToOre, indexer, features, OrePlacedFeatures.ORE_DEBRIS_SMALL, 7, debris, new Color(209, 27, 245)); + registerOre(featureToOre, indexer, features, OrePlacedFeatures.ORE_ANCIENT_DEBRIS_LARGE, 7, debris, new Color(209, 27, 245)); + + + Map, List> biomeOreMap = new HashMap<>(); + + biomes1.forEach(biome -> { + biomeOreMap.put(biome.getKey().get(), new ArrayList<>()); + biome.value().getGenerationSettings().getFeatures().stream() + .flatMap(RegistryEntryList::stream) + .map(RegistryEntry::value) + .filter(featureToOre::containsKey) + .forEach(feature -> { + biomeOreMap.get(biome.getKey().get()).add(featureToOre.get(feature)); + }); + }); + return biomeOreMap; } - Ore(Type type, Identifier dimension, Map index, int step, IntProvider count, boolean depthAverage, int minY, int maxY, - @SuppressWarnings("SameParameterValue") Generator generator, int size, Setting enabled, Color color) { - this(type, dimension, index, step, count, 1F, depthAverage, minY, maxY, generator, size, 0F, enabled, color); - } + private static void registerOre( + Map map, + List indexer, + RegistryWrapper.Impl oreRegistry, + RegistryKey oreKey, + int genStep, + Setting active, + Color color + ) { + var orePlacement = oreRegistry.getOrThrow(oreKey).value(); - private static HashMap indexToMap(int index) { - HashMap map = new HashMap<>(); - map.put("default", index); - return map; - } - - private static List V1_19() { - return V1_18(); - } + int index = indexer.get(genStep).indexMapping().applyAsInt(orePlacement); - private static List V1_18() { - List ores = new ArrayList<>(); + Ore ore = new Ore(orePlacement, genStep, index, active, color); - HashMap extraGoldIndex = new HashMap<>(); - extraGoldIndex.put("default", -1); - String[] extraGoldBiomes = new String[]{"badlands", "eroded_badlands", "wooded_badlands"}; - for (String extraGoldBiome : extraGoldBiomes) { - extraGoldIndex.put(extraGoldBiome, 27); - } - - HashMap emeraldIndex = new HashMap<>(); - emeraldIndex.put("default", -1); - String[] emeraldBiomes = new String[]{"windswept_hills", "meadow", "grove", "jagged_peaks", "snowy_slopes", "frozen_peaks", "stony_peaks"}; - for (String emeraldBiome : emeraldBiomes) { - emeraldIndex.put(emeraldBiome, 27); - } - - ores.add(new Ore(Type.COAL, DimensionTypes.OVERWORLD_ID, 9, 6, ConstantIntProvider.create(30), false, 136, 320, Generator.DEFAULT, 17, coal, new Color(47, 44, 54))); - ores.add(new Ore(Type.COAL, DimensionTypes.OVERWORLD_ID, 10, 6, ConstantIntProvider.create(20), 1F, true, 97, 97, Generator.DEFAULT, 17, 0.5F, coal, new Color(47, 44, 54))); - ores.add(new Ore(Type.IRON, DimensionTypes.OVERWORLD_ID, 11, 6, ConstantIntProvider.create(90), true, 233, 153, Generator.DEFAULT, 9, iron, new Color(236, 173, 119))); - ores.add(new Ore(Type.IRON, DimensionTypes.OVERWORLD_ID, 12, 6, ConstantIntProvider.create(10), true, 17, 41, Generator.DEFAULT, 9, iron, new Color(236, 173, 119))); - ores.add(new Ore(Type.IRON, DimensionTypes.OVERWORLD_ID, 13, 6, ConstantIntProvider.create(10), false, -64, 73, Generator.DEFAULT, 4, iron, new Color(236, 173, 119))); - ores.add(new Ore(Type.GOLD_EXTRA, DimensionTypes.OVERWORLD_ID, extraGoldIndex, 6, ConstantIntProvider.create(50), false, 32, 257, Generator.DEFAULT, 9, gold, new Color(247, 229, 30))); - ores.add(new Ore(Type.GOLD, DimensionTypes.OVERWORLD_ID, 14, 6, ConstantIntProvider.create(4), 1F, true, -15, 49, Generator.DEFAULT, 9, 0.5F, gold, new Color(247, 229, 30))); - ores.add(new Ore(Type.GOLD, DimensionTypes.OVERWORLD_ID, 15, 6, UniformIntProvider.create(0, 1), 1F, false, -64, -47, Generator.DEFAULT, 9, 0.5F, gold, new Color(247, 229, 30))); - ores.add(new Ore(Type.REDSTONE, DimensionTypes.OVERWORLD_ID, 16, 6, ConstantIntProvider.create(4), false, -64, 16, Generator.DEFAULT, 8, redstone, new Color(245, 7, 23))); - ores.add(new Ore(Type.REDSTONE, DimensionTypes.OVERWORLD_ID, 17, 6, ConstantIntProvider.create(8), true, -63, 33, Generator.DEFAULT, 8, redstone, new Color(245, 7, 23))); - ores.add(new Ore(Type.DIAMOND, DimensionTypes.OVERWORLD_ID, 18, 6, ConstantIntProvider.create(7), 1F, true, -63, 81, Generator.DEFAULT, 4, 0.5F, diamond, new Color(33, 244, 255))); - ores.add(new Ore(Type.DIAMOND, DimensionTypes.OVERWORLD_ID, 19, 6, ConstantIntProvider.create(1), (1F / 9F), true, -63, 81, Generator.DEFAULT, 12, 0.7F, diamond, new Color(33, 244, 255))); - ores.add(new Ore(Type.DIAMOND, DimensionTypes.OVERWORLD_ID, 20, 6, ConstantIntProvider.create(4), 1F, true, -63, 81, Generator.DEFAULT, 8, 1F, diamond, new Color(33, 244, 255))); - ores.add(new Ore(Type.LAPIS, DimensionTypes.OVERWORLD_ID, 21, 6, ConstantIntProvider.create(2), true, 1, 33, Generator.DEFAULT, 7, lapis, new Color(8, 26, 189))); - ores.add(new Ore(Type.LAPIS, DimensionTypes.OVERWORLD_ID, 22, 6, ConstantIntProvider.create(4), 1F, false, -64, 65, Generator.DEFAULT, 7, 1F, lapis, new Color(8, 26, 189))); - ores.add(new Ore(Type.EMERALD, DimensionTypes.OVERWORLD_ID, emeraldIndex, 6, ConstantIntProvider.create(100), true, 233, 249, Generator.DEFAULT, 3, emerald, new Color(27, 209, 45))); - //This only generates near dripstone caves. I'll need propper biome detection to get this right - //ores.add(new Ore(Type.COPPER, "overworld", 23, 6, ConstantIntProvider.create(16), true, 49, 65, Generator.DEFAULT, 20, copper, new Color(239, 151, 0))); - ores.add(new Ore(Type.COPPER, DimensionTypes.OVERWORLD_ID, 24, 6, ConstantIntProvider.create(16), true, 49, 65, Generator.DEFAULT, 10, copper, new Color(239, 151, 0))); - ores.add(new Ore(Type.GOLD_NETHER, DimensionTypes.THE_NETHER_ID, Map.of("default", 19, "basalt_deltas", -1), 7, ConstantIntProvider.create(10), false, 10, 118, Generator.DEFAULT, 10, gold, new Color(247, 229, 30))); - ores.add(new Ore(Type.QUARTZ, DimensionTypes.THE_NETHER_ID, Map.of("default", 20, "basalt_deltas", -1), 7, ConstantIntProvider.create(16), false, 10, 118, Generator.DEFAULT, 14, quartz, new Color(205, 205, 205))); - ores.add(new Ore(Type.GOLD_NETHER, DimensionTypes.THE_NETHER_ID, Map.of("default", -1, "basalt_deltas", 13), 7, ConstantIntProvider.create(20), false, 10, 118, Generator.DEFAULT, 10, gold, new Color(247, 229, 30))); - ores.add(new Ore(Type.QUARTZ, DimensionTypes.THE_NETHER_ID, Map.of("default", -1, "basalt_deltas", 14), 7, ConstantIntProvider.create(32), false, 10, 118, Generator.DEFAULT, 14, quartz, new Color(205, 205, 205))); - ores.add(new Ore(Type.LDEBRIS, DimensionTypes.THE_NETHER_ID, 21, 7, ConstantIntProvider.create(1), true, 17, 9, Generator.NO_SURFACE, 3, debris, new Color(209, 27, 245))); - ores.add(new Ore(Type.SDEBRIS, DimensionTypes.THE_NETHER_ID, 22, 7, ConstantIntProvider.create(1), false, 8, 120, Generator.NO_SURFACE, 2, debris, new Color(209, 27, 245))); - return ores; + map.put(orePlacement, ore); } - private static List baseConfig() { - List ores = new ArrayList<>(); - HashMap emeraldIndexes = new HashMap<>(); - emeraldIndexes.put("default", -1); - String[] emeraldBiomes = new String[]{"mountains", "mountain_edge", "wooded_mountains", "gravelly_mountains", "modified_gravelly_mountains", "paper"}; - for (String emeraldBiome : emeraldBiomes) { - emeraldIndexes.put(emeraldBiome, 17); - } - HashMap LDebrisIndexes = new HashMap<>(); - LDebrisIndexes.put("default", 15); - LDebrisIndexes.put("crimson_forest", 12); - LDebrisIndexes.put("warped_forest", 13); - HashMap SDebrisIndexes = new HashMap<>(); - LDebrisIndexes.forEach((biome, index) -> SDebrisIndexes.put(biome, index + 1)); - HashMap extraGoldIndexes = new HashMap<>(); - extraGoldIndexes.put("default", -1); - String[] extraGoldBiomes = new String[]{"badlands", "badlands_plateau", "modified_badlands_plateau", "wooded_badlands_plateau", "modified_wooded_badlands_plateau", "eroded_badlands", "paper"}; - for (String extraGoldBiome : extraGoldBiomes) { - extraGoldIndexes.put(extraGoldBiome, 14); - } - ores.add(new Ore(Type.COAL, DimensionTypes.OVERWORLD_ID, 7, 6, ConstantIntProvider.create(20), false, 0, 128, Generator.DEFAULT, 20, coal, new Color(47, 44, 54))); - ores.add(new Ore(Type.IRON,DimensionTypes.OVERWORLD_ID, 8, 6, ConstantIntProvider.create(20), false, 0, 64, Generator.DEFAULT, 9, iron, new Color(236, 173, 119))); - ores.add(new Ore(Type.GOLD, DimensionTypes.OVERWORLD_ID, 9, 6, ConstantIntProvider.create(2), false, 0, 32, Generator.DEFAULT, 9, gold, new Color(247, 229, 30))); - ores.add(new Ore(Type.REDSTONE, DimensionTypes.OVERWORLD_ID, 10, 6, ConstantIntProvider.create(8), false, 0, 16, Generator.DEFAULT, 8, redstone, new Color(245, 7, 23))); - ores.add(new Ore(Type.DIAMOND, DimensionTypes.OVERWORLD_ID, 11, 6, ConstantIntProvider.create(1), false, 0, 16, Generator.DEFAULT, 8, diamond, new Color(33, 244, 255))); - ores.add(new Ore(Type.LAPIS, DimensionTypes.OVERWORLD_ID, 12, 6, ConstantIntProvider.create(1), true, 16, 16, Generator.DEFAULT, 7, lapis, new Color(8, 26, 189))); - ores.add(new Ore(Type.COPPER, DimensionTypes.OVERWORLD_ID, 13, 6, ConstantIntProvider.create(6), true, 49, 49, Generator.DEFAULT, 10, copper, new Color(239, 151, 0))); - ores.add(new Ore(Type.GOLD_EXTRA, DimensionTypes.OVERWORLD_ID, extraGoldIndexes, 6, ConstantIntProvider.create(20), false, 32, 80, Generator.DEFAULT, 9, gold, new Color(247, 229, 30))); - ores.add(new Ore(Type.EMERALD, DimensionTypes.OVERWORLD_ID, emeraldIndexes, 6, UniformIntProvider.create(6, 8), false, 4, 32, Generator.EMERALD, 1, emerald, new Color(27, 209, 45))); - ores.add(new Ore(Type.GOLD_NETHER, DimensionTypes.THE_NETHER_ID, Map.of("default", 13, "basalt_deltas", -1), 7, ConstantIntProvider.create(10), false, 10, 118, Generator.DEFAULT, 10, gold, new Color(247, 229, 30))); - ores.add(new Ore(Type.QUARTZ, DimensionTypes.THE_NETHER_ID, Map.of("default", 14, "basalt_deltas", -1), 7, ConstantIntProvider.create(16), false, 10, 118, Generator.DEFAULT, 14, quartz, new Color(205, 205, 205))); - ores.add(new Ore(Type.GOLD_NETHER, DimensionTypes.THE_NETHER_ID, Map.of("default", -1, "basalt_deltas", 13), 7, ConstantIntProvider.create(20), false, 10, 118, Generator.DEFAULT, 10, gold, new Color(247, 229, 30))); - ores.add(new Ore(Type.QUARTZ, DimensionTypes.THE_NETHER_ID, Map.of("default", -1, "basalt_deltas", 14), 7, ConstantIntProvider.create(32), false, 10, 118, Generator.DEFAULT, 14, quartz, new Color(205, 205, 205))); - ores.add(new Ore(Type.LDEBRIS, DimensionTypes.THE_NETHER_ID, LDebrisIndexes, 7, ConstantIntProvider.create(1), true, 17, 9, Generator.NO_SURFACE, 3, debris, new Color(209, 27, 245))); - ores.add(new Ore(Type.SDEBRIS, DimensionTypes.THE_NETHER_ID, SDebrisIndexes, 7, ConstantIntProvider.create(1), false, 8, 120, Generator.NO_SURFACE, 2, debris, new Color(209, 27, 245))); - return ores; - } + public int step; + public int index; + public Setting active; + public IntProvider count = ConstantIntProvider.create(1); + public HeightProvider heightProvider; + public HeightContext heightContext; + public float rarity = 1; + public float discardOnAirChance; + public int size; + public Color color; + public boolean scattered; + + private Ore(PlacedFeature feature, int step, int index, Setting active, Color color) { + this.step = step; + this.index = index; + this.active = active; + this.color = color; + int bottom = MinecraftClient.getInstance().world.getBottomY(); + int height = MinecraftClient.getInstance().world.getDimension().logicalHeight(); + this.heightContext = new HeightContext(null, HeightLimitView.create(bottom, height)); - private static List V1_17_1() { - return baseConfig(); - } + for (PlacementModifier modifier : feature.placementModifiers()) { + if (modifier instanceof CountPlacementModifier) { + this.count = ((CountPlacementModifierAccessor) modifier).getCount(); - private static List V1_17() { - List ores = baseConfig(); - for (Ore ore : ores) { - if (ore.type.equals(Type.DIAMOND)) { - ore.maxY = 17; - } - if (ore.type.equals(Type.EMERALD)) { - ore.count = UniformIntProvider.create(6, 24); - } - } - return ores; - } + } else if (modifier instanceof HeightRangePlacementModifier) { + this.heightProvider = ((HeightRangePlacementModifierAccessor) modifier).getHeight(); - private static List V1_16() { - List ores = baseConfig(); - ores.removeIf(ore -> ore.type.equals(Type.COPPER)); - for (Ore ore : ores) { - if (ore.type == Type.EMERALD || ore.type == Type.GOLD_EXTRA) { - ore.index.keySet().forEach(key -> ore.index.put(key, ore.index.get(key) - 3)); - } else if (ore.dimension == DimensionTypes.OVERWORLD_ID) { - ore.index.keySet().forEach(key -> ore.index.put(key, ore.index.get(key) - 2)); - } else if (ore.type == Type.LDEBRIS) { - ore.minY = 16; - ore.maxY = 8; + } else if (modifier instanceof RarityFilterPlacementModifier) { + this.rarity = ((RarityFilterPlacementModifierAccessor) modifier).getChance(); } } - return ores; - } - private static List V1_15() { - List ores = V1_16(); - ores.removeIf(ore -> ore.type == Type.SDEBRIS || ore.type == Type.LDEBRIS || ore.type == Type.GOLD_NETHER); - for (Ore ore : ores) { - ore.step -= 2; - } - return ores; - } + FeatureConfig featureConfig = feature.feature().value().config(); - public static List getConfig(MCVersion version) { - if (version.isNewerOrEqualTo(MCVersion.v1_19)) { - return V1_19(); - } else if (version.isNewerOrEqualTo(MCVersion.v1_18)) { - return V1_18(); - } else if (version.isNewerOrEqualTo(MCVersion.v1_17_1)) { - return V1_17_1(); - } else if (version.isNewerOrEqualTo(MCVersion.v1_17)) { - return V1_17(); - } else if (version.isNewerOrEqualTo(MCVersion.v1_16)) { - return V1_16(); - } else if (version.isNewerOrEqualTo(MCVersion.v1_14)) { - return V1_15(); + if (featureConfig instanceof OreFeatureConfig oreFeatureConfig) { + this.discardOnAirChance = oreFeatureConfig.discardOnAirChance; + this.size = oreFeatureConfig.size; } else { - return null; + throw new IllegalStateException("config for " + feature + "is not OreFeatureConfig.class"); } - } - - public enum Type { - DIAMOND, REDSTONE, GOLD, IRON, COAL, EMERALD, SDEBRIS, LDEBRIS, LAPIS, COPPER, QUARTZ, GOLD_NETHER, GOLD_EXTRA - } - public enum Generator { - DEFAULT, EMERALD, NO_SURFACE + if (feature.feature().value().feature() instanceof ScatteredOreFeature) { + this.scattered = true; + } } } diff --git a/src/main/resources/meteor-rejects.mixins.json b/src/main/resources/meteor-rejects.mixins.json index a349ba07..4ab9b308 100644 --- a/src/main/resources/meteor-rejects.mixins.json +++ b/src/main/resources/meteor-rejects.mixins.json @@ -7,16 +7,20 @@ "ClientPlayerInteractionManagerMixin", "ClientPlayNetworkHandlerMixin", "CommandSuggestorMixin", + "CountPlacementModifierAccessor", "Deadmau5FeatureRendererMixin", "EntityAccessor", "GameRendererMixin", "HandshakeC2SPacketAccessor", + "HeightContextMixin", + "HeightRangePlacementModifierAccessor", "LivingEntityMixin", "LivingEntityRendererMixin", "MultiplayerScreenAccessor", "MultiplayerScreenMixin", "PlayerEntityMixin", "PlayerMoveC2SPacketAccessor", + "RarityFilterPlacementModifierAccessor", "ServerListAccessor", "StructureVoidBlockMixin", "TexturedRenderLayersMixin", From fa6bb052284fda9d3e156faf73f626ce9faeb6c4 Mon Sep 17 00:00:00 2001 From: misterx Date: Sat, 9 Dec 2023 21:30:09 +0100 Subject: [PATCH 2/2] fix bug with rarity modifier and use meteor utils --- .../java/anticope/rejects/modules/OreSim.java | 92 ++++++------------- 1 file changed, 29 insertions(+), 63 deletions(-) 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; }