|
| 1 | +/* |
| 2 | + * This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client). |
| 3 | + * Copyright (c) Meteor Development. |
| 4 | + */ |
| 5 | + |
| 6 | +package meteordevelopment.meteorclient.systems.modules.world; |
| 7 | + |
| 8 | +import meteordevelopment.meteorclient.events.world.TickEvent; |
| 9 | +import meteordevelopment.meteorclient.settings.BoolSetting; |
| 10 | +import meteordevelopment.meteorclient.settings.DoubleSetting; |
| 11 | +import meteordevelopment.meteorclient.settings.Setting; |
| 12 | +import meteordevelopment.meteorclient.settings.SettingGroup; |
| 13 | +import meteordevelopment.meteorclient.systems.modules.Categories; |
| 14 | +import meteordevelopment.meteorclient.systems.modules.Module; |
| 15 | +import meteordevelopment.meteorclient.utils.player.*; |
| 16 | +import meteordevelopment.orbit.EventHandler; |
| 17 | +import net.minecraft.entity.Entity; |
| 18 | +import net.minecraft.entity.mob.CreeperEntity; |
| 19 | +import net.minecraft.item.FlintAndSteelItem; |
| 20 | +import net.minecraft.item.Item; |
| 21 | +import net.minecraft.util.Hand; |
| 22 | + |
| 23 | +import java.util.ArrayList; |
| 24 | +import java.util.concurrent.ThreadLocalRandom; |
| 25 | + |
| 26 | +public class CreeperAura extends Module { |
| 27 | + private final SettingGroup sgGeneral = settings.getDefaultGroup(); |
| 28 | + |
| 29 | + private final Setting<Boolean> autoSwitch = sgGeneral.add(new BoolSetting.Builder() |
| 30 | + .name("auto-switch") |
| 31 | + .description("automatically switches to flint and steal if in hotbar") |
| 32 | + .defaultValue(true) |
| 33 | + .build() |
| 34 | + ); |
| 35 | + |
| 36 | + private final Setting<Boolean> ignoreNamed = sgGeneral.add(new BoolSetting.Builder() |
| 37 | + .name("ignore-named") |
| 38 | + .description("Ignore creepers that are named") |
| 39 | + .defaultValue(false) |
| 40 | + .build() |
| 41 | + ); |
| 42 | + |
| 43 | + private final Setting<Double> distance = sgGeneral.add(new DoubleSetting.Builder() |
| 44 | + .name("distance") |
| 45 | + .description("The maximum distance the creeper has to be to be ignited.") |
| 46 | + .min(0.0) |
| 47 | + .defaultValue(5.0) |
| 48 | + .build() |
| 49 | + ); |
| 50 | + |
| 51 | + public CreeperAura() { |
| 52 | + super(Categories.Combat, "creeper-aura", "Uses a flint and steal to ignite creepers around you"); |
| 53 | + } |
| 54 | + |
| 55 | + private final ArrayList<CreeperEntity> targets = new ArrayList<>(); |
| 56 | + private Hand hand; |
| 57 | + |
| 58 | + @Override |
| 59 | + public void onDeactivate() { |
| 60 | + targets.clear(); |
| 61 | + } |
| 62 | + |
| 63 | + @EventHandler |
| 64 | + public void onTick(TickEvent.Pre event) { |
| 65 | + Item mainHand = mc.player.getInventory().getStack(mc.player.getInventory().selectedSlot).getItem(); |
| 66 | + Item offHand = mc.player.getOffHandStack().getItem(); |
| 67 | + |
| 68 | + // Return early if not needed |
| 69 | + if (!autoSwitch.get() && !(mainHand instanceof FlintAndSteelItem) && !(offHand instanceof FlintAndSteelItem)) return; |
| 70 | + checkEntities(); |
| 71 | + |
| 72 | + } |
| 73 | + public void checkEntities() { |
| 74 | + for (Entity entity : mc.world.getEntities()) { |
| 75 | + if (entity instanceof CreeperEntity creeper && creeper.isAlive() && PlayerUtils.isWithin(creeper, distance.get()) && !creeper.isIgnited() && !targets.contains(creeper)) { |
| 76 | + if (ignoreNamed.get() && creeper.hasCustomName()) return; |
| 77 | + targets.add(creeper); |
| 78 | + CreeperEntity currentTarget = targets.get(ThreadLocalRandom.current().nextInt(targets.size())); |
| 79 | + checkHands(currentTarget); |
| 80 | + } |
| 81 | + } |
| 82 | + } |
| 83 | + |
| 84 | + public void checkHands(CreeperEntity currentTarget) { |
| 85 | + Item mainHand = mc.player.getInventory().getStack(mc.player.getInventory().selectedSlot).getItem(); |
| 86 | + Item offHand = mc.player.getOffHandStack().getItem(); |
| 87 | + // If player isn't holding flint and steal and auto switch is enabled, switch and then ignite |
| 88 | + if (autoSwitch.get() && !(mainHand instanceof FlintAndSteelItem) && !(offHand instanceof FlintAndSteelItem)) { |
| 89 | + InvUtils.swap(findSlot(), true); |
| 90 | + ignite(currentTarget); |
| 91 | + InvUtils.swapBack(); |
| 92 | + } |
| 93 | + if (mainHand instanceof FlintAndSteelItem) { |
| 94 | + hand = Hand.MAIN_HAND; |
| 95 | + ignite(currentTarget); |
| 96 | + } |
| 97 | + if (offHand instanceof FlintAndSteelItem) { |
| 98 | + hand = Hand.OFF_HAND; |
| 99 | + ignite(currentTarget); |
| 100 | + } |
| 101 | + } |
| 102 | + |
| 103 | + public byte findSlot() { |
| 104 | + byte slot = -1; |
| 105 | + Item offHandItem = mc.player.getOffHandStack().getItem(); |
| 106 | + if (offHandItem instanceof FlintAndSteelItem) { |
| 107 | + slot = SlotUtils.OFFHAND; |
| 108 | + hand = Hand.OFF_HAND; |
| 109 | + return slot; |
| 110 | + } |
| 111 | + |
| 112 | + for (byte i = 0; i < 9; i++) { |
| 113 | + Item item = mc.player.getInventory().getStack(i).getItem(); |
| 114 | + if (item instanceof FlintAndSteelItem) { |
| 115 | + slot = i; |
| 116 | + hand = Hand.MAIN_HAND; |
| 117 | + return slot; |
| 118 | + } |
| 119 | + } |
| 120 | + return slot; |
| 121 | + } |
| 122 | + |
| 123 | + public void ignite(CreeperEntity target) { |
| 124 | + mc.interactionManager.interactEntity(mc.player, target, hand); |
| 125 | + targets.remove(target); |
| 126 | + } |
| 127 | +} |
0 commit comments