Fix AutoTNT

This commit is contained in:
StormyBytes
2021-06-03 22:55:39 +07:00
3 changed files with 30 additions and 39 deletions

View File

@@ -29,7 +29,7 @@ public class MeteorRejectsAddon extends MeteorAddon {
modules.add(new AutoExtinguish()); modules.add(new AutoExtinguish());
modules.add(new AutoHighway()); modules.add(new AutoHighway());
modules.add(new AutoPot()); modules.add(new AutoPot());
// modules.add(new AutoTNT()); modules.add(new AutoTNT());
modules.add(new ColorSigns()); modules.add(new ColorSigns());
modules.add(new Confuse()); modules.add(new Confuse());
modules.add(new Dolphin()); modules.add(new Dolphin());

View File

@@ -1,5 +1,6 @@
package cloudburst.rejects.modules; package cloudburst.rejects.modules;
import cloudburst.rejects.MeteorRejectsAddon;
import cloudburst.rejects.utils.WorldUtils; import cloudburst.rejects.utils.WorldUtils;
import meteordevelopment.orbit.EventHandler; import meteordevelopment.orbit.EventHandler;
import minegame159.meteorclient.events.world.TickEvent; import minegame159.meteorclient.events.world.TickEvent;
@@ -10,7 +11,7 @@ import minegame159.meteorclient.settings.SettingGroup;
import minegame159.meteorclient.systems.modules.Module; import minegame159.meteorclient.systems.modules.Module;
import minegame159.meteorclient.utils.player.InvUtils; import minegame159.meteorclient.utils.player.InvUtils;
import minegame159.meteorclient.utils.player.PlayerUtils; import minegame159.meteorclient.utils.player.PlayerUtils;
import net.minecraft.block.TntBlock; import net.minecraft.block.Blocks;
import net.minecraft.item.FlintAndSteelItem; import net.minecraft.item.FlintAndSteelItem;
import net.minecraft.util.ActionResult; import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand; import net.minecraft.util.Hand;
@@ -19,10 +20,9 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction; import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
import cloudburst.rejects.MeteorRejectsAddon;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Comparator; import java.util.Comparator;
import java.util.List;
public class AutoTNT extends Module { public class AutoTNT extends Module {
private final SettingGroup sgGeneral = settings.getDefaultGroup(); private final SettingGroup sgGeneral = settings.getDefaultGroup();
@@ -58,8 +58,7 @@ public class AutoTNT extends Module {
); );
private final ArrayList<BlockPos> blocks = new ArrayList<>(); private final ArrayList<BlockPos> blocks = new ArrayList<>();
private final BlockPos.Mutable bp = new BlockPos.Mutable(); private boolean ignited;
private boolean ignited, messaged;
private int ticks = 0; private int ticks = 0;
private int preSlot, slot; private int preSlot, slot;
@@ -70,7 +69,6 @@ public class AutoTNT extends Module {
@Override @Override
public void onActivate() { public void onActivate() {
ignited = false; ignited = false;
messaged = false;
} }
@Override @Override
@@ -81,44 +79,43 @@ public class AutoTNT extends Module {
@EventHandler @EventHandler
private void onTick(TickEvent.Post event) { private void onTick(TickEvent.Post event) {
if (ticks <= 0) { if (ticks <= 0) {
// Clear and get tnt blocks // Clear and get tnt blocks
blocks.clear(); blocks.clear();
for (BlockPos blockPos : WorldUtils.getSphere(mc.player.getBlockPos(), range.get(), range.get())) { List<BlockPos> searchBlocks = WorldUtils.getSphere(mc.player.getBlockPos(), range.get(), range.get());
bp.set(blockPos); for (BlockPos blockPos : searchBlocks) {
if (mc.world.getBlockState(blockPos).getBlock() instanceof TntBlock) blocks.add(bp); if (mc.world.getBlockState(blockPos).getBlock() == Blocks.TNT) blocks.add(blockPos);
} }
// Make sure there are TNTs around us
// If there isn't any tnt
if (blocks.size() <= 0) { if (blocks.size() <= 0) {
// If already ignited and turnOff.get() // Give a warning
error("No TNT in range");
// If we should just turn off after igniting
if (turnOff.get() && ignited) { if (turnOff.get() && ignited) {
toggle(); toggle();
return;
} }
// If we haven't warned yet
if (!messaged) {
error("No TNT in range");
messaged = true;
}
return; return;
} else messaged = false; }
// Sort based on closest tnt // Sort based on closest tnt
blocks.sort(Comparator.comparingDouble(PlayerUtils::distanceTo)); blocks.sort(Comparator.comparingDouble(PlayerUtils::distanceTo));
// Get slot // Get slot
slot = getSlot(); slot = getFlintAndSteelSlot();
if (slot == -1) { if (slot == -1) {
error("No flint and steel in hotbar"); error("No flint and steel in hotbar");
toggle();
return; return;
} }
// Ignition // Ignition
bp.set(blocks.get(0)); ignite(blocks.get(0), slot);
ignite(bp, slot);
// Reset ticks // Reset ticks
ticks = delay.get(); ticks = delay.get();
@@ -131,22 +128,15 @@ public class AutoTNT extends Module {
mc.player.inventory.selectedSlot = slot; mc.player.inventory.selectedSlot = slot;
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));
// Ignited the tnt // ActionResult result = mc.interactionManager.interactBlock(mc.player, mc.world, Hand.MAIN_HAND, new BlockHitResult(new Vec3d(pos.getX(), pos.getY(), pos.getZ()), Direction.UP, pos, false));
//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));
ActionResult result = mc.interactionManager.interactBlock(mc.player, mc.world, Hand.MAIN_HAND, new BlockHitResult(new Vec3d(pos.getX(), pos.getY(), pos.getZ()), Direction.UP, pos, false));
if (result == ActionResult.CONSUME || result == ActionResult.SUCCESS) ignited = true; if (result == ActionResult.CONSUME || result == ActionResult.SUCCESS) ignited = true;
// Reset slot // Reset slot
mc.player.inventory.selectedSlot = preSlot; mc.player.inventory.selectedSlot = preSlot;
} }
private int getSlot() { private int getFlintAndSteelSlot() {
return InvUtils.findItemInHotbar(item -> item.getItem() instanceof FlintAndSteelItem && (antiBreak.get() && (item.getMaxDamage() - item.getDamage()) > 10)); 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());
}
}

View File

@@ -3,7 +3,8 @@ package cloudburst.rejects.utils;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.MathHelper;
import java.util.*; import java.util.ArrayList;
import java.util.List;
public class WorldUtils { public class WorldUtils {
private static final ArrayList<BlockPos> blocks = new ArrayList<>(); private static final ArrayList<BlockPos> blocks = new ArrayList<>();
@@ -23,10 +24,10 @@ public class WorldUtils {
return blocks; return blocks;
} }
public static double distanceBetween(BlockPos blockPos1, BlockPos blockPos2) { public static double distanceBetween(BlockPos pos1, BlockPos pos2) {
double d = blockPos1.getX() - blockPos2.getX(); double d = pos1.getX() - pos2.getX();
double e = blockPos1.getY() - blockPos2.getY(); double e = pos1.getY() - pos2.getY();
double f = blockPos1.getZ() - blockPos2.getZ(); double f = pos1.getZ() - pos2.getZ();
return MathHelper.sqrt(d * d + e * e + f * f); return MathHelper.sqrt(d * d + e * e + f * f);
} }
} }