Skip to content

Commit

Permalink
AutoTool : Prefer Fortune for ores and crops option (MeteorDevelopmen…
Browse files Browse the repository at this point in the history
  • Loading branch information
DesiCow authored Aug 20, 2023
1 parent b1643d7 commit 7c00a9c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@
import meteordevelopment.meteorclient.systems.modules.Categories;
import meteordevelopment.meteorclient.systems.modules.Module;
import meteordevelopment.meteorclient.systems.modules.Modules;
import meteordevelopment.meteorclient.systems.modules.render.Xray;
import meteordevelopment.meteorclient.systems.modules.world.InfinityMiner;
import meteordevelopment.meteorclient.utils.player.InvUtils;
import meteordevelopment.meteorclient.utils.world.BlockUtils;
import meteordevelopment.orbit.EventHandler;
import meteordevelopment.orbit.EventPriority;
import net.minecraft.block.BambooBlock;
import net.minecraft.block.BambooSaplingBlock;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.*;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.enchantment.Enchantments;
import net.minecraft.item.*;
Expand Down Expand Up @@ -48,6 +46,13 @@ public class AutoTool extends Module {
.build()
);

private final Setting<Boolean> fortuneForOresCrops = sgGeneral.add(new BoolSetting.Builder()
.name("fortune-for-ores-and-crops")
.description("Mines Ores and crops only with the Fortune enchantment.")
.defaultValue(true)
.build()
);

private final Setting<Boolean> antiBreak = sgGeneral.add(new BoolSetting.Builder()
.name("anti-break")
.description("Stops you from breaking your tool.")
Expand Down Expand Up @@ -153,7 +158,7 @@ private void onStartBreakingBlock(StartBreakingBlockEvent event) {
if (listMode.get() == ListMode.Whitelist && !whitelist.get().contains(itemStack.getItem())) continue;
if (listMode.get() == ListMode.Blacklist && blacklist.get().contains(itemStack.getItem())) continue;

double score = getScore(itemStack, blockState, silkTouchForEnderChest.get(), prefer.get(), itemStack2 -> !shouldStopUsing(itemStack2));
double score = getScore(itemStack, blockState, silkTouchForEnderChest.get(), fortuneForOresCrops.get(), prefer.get(), itemStack2 -> !shouldStopUsing(itemStack2));
if (score < 0) continue;

if (score > bestScore) {
Expand All @@ -162,7 +167,7 @@ private void onStartBreakingBlock(StartBreakingBlockEvent event) {
}
}

if ((bestSlot != -1 && (bestScore > getScore(currentStack, blockState, silkTouchForEnderChest.get(), prefer.get(), itemStack -> !shouldStopUsing(itemStack))) || shouldStopUsing(currentStack) || !isTool(currentStack))) {
if ((bestSlot != -1 && (bestScore > getScore(currentStack, blockState, silkTouchForEnderChest.get(), fortuneForOresCrops.get(), prefer.get(), itemStack -> !shouldStopUsing(itemStack))) || shouldStopUsing(currentStack) || !isTool(currentStack))) {
ticks = switchDelay.get();

if (ticks == 0) InvUtils.swap(bestSlot, true);
Expand All @@ -182,7 +187,7 @@ private boolean shouldStopUsing(ItemStack itemStack) {
return antiBreak.get() && (itemStack.getMaxDamage() - itemStack.getDamage()) < (itemStack.getMaxDamage() * breakDurability.get() / 100);
}

public static double getScore(ItemStack itemStack, BlockState state, boolean silkTouchEnderChest, EnchantPreference enchantPreference, Predicate<ItemStack> good) {
public static double getScore(ItemStack itemStack, BlockState state, boolean silkTouchEnderChest, boolean fortuneOre, EnchantPreference enchantPreference, Predicate<ItemStack> good) {
if (!good.test(itemStack) || !isTool(itemStack)) return -1;
if (!itemStack.isSuitableFor(state) && !(itemStack.getItem() instanceof SwordItem && (state.getBlock() instanceof BambooBlock || state.getBlock() instanceof BambooSaplingBlock))) return -1;

Expand All @@ -192,6 +197,12 @@ public static double getScore(ItemStack itemStack, BlockState state, boolean sil
return -1;
}

if (fortuneOre
&& isFortunable(state.getBlock())
&& EnchantmentHelper.getLevel(Enchantments.FORTUNE, itemStack) == 0) {
return -1;
}

double score = 0;

score += itemStack.getMiningSpeedMultiplier(state) * 1000;
Expand All @@ -216,6 +227,11 @@ public static boolean isTool(ItemStack itemStack) {
return isTool(itemStack.getItem());
}

private static boolean isFortunable(Block block) {
if (block == Blocks.ANCIENT_DEBRIS) return false;
return Xray.ORES.contains(block) || block instanceof CropBlock;
}

public enum EnchantPreference {
None,
Fortune,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,30 +31,12 @@
public class Xray extends Module {
private final SettingGroup sgGeneral = settings.getDefaultGroup();

public static final List<Block> ORES = List.of(Blocks.COAL_ORE, Blocks.DEEPSLATE_COAL_ORE, Blocks.IRON_ORE, Blocks.DEEPSLATE_IRON_ORE, Blocks.GOLD_ORE, Blocks.DEEPSLATE_GOLD_ORE, Blocks.LAPIS_ORE, Blocks.DEEPSLATE_LAPIS_ORE, Blocks.REDSTONE_ORE, Blocks.REDSTONE_ORE, Blocks.DIAMOND_ORE, Blocks.DEEPSLATE_DIAMOND_ORE, Blocks.EMERALD_ORE, Blocks.DEEPSLATE_EMERALD_ORE, Blocks.COPPER_ORE, Blocks.DEEPSLATE_COPPER_ORE, Blocks.NETHER_GOLD_ORE, Blocks.NETHER_QUARTZ_ORE, Blocks.ANCIENT_DEBRIS);

private final Setting<List<Block>> blocks = sgGeneral.add(new BlockListSetting.Builder()
.name("whitelist")
.description("Which blocks to show x-rayed.")
.defaultValue(
Blocks.COAL_ORE,
Blocks.DEEPSLATE_COAL_ORE,
Blocks.IRON_ORE,
Blocks.DEEPSLATE_IRON_ORE,
Blocks.GOLD_ORE,
Blocks.DEEPSLATE_GOLD_ORE,
Blocks.LAPIS_ORE,
Blocks.DEEPSLATE_LAPIS_ORE,
Blocks.REDSTONE_ORE,
Blocks.DEEPSLATE_REDSTONE_ORE,
Blocks.DIAMOND_ORE,
Blocks.DEEPSLATE_DIAMOND_ORE,
Blocks.EMERALD_ORE,
Blocks.DEEPSLATE_EMERALD_ORE,
Blocks.COPPER_ORE,
Blocks.DEEPSLATE_COPPER_ORE,
Blocks.NETHER_GOLD_ORE,
Blocks.NETHER_QUARTZ_ORE,
Blocks.ANCIENT_DEBRIS
)
.defaultValue(ORES)
.onChanged(v -> {
if (isActive()) mc.worldRenderer.reload();
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,7 @@ protected int findAndMoveBestToolToHotbar(HighwayBuilder b, BlockState blockStat
int bestSlot = -1;

for (int i = 0; i < b.mc.player.getInventory().main.size(); i++) {
double score = AutoTool.getScore(b.mc.player.getInventory().getStack(i), blockState, false, AutoTool.EnchantPreference.None, itemStack -> {
double score = AutoTool.getScore(b.mc.player.getInventory().getStack(i), blockState, false, false, AutoTool.EnchantPreference.None, itemStack -> {
if (noSilkTouch && EnchantmentHelper.getLevel(Enchantments.SILK_TOUCH, itemStack) != 0) return false;
return !b.dontBreakTools.get() || itemStack.getMaxDamage() - itemStack.getDamage() > 1;
});
Expand Down

0 comments on commit 7c00a9c

Please sign in to comment.