|
| 1 | +package anticope.rejects.modules; |
| 2 | + |
| 3 | +import anticope.rejects.MeteorRejectsAddon; |
| 4 | +import meteordevelopment.meteorclient.events.world.TickEvent; |
| 5 | +import meteordevelopment.meteorclient.settings.*; |
| 6 | +import meteordevelopment.meteorclient.systems.modules.Module; |
| 7 | +import meteordevelopment.meteorclient.utils.player.InvUtils; |
| 8 | +import meteordevelopment.orbit.EventHandler; |
| 9 | +import net.minecraft.block.*; |
| 10 | +import net.minecraft.item.Item; |
| 11 | +import net.minecraft.item.Items; |
| 12 | +import net.minecraft.screen.slot.SlotActionType; |
| 13 | +import net.minecraft.util.Hand; |
| 14 | +import net.minecraft.util.hit.BlockHitResult; |
| 15 | +import net.minecraft.util.math.BlockPos; |
| 16 | +import net.minecraft.util.math.Direction; |
| 17 | +import net.minecraft.util.math.Vec3d; |
| 18 | + |
| 19 | +import java.util.ArrayList; |
| 20 | +import java.util.List; |
| 21 | + |
| 22 | +//TODO: add settings to find/use shovel, delay, range ? |
| 23 | +//https://github.com/DustinRepo/JexClient/blob/main/src/main/java/me/dustin/jex/feature/mod/impl/world/LawnBot.java |
| 24 | +public class LawnBot extends Module { |
| 25 | + private final ArrayList<BlockPos> myceliumSpots = new ArrayList<>(); |
| 26 | + private final SettingGroup sgGeneral = settings.getDefaultGroup(); |
| 27 | + |
| 28 | + private final Setting<List<Block>> blockWhitelist = sgGeneral.add(new BlockListSetting.Builder() |
| 29 | + .name("block-whitelist") |
| 30 | + .description("Which blocks to replace with grass.") |
| 31 | + .defaultValue() |
| 32 | + .filter(this::grassFilter) |
| 33 | + .build() |
| 34 | + ); |
| 35 | + |
| 36 | + public LawnBot() { |
| 37 | + super(MeteorRejectsAddon.CATEGORY, "lawnbot", "Replace a variety of dirt-type blocks with grass"); |
| 38 | + } |
| 39 | + |
| 40 | + @EventHandler |
| 41 | + private void onTick(TickEvent.Post event) { |
| 42 | + Item grassBlockItem = Items.GRASS_BLOCK; |
| 43 | + int grassCount = InvUtils.find(grassBlockItem).count(); |
| 44 | + if (grassCount == 0) { |
| 45 | + return; |
| 46 | + } |
| 47 | + |
| 48 | + int grassHotbarSlot = InvUtils.findInHotbar((itemStack -> itemStack.getItem() == grassBlockItem)).slot(); |
| 49 | + if (grassHotbarSlot == -1) { |
| 50 | + int grassInvSlot = InvUtils.find((itemStack -> itemStack.getItem() == grassBlockItem)).slot(); |
| 51 | + if (grassInvSlot == -1) |
| 52 | + return; |
| 53 | + |
| 54 | + mc.interactionManager.clickSlot(mc.player.currentScreenHandler.syncId, grassInvSlot < 9 ? grassInvSlot + 36 : grassInvSlot, 8, SlotActionType.SWAP, mc.player); |
| 55 | + return; |
| 56 | + } |
| 57 | + for (int i = 0; i < myceliumSpots.size(); i++) { |
| 58 | + BlockPos pos = myceliumSpots.get(i); |
| 59 | + Block block = mc.world.getBlockState(pos).getBlock(); |
| 60 | + double distance = mc.player.getPos().distanceTo(new Vec3d(pos.getX(), pos.getY(), pos.getZ())); |
| 61 | + if (block == Blocks.AIR && distance <= 5) { |
| 62 | + mc.player.getInventory().selectedSlot = grassHotbarSlot; |
| 63 | + mc.interactionManager.interactBlock(mc.player, Hand.MAIN_HAND, new BlockHitResult(new Vec3d(pos.getX(), pos.getY(), pos.getZ()), Direction.UP, pos, false)); |
| 64 | + return; |
| 65 | + } else if (!blockWhitelist.get().contains(block)) { |
| 66 | + myceliumSpots.remove(i); |
| 67 | + } |
| 68 | + } |
| 69 | + for (int i = 0; i < myceliumSpots.size(); i++) { |
| 70 | + BlockPos pos = myceliumSpots.get(i); |
| 71 | + Block block = mc.world.getBlockState(pos).getBlock(); |
| 72 | + double distance = mc.player.getPos().distanceTo(new Vec3d(pos.getX(), pos.getY(), pos.getZ())); |
| 73 | + if (blockWhitelist.get().contains(block) && distance <= 5) { |
| 74 | + mc.interactionManager.updateBlockBreakingProgress(pos, Direction.UP); |
| 75 | + return; |
| 76 | + } |
| 77 | + } |
| 78 | + myceliumSpots.clear(); |
| 79 | + for (int x = -5; x < 5; x++) { |
| 80 | + for (int y = -3; y < 3; y++) { |
| 81 | + for (int z = -5; z < 5; z++) { |
| 82 | + BlockPos pos = mc.player.getBlockPos().add(x, y, z); |
| 83 | + if (blockWhitelist.get().contains(mc.world.getBlockState(pos).getBlock())) { |
| 84 | + myceliumSpots.add(pos); |
| 85 | + } |
| 86 | + } |
| 87 | + } |
| 88 | + } |
| 89 | + } |
| 90 | + |
| 91 | + private boolean grassFilter(Block block) { |
| 92 | + return block == Blocks.MYCELIUM || |
| 93 | + block == Blocks.PODZOL || |
| 94 | + block == Blocks.DIRT_PATH || |
| 95 | + block == Blocks.COARSE_DIRT || |
| 96 | + block == Blocks.ROOTED_DIRT; |
| 97 | + } |
| 98 | +} |
0 commit comments