diff --git a/src/main/java/me/rigamortis/seppuku/impl/module/world/NukerModule.java b/src/main/java/me/rigamortis/seppuku/impl/module/world/NukerModule.java index b483bb1..78777e8 100644 --- a/src/main/java/me/rigamortis/seppuku/impl/module/world/NukerModule.java +++ b/src/main/java/me/rigamortis/seppuku/impl/module/world/NukerModule.java @@ -16,24 +16,36 @@ import net.minecraft.client.Minecraft; import net.minecraft.init.Blocks; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; +import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; import team.stiff.pomelo.impl.annotated.handler.annotation.Listener; +import java.util.HashMap; +import java.util.Map; + /** * Author Seth * 6/10/2019 @ 2:31 PM. */ public final class NukerModule extends Module { - public final Value mode = new Value("Mode", new String[]{"Mode", "M"}, "The nuker mode to use.", Mode.SELECTION); + public final Value mode = new Value("Mode", new String[]{"M"}, "The nuker mode to use.", Mode.SELECTION); + public final Value mineMode = new Value("MineMode", new String[]{"MM"}, "The way that nuker mines blocks", MineMode.NORMAL); public final Value distance = new Value("Distance", new String[]{"Dist", "D"}, "Maximum distance in blocks the nuker will reach", 4.5f, 0.0f, 5.0f, 0.1f); public final Value fixed = new Value("FixedDistance", new String[]{"Fixed", "fdist", "F"}, "Use vertical and horizontal distances in blocks instead of distances relative to the camera", false); public final Value vDistance = new Value("VerticalDistance", new String[]{"Vertical", "vdist", "VD"}, "Maximum vertical distance in blocks the nuker will reach", 4.5f, 0.0f, 5.0f, 0.1f); public final Value hDistance = new Value("HorizontalDistance", new String[]{"Horizontal", "hist", "HD"}, "Maximum horizontal distance in blocks the nuker will reach", 3f, 0.0f, 5.0f, 0.1f); + + public final Value timeout = new Value("Timeout", new String[]{"TO, t"}, "How long to wait (in ms) until trying to break a specific block again (PACKET Mode)", 1000, 0, Integer.MAX_VALUE, 1); + public final Value minMineSpeed = new Value("MinMineSpeed", new String[]{"Min", "Speed", "MineSpeed"}, "How fast you should be able to mine a block for nuker to attempt to mine it (0-1, 0 to allow all blocks, 1 to only allow instantly minable blocks)", 0.2f, 0f, 1.0f, 0.1f); + private final RotationTask rotationTask = new RotationTask("NukerTask", 2); + private Block selected = null; private BlockPos currentPos = null; + private Map attemptedBreaks = new HashMap<>(); + public NukerModule() { super("Nuker", new String[]{"Nuke"}, "Automatically mines blocks within reach", "NONE", -1, ModuleType.WORLD); } @@ -63,67 +75,63 @@ public final class NukerModule extends Module { switch (event.getStage()) { case PRE: - this.currentPos = null; + if (this.mineMode.getValue() == MineMode.PACKET) { + // PACKET mode does not need to rotate. The few servers it works on probably don't care about rotation. + // It also tries to break more than one block per event, and I am not sure how to handle that using the + // rotation task. - switch (this.mode.getValue()) { - case SELECTION: - this.currentPos = this.getClosestBlock(true); - break; - case ALL: - this.currentPos = this.getClosestBlock(false); - break; - } + } else { + this.currentPos = this.getClosestBlock(); - if (this.currentPos != null) { - Seppuku.INSTANCE.getRotationManager().startTask(this.rotationTask); - if (this.rotationTask.isOnline()) { - final float[] angle = MathUtil.calcAngle(mc.player.getPositionEyes(mc.getRenderPartialTicks()), new Vec3d(this.currentPos.getX() + 0.5f, this.currentPos.getY() + 0.5f, this.currentPos.getZ() + 0.5f)); - Seppuku.INSTANCE.getRotationManager().setPlayerRotations(angle[0], angle[1]); + if (this.currentPos != null) { + Seppuku.INSTANCE.getRotationManager().startTask(this.rotationTask); + if (this.rotationTask.isOnline()) { + final float[] angle = MathUtil.calcAngle(mc.player.getPositionEyes(mc.getRenderPartialTicks()), new Vec3d(this.currentPos.getX() + 0.5f, this.currentPos.getY() + 0.5f, this.currentPos.getZ() + 0.5f)); + Seppuku.INSTANCE.getRotationManager().setPlayerRotations(angle[0], angle[1]); + } } } + break; case POST: if (this.mode.getValue().equals(Mode.CREATIVE)) { if (mc.player.capabilities.isCreativeMode) { /* the amazing creative 'nuker' straight from the latch hacked client */ - for (double y = Math.round(mc.player.posY - 1) + this.vDistance.getValue(); y > Math.round(mc.player.posY - 1); y -= 1.0D) { - for (double x = mc.player.posX - this.hDistance.getValue(); x < mc.player.posX + this.hDistance.getValue(); x += 1.0D) { - for (double z = mc.player.posZ - this.hDistance.getValue(); z < mc.player.posZ + this.hDistance.getValue(); z += 1.0D) { - final BlockPos blockPos = new BlockPos(x, y, z); - final Block block = BlockUtil.getBlock(blockPos); - if (block == Blocks.AIR || !mc.world.getBlockState(blockPos).isFullBlock()) - continue; + // TODO: Test moving to the iterable didn't break this + Iterable itr = getBoxIterable(); + for (BlockPos blockPos : itr) { + final Block block = BlockUtil.getBlock(blockPos); + if (block == Blocks.AIR || !mc.world.getBlockState(blockPos).isFullBlock()) + continue; - final Vec3d eyesPos = new Vec3d(mc.player.posX, mc.player.posY + mc.player.getEyeHeight(), mc.player.posZ); - final Vec3d posVec = new Vec3d(blockPos).add(0.5f, 0.5f, 0.5f); - double distanceSqPosVec = eyesPos.squareDistanceTo(posVec); + final Vec3d eyesPos = new Vec3d(mc.player.posX, mc.player.posY + mc.player.getEyeHeight(), mc.player.posZ); + final Vec3d posVec = new Vec3d(blockPos).add(0.5f, 0.5f, 0.5f); + double distanceSqPosVec = eyesPos.squareDistanceTo(posVec); - for (EnumFacing side : EnumFacing.values()) { - final Vec3d hitVec = posVec.add(new Vec3d(side.getDirectionVec()).scale(0.5f)); - double distanceSqHitVec = eyesPos.squareDistanceTo(hitVec); + for (EnumFacing side : EnumFacing.values()) { + final Vec3d hitVec = posVec.add(new Vec3d(side.getDirectionVec()).scale(0.5f)); + double distanceSqHitVec = eyesPos.squareDistanceTo(hitVec); - // check if hitVec is within range (6 blocks) - if (distanceSqHitVec > 36) - continue; + // check if hitVec is within range (6 blocks) + if (distanceSqHitVec > 36) + continue; - // check if side is facing towards player - if (distanceSqHitVec >= distanceSqPosVec) - continue; + // check if side is facing towards player + if (distanceSqHitVec >= distanceSqPosVec) + continue; - // face block - final float[] rotations = EntityUtil.getRotations(hitVec.x, hitVec.y, hitVec.z); - Seppuku.INSTANCE.getRotationManager().setPlayerRotations(rotations[0], rotations[1]); + // face block + final float[] rotations = EntityUtil.getRotations(hitVec.x, hitVec.y, hitVec.z); + Seppuku.INSTANCE.getRotationManager().setPlayerRotations(rotations[0], rotations[1]); - // damage block - if (mc.playerController.onPlayerDamageBlock(blockPos, side)) { - mc.player.swingArm(EnumHand.MAIN_HAND); - } - } + // damage block + if (mc.playerController.onPlayerDamageBlock(blockPos, side)) { + mc.player.swingArm(EnumHand.MAIN_HAND); } } } } - } else { + } else if (this.mineMode.getValue() != MineMode.PACKET) { if (this.currentPos != null) { if (this.rotationTask.isOnline()) { if (SpeedMineModule.autoPos != null) { @@ -160,74 +168,77 @@ public final class NukerModule extends Module { private boolean canBreak(BlockPos pos) { final IBlockState blockState = Minecraft.getMinecraft().world.getBlockState(pos); final Block block = blockState.getBlock(); - return block.getBlockHardness(blockState, Minecraft.getMinecraft().world, pos) != -1; + return block.getBlockHardness(blockState, Minecraft.getMinecraft().world, pos) >= minMineSpeed.getValue(); } - private BlockPos getClosestBlock(boolean selection) { + private boolean shouldBreak(BlockPos pos) { final Minecraft mc = Minecraft.getMinecraft(); - BlockPos ret = null; + // TODO: Might want to double check that the block is within the distance value (getAllInBox is generous) + + // TODO: Replace SELECTION with a filter? + if (this.mode.getValue() == Mode.SELECTION) { + if (this.selected != null && !mc.world.getBlockState(pos).getBlock().equals(this.selected)) { + return false; + } + } + + return mc.world.getBlockState(pos).getBlock() != Blocks.AIR && + !(mc.world.getBlockState(pos).getBlock() instanceof BlockLiquid) && + this.canBreak(pos) && + !pos.equals(SpeedMineModule.autoPos); + } + + private Iterable getBoxIterable () { + final Minecraft mc = Minecraft.getMinecraft(); + AxisAlignedBB bb; if (this.fixed.getValue()) { - float maxVDist = this.vDistance.getValue(); - float maxHDist = this.hDistance.getValue(); - for (float x = 0; x <= maxHDist; x++) { - for (float y = 0; y <= maxVDist; y++) { - for (float z = 0; z <= maxHDist; z++) { - for (int revX = 0; revX <= 1; revX++, x = -x) { - for (int revZ = 0; revZ <= 1; revZ++, z = -z) { - final BlockPos pos = new BlockPos(mc.player.posX + x, mc.player.posY + y, mc.player.posZ + z); - if (pos.equals(SpeedMineModule.autoPos)) { - continue; - } - if ((mc.world.getBlockState(pos).getBlock() != Blocks.AIR && - !(mc.world.getBlockState(pos).getBlock() instanceof BlockLiquid)) && - this.canBreak(pos)) { - if (selection) { - if ((this.selected == null) || !mc.world.getBlockState(pos).getBlock().equals(this.selected)) { - continue; - } - } - - ret = pos; - } - } - } - } - } - } + bb = new AxisAlignedBB( + (int) mc.player.posX - hDistance.getValue(), + (int) mc.player.posY - vDistance.getValue(), + (int) mc.player.posZ - hDistance.getValue(), + (int) mc.player.posX + hDistance.getValue(), + (int) mc.player.posY + vDistance.getValue(), + (int) mc.player.posZ + hDistance.getValue()); } else { - float maxDist = this.distance.getValue(); - for (float x = maxDist; x >= -maxDist; x--) { - for (float y = maxDist; y >= -maxDist; y--) { - for (float z = maxDist; z >= -maxDist; z--) { - final BlockPos pos = new BlockPos(mc.player.posX + x, mc.player.posY + y, mc.player.posZ + z); - final double dist = mc.player.getDistance(pos.getX(), pos.getY(), pos.getZ()); - if (pos.equals(SpeedMineModule.autoPos)) { - continue; - } - if (dist <= maxDist && (mc.world.getBlockState(pos).getBlock() != Blocks.AIR && !(mc.world.getBlockState(pos).getBlock() instanceof BlockLiquid)) && canBreak(pos)) { - if (selection) { - if ((this.selected == null) || !mc.world.getBlockState(pos).getBlock().equals(this.selected)) { - continue; - } - } + bb = new AxisAlignedBB( + (int) mc.player.posX - distance.getValue(), + (int) mc.player.posY - distance.getValue(), + (int) mc.player.posZ - distance.getValue(), + (int) mc.player.posX + distance.getValue(), + (int) mc.player.posY + distance.getValue(), + (int) mc.player.posZ + distance.getValue()); + } - if (pos.getY() < mc.player.posY) - continue; + return BlockPos.getAllInBox((int) bb.minX, (int) bb.minY, (int) bb.minZ, (int) bb.maxX, (int) bb.maxY, (int) bb.maxZ); + } - maxDist = (float) dist; - ret = pos; - } - } + private BlockPos getClosestBlock() { + final Minecraft mc = Minecraft.getMinecraft(); + Iterable itr = getBoxIterable(); + + BlockPos closest = null; + double closestDist = Double.POSITIVE_INFINITY; + for (BlockPos pos : itr) { + double dist = pos.distanceSqToCenter(mc.player.posX, mc.player.getEyeHeight(), mc.player.posZ); + + if (shouldBreak(pos)) { + if (dist < closestDist) { + closestDist = dist; + closest = pos; } } } - return ret; + + return closest; } private enum Mode { SELECTION, ALL, CREATIVE } + private enum MineMode { + NORMAL, PACKET + } }