Fixes for oresim on 1.21.10
Some checks failed
Java CI with Gradle / build (push) Has been cancelled

This commit is contained in:
2025-11-02 14:40:49 -03:00
parent 8fc798ee94
commit f5184d3d13
2 changed files with 308 additions and 28 deletions

View File

@@ -35,6 +35,8 @@ public class AutoFarm extends Module {
private final SettingGroup sgBonemeal = settings.createGroup("Bonemeal");
private final Map<BlockPos, Item> replantMap = new HashMap<>();
private final Map<BlockPos, Integer> miningProgress = new HashMap<>();
private static final int MINING_HITS = 6;
private final Setting<Integer> range = sgGeneral.add(new IntSetting.Builder()
.name("range")
@@ -138,6 +140,7 @@ public class AutoFarm extends Module {
@Override
public void onDeactivate() {
replantMap.clear();
miningProgress.clear();
}
@EventHandler
@@ -152,7 +155,13 @@ public class AutoFarm extends Module {
else if (block == Blocks.BEETROOTS) item = Items.BEETROOT_SEEDS;
else if (block == Blocks.NETHER_WART) item = Items.NETHER_WART;
else if (block == Blocks.PITCHER_CROP) item = Items.PITCHER_POD;
else if (block == Blocks.TORCHFLOWER) item = Items.TORCHFLOWER_SEEDS;
else if (block == Blocks.TORCHFLOWER_CROP) item = Items.TORCHFLOWER_SEEDS;
else if (block == Blocks.SUGAR_CANE) item = Items.SUGAR_CANE;
else if (block == Blocks.BAMBOO) item = Items.BAMBOO;
else if (block == Blocks.CACTUS) item = Items.CACTUS;
else if (block == Blocks.KELP || block == Blocks.KELP_PLANT) item = Items.KELP;
else if (block == Blocks.CHORUS_FLOWER) item = Items.CHORUS_FLOWER;
else if (block == Blocks.CAVE_VINES || block == Blocks.CAVE_VINES_PLANT) item = Items.GLOW_BERRIES;
if (item != null) replantMap.put(event.blockPos, item);
}
}
@@ -160,8 +169,13 @@ public class AutoFarm extends Module {
@EventHandler
private void onTick(TickEvent.Pre event) {
actions = 0;
BlockIterator.register(range.get(), range.get(), (pos, state) -> {
if (mc.player.getEyePos().distanceTo(Vec3d.ofCenter(pos)) <= range.get())
// Scan blocks including vertical range for tall crops
int horizontalRange = range.get();
int verticalRange = range.get() + 2; // Extra vertical range for tall crops
BlockIterator.register(horizontalRange, verticalRange, (pos, state) -> {
if (mc.player.getEyePos().distanceTo(Vec3d.ofCenter(pos)) <= range.get() + 2)
blocks.add(blockPosPool.get().set(pos));
});
@@ -200,19 +214,103 @@ public class AutoFarm extends Module {
private boolean harvest(BlockPos pos, BlockState state, Block block) {
if (!harvest.get()) return false;
if (!harvestBlocks.get().contains(block)) return false;
if (!isMature(state, block)) return false;
if (block instanceof SweetBerryBushBlock)
// Special handling for Sweet Berry Bush (interact instead of breaking)
if (block instanceof SweetBerryBushBlock) {
if (!isMature(pos, state, block)) return false; // Only interact if mature
mc.interactionManager.interactBlock(mc.player, Hand.MAIN_HAND, new BlockHitResult(Utils.vec3d(pos), Direction.UP, pos, false));
else {
mc.interactionManager.updateBlockBreakingProgress(pos, Direction.UP);
return true;
}
// For tall crops (including glow berries, bamboo, sugar cane, kelp, cactus)
if (block == Blocks.CAVE_VINES || block == Blocks.CAVE_VINES_PLANT ||
block == Blocks.BAMBOO || block == Blocks.SUGAR_CANE || block == Blocks.KELP || block == Blocks.CACTUS) {
if (!shouldHarvestTallCrop(pos, block)) {
return false;
}
}
// For other crops, check maturity
else {
if (!isMature(pos, state, block)) return false;
}
// If all checks pass, mine the block
return mineBlock(pos);
}
private boolean mineBlock(BlockPos pos) {
// Check if block still exists
if (mc.world.getBlockState(pos).isAir()) {
miningProgress.remove(pos);
return false;
}
int hits = miningProgress.getOrDefault(pos, 0);
// Rotate towards block
if (rotate.get()) {
meteordevelopment.meteorclient.utils.player.Rotations.rotate(
meteordevelopment.meteorclient.utils.player.Rotations.getYaw(pos),
meteordevelopment.meteorclient.utils.player.Rotations.getPitch(pos)
);
}
if (hits < MINING_HITS - 1) {
// Hit the block (not breaking yet)
mc.interactionManager.attackBlock(pos, Direction.UP);
miningProgress.put(pos, hits + 1);
return true;
} else {
// Final hit - break the block
mc.interactionManager.attackBlock(pos, Direction.UP);
mc.player.swingHand(Hand.MAIN_HAND);
miningProgress.remove(pos);
return true;
}
}
private boolean shouldHarvestTallCrop(BlockPos pos, Block block) {
BlockPos below = pos.down();
Block blockBelow = mc.world.getBlockState(below).getBlock();
// For bamboo, only harvest if it's tall enough (3+ blocks)
if (block == Blocks.BAMBOO) {
if (blockBelow != Blocks.BAMBOO) return false;
BlockPos below2 = below.down();
return mc.world.getBlockState(below2).getBlock() == Blocks.BAMBOO;
}
// For cactus and sugar cane, harvest top blocks only (leave at least one block on sand/dirt)
if (block == Blocks.CACTUS || block == Blocks.SUGAR_CANE) {
// Harvest if there is a crop block below, leaving the base.
return blockBelow == block;
}
// For glow berries (cave vines), harvest from bottom up but leave the top attached
if (block == Blocks.CAVE_VINES || block == Blocks.CAVE_VINES_PLANT) {
BlockPos above = pos.up();
Block blockAbove = mc.world.getBlockState(above).getBlock();
// Must have a vine or solid block above (so we're not breaking the attachment point)
if (blockAbove != Blocks.CAVE_VINES && blockAbove != Blocks.CAVE_VINES_PLANT &&
!mc.world.getBlockState(above).isSolidBlock(mc.world, above)) {
return false;
}
// Only harvest if there's at least 2 blocks above (leave at least one vine attached)
BlockPos above2 = above.up();
Block blockAbove2 = mc.world.getBlockState(above2).getBlock();
return blockAbove2 == Blocks.CAVE_VINES || blockAbove2 == Blocks.CAVE_VINES_PLANT ||
mc.world.getBlockState(above2).isSolidBlock(mc.world, above2);
}
return true;
}
private boolean plant(BlockPos pos, Block block) {
if (!plant.get()) return false;
if (!mc.world.isAir(pos.up())) return false;
FindItemResult findItemResult = null;
if (onlyReplant.get()) {
for (BlockPos replantPos : replantMap.keySet()) {
if (replantPos.equals(pos.up())) {
@@ -221,17 +319,112 @@ public class AutoFarm extends Module {
break;
}
}
} else if (block instanceof FarmlandBlock) {
findItemResult = InvUtils.find(itemStack -> {
Item item = itemStack.getItem();
return item != Items.NETHER_WART && plantItems.get().contains(item);
});
} else if (block instanceof SoulSandBlock) {
findItemResult = InvUtils.find(itemStack -> {
Item item = itemStack.getItem();
return item == Items.NETHER_WART && plantItems.get().contains(Items.NETHER_WART);
});
} else {
// Cave vines for glow berries - ONLY extend existing vines by ONE block
if (block == Blocks.CAVE_VINES || block == Blocks.CAVE_VINES_PLANT) {
// Check if the block directly below is air (to extend by one)
if (mc.world.isAir(pos.down())) {
findItemResult = InvUtils.find(itemStack -> {
Item item = itemStack.getItem();
return item == Items.GLOW_BERRIES && plantItems.get().contains(Items.GLOW_BERRIES);
});
if (findItemResult != null && findItemResult.found()) {
BlockUtils.place(pos.down(), findItemResult, rotate.get(), -100, false);
return true;
}
}
return false;
}
// Check if we can start a new glow berry vine below a solid block (ONE block only)
else if (!mc.world.isAir(pos) && mc.world.getBlockState(pos).isSolidBlock(mc.world, pos)) {
BlockPos below = pos.down();
// Only plant if directly below is air AND it's not already a cave vine
if (mc.world.isAir(below) &&
mc.world.getBlockState(below).getBlock() != Blocks.CAVE_VINES &&
mc.world.getBlockState(below).getBlock() != Blocks.CAVE_VINES_PLANT) {
findItemResult = InvUtils.find(itemStack -> {
Item item = itemStack.getItem();
return item == Items.GLOW_BERRIES && plantItems.get().contains(Items.GLOW_BERRIES);
});
if (findItemResult != null && findItemResult.found()) {
BlockUtils.place(below, findItemResult, rotate.get(), -100, false);
return true;
}
}
return false;
}
if (!mc.world.isAir(pos.up())) return false;
// Farmland crops
if (block instanceof FarmlandBlock) {
findItemResult = InvUtils.find(itemStack -> {
Item item = itemStack.getItem();
return item != Items.NETHER_WART && plantItems.get().contains(item) &&
(item == Items.WHEAT_SEEDS || item == Items.CARROT || item == Items.POTATO ||
item == Items.BEETROOT_SEEDS || item == Items.PUMPKIN_SEEDS ||
item == Items.MELON_SEEDS || item == Items.PITCHER_POD ||
item == Items.TORCHFLOWER_SEEDS);
});
}
// Soul sand crops (nether wart)
else if (block instanceof SoulSandBlock) {
findItemResult = InvUtils.find(itemStack -> {
Item item = itemStack.getItem();
return item == Items.NETHER_WART && plantItems.get().contains(Items.NETHER_WART);
});
}
// Dirt/Grass for sugar cane, bamboo
else if (block == Blocks.DIRT || block == Blocks.GRASS_BLOCK || block == Blocks.PODZOL ||
block == Blocks.COARSE_DIRT || block == Blocks.ROOTED_DIRT || block == Blocks.MOSS_BLOCK) {
findItemResult = InvUtils.find(itemStack -> {
Item item = itemStack.getItem();
return plantItems.get().contains(item) &&
(item == Items.SUGAR_CANE || item == Items.BAMBOO);
});
}
// Sand for cactus and sugar cane
else if (block == Blocks.SAND || block == Blocks.RED_SAND) {
// Check if there's space around for cactus (no adjacent blocks)
BlockPos plantPos = pos.up();
boolean hasSpaceForCactus = mc.world.isAir(plantPos.north()) &&
mc.world.isAir(plantPos.south()) &&
mc.world.isAir(plantPos.east()) &&
mc.world.isAir(plantPos.west());
if (hasSpaceForCactus) {
// Can plant cactus
findItemResult = InvUtils.find(itemStack -> {
Item item = itemStack.getItem();
return plantItems.get().contains(item) &&
(item == Items.CACTUS || item == Items.SUGAR_CANE);
});
} else {
// Only sugar cane (doesn't need space)
findItemResult = InvUtils.find(itemStack -> {
Item item = itemStack.getItem();
return item == Items.SUGAR_CANE && plantItems.get().contains(Items.SUGAR_CANE);
});
}
}
// Water/kelp for kelp
else if (block == Blocks.WATER || block == Blocks.KELP || block == Blocks.KELP_PLANT) {
if (mc.world.getFluidState(pos.up()).isIn(FluidTags.WATER)) {
findItemResult = InvUtils.find(itemStack -> {
Item item = itemStack.getItem();
return item == Items.KELP && plantItems.get().contains(Items.KELP);
});
}
}
// End stone for chorus
else if (block == Blocks.END_STONE) {
findItemResult = InvUtils.find(itemStack -> {
Item item = itemStack.getItem();
return item == Items.CHORUS_FLOWER && plantItems.get().contains(Items.CHORUS_FLOWER);
});
}
}
if (findItemResult != null && findItemResult.found()) {
BlockUtils.place(pos.up(), findItemResult, rotate.get(), -100, false);
return true;
@@ -242,10 +435,41 @@ public class AutoFarm extends Module {
private boolean bonemeal(BlockPos pos, BlockState state, Block block) {
if (!bonemeal.get()) return false;
if (!bonemealBlocks.get().contains(block)) return false;
if (isMature(state, block)) return false;
FindItemResult bonemeal = InvUtils.findInHotbar(Items.BONE_MEAL);
return WorldUtils.interact(pos, bonemeal, rotate.get());
// If crop is already mature, harvest it instead
if (isMature(pos, state, block)) {
return harvest(pos, state, block);
}
FindItemResult bonemealResult = InvUtils.find(Items.BONE_MEAL);
// If no bonemeal available, harvest mature crops instead
if (!bonemealResult.found()) {
if (isMature(pos, state, block)) {
return harvest(pos, state, block);
}
return false;
}
// Move to hotbar if not already there
if (!bonemealResult.isHotbar()) {
for (int i = 0; i < 9; i++) {
if (mc.player.getInventory().getStack(i).isEmpty()) {
InvUtils.move().from(bonemealResult.slot()).to(i);
bonemealResult = InvUtils.findInHotbar(Items.BONE_MEAL);
break;
}
}
// If still not in hotbar after trying to move, harvest if mature
if (!bonemealResult.found() || !bonemealResult.isHotbar()) {
if (isMature(pos, state, block)) {
return harvest(pos, state, block);
}
return false;
}
}
return WorldUtils.interact(pos, bonemealResult, rotate.get());
}
private boolean isWaterNearby(WorldView world, BlockPos pos) {
@@ -255,7 +479,7 @@ public class AutoFarm extends Module {
return false;
}
private boolean isMature(BlockState state, Block block) {
private boolean isMature(BlockPos pos, BlockState state, Block block) {
if (block instanceof CropBlock cropBlock) {
return cropBlock.isMature(state);
} else if (block instanceof CocoaBlock cocoaBlock) {
@@ -268,6 +492,36 @@ public class AutoFarm extends Module {
return state.get(netherWartBlock.AGE) >= 3;
} else if (block instanceof PitcherCropBlock pitcherCropBlock) {
return state.get(pitcherCropBlock.AGE) >= 4;
} else if (block == Blocks.CAVE_VINES || block == Blocks.CAVE_VINES_PLANT) {
// For glow berries: mature means there are berries (triggers harvest of entire vine section)
// During harvest, ALL vine blocks are broken regardless of berries
return state.get(CaveVines.BERRIES);
}
// Bamboo is mature if it's more than 2 blocks tall (ready to harvest)
// For bonemeal check, we consider single bamboo as not mature
else if (block == Blocks.BAMBOO) {
Block below = mc.world.getBlockState(pos.down()).getBlock();
Block below2 = mc.world.getBlockState(pos.down(2)).getBlock();
// If checking for harvest, needs 3 blocks tall
// If checking for bonemeal, single bamboo is not mature
return below == Blocks.BAMBOO && below2 == Blocks.BAMBOO;
}
// Sugar cane is mature if it's more than 2 blocks tall
else if (block == Blocks.SUGAR_CANE) {
return mc.world.getBlockState(pos.down()).getBlock() == Blocks.SUGAR_CANE &&
mc.world.getBlockState(pos.down(2)).getBlock() == Blocks.SUGAR_CANE;
}
// Cactus is mature if it's more than 2 blocks tall
else if (block == Blocks.CACTUS) {
return mc.world.getBlockState(pos.down()).getBlock() == Blocks.CACTUS &&
mc.world.getBlockState(pos.down(2)).getBlock() == Blocks.CACTUS;
}
// Kelp is mature if it's more than 2 blocks tall
else if (block == Blocks.KELP || block == Blocks.KELP_PLANT) {
Block below = mc.world.getBlockState(pos.down()).getBlock();
Block below2 = mc.world.getBlockState(pos.down(2)).getBlock();
return (below == Blocks.KELP || below == Blocks.KELP_PLANT) &&
(below2 == Blocks.KELP || below2 == Blocks.KELP_PLANT);
}
return true;
}
@@ -281,7 +535,14 @@ public class AutoFarm extends Module {
block == Blocks.COCOA ||
block == Blocks.SWEET_BERRY_BUSH ||
block == Blocks.PITCHER_CROP ||
block == Blocks.TORCHFLOWER;
block == Blocks.TORCHFLOWER_CROP ||
block == Blocks.BAMBOO ||
// Cactus and sugar cane removed from bonemeal filter
block == Blocks.KELP ||
block == Blocks.KELP_PLANT ||
block == Blocks.CHORUS_FLOWER ||
block == Blocks.CAVE_VINES ||
block == Blocks.CAVE_VINES_PLANT;
}
private boolean harvestFilter(Block block) {
@@ -292,7 +553,15 @@ public class AutoFarm extends Module {
block == Blocks.SWEET_BERRY_BUSH ||
block == Blocks.COCOA ||
block == Blocks.PITCHER_CROP ||
block == Blocks.TORCHFLOWER;
block == Blocks.TORCHFLOWER_CROP ||
block == Blocks.BAMBOO ||
block == Blocks.SUGAR_CANE ||
block == Blocks.CACTUS ||
block == Blocks.KELP ||
block == Blocks.KELP_PLANT ||
block == Blocks.CHORUS_FLOWER ||
block == Blocks.CAVE_VINES ||
block == Blocks.CAVE_VINES_PLANT;
}
private boolean plantFilter(Item item) {
@@ -304,6 +573,12 @@ public class AutoFarm extends Module {
item == Items.MELON_SEEDS ||
item == Items.NETHER_WART ||
item == Items.PITCHER_POD ||
item == Items.TORCHFLOWER_SEEDS;
item == Items.TORCHFLOWER_SEEDS ||
item == Items.BAMBOO ||
item == Items.SUGAR_CANE ||
item == Items.CACTUS ||
item == Items.KELP ||
item == Items.CHORUS_FLOWER ||
item == Items.GLOW_BERRIES;
}
}
}

View File

@@ -307,8 +307,13 @@ public class OreSim extends Module {
String blockId = Registries.BLOCK.getId(state.getBlock()).toString();
// Check for ore blocks - handles coal_ore, deepslate_coal_ore, emerald_ore, etc.
return blockId.contains("_ore") || blockId.contains("ancient_debris");
// Check for any ore block or ancient debris
// This includes: coal_ore, deepslate_coal_ore, iron_ore, deepslate_iron_ore,
// gold_ore, deepslate_gold_ore, diamond_ore, deepslate_diamond_ore,
// emerald_ore, deepslate_emerald_ore, lapis_ore, deepslate_lapis_ore,
// redstone_ore, deepslate_redstone_ore, copper_ore, deepslate_copper_ore,
// nether_gold_ore, nether_quartz_ore, ancient_debris
return blockId.endsWith("_ore") || blockId.equals("minecraft:ancient_debris");
}
// ====================================