From 3c2eb3cbf5288c2aa30d9e266b9d07a40d7a5430 Mon Sep 17 00:00:00 2001 From: Cloudburst Date: Sun, 30 May 2021 17:54:43 +0200 Subject: [PATCH] autotnt stuff --- .../cloudburst/rejects/modules/AutoTNT.java | 243 +++++++++--------- 1 file changed, 120 insertions(+), 123 deletions(-) diff --git a/src/main/java/cloudburst/rejects/modules/AutoTNT.java b/src/main/java/cloudburst/rejects/modules/AutoTNT.java index b17c3e3..3cb7c1d 100644 --- a/src/main/java/cloudburst/rejects/modules/AutoTNT.java +++ b/src/main/java/cloudburst/rejects/modules/AutoTNT.java @@ -25,126 +25,123 @@ import java.util.ArrayList; import java.util.Comparator; public class AutoTNT extends Module { - private final SettingGroup sgGeneral = settings.getDefaultGroup(); - - // General - - private final Setting delay = sgGeneral.add(new IntSetting.Builder() - .name("delay") - .description("Delay in ticks between ignition") - .defaultValue(1) - .build() - ); - - private final Setting range = sgGeneral.add(new IntSetting.Builder() - .name("range") - .description("Range of ignition") - .defaultValue(4) - .build() - ); - - private final Setting turnOff = sgGeneral.add(new BoolSetting.Builder() - .name("turn-off") - .description("Turns of after igniting tnt") - .defaultValue(true) - .build() - ); - - private final Setting antiBreak = sgGeneral.add(new BoolSetting.Builder() - .name("anti-break") - .description("Whether or not to save flint and steel from breaking.") - .defaultValue(true) - .build() - ); - - private final ArrayList blocks = new ArrayList<>(); - private BlockPos.Mutable bp = new BlockPos.Mutable(); - private boolean ignited, messaged; - private int ticks = 0; - private int preSlot, slot; - - @Override - public void onActivate() { - ignited = false; - messaged = false; - } - - @Override - public void onDeactivate() { - ticks = 0; - } - - public AutoTNT() { - super(MeteorRejectsAddon.CATEGORY, "auto-tnt", "Ignites TNT for you"); - } - - @EventHandler - private void onTick(TickEvent.Post event) { - if (ticks <= 0) { - // Clear and get tnt blocks - blocks.clear(); - for (BlockPos vec3d : BlockUtils.getSphere(mc.player.getBlockPos(), range.get(), range.get())) { - setBpToVec3d(vec3d); - - if (mc.world.getBlockState(bp).getBlock() instanceof TntBlock) blocks.add(bp.toImmutable()); - } - - // Make sure there are TNTs around us - if (blocks.size() <= 0) { - - // If already ignited and turnOff.get() - if (turnOff.get() && ignited) { - toggle(); - return; - } - - // If we haven't warned yet - if (!messaged) { - error("No TNT in range"); - messaged = true; - } - return; - } - else messaged = false; - - // Sort based on closest tnt - blocks.sort(Comparator.comparingDouble(PlayerUtils::distanceTo)); - - // Get slot - slot = getSlot(); - if (slot == -1) { - error("No flint and steel in hotbar"); - return; - } - - // Ignition - bp.set(blocks.get(0)); - ignite(bp, slot); - - // Reset ticks - ticks = delay.get(); - } else ticks--; - } - - private void ignite(BlockPos pos, int slot) { - // Set slots - preSlot = mc.player.inventory.selectedSlot; - mc.player.inventory.selectedSlot = slot; - - // Ignited the tnt - ActionResult result = mc.interactionManager.interactBlock(mc.player, mc.world, Hand.MAIN_HAND, new BlockHitResult(new Vec3d(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5), Direction.UP, pos, true)); - if (result == ActionResult.CONSUME || result == ActionResult.SUCCESS) ignited = true; - - // Reset slot - mc.player.inventory.selectedSlot = preSlot; - } - - private int getSlot() { - return InvUtils.findItemInHotbar(item -> item.getItem() instanceof FlintAndSteelItem && (antiBreak.get() && (item.getMaxDamage() - item.getDamage()) > 10)); - } - - private void setBpToVec3d(BlockPos pos) { - bp.set(pos.getX(), pos.getY(), pos.getZ()); - } -} - + private final SettingGroup sgGeneral = settings.getDefaultGroup(); + + // General + + private final Setting delay = sgGeneral.add(new IntSetting.Builder() + .name("delay") + .description("Delay in ticks between ignition") + .defaultValue(1) + .build() + ); + + private final Setting range = sgGeneral.add(new IntSetting.Builder() + .name("range") + .description("Range of ignition") + .defaultValue(4) + .build() + ); + + private final Setting turnOff = sgGeneral.add(new BoolSetting.Builder() + .name("turn-off") + .description("Turns of after igniting tnt") + .defaultValue(true) + .build() + ); + + private final Setting antiBreak = sgGeneral.add(new BoolSetting.Builder() + .name("anti-break") + .description("Whether or not to save flint and steel from breaking.") + .defaultValue(true) + .build() + ); + + private final ArrayList blocks = new ArrayList<>(); + private final BlockPos.Mutable bp = new BlockPos.Mutable(); + private boolean ignited, messaged; + private int ticks = 0; + private int preSlot, slot; + + public AutoTNT() { + super(MeteorRejectsAddon.CATEGORY, "auto-tnt", "Ignites TNT for you"); + } + + @Override + public void onActivate() { + ignited = false; + messaged = false; + } + + @Override + public void onDeactivate() { + ticks = 0; + } + + @EventHandler + private void onTick(TickEvent.Post event) { + if (ticks <= 0) { + // Clear and get tnt blocks + blocks.clear(); + for (BlockPos blockPos : BlockUtils.getSphere(mc.player.getBlockPos(), range.get(), range.get())) { + bp.set(blockPos); + if (mc.world.getBlockState(blockPos).getBlock() instanceof TntBlock) blocks.add(bp); + } + + // Make sure there are TNTs around us + if (blocks.size() <= 0) { + + // If already ignited and turnOff.get() + if (turnOff.get() && ignited) { + toggle(); + return; + } + + // If we haven't warned yet + if (!messaged) { + error("No TNT in range"); + messaged = true; + } + return; + } else messaged = false; + + // Sort based on closest tnt + blocks.sort(Comparator.comparingDouble(PlayerUtils::distanceTo)); + + // Get slot + slot = getSlot(); + if (slot == -1) { + error("No flint and steel in hotbar"); + return; + } + + // Ignition + bp.set(blocks.get(0)); + ignite(bp, slot); + + // Reset ticks + ticks = delay.get(); + } else ticks--; + } + + private void ignite(BlockPos pos, int slot) { + // Set slots + preSlot = mc.player.inventory.selectedSlot; + mc.player.inventory.selectedSlot = slot; + + // Ignited the tnt + ActionResult result = mc.interactionManager.interactBlock(mc.player, mc.world, Hand.MAIN_HAND, new BlockHitResult(new Vec3d(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5), Direction.UP, pos, true)); + if (result == ActionResult.CONSUME || result == ActionResult.SUCCESS) ignited = true; + + // Reset slot + mc.player.inventory.selectedSlot = preSlot; + } + + private int getSlot() { + return InvUtils.findItemInHotbar(item -> item.getItem() instanceof FlintAndSteelItem && (antiBreak.get() && (item.getMaxDamage() - item.getDamage()) > 10)); + } + + private void setBpToVec3d(Vec3d pos) { + bp.set(pos.getX(), pos.getY(), pos.getZ()); + } +} \ No newline at end of file