From c713a430b4d3a8694638981ec957fb82ebcc9d1a Mon Sep 17 00:00:00 2001 From: Christian Date: Wed, 19 Aug 2020 04:10:07 +0200 Subject: [PATCH 001/390] Added HighwayTools Full automated auto placing obsidian for a highway. Replacing wrong blocks. --- .../kami/module/modules/misc/HighwayTools.kt | 601 ++++++++++++++++++ 1 file changed, 601 insertions(+) create mode 100644 src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt new file mode 100644 index 0000000000..8525854819 --- /dev/null +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -0,0 +1,601 @@ +package me.zeroeightsix.kami.module.modules.misc + +import baritone.api.BaritoneAPI +import baritone.api.pathing.goals.GoalXZ +import com.mojang.realmsclient.gui.ChatFormatting +import me.zeroeightsix.kami.KamiMod +import me.zeroeightsix.kami.event.events.RenderEvent +import me.zeroeightsix.kami.module.Module +import me.zeroeightsix.kami.module.modules.player.Freecam +import me.zeroeightsix.kami.module.modules.player.NoBreakAnimation +import me.zeroeightsix.kami.setting.Settings +import me.zeroeightsix.kami.util.* +import me.zeroeightsix.kami.util.colourUtils.ColourHolder +import net.minecraft.block.* +import net.minecraft.client.audio.PositionedSoundRecord +import net.minecraft.entity.item.EntityItem +import net.minecraft.entity.item.EntityXPOrb +import net.minecraft.init.SoundEvents +import net.minecraft.item.ItemBlock +import net.minecraft.item.ItemStack +import net.minecraft.network.play.client.CPacketEntityAction +import net.minecraft.network.play.client.CPacketPlayerDigging +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 java.util.concurrent.ConcurrentHashMap +import java.util.concurrent.Executors +import java.util.concurrent.TimeUnit +import kotlin.math.roundToInt + +/** + * @author Avanatiker + * @since 15/08/2020 + */ +@Module.Info( + name = "HighwayTools", + description = "Better High-ways for the greater good.", + category = Module.Category.MISC +) +class HighwayTools : Module() { + private val mode = register(Settings.e("Mode", Mode.HIGHWAY)) + private val baritoneModee = register(Settings.b("Baritone", true)) + private val infoMessage = register(Settings.b("Logs", true)) + private val blocksPerTick = register(Settings.integerBuilder("BlocksPerTick").withMinimum(1).withValue(1).withMaximum(9).build()) + private val tickDelay = register(Settings.integerBuilder("TickDelay").withMinimum(0).withValue(1).withMaximum(10).build()) + private val rotate = register(Settings.b("Rotate", true)) + private val filled = register(Settings.b("Filled", true)) + private val outline = register(Settings.b("Outline", true)) + private val aFilled = register(Settings.integerBuilder("FilledAlpha").withMinimum(0).withValue(31).withMaximum(255).withVisibility { filled.value }.build()) + private val aOutline = register(Settings.integerBuilder("OutlineAlpha").withMinimum(0).withValue(127).withMaximum(255).withVisibility { outline.value }.build()) + + private var offsetStep = 0 + private var delayStep = 0 + private var blocksDonePlacing = 0 + private var playerHotbarSlot = -1 + private var lastHotbarSlot = -1 + private var isSneaking = false + private var totalTicksRunning = 0 + private var firstRun = false + private var missingObiDisable = false + private var ismining = false + private var nextBlockPos = BlockPos(0,0,0) + private var currentBlockPos = BlockPos(0,0,0) + private val directions = listOf("North", "East", "South", "West") + + private var buildDirectionSaved = 0 + private var buildDirectionCoordinateSaved = 0.0 + private var buildDirectionCoordinateSavedY = 0.0 + private var offsetPattern = arrayOfNulls(0) + private var maxSteps = 0 + + private var totalBlocksPlaced = 0 + private var totalBlocksDestroyed = 0 + private var totalBlocksDistanceWent = 0 + + private var placementPendingBlockTiles = ConcurrentHashMap() + private var placedBlocksIteration = ConcurrentHashMap() + private var pendingWrongBlocks = ConcurrentHashMap() + + override fun onEnable() { + if (mc.player == null) { + disable() + return + } + firstRun = true + + playerHotbarSlot = mc.player.inventory.currentItem + lastHotbarSlot = -1 + buildDirectionSaved = getPlayerDirection() + buildDirectionCoordinateSavedY = mc.player.positionVector.y + if (buildDirectionSaved == 0 || buildDirectionSaved == 2) { + buildDirectionCoordinateSaved = mc.player.positionVector.x + } + else { + buildDirectionCoordinateSaved = mc.player.positionVector.z + } + + if (mode.value == Mode.FLAT) { + offsetPattern = OffsetsBlocks.FLAT + maxSteps = OffsetsBlocks.FLAT.size + } + if (mode.value == Mode.HIGHWAY) { + if (buildDirectionSaved == 0) { + offsetPattern = OffsetsBlocks.HIGHWAY_0 + maxSteps = OffsetsBlocks.HIGHWAY_0.size + } + else if (buildDirectionSaved == 1) { + offsetPattern = OffsetsBlocks.HIGHWAY_1 + maxSteps = OffsetsBlocks.HIGHWAY_1.size + } + else if (buildDirectionSaved == 2) { + offsetPattern = OffsetsBlocks.HIGHWAY_2 + maxSteps = OffsetsBlocks.HIGHWAY_2.size + } + else if (buildDirectionSaved == 3) { + offsetPattern = OffsetsBlocks.HIGHWAY_3 + maxSteps = OffsetsBlocks.HIGHWAY_3.size + } + } + + MessageSendHelper.sendChatMessage("$chatName Module started." + + "\n §9> §rSelected direction: §a" + directions[getPlayerDirection()] + "§r" + + "\n §9> §rSnap to coordinate: §a" + buildDirectionCoordinateSaved.roundToInt() + "§r" + + "\n §9> §rBaritone mode: §a" + baritoneModee.value + "§r") + } + + override fun onDisable() { + if (mc.player == null) return + + // load initial player hand + if (lastHotbarSlot != playerHotbarSlot && playerHotbarSlot != -1) { + mc.player.inventory.currentItem = playerHotbarSlot + } + if (isSneaking) { + mc.player.connection.sendPacket(CPacketEntityAction(mc.player, CPacketEntityAction.Action.STOP_SNEAKING)) + isSneaking = false + } + playerHotbarSlot = -1 + lastHotbarSlot = -1 + missingObiDisable = false + BaritoneAPI.getProvider().primaryBaritone.pathingBehavior.cancelEverything() + MessageSendHelper.sendChatMessage("$chatName Module stopped." + + "\n §9> §rPlaced obsidian: §a" + totalBlocksPlaced + "§r" + + "\n §9> §rDestroyed blocks: §a" + totalBlocksDestroyed + "§r" + + "\n §9> §rDistance: §a" + totalBlocksDistanceWent + "§r") + totalBlocksPlaced = 0 + totalBlocksDestroyed = 0 + totalBlocksDistanceWent = 0 + } + + override fun onUpdate() { + if (mc.player == null || KamiMod.MODULE_MANAGER.isModuleEnabled(Freecam::class.java)) { + return + } + + if (!firstRun) { + delayStep = if (delayStep < tickDelay.value) { + delayStep++ + return + } else { + 0 + } + } + + if (firstRun) { + firstRun = false + if (findObiInHotbar() == -1) { + missingObiDisable = true + } + } + + var blocksPlaced = 0 + + blocksDonePlacing = 0 + + // get workload and render + placementPendingBlockTiles.clear() + placedBlocksIteration.clear() + pendingWrongBlocks.clear() + for(x in 0 until maxSteps) { + val offsetPos = BlockPos(offsetPattern[x]) + val snappedCoords = BlockPos(mc.player.positionVector) + snappedCoords.y = buildDirectionCoordinateSavedY.toInt() + if (getPlayerDirection() == 0 || getPlayerDirection() == 2) { + snappedCoords.x = buildDirectionCoordinateSaved.toInt() + } + else if (getPlayerDirection() == 1 || getPlayerDirection() == 3) { + snappedCoords.z = buildDirectionCoordinateSaved.toInt() + } + val targetPos = BlockPos(snappedCoords).add(offsetPos.x, offsetPos.y, offsetPos.z) + if (x == 1) { + currentBlockPos = nextBlockPos + nextBlockPos = targetPos + } + val block = mc.world.getBlockState(targetPos).block + if (block is BlockAir) { + placementPendingBlockTiles[targetPos] = ColourHolder(35, 188, 254) + } + if (block is BlockObsidian) { + placementPendingBlockTiles[targetPos] = ColourHolder(50, 50, 50) + blocksDonePlacing++ + } + } + + // actually do the work + while (blocksPlaced < blocksPerTick.value) { + if (offsetStep >= maxSteps) { + offsetStep = 0 + break + } + val offsetPos = BlockPos(offsetPattern[offsetStep]) + var targetPos = BlockPos(mc.player.positionVector).add(offsetPos.x, offsetPos.y, offsetPos.z) + if (mode.value == Mode.HIGHWAY) { + val snappedCoords = BlockPos(mc.player.positionVector) + snappedCoords.y = buildDirectionCoordinateSavedY.toInt() + if (getPlayerDirection() == 0 || getPlayerDirection() == 2) { + snappedCoords.x = buildDirectionCoordinateSaved.toInt() + } + else if (getPlayerDirection() == 1 || getPlayerDirection() == 3) { + snappedCoords.z = buildDirectionCoordinateSaved.toInt() + } + targetPos = BlockPos(snappedCoords).add(offsetPos.x, offsetPos.y, offsetPos.z) + } + if (placeBlock(targetPos)) { + placedBlocksIteration[targetPos] = ColourHolder(53, 222, 66) + blocksPlaced++ + totalBlocksPlaced++ + } + offsetStep++ + } + + // check if row is ready for moving on + if (baritoneModee.value && (blocksDonePlacing == maxSteps)) { + moveOneBlock() + } + + if (blocksPlaced > 0) { + if (lastHotbarSlot != playerHotbarSlot && playerHotbarSlot != -1) { + mc.player.inventory.currentItem = playerHotbarSlot + lastHotbarSlot = playerHotbarSlot + } + if (isSneaking) { + mc.player.connection.sendPacket(CPacketEntityAction(mc.player, CPacketEntityAction.Action.STOP_SNEAKING)) + isSneaking = false + } + } + + totalTicksRunning++ + + if (missingObiDisable && infoMessage.value) { + missingObiDisable = false + MessageSendHelper.sendChatMessage("$chatName " + ChatFormatting.RED + "Disabled" + ChatFormatting.RESET + ", Obsidian missing!") + disable() + } + } + + private fun getPlayerDirection(): Int { + val yaw = (mc.player.rotationYaw % 360 + 360) % 360 + if (yaw >= 135 && yaw < 225) { + return 0 //NORTH + } + else if (yaw >= 225 && yaw < 315) { + return 1 //EAST + } + else if (yaw >= 315 || yaw < 45) { + return 2 //SOUTH + } + else if (yaw >= 45 && yaw < 135){ + return 3 //WEST + } + else { + return -1 + } + } + + private fun placeBlock(pos: BlockPos): Boolean { + // check if block is already placed + val block = mc.world.getBlockState(pos).block + if (block !is BlockAir && block !is BlockLiquid) { + if (block !is BlockObsidian) { + pendingWrongBlocks[pos] = ColourHolder(222, 0, 0) + val backupYaw = mc.player.rotationYaw + val backupPitch = mc.player.rotationPitch + mineBlock(pos, true) + Executors.newSingleThreadScheduledExecutor().schedule({ + mineBlock(pos, false) + mc.player.rotationYaw = backupYaw + mc.player.rotationPitch = backupPitch + totalBlocksDestroyed++ + }, tickDelay.value * 50L, TimeUnit.MILLISECONDS) + blocksDonePlacing-- + } + return false + } + + // check if entity blocks placing + for (entity in mc.world.getEntitiesWithinAABBExcludingEntity(null, AxisAlignedBB(pos))) { + if (entity !is EntityItem && entity !is EntityXPOrb) { + return false + } + } + val side = getPlaceableSide(pos) ?: return false + + // check if we have a block adjacent to blockpos to click at + val neighbour = pos.offset(side) + val opposite = side.opposite + + // check if neighbor can be right clicked + if (!BlockUtils.canBeClicked(neighbour)) { + return false + } + + val hitVec = Vec3d(neighbour).add(0.5, 0.5, 0.5).add(Vec3d(opposite.directionVec).scale(0.5)) + val neighbourBlock = mc.world.getBlockState(neighbour).block + val obiSlot = findObiInHotbar() + + if (obiSlot == -1) { + missingObiDisable = true + return false + } + if (lastHotbarSlot != obiSlot) { + mc.player.inventory.currentItem = obiSlot + lastHotbarSlot = obiSlot + } + if (!isSneaking && BlockUtils.blackList.contains(neighbourBlock) || BlockUtils.shulkerList.contains(neighbourBlock)) { + mc.player.connection.sendPacket(CPacketEntityAction(mc.player, CPacketEntityAction.Action.START_SNEAKING)) + isSneaking = true + } + if (rotate.value) { + BlockUtils.faceVectorPacketInstant(hitVec) + } + + mc.playerController.processRightClickBlock(mc.player, mc.world, neighbour, opposite, hitVec, EnumHand.MAIN_HAND) + mc.player.swingArm(EnumHand.MAIN_HAND) + mc.rightClickDelayTimer = 4 + + if (KamiMod.MODULE_MANAGER.isModuleEnabled(NoBreakAnimation::class.java)) { + KamiMod.MODULE_MANAGER.getModuleT(NoBreakAnimation::class.java).resetMining() + } + return true + } + + private fun mineBlock(pos: BlockPos, pre: Boolean) { + // get mining tool in mainhand + if (InventoryUtils.getSlotsHotbar(278) == null && InventoryUtils.getSlotsNoHotbar(278) != null) { + InventoryUtils.moveToHotbar(278, 130, (tickDelay.value * 16).toLong()) + return + } else if (InventoryUtils.getSlots(0, 35, 278) == null) { + MessageSendHelper.sendChatMessage("$chatName No pickaxe was found in inventory, disabling.") + mc.getSoundHandler().playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) + this.disable() + return + } + InventoryUtils.swapSlotToItem(278) + lookAtBlock(pos) + + /* Packet mining lol */ + if (pre) { + mc.connection!!.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, pos, mc.objectMouseOver.sideHit)) + //if (state != AutoObsidian.State.SEARCHING) state = AutoObsidian.State.MINING else searchingState = AutoObsidian.SearchingState.MINING + } else { + mc.connection!!.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, pos, mc.objectMouseOver.sideHit)) + } + mc.player.swingArm(EnumHand.MAIN_HAND) + } + + // just experimental + private fun mineBlockBaritone(pos: BlockPos) { + ismining = true + val bapi = BaritoneAPI.getProvider().getPrimaryBaritone().getCommandManager() + bapi.execute("sel 1 " + pos.x + " " + pos.y + " " + pos.z) + bapi.execute("sel 2 " + pos.x + " " + pos.y + " " + pos.z) + bapi.execute("sel ca") + bapi.execute("sel clear") + BaritoneAPI.getProvider().primaryBaritone.customGoalProcess.setGoalAndPath(GoalXZ(nextBlockPos.getX(), nextBlockPos.getZ())) + ismining = false + } + + private fun moveOneBlock() { + // set head rotation to get max walking speed + if (getPlayerDirection() == 0) { + mc.player.rotationYaw = -180F + } + else if (getPlayerDirection() == 1) { + mc.player.rotationYaw = -90F + } + else if (getPlayerDirection() == 2) { + mc.player.rotationYaw = 0F + } else { + mc.player.rotationYaw = 90F + } + mc.player.rotationPitch = 0F + //move to next block pos + BaritoneAPI.getProvider().primaryBaritone.customGoalProcess.setGoalAndPath(GoalXZ(nextBlockPos.getX(), nextBlockPos.getZ())) + totalBlocksDistanceWent++ + } + + private fun lookAtBlock(pos: BlockPos) { + val vec3d = Vec3d((pos.x + 0.5) - mc.player.posX, pos.y - (mc.player.eyeHeight + mc.player.posY), (pos.z + 0.5) - mc.player.posZ) + val lookAt = EntityUtils.getRotationFromVec3d(vec3d) + mc.player.rotationYaw = lookAt[0].toFloat() + mc.player.rotationPitch = lookAt[1].toFloat() + } + + override fun onWorldRender(event: RenderEvent) { + if (mc.player == null) return + val side = GeometryMasks.Quad.ALL + val renderer = ESPRenderer(event.partialTicks) + renderer.aFilled = if (filled.value) aFilled.value else 0 + renderer.aOutline = if (outline.value) aOutline.value else 0 + if (!placementPendingBlockTiles.isEmpty()) { + for ((pos, colour) in placementPendingBlockTiles) { + renderer.add(pos, colour, side) + } + } + if (!placedBlocksIteration.isEmpty()) { + for ((pos, colour) in placedBlocksIteration) { + renderer.add(pos, colour, side) + } + } + if (!pendingWrongBlocks.isEmpty()) { + for ((pos, colour) in pendingWrongBlocks) { + renderer.add(pos, colour, side) + } + } + renderer.render() + } + + private fun findObiInHotbar(): Int { + // search blocks in hotbar + var slot = -1 + for (i in 0..8) { + // filter out non-block items + val stack = mc.player.inventory.getStackInSlot(i) + if (stack == ItemStack.EMPTY || stack.getItem() !is ItemBlock) { + continue + } + val block = (stack.getItem() as ItemBlock).block + if (block is BlockObsidian) { + slot = i + break + } + //else if (block is BlockNetherrack) { + // slot = i + // break + //} + } + return slot + } + + private enum class Mode { + FLAT, HIGHWAY + } + + private object Offsets_Space { + val HIGHWAY_0 = arrayOf( + Vec3d(0.0, -1.0, 0.0), + Vec3d(0.0, -1.0, -1.0), + Vec3d(-1.0, -1.0, -1.0), + Vec3d(1.0, -1.0, -1.0), + Vec3d(-2.0, -1.0, -1.0), + Vec3d(2.0, -1.0, -1.0), + Vec3d(-3.0, -1.0, -1.0), + Vec3d(3.0, -1.0, -1.0), + Vec3d(3.0, 0.0, -1.0), + Vec3d(-3.0, 0.0, -1.0) + ) + val HIGHWAY_1 = arrayOf( + Vec3d(0.0, -1.0, 0.0), + Vec3d(1.0, -1.0, 0.0), + Vec3d(1.0, -1.0, -1.0), + Vec3d(1.0, -1.0, 1.0), + Vec3d(1.0, -1.0, -2.0), + Vec3d(1.0, -1.0, 2.0), + Vec3d(1.0, -1.0, -3.0), + Vec3d(1.0, -1.0, 3.0), + Vec3d(1.0, 0.0, 3.0), + Vec3d(1.0, 0.0, -3.0) + ) + val HIGHWAY_2 = arrayOf( + Vec3d(0.0, -1.0, 0.0), + Vec3d(0.0, -1.0, 1.0), + Vec3d(-1.0, -1.0, 1.0), + Vec3d(1.0, -1.0, 1.0), + Vec3d(-2.0, -1.0, 1.0), + Vec3d(2.0, -1.0, 1.0), + Vec3d(-3.0, -1.0, 1.0), + Vec3d(3.0, -1.0, 1.0), + Vec3d(3.0, 0.0, 1.0), + Vec3d(-3.0, 0.0, 1.0) + ) + val HIGHWAY_3 = arrayOf( + Vec3d(0.0, -1.0, 0.0), + Vec3d(-1.0, -1.0, 0.0), + Vec3d(-1.0, -1.0, -1.0), + Vec3d(-1.0, -1.0, 1.0), + Vec3d(-1.0, -1.0, -2.0), + Vec3d(-1.0, -1.0, 2.0), + Vec3d(-1.0, -1.0, -3.0), + Vec3d(-1.0, -1.0, 3.0), + Vec3d(-1.0, 0.0, 3.0), + Vec3d(-1.0, 0.0, -3.0) + ) + } + + private object OffsetsBlocks { + val FLAT = arrayOf( + Vec3d(0.0, -1.0, 0.0), + Vec3d(1.0, -1.0, 0.0), + Vec3d(-1.0, -1.0, 0.0), + Vec3d(0.0, -1.0, 1.0), + Vec3d(0.0, -1.0, -1.0), + Vec3d(1.0, -1.0, 1.0), + Vec3d(-1.0, -1.0, -1.0), + Vec3d(1.0, -1.0, -1.0), + Vec3d(-1.0, -1.0, 1.0), + Vec3d(2.0, -1.0, 0.0), + Vec3d(-2.0, -1.0, 0.0), + Vec3d(0.0, -1.0, 2.0), + Vec3d(0.0, -1.0, -2.0), + Vec3d(1.0, -1.0, 2.0), + Vec3d(-1.0, -1.0, 2.0), + Vec3d(2.0, -1.0, -1.0), + Vec3d(2.0, -1.0, 1.0), + Vec3d(-2.0, -1.0, -1.0), + Vec3d(-2.0, -1.0, 1.0), + Vec3d(1.0, -1.0, -2.0), + Vec3d(-1.0, -1.0, -2.0), + Vec3d(2.0, -1.0, 2.0), + Vec3d(-2.0, -1.0, 2.0), + Vec3d(-2.0, -1.0, -2.0), + Vec3d(2.0, -1.0, -2.0) + ) + val HIGHWAY_0 = arrayOf( + Vec3d(0.0, -1.0, 0.0), + Vec3d(0.0, -1.0, -1.0), + Vec3d(-1.0, -1.0, -1.0), + Vec3d(1.0, -1.0, -1.0), + Vec3d(-2.0, -1.0, -1.0), + Vec3d(2.0, -1.0, -1.0), + Vec3d(-3.0, -1.0, -1.0), + Vec3d(3.0, -1.0, -1.0), + Vec3d(3.0, 0.0, -1.0), + Vec3d(-3.0, 0.0, -1.0) + ) + val HIGHWAY_1 = arrayOf( + Vec3d(0.0, -1.0, 0.0), + Vec3d(1.0, -1.0, 0.0), + Vec3d(1.0, -1.0, -1.0), + Vec3d(1.0, -1.0, 1.0), + Vec3d(1.0, -1.0, -2.0), + Vec3d(1.0, -1.0, 2.0), + Vec3d(1.0, -1.0, -3.0), + Vec3d(1.0, -1.0, 3.0), + Vec3d(1.0, 0.0, 3.0), + Vec3d(1.0, 0.0, -3.0) + ) + val HIGHWAY_2 = arrayOf( + Vec3d(0.0, -1.0, 0.0), + Vec3d(0.0, -1.0, 1.0), + Vec3d(-1.0, -1.0, 1.0), + Vec3d(1.0, -1.0, 1.0), + Vec3d(-2.0, -1.0, 1.0), + Vec3d(2.0, -1.0, 1.0), + Vec3d(-3.0, -1.0, 1.0), + Vec3d(3.0, -1.0, 1.0), + Vec3d(3.0, 0.0, 1.0), + Vec3d(-3.0, 0.0, 1.0) + ) + val HIGHWAY_3 = arrayOf( + Vec3d(0.0, -1.0, 0.0), + Vec3d(-1.0, -1.0, 0.0), + Vec3d(-1.0, -1.0, -1.0), + Vec3d(-1.0, -1.0, 1.0), + Vec3d(-1.0, -1.0, -2.0), + Vec3d(-1.0, -1.0, 2.0), + Vec3d(-1.0, -1.0, -3.0), + Vec3d(-1.0, -1.0, 3.0), + Vec3d(-1.0, 0.0, 3.0), + Vec3d(-1.0, 0.0, -3.0) + ) + } + + companion object { + private fun getPlaceableSide(pos: BlockPos): EnumFacing? { + for (side in EnumFacing.values()) { + val neighbour = pos.offset(side) + if (!mc.world.getBlockState(neighbour).block.canCollideCheck(mc.world.getBlockState(neighbour), false)) { + continue + } + val blockState = mc.world.getBlockState(neighbour) + if (!blockState.material.isReplaceable) { + return side + } + } + return null + } + } +} \ No newline at end of file From debcd588ffc5a876c3d5a35a885a4370ecde7009 Mon Sep 17 00:00:00 2001 From: Christian Date: Wed, 19 Aug 2020 23:46:06 +0200 Subject: [PATCH 002/390] Fix for Java SDK 12.0.2? Wtf --- src/main/java/me/zeroeightsix/kami/KamiMod.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/me/zeroeightsix/kami/KamiMod.java b/src/main/java/me/zeroeightsix/kami/KamiMod.java index f900c93d0e..440e5cb91c 100644 --- a/src/main/java/me/zeroeightsix/kami/KamiMod.java +++ b/src/main/java/me/zeroeightsix/kami/KamiMod.java @@ -18,6 +18,7 @@ import me.zeroeightsix.kami.gui.rgui.util.ContainerHelper; import me.zeroeightsix.kami.gui.rgui.util.Docking; import me.zeroeightsix.kami.module.*; +import me.zeroeightsix.kami.module.Module; import me.zeroeightsix.kami.module.modules.chat.ChatEncryption; import me.zeroeightsix.kami.module.modules.client.CommandConfig; import me.zeroeightsix.kami.module.modules.hidden.RunConfig; From 763c1002315956f0a7300589b2eaff777cdcec81 Mon Sep 17 00:00:00 2001 From: Christian Date: Mon, 24 Aug 2020 12:15:52 +0200 Subject: [PATCH 003/390] Complete overhaul from scratch Check new engine: https://youtu.be/G6oMppnCd4s - Reworked whole code from scratch to be able to handle all different tasks correctly - Way more reliable block breaking - Able to clear space blocks - Capable of auto tunneling the path using packets so no pre tunneling using baritone or similar tools ToDo: - Check if queue is correct after done to minimize glitched blocks after breaking (like the 3 Netherrack in the video) - Diagonal modes - Intelligent liquid handling - Blocks per Tick / delay optimization - Get obsidian from shulkers if inventory is empty and get shulkers from enderchest - Logout if getting killed by Wither or similar --- .../kami/module/modules/misc/HighwayTools.kt | 774 ++++++++---------- 1 file changed, 334 insertions(+), 440 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 8525854819..a5d969a8c1 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -2,16 +2,15 @@ package me.zeroeightsix.kami.module.modules.misc import baritone.api.BaritoneAPI import baritone.api.pathing.goals.GoalXZ -import com.mojang.realmsclient.gui.ChatFormatting import me.zeroeightsix.kami.KamiMod import me.zeroeightsix.kami.event.events.RenderEvent import me.zeroeightsix.kami.module.Module -import me.zeroeightsix.kami.module.modules.player.Freecam import me.zeroeightsix.kami.module.modules.player.NoBreakAnimation import me.zeroeightsix.kami.setting.Settings import me.zeroeightsix.kami.util.* import me.zeroeightsix.kami.util.colourUtils.ColourHolder import net.minecraft.block.* +import net.minecraft.client.Minecraft import net.minecraft.client.audio.PositionedSoundRecord import net.minecraft.entity.item.EntityItem import net.minecraft.entity.item.EntityXPOrb @@ -25,18 +24,17 @@ import net.minecraft.util.EnumHand import net.minecraft.util.math.AxisAlignedBB import net.minecraft.util.math.BlockPos import net.minecraft.util.math.Vec3d -import java.util.concurrent.ConcurrentHashMap -import java.util.concurrent.Executors -import java.util.concurrent.TimeUnit +import java.util.* import kotlin.math.roundToInt /** * @author Avanatiker - * @since 15/08/2020 + * @since 20/08/2020 */ + @Module.Info( name = "HighwayTools", - description = "Better High-ways for the greater good.", + description = "Even Better High-ways for the greater good.", category = Module.Category.MISC ) class HighwayTools : Module() { @@ -51,44 +49,32 @@ class HighwayTools : Module() { private val aFilled = register(Settings.integerBuilder("FilledAlpha").withMinimum(0).withValue(31).withMaximum(255).withVisibility { filled.value }.build()) private val aOutline = register(Settings.integerBuilder("OutlineAlpha").withMinimum(0).withValue(127).withMaximum(255).withVisibility { outline.value }.build()) - private var offsetStep = 0 - private var delayStep = 0 - private var blocksDonePlacing = 0 private var playerHotbarSlot = -1 - private var lastHotbarSlot = -1 - private var isSneaking = false - private var totalTicksRunning = 0 - private var firstRun = false - private var missingObiDisable = false - private var ismining = false - private var nextBlockPos = BlockPos(0,0,0) - private var currentBlockPos = BlockPos(0,0,0) - private val directions = listOf("North", "East", "South", "West") - private var buildDirectionSaved = 0 private var buildDirectionCoordinateSaved = 0.0 private var buildDirectionCoordinateSavedY = 0.0 - private var offsetPattern = arrayOfNulls(0) - private var maxSteps = 0 + private val directions = listOf("North", "East", "South", "West") - private var totalBlocksPlaced = 0 - private var totalBlocksDestroyed = 0 - private var totalBlocksDistanceWent = 0 + private var isSneaking = false + + //Stats + var totalBlocksPlaced = 0 + var totalBlocksDestroyed = 0 + var totalBlocksDistanceWent = 0 - private var placementPendingBlockTiles = ConcurrentHashMap() - private var placedBlocksIteration = ConcurrentHashMap() - private var pendingWrongBlocks = ConcurrentHashMap() + val blockQueue: Queue = LinkedList() + private val doneQueue: Queue = LinkedList() + var a = mutableListOf>() + var waitTicks = 0 override fun onEnable() { if (mc.player == null) { disable() return } - firstRun = true + buildDirectionSaved = getPlayerDirection() playerHotbarSlot = mc.player.inventory.currentItem - lastHotbarSlot = -1 - buildDirectionSaved = getPlayerDirection() buildDirectionCoordinateSavedY = mc.player.positionVector.y if (buildDirectionSaved == 0 || buildDirectionSaved == 2) { buildDirectionCoordinateSaved = mc.player.positionVector.x @@ -97,201 +83,162 @@ class HighwayTools : Module() { buildDirectionCoordinateSaved = mc.player.positionVector.z } - if (mode.value == Mode.FLAT) { - offsetPattern = OffsetsBlocks.FLAT - maxSteps = OffsetsBlocks.FLAT.size - } - if (mode.value == Mode.HIGHWAY) { - if (buildDirectionSaved == 0) { - offsetPattern = OffsetsBlocks.HIGHWAY_0 - maxSteps = OffsetsBlocks.HIGHWAY_0.size - } - else if (buildDirectionSaved == 1) { - offsetPattern = OffsetsBlocks.HIGHWAY_1 - maxSteps = OffsetsBlocks.HIGHWAY_1.size - } - else if (buildDirectionSaved == 2) { - offsetPattern = OffsetsBlocks.HIGHWAY_2 - maxSteps = OffsetsBlocks.HIGHWAY_2.size - } - else if (buildDirectionSaved == 3) { - offsetPattern = OffsetsBlocks.HIGHWAY_3 - maxSteps = OffsetsBlocks.HIGHWAY_3.size - } - } - + blockQueue.clear() + doneQueueReset() + updateTasks() MessageSendHelper.sendChatMessage("$chatName Module started." + - "\n §9> §rSelected direction: §a" + directions[getPlayerDirection()] + "§r" + + "\n §9> §rSelected direction: §a" + directions[buildDirectionSaved] + "§r" + "\n §9> §rSnap to coordinate: §a" + buildDirectionCoordinateSaved.roundToInt() + "§r" + "\n §9> §rBaritone mode: §a" + baritoneModee.value + "§r") } - override fun onDisable() { - if (mc.player == null) return - - // load initial player hand - if (lastHotbarSlot != playerHotbarSlot && playerHotbarSlot != -1) { - mc.player.inventory.currentItem = playerHotbarSlot - } - if (isSneaking) { - mc.player.connection.sendPacket(CPacketEntityAction(mc.player, CPacketEntityAction.Action.STOP_SNEAKING)) - isSneaking = false - } - playerHotbarSlot = -1 - lastHotbarSlot = -1 - missingObiDisable = false - BaritoneAPI.getProvider().primaryBaritone.pathingBehavior.cancelEverything() - MessageSendHelper.sendChatMessage("$chatName Module stopped." + - "\n §9> §rPlaced obsidian: §a" + totalBlocksPlaced + "§r" + - "\n §9> §rDestroyed blocks: §a" + totalBlocksDestroyed + "§r" + - "\n §9> §rDistance: §a" + totalBlocksDistanceWent + "§r") - totalBlocksPlaced = 0 - totalBlocksDestroyed = 0 - totalBlocksDistanceWent = 0 - } - override fun onUpdate() { - if (mc.player == null || KamiMod.MODULE_MANAGER.isModuleEnabled(Freecam::class.java)) { - return - } - - if (!firstRun) { - delayStep = if (delayStep < tickDelay.value) { - delayStep++ - return + if (!BaritoneAPI.getProvider().primaryBaritone.customGoalProcess.isActive) { + if (isDone()) { + if (baritoneModee.value) { + moveOneBlock() + } + doneQueueReset() + updateTasks() + totalBlocksDistanceWent++ } else { - 0 + doTask() + //getDebug() } } + } - if (firstRun) { - firstRun = false - if (findObiInHotbar() == -1) { - missingObiDisable = true - } - } - - var blocksPlaced = 0 - - blocksDonePlacing = 0 + private fun addTask(bps: BlockPos, ts: TaskState, bb: Boolean) { + blockQueue.add(BlockTask(bps, ts, bb)) + } - // get workload and render - placementPendingBlockTiles.clear() - placedBlocksIteration.clear() - pendingWrongBlocks.clear() - for(x in 0 until maxSteps) { - val offsetPos = BlockPos(offsetPattern[x]) - val snappedCoords = BlockPos(mc.player.positionVector) - snappedCoords.y = buildDirectionCoordinateSavedY.toInt() - if (getPlayerDirection() == 0 || getPlayerDirection() == 2) { - snappedCoords.x = buildDirectionCoordinateSaved.toInt() - } - else if (getPlayerDirection() == 1 || getPlayerDirection() == 3) { - snappedCoords.z = buildDirectionCoordinateSaved.toInt() - } - val targetPos = BlockPos(snappedCoords).add(offsetPos.x, offsetPos.y, offsetPos.z) - if (x == 1) { - currentBlockPos = nextBlockPos - nextBlockPos = targetPos - } - val block = mc.world.getBlockState(targetPos).block - if (block is BlockAir) { - placementPendingBlockTiles[targetPos] = ColourHolder(35, 188, 254) - } - if (block is BlockObsidian) { - placementPendingBlockTiles[targetPos] = ColourHolder(50, 50, 50) - blocksDonePlacing++ - } + private fun getDebug() { + MessageSendHelper.sendChatMessage("#### LOG ####") + for (bt in blockQueue) { + MessageSendHelper.sendChatMessage(bt.getBlockPos().toString() + " " + bt.getTaskState().toString() + " " + bt.getBlock().toString()) + } + MessageSendHelper.sendChatMessage("#### DONE ####") + for (bt in doneQueue) { + MessageSendHelper.sendChatMessage(bt.getBlockPos().toString() + " " + bt.getTaskState().toString() + " " + bt.getBlock().toString()) } + } - // actually do the work - while (blocksPlaced < blocksPerTick.value) { - if (offsetStep >= maxSteps) { - offsetStep = 0 - break - } - val offsetPos = BlockPos(offsetPattern[offsetStep]) - var targetPos = BlockPos(mc.player.positionVector).add(offsetPos.x, offsetPos.y, offsetPos.z) - if (mode.value == Mode.HIGHWAY) { - val snappedCoords = BlockPos(mc.player.positionVector) - snappedCoords.y = buildDirectionCoordinateSavedY.toInt() - if (getPlayerDirection() == 0 || getPlayerDirection() == 2) { - snappedCoords.x = buildDirectionCoordinateSaved.toInt() + private fun doTask(): Boolean { + if (!isDone()) { + if (waitTicks == 0) { + var blockAction = blockQueue.peek() + if (blockAction.getTaskState() == TaskState.BREAK) { + mineBlock(blockAction.getBlockPos(), true) + blockAction.setTaskState(TaskState.BREAKING) + val block = mc.world.getBlockState(blockAction.getBlockPos()).block + if (block is BlockNetherrack) { + waitTicks = 0 + } else { + val efficiencyLevel = 5 + waitTicks = (block.blockHardness * 5.0 / (8 + efficiencyLevel * efficiencyLevel + 1) / 20).toInt() + waitTicks = 20 + } + } else if (blockAction.getTaskState() == TaskState.BREAKING) { + mineBlock(blockAction.getBlockPos(), false) + if (blockAction.getBlock()) { + blockAction.setTaskState(TaskState.PLACE) + } else { + blockAction.setTaskState(TaskState.DONE) + } + } else if (blockAction.getTaskState() == TaskState.PLACE) { + if (placeBlock(blockAction.getBlockPos())) { + blockAction.setTaskState(TaskState.PLACED) + } else { + return false + } + } else if (blockAction.getTaskState() == TaskState.PLACED) { + blockAction.setTaskState(TaskState.DONE) + doTask() + } else if (blockAction.getTaskState() == TaskState.DONE) { + blockQueue.remove() + doneQueue.add(blockAction) + doTask() } - else if (getPlayerDirection() == 1 || getPlayerDirection() == 3) { - snappedCoords.z = buildDirectionCoordinateSaved.toInt() - } - targetPos = BlockPos(snappedCoords).add(offsetPos.x, offsetPos.y, offsetPos.z) - } - if (placeBlock(targetPos)) { - placedBlocksIteration[targetPos] = ColourHolder(53, 222, 66) - blocksPlaced++ - totalBlocksPlaced++ + } else { + waitTicks-- } - offsetStep++ + return true + } else { + return false } + } - // check if row is ready for moving on - if (baritoneModee.value && (blocksDonePlacing == maxSteps)) { - moveOneBlock() + private fun updateTasks() { + updateBlockArray() + for ((a, b) in a) { + val block = mc.world.getBlockState(a).block + if (b && block is BlockAir) { addTask(a, TaskState.PLACE, true) } + else if (b && block !is BlockAir && block !is BlockObsidian) { addTask(a, TaskState.BREAK, true) } + else if (!b && block !is BlockAir) { addTask(a, TaskState.BREAK, false) } + else if (b && block is BlockObsidian) { addTask(a, TaskState.DONE, true) } + else if (!b && block is BlockAir) { addTask(a, TaskState.DONE, false) } } + } - if (blocksPlaced > 0) { - if (lastHotbarSlot != playerHotbarSlot && playerHotbarSlot != -1) { - mc.player.inventory.currentItem = playerHotbarSlot - lastHotbarSlot = playerHotbarSlot - } - if (isSneaking) { - mc.player.connection.sendPacket(CPacketEntityAction(mc.player, CPacketEntityAction.Action.STOP_SNEAKING)) - isSneaking = false - } + private fun updateRenderer(renderer: ESPRenderer): ESPRenderer { + val side = GeometryMasks.Quad.ALL + for (bt in blockQueue) { + if (bt.getTaskState() != TaskState.DONE) { renderer.add(bt.getBlockPos(), bt.getTaskState().color, side) } } - - totalTicksRunning++ - - if (missingObiDisable && infoMessage.value) { - missingObiDisable = false - MessageSendHelper.sendChatMessage("$chatName " + ChatFormatting.RED + "Disabled" + ChatFormatting.RESET + ", Obsidian missing!") - disable() + for (bt in doneQueue) { + if (bt.getBlock()) { renderer.add(bt.getBlockPos(), bt.getTaskState().color, side) } } + return renderer } - private fun getPlayerDirection(): Int { - val yaw = (mc.player.rotationYaw % 360 + 360) % 360 - if (yaw >= 135 && yaw < 225) { - return 0 //NORTH + private fun moveOneBlock() { + // set head rotation to get max walking speed + var nextBlockPos: BlockPos + if (buildDirectionSaved == 0) { + nextBlockPos = BlockPos(mc.player.positionVector).north() + mc.player.rotationYaw = -180F } - else if (yaw >= 225 && yaw < 315) { - return 1 //EAST + else if (buildDirectionSaved == 1) { + nextBlockPos = BlockPos(mc.player.positionVector).east() + mc.player.rotationYaw = -90F } - else if (yaw >= 315 || yaw < 45) { - return 2 //SOUTH + else if (buildDirectionSaved == 2) { + nextBlockPos = BlockPos(mc.player.positionVector).south() + mc.player.rotationYaw = 0F + } else { + nextBlockPos = BlockPos(mc.player.positionVector).west() + mc.player.rotationYaw = 90F } - else if (yaw >= 45 && yaw < 135){ - return 3 //WEST + mc.player.rotationPitch = 0F + BaritoneAPI.getProvider().primaryBaritone.customGoalProcess.setGoalAndPath(GoalXZ(nextBlockPos.getX(), nextBlockPos.getZ())) + } + + private fun mineBlock(pos: BlockPos, pre: Boolean) { + if (InventoryUtils.getSlotsHotbar(278) == null && InventoryUtils.getSlotsNoHotbar(278) != null) { + InventoryUtils.moveToHotbar(278, 130, (tickDelay.value * 16).toLong()) + return + } else if (InventoryUtils.getSlots(0, 35, 278) == null) { + MessageSendHelper.sendChatMessage("$chatName No pickaxe was found in inventory, disabling.") + mc.getSoundHandler().playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) + disable() + return } - else { - return -1 + InventoryUtils.swapSlotToItem(278) + lookAtBlock(pos) + + if (pre) { + mc.connection!!.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, pos, mc.objectMouseOver.sideHit)) + } else { + mc.connection!!.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, pos, mc.objectMouseOver.sideHit)) } + mc.player.swingArm(EnumHand.MAIN_HAND) } - private fun placeBlock(pos: BlockPos): Boolean { + private fun placeBlock(pos: BlockPos): Boolean + { // check if block is already placed val block = mc.world.getBlockState(pos).block if (block !is BlockAir && block !is BlockLiquid) { - if (block !is BlockObsidian) { - pendingWrongBlocks[pos] = ColourHolder(222, 0, 0) - val backupYaw = mc.player.rotationYaw - val backupPitch = mc.player.rotationPitch - mineBlock(pos, true) - Executors.newSingleThreadScheduledExecutor().schedule({ - mineBlock(pos, false) - mc.player.rotationYaw = backupYaw - mc.player.rotationPitch = backupPitch - totalBlocksDestroyed++ - }, tickDelay.value * 50L, TimeUnit.MILLISECONDS) - blocksDonePlacing-- - } return false } @@ -312,18 +259,21 @@ class HighwayTools : Module() { return false } + //Swap to Obsidian in Hotbar or get from inventory + if (InventoryUtils.getSlotsHotbar(49) == null && InventoryUtils.getSlotsNoHotbar(49) != null) { + InventoryUtils.moveToHotbar(49, 130, (tickDelay.value * 16).toLong()) + return false + } else if (InventoryUtils.getSlots(0, 35, 49) == null) { + MessageSendHelper.sendChatMessage("$chatName No Obsidian was found in inventory, disabling.") + mc.getSoundHandler().playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) + disable() + return false + } + InventoryUtils.swapSlotToItem(49) + val hitVec = Vec3d(neighbour).add(0.5, 0.5, 0.5).add(Vec3d(opposite.directionVec).scale(0.5)) val neighbourBlock = mc.world.getBlockState(neighbour).block - val obiSlot = findObiInHotbar() - if (obiSlot == -1) { - missingObiDisable = true - return false - } - if (lastHotbarSlot != obiSlot) { - mc.player.inventory.currentItem = obiSlot - lastHotbarSlot = obiSlot - } if (!isSneaking && BlockUtils.blackList.contains(neighbourBlock) || BlockUtils.shulkerList.contains(neighbourBlock)) { mc.player.connection.sendPacket(CPacketEntityAction(mc.player, CPacketEntityAction.Action.START_SNEAKING)) isSneaking = true @@ -342,59 +292,18 @@ class HighwayTools : Module() { return true } - private fun mineBlock(pos: BlockPos, pre: Boolean) { - // get mining tool in mainhand - if (InventoryUtils.getSlotsHotbar(278) == null && InventoryUtils.getSlotsNoHotbar(278) != null) { - InventoryUtils.moveToHotbar(278, 130, (tickDelay.value * 16).toLong()) - return - } else if (InventoryUtils.getSlots(0, 35, 278) == null) { - MessageSendHelper.sendChatMessage("$chatName No pickaxe was found in inventory, disabling.") - mc.getSoundHandler().playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) - this.disable() - return - } - InventoryUtils.swapSlotToItem(278) - lookAtBlock(pos) - - /* Packet mining lol */ - if (pre) { - mc.connection!!.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, pos, mc.objectMouseOver.sideHit)) - //if (state != AutoObsidian.State.SEARCHING) state = AutoObsidian.State.MINING else searchingState = AutoObsidian.SearchingState.MINING - } else { - mc.connection!!.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, pos, mc.objectMouseOver.sideHit)) - } - mc.player.swingArm(EnumHand.MAIN_HAND) - } - - // just experimental - private fun mineBlockBaritone(pos: BlockPos) { - ismining = true - val bapi = BaritoneAPI.getProvider().getPrimaryBaritone().getCommandManager() - bapi.execute("sel 1 " + pos.x + " " + pos.y + " " + pos.z) - bapi.execute("sel 2 " + pos.x + " " + pos.y + " " + pos.z) - bapi.execute("sel ca") - bapi.execute("sel clear") - BaritoneAPI.getProvider().primaryBaritone.customGoalProcess.setGoalAndPath(GoalXZ(nextBlockPos.getX(), nextBlockPos.getZ())) - ismining = false - } - - private fun moveOneBlock() { - // set head rotation to get max walking speed - if (getPlayerDirection() == 0) { - mc.player.rotationYaw = -180F - } - else if (getPlayerDirection() == 1) { - mc.player.rotationYaw = -90F - } - else if (getPlayerDirection() == 2) { - mc.player.rotationYaw = 0F - } else { - mc.player.rotationYaw = 90F + private fun getPlaceableSide(pos: BlockPos): EnumFacing? { + for (side in EnumFacing.values()) { + val neighbour = pos.offset(side) + if (!mc.world.getBlockState(neighbour).block.canCollideCheck(mc.world.getBlockState(neighbour), false)) { + continue + } + val blockState = mc.world.getBlockState(neighbour) + if (!blockState.material.isReplaceable) { + return side + } } - mc.player.rotationPitch = 0F - //move to next block pos - BaritoneAPI.getProvider().primaryBaritone.customGoalProcess.setGoalAndPath(GoalXZ(nextBlockPos.getX(), nextBlockPos.getZ())) - totalBlocksDistanceWent++ + return null } private fun lookAtBlock(pos: BlockPos) { @@ -404,198 +313,183 @@ class HighwayTools : Module() { mc.player.rotationPitch = lookAt[1].toFloat() } + private fun updateBlockArray() { + a.clear() + var b = BlockPos(mc.player.positionVector) + + when(mode.value) { + Mode.HIGHWAY -> { + when (buildDirectionSaved) { + 0 -> { //NORTH + a.add(Pair(b.down(), true)) + a.add(Pair(b.down().north(), true)) + a.add(Pair(b.down().north().north(), true)) + a.add(Pair(b.down().north().north().east(), true)) + a.add(Pair(b.down().north().north().west(), true)) + a.add(Pair(b.down().north().north().east().east(), true)) + a.add(Pair(b.down().north().north().west().west(), true)) + a.add(Pair(b.down().north().north().east().east().east(), true)) + a.add(Pair(b.down().north().north().west().west().west(), true)) + a.add(Pair(b.north().north().east().east().east(), true)) + a.add(Pair(b.north().north().west().west().west(), true)) + a.add(Pair(b.north().north(), false)) + a.add(Pair(b.north().north().east(), false)) + a.add(Pair(b.north().north().west(), false)) + a.add(Pair(b.north().north().east().east(), false)) + a.add(Pair(b.north().north().west().west(), false)) + a.add(Pair(b.up().north().north(), false)) + a.add(Pair(b.up().north().north().east(), false)) + a.add(Pair(b.up().north().north().west(), false)) + a.add(Pair(b.up().north().north().east().east(), false)) + a.add(Pair(b.up().north().north().west().west(), false)) + a.add(Pair(b.up().north().north().east().east().east(), false)) + a.add(Pair(b.up().north().north().west().west().west(), false)) + a.add(Pair(b.up().up().north().north(), false)) + a.add(Pair(b.up().up().north().north().east(), false)) + a.add(Pair(b.up().up().north().north().west(), false)) + a.add(Pair(b.up().up().north().north().east().east(), false)) + a.add(Pair(b.up().up().north().north().west().west(), false)) + a.add(Pair(b.up().up().north().north().east().east().east(), false)) + a.add(Pair(b.up().up().north().north().west().west().west(), false)) + } + 1 -> { //EAST + a.add(Pair(b.down(), true)) + a.add(Pair(b.down().east(), true)) + a.add(Pair(b.down().east().east(), true)) + a.add(Pair(b.down().east().east().south(), true)) + a.add(Pair(b.down().east().east().north(), true)) + a.add(Pair(b.down().east().east().south().south(), true)) + a.add(Pair(b.down().east().east().north().north(), true)) + a.add(Pair(b.down().east().east().south().south().south(), true)) + a.add(Pair(b.down().east().east().north().north().north(), true)) + a.add(Pair(b.east().east().south().south().south(), true)) + a.add(Pair(b.east().east().north().north().north(), true)) + a.add(Pair(b.east().east(), false)) + a.add(Pair(b.east().east().south(), false)) + a.add(Pair(b.east().east().north(), false)) + a.add(Pair(b.east().east().south().south(), false)) + a.add(Pair(b.east().east().north().north(), false)) + a.add(Pair(b.up().east().east(), false)) + a.add(Pair(b.up().east().east().south(), false)) + a.add(Pair(b.up().east().east().north(), false)) + a.add(Pair(b.up().east().east().south().south(), false)) + a.add(Pair(b.up().east().east().north().north(), false)) + a.add(Pair(b.up().east().east().south().south().south(), false)) + a.add(Pair(b.up().east().east().north().north().north(), false)) + a.add(Pair(b.up().up().east().east(), false)) + a.add(Pair(b.up().up().east().east().south(), false)) + a.add(Pair(b.up().up().east().east().north(), false)) + a.add(Pair(b.up().up().east().east().south().south(), false)) + a.add(Pair(b.up().up().east().east().north().north(), false)) + a.add(Pair(b.up().up().east().east().south().south().south(), false)) + a.add(Pair(b.up().up().east().east().north().north().north(), false)) + } + 2 -> { //SOUTH + a.add(Pair(b.down(), true)) + a.add(Pair(b.down().south(), true)) + a.add(Pair(b.down().south().south(), true)) + a.add(Pair(b.down().south().south().east(), true)) + a.add(Pair(b.down().south().south().west(), true)) + a.add(Pair(b.down().south().south().east().east(), true)) + a.add(Pair(b.down().south().south().west().west(), true)) + a.add(Pair(b.down().south().south().east().east().east(), true)) + a.add(Pair(b.down().south().south().west().west().west(), true)) + a.add(Pair(b.south().south().east().east().east(), true)) + a.add(Pair(b.south().south().west().west().west(), true)) + a.add(Pair(b.south().south(), false)) + a.add(Pair(b.south().south().east(), false)) + a.add(Pair(b.south().south().west(), false)) + a.add(Pair(b.south().south().east().east(), false)) + a.add(Pair(b.south().south().west().west(), false)) + a.add(Pair(b.up().south().south(), false)) + a.add(Pair(b.up().south().south().east(), false)) + a.add(Pair(b.up().south().south().west(), false)) + a.add(Pair(b.up().south().south().east().east(), false)) + a.add(Pair(b.up().south().south().west().west(), false)) + a.add(Pair(b.up().south().south().east().east().east(), false)) + a.add(Pair(b.up().south().south().west().west().west(), false)) + a.add(Pair(b.up().up().south().south(), false)) + a.add(Pair(b.up().up().south().south().east(), false)) + a.add(Pair(b.up().up().south().south().west(), false)) + a.add(Pair(b.up().up().south().south().east().east(), false)) + a.add(Pair(b.up().up().south().south().west().west(), false)) + a.add(Pair(b.up().up().south().south().east().east().east(), false)) + a.add(Pair(b.up().up().south().south().west().west().west(), false)) + } + 3 -> { //WEST + a.add(Pair(b.down(), true)) + a.add(Pair(b.down().west(), true)) + a.add(Pair(b.down().west().west(), true)) + a.add(Pair(b.down().west().west().south(), true)) + a.add(Pair(b.down().west().west().north(), true)) + a.add(Pair(b.down().west().west().south().south(), true)) + a.add(Pair(b.down().west().west().north().north(), true)) + a.add(Pair(b.down().west().west().south().south().south(), true)) + a.add(Pair(b.down().west().west().north().north().north(), true)) + a.add(Pair(b.west().west().south().south().south(), true)) + a.add(Pair(b.west().west().north().north().north(), true)) + a.add(Pair(b.west().west(), false)) + a.add(Pair(b.west().west().south(), false)) + a.add(Pair(b.west().west().north(), false)) + a.add(Pair(b.west().west().south().south(), false)) + a.add(Pair(b.west().west().north().north(), false)) + a.add(Pair(b.up().west().west(), false)) + a.add(Pair(b.up().west().west().south(), false)) + a.add(Pair(b.up().west().west().north(), false)) + a.add(Pair(b.up().west().west().south().south(), false)) + a.add(Pair(b.up().west().west().north().north(), false)) + a.add(Pair(b.up().west().west().south().south().south(), false)) + a.add(Pair(b.up().west().west().north().north().north(), false)) + a.add(Pair(b.up().up().west().west(), false)) + a.add(Pair(b.up().up().west().west().south(), false)) + a.add(Pair(b.up().up().west().west().north(), false)) + a.add(Pair(b.up().up().west().west().south().south(), false)) + a.add(Pair(b.up().up().west().west().north().north(), false)) + a.add(Pair(b.up().up().west().west().south().south().south(), false)) + a.add(Pair(b.up().up().west().west().north().north().north(), false)) + } + } + } + } + } + + fun isDone(): Boolean { return blockQueue.size == 0 } + fun doneQueueReset() { doneQueue.clear() } + override fun onWorldRender(event: RenderEvent) { if (mc.player == null) return - val side = GeometryMasks.Quad.ALL val renderer = ESPRenderer(event.partialTicks) renderer.aFilled = if (filled.value) aFilled.value else 0 renderer.aOutline = if (outline.value) aOutline.value else 0 - if (!placementPendingBlockTiles.isEmpty()) { - for ((pos, colour) in placementPendingBlockTiles) { - renderer.add(pos, colour, side) - } - } - if (!placedBlocksIteration.isEmpty()) { - for ((pos, colour) in placedBlocksIteration) { - renderer.add(pos, colour, side) - } - } - if (!pendingWrongBlocks.isEmpty()) { - for ((pos, colour) in pendingWrongBlocks) { - renderer.add(pos, colour, side) - } - } + updateRenderer(renderer) renderer.render() } - private fun findObiInHotbar(): Int { - // search blocks in hotbar - var slot = -1 - for (i in 0..8) { - // filter out non-block items - val stack = mc.player.inventory.getStackInSlot(i) - if (stack == ItemStack.EMPTY || stack.getItem() !is ItemBlock) { - continue - } - val block = (stack.getItem() as ItemBlock).block - if (block is BlockObsidian) { - slot = i - break - } - //else if (block is BlockNetherrack) { - // slot = i - // break - //} - } - return slot - } - - private enum class Mode { - FLAT, HIGHWAY - } - - private object Offsets_Space { - val HIGHWAY_0 = arrayOf( - Vec3d(0.0, -1.0, 0.0), - Vec3d(0.0, -1.0, -1.0), - Vec3d(-1.0, -1.0, -1.0), - Vec3d(1.0, -1.0, -1.0), - Vec3d(-2.0, -1.0, -1.0), - Vec3d(2.0, -1.0, -1.0), - Vec3d(-3.0, -1.0, -1.0), - Vec3d(3.0, -1.0, -1.0), - Vec3d(3.0, 0.0, -1.0), - Vec3d(-3.0, 0.0, -1.0) - ) - val HIGHWAY_1 = arrayOf( - Vec3d(0.0, -1.0, 0.0), - Vec3d(1.0, -1.0, 0.0), - Vec3d(1.0, -1.0, -1.0), - Vec3d(1.0, -1.0, 1.0), - Vec3d(1.0, -1.0, -2.0), - Vec3d(1.0, -1.0, 2.0), - Vec3d(1.0, -1.0, -3.0), - Vec3d(1.0, -1.0, 3.0), - Vec3d(1.0, 0.0, 3.0), - Vec3d(1.0, 0.0, -3.0) - ) - val HIGHWAY_2 = arrayOf( - Vec3d(0.0, -1.0, 0.0), - Vec3d(0.0, -1.0, 1.0), - Vec3d(-1.0, -1.0, 1.0), - Vec3d(1.0, -1.0, 1.0), - Vec3d(-2.0, -1.0, 1.0), - Vec3d(2.0, -1.0, 1.0), - Vec3d(-3.0, -1.0, 1.0), - Vec3d(3.0, -1.0, 1.0), - Vec3d(3.0, 0.0, 1.0), - Vec3d(-3.0, 0.0, 1.0) - ) - val HIGHWAY_3 = arrayOf( - Vec3d(0.0, -1.0, 0.0), - Vec3d(-1.0, -1.0, 0.0), - Vec3d(-1.0, -1.0, -1.0), - Vec3d(-1.0, -1.0, 1.0), - Vec3d(-1.0, -1.0, -2.0), - Vec3d(-1.0, -1.0, 2.0), - Vec3d(-1.0, -1.0, -3.0), - Vec3d(-1.0, -1.0, 3.0), - Vec3d(-1.0, 0.0, 3.0), - Vec3d(-1.0, 0.0, -3.0) - ) - } - - private object OffsetsBlocks { - val FLAT = arrayOf( - Vec3d(0.0, -1.0, 0.0), - Vec3d(1.0, -1.0, 0.0), - Vec3d(-1.0, -1.0, 0.0), - Vec3d(0.0, -1.0, 1.0), - Vec3d(0.0, -1.0, -1.0), - Vec3d(1.0, -1.0, 1.0), - Vec3d(-1.0, -1.0, -1.0), - Vec3d(1.0, -1.0, -1.0), - Vec3d(-1.0, -1.0, 1.0), - Vec3d(2.0, -1.0, 0.0), - Vec3d(-2.0, -1.0, 0.0), - Vec3d(0.0, -1.0, 2.0), - Vec3d(0.0, -1.0, -2.0), - Vec3d(1.0, -1.0, 2.0), - Vec3d(-1.0, -1.0, 2.0), - Vec3d(2.0, -1.0, -1.0), - Vec3d(2.0, -1.0, 1.0), - Vec3d(-2.0, -1.0, -1.0), - Vec3d(-2.0, -1.0, 1.0), - Vec3d(1.0, -1.0, -2.0), - Vec3d(-1.0, -1.0, -2.0), - Vec3d(2.0, -1.0, 2.0), - Vec3d(-2.0, -1.0, 2.0), - Vec3d(-2.0, -1.0, -2.0), - Vec3d(2.0, -1.0, -2.0) - ) - val HIGHWAY_0 = arrayOf( - Vec3d(0.0, -1.0, 0.0), - Vec3d(0.0, -1.0, -1.0), - Vec3d(-1.0, -1.0, -1.0), - Vec3d(1.0, -1.0, -1.0), - Vec3d(-2.0, -1.0, -1.0), - Vec3d(2.0, -1.0, -1.0), - Vec3d(-3.0, -1.0, -1.0), - Vec3d(3.0, -1.0, -1.0), - Vec3d(3.0, 0.0, -1.0), - Vec3d(-3.0, 0.0, -1.0) - ) - val HIGHWAY_1 = arrayOf( - Vec3d(0.0, -1.0, 0.0), - Vec3d(1.0, -1.0, 0.0), - Vec3d(1.0, -1.0, -1.0), - Vec3d(1.0, -1.0, 1.0), - Vec3d(1.0, -1.0, -2.0), - Vec3d(1.0, -1.0, 2.0), - Vec3d(1.0, -1.0, -3.0), - Vec3d(1.0, -1.0, 3.0), - Vec3d(1.0, 0.0, 3.0), - Vec3d(1.0, 0.0, -3.0) - ) - val HIGHWAY_2 = arrayOf( - Vec3d(0.0, -1.0, 0.0), - Vec3d(0.0, -1.0, 1.0), - Vec3d(-1.0, -1.0, 1.0), - Vec3d(1.0, -1.0, 1.0), - Vec3d(-2.0, -1.0, 1.0), - Vec3d(2.0, -1.0, 1.0), - Vec3d(-3.0, -1.0, 1.0), - Vec3d(3.0, -1.0, 1.0), - Vec3d(3.0, 0.0, 1.0), - Vec3d(-3.0, 0.0, 1.0) - ) - val HIGHWAY_3 = arrayOf( - Vec3d(0.0, -1.0, 0.0), - Vec3d(-1.0, -1.0, 0.0), - Vec3d(-1.0, -1.0, -1.0), - Vec3d(-1.0, -1.0, 1.0), - Vec3d(-1.0, -1.0, -2.0), - Vec3d(-1.0, -1.0, 2.0), - Vec3d(-1.0, -1.0, -3.0), - Vec3d(-1.0, -1.0, 3.0), - Vec3d(-1.0, 0.0, 3.0), - Vec3d(-1.0, 0.0, -3.0) - ) - } - - companion object { - private fun getPlaceableSide(pos: BlockPos): EnumFacing? { - for (side in EnumFacing.values()) { - val neighbour = pos.offset(side) - if (!mc.world.getBlockState(neighbour).block.canCollideCheck(mc.world.getBlockState(neighbour), false)) { - continue - } - val blockState = mc.world.getBlockState(neighbour) - if (!blockState.material.isReplaceable) { - return side - } - } - return null - } + fun getPlayerDirection(): Int { + val yaw = (mc.player.rotationYaw % 360 + 360) % 360 + if (yaw >= 135 && yaw < 225) { return 0 } //NORTH + else if (yaw >= 225 && yaw < 315) { return 1 } //EAST + else if (yaw >= 315 || yaw < 45) { return 2 } //SOUTH + else if (yaw >= 45 && yaw < 135){ return 3 } //WEST + else { return -1 } //WRONG } -} \ No newline at end of file +} + +class BlockTask(private val bp: BlockPos, private var tt: TaskState, private val bb: Boolean) { + fun getBlockPos(): BlockPos { return bp } + fun getTaskState(): TaskState { return tt } + fun setTaskState(tts: TaskState) { tt = tts } + fun getBlock(): Boolean { return bb } +} + +enum class TaskState(val color: ColourHolder) { + BREAK(ColourHolder(222, 0, 0)), + BREAKING(ColourHolder(240, 222, 60)), + PLACE(ColourHolder(35, 188, 254)), + PLACED(ColourHolder(53, 222, 66)), + DONE(ColourHolder(50, 50, 50)) +} + +enum class Mode { + FLAT, HIGHWAY +} From 773ea56ff62967ba54e74badfd8a8071878cf01d Mon Sep 17 00:00:00 2001 From: Christian Date: Mon, 24 Aug 2020 16:55:52 +0200 Subject: [PATCH 004/390] Small fixes - New TaskState to check if block broke successfully - Code cleanup --- .../kami/module/modules/misc/HighwayTools.kt | 88 +++++++++++-------- 1 file changed, 51 insertions(+), 37 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index a5d969a8c1..5b5554fcf5 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -10,13 +10,10 @@ import me.zeroeightsix.kami.setting.Settings import me.zeroeightsix.kami.util.* import me.zeroeightsix.kami.util.colourUtils.ColourHolder import net.minecraft.block.* -import net.minecraft.client.Minecraft import net.minecraft.client.audio.PositionedSoundRecord import net.minecraft.entity.item.EntityItem import net.minecraft.entity.item.EntityXPOrb import net.minecraft.init.SoundEvents -import net.minecraft.item.ItemBlock -import net.minecraft.item.ItemStack import net.minecraft.network.play.client.CPacketEntityAction import net.minecraft.network.play.client.CPacketPlayerDigging import net.minecraft.util.EnumFacing @@ -39,7 +36,7 @@ import kotlin.math.roundToInt ) class HighwayTools : Module() { private val mode = register(Settings.e("Mode", Mode.HIGHWAY)) - private val baritoneModee = register(Settings.b("Baritone", true)) + private val baritoneMode = register(Settings.b("Baritone", true)) private val infoMessage = register(Settings.b("Logs", true)) private val blocksPerTick = register(Settings.integerBuilder("BlocksPerTick").withMinimum(1).withValue(1).withMaximum(9).build()) private val tickDelay = register(Settings.integerBuilder("TickDelay").withMinimum(0).withValue(1).withMaximum(10).build()) @@ -60,12 +57,12 @@ class HighwayTools : Module() { //Stats var totalBlocksPlaced = 0 var totalBlocksDestroyed = 0 - var totalBlocksDistanceWent = 0 + private var totalBlocksDistanceWent = 0 val blockQueue: Queue = LinkedList() private val doneQueue: Queue = LinkedList() var a = mutableListOf>() - var waitTicks = 0 + private var waitTicks = 0 override fun onEnable() { if (mc.player == null) { @@ -76,11 +73,11 @@ class HighwayTools : Module() { playerHotbarSlot = mc.player.inventory.currentItem buildDirectionCoordinateSavedY = mc.player.positionVector.y - if (buildDirectionSaved == 0 || buildDirectionSaved == 2) { - buildDirectionCoordinateSaved = mc.player.positionVector.x + buildDirectionCoordinateSaved = if (buildDirectionSaved == 0 || buildDirectionSaved == 2) { + mc.player.positionVector.x } else { - buildDirectionCoordinateSaved = mc.player.positionVector.z + mc.player.positionVector.z } blockQueue.clear() @@ -89,13 +86,13 @@ class HighwayTools : Module() { MessageSendHelper.sendChatMessage("$chatName Module started." + "\n §9> §rSelected direction: §a" + directions[buildDirectionSaved] + "§r" + "\n §9> §rSnap to coordinate: §a" + buildDirectionCoordinateSaved.roundToInt() + "§r" + - "\n §9> §rBaritone mode: §a" + baritoneModee.value + "§r") + "\n §9> §rBaritone mode: §a" + baritoneMode.value + "§r") } override fun onUpdate() { if (!BaritoneAPI.getProvider().primaryBaritone.customGoalProcess.isActive) { if (isDone()) { - if (baritoneModee.value) { + if (baritoneMode.value) { moveOneBlock() } doneQueueReset() @@ -126,7 +123,7 @@ class HighwayTools : Module() { private fun doTask(): Boolean { if (!isDone()) { if (waitTicks == 0) { - var blockAction = blockQueue.peek() + val blockAction = blockQueue.peek() if (blockAction.getTaskState() == TaskState.BREAK) { mineBlock(blockAction.getBlockPos(), true) blockAction.setTaskState(TaskState.BREAKING) @@ -140,10 +137,19 @@ class HighwayTools : Module() { } } else if (blockAction.getTaskState() == TaskState.BREAKING) { mineBlock(blockAction.getBlockPos(), false) - if (blockAction.getBlock()) { - blockAction.setTaskState(TaskState.PLACE) + blockAction.setTaskState(TaskState.BROKE) + doTask() + } else if (blockAction.getTaskState() == TaskState.BROKE) { + val block = mc.world.getBlockState(blockAction.getBlockPos()).block + if (block is BlockAir) { + if (blockAction.getBlock()) { + blockAction.setTaskState(TaskState.PLACE) + } else { + blockAction.setTaskState(TaskState.DONE) + } + doTask() } else { - blockAction.setTaskState(TaskState.DONE) + blockAction.setTaskState(TaskState.BREAK) } } else if (blockAction.getTaskState() == TaskState.PLACE) { if (placeBlock(blockAction.getBlockPos())) { @@ -160,6 +166,7 @@ class HighwayTools : Module() { doTask() } } else { + MessageSendHelper.sendChatMessage(waitTicks.toString()) waitTicks-- } return true @@ -193,21 +200,24 @@ class HighwayTools : Module() { private fun moveOneBlock() { // set head rotation to get max walking speed - var nextBlockPos: BlockPos - if (buildDirectionSaved == 0) { - nextBlockPos = BlockPos(mc.player.positionVector).north() - mc.player.rotationYaw = -180F - } - else if (buildDirectionSaved == 1) { - nextBlockPos = BlockPos(mc.player.positionVector).east() - mc.player.rotationYaw = -90F - } - else if (buildDirectionSaved == 2) { - nextBlockPos = BlockPos(mc.player.positionVector).south() - mc.player.rotationYaw = 0F - } else { - nextBlockPos = BlockPos(mc.player.positionVector).west() - mc.player.rotationYaw = 90F + val nextBlockPos: BlockPos + when (buildDirectionSaved) { + 0 -> { + nextBlockPos = BlockPos(mc.player.positionVector).north() + mc.player.rotationYaw = -180F + } + 1 -> { + nextBlockPos = BlockPos(mc.player.positionVector).east() + mc.player.rotationYaw = -90F + } + 2 -> { + nextBlockPos = BlockPos(mc.player.positionVector).south() + mc.player.rotationYaw = 0F + } + else -> { + nextBlockPos = BlockPos(mc.player.positionVector).west() + mc.player.rotationYaw = 90F + } } mc.player.rotationPitch = 0F BaritoneAPI.getProvider().primaryBaritone.customGoalProcess.setGoalAndPath(GoalXZ(nextBlockPos.getX(), nextBlockPos.getZ())) @@ -262,6 +272,7 @@ class HighwayTools : Module() { //Swap to Obsidian in Hotbar or get from inventory if (InventoryUtils.getSlotsHotbar(49) == null && InventoryUtils.getSlotsNoHotbar(49) != null) { InventoryUtils.moveToHotbar(49, 130, (tickDelay.value * 16).toLong()) + InventoryUtils.quickMoveSlot(1, (tickDelay.value * 16).toLong()) return false } else if (InventoryUtils.getSlots(0, 35, 49) == null) { MessageSendHelper.sendChatMessage("$chatName No Obsidian was found in inventory, disabling.") @@ -315,7 +326,7 @@ class HighwayTools : Module() { private fun updateBlockArray() { a.clear() - var b = BlockPos(mc.player.positionVector) + val b = BlockPos(mc.player.positionVector) when(mode.value) { Mode.HIGHWAY -> { @@ -450,11 +461,14 @@ class HighwayTools : Module() { } } } + Mode.FLAT -> { + a.add(Pair((b), false)) + } } } fun isDone(): Boolean { return blockQueue.size == 0 } - fun doneQueueReset() { doneQueue.clear() } + private fun doneQueueReset() { doneQueue.clear() } override fun onWorldRender(event: RenderEvent) { if (mc.player == null) return @@ -467,11 +481,10 @@ class HighwayTools : Module() { fun getPlayerDirection(): Int { val yaw = (mc.player.rotationYaw % 360 + 360) % 360 - if (yaw >= 135 && yaw < 225) { return 0 } //NORTH - else if (yaw >= 225 && yaw < 315) { return 1 } //EAST - else if (yaw >= 315 || yaw < 45) { return 2 } //SOUTH - else if (yaw >= 45 && yaw < 135){ return 3 } //WEST - else { return -1 } //WRONG + return if (yaw >= 135 && yaw < 225) { 0 } //NORTH + else if (yaw >= 225 && yaw < 315) { 1 } //EAST + else if (yaw >= 315 || yaw < 45) { 2 } //SOUTH + else { 3 } //WEST } } @@ -485,6 +498,7 @@ class BlockTask(private val bp: BlockPos, private var tt: TaskState, private val enum class TaskState(val color: ColourHolder) { BREAK(ColourHolder(222, 0, 0)), BREAKING(ColourHolder(240, 222, 60)), + BROKE(ColourHolder(240, 77, 60)), PLACE(ColourHolder(35, 188, 254)), PLACED(ColourHolder(53, 222, 66)), DONE(ColourHolder(50, 50, 50)) From 9281da8df72b055b3439137e3209bfadea95535a Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 25 Aug 2020 19:53:05 +0200 Subject: [PATCH 005/390] Intelligent liquid handling - Added a liquid handling scoping at nether enviroment - Handles: Single lava blocks scattered in Netherrack, Small lava lakes, flowing lava removal in most cases --- .../kami/module/modules/misc/HighwayTools.kt | 73 ++++++++++++++++--- 1 file changed, 62 insertions(+), 11 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 5b5554fcf5..a59e9dc803 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -37,7 +37,6 @@ import kotlin.math.roundToInt class HighwayTools : Module() { private val mode = register(Settings.e("Mode", Mode.HIGHWAY)) private val baritoneMode = register(Settings.b("Baritone", true)) - private val infoMessage = register(Settings.b("Logs", true)) private val blocksPerTick = register(Settings.integerBuilder("BlocksPerTick").withMinimum(1).withValue(1).withMaximum(9).build()) private val tickDelay = register(Settings.integerBuilder("TickDelay").withMinimum(0).withValue(1).withMaximum(10).build()) private val rotate = register(Settings.b("Rotate", true)) @@ -63,6 +62,7 @@ class HighwayTools : Module() { private val doneQueue: Queue = LinkedList() var a = mutableListOf>() private var waitTicks = 0 + private var blocksPlaced = 0 override fun onEnable() { if (mc.player == null) { @@ -125,23 +125,55 @@ class HighwayTools : Module() { if (waitTicks == 0) { val blockAction = blockQueue.peek() if (blockAction.getTaskState() == TaskState.BREAK) { - mineBlock(blockAction.getBlockPos(), true) - blockAction.setTaskState(TaskState.BREAKING) val block = mc.world.getBlockState(blockAction.getBlockPos()).block - if (block is BlockNetherrack) { - waitTicks = 0 + for (side in EnumFacing.values()) { + val neighbour = blockAction.getBlockPos().offset(side) + var found = false + if (mc.world.getBlockState(neighbour).block is BlockLiquid) { + for (bt in blockQueue) { + if (bt.getBlockPos() == neighbour) { + found = true + } + } + if (!found) { + var inside_build = false + for ((pos, block) in a) { + if (neighbour == pos) { + if (!block) { inside_build = true } + } + } + if (inside_build) { + addTask(neighbour, TaskState.PLACE, false) + } else { + addTask(neighbour, TaskState.PLACE, true) + } + } + } + } + if (block is BlockAir) { + blockAction.setTaskState(TaskState.BROKE) + doTask() + } else if (block is BlockLiquid) { + blockAction.setTaskState(TaskState.PLACE) + doTask() } else { - val efficiencyLevel = 5 - waitTicks = (block.blockHardness * 5.0 / (8 + efficiencyLevel * efficiencyLevel + 1) / 20).toInt() - waitTicks = 20 + mineBlock(blockAction.getBlockPos(), true) + blockAction.setTaskState(TaskState.BREAKING) + if (block is BlockNetherrack) { + waitTicks = 0 + } else { + val efficiencyLevel = 5 + waitTicks = (block.blockHardness * 5.0 / (8 + efficiencyLevel * efficiencyLevel + 1) / 20).toInt() + waitTicks = 20 + } } } else if (blockAction.getTaskState() == TaskState.BREAKING) { mineBlock(blockAction.getBlockPos(), false) blockAction.setTaskState(TaskState.BROKE) - doTask() } else if (blockAction.getTaskState() == TaskState.BROKE) { val block = mc.world.getBlockState(blockAction.getBlockPos()).block if (block is BlockAir) { + totalBlocksDestroyed++ if (blockAction.getBlock()) { blockAction.setTaskState(TaskState.PLACE) } else { @@ -154,11 +186,22 @@ class HighwayTools : Module() { } else if (blockAction.getTaskState() == TaskState.PLACE) { if (placeBlock(blockAction.getBlockPos())) { blockAction.setTaskState(TaskState.PLACED) + if (blocksPerTick.value > blocksPlaced) { + blocksPlaced++ + doTask() + } else { + blocksPlaced = 0 + } + totalBlocksPlaced++ } else { return false } } else if (blockAction.getTaskState() == TaskState.PLACED) { - blockAction.setTaskState(TaskState.DONE) + if (blockAction.getBlock()) { + blockAction.setTaskState(TaskState.DONE) + } else { + blockAction.setTaskState(TaskState.BREAK) + } doTask() } else if (blockAction.getTaskState() == TaskState.DONE) { blockQueue.remove() @@ -462,7 +505,15 @@ class HighwayTools : Module() { } } Mode.FLAT -> { - a.add(Pair((b), false)) + a.add(Pair((b.down()), true)) + a.add(Pair((b.down().north()), true)) + a.add(Pair((b.down().east()), true)) + a.add(Pair((b.down().south()), true)) + a.add(Pair((b.down().west()), true)) + a.add(Pair((b.down().north().east()), true)) + a.add(Pair((b.down().north().west()), true)) + a.add(Pair((b.down().south().east()), true)) + a.add(Pair((b.down().south().west()), true)) } } } From 414ad7ed2316d3653c7ce80f88431b7aee3ff107 Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 25 Aug 2020 19:53:05 +0200 Subject: [PATCH 006/390] Intelligent liquid handling Video: https://youtu.be/JE6hEJNzIkU - Added a liquid handling scoping at nether enviroment - Handles: Single lava blocks scattered in Netherrack, Small lava lakes, flowing lava removal in most cases --- .../kami/module/modules/misc/HighwayTools.kt | 73 ++++++++++++++++--- 1 file changed, 62 insertions(+), 11 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 5b5554fcf5..a59e9dc803 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -37,7 +37,6 @@ import kotlin.math.roundToInt class HighwayTools : Module() { private val mode = register(Settings.e("Mode", Mode.HIGHWAY)) private val baritoneMode = register(Settings.b("Baritone", true)) - private val infoMessage = register(Settings.b("Logs", true)) private val blocksPerTick = register(Settings.integerBuilder("BlocksPerTick").withMinimum(1).withValue(1).withMaximum(9).build()) private val tickDelay = register(Settings.integerBuilder("TickDelay").withMinimum(0).withValue(1).withMaximum(10).build()) private val rotate = register(Settings.b("Rotate", true)) @@ -63,6 +62,7 @@ class HighwayTools : Module() { private val doneQueue: Queue = LinkedList() var a = mutableListOf>() private var waitTicks = 0 + private var blocksPlaced = 0 override fun onEnable() { if (mc.player == null) { @@ -125,23 +125,55 @@ class HighwayTools : Module() { if (waitTicks == 0) { val blockAction = blockQueue.peek() if (blockAction.getTaskState() == TaskState.BREAK) { - mineBlock(blockAction.getBlockPos(), true) - blockAction.setTaskState(TaskState.BREAKING) val block = mc.world.getBlockState(blockAction.getBlockPos()).block - if (block is BlockNetherrack) { - waitTicks = 0 + for (side in EnumFacing.values()) { + val neighbour = blockAction.getBlockPos().offset(side) + var found = false + if (mc.world.getBlockState(neighbour).block is BlockLiquid) { + for (bt in blockQueue) { + if (bt.getBlockPos() == neighbour) { + found = true + } + } + if (!found) { + var inside_build = false + for ((pos, block) in a) { + if (neighbour == pos) { + if (!block) { inside_build = true } + } + } + if (inside_build) { + addTask(neighbour, TaskState.PLACE, false) + } else { + addTask(neighbour, TaskState.PLACE, true) + } + } + } + } + if (block is BlockAir) { + blockAction.setTaskState(TaskState.BROKE) + doTask() + } else if (block is BlockLiquid) { + blockAction.setTaskState(TaskState.PLACE) + doTask() } else { - val efficiencyLevel = 5 - waitTicks = (block.blockHardness * 5.0 / (8 + efficiencyLevel * efficiencyLevel + 1) / 20).toInt() - waitTicks = 20 + mineBlock(blockAction.getBlockPos(), true) + blockAction.setTaskState(TaskState.BREAKING) + if (block is BlockNetherrack) { + waitTicks = 0 + } else { + val efficiencyLevel = 5 + waitTicks = (block.blockHardness * 5.0 / (8 + efficiencyLevel * efficiencyLevel + 1) / 20).toInt() + waitTicks = 20 + } } } else if (blockAction.getTaskState() == TaskState.BREAKING) { mineBlock(blockAction.getBlockPos(), false) blockAction.setTaskState(TaskState.BROKE) - doTask() } else if (blockAction.getTaskState() == TaskState.BROKE) { val block = mc.world.getBlockState(blockAction.getBlockPos()).block if (block is BlockAir) { + totalBlocksDestroyed++ if (blockAction.getBlock()) { blockAction.setTaskState(TaskState.PLACE) } else { @@ -154,11 +186,22 @@ class HighwayTools : Module() { } else if (blockAction.getTaskState() == TaskState.PLACE) { if (placeBlock(blockAction.getBlockPos())) { blockAction.setTaskState(TaskState.PLACED) + if (blocksPerTick.value > blocksPlaced) { + blocksPlaced++ + doTask() + } else { + blocksPlaced = 0 + } + totalBlocksPlaced++ } else { return false } } else if (blockAction.getTaskState() == TaskState.PLACED) { - blockAction.setTaskState(TaskState.DONE) + if (blockAction.getBlock()) { + blockAction.setTaskState(TaskState.DONE) + } else { + blockAction.setTaskState(TaskState.BREAK) + } doTask() } else if (blockAction.getTaskState() == TaskState.DONE) { blockQueue.remove() @@ -462,7 +505,15 @@ class HighwayTools : Module() { } } Mode.FLAT -> { - a.add(Pair((b), false)) + a.add(Pair((b.down()), true)) + a.add(Pair((b.down().north()), true)) + a.add(Pair((b.down().east()), true)) + a.add(Pair((b.down().south()), true)) + a.add(Pair((b.down().west()), true)) + a.add(Pair((b.down().north().east()), true)) + a.add(Pair((b.down().north().west()), true)) + a.add(Pair((b.down().south().east()), true)) + a.add(Pair((b.down().south().west()), true)) } } } From 04efe368c5e66d8f2457aa078b5235dce77de574 Mon Sep 17 00:00:00 2001 From: Christian Date: Wed, 26 Aug 2020 00:49:36 +0200 Subject: [PATCH 007/390] Added diagonals Demo: https://youtu.be/JgVrYJKtYcc The tool supports 8 directions now --- .../kami/module/modules/misc/HighwayTools.kt | 474 ++++++++++++------ 1 file changed, 325 insertions(+), 149 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index a59e9dc803..bc4f38ace6 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -49,7 +49,7 @@ class HighwayTools : Module() { private var buildDirectionSaved = 0 private var buildDirectionCoordinateSaved = 0.0 private var buildDirectionCoordinateSavedY = 0.0 - private val directions = listOf("North", "East", "South", "West") + private val directions = listOf("North", "North-East", "East", "South-East", "South", "South-West", "West", "North-West") private var isSneaking = false @@ -60,7 +60,7 @@ class HighwayTools : Module() { val blockQueue: Queue = LinkedList() private val doneQueue: Queue = LinkedList() - var a = mutableListOf>() + private var blockOffsets = mutableListOf>() private var waitTicks = 0 private var blocksPlaced = 0 @@ -109,7 +109,7 @@ class HighwayTools : Module() { blockQueue.add(BlockTask(bps, ts, bb)) } - private fun getDebug() { + private fun printDebug() { MessageSendHelper.sendChatMessage("#### LOG ####") for (bt in blockQueue) { MessageSendHelper.sendChatMessage(bt.getBlockPos().toString() + " " + bt.getTaskState().toString() + " " + bt.getBlock().toString()) @@ -137,7 +137,7 @@ class HighwayTools : Module() { } if (!found) { var inside_build = false - for ((pos, block) in a) { + for ((pos, block) in blockOffsets) { if (neighbour == pos) { if (!block) { inside_build = true } } @@ -159,12 +159,12 @@ class HighwayTools : Module() { } else { mineBlock(blockAction.getBlockPos(), true) blockAction.setTaskState(TaskState.BREAKING) - if (block is BlockNetherrack) { + if (block is BlockNetherrack || block is BlockMagma) { waitTicks = 0 } else { - val efficiencyLevel = 5 - waitTicks = (block.blockHardness * 5.0 / (8 + efficiencyLevel * efficiencyLevel + 1) / 20).toInt() - waitTicks = 20 + //val efficiencyLevel = 5 + //waitTicks = (block.blockHardness * 5.0 / (8 + efficiencyLevel * efficiencyLevel + 1) / 20).toInt() + waitTicks = 5 } } } else if (blockAction.getTaskState() == TaskState.BREAKING) { @@ -186,7 +186,7 @@ class HighwayTools : Module() { } else if (blockAction.getTaskState() == TaskState.PLACE) { if (placeBlock(blockAction.getBlockPos())) { blockAction.setTaskState(TaskState.PLACED) - if (blocksPerTick.value > blocksPlaced) { + if (blocksPerTick.value > blocksPlaced + 1) { blocksPlaced++ doTask() } else { @@ -220,7 +220,7 @@ class HighwayTools : Module() { private fun updateTasks() { updateBlockArray() - for ((a, b) in a) { + for ((a, b) in blockOffsets) { val block = mc.world.getBlockState(a).block if (b && block is BlockAir) { addTask(a, TaskState.PLACE, true) } else if (b && block !is BlockAir && block !is BlockObsidian) { addTask(a, TaskState.BREAK, true) } @@ -250,17 +250,33 @@ class HighwayTools : Module() { mc.player.rotationYaw = -180F } 1 -> { + nextBlockPos = BlockPos(mc.player.positionVector).north().east() + mc.player.rotationYaw = -135F + } + 2 -> { nextBlockPos = BlockPos(mc.player.positionVector).east() mc.player.rotationYaw = -90F } - 2 -> { + 3 -> { + nextBlockPos = BlockPos(mc.player.positionVector).south().east() + mc.player.rotationYaw = -45F + } + 4 -> { nextBlockPos = BlockPos(mc.player.positionVector).south() mc.player.rotationYaw = 0F } - else -> { + 5 -> { + nextBlockPos = BlockPos(mc.player.positionVector).south().west() + mc.player.rotationYaw = 45F + } + 6 -> { nextBlockPos = BlockPos(mc.player.positionVector).west() mc.player.rotationYaw = 90F } + else -> { + nextBlockPos = BlockPos(mc.player.positionVector).north().west() + mc.player.rotationYaw = 135F + } } mc.player.rotationPitch = 0F BaritoneAPI.getProvider().primaryBaritone.customGoalProcess.setGoalAndPath(GoalXZ(nextBlockPos.getX(), nextBlockPos.getZ())) @@ -368,152 +384,308 @@ class HighwayTools : Module() { } private fun updateBlockArray() { - a.clear() + blockOffsets.clear() val b = BlockPos(mc.player.positionVector) when(mode.value) { Mode.HIGHWAY -> { when (buildDirectionSaved) { 0 -> { //NORTH - a.add(Pair(b.down(), true)) - a.add(Pair(b.down().north(), true)) - a.add(Pair(b.down().north().north(), true)) - a.add(Pair(b.down().north().north().east(), true)) - a.add(Pair(b.down().north().north().west(), true)) - a.add(Pair(b.down().north().north().east().east(), true)) - a.add(Pair(b.down().north().north().west().west(), true)) - a.add(Pair(b.down().north().north().east().east().east(), true)) - a.add(Pair(b.down().north().north().west().west().west(), true)) - a.add(Pair(b.north().north().east().east().east(), true)) - a.add(Pair(b.north().north().west().west().west(), true)) - a.add(Pair(b.north().north(), false)) - a.add(Pair(b.north().north().east(), false)) - a.add(Pair(b.north().north().west(), false)) - a.add(Pair(b.north().north().east().east(), false)) - a.add(Pair(b.north().north().west().west(), false)) - a.add(Pair(b.up().north().north(), false)) - a.add(Pair(b.up().north().north().east(), false)) - a.add(Pair(b.up().north().north().west(), false)) - a.add(Pair(b.up().north().north().east().east(), false)) - a.add(Pair(b.up().north().north().west().west(), false)) - a.add(Pair(b.up().north().north().east().east().east(), false)) - a.add(Pair(b.up().north().north().west().west().west(), false)) - a.add(Pair(b.up().up().north().north(), false)) - a.add(Pair(b.up().up().north().north().east(), false)) - a.add(Pair(b.up().up().north().north().west(), false)) - a.add(Pair(b.up().up().north().north().east().east(), false)) - a.add(Pair(b.up().up().north().north().west().west(), false)) - a.add(Pair(b.up().up().north().north().east().east().east(), false)) - a.add(Pair(b.up().up().north().north().west().west().west(), false)) + blockOffsets.add(Pair(b.down(), true)) + blockOffsets.add(Pair(b.down().north(), true)) + blockOffsets.add(Pair(b.down().north().north(), true)) + blockOffsets.add(Pair(b.down().north().north().east(), true)) + blockOffsets.add(Pair(b.down().north().north().west(), true)) + blockOffsets.add(Pair(b.down().north().north().east().east(), true)) + blockOffsets.add(Pair(b.down().north().north().west().west(), true)) + blockOffsets.add(Pair(b.down().north().north().east().east().east(), true)) + blockOffsets.add(Pair(b.down().north().north().west().west().west(), true)) + blockOffsets.add(Pair(b.north().north().east().east().east(), true)) + blockOffsets.add(Pair(b.north().north().west().west().west(), true)) + blockOffsets.add(Pair(b.north().north(), false)) + blockOffsets.add(Pair(b.north().north().east(), false)) + blockOffsets.add(Pair(b.north().north().west(), false)) + blockOffsets.add(Pair(b.north().north().east().east(), false)) + blockOffsets.add(Pair(b.north().north().west().west(), false)) + blockOffsets.add(Pair(b.up().north().north(), false)) + blockOffsets.add(Pair(b.up().north().north().east(), false)) + blockOffsets.add(Pair(b.up().north().north().west(), false)) + blockOffsets.add(Pair(b.up().north().north().east().east(), false)) + blockOffsets.add(Pair(b.up().north().north().west().west(), false)) + blockOffsets.add(Pair(b.up().north().north().east().east().east(), false)) + blockOffsets.add(Pair(b.up().north().north().west().west().west(), false)) + blockOffsets.add(Pair(b.up().up().north().north(), false)) + blockOffsets.add(Pair(b.up().up().north().north().east(), false)) + blockOffsets.add(Pair(b.up().up().north().north().west(), false)) + blockOffsets.add(Pair(b.up().up().north().north().east().east(), false)) + blockOffsets.add(Pair(b.up().up().north().north().west().west(), false)) + blockOffsets.add(Pair(b.up().up().north().north().east().east().east(), false)) + blockOffsets.add(Pair(b.up().up().north().north().west().west().west(), false)) + } + 1 -> { // NORTH-EAST + blockOffsets.add(Pair(b.north().east().down(), true)) + blockOffsets.add(Pair(b.north().east().down().north(), true)) + blockOffsets.add(Pair(b.north().east().down().east(), true)) + blockOffsets.add(Pair(b.north().east().down().north().east(), true)) + blockOffsets.add(Pair(b.north().east().down().north().north(), true)) + blockOffsets.add(Pair(b.north().east().down().east().east(), true)) + blockOffsets.add(Pair(b.north().east().down().east().east().south(), true)) + blockOffsets.add(Pair(b.north().east().down().north().north().west(), true)) + blockOffsets.add(Pair(b.north().east().down().east().east().south().east(), true)) + blockOffsets.add(Pair(b.north().east().down().north().north().west().north(), true)) + blockOffsets.add(Pair(b.north().east().east().east().south().east(), true)) + blockOffsets.add(Pair(b.north().east().north().north().west().north(), true)) + blockOffsets.add(Pair(b.north().east().north(), false)) + blockOffsets.add(Pair(b.north().east().north().up(), false)) + blockOffsets.add(Pair(b.north().east().north().up().up(), false)) + blockOffsets.add(Pair(b.north().east().east(), false)) + blockOffsets.add(Pair(b.north().east().east().up(), false)) + blockOffsets.add(Pair(b.north().east().east().up().up(), false)) + blockOffsets.add(Pair(b.north().east().north().east(), false)) + blockOffsets.add(Pair(b.north().east().north().east().up(), false)) + blockOffsets.add(Pair(b.north().east().north().east().up().up(), false)) + blockOffsets.add(Pair(b.north().east().north().north(), false)) + blockOffsets.add(Pair(b.north().east().north().north().up(), false)) + blockOffsets.add(Pair(b.north().east().north().north().up().up(), false)) + blockOffsets.add(Pair(b.north().east().east().east(), false)) + blockOffsets.add(Pair(b.north().east().east().east().up(), false)) + blockOffsets.add(Pair(b.north().east().east().east().up().up(), false)) + blockOffsets.add(Pair(b.north().east().north().north().west(), false)) + blockOffsets.add(Pair(b.north().east().north().north().west().up(), false)) + blockOffsets.add(Pair(b.north().east().north().north().west().up().up(), false)) + blockOffsets.add(Pair(b.north().east().east().east().south(), false)) + blockOffsets.add(Pair(b.north().east().east().east().south().up(), false)) + blockOffsets.add(Pair(b.north().east().east().east().south().up().up(), false)) + blockOffsets.add(Pair(b.north().east().north().north().west().north().up(), false)) + blockOffsets.add(Pair(b.north().east().north().north().west().north().up().up(), false)) + blockOffsets.add(Pair(b.north().east().east().east().south().east().up(), false)) + blockOffsets.add(Pair(b.north().east().east().east().south().east().up().up(), false)) + } + 2 -> { //EAST + blockOffsets.add(Pair(b.down(), true)) + blockOffsets.add(Pair(b.down().east(), true)) + blockOffsets.add(Pair(b.down().east().east(), true)) + blockOffsets.add(Pair(b.down().east().east().south(), true)) + blockOffsets.add(Pair(b.down().east().east().north(), true)) + blockOffsets.add(Pair(b.down().east().east().south().south(), true)) + blockOffsets.add(Pair(b.down().east().east().north().north(), true)) + blockOffsets.add(Pair(b.down().east().east().south().south().south(), true)) + blockOffsets.add(Pair(b.down().east().east().north().north().north(), true)) + blockOffsets.add(Pair(b.east().east().south().south().south(), true)) + blockOffsets.add(Pair(b.east().east().north().north().north(), true)) + blockOffsets.add(Pair(b.east().east(), false)) + blockOffsets.add(Pair(b.east().east().south(), false)) + blockOffsets.add(Pair(b.east().east().north(), false)) + blockOffsets.add(Pair(b.east().east().south().south(), false)) + blockOffsets.add(Pair(b.east().east().north().north(), false)) + blockOffsets.add(Pair(b.up().east().east(), false)) + blockOffsets.add(Pair(b.up().east().east().south(), false)) + blockOffsets.add(Pair(b.up().east().east().north(), false)) + blockOffsets.add(Pair(b.up().east().east().south().south(), false)) + blockOffsets.add(Pair(b.up().east().east().north().north(), false)) + blockOffsets.add(Pair(b.up().east().east().south().south().south(), false)) + blockOffsets.add(Pair(b.up().east().east().north().north().north(), false)) + blockOffsets.add(Pair(b.up().up().east().east(), false)) + blockOffsets.add(Pair(b.up().up().east().east().south(), false)) + blockOffsets.add(Pair(b.up().up().east().east().north(), false)) + blockOffsets.add(Pair(b.up().up().east().east().south().south(), false)) + blockOffsets.add(Pair(b.up().up().east().east().north().north(), false)) + blockOffsets.add(Pair(b.up().up().east().east().south().south().south(), false)) + blockOffsets.add(Pair(b.up().up().east().east().north().north().north(), false)) + } + 3 -> { //SOUTH-EAST + blockOffsets.add(Pair(b.east().south().down(), true)) + blockOffsets.add(Pair(b.east().south().down().east(), true)) + blockOffsets.add(Pair(b.east().south().down().south(), true)) + blockOffsets.add(Pair(b.east().south().down().east().south(), true)) + blockOffsets.add(Pair(b.east().south().down().east().east(), true)) + blockOffsets.add(Pair(b.east().south().down().south().south(), true)) + blockOffsets.add(Pair(b.east().south().down().south().south().west(), true)) + blockOffsets.add(Pair(b.east().south().down().east().east().north(), true)) + blockOffsets.add(Pair(b.east().south().down().south().south().west().south(), true)) + blockOffsets.add(Pair(b.east().south().down().east().east().north().east(), true)) + blockOffsets.add(Pair(b.east().south().south().south().west().south(), true)) + blockOffsets.add(Pair(b.east().south().east().east().north().east(), true)) + blockOffsets.add(Pair(b.east().south().east(), false)) + blockOffsets.add(Pair(b.east().south().east().up(), false)) + blockOffsets.add(Pair(b.east().south().east().up().up(), false)) + blockOffsets.add(Pair(b.east().south().south(), false)) + blockOffsets.add(Pair(b.east().south().south().up(), false)) + blockOffsets.add(Pair(b.east().south().south().up().up(), false)) + blockOffsets.add(Pair(b.east().south().east().south(), false)) + blockOffsets.add(Pair(b.east().south().east().south().up(), false)) + blockOffsets.add(Pair(b.east().south().east().south().up().up(), false)) + blockOffsets.add(Pair(b.east().south().east().east(), false)) + blockOffsets.add(Pair(b.east().south().east().east().up(), false)) + blockOffsets.add(Pair(b.east().south().east().east().up().up(), false)) + blockOffsets.add(Pair(b.east().south().south().south(), false)) + blockOffsets.add(Pair(b.east().south().south().south().up(), false)) + blockOffsets.add(Pair(b.east().south().south().south().up().up(), false)) + blockOffsets.add(Pair(b.east().south().east().east().north(), false)) + blockOffsets.add(Pair(b.east().south().east().east().north().up(), false)) + blockOffsets.add(Pair(b.east().south().east().east().north().up().up(), false)) + blockOffsets.add(Pair(b.east().south().south().south().west(), false)) + blockOffsets.add(Pair(b.east().south().south().south().west().up(), false)) + blockOffsets.add(Pair(b.east().south().south().south().west().up().up(), false)) + blockOffsets.add(Pair(b.east().south().east().east().north().east().up(), false)) + blockOffsets.add(Pair(b.east().south().east().east().north().east().up().up(), false)) + blockOffsets.add(Pair(b.east().south().south().south().west().south().up(), false)) + blockOffsets.add(Pair(b.east().south().south().south().west().south().up().up(), false)) + } + 4 -> { //SOUTH + blockOffsets.add(Pair(b.down(), true)) + blockOffsets.add(Pair(b.down().south(), true)) + blockOffsets.add(Pair(b.down().south().south(), true)) + blockOffsets.add(Pair(b.down().south().south().east(), true)) + blockOffsets.add(Pair(b.down().south().south().west(), true)) + blockOffsets.add(Pair(b.down().south().south().east().east(), true)) + blockOffsets.add(Pair(b.down().south().south().west().west(), true)) + blockOffsets.add(Pair(b.down().south().south().east().east().east(), true)) + blockOffsets.add(Pair(b.down().south().south().west().west().west(), true)) + blockOffsets.add(Pair(b.south().south().east().east().east(), true)) + blockOffsets.add(Pair(b.south().south().west().west().west(), true)) + blockOffsets.add(Pair(b.south().south(), false)) + blockOffsets.add(Pair(b.south().south().east(), false)) + blockOffsets.add(Pair(b.south().south().west(), false)) + blockOffsets.add(Pair(b.south().south().east().east(), false)) + blockOffsets.add(Pair(b.south().south().west().west(), false)) + blockOffsets.add(Pair(b.up().south().south(), false)) + blockOffsets.add(Pair(b.up().south().south().east(), false)) + blockOffsets.add(Pair(b.up().south().south().west(), false)) + blockOffsets.add(Pair(b.up().south().south().east().east(), false)) + blockOffsets.add(Pair(b.up().south().south().west().west(), false)) + blockOffsets.add(Pair(b.up().south().south().east().east().east(), false)) + blockOffsets.add(Pair(b.up().south().south().west().west().west(), false)) + blockOffsets.add(Pair(b.up().up().south().south(), false)) + blockOffsets.add(Pair(b.up().up().south().south().east(), false)) + blockOffsets.add(Pair(b.up().up().south().south().west(), false)) + blockOffsets.add(Pair(b.up().up().south().south().east().east(), false)) + blockOffsets.add(Pair(b.up().up().south().south().west().west(), false)) + blockOffsets.add(Pair(b.up().up().south().south().east().east().east(), false)) + blockOffsets.add(Pair(b.up().up().south().south().west().west().west(), false)) } - 1 -> { //EAST - a.add(Pair(b.down(), true)) - a.add(Pair(b.down().east(), true)) - a.add(Pair(b.down().east().east(), true)) - a.add(Pair(b.down().east().east().south(), true)) - a.add(Pair(b.down().east().east().north(), true)) - a.add(Pair(b.down().east().east().south().south(), true)) - a.add(Pair(b.down().east().east().north().north(), true)) - a.add(Pair(b.down().east().east().south().south().south(), true)) - a.add(Pair(b.down().east().east().north().north().north(), true)) - a.add(Pair(b.east().east().south().south().south(), true)) - a.add(Pair(b.east().east().north().north().north(), true)) - a.add(Pair(b.east().east(), false)) - a.add(Pair(b.east().east().south(), false)) - a.add(Pair(b.east().east().north(), false)) - a.add(Pair(b.east().east().south().south(), false)) - a.add(Pair(b.east().east().north().north(), false)) - a.add(Pair(b.up().east().east(), false)) - a.add(Pair(b.up().east().east().south(), false)) - a.add(Pair(b.up().east().east().north(), false)) - a.add(Pair(b.up().east().east().south().south(), false)) - a.add(Pair(b.up().east().east().north().north(), false)) - a.add(Pair(b.up().east().east().south().south().south(), false)) - a.add(Pair(b.up().east().east().north().north().north(), false)) - a.add(Pair(b.up().up().east().east(), false)) - a.add(Pair(b.up().up().east().east().south(), false)) - a.add(Pair(b.up().up().east().east().north(), false)) - a.add(Pair(b.up().up().east().east().south().south(), false)) - a.add(Pair(b.up().up().east().east().north().north(), false)) - a.add(Pair(b.up().up().east().east().south().south().south(), false)) - a.add(Pair(b.up().up().east().east().north().north().north(), false)) + 5 -> { // SOUTH-WEST + blockOffsets.add(Pair(b.south().west().down(), true)) + blockOffsets.add(Pair(b.south().west().down().south(), true)) + blockOffsets.add(Pair(b.south().west().down().west(), true)) + blockOffsets.add(Pair(b.south().west().down().south().west(), true)) + blockOffsets.add(Pair(b.south().west().down().south().south(), true)) + blockOffsets.add(Pair(b.south().west().down().west().west(), true)) + blockOffsets.add(Pair(b.south().west().down().west().west().north(), true)) + blockOffsets.add(Pair(b.south().west().down().south().south().east(), true)) + blockOffsets.add(Pair(b.south().west().down().west().west().north().west(), true)) + blockOffsets.add(Pair(b.south().west().down().south().south().east().south(), true)) + blockOffsets.add(Pair(b.south().west().west().west().north().west(), true)) + blockOffsets.add(Pair(b.south().west().south().south().east().south(), true)) + blockOffsets.add(Pair(b.south().west().south(), false)) + blockOffsets.add(Pair(b.south().west().south().up(), false)) + blockOffsets.add(Pair(b.south().west().south().up().up(), false)) + blockOffsets.add(Pair(b.south().west().west(), false)) + blockOffsets.add(Pair(b.south().west().west().up(), false)) + blockOffsets.add(Pair(b.south().west().west().up().up(), false)) + blockOffsets.add(Pair(b.south().west().south().west(), false)) + blockOffsets.add(Pair(b.south().west().south().west().up(), false)) + blockOffsets.add(Pair(b.south().west().south().west().up().up(), false)) + blockOffsets.add(Pair(b.south().west().south().south(), false)) + blockOffsets.add(Pair(b.south().west().south().south().up(), false)) + blockOffsets.add(Pair(b.south().west().south().south().up().up(), false)) + blockOffsets.add(Pair(b.south().west().west().west(), false)) + blockOffsets.add(Pair(b.south().west().west().west().up(), false)) + blockOffsets.add(Pair(b.south().west().west().west().up().up(), false)) + blockOffsets.add(Pair(b.south().west().south().south().east(), false)) + blockOffsets.add(Pair(b.south().west().south().south().east().up(), false)) + blockOffsets.add(Pair(b.south().west().south().south().east().up().up(), false)) + blockOffsets.add(Pair(b.south().west().west().west().north(), false)) + blockOffsets.add(Pair(b.south().west().west().west().north().up(), false)) + blockOffsets.add(Pair(b.south().west().west().west().north().up().up(), false)) + blockOffsets.add(Pair(b.south().west().south().south().east().south().up(), false)) + blockOffsets.add(Pair(b.south().west().south().south().east().south().up().up(), false)) + blockOffsets.add(Pair(b.south().west().west().west().north().west().up(), false)) + blockOffsets.add(Pair(b.south().west().west().west().north().west().up().up(), false)) } - 2 -> { //SOUTH - a.add(Pair(b.down(), true)) - a.add(Pair(b.down().south(), true)) - a.add(Pair(b.down().south().south(), true)) - a.add(Pair(b.down().south().south().east(), true)) - a.add(Pair(b.down().south().south().west(), true)) - a.add(Pair(b.down().south().south().east().east(), true)) - a.add(Pair(b.down().south().south().west().west(), true)) - a.add(Pair(b.down().south().south().east().east().east(), true)) - a.add(Pair(b.down().south().south().west().west().west(), true)) - a.add(Pair(b.south().south().east().east().east(), true)) - a.add(Pair(b.south().south().west().west().west(), true)) - a.add(Pair(b.south().south(), false)) - a.add(Pair(b.south().south().east(), false)) - a.add(Pair(b.south().south().west(), false)) - a.add(Pair(b.south().south().east().east(), false)) - a.add(Pair(b.south().south().west().west(), false)) - a.add(Pair(b.up().south().south(), false)) - a.add(Pair(b.up().south().south().east(), false)) - a.add(Pair(b.up().south().south().west(), false)) - a.add(Pair(b.up().south().south().east().east(), false)) - a.add(Pair(b.up().south().south().west().west(), false)) - a.add(Pair(b.up().south().south().east().east().east(), false)) - a.add(Pair(b.up().south().south().west().west().west(), false)) - a.add(Pair(b.up().up().south().south(), false)) - a.add(Pair(b.up().up().south().south().east(), false)) - a.add(Pair(b.up().up().south().south().west(), false)) - a.add(Pair(b.up().up().south().south().east().east(), false)) - a.add(Pair(b.up().up().south().south().west().west(), false)) - a.add(Pair(b.up().up().south().south().east().east().east(), false)) - a.add(Pair(b.up().up().south().south().west().west().west(), false)) + 6 -> { //WEST + blockOffsets.add(Pair(b.down(), true)) + blockOffsets.add(Pair(b.down().west(), true)) + blockOffsets.add(Pair(b.down().west().west(), true)) + blockOffsets.add(Pair(b.down().west().west().south(), true)) + blockOffsets.add(Pair(b.down().west().west().north(), true)) + blockOffsets.add(Pair(b.down().west().west().south().south(), true)) + blockOffsets.add(Pair(b.down().west().west().north().north(), true)) + blockOffsets.add(Pair(b.down().west().west().south().south().south(), true)) + blockOffsets.add(Pair(b.down().west().west().north().north().north(), true)) + blockOffsets.add(Pair(b.west().west().south().south().south(), true)) + blockOffsets.add(Pair(b.west().west().north().north().north(), true)) + blockOffsets.add(Pair(b.west().west(), false)) + blockOffsets.add(Pair(b.west().west().south(), false)) + blockOffsets.add(Pair(b.west().west().north(), false)) + blockOffsets.add(Pair(b.west().west().south().south(), false)) + blockOffsets.add(Pair(b.west().west().north().north(), false)) + blockOffsets.add(Pair(b.up().west().west(), false)) + blockOffsets.add(Pair(b.up().west().west().south(), false)) + blockOffsets.add(Pair(b.up().west().west().north(), false)) + blockOffsets.add(Pair(b.up().west().west().south().south(), false)) + blockOffsets.add(Pair(b.up().west().west().north().north(), false)) + blockOffsets.add(Pair(b.up().west().west().south().south().south(), false)) + blockOffsets.add(Pair(b.up().west().west().north().north().north(), false)) + blockOffsets.add(Pair(b.up().up().west().west(), false)) + blockOffsets.add(Pair(b.up().up().west().west().south(), false)) + blockOffsets.add(Pair(b.up().up().west().west().north(), false)) + blockOffsets.add(Pair(b.up().up().west().west().south().south(), false)) + blockOffsets.add(Pair(b.up().up().west().west().north().north(), false)) + blockOffsets.add(Pair(b.up().up().west().west().south().south().south(), false)) + blockOffsets.add(Pair(b.up().up().west().west().north().north().north(), false)) } - 3 -> { //WEST - a.add(Pair(b.down(), true)) - a.add(Pair(b.down().west(), true)) - a.add(Pair(b.down().west().west(), true)) - a.add(Pair(b.down().west().west().south(), true)) - a.add(Pair(b.down().west().west().north(), true)) - a.add(Pair(b.down().west().west().south().south(), true)) - a.add(Pair(b.down().west().west().north().north(), true)) - a.add(Pair(b.down().west().west().south().south().south(), true)) - a.add(Pair(b.down().west().west().north().north().north(), true)) - a.add(Pair(b.west().west().south().south().south(), true)) - a.add(Pair(b.west().west().north().north().north(), true)) - a.add(Pair(b.west().west(), false)) - a.add(Pair(b.west().west().south(), false)) - a.add(Pair(b.west().west().north(), false)) - a.add(Pair(b.west().west().south().south(), false)) - a.add(Pair(b.west().west().north().north(), false)) - a.add(Pair(b.up().west().west(), false)) - a.add(Pair(b.up().west().west().south(), false)) - a.add(Pair(b.up().west().west().north(), false)) - a.add(Pair(b.up().west().west().south().south(), false)) - a.add(Pair(b.up().west().west().north().north(), false)) - a.add(Pair(b.up().west().west().south().south().south(), false)) - a.add(Pair(b.up().west().west().north().north().north(), false)) - a.add(Pair(b.up().up().west().west(), false)) - a.add(Pair(b.up().up().west().west().south(), false)) - a.add(Pair(b.up().up().west().west().north(), false)) - a.add(Pair(b.up().up().west().west().south().south(), false)) - a.add(Pair(b.up().up().west().west().north().north(), false)) - a.add(Pair(b.up().up().west().west().south().south().south(), false)) - a.add(Pair(b.up().up().west().west().north().north().north(), false)) + 7 -> { //NORTH-WEST + blockOffsets.add(Pair(b.west().north().down(), true)) + blockOffsets.add(Pair(b.west().north().down().west(), true)) + blockOffsets.add(Pair(b.west().north().down().north(), true)) + blockOffsets.add(Pair(b.west().north().down().west().north(), true)) + blockOffsets.add(Pair(b.west().north().down().west().west(), true)) + blockOffsets.add(Pair(b.west().north().down().north().north(), true)) + blockOffsets.add(Pair(b.west().north().down().north().north().east(), true)) + blockOffsets.add(Pair(b.west().north().down().west().west().south(), true)) + blockOffsets.add(Pair(b.west().north().down().north().north().east().north(), true)) + blockOffsets.add(Pair(b.west().north().down().west().west().south().west(), true)) + blockOffsets.add(Pair(b.west().north().north().north().east().north(), true)) + blockOffsets.add(Pair(b.west().north().west().west().south().west(), true)) + blockOffsets.add(Pair(b.west().north().west(), false)) + blockOffsets.add(Pair(b.west().north().west().up(), false)) + blockOffsets.add(Pair(b.west().north().west().up().up(), false)) + blockOffsets.add(Pair(b.west().north().north(), false)) + blockOffsets.add(Pair(b.west().north().north().up(), false)) + blockOffsets.add(Pair(b.west().north().north().up().up(), false)) + blockOffsets.add(Pair(b.west().north().west().north(), false)) + blockOffsets.add(Pair(b.west().north().west().north().up(), false)) + blockOffsets.add(Pair(b.west().north().west().north().up().up(), false)) + blockOffsets.add(Pair(b.west().north().west().west(), false)) + blockOffsets.add(Pair(b.west().north().west().west().up(), false)) + blockOffsets.add(Pair(b.west().north().west().west().up().up(), false)) + blockOffsets.add(Pair(b.west().north().north().north(), false)) + blockOffsets.add(Pair(b.west().north().north().north().up(), false)) + blockOffsets.add(Pair(b.west().north().north().north().up().up(), false)) + blockOffsets.add(Pair(b.west().north().west().west().south(), false)) + blockOffsets.add(Pair(b.west().north().west().west().south().up(), false)) + blockOffsets.add(Pair(b.west().north().west().west().south().up().up(), false)) + blockOffsets.add(Pair(b.west().north().north().north().east(), false)) + blockOffsets.add(Pair(b.west().north().north().north().east().up(), false)) + blockOffsets.add(Pair(b.west().north().north().north().east().up().up(), false)) + blockOffsets.add(Pair(b.west().north().west().west().south().west().up(), false)) + blockOffsets.add(Pair(b.west().north().west().west().south().west().up().up(), false)) + blockOffsets.add(Pair(b.west().north().north().north().east().north().up(), false)) + blockOffsets.add(Pair(b.west().north().north().north().east().north().up().up(), false)) } } } Mode.FLAT -> { - a.add(Pair((b.down()), true)) - a.add(Pair((b.down().north()), true)) - a.add(Pair((b.down().east()), true)) - a.add(Pair((b.down().south()), true)) - a.add(Pair((b.down().west()), true)) - a.add(Pair((b.down().north().east()), true)) - a.add(Pair((b.down().north().west()), true)) - a.add(Pair((b.down().south().east()), true)) - a.add(Pair((b.down().south().west()), true)) + blockOffsets.add(Pair((b.down()), true)) + blockOffsets.add(Pair((b.down().north()), true)) + blockOffsets.add(Pair((b.down().east()), true)) + blockOffsets.add(Pair((b.down().south()), true)) + blockOffsets.add(Pair((b.down().west()), true)) + blockOffsets.add(Pair((b.down().north().east()), true)) + blockOffsets.add(Pair((b.down().north().west()), true)) + blockOffsets.add(Pair((b.down().south().east()), true)) + blockOffsets.add(Pair((b.down().south().west()), true)) } } } @@ -532,10 +704,14 @@ class HighwayTools : Module() { fun getPlayerDirection(): Int { val yaw = (mc.player.rotationYaw % 360 + 360) % 360 - return if (yaw >= 135 && yaw < 225) { 0 } //NORTH - else if (yaw >= 225 && yaw < 315) { 1 } //EAST - else if (yaw >= 315 || yaw < 45) { 2 } //SOUTH - else { 3 } //WEST + return if (yaw >= 158 && yaw < 203) { 0 } //NORTH + else if (yaw >= 203 && yaw < 258) { 1 } //NORTH-EAST + else if (yaw >= 258 && yaw < 293) { 2 } //EAST + else if (yaw >= 293 && yaw < 338) { 3 } //SOUTH-EAST + else if (yaw >= 338 || yaw < 23) { 4 } //SOUTH + else if (yaw >= 23 && yaw < 68) { 5 } //SOUTH-WEST + else if (yaw >= 68 && yaw < 113) { 6 } //WEST + else { 7 } //NORTH-WEST } } From 73d71c6c0fab592594ac1557fad61fd52d71b70b Mon Sep 17 00:00:00 2001 From: Christian Date: Wed, 26 Aug 2020 18:09:00 +0200 Subject: [PATCH 008/390] Lag fix and baritone process - Added HighwayTools as baritone process to make it pause while server is lagging and display current task - Added old onDisable message - Now saves initial hand - Delay actually works now - Check if removing JDK 12.0.2 fix fixes build error on github --- .../java/me/zeroeightsix/kami/KamiMod.java | 4 +- .../kami/module/modules/misc/HighwayTools.kt | 123 ++++++++++++------ .../kami/process/HighwayToolsProcess.kt | 52 ++++++++ 3 files changed, 137 insertions(+), 42 deletions(-) create mode 100644 src/main/java/me/zeroeightsix/kami/process/HighwayToolsProcess.kt diff --git a/src/main/java/me/zeroeightsix/kami/KamiMod.java b/src/main/java/me/zeroeightsix/kami/KamiMod.java index 440e5cb91c..c69862822a 100644 --- a/src/main/java/me/zeroeightsix/kami/KamiMod.java +++ b/src/main/java/me/zeroeightsix/kami/KamiMod.java @@ -18,11 +18,11 @@ import me.zeroeightsix.kami.gui.rgui.util.ContainerHelper; import me.zeroeightsix.kami.gui.rgui.util.Docking; import me.zeroeightsix.kami.module.*; -import me.zeroeightsix.kami.module.Module; import me.zeroeightsix.kami.module.modules.chat.ChatEncryption; import me.zeroeightsix.kami.module.modules.client.CommandConfig; import me.zeroeightsix.kami.module.modules.hidden.RunConfig; import me.zeroeightsix.kami.process.AutoObsidianProcess; +import me.zeroeightsix.kami.process.HighwayToolsProcess; import me.zeroeightsix.kami.process.TemporaryPauseProcess; import me.zeroeightsix.kami.setting.Setting; import me.zeroeightsix.kami.setting.Settings; @@ -102,6 +102,7 @@ public class KamiMod { public static TemporaryPauseProcess pauseProcess; public static AutoObsidianProcess autoObsidianProcess; + public static HighwayToolsProcess highwayToolsProcess; @Mod.Instance private static KamiMod INSTANCE; @@ -126,6 +127,7 @@ public void preInit(FMLPreInitializationEvent event) { pauseProcess = new TemporaryPauseProcess(); autoObsidianProcess = new AutoObsidianProcess(); + highwayToolsProcess = new HighwayToolsProcess(); } @Mod.EventHandler diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index bc4f38ace6..309eb1ce12 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -3,8 +3,10 @@ package me.zeroeightsix.kami.module.modules.misc import baritone.api.BaritoneAPI import baritone.api.pathing.goals.GoalXZ import me.zeroeightsix.kami.KamiMod +import me.zeroeightsix.kami.KamiMod.MODULE_MANAGER import me.zeroeightsix.kami.event.events.RenderEvent import me.zeroeightsix.kami.module.Module +import me.zeroeightsix.kami.module.modules.player.LagNotifier import me.zeroeightsix.kami.module.modules.player.NoBreakAnimation import me.zeroeightsix.kami.setting.Settings import me.zeroeightsix.kami.util.* @@ -24,6 +26,7 @@ import net.minecraft.util.math.Vec3d import java.util.* import kotlin.math.roundToInt + /** * @author Avanatiker * @since 20/08/2020 @@ -36,7 +39,7 @@ import kotlin.math.roundToInt ) class HighwayTools : Module() { private val mode = register(Settings.e("Mode", Mode.HIGHWAY)) - private val baritoneMode = register(Settings.b("Baritone", true)) + val baritoneMode = register(Settings.b("Baritone", true)) private val blocksPerTick = register(Settings.integerBuilder("BlocksPerTick").withMinimum(1).withValue(1).withMaximum(9).build()) private val tickDelay = register(Settings.integerBuilder("TickDelay").withMinimum(0).withValue(1).withMaximum(10).build()) private val rotate = register(Settings.b("Rotate", true)) @@ -46,15 +49,15 @@ class HighwayTools : Module() { private val aOutline = register(Settings.integerBuilder("OutlineAlpha").withMinimum(0).withValue(127).withMaximum(255).withVisibility { outline.value }.build()) private var playerHotbarSlot = -1 + private var lastHotbarSlot = -1 + private var isSneaking = false private var buildDirectionSaved = 0 private var buildDirectionCoordinateSaved = 0.0 private var buildDirectionCoordinateSavedY = 0.0 private val directions = listOf("North", "North-East", "East", "South-East", "South", "South-West", "West", "North-West") - private var isSneaking = false - //Stats - var totalBlocksPlaced = 0 + private var totalBlocksPlaced = 0 var totalBlocksDestroyed = 0 private var totalBlocksDistanceWent = 0 @@ -63,6 +66,7 @@ class HighwayTools : Module() { private var blockOffsets = mutableListOf>() private var waitTicks = 0 private var blocksPlaced = 0 + var walking = false override fun onEnable() { if (mc.player == null) { @@ -70,6 +74,8 @@ class HighwayTools : Module() { return } buildDirectionSaved = getPlayerDirection() + playerHotbarSlot = mc.player.inventory.currentItem + lastHotbarSlot = -1 playerHotbarSlot = mc.player.inventory.currentItem buildDirectionCoordinateSavedY = mc.player.positionVector.y @@ -89,22 +95,45 @@ class HighwayTools : Module() { "\n §9> §rBaritone mode: §a" + baritoneMode.value + "§r") } + override fun onDisable() { + if (mc.player == null) return + + // load initial player hand + if (lastHotbarSlot != playerHotbarSlot && playerHotbarSlot != -1) { + mc.player.inventory.currentItem = playerHotbarSlot + } + if (isSneaking) { + mc.player.connection.sendPacket(CPacketEntityAction(mc.player, CPacketEntityAction.Action.STOP_SNEAKING)) + isSneaking = false + } + playerHotbarSlot = -1 + lastHotbarSlot = -1 + + BaritoneAPI.getProvider().primaryBaritone.pathingBehavior.cancelEverything() + MessageSendHelper.sendChatMessage("$chatName Module stopped." + + "\n §9> §rPlaced obsidian: §a" + totalBlocksPlaced + "§r" + + "\n §9> §rDestroyed blocks: §a" + totalBlocksDestroyed + "§r" + + "\n §9> §rDistance: §a" + totalBlocksDistanceWent + "§r") + totalBlocksPlaced = 0 + totalBlocksDestroyed = 0 + totalBlocksDistanceWent = 0 + } + override fun onUpdate() { - if (!BaritoneAPI.getProvider().primaryBaritone.customGoalProcess.isActive) { - if (isDone()) { - if (baritoneMode.value) { - moveOneBlock() - } - doneQueueReset() - updateTasks() - totalBlocksDistanceWent++ - } else { - doTask() - //getDebug() - } + if (mc.playerController == null) return + + if (!isDone()) { + doTask() + //getDebug() } } + fun done() { + doneQueueReset() + updateTasks() + totalBlocksDistanceWent++ + } + private fun addTask(bps: BlockPos, ts: TaskState, bb: Boolean) { blockQueue.add(BlockTask(bps, ts, bb)) } @@ -121,9 +150,10 @@ class HighwayTools : Module() { } private fun doTask(): Boolean { - if (!isDone()) { + if (!isDone() && !MODULE_MANAGER.getModuleT(LagNotifier::class.java).paused) { if (waitTicks == 0) { val blockAction = blockQueue.peek() + BaritoneAPI.getProvider().primaryBaritone.pathingControlManager.registerProcess(KamiMod.highwayToolsProcess) if (blockAction.getTaskState() == TaskState.BREAK) { val block = mc.world.getBlockState(blockAction.getBlockPos()).block for (side in EnumFacing.values()) { @@ -136,13 +166,13 @@ class HighwayTools : Module() { } } if (!found) { - var inside_build = false - for ((pos, block) in blockOffsets) { + var insideBuild = false + for ((pos, buildBlock) in blockOffsets) { if (neighbour == pos) { - if (!block) { inside_build = true } + if (!buildBlock) { insideBuild = true } } } - if (inside_build) { + if (insideBuild) { addTask(neighbour, TaskState.PLACE, false) } else { addTask(neighbour, TaskState.PLACE, true) @@ -150,30 +180,36 @@ class HighwayTools : Module() { } } } - if (block is BlockAir) { - blockAction.setTaskState(TaskState.BROKE) - doTask() - } else if (block is BlockLiquid) { - blockAction.setTaskState(TaskState.PLACE) - doTask() - } else { - mineBlock(blockAction.getBlockPos(), true) - blockAction.setTaskState(TaskState.BREAKING) - if (block is BlockNetherrack || block is BlockMagma) { - waitTicks = 0 - } else { - //val efficiencyLevel = 5 - //waitTicks = (block.blockHardness * 5.0 / (8 + efficiencyLevel * efficiencyLevel + 1) / 20).toInt() - waitTicks = 5 + when (block) { + is BlockAir -> { + blockAction.setTaskState(TaskState.BROKE) + doTask() + } + is BlockLiquid -> { + blockAction.setTaskState(TaskState.PLACE) + doTask() + } + else -> { + mineBlock(blockAction.getBlockPos(), true) + blockAction.setTaskState(TaskState.BREAKING) + waitTicks = if (block is BlockNetherrack || block is BlockMagma) { + 0 + } else { + //val efficiencyLevel = 5 + //waitTicks = (block.blockHardness * 5.0 / (8 + efficiencyLevel * efficiencyLevel + 1) / 20).toInt() + 5 + } } } } else if (blockAction.getTaskState() == TaskState.BREAKING) { mineBlock(blockAction.getBlockPos(), false) blockAction.setTaskState(TaskState.BROKE) + waitTicks = tickDelay.value - 1 } else if (blockAction.getTaskState() == TaskState.BROKE) { val block = mc.world.getBlockState(blockAction.getBlockPos()).block if (block is BlockAir) { totalBlocksDestroyed++ + waitTicks = tickDelay.value - 1 if (blockAction.getBlock()) { blockAction.setTaskState(TaskState.PLACE) } else { @@ -192,6 +228,7 @@ class HighwayTools : Module() { } else { blocksPlaced = 0 } + waitTicks = tickDelay.value - 1 totalBlocksPlaced++ } else { return false @@ -209,7 +246,7 @@ class HighwayTools : Module() { doTask() } } else { - MessageSendHelper.sendChatMessage(waitTicks.toString()) + //MessageSendHelper.sendChatMessage(waitTicks.toString()) waitTicks-- } return true @@ -241,7 +278,7 @@ class HighwayTools : Module() { return renderer } - private fun moveOneBlock() { + fun getNextBlock(): BlockPos { // set head rotation to get max walking speed val nextBlockPos: BlockPos when (buildDirectionSaved) { @@ -279,7 +316,8 @@ class HighwayTools : Module() { } } mc.player.rotationPitch = 0F - BaritoneAPI.getProvider().primaryBaritone.customGoalProcess.setGoalAndPath(GoalXZ(nextBlockPos.getX(), nextBlockPos.getZ())) + return nextBlockPos + //BaritoneAPI.getProvider().primaryBaritone.customGoalProcess.setGoalAndPath(GoalXZ(nextBlockPos.getX(), nextBlockPos.getZ())) } private fun mineBlock(pos: BlockPos, pre: Boolean) { @@ -356,8 +394,8 @@ class HighwayTools : Module() { mc.player.swingArm(EnumHand.MAIN_HAND) mc.rightClickDelayTimer = 4 - if (KamiMod.MODULE_MANAGER.isModuleEnabled(NoBreakAnimation::class.java)) { - KamiMod.MODULE_MANAGER.getModuleT(NoBreakAnimation::class.java).resetMining() + if (MODULE_MANAGER.isModuleEnabled(NoBreakAnimation::class.java)) { + MODULE_MANAGER.getModuleT(NoBreakAnimation::class.java).resetMining() } return true } @@ -687,6 +725,9 @@ class HighwayTools : Module() { blockOffsets.add(Pair((b.down().south().east()), true)) blockOffsets.add(Pair((b.down().south().west()), true)) } + null -> { + disable() + } } } diff --git a/src/main/java/me/zeroeightsix/kami/process/HighwayToolsProcess.kt b/src/main/java/me/zeroeightsix/kami/process/HighwayToolsProcess.kt new file mode 100644 index 0000000000..921e175fed --- /dev/null +++ b/src/main/java/me/zeroeightsix/kami/process/HighwayToolsProcess.kt @@ -0,0 +1,52 @@ +package me.zeroeightsix.kami.process + +import baritone.api.BaritoneAPI +import baritone.api.IBaritone +import baritone.api.pathing.goals.GoalNear +import baritone.api.process.IBaritoneProcess +import baritone.api.process.PathingCommand +import baritone.api.process.PathingCommandType +import me.zeroeightsix.kami.KamiMod +import me.zeroeightsix.kami.module.modules.misc.HighwayTools + +/** + * Created by Avanatiker on 26/08/20. + */ +class HighwayToolsProcess : IBaritoneProcess { + + private lateinit var baritone: IBaritone + + override fun isTemporary(): Boolean { + return true + } + + override fun priority(): Double { + return 2.0 + } + + override fun onLostControl() {} + + override fun displayName0(): String { + val highwayTools = KamiMod.MODULE_MANAGER.getModuleT(HighwayTools::class.java) + var processName = "" + processName = if (highwayTools.blockQueue.size > 0) { + highwayTools.blockQueue.peek().getTaskState().toString() + " " + highwayTools.blockQueue.peek().getBlockPos().toString() + } else { + "Moving to next block" + } + return "HighwayTools: $processName" + } + + override fun isActive(): Boolean { + return (KamiMod.MODULE_MANAGER.isModuleEnabled(HighwayTools::class.java)) + } + + override fun onTick(p0: Boolean, p1: Boolean): PathingCommand? { + baritone = BaritoneAPI.getProvider().primaryBaritone + val highwayTools = KamiMod.MODULE_MANAGER.getModuleT(HighwayTools::class.java) + return if (highwayTools.isDone() && highwayTools.baritoneMode.value) { + highwayTools.done() + PathingCommand(GoalNear(highwayTools.getNextBlock(), 0), PathingCommandType.SET_GOAL_AND_PATH) + } else PathingCommand(null, PathingCommandType.REQUEST_PAUSE) + } +} \ No newline at end of file From 0af5be37718f0b4c8f02322f6e4065979a5b3d2d Mon Sep 17 00:00:00 2001 From: Christian Date: Wed, 26 Aug 2020 19:28:31 +0200 Subject: [PATCH 009/390] Github build error fix --- src/main/java/me/zeroeightsix/kami/KamiMod.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/me/zeroeightsix/kami/KamiMod.java b/src/main/java/me/zeroeightsix/kami/KamiMod.java index 777c42fd32..d9cfd424ef 100644 --- a/src/main/java/me/zeroeightsix/kami/KamiMod.java +++ b/src/main/java/me/zeroeightsix/kami/KamiMod.java @@ -18,6 +18,7 @@ import me.zeroeightsix.kami.gui.rgui.util.ContainerHelper; import me.zeroeightsix.kami.gui.rgui.util.Docking; import me.zeroeightsix.kami.module.*; +import me.zeroeightsix.kami.module.Module; import me.zeroeightsix.kami.module.modules.chat.ChatEncryption; import me.zeroeightsix.kami.module.modules.client.CommandConfig; import me.zeroeightsix.kami.module.modules.hidden.RunConfig; From be4508fa8e040489728747647c1b77ecec98bd0b Mon Sep 17 00:00:00 2001 From: Christian Date: Wed, 26 Aug 2020 19:45:15 +0200 Subject: [PATCH 010/390] Real fix. Was some commits behind --- .../kami/module/modules/misc/HighwayTools.kt | 22 +++++-------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 309eb1ce12..3f2804f433 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -1,7 +1,6 @@ package me.zeroeightsix.kami.module.modules.misc import baritone.api.BaritoneAPI -import baritone.api.pathing.goals.GoalXZ import me.zeroeightsix.kami.KamiMod import me.zeroeightsix.kami.KamiMod.MODULE_MANAGER import me.zeroeightsix.kami.event.events.RenderEvent @@ -79,12 +78,9 @@ class HighwayTools : Module() { playerHotbarSlot = mc.player.inventory.currentItem buildDirectionCoordinateSavedY = mc.player.positionVector.y - buildDirectionCoordinateSaved = if (buildDirectionSaved == 0 || buildDirectionSaved == 2) { - mc.player.positionVector.x - } - else { - mc.player.positionVector.z - } + buildDirectionCoordinateSaved = if (buildDirectionSaved == 0 || buildDirectionSaved == 4) { mc.player.positionVector.x } + else if (buildDirectionSaved == 2 || buildDirectionSaved == 6) { mc.player.positionVector.z } + else { 0.0 } blockQueue.clear() doneQueueReset() @@ -124,7 +120,6 @@ class HighwayTools : Module() { if (!isDone()) { doTask() - //getDebug() } } @@ -246,7 +241,6 @@ class HighwayTools : Module() { doTask() } } else { - //MessageSendHelper.sendChatMessage(waitTicks.toString()) waitTicks-- } return true @@ -317,7 +311,6 @@ class HighwayTools : Module() { } mc.player.rotationPitch = 0F return nextBlockPos - //BaritoneAPI.getProvider().primaryBaritone.customGoalProcess.setGoalAndPath(GoalXZ(nextBlockPos.getX(), nextBlockPos.getZ())) } private fun mineBlock(pos: BlockPos, pre: Boolean) { @@ -429,7 +422,6 @@ class HighwayTools : Module() { Mode.HIGHWAY -> { when (buildDirectionSaved) { 0 -> { //NORTH - blockOffsets.add(Pair(b.down(), true)) blockOffsets.add(Pair(b.down().north(), true)) blockOffsets.add(Pair(b.down().north().north(), true)) blockOffsets.add(Pair(b.down().north().north().east(), true)) @@ -500,7 +492,6 @@ class HighwayTools : Module() { blockOffsets.add(Pair(b.north().east().east().east().south().east().up().up(), false)) } 2 -> { //EAST - blockOffsets.add(Pair(b.down(), true)) blockOffsets.add(Pair(b.down().east(), true)) blockOffsets.add(Pair(b.down().east().east(), true)) blockOffsets.add(Pair(b.down().east().east().south(), true)) @@ -571,7 +562,6 @@ class HighwayTools : Module() { blockOffsets.add(Pair(b.east().south().south().south().west().south().up().up(), false)) } 4 -> { //SOUTH - blockOffsets.add(Pair(b.down(), true)) blockOffsets.add(Pair(b.down().south(), true)) blockOffsets.add(Pair(b.down().south().south(), true)) blockOffsets.add(Pair(b.down().south().south().east(), true)) @@ -642,7 +632,6 @@ class HighwayTools : Module() { blockOffsets.add(Pair(b.south().west().west().west().north().west().up().up(), false)) } 6 -> { //WEST - blockOffsets.add(Pair(b.down(), true)) blockOffsets.add(Pair(b.down().west(), true)) blockOffsets.add(Pair(b.down().west().west(), true)) blockOffsets.add(Pair(b.down().west().west().south(), true)) @@ -715,7 +704,6 @@ class HighwayTools : Module() { } } Mode.FLAT -> { - blockOffsets.add(Pair((b.down()), true)) blockOffsets.add(Pair((b.down().north()), true)) blockOffsets.add(Pair((b.down().east()), true)) blockOffsets.add(Pair((b.down().south()), true)) @@ -736,11 +724,11 @@ class HighwayTools : Module() { override fun onWorldRender(event: RenderEvent) { if (mc.player == null) return - val renderer = ESPRenderer(event.partialTicks) + val renderer = ESPRenderer() renderer.aFilled = if (filled.value) aFilled.value else 0 renderer.aOutline = if (outline.value) aOutline.value else 0 updateRenderer(renderer) - renderer.render() + renderer.render(true) } fun getPlayerDirection(): Int { From 45033ce76255bd0fd68d9f3e38c4fb284db1fec0 Mon Sep 17 00:00:00 2001 From: Christian Date: Wed, 26 Aug 2020 20:06:22 +0200 Subject: [PATCH 011/390] Tickdelay fix and i try verified commits first time --- .../zeroeightsix/kami/module/modules/misc/HighwayTools.kt | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 3f2804f433..86f39397bc 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -65,7 +65,6 @@ class HighwayTools : Module() { private var blockOffsets = mutableListOf>() private var waitTicks = 0 private var blocksPlaced = 0 - var walking = false override fun onEnable() { if (mc.player == null) { @@ -199,12 +198,12 @@ class HighwayTools : Module() { } else if (blockAction.getTaskState() == TaskState.BREAKING) { mineBlock(blockAction.getBlockPos(), false) blockAction.setTaskState(TaskState.BROKE) - waitTicks = tickDelay.value - 1 + waitTicks = tickDelay.value } else if (blockAction.getTaskState() == TaskState.BROKE) { val block = mc.world.getBlockState(blockAction.getBlockPos()).block if (block is BlockAir) { totalBlocksDestroyed++ - waitTicks = tickDelay.value - 1 + waitTicks = tickDelay.value if (blockAction.getBlock()) { blockAction.setTaskState(TaskState.PLACE) } else { @@ -223,7 +222,7 @@ class HighwayTools : Module() { } else { blocksPlaced = 0 } - waitTicks = tickDelay.value - 1 + waitTicks = tickDelay.value totalBlocksPlaced++ } else { return false From 67e321b9b9f781c7f4a1909b2dc3437ec7426b38 Mon Sep 17 00:00:00 2001 From: Christian Date: Wed, 26 Aug 2020 20:21:39 +0200 Subject: [PATCH 012/390] Small console print change and another verify try --- .../kami/module/modules/misc/HighwayTools.kt | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 86f39397bc..51aef33e63 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -7,6 +7,7 @@ import me.zeroeightsix.kami.event.events.RenderEvent import me.zeroeightsix.kami.module.Module import me.zeroeightsix.kami.module.modules.player.LagNotifier import me.zeroeightsix.kami.module.modules.player.NoBreakAnimation +import me.zeroeightsix.kami.setting.Setting import me.zeroeightsix.kami.setting.Settings import me.zeroeightsix.kami.util.* import me.zeroeightsix.kami.util.colourUtils.ColourHolder @@ -38,9 +39,9 @@ import kotlin.math.roundToInt ) class HighwayTools : Module() { private val mode = register(Settings.e("Mode", Mode.HIGHWAY)) - val baritoneMode = register(Settings.b("Baritone", true)) + val baritoneMode: Setting = register(Settings.b("Baritone", true)) private val blocksPerTick = register(Settings.integerBuilder("BlocksPerTick").withMinimum(1).withValue(1).withMaximum(9).build()) - private val tickDelay = register(Settings.integerBuilder("TickDelay").withMinimum(0).withValue(1).withMaximum(10).build()) + private val tickDelay = register(Settings.integerBuilder("TickDelay").withMinimum(0).withValue(0).withMaximum(10).build()) private val rotate = register(Settings.b("Rotate", true)) private val filled = register(Settings.b("Filled", true)) private val outline = register(Settings.b("Outline", true)) @@ -84,10 +85,18 @@ class HighwayTools : Module() { blockQueue.clear() doneQueueReset() updateTasks() - MessageSendHelper.sendChatMessage("$chatName Module started." + - "\n §9> §rSelected direction: §a" + directions[buildDirectionSaved] + "§r" + - "\n §9> §rSnap to coordinate: §a" + buildDirectionCoordinateSaved.roundToInt() + "§r" + - "\n §9> §rBaritone mode: §a" + baritoneMode.value + "§r") + if (buildDirectionSaved == 1 || buildDirectionSaved == 3 || buildDirectionSaved == 5 || buildDirectionSaved == 5 || buildDirectionSaved == 7) { + MessageSendHelper.sendChatMessage("$chatName Module started." + + "\n §9> §rSelected direction: §a" + directions[buildDirectionSaved] + "§r" + + "\n §9> §rSnap to coordinates: §a" + mc.player.positionVector.x.roundToInt() + ", " + mc.player.positionVector.z.roundToInt() + "§r" + + "\n §9> §rBaritone mode: §a" + baritoneMode.value + "§r") + } else { + MessageSendHelper.sendChatMessage("$chatName Module started." + + "\n §9> §rSelected direction: §a" + directions[buildDirectionSaved] + "§r" + + "\n §9> §rSnap to coordinate: §a" + buildDirectionCoordinateSaved.roundToInt() + "§r" + + "\n §9> §rBaritone mode: §a" + baritoneMode.value + "§r") + } + } override fun onDisable() { From e4596b8401df06ba1e88963778ca068a37a5f376 Mon Sep 17 00:00:00 2001 From: Christian Date: Wed, 26 Aug 2020 23:40:58 +0200 Subject: [PATCH 013/390] Splitted tick delay of break and place for better speed optimization --- .../kami/module/modules/misc/HighwayTools.kt | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 51aef33e63..7dab533d64 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -40,13 +40,14 @@ import kotlin.math.roundToInt class HighwayTools : Module() { private val mode = register(Settings.e("Mode", Mode.HIGHWAY)) val baritoneMode: Setting = register(Settings.b("Baritone", true)) - private val blocksPerTick = register(Settings.integerBuilder("BlocksPerTick").withMinimum(1).withValue(1).withMaximum(9).build()) - private val tickDelay = register(Settings.integerBuilder("TickDelay").withMinimum(0).withValue(0).withMaximum(10).build()) + private val blocksPerTick = register(Settings.integerBuilder("Blocks Per Tick").withMinimum(1).withValue(1).withMaximum(9).build()) + private val tickDelay = register(Settings.integerBuilder("Tick-Delay Place").withMinimum(0).withValue(0).withMaximum(10).build()) + private val tickDelayBreak = register(Settings.integerBuilder("Tick-Delay Break").withMinimum(0).withValue(0).withMaximum(10).build()) private val rotate = register(Settings.b("Rotate", true)) private val filled = register(Settings.b("Filled", true)) private val outline = register(Settings.b("Outline", true)) - private val aFilled = register(Settings.integerBuilder("FilledAlpha").withMinimum(0).withValue(31).withMaximum(255).withVisibility { filled.value }.build()) - private val aOutline = register(Settings.integerBuilder("OutlineAlpha").withMinimum(0).withValue(127).withMaximum(255).withVisibility { outline.value }.build()) + private val aFilled = register(Settings.integerBuilder("Filled Alpha").withMinimum(0).withValue(31).withMaximum(255).withVisibility { filled.value }.build()) + private val aOutline = register(Settings.integerBuilder("Outline Alpha").withMinimum(0).withValue(127).withMaximum(255).withVisibility { outline.value }.build()) private var playerHotbarSlot = -1 private var lastHotbarSlot = -1 @@ -207,12 +208,11 @@ class HighwayTools : Module() { } else if (blockAction.getTaskState() == TaskState.BREAKING) { mineBlock(blockAction.getBlockPos(), false) blockAction.setTaskState(TaskState.BROKE) - waitTicks = tickDelay.value } else if (blockAction.getTaskState() == TaskState.BROKE) { val block = mc.world.getBlockState(blockAction.getBlockPos()).block if (block is BlockAir) { totalBlocksDestroyed++ - waitTicks = tickDelay.value + waitTicks = tickDelayBreak.value if (blockAction.getBlock()) { blockAction.setTaskState(TaskState.PLACE) } else { @@ -326,7 +326,7 @@ class HighwayTools : Module() { InventoryUtils.moveToHotbar(278, 130, (tickDelay.value * 16).toLong()) return } else if (InventoryUtils.getSlots(0, 35, 278) == null) { - MessageSendHelper.sendChatMessage("$chatName No pickaxe was found in inventory, disabling.") + MessageSendHelper.sendChatMessage("$chatName No Pickaxe was found in inventory") mc.getSoundHandler().playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) disable() return @@ -373,7 +373,7 @@ class HighwayTools : Module() { InventoryUtils.quickMoveSlot(1, (tickDelay.value * 16).toLong()) return false } else if (InventoryUtils.getSlots(0, 35, 49) == null) { - MessageSendHelper.sendChatMessage("$chatName No Obsidian was found in inventory, disabling.") + MessageSendHelper.sendChatMessage("$chatName No Obsidian was found in inventory") mc.getSoundHandler().playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) disable() return false From 77b3ed26a266e7ee08a87bb96028ec1e39f36b04 Mon Sep 17 00:00:00 2001 From: Christian Date: Wed, 2 Sep 2020 00:02:13 +0200 Subject: [PATCH 014/390] Improved reliability - Reworked position clipping - Added experimental command - Position cant get out of sync - Better task control (multiple checks) - If stuck refreshes the tasks - Better player positioning --- .../command/commands/HighwayToolsCommand.kt | 72 +++++++++++ .../kami/module/modules/misc/HighwayTools.kt | 114 +++++++++++++----- .../kami/process/HighwayToolsProcess.kt | 3 +- 3 files changed, 156 insertions(+), 33 deletions(-) create mode 100644 src/main/java/me/zeroeightsix/kami/command/commands/HighwayToolsCommand.kt diff --git a/src/main/java/me/zeroeightsix/kami/command/commands/HighwayToolsCommand.kt b/src/main/java/me/zeroeightsix/kami/command/commands/HighwayToolsCommand.kt new file mode 100644 index 0000000000..d145c61b51 --- /dev/null +++ b/src/main/java/me/zeroeightsix/kami/command/commands/HighwayToolsCommand.kt @@ -0,0 +1,72 @@ +package me.zeroeightsix.kami.command.commands + +import me.zeroeightsix.kami.command.Command +import me.zeroeightsix.kami.command.syntax.ChunkBuilder +import me.zeroeightsix.kami.command.syntax.parsers.EnumParser +import me.zeroeightsix.kami.module.ModuleManager +import me.zeroeightsix.kami.module.modules.misc.HighwayTools +import me.zeroeightsix.kami.util.text.MessageSendHelper +import net.minecraft.item.Item.getByNameOrId + +/** + * @author Avanatiker + * @since 01/09/2020 + */ +class HighwayToolsCommand : Command("highwaytools", ChunkBuilder() + .append("mode", true, EnumParser(arrayOf("airspace", "corner", "material", "ignore", "baritone", "logout"))) + .append("value") + .build(), "ht") { + + override fun call(args: Array) { + val subCommand = getSubCommand(args) + val ht = ModuleManager.getModuleT(HighwayTools::class.java) + when (subCommand) { + SubCommands.SHOWSETTINGS -> { + ht!!.printSettings() + } + + SubCommands.MATERIAL -> { + try { + val newmat = getByNameOrId(args[1].toString()) + ht!!.material = args[1].toString() + MessageSendHelper.sendChatMessage("&7${newmat}&r is now your building material.") + } catch (e: Exception) { + MessageSendHelper.sendChatMessage("&7${args[1]}&r is no material.") + } + + } + + SubCommands.IGNORE -> { + ht!!.material = args[1].toString() + MessageSendHelper.sendChatMessage("&7${args[1]}&r is now building material.") + } + + SubCommands.NULL -> { + val commands = args.joinToString(separator = " ") + MessageSendHelper.sendChatMessage("Invalid command &7${commandPrefix.value}${label} $commands&f!") + } + } + } + + private fun getSubCommand(args: Array): SubCommands { + return when { + args[0].isNullOrBlank() -> SubCommands.SHOWSETTINGS + + args[1].isNullOrBlank() -> SubCommands.NULL + + args[0].equals("material", ignoreCase = true) -> SubCommands.MATERIAL + + args[0].equals("ignore", ignoreCase = true) -> SubCommands.IGNORE + + else -> SubCommands.NULL + } + } + + private enum class SubCommands { + MATERIAL, IGNORE, SHOWSETTINGS, NULL + } + + init { + setDescription("Customize HighwayTools settings.") + } +} \ No newline at end of file diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index dea25ea141..92e6be575c 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -5,7 +5,6 @@ import me.zeroeightsix.kami.KamiMod import me.zeroeightsix.kami.event.events.RenderEvent import me.zeroeightsix.kami.module.Module import me.zeroeightsix.kami.module.ModuleManager -import me.zeroeightsix.kami.module.modules.player.LagNotifier import me.zeroeightsix.kami.module.modules.player.NoBreakAnimation import me.zeroeightsix.kami.setting.Setting import me.zeroeightsix.kami.setting.Settings @@ -20,6 +19,8 @@ import net.minecraft.client.audio.PositionedSoundRecord import net.minecraft.entity.item.EntityItem import net.minecraft.entity.item.EntityXPOrb import net.minecraft.init.SoundEvents +import net.minecraft.item.Item.getByNameOrId +import net.minecraft.item.Item.getIdFromItem import net.minecraft.network.play.client.CPacketEntityAction import net.minecraft.network.play.client.CPacketPlayerDigging import net.minecraft.util.EnumFacing @@ -28,6 +29,7 @@ import net.minecraft.util.math.AxisAlignedBB import net.minecraft.util.math.BlockPos import net.minecraft.util.math.Vec3d import java.util.* +import kotlin.math.floor import kotlin.math.roundToInt @@ -56,21 +58,30 @@ class HighwayTools : Module() { private var playerHotbarSlot = -1 private var lastHotbarSlot = -1 private var isSneaking = false + var pathing = false + var material = "obsidian" + var ignoreBlocks = listOf("sign", "banner", "portal") private var buildDirectionSaved = 0 - private var buildDirectionCoordinateSaved = 0.0 - private var buildDirectionCoordinateSavedY = 0.0 + private var buildDirectionCoordinateSaved = 0 + private var buildDirectionCoordinateSavedY = 0 private val directions = listOf("North", "North-East", "East", "South-East", "South", "South-West", "West", "North-West") //Stats private var totalBlocksPlaced = 0 var totalBlocksDestroyed = 0 private var totalBlocksDistanceWent = 0 + + //Custom settings + @JvmField + var buildHeight: Setting = register(Settings.integerBuilder("BuildHeight").withMinimum(0).withValue(0).withMaximum(10).build()) val blockQueue: Queue = LinkedList() private val doneQueue: Queue = LinkedList() private var blockOffsets = mutableListOf>() private var waitTicks = 0 private var blocksPlaced = 0 + private lateinit var currentBlockPos: BlockPos + private lateinit var startingBlockPos: BlockPos override fun onEnable() { if (mc.player == null) { @@ -78,14 +89,16 @@ class HighwayTools : Module() { return } buildDirectionSaved = getPlayerDirection() + startingBlockPos = BlockPos(floor(mc.player.posX).toInt(), floor(mc.player.posY).toInt(), floor(mc.player.posZ).toInt()) + currentBlockPos = startingBlockPos playerHotbarSlot = mc.player.inventory.currentItem lastHotbarSlot = -1 playerHotbarSlot = mc.player.inventory.currentItem - buildDirectionCoordinateSavedY = mc.player.positionVector.y - buildDirectionCoordinateSaved = if (buildDirectionSaved == 0 || buildDirectionSaved == 4) { mc.player.positionVector.x } - else if (buildDirectionSaved == 2 || buildDirectionSaved == 6) { mc.player.positionVector.z } - else { 0.0 } + buildDirectionCoordinateSavedY = startingBlockPos.getY() + buildDirectionCoordinateSaved = if (buildDirectionSaved == 0 || buildDirectionSaved == 4) { startingBlockPos.getX() } + else if (buildDirectionSaved == 2 || buildDirectionSaved == 6) { startingBlockPos.getZ() } + else { 0 } blockQueue.clear() doneQueueReset() @@ -98,7 +111,7 @@ class HighwayTools : Module() { } else { MessageSendHelper.sendChatMessage("$chatName Module started." + "\n §9> §rSelected direction: §a" + directions[buildDirectionSaved] + "§r" + - "\n §9> §rSnap to coordinate: §a" + buildDirectionCoordinateSaved.roundToInt() + "§r" + + "\n §9> §rSnap to coordinate: §a" + buildDirectionCoordinateSaved + "§r" + "\n §9> §rBaritone mode: §a" + baritoneMode.value + "§r") } @@ -132,20 +145,46 @@ class HighwayTools : Module() { if (mc.playerController == null) return if (!isDone()) { - doTask() + val playerBlockPos = BlockPos(floor(mc.player.posX).toInt(), floor(mc.player.posY).toInt(), floor(mc.player.posZ).toInt()) + if (currentBlockPos.x == playerBlockPos.x && currentBlockPos.z == playerBlockPos.z) { + pathing = false + } + if (!doTask()) { + doneQueueReset() + blockQueue.clear() + updateTasks() + } + } else { + if (checkTasks()) { + currentBlockPos = getNextBlock() + totalBlocksDistanceWent++ + doneQueueReset() + updateTasks() + pathing = true + } else { + doneQueueReset() + updateTasks() + } } - } - - fun done() { - doneQueueReset() - updateTasks() - totalBlocksDistanceWent++ + //printDebug() } private fun addTask(blockPos: BlockPos, taskState: TaskState, filled: Boolean) { blockQueue.add(BlockTask(blockPos, taskState, filled)) } + private fun checkTasks(): Boolean { + for (bt in doneQueue) { + val block = mc.world.getBlockState(bt.getBlockPos()).block + if (bt.getBlock() && block is BlockAir) { + return false + } else if (!bt.getBlock() && block !is BlockAir) { + return false + } + } + return true + } + private fun printDebug() { MessageSendHelper.sendChatMessage("#### LOG ####") for (bt in blockQueue) { @@ -157,13 +196,21 @@ class HighwayTools : Module() { } } + fun printSettings() { + MessageSendHelper.sendChatMessage("Settings") + } + private fun doTask(): Boolean { - if (!isDone() && !ModuleManager.getModuleT(LagNotifier::class.java)?.paused!!) { + BaritoneAPI.getProvider().primaryBaritone.pathingControlManager.registerProcess(KamiMod.highwayToolsProcess) + if (!isDone() && !pathing) { if (waitTicks == 0) { val blockAction = blockQueue.peek() - BaritoneAPI.getProvider().primaryBaritone.pathingControlManager.registerProcess(KamiMod.highwayToolsProcess) if (blockAction.getTaskState() == TaskState.BREAK) { val block = mc.world.getBlockState(blockAction.getBlockPos()).block + if (block is BlockPortal || block is BlockSign || block is BlockBanner) { + blockAction.setTaskState(TaskState.DONE) + return true + } for (side in EnumFacing.values()) { val neighbour = blockAction.getBlockPos().offset(side) var found = false @@ -235,7 +282,12 @@ class HighwayTools : Module() { } } else if (blockAction.getTaskState() == TaskState.PLACED) { if (blockAction.getBlock()) { - blockAction.setTaskState(TaskState.DONE) + val block = mc.world.getBlockState(blockAction.getBlockPos()).block + if (block !is BlockAir) { + blockAction.setTaskState(TaskState.DONE) + } else { + blockAction.setTaskState(TaskState.PLACE) + } } else { blockAction.setTaskState(TaskState.BREAK) } @@ -282,35 +334,35 @@ class HighwayTools : Module() { val nextBlockPos: BlockPos when (buildDirectionSaved) { 0 -> { - nextBlockPos = BlockPos(mc.player.positionVector).north() + nextBlockPos = currentBlockPos.north() mc.player.rotationYaw = -180F } 1 -> { - nextBlockPos = BlockPos(mc.player.positionVector).north().east() + nextBlockPos = currentBlockPos.north().east() mc.player.rotationYaw = -135F } 2 -> { - nextBlockPos = BlockPos(mc.player.positionVector).east() + nextBlockPos = currentBlockPos.east() mc.player.rotationYaw = -90F } 3 -> { - nextBlockPos = BlockPos(mc.player.positionVector).south().east() + nextBlockPos = currentBlockPos.south().east() mc.player.rotationYaw = -45F } 4 -> { - nextBlockPos = BlockPos(mc.player.positionVector).south() + nextBlockPos = currentBlockPos.south() mc.player.rotationYaw = 0F } 5 -> { - nextBlockPos = BlockPos(mc.player.positionVector).south().west() + nextBlockPos = currentBlockPos.south().west() mc.player.rotationYaw = 45F } 6 -> { - nextBlockPos = BlockPos(mc.player.positionVector).west() + nextBlockPos = currentBlockPos.west() mc.player.rotationYaw = 90F } else -> { - nextBlockPos = BlockPos(mc.player.positionVector).north().west() + nextBlockPos = currentBlockPos.north().west() mc.player.rotationYaw = 135F } } @@ -365,17 +417,17 @@ class HighwayTools : Module() { } //Swap to Obsidian in Hotbar or get from inventory - if (InventoryUtils.getSlotsHotbar(49) == null && InventoryUtils.getSlotsNoHotbar(49) != null) { + if (InventoryUtils.getSlotsHotbar(getIdFromItem(getByNameOrId(material))) == null && InventoryUtils.getSlotsNoHotbar(getIdFromItem(getByNameOrId(material))) != null) { InventoryUtils.moveToHotbar(49, 130, (tickDelay.value * 16).toLong()) InventoryUtils.quickMoveSlot(1, (tickDelay.value * 16).toLong()) return false - } else if (InventoryUtils.getSlots(0, 35, 49) == null) { - MessageSendHelper.sendChatMessage("$chatName No Obsidian was found in inventory") + } else if (InventoryUtils.getSlots(0, 35, getIdFromItem(getByNameOrId(material))) == null) { + MessageSendHelper.sendChatMessage("$chatName No $material was found in inventory") mc.getSoundHandler().playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) disable() return false } - InventoryUtils.swapSlotToItem(49) + InventoryUtils.swapSlotToItem(getIdFromItem(getByNameOrId(material))) val hitVec = Vec3d(neighbour).add(0.5, 0.5, 0.5).add(Vec3d(opposite.directionVec).scale(0.5)) val neighbourBlock = mc.world.getBlockState(neighbour).block @@ -422,7 +474,7 @@ class HighwayTools : Module() { private fun updateBlockArray() { blockOffsets.clear() - val b = BlockPos(mc.player.positionVector) + val b = currentBlockPos when(mode.value) { Mode.HIGHWAY -> { diff --git a/src/main/java/me/zeroeightsix/kami/process/HighwayToolsProcess.kt b/src/main/java/me/zeroeightsix/kami/process/HighwayToolsProcess.kt index ca2e64a2ef..0d20798fd7 100644 --- a/src/main/java/me/zeroeightsix/kami/process/HighwayToolsProcess.kt +++ b/src/main/java/me/zeroeightsix/kami/process/HighwayToolsProcess.kt @@ -45,8 +45,7 @@ class HighwayToolsProcess : IBaritoneProcess { override fun onTick(p0: Boolean, p1: Boolean): PathingCommand? { baritone = BaritoneAPI.getProvider().primaryBaritone val highwayTools = ModuleManager.getModuleT(HighwayTools::class.java)!! - return if (highwayTools.isDone() && highwayTools.baritoneMode.value) { - highwayTools.done() + return if (highwayTools.pathing && highwayTools.baritoneMode.value) { PathingCommand(GoalNear(highwayTools.getNextBlock(), 0), PathingCommandType.SET_GOAL_AND_PATH) } else PathingCommand(null, PathingCommandType.REQUEST_PAUSE) } From 5472dc48535ff5565773f3a1c57337e369d6e6ce Mon Sep 17 00:00:00 2001 From: Christian Date: Thu, 3 Sep 2020 04:09:04 +0200 Subject: [PATCH 015/390] Commands and customizing - Added a command to customize options > Choose building material > Add ignored blocks (still lacks of removing them) > Get detailed settings - Made material checks dynamic - Improved liquid handling --- .../command/commands/HighwayToolsCommand.kt | 20 +++-- .../kami/module/modules/misc/HighwayTools.kt | 81 +++++++++++-------- .../kami/process/HighwayToolsProcess.kt | 6 +- 3 files changed, 64 insertions(+), 43 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/command/commands/HighwayToolsCommand.kt b/src/main/java/me/zeroeightsix/kami/command/commands/HighwayToolsCommand.kt index d145c61b51..a1d08665d8 100644 --- a/src/main/java/me/zeroeightsix/kami/command/commands/HighwayToolsCommand.kt +++ b/src/main/java/me/zeroeightsix/kami/command/commands/HighwayToolsCommand.kt @@ -6,7 +6,7 @@ import me.zeroeightsix.kami.command.syntax.parsers.EnumParser import me.zeroeightsix.kami.module.ModuleManager import me.zeroeightsix.kami.module.modules.misc.HighwayTools import me.zeroeightsix.kami.util.text.MessageSendHelper -import net.minecraft.item.Item.getByNameOrId +import net.minecraft.block.Block /** * @author Avanatiker @@ -27,18 +27,26 @@ class HighwayToolsCommand : Command("highwaytools", ChunkBuilder() SubCommands.MATERIAL -> { try { - val newmat = getByNameOrId(args[1].toString()) - ht!!.material = args[1].toString() + val newmat = Block.getBlockFromName(args[1].toString())!! + ht!!.material = newmat MessageSendHelper.sendChatMessage("&7${newmat}&r is now your building material.") } catch (e: Exception) { MessageSendHelper.sendChatMessage("&7${args[1]}&r is no material.") } - } SubCommands.IGNORE -> { - ht!!.material = args[1].toString() - MessageSendHelper.sendChatMessage("&7${args[1]}&r is now building material.") + try { + val newmat = Block.getBlockFromName(args[1].toString())!! + if (newmat !in ht!!.ignoreBlocks) { + ht.ignoreBlocks.add(newmat) + MessageSendHelper.sendChatMessage("&7${newmat}&r is now ignored.") + } else { + MessageSendHelper.sendChatMessage("&7${newmat}&r is already ignored.") + } + } catch (e: Exception) { + MessageSendHelper.sendChatMessage("&7${args[1]}&r is no material.") + } } SubCommands.NULL -> { diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 92e6be575c..e99ad37e48 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -15,12 +15,12 @@ import me.zeroeightsix.kami.util.graphics.GeometryMasks import me.zeroeightsix.kami.util.math.RotationUtils import me.zeroeightsix.kami.util.text.MessageSendHelper import net.minecraft.block.* +import net.minecraft.block.Block.getBlockById +import net.minecraft.block.Block.getIdFromBlock import net.minecraft.client.audio.PositionedSoundRecord import net.minecraft.entity.item.EntityItem import net.minecraft.entity.item.EntityXPOrb import net.minecraft.init.SoundEvents -import net.minecraft.item.Item.getByNameOrId -import net.minecraft.item.Item.getIdFromItem import net.minecraft.network.play.client.CPacketEntityAction import net.minecraft.network.play.client.CPacketPlayerDigging import net.minecraft.util.EnumFacing @@ -59,8 +59,8 @@ class HighwayTools : Module() { private var lastHotbarSlot = -1 private var isSneaking = false var pathing = false - var material = "obsidian" - var ignoreBlocks = listOf("sign", "banner", "portal") + var material: Block = getBlockById(49) + var ignoreBlocks = mutableListOf(BlockStandingSign(), BlockWallSign(), BlockBanner.BlockBannerHanging(), BlockBanner.BlockBannerStanding(), BlockPortal()) private var buildDirectionSaved = 0 private var buildDirectionCoordinateSaved = 0 private var buildDirectionCoordinateSavedY = 0 @@ -105,13 +105,13 @@ class HighwayTools : Module() { updateTasks() if (buildDirectionSaved == 1 || buildDirectionSaved == 3 || buildDirectionSaved == 5 || buildDirectionSaved == 5 || buildDirectionSaved == 7) { MessageSendHelper.sendChatMessage("$chatName Module started." + - "\n §9> §rSelected direction: §a" + directions[buildDirectionSaved] + "§r" + - "\n §9> §rSnap to coordinates: §a" + mc.player.positionVector.x.roundToInt() + ", " + mc.player.positionVector.z.roundToInt() + "§r" + + "\n §9> §rDirection: §a" + directions[buildDirectionSaved] + "§r" + + "\n §9> §rCoordinates: §a" + mc.player.positionVector.x.roundToInt() + ", " + mc.player.positionVector.z.roundToInt() + "§r" + "\n §9> §rBaritone mode: §a" + baritoneMode.value + "§r") } else { MessageSendHelper.sendChatMessage("$chatName Module started." + - "\n §9> §rSelected direction: §a" + directions[buildDirectionSaved] + "§r" + - "\n §9> §rSnap to coordinate: §a" + buildDirectionCoordinateSaved + "§r" + + "\n §9> §rDirection: §a" + directions[buildDirectionSaved] + "§r" + + "\n §9> §rCoordinate: §a" + buildDirectionCoordinateSaved + "§r" + "\n §9> §rBaritone mode: §a" + baritoneMode.value + "§r") } @@ -133,7 +133,7 @@ class HighwayTools : Module() { BaritoneAPI.getProvider().primaryBaritone.pathingBehavior.cancelEverything() MessageSendHelper.sendChatMessage("$chatName Module stopped." + - "\n §9> §rPlaced obsidian: §a" + totalBlocksPlaced + "§r" + + "\n §9> §rPlaced blocks: §a" + totalBlocksPlaced + "§r" + "\n §9> §rDestroyed blocks: §a" + totalBlocksDestroyed + "§r" + "\n §9> §rDistance: §a" + totalBlocksDistanceWent + "§r") totalBlocksPlaced = 0 @@ -169,16 +169,21 @@ class HighwayTools : Module() { //printDebug() } - private fun addTask(blockPos: BlockPos, taskState: TaskState, filled: Boolean) { - blockQueue.add(BlockTask(blockPos, taskState, filled)) + private fun addTask(blockPos: BlockPos, taskState: TaskState, material: Block) { + blockQueue.add(BlockTask(blockPos, taskState, material)) } private fun checkTasks(): Boolean { for (bt in doneQueue) { val block = mc.world.getBlockState(bt.getBlockPos()).block - if (bt.getBlock() && block is BlockAir) { + var cont = false + for (b in ignoreBlocks) { + if (b::class == block::class) { cont = true } + } + if (cont) { continue } + if (bt.getBlock()::class == material::class && block is BlockAir) { return false - } else if (!bt.getBlock() && block !is BlockAir) { + } else if (bt.getBlock()::class == BlockAir::class && block !is BlockAir) { return false } } @@ -197,7 +202,10 @@ class HighwayTools : Module() { } fun printSettings() { - MessageSendHelper.sendChatMessage("Settings") + MessageSendHelper.sendChatMessage("---- Settings ----\nIgnored Blocks: ") + for (b in ignoreBlocks) { + MessageSendHelper.sendChatMessage(" > $b") + } } private fun doTask(): Boolean { @@ -207,9 +215,11 @@ class HighwayTools : Module() { val blockAction = blockQueue.peek() if (blockAction.getTaskState() == TaskState.BREAK) { val block = mc.world.getBlockState(blockAction.getBlockPos()).block - if (block is BlockPortal || block is BlockSign || block is BlockBanner) { - blockAction.setTaskState(TaskState.DONE) - return true + for (b in ignoreBlocks) { + if (block::class == b::class) { + blockAction.setTaskState(TaskState.DONE) + doTask() + } } for (side in EnumFacing.values()) { val neighbour = blockAction.getBlockPos().offset(side) @@ -228,9 +238,9 @@ class HighwayTools : Module() { } } if (insideBuild) { - addTask(neighbour, TaskState.PLACE, false) + addTask(neighbour, TaskState.PLACE, getBlockById(0)) } else { - addTask(neighbour, TaskState.PLACE, true) + addTask(neighbour, TaskState.PLACE, material) } } } @@ -257,7 +267,7 @@ class HighwayTools : Module() { if (block is BlockAir) { totalBlocksDestroyed++ waitTicks = tickDelayBreak.value - if (blockAction.getBlock()) { + if (blockAction.getBlock()::class == material::class) { blockAction.setTaskState(TaskState.PLACE) } else { blockAction.setTaskState(TaskState.DONE) @@ -267,6 +277,11 @@ class HighwayTools : Module() { blockAction.setTaskState(TaskState.BREAK) } } else if (blockAction.getTaskState() == TaskState.PLACE) { + val block = mc.world.getBlockState(blockAction.getBlockPos()).block + if (blockAction.getBlock() is BlockAir && block !is BlockLiquid) { + blockQueue.remove() + return true + } if (placeBlock(blockAction.getBlockPos())) { blockAction.setTaskState(TaskState.PLACED) if (blocksPerTick.value > blocksPlaced + 1) { @@ -281,7 +296,7 @@ class HighwayTools : Module() { return false } } else if (blockAction.getTaskState() == TaskState.PLACED) { - if (blockAction.getBlock()) { + if (blockAction.getBlock()::class == material::class) { val block = mc.world.getBlockState(blockAction.getBlockPos()).block if (block !is BlockAir) { blockAction.setTaskState(TaskState.DONE) @@ -310,11 +325,11 @@ class HighwayTools : Module() { updateBlockArray() for ((a, b) in blockOffsets) { val block = mc.world.getBlockState(a).block - if (b && block is BlockAir) { addTask(a, TaskState.PLACE, true) } - else if (b && block !is BlockAir && block !is BlockObsidian) { addTask(a, TaskState.BREAK, true) } - else if (!b && block !is BlockAir) { addTask(a, TaskState.BREAK, false) } - else if (b && block is BlockObsidian) { addTask(a, TaskState.DONE, true) } - else if (!b && block is BlockAir) { addTask(a, TaskState.DONE, false) } + if (b && block is BlockAir) { addTask(a, TaskState.PLACE, material) } + else if (b && block !is BlockAir && block::class != material::class) { addTask(a, TaskState.BREAK, material) } + else if (!b && block !is BlockAir) { addTask(a, TaskState.BREAK, getBlockById(0)) } + else if (b && block::class == material::class) { addTask(a, TaskState.DONE, material) } + else if (!b && block is BlockAir) { addTask(a, TaskState.DONE, getBlockById(0)) } } } @@ -324,7 +339,7 @@ class HighwayTools : Module() { if (bt.getTaskState() != TaskState.DONE) { renderer.add(bt.getBlockPos(), bt.getTaskState().color, side) } } for (bt in doneQueue) { - if (bt.getBlock()) { renderer.add(bt.getBlockPos(), bt.getTaskState().color, side) } + if (bt.getBlock()::class != BlockAir::class) { renderer.add(bt.getBlockPos(), bt.getTaskState().color, side) } } return renderer } @@ -417,17 +432,17 @@ class HighwayTools : Module() { } //Swap to Obsidian in Hotbar or get from inventory - if (InventoryUtils.getSlotsHotbar(getIdFromItem(getByNameOrId(material))) == null && InventoryUtils.getSlotsNoHotbar(getIdFromItem(getByNameOrId(material))) != null) { - InventoryUtils.moveToHotbar(49, 130, (tickDelay.value * 16).toLong()) + if (InventoryUtils.getSlotsHotbar(getIdFromBlock(material)) == null && InventoryUtils.getSlotsNoHotbar(getIdFromBlock(material)) != null) { + InventoryUtils.moveToHotbar(getIdFromBlock(material), 130, (tickDelay.value * 16).toLong()) InventoryUtils.quickMoveSlot(1, (tickDelay.value * 16).toLong()) return false - } else if (InventoryUtils.getSlots(0, 35, getIdFromItem(getByNameOrId(material))) == null) { + } else if (InventoryUtils.getSlots(0, 35, getIdFromBlock(material)) == null) { MessageSendHelper.sendChatMessage("$chatName No $material was found in inventory") mc.getSoundHandler().playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) disable() return false } - InventoryUtils.swapSlotToItem(getIdFromItem(getByNameOrId(material))) + InventoryUtils.swapSlotToItem(getIdFromBlock(material)) val hitVec = Vec3d(neighbour).add(0.5, 0.5, 0.5).add(Vec3d(opposite.directionVec).scale(0.5)) val neighbourBlock = mc.world.getBlockState(neighbour).block @@ -802,11 +817,11 @@ class HighwayTools : Module() { } } -class BlockTask(private val bp: BlockPos, private var tt: TaskState, private val bb: Boolean) { +class BlockTask(private val bp: BlockPos, private var tt: TaskState, private val bb: Block) { fun getBlockPos(): BlockPos { return bp } fun getTaskState(): TaskState { return tt } fun setTaskState(tts: TaskState) { tt = tts } - fun getBlock(): Boolean { return bb } + fun getBlock(): Block { return bb } } enum class TaskState(val color: ColorHolder) { diff --git a/src/main/java/me/zeroeightsix/kami/process/HighwayToolsProcess.kt b/src/main/java/me/zeroeightsix/kami/process/HighwayToolsProcess.kt index 0d20798fd7..9e75817edd 100644 --- a/src/main/java/me/zeroeightsix/kami/process/HighwayToolsProcess.kt +++ b/src/main/java/me/zeroeightsix/kami/process/HighwayToolsProcess.kt @@ -6,7 +6,6 @@ import baritone.api.pathing.goals.GoalNear import baritone.api.process.IBaritoneProcess import baritone.api.process.PathingCommand import baritone.api.process.PathingCommandType -import me.zeroeightsix.kami.KamiMod import me.zeroeightsix.kami.module.ModuleManager import me.zeroeightsix.kami.module.modules.misc.HighwayTools @@ -29,9 +28,8 @@ class HighwayToolsProcess : IBaritoneProcess { override fun displayName0(): String { val highwayTools = ModuleManager.getModuleT(HighwayTools::class.java)!! - var processName = "" - processName = if (highwayTools.blockQueue.size > 0) { - highwayTools.blockQueue.peek().getTaskState().toString() + " " + highwayTools.blockQueue.peek().getBlockPos().toString() + val processName = if (highwayTools.blockQueue.size > 0) { + highwayTools.blockQueue.peek().getBlockPos().toString() + " " + highwayTools.blockQueue.peek().getTaskState().toString() + " " + highwayTools.blockQueue.peek().getBlock().toString() } else { "Moving to next block" } From 22f16625f7c93fb6b910bdc5d7cf2a4cf0abf259 Mon Sep 17 00:00:00 2001 From: Christian Date: Thu, 3 Sep 2020 05:13:35 +0200 Subject: [PATCH 016/390] Reformatting --- .../java/me/zeroeightsix/kami/KamiMod.java | 1 - .../kami/module/modules/misc/HighwayTools.kt | 239 +++++++++--------- .../kami/process/HighwayToolsProcess.kt | 9 +- 3 files changed, 129 insertions(+), 120 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/KamiMod.java b/src/main/java/me/zeroeightsix/kami/KamiMod.java index 01e923dfab..d3a8c270d2 100644 --- a/src/main/java/me/zeroeightsix/kami/KamiMod.java +++ b/src/main/java/me/zeroeightsix/kami/KamiMod.java @@ -36,7 +36,6 @@ import org.apache.logging.log4j.Logger; import org.lwjgl.opengl.Display; - import javax.annotation.Nullable; import java.io.IOException; import java.net.URL; diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index e99ad37e48..d7d3ef666d 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -32,7 +32,6 @@ import java.util.* import kotlin.math.floor import kotlin.math.roundToInt - /** * @author Avanatiker * @since 20/08/2020 @@ -83,6 +82,8 @@ class HighwayTools : Module() { private lateinit var currentBlockPos: BlockPos private lateinit var startingBlockPos: BlockPos + fun isDone(): Boolean { return blockQueue.size == 0 } + override fun onEnable() { if (mc.player == null) { disable() @@ -101,20 +102,9 @@ class HighwayTools : Module() { else { 0 } blockQueue.clear() - doneQueueReset() + doneQueue.clear() updateTasks() - if (buildDirectionSaved == 1 || buildDirectionSaved == 3 || buildDirectionSaved == 5 || buildDirectionSaved == 5 || buildDirectionSaved == 7) { - MessageSendHelper.sendChatMessage("$chatName Module started." + - "\n §9> §rDirection: §a" + directions[buildDirectionSaved] + "§r" + - "\n §9> §rCoordinates: §a" + mc.player.positionVector.x.roundToInt() + ", " + mc.player.positionVector.z.roundToInt() + "§r" + - "\n §9> §rBaritone mode: §a" + baritoneMode.value + "§r") - } else { - MessageSendHelper.sendChatMessage("$chatName Module started." + - "\n §9> §rDirection: §a" + directions[buildDirectionSaved] + "§r" + - "\n §9> §rCoordinate: §a" + buildDirectionCoordinateSaved + "§r" + - "\n §9> §rBaritone mode: §a" + baritoneMode.value + "§r") - } - + printEnable() } override fun onDisable() { @@ -132,10 +122,7 @@ class HighwayTools : Module() { lastHotbarSlot = -1 BaritoneAPI.getProvider().primaryBaritone.pathingBehavior.cancelEverything() - MessageSendHelper.sendChatMessage("$chatName Module stopped." + - "\n §9> §rPlaced blocks: §a" + totalBlocksPlaced + "§r" + - "\n §9> §rDestroyed blocks: §a" + totalBlocksDestroyed + "§r" + - "\n §9> §rDistance: §a" + totalBlocksDistanceWent + "§r") + printDisable() totalBlocksPlaced = 0 totalBlocksDestroyed = 0 totalBlocksDistanceWent = 0 @@ -150,7 +137,7 @@ class HighwayTools : Module() { pathing = false } if (!doTask()) { - doneQueueReset() + doneQueue.clear() blockQueue.clear() updateTasks() } @@ -158,11 +145,11 @@ class HighwayTools : Module() { if (checkTasks()) { currentBlockPos = getNextBlock() totalBlocksDistanceWent++ - doneQueueReset() + doneQueue.clear() updateTasks() pathing = true } else { - doneQueueReset() + doneQueue.clear() updateTasks() } } @@ -190,24 +177,6 @@ class HighwayTools : Module() { return true } - private fun printDebug() { - MessageSendHelper.sendChatMessage("#### LOG ####") - for (bt in blockQueue) { - MessageSendHelper.sendChatMessage(bt.getBlockPos().toString() + " " + bt.getTaskState().toString() + " " + bt.getBlock().toString()) - } - MessageSendHelper.sendChatMessage("#### DONE ####") - for (bt in doneQueue) { - MessageSendHelper.sendChatMessage(bt.getBlockPos().toString() + " " + bt.getTaskState().toString() + " " + bt.getBlock().toString()) - } - } - - fun printSettings() { - MessageSendHelper.sendChatMessage("---- Settings ----\nIgnored Blocks: ") - for (b in ignoreBlocks) { - MessageSendHelper.sendChatMessage(" > $b") - } - } - private fun doTask(): Boolean { BaritoneAPI.getProvider().primaryBaritone.pathingControlManager.registerProcess(KamiMod.highwayToolsProcess) if (!isDone() && !pathing) { @@ -333,58 +302,6 @@ class HighwayTools : Module() { } } - private fun updateRenderer(renderer: ESPRenderer): ESPRenderer { - val side = GeometryMasks.Quad.ALL - for (bt in blockQueue) { - if (bt.getTaskState() != TaskState.DONE) { renderer.add(bt.getBlockPos(), bt.getTaskState().color, side) } - } - for (bt in doneQueue) { - if (bt.getBlock()::class != BlockAir::class) { renderer.add(bt.getBlockPos(), bt.getTaskState().color, side) } - } - return renderer - } - - fun getNextBlock(): BlockPos { - // set head rotation to get max walking speed - val nextBlockPos: BlockPos - when (buildDirectionSaved) { - 0 -> { - nextBlockPos = currentBlockPos.north() - mc.player.rotationYaw = -180F - } - 1 -> { - nextBlockPos = currentBlockPos.north().east() - mc.player.rotationYaw = -135F - } - 2 -> { - nextBlockPos = currentBlockPos.east() - mc.player.rotationYaw = -90F - } - 3 -> { - nextBlockPos = currentBlockPos.south().east() - mc.player.rotationYaw = -45F - } - 4 -> { - nextBlockPos = currentBlockPos.south() - mc.player.rotationYaw = 0F - } - 5 -> { - nextBlockPos = currentBlockPos.south().west() - mc.player.rotationYaw = 45F - } - 6 -> { - nextBlockPos = currentBlockPos.west() - mc.player.rotationYaw = 90F - } - else -> { - nextBlockPos = currentBlockPos.north().west() - mc.player.rotationYaw = 135F - } - } - mc.player.rotationPitch = 0F - return nextBlockPos - } - private fun mineBlock(pos: BlockPos, pre: Boolean) { if (InventoryUtils.getSlotsHotbar(278) == null && InventoryUtils.getSlotsNoHotbar(278) != null) { InventoryUtils.moveToHotbar(278, 130, (tickDelay.value * 16).toLong()) @@ -487,6 +404,122 @@ class HighwayTools : Module() { mc.player.rotationPitch = lookAt.y.toFloat() } + fun getPlayerDirection(): Int { + val yaw = (mc.player.rotationYaw % 360 + 360) % 360 + return if (yaw >= 158 && yaw < 203) { 0 } //NORTH + else if (yaw >= 203 && yaw < 258) { 1 } //NORTH-EAST + else if (yaw >= 258 && yaw < 293) { 2 } //EAST + else if (yaw >= 293 && yaw < 338) { 3 } //SOUTH-EAST + else if (yaw >= 338 || yaw < 23) { 4 } //SOUTH + else if (yaw >= 23 && yaw < 68) { 5 } //SOUTH-WEST + else if (yaw >= 68 && yaw < 113) { 6 } //WEST + else { 7 } //NORTH-WEST + } + + private fun updateRenderer(renderer: ESPRenderer): ESPRenderer { + val side = GeometryMasks.Quad.ALL + for (bt in blockQueue) { + if (bt.getTaskState() != TaskState.DONE) { renderer.add(bt.getBlockPos(), bt.getTaskState().color, side) } + } + for (bt in doneQueue) { + if (bt.getBlock()::class != BlockAir::class) { renderer.add(bt.getBlockPos(), bt.getTaskState().color, side) } + } + return renderer + } + + override fun onWorldRender(event: RenderEvent) { + if (mc.player == null) return + val renderer = ESPRenderer() + renderer.aFilled = if (filled.value) aFilled.value else 0 + renderer.aOutline = if (outline.value) aOutline.value else 0 + updateRenderer(renderer) + renderer.render(true) + } + + private fun printDebug() { + MessageSendHelper.sendChatMessage("#### LOG ####") + for (bt in blockQueue) { + MessageSendHelper.sendChatMessage(bt.getBlockPos().toString() + " " + bt.getTaskState().toString() + " " + bt.getBlock().toString()) + } + MessageSendHelper.sendChatMessage("#### DONE ####") + for (bt in doneQueue) { + MessageSendHelper.sendChatMessage(bt.getBlockPos().toString() + " " + bt.getTaskState().toString() + " " + bt.getBlock().toString()) + } + } + + fun printSettings() { + var message = "$chatName Settings" + + "\n §9> §rMaterial: §7$material" + + "\n §9> §rBaritone: §7${baritoneMode.value}" + + "\n §9> §rIgnored Blocks:" + for (b in ignoreBlocks) { + message += "\n §9> §7$b" + } + MessageSendHelper.sendChatMessage(message) + } + + private fun printEnable() { + if (buildDirectionSaved == 1 || buildDirectionSaved == 3 || buildDirectionSaved == 5 || buildDirectionSaved == 5 || buildDirectionSaved == 7) { + MessageSendHelper.sendChatMessage("$chatName Module started." + + "\n §9> §7Direction: §a" + directions[buildDirectionSaved] + "§r" + + "\n §9> §7Coordinates: §a" + mc.player.positionVector.x.roundToInt() + ", " + mc.player.positionVector.z.roundToInt() + "§r" + + "\n §9> §7Baritone mode: §a" + baritoneMode.value + "§r") + } else { + MessageSendHelper.sendChatMessage("$chatName Module started." + + "\n §9> §7Direction: §a" + directions[buildDirectionSaved] + "§r" + + "\n §9> §7Coordinate: §a" + buildDirectionCoordinateSaved + "§r" + + "\n §9> §7Baritone mode: §a" + baritoneMode.value + "§r") + } + } + + private fun printDisable() { + MessageSendHelper.sendChatMessage("$chatName Module stopped." + + "\n §9> §rPlaced blocks: §a" + totalBlocksPlaced + "§r" + + "\n §9> §rDestroyed blocks: §a" + totalBlocksDestroyed + "§r" + + "\n §9> §rDistance: §a" + totalBlocksDistanceWent + "§r") + } + + fun getNextBlock(): BlockPos { + // set head rotation to get max walking speed + val nextBlockPos: BlockPos + when (buildDirectionSaved) { + 0 -> { + nextBlockPos = currentBlockPos.north() + mc.player.rotationYaw = -180F + } + 1 -> { + nextBlockPos = currentBlockPos.north().east() + mc.player.rotationYaw = -135F + } + 2 -> { + nextBlockPos = currentBlockPos.east() + mc.player.rotationYaw = -90F + } + 3 -> { + nextBlockPos = currentBlockPos.south().east() + mc.player.rotationYaw = -45F + } + 4 -> { + nextBlockPos = currentBlockPos.south() + mc.player.rotationYaw = 0F + } + 5 -> { + nextBlockPos = currentBlockPos.south().west() + mc.player.rotationYaw = 45F + } + 6 -> { + nextBlockPos = currentBlockPos.west() + mc.player.rotationYaw = 90F + } + else -> { + nextBlockPos = currentBlockPos.north().west() + mc.player.rotationYaw = 135F + } + } + mc.player.rotationPitch = 0F + return nextBlockPos + } + private fun updateBlockArray() { blockOffsets.clear() val b = currentBlockPos @@ -791,30 +824,6 @@ class HighwayTools : Module() { } } } - - fun isDone(): Boolean { return blockQueue.size == 0 } - private fun doneQueueReset() { doneQueue.clear() } - - override fun onWorldRender(event: RenderEvent) { - if (mc.player == null) return - val renderer = ESPRenderer() - renderer.aFilled = if (filled.value) aFilled.value else 0 - renderer.aOutline = if (outline.value) aOutline.value else 0 - updateRenderer(renderer) - renderer.render(true) - } - - fun getPlayerDirection(): Int { - val yaw = (mc.player.rotationYaw % 360 + 360) % 360 - return if (yaw >= 158 && yaw < 203) { 0 } //NORTH - else if (yaw >= 203 && yaw < 258) { 1 } //NORTH-EAST - else if (yaw >= 258 && yaw < 293) { 2 } //EAST - else if (yaw >= 293 && yaw < 338) { 3 } //SOUTH-EAST - else if (yaw >= 338 || yaw < 23) { 4 } //SOUTH - else if (yaw >= 23 && yaw < 68) { 5 } //SOUTH-WEST - else if (yaw >= 68 && yaw < 113) { 6 } //WEST - else { 7 } //NORTH-WEST - } } class BlockTask(private val bp: BlockPos, private var tt: TaskState, private val bb: Block) { diff --git a/src/main/java/me/zeroeightsix/kami/process/HighwayToolsProcess.kt b/src/main/java/me/zeroeightsix/kami/process/HighwayToolsProcess.kt index 9e75817edd..ff24f7e125 100644 --- a/src/main/java/me/zeroeightsix/kami/process/HighwayToolsProcess.kt +++ b/src/main/java/me/zeroeightsix/kami/process/HighwayToolsProcess.kt @@ -10,7 +10,8 @@ import me.zeroeightsix.kami.module.ModuleManager import me.zeroeightsix.kami.module.modules.misc.HighwayTools /** - * Created by Avanatiker on 26/08/20. + * @author Avanatiker + * @since 26/08/20 */ class HighwayToolsProcess : IBaritoneProcess { @@ -28,10 +29,10 @@ class HighwayToolsProcess : IBaritoneProcess { override fun displayName0(): String { val highwayTools = ModuleManager.getModuleT(HighwayTools::class.java)!! - val processName = if (highwayTools.blockQueue.size > 0) { - highwayTools.blockQueue.peek().getBlockPos().toString() + " " + highwayTools.blockQueue.peek().getTaskState().toString() + " " + highwayTools.blockQueue.peek().getBlock().toString() + val processName = if (highwayTools.blockQueue.size > 0 && !highwayTools.pathing) { + highwayTools.blockQueue.peek().getBlock().toString() + " @ " + highwayTools.blockQueue.peek().getBlockPos().toString() + " State: " + highwayTools.blockQueue.peek().getTaskState().toString() } else { - "Moving to next block" + "Moving to ${highwayTools.getNextBlock()}" } return "HighwayTools: $processName" } From c36064a7c18441c10e42a61f1e4acaa58bdd2812 Mon Sep 17 00:00:00 2001 From: Christian Date: Thu, 3 Sep 2020 05:58:24 +0200 Subject: [PATCH 017/390] Cleanup --- .../command/commands/HighwayToolsCommand.kt | 2 +- .../kami/module/modules/misc/HighwayTools.kt | 20 +++++++++---------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/command/commands/HighwayToolsCommand.kt b/src/main/java/me/zeroeightsix/kami/command/commands/HighwayToolsCommand.kt index a1d08665d8..288dfa179c 100644 --- a/src/main/java/me/zeroeightsix/kami/command/commands/HighwayToolsCommand.kt +++ b/src/main/java/me/zeroeightsix/kami/command/commands/HighwayToolsCommand.kt @@ -13,7 +13,7 @@ import net.minecraft.block.Block * @since 01/09/2020 */ class HighwayToolsCommand : Command("highwaytools", ChunkBuilder() - .append("mode", true, EnumParser(arrayOf("airspace", "corner", "material", "ignore", "baritone", "logout"))) + .append("mode", true, EnumParser(arrayOf("material", "ignore", "settings"))) .append("value") .build(), "ht") { diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index d7d3ef666d..f5eeb01e81 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -61,14 +61,13 @@ class HighwayTools : Module() { var material: Block = getBlockById(49) var ignoreBlocks = mutableListOf(BlockStandingSign(), BlockWallSign(), BlockBanner.BlockBannerHanging(), BlockBanner.BlockBannerStanding(), BlockPortal()) private var buildDirectionSaved = 0 - private var buildDirectionCoordinateSaved = 0 - private var buildDirectionCoordinateSavedY = 0 + private var buildDirectionCoordinate = 0 private val directions = listOf("North", "North-East", "East", "South-East", "South", "South-West", "West", "North-West") //Stats private var totalBlocksPlaced = 0 var totalBlocksDestroyed = 0 - private var totalBlocksDistanceWent = 0 + private var totalBlocksDistance = 0 //Custom settings @JvmField @@ -96,8 +95,7 @@ class HighwayTools : Module() { lastHotbarSlot = -1 playerHotbarSlot = mc.player.inventory.currentItem - buildDirectionCoordinateSavedY = startingBlockPos.getY() - buildDirectionCoordinateSaved = if (buildDirectionSaved == 0 || buildDirectionSaved == 4) { startingBlockPos.getX() } + buildDirectionCoordinate = if (buildDirectionSaved == 0 || buildDirectionSaved == 4) { startingBlockPos.getX() } else if (buildDirectionSaved == 2 || buildDirectionSaved == 6) { startingBlockPos.getZ() } else { 0 } @@ -125,7 +123,7 @@ class HighwayTools : Module() { printDisable() totalBlocksPlaced = 0 totalBlocksDestroyed = 0 - totalBlocksDistanceWent = 0 + totalBlocksDistance = 0 } override fun onUpdate() { @@ -144,7 +142,7 @@ class HighwayTools : Module() { } else { if (checkTasks()) { currentBlockPos = getNextBlock() - totalBlocksDistanceWent++ + totalBlocksDistance++ doneQueue.clear() updateTasks() pathing = true @@ -467,16 +465,16 @@ class HighwayTools : Module() { } else { MessageSendHelper.sendChatMessage("$chatName Module started." + "\n §9> §7Direction: §a" + directions[buildDirectionSaved] + "§r" + - "\n §9> §7Coordinate: §a" + buildDirectionCoordinateSaved + "§r" + + "\n §9> §7Coordinate: §a" + buildDirectionCoordinate + "§r" + "\n §9> §7Baritone mode: §a" + baritoneMode.value + "§r") } } private fun printDisable() { MessageSendHelper.sendChatMessage("$chatName Module stopped." + - "\n §9> §rPlaced blocks: §a" + totalBlocksPlaced + "§r" + - "\n §9> §rDestroyed blocks: §a" + totalBlocksDestroyed + "§r" + - "\n §9> §rDistance: §a" + totalBlocksDistanceWent + "§r") + "\n §9> §7Placed blocks: §a" + totalBlocksPlaced + "§r" + + "\n §9> §7Destroyed blocks: §a" + totalBlocksDestroyed + "§r" + + "\n §9> §7Distance: §a" + totalBlocksDistance + "§r") } fun getNextBlock(): BlockPos { From 0fdfdbd66cec250ca4b9e8400cb92788b20c5f41 Mon Sep 17 00:00:00 2001 From: Christian Date: Mon, 7 Sep 2020 19:04:47 +0200 Subject: [PATCH 018/390] Reworked command, liquids, block types, pathing - Better working commands - Better working liquid handling - Better block type implementation - Pathing works like intended now --- .../command/commands/HighwayToolsCommand.kt | 32 ++- .../kami/module/modules/misc/HighwayTools.kt | 185 ++++++++++-------- .../kami/process/HighwayToolsProcess.kt | 2 +- 3 files changed, 134 insertions(+), 85 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/command/commands/HighwayToolsCommand.kt b/src/main/java/me/zeroeightsix/kami/command/commands/HighwayToolsCommand.kt index 288dfa179c..cc044e4e75 100644 --- a/src/main/java/me/zeroeightsix/kami/command/commands/HighwayToolsCommand.kt +++ b/src/main/java/me/zeroeightsix/kami/command/commands/HighwayToolsCommand.kt @@ -31,16 +31,17 @@ class HighwayToolsCommand : Command("highwaytools", ChunkBuilder() ht!!.material = newmat MessageSendHelper.sendChatMessage("&7${newmat}&r is now your building material.") } catch (e: Exception) { - MessageSendHelper.sendChatMessage("&7${args[1]}&r is no material.") + MessageSendHelper.sendChatMessage("&7${args[1]}&r is no block.") } } - SubCommands.IGNORE -> { + SubCommands.IGNORE_ADD -> { try { - val newmat = Block.getBlockFromName(args[1].toString())!! + val newmat = Block.getBlockFromName(args[2].toString())!! if (newmat !in ht!!.ignoreBlocks) { ht.ignoreBlocks.add(newmat) - MessageSendHelper.sendChatMessage("&7${newmat}&r is now ignored.") + ht.printSettings() + MessageSendHelper.sendChatMessage("&7${newmat}&r is now added to your ignore list.") } else { MessageSendHelper.sendChatMessage("&7${newmat}&r is already ignored.") } @@ -49,6 +50,21 @@ class HighwayToolsCommand : Command("highwaytools", ChunkBuilder() } } + SubCommands.IGNORE_DEL -> { + try { + val newmat = Block.getBlockFromName(args[2].toString())!! + if (newmat !in ht!!.ignoreBlocks) { + ht.ignoreBlocks.remove(newmat) + ht.printSettings() + MessageSendHelper.sendChatMessage("&7${newmat}&r is now removed from your ignore list.") + } else { + MessageSendHelper.sendChatMessage("&7${newmat}&r is not yet ignored.") + } + } catch (e: Exception) { + MessageSendHelper.sendChatMessage("&7${args[1]}&r is no material.") + } + } + SubCommands.NULL -> { val commands = args.joinToString(separator = " ") MessageSendHelper.sendChatMessage("Invalid command &7${commandPrefix.value}${label} $commands&f!") @@ -64,14 +80,18 @@ class HighwayToolsCommand : Command("highwaytools", ChunkBuilder() args[0].equals("material", ignoreCase = true) -> SubCommands.MATERIAL - args[0].equals("ignore", ignoreCase = true) -> SubCommands.IGNORE + args[0].equals("ignore", ignoreCase = true) && args[2].isNullOrBlank() -> SubCommands.IGNORE_ADD + + args[0].equals("ignore", ignoreCase = true) && args[1].equals("add", ignoreCase = true) -> SubCommands.IGNORE_ADD + + args[0].equals("ignore", ignoreCase = true) && args[1].equals("del", ignoreCase = true) -> SubCommands.IGNORE_DEL else -> SubCommands.NULL } } private enum class SubCommands { - MATERIAL, IGNORE, SHOWSETTINGS, NULL + MATERIAL, IGNORE_ADD, IGNORE_DEL, SHOWSETTINGS, NULL } init { diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index f5eeb01e81..38d3ed8b49 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -5,6 +5,7 @@ import me.zeroeightsix.kami.KamiMod import me.zeroeightsix.kami.event.events.RenderEvent import me.zeroeightsix.kami.module.Module import me.zeroeightsix.kami.module.ModuleManager +import me.zeroeightsix.kami.module.modules.player.LagNotifier import me.zeroeightsix.kami.module.modules.player.NoBreakAnimation import me.zeroeightsix.kami.setting.Setting import me.zeroeightsix.kami.setting.Settings @@ -15,8 +16,7 @@ import me.zeroeightsix.kami.util.graphics.GeometryMasks import me.zeroeightsix.kami.util.math.RotationUtils import me.zeroeightsix.kami.util.text.MessageSendHelper import net.minecraft.block.* -import net.minecraft.block.Block.getBlockById -import net.minecraft.block.Block.getIdFromBlock +import net.minecraft.block.Block.* import net.minecraft.client.audio.PositionedSoundRecord import net.minecraft.entity.item.EntityItem import net.minecraft.entity.item.EntityXPOrb @@ -25,9 +25,11 @@ import net.minecraft.network.play.client.CPacketEntityAction import net.minecraft.network.play.client.CPacketPlayerDigging import net.minecraft.util.EnumFacing import net.minecraft.util.EnumHand +import net.minecraft.util.ResourceLocation import net.minecraft.util.math.AxisAlignedBB import net.minecraft.util.math.BlockPos import net.minecraft.util.math.Vec3d +import net.minecraftforge.fml.common.registry.ForgeRegistries import java.util.* import kotlin.math.floor import kotlin.math.roundToInt @@ -57,9 +59,7 @@ class HighwayTools : Module() { private var playerHotbarSlot = -1 private var lastHotbarSlot = -1 private var isSneaking = false - var pathing = false - var material: Block = getBlockById(49) - var ignoreBlocks = mutableListOf(BlockStandingSign(), BlockWallSign(), BlockBanner.BlockBannerHanging(), BlockBanner.BlockBannerStanding(), BlockPortal()) + var pathing = true private var buildDirectionSaved = 0 private var buildDirectionCoordinate = 0 private val directions = listOf("North", "North-East", "East", "South-East", "South", "South-West", "West", "North-West") @@ -71,7 +71,17 @@ class HighwayTools : Module() { //Custom settings @JvmField - var buildHeight: Setting = register(Settings.integerBuilder("BuildHeight").withMinimum(0).withValue(0).withMaximum(10).build()) + var material: Block = ForgeRegistries.BLOCKS.getValue(ResourceLocation("minecraft", "obsidian"))!! + var ignoreBlocks = mutableListOf(ForgeRegistries.BLOCKS.getValue(ResourceLocation("minecraft", "standing_sign")), + ForgeRegistries.BLOCKS.getValue(ResourceLocation("minecraft", "wall_sign")), + ForgeRegistries.BLOCKS.getValue(ResourceLocation("minecraft", "standing_banner")), + ForgeRegistries.BLOCKS.getValue(ResourceLocation("minecraft", "wall_banner")), + ForgeRegistries.BLOCKS.getValue(ResourceLocation("minecraft", "portal"))) + var buildHeight: Setting = register(Settings.integerBuilder("BuildHeight").withMinimum(1).withValue(4).withMaximum(6).build()) + var buildWidth: Setting = register(Settings.integerBuilder("BuildWidth").withMinimum(3).withValue(7).withMaximum(9).build()) + private val cornerBlock: Setting = register(Settings.b("CornerBlock", true)) + val clearSpace: Setting = register(Settings.b("ClearSpace", true)) + private val noRims: Setting = register(Settings.b("NoRims", false)) val blockQueue: Queue = LinkedList() private val doneQueue: Queue = LinkedList() @@ -130,8 +140,7 @@ class HighwayTools : Module() { if (mc.playerController == null) return if (!isDone()) { - val playerBlockPos = BlockPos(floor(mc.player.posX).toInt(), floor(mc.player.posY).toInt(), floor(mc.player.posZ).toInt()) - if (currentBlockPos.x == playerBlockPos.x && currentBlockPos.z == playerBlockPos.z) { + if (!BaritoneAPI.getProvider().primaryBaritone.pathingBehavior.isPathing) { pathing = false } if (!doTask()) { @@ -146,6 +155,7 @@ class HighwayTools : Module() { doneQueue.clear() updateTasks() pathing = true + lookInWalkDirection() } else { doneQueue.clear() updateTasks() @@ -163,7 +173,7 @@ class HighwayTools : Module() { val block = mc.world.getBlockState(bt.getBlockPos()).block var cont = false for (b in ignoreBlocks) { - if (b::class == block::class) { cont = true } + if (b!!::class == block::class) { cont = true } } if (cont) { continue } if (bt.getBlock()::class == material::class && block is BlockAir) { @@ -177,13 +187,13 @@ class HighwayTools : Module() { private fun doTask(): Boolean { BaritoneAPI.getProvider().primaryBaritone.pathingControlManager.registerProcess(KamiMod.highwayToolsProcess) - if (!isDone() && !pathing) { + if (!isDone() && !pathing && !ModuleManager.getModuleT(LagNotifier::class.java)!!.paused) { if (waitTicks == 0) { val blockAction = blockQueue.peek() if (blockAction.getTaskState() == TaskState.BREAK) { val block = mc.world.getBlockState(blockAction.getBlockPos()).block for (b in ignoreBlocks) { - if (block::class == b::class) { + if (block::class == b!!::class) { blockAction.setTaskState(TaskState.DONE) doTask() } @@ -205,7 +215,7 @@ class HighwayTools : Module() { } } if (insideBuild) { - addTask(neighbour, TaskState.PLACE, getBlockById(0)) + addTask(neighbour, TaskState.PLACE, ForgeRegistries.BLOCKS.getValue(ResourceLocation("minecraft", "netherrack"))!!) } else { addTask(neighbour, TaskState.PLACE, material) } @@ -249,7 +259,10 @@ class HighwayTools : Module() { blockQueue.remove() return true } - if (placeBlock(blockAction.getBlockPos())) { + if (block is BlockLiquid) { + blockAction.setBlock(ForgeRegistries.BLOCKS.getValue(ResourceLocation("minecraft", "netherrack"))!!) + } + if (placeBlock(blockAction.getBlockPos(), blockAction.getBlock())) { blockAction.setTaskState(TaskState.PLACED) if (blocksPerTick.value > blocksPlaced + 1) { blocksPlaced++ @@ -292,7 +305,8 @@ class HighwayTools : Module() { updateBlockArray() for ((a, b) in blockOffsets) { val block = mc.world.getBlockState(a).block - if (b && block is BlockAir) { addTask(a, TaskState.PLACE, material) } + if (!b && block in ignoreBlocks) { addTask(a, TaskState.DONE, getBlockById(0)) } + else if (b && block is BlockAir) { addTask(a, TaskState.PLACE, material) } else if (b && block !is BlockAir && block::class != material::class) { addTask(a, TaskState.BREAK, material) } else if (!b && block !is BlockAir) { addTask(a, TaskState.BREAK, getBlockById(0)) } else if (b && block::class == material::class) { addTask(a, TaskState.DONE, material) } @@ -321,7 +335,7 @@ class HighwayTools : Module() { mc.player.swingArm(EnumHand.MAIN_HAND) } - private fun placeBlock(pos: BlockPos): Boolean + private fun placeBlock(pos: BlockPos, mat: Block): Boolean { // check if block is already placed val block = mc.world.getBlockState(pos).block @@ -347,17 +361,17 @@ class HighwayTools : Module() { } //Swap to Obsidian in Hotbar or get from inventory - if (InventoryUtils.getSlotsHotbar(getIdFromBlock(material)) == null && InventoryUtils.getSlotsNoHotbar(getIdFromBlock(material)) != null) { - InventoryUtils.moveToHotbar(getIdFromBlock(material), 130, (tickDelay.value * 16).toLong()) + if (InventoryUtils.getSlotsHotbar(getIdFromBlock(mat)) == null && InventoryUtils.getSlotsNoHotbar(getIdFromBlock(mat)) != null) { + InventoryUtils.moveToHotbar(getIdFromBlock(mat), 130, (tickDelay.value * 16).toLong()) InventoryUtils.quickMoveSlot(1, (tickDelay.value * 16).toLong()) return false - } else if (InventoryUtils.getSlots(0, 35, getIdFromBlock(material)) == null) { - MessageSendHelper.sendChatMessage("$chatName No $material was found in inventory") + } else if (InventoryUtils.getSlots(0, 35, getIdFromBlock(mat)) == null) { + MessageSendHelper.sendChatMessage("$chatName No $mat was found in inventory") mc.getSoundHandler().playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) disable() return false } - InventoryUtils.swapSlotToItem(getIdFromBlock(material)) + InventoryUtils.swapSlotToItem(getIdFromBlock(mat)) val hitVec = Vec3d(neighbour).add(0.5, 0.5, 0.5).add(Vec3d(opposite.directionVec).scale(0.5)) val neighbourBlock = mc.world.getBlockState(neighbour).block @@ -478,44 +492,31 @@ class HighwayTools : Module() { } fun getNextBlock(): BlockPos { + return when (buildDirectionSaved) { + 0 -> { currentBlockPos.north() } + 1 -> { currentBlockPos.north().east() } + 2 -> { currentBlockPos.east() } + 3 -> { currentBlockPos.south().east() } + 4 -> { currentBlockPos.south() } + 5 -> { currentBlockPos.south().west() } + 6 -> { currentBlockPos.west() } + else -> { currentBlockPos.north().west() } + } + } + + private fun lookInWalkDirection() { // set head rotation to get max walking speed - val nextBlockPos: BlockPos when (buildDirectionSaved) { - 0 -> { - nextBlockPos = currentBlockPos.north() - mc.player.rotationYaw = -180F - } - 1 -> { - nextBlockPos = currentBlockPos.north().east() - mc.player.rotationYaw = -135F - } - 2 -> { - nextBlockPos = currentBlockPos.east() - mc.player.rotationYaw = -90F - } - 3 -> { - nextBlockPos = currentBlockPos.south().east() - mc.player.rotationYaw = -45F - } - 4 -> { - nextBlockPos = currentBlockPos.south() - mc.player.rotationYaw = 0F - } - 5 -> { - nextBlockPos = currentBlockPos.south().west() - mc.player.rotationYaw = 45F - } - 6 -> { - nextBlockPos = currentBlockPos.west() - mc.player.rotationYaw = 90F - } - else -> { - nextBlockPos = currentBlockPos.north().west() - mc.player.rotationYaw = 135F - } + 0 -> { mc.player.rotationYaw = -180F } + 1 -> { mc.player.rotationYaw = -135F } + 2 -> { mc.player.rotationYaw = -90F } + 3 -> { mc.player.rotationYaw = -45F } + 4 -> { mc.player.rotationYaw = 0F } + 5 -> { mc.player.rotationYaw = 45F } + 6 -> { mc.player.rotationYaw = 90F } + else -> { mc.player.rotationYaw = 135F } } mc.player.rotationPitch = 0F - return nextBlockPos } private fun updateBlockArray() { @@ -532,29 +533,56 @@ class HighwayTools : Module() { blockOffsets.add(Pair(b.down().north().north().west(), true)) blockOffsets.add(Pair(b.down().north().north().east().east(), true)) blockOffsets.add(Pair(b.down().north().north().west().west(), true)) - blockOffsets.add(Pair(b.down().north().north().east().east().east(), true)) - blockOffsets.add(Pair(b.down().north().north().west().west().west(), true)) - blockOffsets.add(Pair(b.north().north().east().east().east(), true)) - blockOffsets.add(Pair(b.north().north().west().west().west(), true)) - blockOffsets.add(Pair(b.north().north(), false)) - blockOffsets.add(Pair(b.north().north().east(), false)) - blockOffsets.add(Pair(b.north().north().west(), false)) - blockOffsets.add(Pair(b.north().north().east().east(), false)) - blockOffsets.add(Pair(b.north().north().west().west(), false)) - blockOffsets.add(Pair(b.up().north().north(), false)) - blockOffsets.add(Pair(b.up().north().north().east(), false)) - blockOffsets.add(Pair(b.up().north().north().west(), false)) - blockOffsets.add(Pair(b.up().north().north().east().east(), false)) - blockOffsets.add(Pair(b.up().north().north().west().west(), false)) - blockOffsets.add(Pair(b.up().north().north().east().east().east(), false)) - blockOffsets.add(Pair(b.up().north().north().west().west().west(), false)) - blockOffsets.add(Pair(b.up().up().north().north(), false)) - blockOffsets.add(Pair(b.up().up().north().north().east(), false)) - blockOffsets.add(Pair(b.up().up().north().north().west(), false)) - blockOffsets.add(Pair(b.up().up().north().north().east().east(), false)) - blockOffsets.add(Pair(b.up().up().north().north().west().west(), false)) - blockOffsets.add(Pair(b.up().up().north().north().east().east().east(), false)) - blockOffsets.add(Pair(b.up().up().north().north().west().west().west(), false)) + if (cornerBlock.value) { + blockOffsets.add(Pair(b.down().north().north().east().east().east(), true)) + blockOffsets.add(Pair(b.down().north().north().west().west().west(), true)) + } + if (buildHeight.value > 1) { + if (!noRims.value) { + blockOffsets.add(Pair(b.north().north().east().east().east(), true)) + blockOffsets.add(Pair(b.north().north().west().west().west(), true)) + } + } + if (clearSpace.value) { + if (noRims.value) { + blockOffsets.add(Pair(b.north().north().east().east().east(), false)) + blockOffsets.add(Pair(b.north().north().west().west().west(), false)) + } + if (buildHeight.value > 1) { + blockOffsets.add(Pair(b.north().north(), false)) + blockOffsets.add(Pair(b.north().north().east(), false)) + blockOffsets.add(Pair(b.north().north().west(), false)) + blockOffsets.add(Pair(b.north().north().east().east(), false)) + blockOffsets.add(Pair(b.north().north().west().west(), false)) + } + if (buildHeight.value > 2) { + blockOffsets.add(Pair(b.up().north().north(), false)) + blockOffsets.add(Pair(b.up().north().north().east(), false)) + blockOffsets.add(Pair(b.up().north().north().west(), false)) + blockOffsets.add(Pair(b.up().north().north().east().east(), false)) + blockOffsets.add(Pair(b.up().north().north().west().west(), false)) + blockOffsets.add(Pair(b.up().north().north().east().east().east(), false)) + blockOffsets.add(Pair(b.up().north().north().west().west().west(), false)) + } + if (buildHeight.value > 3) { + blockOffsets.add(Pair(b.up().up().north().north(), false)) + blockOffsets.add(Pair(b.up().up().north().north().east(), false)) + blockOffsets.add(Pair(b.up().up().north().north().west(), false)) + blockOffsets.add(Pair(b.up().up().north().north().east().east(), false)) + blockOffsets.add(Pair(b.up().up().north().north().west().west(), false)) + blockOffsets.add(Pair(b.up().up().north().north().east().east().east(), false)) + blockOffsets.add(Pair(b.up().up().north().north().west().west().west(), false)) + } + if (buildHeight.value > 4) { + blockOffsets.add(Pair(b.up().up().up().north().north(), false)) + blockOffsets.add(Pair(b.up().up().up().north().north().east(), false)) + blockOffsets.add(Pair(b.up().up().up().north().north().west(), false)) + blockOffsets.add(Pair(b.up().up().up().north().north().east().east(), false)) + blockOffsets.add(Pair(b.up().up().up().north().north().west().west(), false)) + blockOffsets.add(Pair(b.up().up().up().north().north().east().east().east(), false)) + blockOffsets.add(Pair(b.up().up().up().north().north().west().west().west(), false)) + } + } } 1 -> { // NORTH-EAST blockOffsets.add(Pair(b.north().east().down(), true)) @@ -824,11 +852,12 @@ class HighwayTools : Module() { } } -class BlockTask(private val bp: BlockPos, private var tt: TaskState, private val bb: Block) { +class BlockTask(private val bp: BlockPos, private var tt: TaskState, private var bb: Block) { fun getBlockPos(): BlockPos { return bp } fun getTaskState(): TaskState { return tt } fun setTaskState(tts: TaskState) { tt = tts } fun getBlock(): Block { return bb } + fun setBlock(b: Block) { bb = b } } enum class TaskState(val color: ColorHolder) { diff --git a/src/main/java/me/zeroeightsix/kami/process/HighwayToolsProcess.kt b/src/main/java/me/zeroeightsix/kami/process/HighwayToolsProcess.kt index ff24f7e125..f8d4ab223b 100644 --- a/src/main/java/me/zeroeightsix/kami/process/HighwayToolsProcess.kt +++ b/src/main/java/me/zeroeightsix/kami/process/HighwayToolsProcess.kt @@ -44,7 +44,7 @@ class HighwayToolsProcess : IBaritoneProcess { override fun onTick(p0: Boolean, p1: Boolean): PathingCommand? { baritone = BaritoneAPI.getProvider().primaryBaritone val highwayTools = ModuleManager.getModuleT(HighwayTools::class.java)!! - return if (highwayTools.pathing && highwayTools.baritoneMode.value) { + return if (highwayTools.baritoneMode.value && highwayTools.pathing) { PathingCommand(GoalNear(highwayTools.getNextBlock(), 0), PathingCommandType.SET_GOAL_AND_PATH) } else PathingCommand(null, PathingCommandType.REQUEST_PAUSE) } From 3824d39e0ac9fdf35a69cadb4c2bf1a60354e384 Mon Sep 17 00:00:00 2001 From: Christian Date: Sat, 12 Sep 2020 08:12:18 +0200 Subject: [PATCH 019/390] Such upgrade many work very smooth much wow - Added mind bending fully dynamically generated blueprint algorithm which respects six customizable variables and build sequence while having diagonal and straight possible - Rework of setting render with two pages now: Main and Build - Added option to choose if view gets set before walking - Added option to choose the detail level of prints - Added priority to BlockTask (Sort still does not work with PriorityQueue) - Fixed Block names with localizedName - Fixed print formatting - Optimized object properties - Added command to choose filler material --- .../command/commands/HighwayToolsCommand.kt | 26 +- .../kami/module/modules/misc/HighwayTools.kt | 597 +++++++----------- .../kami/process/HighwayToolsProcess.kt | 5 +- 3 files changed, 242 insertions(+), 386 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/command/commands/HighwayToolsCommand.kt b/src/main/java/me/zeroeightsix/kami/command/commands/HighwayToolsCommand.kt index cc044e4e75..84a000597c 100644 --- a/src/main/java/me/zeroeightsix/kami/command/commands/HighwayToolsCommand.kt +++ b/src/main/java/me/zeroeightsix/kami/command/commands/HighwayToolsCommand.kt @@ -13,7 +13,7 @@ import net.minecraft.block.Block * @since 01/09/2020 */ class HighwayToolsCommand : Command("highwaytools", ChunkBuilder() - .append("mode", true, EnumParser(arrayOf("material", "ignore", "settings"))) + .append("mode", true, EnumParser(arrayOf("material", "filler", "ignore", "settings"))) .append("value") .build(), "ht") { @@ -29,7 +29,17 @@ class HighwayToolsCommand : Command("highwaytools", ChunkBuilder() try { val newmat = Block.getBlockFromName(args[1].toString())!! ht!!.material = newmat - MessageSendHelper.sendChatMessage("&7${newmat}&r is now your building material.") + MessageSendHelper.sendChatMessage("&7${newmat.localizedName}&r is now your building material.") + } catch (e: Exception) { + MessageSendHelper.sendChatMessage("&7${args[1]}&r is no block.") + } + } + + SubCommands.FILLER -> { + try { + val newmat = Block.getBlockFromName(args[1].toString())!! + ht!!.fillerMat = newmat + MessageSendHelper.sendChatMessage("&7${newmat.localizedName}&r is now your filling material.") } catch (e: Exception) { MessageSendHelper.sendChatMessage("&7${args[1]}&r is no block.") } @@ -41,9 +51,9 @@ class HighwayToolsCommand : Command("highwaytools", ChunkBuilder() if (newmat !in ht!!.ignoreBlocks) { ht.ignoreBlocks.add(newmat) ht.printSettings() - MessageSendHelper.sendChatMessage("&7${newmat}&r is now added to your ignore list.") + MessageSendHelper.sendChatMessage("&7${newmat.localizedName}&r is now added to your ignore list.") } else { - MessageSendHelper.sendChatMessage("&7${newmat}&r is already ignored.") + MessageSendHelper.sendChatMessage("&7${newmat.localizedName}&r is already ignored.") } } catch (e: Exception) { MessageSendHelper.sendChatMessage("&7${args[1]}&r is no material.") @@ -56,9 +66,9 @@ class HighwayToolsCommand : Command("highwaytools", ChunkBuilder() if (newmat !in ht!!.ignoreBlocks) { ht.ignoreBlocks.remove(newmat) ht.printSettings() - MessageSendHelper.sendChatMessage("&7${newmat}&r is now removed from your ignore list.") + MessageSendHelper.sendChatMessage("&7${newmat.localizedName}&r is now removed from your ignore list.") } else { - MessageSendHelper.sendChatMessage("&7${newmat}&r is not yet ignored.") + MessageSendHelper.sendChatMessage("&7${newmat.localizedName}&r is not yet ignored.") } } catch (e: Exception) { MessageSendHelper.sendChatMessage("&7${args[1]}&r is no material.") @@ -80,6 +90,8 @@ class HighwayToolsCommand : Command("highwaytools", ChunkBuilder() args[0].equals("material", ignoreCase = true) -> SubCommands.MATERIAL + args[0].equals("filler", ignoreCase = true) -> SubCommands.FILLER + args[0].equals("ignore", ignoreCase = true) && args[2].isNullOrBlank() -> SubCommands.IGNORE_ADD args[0].equals("ignore", ignoreCase = true) && args[1].equals("add", ignoreCase = true) -> SubCommands.IGNORE_ADD @@ -91,7 +103,7 @@ class HighwayToolsCommand : Command("highwaytools", ChunkBuilder() } private enum class SubCommands { - MATERIAL, IGNORE_ADD, IGNORE_DEL, SHOWSETTINGS, NULL + MATERIAL, FILLER, IGNORE_ADD, IGNORE_DEL, SHOWSETTINGS, NULL } init { diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 38d3ed8b49..d7b984a34b 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -7,12 +7,12 @@ import me.zeroeightsix.kami.module.Module import me.zeroeightsix.kami.module.ModuleManager import me.zeroeightsix.kami.module.modules.player.LagNotifier import me.zeroeightsix.kami.module.modules.player.NoBreakAnimation -import me.zeroeightsix.kami.setting.Setting import me.zeroeightsix.kami.setting.Settings import me.zeroeightsix.kami.util.* import me.zeroeightsix.kami.util.color.ColorHolder import me.zeroeightsix.kami.util.graphics.ESPRenderer import me.zeroeightsix.kami.util.graphics.GeometryMasks +import me.zeroeightsix.kami.util.math.CoordinateConverter.asString import me.zeroeightsix.kami.util.math.RotationUtils import me.zeroeightsix.kami.util.text.MessageSendHelper import net.minecraft.block.* @@ -31,6 +31,8 @@ import net.minecraft.util.math.BlockPos import net.minecraft.util.math.Vec3d import net.minecraftforge.fml.common.registry.ForgeRegistries import java.util.* +import java.util.stream.IntStream.range +import kotlin.Comparator import kotlin.math.floor import kotlin.math.roundToInt @@ -45,17 +47,37 @@ import kotlin.math.roundToInt category = Module.Category.MISC ) class HighwayTools : Module() { + private val mode = register(Settings.e("Mode", Mode.HIGHWAY)) - val baritoneMode: Setting = register(Settings.b("Baritone", true)) - private val blocksPerTick = register(Settings.integerBuilder("Blocks Per Tick").withMinimum(1).withValue(1).withMaximum(9).build()) - private val tickDelay = register(Settings.integerBuilder("Tick-Delay Place").withMinimum(0).withValue(0).withMaximum(10).build()) - private val tickDelayBreak = register(Settings.integerBuilder("Tick-Delay Break").withMinimum(0).withValue(0).withMaximum(10).build()) - private val rotate = register(Settings.b("Rotate", true)) - private val filled = register(Settings.b("Filled", true)) - private val outline = register(Settings.b("Outline", true)) - private val aFilled = register(Settings.integerBuilder("Filled Alpha").withMinimum(0).withValue(31).withMaximum(255).withVisibility { filled.value }.build()) - private val aOutline = register(Settings.integerBuilder("Outline Alpha").withMinimum(0).withValue(127).withMaximum(255).withVisibility { outline.value }.build()) + private val page = register(Settings.e("Page", Page.MAIN)) + //Settings for module + val baritoneMode = register(Settings.booleanBuilder("Baritone").withValue(true).withVisibility { page.value == Page.MAIN }.build()) + private val blocksPerTick = register(Settings.integerBuilder("Blocks Per Tick").withMinimum(1).withValue(1).withMaximum(9).withVisibility { page.value == Page.MAIN }.build()) + private val tickDelay = register(Settings.integerBuilder("Tick-Delay Place").withMinimum(0).withValue(0).withMaximum(10).withVisibility { page.value == Page.MAIN }.build()) + private val tickDelayBreak = register(Settings.integerBuilder("Tick-Delay Break").withMinimum(0).withValue(0).withMaximum(10).withVisibility { page.value == Page.MAIN }.build()) + private val noViewReset = register(Settings.booleanBuilder("NoViewReset").withValue(true).withVisibility { page.value == Page.MAIN }.build()) + private val rotate = register(Settings.booleanBuilder("Rotate").withValue(true).withVisibility { page.value == Page.MAIN }.build()) + private val stats = register(Settings.booleanBuilder("ShowStats").withValue(true).withVisibility { page.value == Page.MAIN }.build()) + private val filled = register(Settings.booleanBuilder("Filled").withValue(true).withVisibility { page.value == Page.MAIN }.build()) + private val outline = register(Settings.booleanBuilder("Outline").withValue(true).withVisibility { page.value == Page.MAIN }.build()) + private val aFilled = register(Settings.integerBuilder("Filled Alpha").withMinimum(0).withValue(31).withMaximum(255).withVisibility { filled.value && page.value == Page.MAIN }.build()) + private val aOutline = register(Settings.integerBuilder("Outline Alpha").withMinimum(0).withValue(127).withMaximum(255).withVisibility { outline.value && page.value == Page.MAIN }.build()) + + //Custom build settings + val clearSpace = register(Settings.booleanBuilder("ClearSpace").withValue(true).withVisibility { page.value == Page.BUILD }.build()) + var clearHeight = register(Settings.integerBuilder("ClearHeight").withMinimum(1).withValue(4).withMaximum(6).withVisibility { page.value == Page.BUILD && clearSpace.value }.build()) + private var buildWidth = register(Settings.integerBuilder("BuildWidth").withMinimum(1).withValue(7).withMaximum(9).withVisibility { page.value == Page.BUILD }.build()) + private val rims = register(Settings.booleanBuilder("Rims").withValue(true).withVisibility { page.value == Page.BUILD }.build()) + private var rimHeight = register(Settings.integerBuilder("RimHeight").withMinimum(1).withValue(1).withMaximum(clearHeight.value).withVisibility { rims.value && page.value == Page.BUILD }.build()) + private val cornerBlock = register(Settings.booleanBuilder("CornerBlock").withValue(true).withVisibility { page.value == Page.BUILD }.build()) + var ignoreBlocks = mutableListOf(ForgeRegistries.BLOCKS.getValue(ResourceLocation("minecraft", "standing_sign")), + ForgeRegistries.BLOCKS.getValue(ResourceLocation("minecraft", "wall_sign")), + ForgeRegistries.BLOCKS.getValue(ResourceLocation("minecraft", "standing_banner")), + ForgeRegistries.BLOCKS.getValue(ResourceLocation("minecraft", "wall_banner")), + ForgeRegistries.BLOCKS.getValue(ResourceLocation("minecraft", "portal"))) + var material: Block = ForgeRegistries.BLOCKS.getValue(ResourceLocation("minecraft", "obsidian"))!! + var fillerMat: Block = ForgeRegistries.BLOCKS.getValue(ResourceLocation("minecraft", "netherrack"))!! private var playerHotbarSlot = -1 private var lastHotbarSlot = -1 private var isSneaking = false @@ -68,21 +90,8 @@ class HighwayTools : Module() { private var totalBlocksPlaced = 0 var totalBlocksDestroyed = 0 private var totalBlocksDistance = 0 - - //Custom settings - @JvmField - var material: Block = ForgeRegistries.BLOCKS.getValue(ResourceLocation("minecraft", "obsidian"))!! - var ignoreBlocks = mutableListOf(ForgeRegistries.BLOCKS.getValue(ResourceLocation("minecraft", "standing_sign")), - ForgeRegistries.BLOCKS.getValue(ResourceLocation("minecraft", "wall_sign")), - ForgeRegistries.BLOCKS.getValue(ResourceLocation("minecraft", "standing_banner")), - ForgeRegistries.BLOCKS.getValue(ResourceLocation("minecraft", "wall_banner")), - ForgeRegistries.BLOCKS.getValue(ResourceLocation("minecraft", "portal"))) - var buildHeight: Setting = register(Settings.integerBuilder("BuildHeight").withMinimum(1).withValue(4).withMaximum(6).build()) - var buildWidth: Setting = register(Settings.integerBuilder("BuildWidth").withMinimum(3).withValue(7).withMaximum(9).build()) - private val cornerBlock: Setting = register(Settings.b("CornerBlock", true)) - val clearSpace: Setting = register(Settings.b("ClearSpace", true)) - private val noRims: Setting = register(Settings.b("NoRims", false)) + //val blockQueue = PriorityQueue(TaskComparator()) val blockQueue: Queue = LinkedList() private val doneQueue: Queue = LinkedList() private var blockOffsets = mutableListOf>() @@ -138,11 +147,10 @@ class HighwayTools : Module() { override fun onUpdate() { if (mc.playerController == null) return - + if (!BaritoneAPI.getProvider().primaryBaritone.pathingBehavior.isPathing) { + pathing = false + } if (!isDone()) { - if (!BaritoneAPI.getProvider().primaryBaritone.pathingBehavior.isPathing) { - pathing = false - } if (!doTask()) { doneQueue.clear() blockQueue.clear() @@ -155,7 +163,7 @@ class HighwayTools : Module() { doneQueue.clear() updateTasks() pathing = true - lookInWalkDirection() + if (!noViewReset.value) lookInWalkDirection() } else { doneQueue.clear() updateTasks() @@ -164,8 +172,8 @@ class HighwayTools : Module() { //printDebug() } - private fun addTask(blockPos: BlockPos, taskState: TaskState, material: Block) { - blockQueue.add(BlockTask(blockPos, taskState, material)) + private fun addTask(blockPos: BlockPos, taskState: TaskState, material: Block, prio: Int) { + blockQueue.add(BlockTask(blockPos, taskState, material, prio)) } private fun checkTasks(): Boolean { @@ -195,6 +203,7 @@ class HighwayTools : Module() { for (b in ignoreBlocks) { if (block::class == b!!::class) { blockAction.setTaskState(TaskState.DONE) + blockAction.setPriority(4) doTask() } } @@ -215,9 +224,9 @@ class HighwayTools : Module() { } } if (insideBuild) { - addTask(neighbour, TaskState.PLACE, ForgeRegistries.BLOCKS.getValue(ResourceLocation("minecraft", "netherrack"))!!) + addTask(neighbour, TaskState.PLACE, fillerMat, 1) } else { - addTask(neighbour, TaskState.PLACE, material) + addTask(neighbour, TaskState.PLACE, material, 1) } } } @@ -229,6 +238,7 @@ class HighwayTools : Module() { } is BlockLiquid -> { blockAction.setTaskState(TaskState.PLACE) + blockAction.setPriority(3) doTask() } else -> { @@ -246,8 +256,10 @@ class HighwayTools : Module() { waitTicks = tickDelayBreak.value if (blockAction.getBlock()::class == material::class) { blockAction.setTaskState(TaskState.PLACE) + blockAction.setPriority(3) } else { blockAction.setTaskState(TaskState.DONE) + blockAction.setPriority(4) } doTask() } else { @@ -256,11 +268,11 @@ class HighwayTools : Module() { } else if (blockAction.getTaskState() == TaskState.PLACE) { val block = mc.world.getBlockState(blockAction.getBlockPos()).block if (blockAction.getBlock() is BlockAir && block !is BlockLiquid) { - blockQueue.remove() + blockQueue.poll() return true } if (block is BlockLiquid) { - blockAction.setBlock(ForgeRegistries.BLOCKS.getValue(ResourceLocation("minecraft", "netherrack"))!!) + blockAction.setBlock(fillerMat) } if (placeBlock(blockAction.getBlockPos(), blockAction.getBlock())) { blockAction.setTaskState(TaskState.PLACED) @@ -280,15 +292,17 @@ class HighwayTools : Module() { val block = mc.world.getBlockState(blockAction.getBlockPos()).block if (block !is BlockAir) { blockAction.setTaskState(TaskState.DONE) + blockAction.setPriority(4) } else { blockAction.setTaskState(TaskState.PLACE) } } else { blockAction.setTaskState(TaskState.BREAK) + blockAction.setPriority(2) } doTask() } else if (blockAction.getTaskState() == TaskState.DONE) { - blockQueue.remove() + blockQueue.poll() doneQueue.add(blockAction) doTask() } @@ -305,12 +319,12 @@ class HighwayTools : Module() { updateBlockArray() for ((a, b) in blockOffsets) { val block = mc.world.getBlockState(a).block - if (!b && block in ignoreBlocks) { addTask(a, TaskState.DONE, getBlockById(0)) } - else if (b && block is BlockAir) { addTask(a, TaskState.PLACE, material) } - else if (b && block !is BlockAir && block::class != material::class) { addTask(a, TaskState.BREAK, material) } - else if (!b && block !is BlockAir) { addTask(a, TaskState.BREAK, getBlockById(0)) } - else if (b && block::class == material::class) { addTask(a, TaskState.DONE, material) } - else if (!b && block is BlockAir) { addTask(a, TaskState.DONE, getBlockById(0)) } + if (!b && block in ignoreBlocks) { addTask(a, TaskState.DONE, getBlockById(0), 4) } + else if (b && block is BlockAir) { addTask(a, TaskState.PLACE, material, 3) } + else if (b && block !is BlockAir && block::class != material::class) { addTask(a, TaskState.BREAK, material, 2) } + else if (!b && block !is BlockAir) { addTask(a, TaskState.BREAK, getBlockById(0), 2) } + else if (b && block::class == material::class) { addTask(a, TaskState.DONE, material, 4) } + else if (!b && block is BlockAir) { addTask(a, TaskState.DONE, getBlockById(0), 4) } } } @@ -449,46 +463,57 @@ class HighwayTools : Module() { } private fun printDebug() { - MessageSendHelper.sendChatMessage("#### LOG ####") + MessageSendHelper.sendChatMessage("") + MessageSendHelper.sendChatMessage("") + MessageSendHelper.sendChatMessage("-------------------- QUEUE -------------------") for (bt in blockQueue) { - MessageSendHelper.sendChatMessage(bt.getBlockPos().toString() + " " + bt.getTaskState().toString() + " " + bt.getBlock().toString()) + MessageSendHelper.sendChatMessage(bt.getBlock().localizedName + "@(" + bt.getBlockPos().asString() + ") State: " + bt.getTaskState().toString() + " Prio: " + bt.getPriority()) } - MessageSendHelper.sendChatMessage("#### DONE ####") + MessageSendHelper.sendChatMessage("") + MessageSendHelper.sendChatMessage("-------------------- DONE --------------------") for (bt in doneQueue) { - MessageSendHelper.sendChatMessage(bt.getBlockPos().toString() + " " + bt.getTaskState().toString() + " " + bt.getBlock().toString()) + MessageSendHelper.sendChatMessage(bt.getBlock().localizedName + "@(" + bt.getBlockPos().asString() + ") State: " + bt.getTaskState().toString() + " Prio: " + bt.getPriority()) } } fun printSettings() { var message = "$chatName Settings" + - "\n §9> §rMaterial: §7$material" + + "\n §9> §rMaterial: §7${material.localizedName}" + "\n §9> §rBaritone: §7${baritoneMode.value}" + "\n §9> §rIgnored Blocks:" for (b in ignoreBlocks) { - message += "\n §9> §7$b" + message += "\n §9> §7${b!!.localizedName}" } MessageSendHelper.sendChatMessage(message) } private fun printEnable() { - if (buildDirectionSaved == 1 || buildDirectionSaved == 3 || buildDirectionSaved == 5 || buildDirectionSaved == 5 || buildDirectionSaved == 7) { - MessageSendHelper.sendChatMessage("$chatName Module started." + - "\n §9> §7Direction: §a" + directions[buildDirectionSaved] + "§r" + - "\n §9> §7Coordinates: §a" + mc.player.positionVector.x.roundToInt() + ", " + mc.player.positionVector.z.roundToInt() + "§r" + - "\n §9> §7Baritone mode: §a" + baritoneMode.value + "§r") + if (stats.value) { + if (buildDirectionSaved == 1 || buildDirectionSaved == 3 || buildDirectionSaved == 5 || buildDirectionSaved == 5 || buildDirectionSaved == 7) { + MessageSendHelper.sendChatMessage("$chatName Module started." + + "\n §9> §7Direction: §a" + directions[buildDirectionSaved] + "§r" + + "\n §9> §7Coordinates: §a" + mc.player.positionVector.x.roundToInt() + ", " + mc.player.positionVector.z.roundToInt() + "§r" + + "\n §9> §7Baritone mode: §a" + baritoneMode.value + "§r") + } else { + MessageSendHelper.sendChatMessage("$chatName Module started." + + "\n §9> §7Direction: §a" + directions[buildDirectionSaved] + "§r" + + "\n §9> §7Coordinate: §a" + buildDirectionCoordinate + "§r" + + "\n §9> §7Baritone mode: §a" + baritoneMode.value + "§r") + } } else { - MessageSendHelper.sendChatMessage("$chatName Module started." + - "\n §9> §7Direction: §a" + directions[buildDirectionSaved] + "§r" + - "\n §9> §7Coordinate: §a" + buildDirectionCoordinate + "§r" + - "\n §9> §7Baritone mode: §a" + baritoneMode.value + "§r") + MessageSendHelper.sendChatMessage("$chatName Module started.") } } private fun printDisable() { - MessageSendHelper.sendChatMessage("$chatName Module stopped." + - "\n §9> §7Placed blocks: §a" + totalBlocksPlaced + "§r" + - "\n §9> §7Destroyed blocks: §a" + totalBlocksDestroyed + "§r" + - "\n §9> §7Distance: §a" + totalBlocksDistance + "§r") + if (stats.value) { + MessageSendHelper.sendChatMessage("$chatName Module stopped." + + "\n §9> §7Placed blocks: §a" + totalBlocksPlaced + "§r" + + "\n §9> §7Destroyed blocks: §a" + totalBlocksDestroyed + "§r" + + "\n §9> §7Distance: §a" + totalBlocksDistance + "§r") + } else { + MessageSendHelper.sendChatMessage("$chatName Module stopped.") + } } fun getNextBlock(): BlockPos { @@ -519,320 +544,122 @@ class HighwayTools : Module() { mc.player.rotationPitch = 0F } + private fun relativeDirection(curs: BlockPos, steps: Int, turn: Int): BlockPos { + var c = curs + var d = (buildDirectionSaved + turn).rem(8) + if (d < 0) d += 8 + when (d) { + 0 -> c = c.north(steps) + 1 -> c = c.north(steps).east(steps) + 2 -> c = c.east(steps) + 3 -> c = c.south(steps).east(steps) + 4 -> c = c.south(steps) + 5 -> c = c.south(steps).west(steps) + 6 -> c = c.west(steps) + 7 -> c = c.north(steps).west(steps) + } + return c + } + + private fun isDiagonal(): Boolean { + return when(buildDirectionSaved) { + 1 -> true + 3 -> true + 5 -> true + 7 -> true + else -> false + } + } + private fun updateBlockArray() { blockOffsets.clear() val b = currentBlockPos when(mode.value) { Mode.HIGHWAY -> { - when (buildDirectionSaved) { - 0 -> { //NORTH - blockOffsets.add(Pair(b.down().north(), true)) - blockOffsets.add(Pair(b.down().north().north(), true)) - blockOffsets.add(Pair(b.down().north().north().east(), true)) - blockOffsets.add(Pair(b.down().north().north().west(), true)) - blockOffsets.add(Pair(b.down().north().north().east().east(), true)) - blockOffsets.add(Pair(b.down().north().north().west().west(), true)) - if (cornerBlock.value) { - blockOffsets.add(Pair(b.down().north().north().east().east().east(), true)) - blockOffsets.add(Pair(b.down().north().north().west().west().west(), true)) + var cursor = b + cursor = cursor.down() + + cursor = relativeDirection(cursor, 1, 0) + blockOffsets.add(Pair(cursor, true)) + cursor = relativeDirection(cursor, 1, 0) + + var flip = false + for (x in range(1, buildWidth.value + 1)) { + val alterDirection = if (flip) { -1 } else { 1 } + if (isDiagonal()) { + if (x != 1) { + blockOffsets.add(Pair(relativeDirection(relativeDirection(cursor, x / 2 - 1, 1 * alterDirection), x / 2, 3 * alterDirection), true)) } - if (buildHeight.value > 1) { - if (!noRims.value) { - blockOffsets.add(Pair(b.north().north().east().east().east(), true)) - blockOffsets.add(Pair(b.north().north().west().west().west(), true)) + blockOffsets.add(Pair(relativeDirection(cursor, x / 2, 2 * alterDirection), true)) + if (rims.value && x == buildWidth.value) { + var c = cursor + for (y in range(1, rimHeight.value + 1)) { + c = c.up() + if (buildWidth.value % 2 != 0) { + blockOffsets.add(Pair(relativeDirection(c, x / 2, 2 * alterDirection), true)) + blockOffsets.add(Pair(relativeDirection(c, x / 2, 2 * alterDirection * (-1)), true)) + } else { + blockOffsets.add(Pair(relativeDirection(c, x / 2, 2 * alterDirection), true)) + blockOffsets.add(Pair(relativeDirection(c, x / 2 - 1, 2 * alterDirection * (-1)), true)) + } } } if (clearSpace.value) { - if (noRims.value) { - blockOffsets.add(Pair(b.north().north().east().east().east(), false)) - blockOffsets.add(Pair(b.north().north().west().west().west(), false)) - } - if (buildHeight.value > 1) { - blockOffsets.add(Pair(b.north().north(), false)) - blockOffsets.add(Pair(b.north().north().east(), false)) - blockOffsets.add(Pair(b.north().north().west(), false)) - blockOffsets.add(Pair(b.north().north().east().east(), false)) - blockOffsets.add(Pair(b.north().north().west().west(), false)) + var c = cursor + for (y in range(1, clearHeight.value)) { + c = c.up() + if (rims.value) { + if (!((x == buildWidth.value || x == buildWidth.value - 1) && y <= rimHeight.value)) { + blockOffsets.add(Pair(relativeDirection(relativeDirection(c, x / 2 - 1, 1 * alterDirection), x / 2, 3 * alterDirection), false)) + blockOffsets.add(Pair(relativeDirection(c, x / 2, 2 * alterDirection), false)) + } else { + blockOffsets.add(Pair(relativeDirection(relativeDirection(c, x / 2 - 1, 1 * alterDirection), x / 2, 3 * alterDirection), false)) + } + } else { + if (x != 1) { + blockOffsets.add(Pair(relativeDirection(relativeDirection(c, x / 2 - 1, 1 * alterDirection), x / 2, 3 * alterDirection), false)) + } + blockOffsets.add(Pair(relativeDirection(c, x / 2, 2 * alterDirection), false)) + } } - if (buildHeight.value > 2) { - blockOffsets.add(Pair(b.up().north().north(), false)) - blockOffsets.add(Pair(b.up().north().north().east(), false)) - blockOffsets.add(Pair(b.up().north().north().west(), false)) - blockOffsets.add(Pair(b.up().north().north().east().east(), false)) - blockOffsets.add(Pair(b.up().north().north().west().west(), false)) - blockOffsets.add(Pair(b.up().north().north().east().east().east(), false)) - blockOffsets.add(Pair(b.up().north().north().west().west().west(), false)) + } + } else { + if (cornerBlock.value) { + blockOffsets.add(Pair(relativeDirection(cursor, x / 2, 2 * alterDirection), true)) + } else { + if (!(x == buildWidth.value || x == buildWidth.value - 1)) { + blockOffsets.add(Pair(relativeDirection(cursor, x / 2, 2 * alterDirection), true)) } - if (buildHeight.value > 3) { - blockOffsets.add(Pair(b.up().up().north().north(), false)) - blockOffsets.add(Pair(b.up().up().north().north().east(), false)) - blockOffsets.add(Pair(b.up().up().north().north().west(), false)) - blockOffsets.add(Pair(b.up().up().north().north().east().east(), false)) - blockOffsets.add(Pair(b.up().up().north().north().west().west(), false)) - blockOffsets.add(Pair(b.up().up().north().north().east().east().east(), false)) - blockOffsets.add(Pair(b.up().up().north().north().west().west().west(), false)) + } + if (rims.value && x == buildWidth.value) { + var c = cursor + for (y in range(1, rimHeight.value + 1)) { + c = c.up() + if (buildWidth.value % 2 != 0) { + blockOffsets.add(Pair(relativeDirection(c, x / 2, 2 * alterDirection), true)) + blockOffsets.add(Pair(relativeDirection(c, x / 2, 2 * alterDirection * (-1)), true)) + } else { + blockOffsets.add(Pair(relativeDirection(c, x / 2, 2 * alterDirection), true)) + blockOffsets.add(Pair(relativeDirection(c, x / 2 - 1, 2 * alterDirection * (-1)), true)) + } } - if (buildHeight.value > 4) { - blockOffsets.add(Pair(b.up().up().up().north().north(), false)) - blockOffsets.add(Pair(b.up().up().up().north().north().east(), false)) - blockOffsets.add(Pair(b.up().up().up().north().north().west(), false)) - blockOffsets.add(Pair(b.up().up().up().north().north().east().east(), false)) - blockOffsets.add(Pair(b.up().up().up().north().north().west().west(), false)) - blockOffsets.add(Pair(b.up().up().up().north().north().east().east().east(), false)) - blockOffsets.add(Pair(b.up().up().up().north().north().west().west().west(), false)) + } + if (clearSpace.value) { + var c = cursor + for (y in range(1, clearHeight.value)) { + c = c.up() + if (rims.value) { + if (!((x == buildWidth.value || x == buildWidth.value - 1) && y <= rimHeight.value)) { + blockOffsets.add(Pair(relativeDirection(c, x / 2, 2 * alterDirection), false)) + } + } else { + blockOffsets.add(Pair(relativeDirection(c, x / 2, 2 * alterDirection), false)) + } } } } - 1 -> { // NORTH-EAST - blockOffsets.add(Pair(b.north().east().down(), true)) - blockOffsets.add(Pair(b.north().east().down().north(), true)) - blockOffsets.add(Pair(b.north().east().down().east(), true)) - blockOffsets.add(Pair(b.north().east().down().north().east(), true)) - blockOffsets.add(Pair(b.north().east().down().north().north(), true)) - blockOffsets.add(Pair(b.north().east().down().east().east(), true)) - blockOffsets.add(Pair(b.north().east().down().east().east().south(), true)) - blockOffsets.add(Pair(b.north().east().down().north().north().west(), true)) - blockOffsets.add(Pair(b.north().east().down().east().east().south().east(), true)) - blockOffsets.add(Pair(b.north().east().down().north().north().west().north(), true)) - blockOffsets.add(Pair(b.north().east().east().east().south().east(), true)) - blockOffsets.add(Pair(b.north().east().north().north().west().north(), true)) - blockOffsets.add(Pair(b.north().east().north(), false)) - blockOffsets.add(Pair(b.north().east().north().up(), false)) - blockOffsets.add(Pair(b.north().east().north().up().up(), false)) - blockOffsets.add(Pair(b.north().east().east(), false)) - blockOffsets.add(Pair(b.north().east().east().up(), false)) - blockOffsets.add(Pair(b.north().east().east().up().up(), false)) - blockOffsets.add(Pair(b.north().east().north().east(), false)) - blockOffsets.add(Pair(b.north().east().north().east().up(), false)) - blockOffsets.add(Pair(b.north().east().north().east().up().up(), false)) - blockOffsets.add(Pair(b.north().east().north().north(), false)) - blockOffsets.add(Pair(b.north().east().north().north().up(), false)) - blockOffsets.add(Pair(b.north().east().north().north().up().up(), false)) - blockOffsets.add(Pair(b.north().east().east().east(), false)) - blockOffsets.add(Pair(b.north().east().east().east().up(), false)) - blockOffsets.add(Pair(b.north().east().east().east().up().up(), false)) - blockOffsets.add(Pair(b.north().east().north().north().west(), false)) - blockOffsets.add(Pair(b.north().east().north().north().west().up(), false)) - blockOffsets.add(Pair(b.north().east().north().north().west().up().up(), false)) - blockOffsets.add(Pair(b.north().east().east().east().south(), false)) - blockOffsets.add(Pair(b.north().east().east().east().south().up(), false)) - blockOffsets.add(Pair(b.north().east().east().east().south().up().up(), false)) - blockOffsets.add(Pair(b.north().east().north().north().west().north().up(), false)) - blockOffsets.add(Pair(b.north().east().north().north().west().north().up().up(), false)) - blockOffsets.add(Pair(b.north().east().east().east().south().east().up(), false)) - blockOffsets.add(Pair(b.north().east().east().east().south().east().up().up(), false)) - } - 2 -> { //EAST - blockOffsets.add(Pair(b.down().east(), true)) - blockOffsets.add(Pair(b.down().east().east(), true)) - blockOffsets.add(Pair(b.down().east().east().south(), true)) - blockOffsets.add(Pair(b.down().east().east().north(), true)) - blockOffsets.add(Pair(b.down().east().east().south().south(), true)) - blockOffsets.add(Pair(b.down().east().east().north().north(), true)) - blockOffsets.add(Pair(b.down().east().east().south().south().south(), true)) - blockOffsets.add(Pair(b.down().east().east().north().north().north(), true)) - blockOffsets.add(Pair(b.east().east().south().south().south(), true)) - blockOffsets.add(Pair(b.east().east().north().north().north(), true)) - blockOffsets.add(Pair(b.east().east(), false)) - blockOffsets.add(Pair(b.east().east().south(), false)) - blockOffsets.add(Pair(b.east().east().north(), false)) - blockOffsets.add(Pair(b.east().east().south().south(), false)) - blockOffsets.add(Pair(b.east().east().north().north(), false)) - blockOffsets.add(Pair(b.up().east().east(), false)) - blockOffsets.add(Pair(b.up().east().east().south(), false)) - blockOffsets.add(Pair(b.up().east().east().north(), false)) - blockOffsets.add(Pair(b.up().east().east().south().south(), false)) - blockOffsets.add(Pair(b.up().east().east().north().north(), false)) - blockOffsets.add(Pair(b.up().east().east().south().south().south(), false)) - blockOffsets.add(Pair(b.up().east().east().north().north().north(), false)) - blockOffsets.add(Pair(b.up().up().east().east(), false)) - blockOffsets.add(Pair(b.up().up().east().east().south(), false)) - blockOffsets.add(Pair(b.up().up().east().east().north(), false)) - blockOffsets.add(Pair(b.up().up().east().east().south().south(), false)) - blockOffsets.add(Pair(b.up().up().east().east().north().north(), false)) - blockOffsets.add(Pair(b.up().up().east().east().south().south().south(), false)) - blockOffsets.add(Pair(b.up().up().east().east().north().north().north(), false)) - } - 3 -> { //SOUTH-EAST - blockOffsets.add(Pair(b.east().south().down(), true)) - blockOffsets.add(Pair(b.east().south().down().east(), true)) - blockOffsets.add(Pair(b.east().south().down().south(), true)) - blockOffsets.add(Pair(b.east().south().down().east().south(), true)) - blockOffsets.add(Pair(b.east().south().down().east().east(), true)) - blockOffsets.add(Pair(b.east().south().down().south().south(), true)) - blockOffsets.add(Pair(b.east().south().down().south().south().west(), true)) - blockOffsets.add(Pair(b.east().south().down().east().east().north(), true)) - blockOffsets.add(Pair(b.east().south().down().south().south().west().south(), true)) - blockOffsets.add(Pair(b.east().south().down().east().east().north().east(), true)) - blockOffsets.add(Pair(b.east().south().south().south().west().south(), true)) - blockOffsets.add(Pair(b.east().south().east().east().north().east(), true)) - blockOffsets.add(Pair(b.east().south().east(), false)) - blockOffsets.add(Pair(b.east().south().east().up(), false)) - blockOffsets.add(Pair(b.east().south().east().up().up(), false)) - blockOffsets.add(Pair(b.east().south().south(), false)) - blockOffsets.add(Pair(b.east().south().south().up(), false)) - blockOffsets.add(Pair(b.east().south().south().up().up(), false)) - blockOffsets.add(Pair(b.east().south().east().south(), false)) - blockOffsets.add(Pair(b.east().south().east().south().up(), false)) - blockOffsets.add(Pair(b.east().south().east().south().up().up(), false)) - blockOffsets.add(Pair(b.east().south().east().east(), false)) - blockOffsets.add(Pair(b.east().south().east().east().up(), false)) - blockOffsets.add(Pair(b.east().south().east().east().up().up(), false)) - blockOffsets.add(Pair(b.east().south().south().south(), false)) - blockOffsets.add(Pair(b.east().south().south().south().up(), false)) - blockOffsets.add(Pair(b.east().south().south().south().up().up(), false)) - blockOffsets.add(Pair(b.east().south().east().east().north(), false)) - blockOffsets.add(Pair(b.east().south().east().east().north().up(), false)) - blockOffsets.add(Pair(b.east().south().east().east().north().up().up(), false)) - blockOffsets.add(Pair(b.east().south().south().south().west(), false)) - blockOffsets.add(Pair(b.east().south().south().south().west().up(), false)) - blockOffsets.add(Pair(b.east().south().south().south().west().up().up(), false)) - blockOffsets.add(Pair(b.east().south().east().east().north().east().up(), false)) - blockOffsets.add(Pair(b.east().south().east().east().north().east().up().up(), false)) - blockOffsets.add(Pair(b.east().south().south().south().west().south().up(), false)) - blockOffsets.add(Pair(b.east().south().south().south().west().south().up().up(), false)) - } - 4 -> { //SOUTH - blockOffsets.add(Pair(b.down().south(), true)) - blockOffsets.add(Pair(b.down().south().south(), true)) - blockOffsets.add(Pair(b.down().south().south().east(), true)) - blockOffsets.add(Pair(b.down().south().south().west(), true)) - blockOffsets.add(Pair(b.down().south().south().east().east(), true)) - blockOffsets.add(Pair(b.down().south().south().west().west(), true)) - blockOffsets.add(Pair(b.down().south().south().east().east().east(), true)) - blockOffsets.add(Pair(b.down().south().south().west().west().west(), true)) - blockOffsets.add(Pair(b.south().south().east().east().east(), true)) - blockOffsets.add(Pair(b.south().south().west().west().west(), true)) - blockOffsets.add(Pair(b.south().south(), false)) - blockOffsets.add(Pair(b.south().south().east(), false)) - blockOffsets.add(Pair(b.south().south().west(), false)) - blockOffsets.add(Pair(b.south().south().east().east(), false)) - blockOffsets.add(Pair(b.south().south().west().west(), false)) - blockOffsets.add(Pair(b.up().south().south(), false)) - blockOffsets.add(Pair(b.up().south().south().east(), false)) - blockOffsets.add(Pair(b.up().south().south().west(), false)) - blockOffsets.add(Pair(b.up().south().south().east().east(), false)) - blockOffsets.add(Pair(b.up().south().south().west().west(), false)) - blockOffsets.add(Pair(b.up().south().south().east().east().east(), false)) - blockOffsets.add(Pair(b.up().south().south().west().west().west(), false)) - blockOffsets.add(Pair(b.up().up().south().south(), false)) - blockOffsets.add(Pair(b.up().up().south().south().east(), false)) - blockOffsets.add(Pair(b.up().up().south().south().west(), false)) - blockOffsets.add(Pair(b.up().up().south().south().east().east(), false)) - blockOffsets.add(Pair(b.up().up().south().south().west().west(), false)) - blockOffsets.add(Pair(b.up().up().south().south().east().east().east(), false)) - blockOffsets.add(Pair(b.up().up().south().south().west().west().west(), false)) - } - 5 -> { // SOUTH-WEST - blockOffsets.add(Pair(b.south().west().down(), true)) - blockOffsets.add(Pair(b.south().west().down().south(), true)) - blockOffsets.add(Pair(b.south().west().down().west(), true)) - blockOffsets.add(Pair(b.south().west().down().south().west(), true)) - blockOffsets.add(Pair(b.south().west().down().south().south(), true)) - blockOffsets.add(Pair(b.south().west().down().west().west(), true)) - blockOffsets.add(Pair(b.south().west().down().west().west().north(), true)) - blockOffsets.add(Pair(b.south().west().down().south().south().east(), true)) - blockOffsets.add(Pair(b.south().west().down().west().west().north().west(), true)) - blockOffsets.add(Pair(b.south().west().down().south().south().east().south(), true)) - blockOffsets.add(Pair(b.south().west().west().west().north().west(), true)) - blockOffsets.add(Pair(b.south().west().south().south().east().south(), true)) - blockOffsets.add(Pair(b.south().west().south(), false)) - blockOffsets.add(Pair(b.south().west().south().up(), false)) - blockOffsets.add(Pair(b.south().west().south().up().up(), false)) - blockOffsets.add(Pair(b.south().west().west(), false)) - blockOffsets.add(Pair(b.south().west().west().up(), false)) - blockOffsets.add(Pair(b.south().west().west().up().up(), false)) - blockOffsets.add(Pair(b.south().west().south().west(), false)) - blockOffsets.add(Pair(b.south().west().south().west().up(), false)) - blockOffsets.add(Pair(b.south().west().south().west().up().up(), false)) - blockOffsets.add(Pair(b.south().west().south().south(), false)) - blockOffsets.add(Pair(b.south().west().south().south().up(), false)) - blockOffsets.add(Pair(b.south().west().south().south().up().up(), false)) - blockOffsets.add(Pair(b.south().west().west().west(), false)) - blockOffsets.add(Pair(b.south().west().west().west().up(), false)) - blockOffsets.add(Pair(b.south().west().west().west().up().up(), false)) - blockOffsets.add(Pair(b.south().west().south().south().east(), false)) - blockOffsets.add(Pair(b.south().west().south().south().east().up(), false)) - blockOffsets.add(Pair(b.south().west().south().south().east().up().up(), false)) - blockOffsets.add(Pair(b.south().west().west().west().north(), false)) - blockOffsets.add(Pair(b.south().west().west().west().north().up(), false)) - blockOffsets.add(Pair(b.south().west().west().west().north().up().up(), false)) - blockOffsets.add(Pair(b.south().west().south().south().east().south().up(), false)) - blockOffsets.add(Pair(b.south().west().south().south().east().south().up().up(), false)) - blockOffsets.add(Pair(b.south().west().west().west().north().west().up(), false)) - blockOffsets.add(Pair(b.south().west().west().west().north().west().up().up(), false)) - } - 6 -> { //WEST - blockOffsets.add(Pair(b.down().west(), true)) - blockOffsets.add(Pair(b.down().west().west(), true)) - blockOffsets.add(Pair(b.down().west().west().south(), true)) - blockOffsets.add(Pair(b.down().west().west().north(), true)) - blockOffsets.add(Pair(b.down().west().west().south().south(), true)) - blockOffsets.add(Pair(b.down().west().west().north().north(), true)) - blockOffsets.add(Pair(b.down().west().west().south().south().south(), true)) - blockOffsets.add(Pair(b.down().west().west().north().north().north(), true)) - blockOffsets.add(Pair(b.west().west().south().south().south(), true)) - blockOffsets.add(Pair(b.west().west().north().north().north(), true)) - blockOffsets.add(Pair(b.west().west(), false)) - blockOffsets.add(Pair(b.west().west().south(), false)) - blockOffsets.add(Pair(b.west().west().north(), false)) - blockOffsets.add(Pair(b.west().west().south().south(), false)) - blockOffsets.add(Pair(b.west().west().north().north(), false)) - blockOffsets.add(Pair(b.up().west().west(), false)) - blockOffsets.add(Pair(b.up().west().west().south(), false)) - blockOffsets.add(Pair(b.up().west().west().north(), false)) - blockOffsets.add(Pair(b.up().west().west().south().south(), false)) - blockOffsets.add(Pair(b.up().west().west().north().north(), false)) - blockOffsets.add(Pair(b.up().west().west().south().south().south(), false)) - blockOffsets.add(Pair(b.up().west().west().north().north().north(), false)) - blockOffsets.add(Pair(b.up().up().west().west(), false)) - blockOffsets.add(Pair(b.up().up().west().west().south(), false)) - blockOffsets.add(Pair(b.up().up().west().west().north(), false)) - blockOffsets.add(Pair(b.up().up().west().west().south().south(), false)) - blockOffsets.add(Pair(b.up().up().west().west().north().north(), false)) - blockOffsets.add(Pair(b.up().up().west().west().south().south().south(), false)) - blockOffsets.add(Pair(b.up().up().west().west().north().north().north(), false)) - } - 7 -> { //NORTH-WEST - blockOffsets.add(Pair(b.west().north().down(), true)) - blockOffsets.add(Pair(b.west().north().down().west(), true)) - blockOffsets.add(Pair(b.west().north().down().north(), true)) - blockOffsets.add(Pair(b.west().north().down().west().north(), true)) - blockOffsets.add(Pair(b.west().north().down().west().west(), true)) - blockOffsets.add(Pair(b.west().north().down().north().north(), true)) - blockOffsets.add(Pair(b.west().north().down().north().north().east(), true)) - blockOffsets.add(Pair(b.west().north().down().west().west().south(), true)) - blockOffsets.add(Pair(b.west().north().down().north().north().east().north(), true)) - blockOffsets.add(Pair(b.west().north().down().west().west().south().west(), true)) - blockOffsets.add(Pair(b.west().north().north().north().east().north(), true)) - blockOffsets.add(Pair(b.west().north().west().west().south().west(), true)) - blockOffsets.add(Pair(b.west().north().west(), false)) - blockOffsets.add(Pair(b.west().north().west().up(), false)) - blockOffsets.add(Pair(b.west().north().west().up().up(), false)) - blockOffsets.add(Pair(b.west().north().north(), false)) - blockOffsets.add(Pair(b.west().north().north().up(), false)) - blockOffsets.add(Pair(b.west().north().north().up().up(), false)) - blockOffsets.add(Pair(b.west().north().west().north(), false)) - blockOffsets.add(Pair(b.west().north().west().north().up(), false)) - blockOffsets.add(Pair(b.west().north().west().north().up().up(), false)) - blockOffsets.add(Pair(b.west().north().west().west(), false)) - blockOffsets.add(Pair(b.west().north().west().west().up(), false)) - blockOffsets.add(Pair(b.west().north().west().west().up().up(), false)) - blockOffsets.add(Pair(b.west().north().north().north(), false)) - blockOffsets.add(Pair(b.west().north().north().north().up(), false)) - blockOffsets.add(Pair(b.west().north().north().north().up().up(), false)) - blockOffsets.add(Pair(b.west().north().west().west().south(), false)) - blockOffsets.add(Pair(b.west().north().west().west().south().up(), false)) - blockOffsets.add(Pair(b.west().north().west().west().south().up().up(), false)) - blockOffsets.add(Pair(b.west().north().north().north().east(), false)) - blockOffsets.add(Pair(b.west().north().north().north().east().up(), false)) - blockOffsets.add(Pair(b.west().north().north().north().east().up().up(), false)) - blockOffsets.add(Pair(b.west().north().west().west().south().west().up(), false)) - blockOffsets.add(Pair(b.west().north().west().west().south().west().up().up(), false)) - blockOffsets.add(Pair(b.west().north().north().north().east().north().up(), false)) - blockOffsets.add(Pair(b.west().north().north().north().east().north().up().up(), false)) - } + flip = !flip } } Mode.FLAT -> { @@ -850,25 +677,41 @@ class HighwayTools : Module() { } } } -} -class BlockTask(private val bp: BlockPos, private var tt: TaskState, private var bb: Block) { - fun getBlockPos(): BlockPos { return bp } - fun getTaskState(): TaskState { return tt } - fun setTaskState(tts: TaskState) { tt = tts } - fun getBlock(): Block { return bb } - fun setBlock(b: Block) { bb = b } -} + private enum class Mode { + FLAT, HIGHWAY + } -enum class TaskState(val color: ColorHolder) { - BREAK(ColorHolder(222, 0, 0)), - BREAKING(ColorHolder(240, 222, 60)), - BROKE(ColorHolder(240, 77, 60)), - PLACE(ColorHolder(35, 188, 254)), - PLACED(ColorHolder(53, 222, 66)), - DONE(ColorHolder(50, 50, 50)) -} + private enum class Page { + MAIN, BUILD + } -enum class Mode { - FLAT, HIGHWAY + class BlockTask(private val bp: BlockPos, private var tt: TaskState, private var bb: Block, private var prio: Int) { + fun getBlockPos(): BlockPos { return bp } + fun getTaskState(): TaskState { return tt } + fun setTaskState(tts: TaskState) { tt = tts } + fun getBlock(): Block { return bb } + fun setBlock(b: Block) { bb = b } + fun getPriority(): Int { return prio } + fun setPriority(p: Int) { prio = p } + } + + private class TaskComparator: Comparator{ + override fun compare(o1: BlockTask?, o2: BlockTask?): Int { + if (o1 == null || o2 == null) { + return 0 + } + return o1.getPriority().compareTo(o2.getPriority()) + } + } + + enum class TaskState(val color: ColorHolder) { + BREAK(ColorHolder(222, 0, 0)), + BREAKING(ColorHolder(240, 222, 60)), + BROKE(ColorHolder(240, 77, 60)), + PLACE(ColorHolder(35, 188, 254)), + PLACED(ColorHolder(53, 222, 66)), + DONE(ColorHolder(50, 50, 50)) + } } + diff --git a/src/main/java/me/zeroeightsix/kami/process/HighwayToolsProcess.kt b/src/main/java/me/zeroeightsix/kami/process/HighwayToolsProcess.kt index f8d4ab223b..4d8f5cb63e 100644 --- a/src/main/java/me/zeroeightsix/kami/process/HighwayToolsProcess.kt +++ b/src/main/java/me/zeroeightsix/kami/process/HighwayToolsProcess.kt @@ -8,6 +8,7 @@ import baritone.api.process.PathingCommand import baritone.api.process.PathingCommandType import me.zeroeightsix.kami.module.ModuleManager import me.zeroeightsix.kami.module.modules.misc.HighwayTools +import me.zeroeightsix.kami.util.math.CoordinateConverter.asString /** * @author Avanatiker @@ -30,9 +31,9 @@ class HighwayToolsProcess : IBaritoneProcess { override fun displayName0(): String { val highwayTools = ModuleManager.getModuleT(HighwayTools::class.java)!! val processName = if (highwayTools.blockQueue.size > 0 && !highwayTools.pathing) { - highwayTools.blockQueue.peek().getBlock().toString() + " @ " + highwayTools.blockQueue.peek().getBlockPos().toString() + " State: " + highwayTools.blockQueue.peek().getTaskState().toString() + "Block: " + highwayTools.blockQueue.peek().getBlock().localizedName + " @ Position: (" + highwayTools.blockQueue.peek().getBlockPos().asString() + ") Prio: " + highwayTools.blockQueue.peek().getPriority() + " State: " + highwayTools.blockQueue.peek().getTaskState().toString() } else { - "Moving to ${highwayTools.getNextBlock()}" + "Moving to Position: (${highwayTools.getNextBlock().asString()})" } return "HighwayTools: $processName" } From 88c270f35e8bf0d4377577478532492042d1ee9c Mon Sep 17 00:00:00 2001 From: Christian Date: Sat, 12 Sep 2020 22:53:09 +0200 Subject: [PATCH 020/390] Dirty sequence fix - Added a stuck detection and resolve problem by shuffeling the Queue till it can place again - Dirty inventory manager fix. this can be way better --- .../kami/module/modules/misc/HighwayTools.kt | 56 +++++++++++++------ 1 file changed, 38 insertions(+), 18 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index d7b984a34b..29c14406b8 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -8,15 +8,19 @@ import me.zeroeightsix.kami.module.ModuleManager import me.zeroeightsix.kami.module.modules.player.LagNotifier import me.zeroeightsix.kami.module.modules.player.NoBreakAnimation import me.zeroeightsix.kami.setting.Settings -import me.zeroeightsix.kami.util.* +import me.zeroeightsix.kami.util.BlockUtils +import me.zeroeightsix.kami.util.InventoryUtils import me.zeroeightsix.kami.util.color.ColorHolder import me.zeroeightsix.kami.util.graphics.ESPRenderer import me.zeroeightsix.kami.util.graphics.GeometryMasks import me.zeroeightsix.kami.util.math.CoordinateConverter.asString import me.zeroeightsix.kami.util.math.RotationUtils import me.zeroeightsix.kami.util.text.MessageSendHelper -import net.minecraft.block.* -import net.minecraft.block.Block.* +import net.minecraft.block.Block +import net.minecraft.block.Block.getBlockById +import net.minecraft.block.Block.getIdFromBlock +import net.minecraft.block.BlockAir +import net.minecraft.block.BlockLiquid import net.minecraft.client.audio.PositionedSoundRecord import net.minecraft.entity.item.EntityItem import net.minecraft.entity.item.EntityXPOrb @@ -32,7 +36,6 @@ import net.minecraft.util.math.Vec3d import net.minecraftforge.fml.common.registry.ForgeRegistries import java.util.* import java.util.stream.IntStream.range -import kotlin.Comparator import kotlin.math.floor import kotlin.math.roundToInt @@ -75,6 +78,7 @@ class HighwayTools : Module() { ForgeRegistries.BLOCKS.getValue(ResourceLocation("minecraft", "wall_sign")), ForgeRegistries.BLOCKS.getValue(ResourceLocation("minecraft", "standing_banner")), ForgeRegistries.BLOCKS.getValue(ResourceLocation("minecraft", "wall_banner")), + ForgeRegistries.BLOCKS.getValue(ResourceLocation("minecraft", "bedrock")), ForgeRegistries.BLOCKS.getValue(ResourceLocation("minecraft", "portal"))) var material: Block = ForgeRegistries.BLOCKS.getValue(ResourceLocation("minecraft", "obsidian"))!! var fillerMat: Block = ForgeRegistries.BLOCKS.getValue(ResourceLocation("minecraft", "netherrack"))!! @@ -82,6 +86,7 @@ class HighwayTools : Module() { private var lastHotbarSlot = -1 private var isSneaking = false var pathing = true + private var stuckDetector = 0 private var buildDirectionSaved = 0 private var buildDirectionCoordinate = 0 private val directions = listOf("North", "North-East", "East", "South-East", "South", "South-West", "West", "North-West") @@ -92,7 +97,7 @@ class HighwayTools : Module() { private var totalBlocksDistance = 0 //val blockQueue = PriorityQueue(TaskComparator()) - val blockQueue: Queue = LinkedList() + var blockQueue: Queue = LinkedList() private val doneQueue: Queue = LinkedList() private var blockOffsets = mutableListOf>() private var waitTicks = 0 @@ -147,14 +152,27 @@ class HighwayTools : Module() { override fun onUpdate() { if (mc.playerController == null) return - if (!BaritoneAPI.getProvider().primaryBaritone.pathingBehavior.isPathing) { - pathing = false - } + if (!isDone()) { + if (!BaritoneAPI.getProvider().primaryBaritone.pathingBehavior.isPathing) { + pathing = false + } if (!doTask()) { - doneQueue.clear() - blockQueue.clear() - updateTasks() + if (!pathing && !ModuleManager.getModuleT(LagNotifier::class.java)!!.paused) { + stuckDetector += 1 + blockQueue = LinkedList(blockQueue.shuffled()) + if (stuckDetector > 20) { + doneQueue.clear() + blockQueue.clear() + updateTasks() + } + } else { + doneQueue.clear() + blockQueue.clear() + updateTasks() + } + } else { + stuckDetector = 0 } } else { if (checkTasks()) { @@ -218,9 +236,9 @@ class HighwayTools : Module() { } if (!found) { var insideBuild = false - for ((pos, buildBlock) in blockOffsets) { + for ((pos, _) in blockOffsets) { if (neighbour == pos) { - if (!buildBlock) { insideBuild = true } + insideBuild = true } } if (insideBuild) { @@ -374,13 +392,15 @@ class HighwayTools : Module() { return false } - //Swap to Obsidian in Hotbar or get from inventory + //Swap to material in Hotbar or get from inventory if (InventoryUtils.getSlotsHotbar(getIdFromBlock(mat)) == null && InventoryUtils.getSlotsNoHotbar(getIdFromBlock(mat)) != null) { - InventoryUtils.moveToHotbar(getIdFromBlock(mat), 130, (tickDelay.value * 16).toLong()) - InventoryUtils.quickMoveSlot(1, (tickDelay.value * 16).toLong()) - return false + //InventoryUtils.moveToHotbar(getIdFromBlock(mat), 130, (tickDelay.value * 16).toLong()) + for (x in InventoryUtils.getSlotsNoHotbar(getIdFromBlock(mat))!!) { + InventoryUtils.quickMoveSlot(x, (tickDelay.value * 16).toLong()) + } + //InventoryUtils.quickMoveSlot(1, (tickDelay.value * 16).toLong()) } else if (InventoryUtils.getSlots(0, 35, getIdFromBlock(mat)) == null) { - MessageSendHelper.sendChatMessage("$chatName No $mat was found in inventory") + MessageSendHelper.sendChatMessage("$chatName No ${mat.localizedName} was found in inventory") mc.getSoundHandler().playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) disable() return false From e120eced129c58e8099c1be75715453f84832f2e Mon Sep 17 00:00:00 2001 From: Christian Date: Sun, 13 Sep 2020 04:56:58 +0200 Subject: [PATCH 021/390] Patched compatibility with AutoObsidian --- .../me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 29c14406b8..85ce391afb 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -5,6 +5,7 @@ import me.zeroeightsix.kami.KamiMod import me.zeroeightsix.kami.event.events.RenderEvent import me.zeroeightsix.kami.module.Module import me.zeroeightsix.kami.module.ModuleManager +import me.zeroeightsix.kami.module.modules.player.InventoryManager import me.zeroeightsix.kami.module.modules.player.LagNotifier import me.zeroeightsix.kami.module.modules.player.NoBreakAnimation import me.zeroeightsix.kami.setting.Settings @@ -212,8 +213,8 @@ class HighwayTools : Module() { } private fun doTask(): Boolean { - BaritoneAPI.getProvider().primaryBaritone.pathingControlManager.registerProcess(KamiMod.highwayToolsProcess) - if (!isDone() && !pathing && !ModuleManager.getModuleT(LagNotifier::class.java)!!.paused) { + if (!isDone() && !pathing && !ModuleManager.getModuleT(LagNotifier::class.java)!!.paused && !ModuleManager.getModuleT(AutoObsidian::class.java)!!.active) { + BaritoneAPI.getProvider().primaryBaritone.pathingControlManager.registerProcess(KamiMod.highwayToolsProcess) if (waitTicks == 0) { val blockAction = blockQueue.peek() if (blockAction.getTaskState() == TaskState.BREAK) { From 467bd78db497078098405e25fba13552bb4be620 Mon Sep 17 00:00:00 2001 From: Christian Date: Mon, 14 Sep 2020 04:09:58 +0200 Subject: [PATCH 022/390] Review requested changes made Check diff --- .../command/commands/HighwayToolsCommand.kt | 16 +- .../kami/module/modules/misc/HighwayTools.kt | 452 ++++++++++-------- .../kami/process/HighwayToolsProcess.kt | 2 +- 3 files changed, 256 insertions(+), 214 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/command/commands/HighwayToolsCommand.kt b/src/main/java/me/zeroeightsix/kami/command/commands/HighwayToolsCommand.kt index 84a000597c..ca0652134e 100644 --- a/src/main/java/me/zeroeightsix/kami/command/commands/HighwayToolsCommand.kt +++ b/src/main/java/me/zeroeightsix/kami/command/commands/HighwayToolsCommand.kt @@ -29,9 +29,9 @@ class HighwayToolsCommand : Command("highwaytools", ChunkBuilder() try { val newmat = Block.getBlockFromName(args[1].toString())!! ht!!.material = newmat - MessageSendHelper.sendChatMessage("&7${newmat.localizedName}&r is now your building material.") + MessageSendHelper.sendChatMessage("Set your building material to &7${newmat.localizedName}&r.") } catch (e: Exception) { - MessageSendHelper.sendChatMessage("&7${args[1]}&r is no block.") + MessageSendHelper.sendChatMessage("&7${args[1]}&r is not a valid block.") } } @@ -39,9 +39,9 @@ class HighwayToolsCommand : Command("highwaytools", ChunkBuilder() try { val newmat = Block.getBlockFromName(args[1].toString())!! ht!!.fillerMat = newmat - MessageSendHelper.sendChatMessage("&7${newmat.localizedName}&r is now your filling material.") + MessageSendHelper.sendChatMessage("Set your filling material to &7${newmat.localizedName}&r.") } catch (e: Exception) { - MessageSendHelper.sendChatMessage("&7${args[1]}&r is no block.") + MessageSendHelper.sendChatMessage("&7${args[1]}&r is not a valid block.") } } @@ -51,12 +51,12 @@ class HighwayToolsCommand : Command("highwaytools", ChunkBuilder() if (newmat !in ht!!.ignoreBlocks) { ht.ignoreBlocks.add(newmat) ht.printSettings() - MessageSendHelper.sendChatMessage("&7${newmat.localizedName}&r is now added to your ignore list.") + MessageSendHelper.sendChatMessage("Added &7${newmat.localizedName}&r to ignore list.") } else { MessageSendHelper.sendChatMessage("&7${newmat.localizedName}&r is already ignored.") } } catch (e: Exception) { - MessageSendHelper.sendChatMessage("&7${args[1]}&r is no material.") + MessageSendHelper.sendChatMessage("&7${args[1]}&r is not a valid block.") } } @@ -66,12 +66,12 @@ class HighwayToolsCommand : Command("highwaytools", ChunkBuilder() if (newmat !in ht!!.ignoreBlocks) { ht.ignoreBlocks.remove(newmat) ht.printSettings() - MessageSendHelper.sendChatMessage("&7${newmat.localizedName}&r is now removed from your ignore list.") + MessageSendHelper.sendChatMessage("Removed &7${newmat.localizedName}&r from ignore list.") } else { MessageSendHelper.sendChatMessage("&7${newmat.localizedName}&r is not yet ignored.") } } catch (e: Exception) { - MessageSendHelper.sendChatMessage("&7${args[1]}&r is no material.") + MessageSendHelper.sendChatMessage("&7${args[1]}&r is not a valid block.") } } diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 85ce391afb..ff5ddf1a71 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -5,7 +5,6 @@ import me.zeroeightsix.kami.KamiMod import me.zeroeightsix.kami.event.events.RenderEvent import me.zeroeightsix.kami.module.Module import me.zeroeightsix.kami.module.ModuleManager -import me.zeroeightsix.kami.module.modules.player.InventoryManager import me.zeroeightsix.kami.module.modules.player.LagNotifier import me.zeroeightsix.kami.module.modules.player.NoBreakAnimation import me.zeroeightsix.kami.setting.Settings @@ -16,25 +15,23 @@ import me.zeroeightsix.kami.util.graphics.ESPRenderer import me.zeroeightsix.kami.util.graphics.GeometryMasks import me.zeroeightsix.kami.util.math.CoordinateConverter.asString import me.zeroeightsix.kami.util.math.RotationUtils +import me.zeroeightsix.kami.util.math.VectorUtils import me.zeroeightsix.kami.util.text.MessageSendHelper -import net.minecraft.block.Block +import net.minecraft.block.* import net.minecraft.block.Block.getBlockById import net.minecraft.block.Block.getIdFromBlock -import net.minecraft.block.BlockAir -import net.minecraft.block.BlockLiquid import net.minecraft.client.audio.PositionedSoundRecord import net.minecraft.entity.item.EntityItem import net.minecraft.entity.item.EntityXPOrb +import net.minecraft.init.Blocks import net.minecraft.init.SoundEvents import net.minecraft.network.play.client.CPacketEntityAction import net.minecraft.network.play.client.CPacketPlayerDigging import net.minecraft.util.EnumFacing import net.minecraft.util.EnumHand -import net.minecraft.util.ResourceLocation import net.minecraft.util.math.AxisAlignedBB import net.minecraft.util.math.BlockPos import net.minecraft.util.math.Vec3d -import net.minecraftforge.fml.common.registry.ForgeRegistries import java.util.* import java.util.stream.IntStream.range import kotlin.math.floor @@ -54,20 +51,21 @@ class HighwayTools : Module() { private val mode = register(Settings.e("Mode", Mode.HIGHWAY)) private val page = register(Settings.e("Page", Page.MAIN)) - //Settings for module - val baritoneMode = register(Settings.booleanBuilder("Baritone").withValue(true).withVisibility { page.value == Page.MAIN }.build()) - private val blocksPerTick = register(Settings.integerBuilder("Blocks Per Tick").withMinimum(1).withValue(1).withMaximum(9).withVisibility { page.value == Page.MAIN }.build()) - private val tickDelay = register(Settings.integerBuilder("Tick-Delay Place").withMinimum(0).withValue(0).withMaximum(10).withVisibility { page.value == Page.MAIN }.build()) - private val tickDelayBreak = register(Settings.integerBuilder("Tick-Delay Break").withMinimum(0).withValue(0).withMaximum(10).withVisibility { page.value == Page.MAIN }.build()) - private val noViewReset = register(Settings.booleanBuilder("NoViewReset").withValue(true).withVisibility { page.value == Page.MAIN }.build()) + + // settings for module + val baritoneMode = register(Settings.booleanBuilder("Baritone").withValue(true).withVisibility { false }.build()) + private val blocksPerTick = register(Settings.integerBuilder("BlocksPerTick").withMinimum(1).withValue(1).withMaximum(9).withVisibility { page.value == Page.MAIN }.build()) + private val tickDelay = register(Settings.integerBuilder("TickDelayPlace").withMinimum(0).withValue(0).withMaximum(10).withVisibility { page.value == Page.MAIN }.build()) + private val tickDelayBreak = register(Settings.integerBuilder("TickDelayBreak").withMinimum(0).withValue(0).withMaximum(10).withVisibility { page.value == Page.MAIN }.build()) + private val noViewReset = register(Settings.booleanBuilder("NoViewReset").withValue(false).withVisibility { page.value == Page.MAIN }.build()) private val rotate = register(Settings.booleanBuilder("Rotate").withValue(true).withVisibility { page.value == Page.MAIN }.build()) - private val stats = register(Settings.booleanBuilder("ShowStats").withValue(true).withVisibility { page.value == Page.MAIN }.build()) + private val info = register(Settings.booleanBuilder("ShowInfo").withValue(true).withVisibility { page.value == Page.MAIN }.build()) private val filled = register(Settings.booleanBuilder("Filled").withValue(true).withVisibility { page.value == Page.MAIN }.build()) private val outline = register(Settings.booleanBuilder("Outline").withValue(true).withVisibility { page.value == Page.MAIN }.build()) - private val aFilled = register(Settings.integerBuilder("Filled Alpha").withMinimum(0).withValue(31).withMaximum(255).withVisibility { filled.value && page.value == Page.MAIN }.build()) - private val aOutline = register(Settings.integerBuilder("Outline Alpha").withMinimum(0).withValue(127).withMaximum(255).withVisibility { outline.value && page.value == Page.MAIN }.build()) + private val aFilled = register(Settings.integerBuilder("FilledAlpha").withMinimum(0).withValue(31).withMaximum(255).withVisibility { filled.value && page.value == Page.MAIN }.build()) + private val aOutline = register(Settings.integerBuilder("OutlineAlpha").withMinimum(0).withValue(127).withMaximum(255).withVisibility { outline.value && page.value == Page.MAIN }.build()) - //Custom build settings + // custom build settings val clearSpace = register(Settings.booleanBuilder("ClearSpace").withValue(true).withVisibility { page.value == Page.BUILD }.build()) var clearHeight = register(Settings.integerBuilder("ClearHeight").withMinimum(1).withValue(4).withMaximum(6).withVisibility { page.value == Page.BUILD && clearSpace.value }.build()) private var buildWidth = register(Settings.integerBuilder("BuildWidth").withMinimum(1).withValue(7).withMaximum(9).withVisibility { page.value == Page.BUILD }.build()) @@ -75,14 +73,9 @@ class HighwayTools : Module() { private var rimHeight = register(Settings.integerBuilder("RimHeight").withMinimum(1).withValue(1).withMaximum(clearHeight.value).withVisibility { rims.value && page.value == Page.BUILD }.build()) private val cornerBlock = register(Settings.booleanBuilder("CornerBlock").withValue(true).withVisibility { page.value == Page.BUILD }.build()) - var ignoreBlocks = mutableListOf(ForgeRegistries.BLOCKS.getValue(ResourceLocation("minecraft", "standing_sign")), - ForgeRegistries.BLOCKS.getValue(ResourceLocation("minecraft", "wall_sign")), - ForgeRegistries.BLOCKS.getValue(ResourceLocation("minecraft", "standing_banner")), - ForgeRegistries.BLOCKS.getValue(ResourceLocation("minecraft", "wall_banner")), - ForgeRegistries.BLOCKS.getValue(ResourceLocation("minecraft", "bedrock")), - ForgeRegistries.BLOCKS.getValue(ResourceLocation("minecraft", "portal"))) - var material: Block = ForgeRegistries.BLOCKS.getValue(ResourceLocation("minecraft", "obsidian"))!! - var fillerMat: Block = ForgeRegistries.BLOCKS.getValue(ResourceLocation("minecraft", "netherrack"))!! + var ignoreBlocks = mutableListOf(Blocks.STANDING_SIGN, Blocks.WALL_SIGN, Blocks.STANDING_BANNER, Blocks.WALL_BANNER, Blocks.BEDROCK, Blocks.PORTAL) + var material: Block = Blocks.OBSIDIAN + var fillerMat: Block = Blocks.NETHERRACK private var playerHotbarSlot = -1 private var lastHotbarSlot = -1 private var isSneaking = false @@ -92,9 +85,9 @@ class HighwayTools : Module() { private var buildDirectionCoordinate = 0 private val directions = listOf("North", "North-East", "East", "South-East", "South", "South-West", "West", "North-West") - //Stats + // stats private var totalBlocksPlaced = 0 - var totalBlocksDestroyed = 0 + private var totalBlocksDestroyed = 0 private var totalBlocksDistance = 0 //val blockQueue = PriorityQueue(TaskComparator()) @@ -106,7 +99,9 @@ class HighwayTools : Module() { private lateinit var currentBlockPos: BlockPos private lateinit var startingBlockPos: BlockPos - fun isDone(): Boolean { return blockQueue.size == 0 } + fun isDone(): Boolean { + return blockQueue.size == 0 + } override fun onEnable() { if (mc.player == null) { @@ -120,13 +115,15 @@ class HighwayTools : Module() { lastHotbarSlot = -1 playerHotbarSlot = mc.player.inventory.currentItem - buildDirectionCoordinate = if (buildDirectionSaved == 0 || buildDirectionSaved == 4) { startingBlockPos.getX() } - else if (buildDirectionSaved == 2 || buildDirectionSaved == 6) { startingBlockPos.getZ() } - else { 0 } + buildDirectionCoordinate = if (buildDirectionSaved == 0 || buildDirectionSaved == 4) { + startingBlockPos.getX() + } else if (buildDirectionSaved == 2 || buildDirectionSaved == 6) { + startingBlockPos.getZ() + } else { + 0 + } - blockQueue.clear() - doneQueue.clear() - updateTasks() + refreshData() printEnable() } @@ -163,14 +160,10 @@ class HighwayTools : Module() { stuckDetector += 1 blockQueue = LinkedList(blockQueue.shuffled()) if (stuckDetector > 20) { - doneQueue.clear() - blockQueue.clear() - updateTasks() + refreshData() } } else { - doneQueue.clear() - blockQueue.clear() - updateTasks() + refreshData() } } else { stuckDetector = 0 @@ -196,16 +189,20 @@ class HighwayTools : Module() { } private fun checkTasks(): Boolean { - for (bt in doneQueue) { - val block = mc.world.getBlockState(bt.getBlockPos()).block + for (blockTask in doneQueue) { + val block = mc.world.getBlockState(blockTask.blockPos).block var cont = false for (b in ignoreBlocks) { - if (b!!::class == block::class) { cont = true } + if (b!!::class == block::class) { + cont = true + } } - if (cont) { continue } - if (bt.getBlock()::class == material::class && block is BlockAir) { + if (cont) { + continue + } + if (blockTask.block::class == material::class && block is BlockAir) { return false - } else if (bt.getBlock()::class == BlockAir::class && block !is BlockAir) { + } else if (blockTask.block::class == BlockAir::class && block !is BlockAir) { return false } } @@ -215,115 +212,139 @@ class HighwayTools : Module() { private fun doTask(): Boolean { if (!isDone() && !pathing && !ModuleManager.getModuleT(LagNotifier::class.java)!!.paused && !ModuleManager.getModuleT(AutoObsidian::class.java)!!.active) { BaritoneAPI.getProvider().primaryBaritone.pathingControlManager.registerProcess(KamiMod.highwayToolsProcess) + if (waitTicks == 0) { val blockAction = blockQueue.peek() - if (blockAction.getTaskState() == TaskState.BREAK) { - val block = mc.world.getBlockState(blockAction.getBlockPos()).block - for (b in ignoreBlocks) { - if (block::class == b!!::class) { - blockAction.setTaskState(TaskState.DONE) - blockAction.setPriority(4) - doTask() - } - } - for (side in EnumFacing.values()) { - val neighbour = blockAction.getBlockPos().offset(side) - var found = false - if (mc.world.getBlockState(neighbour).block is BlockLiquid) { - for (bt in blockQueue) { - if (bt.getBlockPos() == neighbour) { - found = true - } + + when (blockAction.taskState) { + TaskState.BREAK -> { + val block = mc.world.getBlockState(blockAction.blockPos).block + + for (b in ignoreBlocks) { + if (block::class == b!!::class) { + blockAction.taskState = TaskState.DONE + blockAction.priority = 4 + doTask() } - if (!found) { - var insideBuild = false - for ((pos, _) in blockOffsets) { - if (neighbour == pos) { - insideBuild = true + } + + for (side in EnumFacing.values()) { + val neighbour = blockAction.blockPos.offset(side) + var found = false + + if (mc.world.getBlockState(neighbour).block is BlockLiquid) { + + for (bt in blockQueue) { + if (bt.blockPos == neighbour) { + found = true } } - if (insideBuild) { - addTask(neighbour, TaskState.PLACE, fillerMat, 1) - } else { - addTask(neighbour, TaskState.PLACE, material, 1) + + if (!found) { + var insideBuild = false + + for ((pos, _) in blockOffsets) { + if (neighbour == pos) { + insideBuild = true + } + } + + if (insideBuild) { + addTask(neighbour, TaskState.PLACE, fillerMat, 1) + } else { + addTask(neighbour, TaskState.PLACE, material, 1) + } } } } + + when (block) { + is BlockAir -> { + blockAction.taskState = TaskState.BROKE + doTask() + } + is BlockLiquid -> { + blockAction.taskState = TaskState.PLACE + blockAction.priority = 3 + doTask() + } + else -> { + mineBlock(blockAction.blockPos, true) + blockAction.taskState = TaskState.BREAKING + } + } } - when (block) { - is BlockAir -> { - blockAction.setTaskState(TaskState.BROKE) + TaskState.BREAKING -> { + mineBlock(blockAction.blockPos, false) + blockAction.taskState = TaskState.BROKE + } + TaskState.BROKE -> { + val block = mc.world.getBlockState(blockAction.blockPos).block + + if (block is BlockAir) { + totalBlocksDestroyed++ + waitTicks = tickDelayBreak.value + + if (blockAction.block::class == material::class) { + blockAction.taskState = TaskState.PLACE + blockAction.priority = 3 + } else { + blockAction.taskState = TaskState.DONE + blockAction.priority = 4 + } + doTask() + } else { + blockAction.taskState = TaskState.BREAK } - is BlockLiquid -> { - blockAction.setTaskState(TaskState.PLACE) - blockAction.setPriority(3) - doTask() + } + TaskState.PLACE -> { + val block = mc.world.getBlockState(blockAction.blockPos).block + + if (blockAction.block is BlockAir && block !is BlockLiquid) { + blockQueue.poll() + return true } - else -> { - mineBlock(blockAction.getBlockPos(), true) - blockAction.setTaskState(TaskState.BREAKING) + + if (block is BlockLiquid) { + blockAction.block = fillerMat } - } - } else if (blockAction.getTaskState() == TaskState.BREAKING) { - mineBlock(blockAction.getBlockPos(), false) - blockAction.setTaskState(TaskState.BROKE) - } else if (blockAction.getTaskState() == TaskState.BROKE) { - val block = mc.world.getBlockState(blockAction.getBlockPos()).block - if (block is BlockAir) { - totalBlocksDestroyed++ - waitTicks = tickDelayBreak.value - if (blockAction.getBlock()::class == material::class) { - blockAction.setTaskState(TaskState.PLACE) - blockAction.setPriority(3) + + if (placeBlock(blockAction.blockPos, blockAction.block)) { + blockAction.taskState = TaskState.PLACED + if (blocksPerTick.value > blocksPlaced + 1) { + blocksPlaced++ + doTask() + } else { + blocksPlaced = 0 + } + waitTicks = tickDelay.value + totalBlocksPlaced++ } else { - blockAction.setTaskState(TaskState.DONE) - blockAction.setPriority(4) + return false } - doTask() - } else { - blockAction.setTaskState(TaskState.BREAK) - } - } else if (blockAction.getTaskState() == TaskState.PLACE) { - val block = mc.world.getBlockState(blockAction.getBlockPos()).block - if (blockAction.getBlock() is BlockAir && block !is BlockLiquid) { - blockQueue.poll() - return true - } - if (block is BlockLiquid) { - blockAction.setBlock(fillerMat) } - if (placeBlock(blockAction.getBlockPos(), blockAction.getBlock())) { - blockAction.setTaskState(TaskState.PLACED) - if (blocksPerTick.value > blocksPlaced + 1) { - blocksPlaced++ - doTask() + TaskState.PLACED -> { + if (blockAction.block::class == material::class) { + val block = mc.world.getBlockState(blockAction.blockPos).block + + if (block !is BlockAir) { + blockAction.taskState = TaskState.DONE + blockAction.priority = 4 + } else { + blockAction.taskState = TaskState.PLACE + } } else { - blocksPlaced = 0 + blockAction.taskState = TaskState.BREAK + blockAction.priority = 2 } - waitTicks = tickDelay.value - totalBlocksPlaced++ - } else { - return false + doTask() } - } else if (blockAction.getTaskState() == TaskState.PLACED) { - if (blockAction.getBlock()::class == material::class) { - val block = mc.world.getBlockState(blockAction.getBlockPos()).block - if (block !is BlockAir) { - blockAction.setTaskState(TaskState.DONE) - blockAction.setPriority(4) - } else { - blockAction.setTaskState(TaskState.PLACE) - } - } else { - blockAction.setTaskState(TaskState.BREAK) - blockAction.setPriority(2) + TaskState.DONE -> { + blockQueue.poll() + doneQueue.add(blockAction) + doTask() } - doTask() - } else if (blockAction.getTaskState() == TaskState.DONE) { - blockQueue.poll() - doneQueue.add(blockAction) - doTask() } } else { waitTicks-- @@ -338,12 +359,19 @@ class HighwayTools : Module() { updateBlockArray() for ((a, b) in blockOffsets) { val block = mc.world.getBlockState(a).block - if (!b && block in ignoreBlocks) { addTask(a, TaskState.DONE, getBlockById(0), 4) } - else if (b && block is BlockAir) { addTask(a, TaskState.PLACE, material, 3) } - else if (b && block !is BlockAir && block::class != material::class) { addTask(a, TaskState.BREAK, material, 2) } - else if (!b && block !is BlockAir) { addTask(a, TaskState.BREAK, getBlockById(0), 2) } - else if (b && block::class == material::class) { addTask(a, TaskState.DONE, material, 4) } - else if (!b && block is BlockAir) { addTask(a, TaskState.DONE, getBlockById(0), 4) } + if (!b && block in ignoreBlocks) { + addTask(a, TaskState.DONE, getBlockById(0), 4) + } else if (b && block is BlockAir) { + addTask(a, TaskState.PLACE, material, 3) + } else if (b && block !is BlockAir && block::class != material::class) { + addTask(a, TaskState.BREAK, material, 2) + } else if (!b && block !is BlockAir) { + addTask(a, TaskState.BREAK, getBlockById(0), 2) + } else if (b && block::class == material::class) { + addTask(a, TaskState.DONE, material, 4) + } else if (!b && block is BlockAir) { + addTask(a, TaskState.DONE, getBlockById(0), 4) + } } } @@ -368,8 +396,7 @@ class HighwayTools : Module() { mc.player.swingArm(EnumHand.MAIN_HAND) } - private fun placeBlock(pos: BlockPos, mat: Block): Boolean - { + private fun placeBlock(pos: BlockPos, mat: Block): Boolean { // check if block is already placed val block = mc.world.getBlockState(pos).block if (block !is BlockAir && block !is BlockLiquid) { @@ -393,7 +420,7 @@ class HighwayTools : Module() { return false } - //Swap to material in Hotbar or get from inventory + // swap to material in Hotbar or get from inventory if (InventoryUtils.getSlotsHotbar(getIdFromBlock(mat)) == null && InventoryUtils.getSlotsNoHotbar(getIdFromBlock(mat)) != null) { //InventoryUtils.moveToHotbar(getIdFromBlock(mat), 130, (tickDelay.value * 16).toLong()) for (x in InventoryUtils.getSlotsNoHotbar(getIdFromBlock(mat))!!) { @@ -415,6 +442,7 @@ class HighwayTools : Module() { mc.player.connection.sendPacket(CPacketEntityAction(mc.player, CPacketEntityAction.Action.START_SNEAKING)) isSneaking = true } + if (rotate.value) { BlockUtils.faceVectorPacketInstant(hitVec) } @@ -453,23 +481,27 @@ class HighwayTools : Module() { fun getPlayerDirection(): Int { val yaw = (mc.player.rotationYaw % 360 + 360) % 360 - return if (yaw >= 158 && yaw < 203) { 0 } //NORTH - else if (yaw >= 203 && yaw < 258) { 1 } //NORTH-EAST - else if (yaw >= 258 && yaw < 293) { 2 } //EAST - else if (yaw >= 293 && yaw < 338) { 3 } //SOUTH-EAST - else if (yaw >= 338 || yaw < 23) { 4 } //SOUTH - else if (yaw >= 23 && yaw < 68) { 5 } //SOUTH-WEST - else if (yaw >= 68 && yaw < 113) { 6 } //WEST - else { 7 } //NORTH-WEST + return if (yaw >= 158 && yaw < 203) 0 //NORTH + else if (yaw >= 203 && yaw < 258) 1 //NORTH-EAST + else if (yaw >= 258 && yaw < 293) 2 //EAST + else if (yaw >= 293 && yaw < 338) 3 //SOUTH-EAST + else if (yaw >= 338 || yaw < 23) 4 //SOUTH + else if (yaw >= 23 && yaw < 68) 5 //SOUTH-WEST + else if (yaw >= 68 && yaw < 113) 6 //WEST + else 7 //NORTH-WEST } private fun updateRenderer(renderer: ESPRenderer): ESPRenderer { val side = GeometryMasks.Quad.ALL - for (bt in blockQueue) { - if (bt.getTaskState() != TaskState.DONE) { renderer.add(bt.getBlockPos(), bt.getTaskState().color, side) } + for (blockTask in blockQueue) { + if (blockTask.taskState != TaskState.DONE) { + renderer.add(blockTask.blockPos, blockTask.taskState.color, side) + } } - for (bt in doneQueue) { - if (bt.getBlock()::class != BlockAir::class) { renderer.add(bt.getBlockPos(), bt.getTaskState().color, side) } + for (blockTask in doneQueue) { + if (blockTask.block::class != BlockAir::class) { + renderer.add(blockTask.blockPos, blockTask.taskState.color, side) + } } return renderer } @@ -484,17 +516,16 @@ class HighwayTools : Module() { } private fun printDebug() { - MessageSendHelper.sendChatMessage("") - MessageSendHelper.sendChatMessage("") - MessageSendHelper.sendChatMessage("-------------------- QUEUE -------------------") - for (bt in blockQueue) { - MessageSendHelper.sendChatMessage(bt.getBlock().localizedName + "@(" + bt.getBlockPos().asString() + ") State: " + bt.getTaskState().toString() + " Prio: " + bt.getPriority()) + var message = "\n\n" + message += "-------------------- QUEUE -------------------" + for (blockTask in blockQueue) { + message += "\n" + blockTask.block.localizedName + "@(" + blockTask.blockPos.asString() + ") State: " + blockTask.taskState.toString() + " Prio: " + blockTask.priority } - MessageSendHelper.sendChatMessage("") - MessageSendHelper.sendChatMessage("-------------------- DONE --------------------") - for (bt in doneQueue) { - MessageSendHelper.sendChatMessage(bt.getBlock().localizedName + "@(" + bt.getBlockPos().asString() + ") State: " + bt.getTaskState().toString() + " Prio: " + bt.getPriority()) + message += "\n-------------------- DONE --------------------" + for (blockTask in doneQueue) { + message += "\n" + blockTask.block.localizedName + "@(" + blockTask.blockPos.asString() + ") State: " + blockTask.taskState.toString() + " Prio: " + blockTask.priority } + MessageSendHelper.sendChatMessage(message) } fun printSettings() { @@ -509,7 +540,7 @@ class HighwayTools : Module() { } private fun printEnable() { - if (stats.value) { + if (info.value) { if (buildDirectionSaved == 1 || buildDirectionSaved == 3 || buildDirectionSaved == 5 || buildDirectionSaved == 5 || buildDirectionSaved == 7) { MessageSendHelper.sendChatMessage("$chatName Module started." + "\n §9> §7Direction: §a" + directions[buildDirectionSaved] + "§r" + @@ -527,7 +558,7 @@ class HighwayTools : Module() { } private fun printDisable() { - if (stats.value) { + if (info.value) { MessageSendHelper.sendChatMessage("$chatName Module stopped." + "\n §9> §7Placed blocks: §a" + totalBlocksPlaced + "§r" + "\n §9> §7Destroyed blocks: §a" + totalBlocksDestroyed + "§r" + @@ -539,28 +570,32 @@ class HighwayTools : Module() { fun getNextBlock(): BlockPos { return when (buildDirectionSaved) { - 0 -> { currentBlockPos.north() } - 1 -> { currentBlockPos.north().east() } - 2 -> { currentBlockPos.east() } - 3 -> { currentBlockPos.south().east() } - 4 -> { currentBlockPos.south() } - 5 -> { currentBlockPos.south().west() } - 6 -> { currentBlockPos.west() } - else -> { currentBlockPos.north().west() } + 0 -> currentBlockPos.north() + 1 -> currentBlockPos.north().east() + 2 -> currentBlockPos.east() + 3 -> currentBlockPos.south().east() + 4 -> currentBlockPos.south() + 5 -> currentBlockPos.south().west() + 6 -> currentBlockPos.west() + else -> { + currentBlockPos.north().west() + } } } private fun lookInWalkDirection() { // set head rotation to get max walking speed when (buildDirectionSaved) { - 0 -> { mc.player.rotationYaw = -180F } - 1 -> { mc.player.rotationYaw = -135F } - 2 -> { mc.player.rotationYaw = -90F } - 3 -> { mc.player.rotationYaw = -45F } - 4 -> { mc.player.rotationYaw = 0F } - 5 -> { mc.player.rotationYaw = 45F } - 6 -> { mc.player.rotationYaw = 90F } - else -> { mc.player.rotationYaw = 135F } + 0 -> mc.player.rotationYaw = -180F + 1 -> mc.player.rotationYaw = -135F + 2 -> mc.player.rotationYaw = -90F + 3 -> mc.player.rotationYaw = -45F + 4 -> mc.player.rotationYaw = 0F + 5 -> mc.player.rotationYaw = 45F + 6 -> mc.player.rotationYaw = 90F + else -> { + mc.player.rotationYaw = 135F + } } mc.player.rotationPitch = 0F } @@ -583,7 +618,7 @@ class HighwayTools : Module() { } private fun isDiagonal(): Boolean { - return when(buildDirectionSaved) { + return when (buildDirectionSaved) { 1 -> true 3 -> true 5 -> true @@ -592,11 +627,17 @@ class HighwayTools : Module() { } } + private fun refreshData() { + doneQueue.clear() + blockQueue.clear() + updateTasks() + } + private fun updateBlockArray() { blockOffsets.clear() val b = currentBlockPos - when(mode.value) { + when (mode.value) { Mode.HIGHWAY -> { var cursor = b cursor = cursor.down() @@ -604,17 +645,24 @@ class HighwayTools : Module() { cursor = relativeDirection(cursor, 1, 0) blockOffsets.add(Pair(cursor, true)) cursor = relativeDirection(cursor, 1, 0) - var flip = false + for (x in range(1, buildWidth.value + 1)) { - val alterDirection = if (flip) { -1 } else { 1 } + val alterDirection = if (flip) { + -1 + } else { + 1 + } + if (isDiagonal()) { if (x != 1) { blockOffsets.add(Pair(relativeDirection(relativeDirection(cursor, x / 2 - 1, 1 * alterDirection), x / 2, 3 * alterDirection), true)) } + blockOffsets.add(Pair(relativeDirection(cursor, x / 2, 2 * alterDirection), true)) if (rims.value && x == buildWidth.value) { var c = cursor + for (y in range(1, rimHeight.value + 1)) { c = c.up() if (buildWidth.value % 2 != 0) { @@ -626,10 +674,13 @@ class HighwayTools : Module() { } } } + if (clearSpace.value) { var c = cursor + for (y in range(1, clearHeight.value)) { c = c.up() + if (rims.value) { if (!((x == buildWidth.value || x == buildWidth.value - 1) && y <= rimHeight.value)) { blockOffsets.add(Pair(relativeDirection(relativeDirection(c, x / 2 - 1, 1 * alterDirection), x / 2, 3 * alterDirection), false)) @@ -653,10 +704,12 @@ class HighwayTools : Module() { blockOffsets.add(Pair(relativeDirection(cursor, x / 2, 2 * alterDirection), true)) } } + if (rims.value && x == buildWidth.value) { var c = cursor for (y in range(1, rimHeight.value + 1)) { c = c.up() + if (buildWidth.value % 2 != 0) { blockOffsets.add(Pair(relativeDirection(c, x / 2, 2 * alterDirection), true)) blockOffsets.add(Pair(relativeDirection(c, x / 2, 2 * alterDirection * (-1)), true)) @@ -666,6 +719,7 @@ class HighwayTools : Module() { } } } + if (clearSpace.value) { var c = cursor for (y in range(1, clearHeight.value)) { @@ -684,16 +738,12 @@ class HighwayTools : Module() { } } Mode.FLAT -> { - blockOffsets.add(Pair((b.down().north()), true)) - blockOffsets.add(Pair((b.down().east()), true)) - blockOffsets.add(Pair((b.down().south()), true)) - blockOffsets.add(Pair((b.down().west()), true)) - blockOffsets.add(Pair((b.down().north().east()), true)) - blockOffsets.add(Pair((b.down().north().west()), true)) - blockOffsets.add(Pair((b.down().south().east()), true)) - blockOffsets.add(Pair((b.down().south().west()), true)) + for (bp in VectorUtils.getBlockPositionsInArea(b.down().north(buildWidth.value).west(buildWidth.value), b.down().south(buildWidth.value).east(buildWidth.value))) { + blockOffsets.add(Pair(bp, true)) + } } null -> { + MessageSendHelper.sendChatMessage("Module logic is a lie.") disable() } } @@ -707,22 +757,14 @@ class HighwayTools : Module() { MAIN, BUILD } - class BlockTask(private val bp: BlockPos, private var tt: TaskState, private var bb: Block, private var prio: Int) { - fun getBlockPos(): BlockPos { return bp } - fun getTaskState(): TaskState { return tt } - fun setTaskState(tts: TaskState) { tt = tts } - fun getBlock(): Block { return bb } - fun setBlock(b: Block) { bb = b } - fun getPriority(): Int { return prio } - fun setPriority(p: Int) { prio = p } - } + data class BlockTask(val blockPos: BlockPos, var taskState: TaskState, var block: Block, var priority: Int) - private class TaskComparator: Comparator{ + private class TaskComparator : Comparator { override fun compare(o1: BlockTask?, o2: BlockTask?): Int { if (o1 == null || o2 == null) { return 0 } - return o1.getPriority().compareTo(o2.getPriority()) + return o1.priority.compareTo(o2.priority) } } diff --git a/src/main/java/me/zeroeightsix/kami/process/HighwayToolsProcess.kt b/src/main/java/me/zeroeightsix/kami/process/HighwayToolsProcess.kt index 4d8f5cb63e..86819570ce 100644 --- a/src/main/java/me/zeroeightsix/kami/process/HighwayToolsProcess.kt +++ b/src/main/java/me/zeroeightsix/kami/process/HighwayToolsProcess.kt @@ -31,7 +31,7 @@ class HighwayToolsProcess : IBaritoneProcess { override fun displayName0(): String { val highwayTools = ModuleManager.getModuleT(HighwayTools::class.java)!! val processName = if (highwayTools.blockQueue.size > 0 && !highwayTools.pathing) { - "Block: " + highwayTools.blockQueue.peek().getBlock().localizedName + " @ Position: (" + highwayTools.blockQueue.peek().getBlockPos().asString() + ") Prio: " + highwayTools.blockQueue.peek().getPriority() + " State: " + highwayTools.blockQueue.peek().getTaskState().toString() + "Block: " + highwayTools.blockQueue.peek().block.localizedName + " @ Position: (" + highwayTools.blockQueue.peek().blockPos.asString() + ") Prio: " + highwayTools.blockQueue.peek().priority + " State: " + highwayTools.blockQueue.peek().taskState.toString() } else { "Moving to Position: (${highwayTools.getNextBlock().asString()})" } From ac588ddf1b8fb0bd2c855a6ffb45e7bf12115416 Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 15 Sep 2020 04:00:35 +0200 Subject: [PATCH 023/390] Clean up, clean up, clean up - Broke baritone walking --- .../command/commands/HighwayToolsCommand.kt | 38 +- .../zeroeightsix/kami/gui/kami/KamiGUI.java | 2 +- .../kami/module/modules/misc/HighwayTools.kt | 383 ++++++++++-------- .../kami/process/HighwayToolsProcess.kt | 7 +- .../zeroeightsix/kami/util/math/MathUtils.kt | 64 ++- 5 files changed, 266 insertions(+), 228 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/command/commands/HighwayToolsCommand.kt b/src/main/java/me/zeroeightsix/kami/command/commands/HighwayToolsCommand.kt index ca0652134e..a798b950d0 100644 --- a/src/main/java/me/zeroeightsix/kami/command/commands/HighwayToolsCommand.kt +++ b/src/main/java/me/zeroeightsix/kami/command/commands/HighwayToolsCommand.kt @@ -21,15 +21,15 @@ class HighwayToolsCommand : Command("highwaytools", ChunkBuilder() val subCommand = getSubCommand(args) val ht = ModuleManager.getModuleT(HighwayTools::class.java) when (subCommand) { - SubCommands.SHOWSETTINGS -> { + SubCommands.SETTINGS -> { ht!!.printSettings() } SubCommands.MATERIAL -> { try { - val newmat = Block.getBlockFromName(args[1].toString())!! - ht!!.material = newmat - MessageSendHelper.sendChatMessage("Set your building material to &7${newmat.localizedName}&r.") + val block = Block.getBlockFromName(args[1].toString())!! + ht!!.material = block + MessageSendHelper.sendChatMessage("Set your building material to &7${block.localizedName}&r.") } catch (e: Exception) { MessageSendHelper.sendChatMessage("&7${args[1]}&r is not a valid block.") } @@ -37,9 +37,9 @@ class HighwayToolsCommand : Command("highwaytools", ChunkBuilder() SubCommands.FILLER -> { try { - val newmat = Block.getBlockFromName(args[1].toString())!! - ht!!.fillerMat = newmat - MessageSendHelper.sendChatMessage("Set your filling material to &7${newmat.localizedName}&r.") + val block = Block.getBlockFromName(args[1].toString())!! + ht!!.fillerMat = block + MessageSendHelper.sendChatMessage("Set your filling material to &7${block.localizedName}&r.") } catch (e: Exception) { MessageSendHelper.sendChatMessage("&7${args[1]}&r is not a valid block.") } @@ -47,13 +47,13 @@ class HighwayToolsCommand : Command("highwaytools", ChunkBuilder() SubCommands.IGNORE_ADD -> { try { - val newmat = Block.getBlockFromName(args[2].toString())!! - if (newmat !in ht!!.ignoreBlocks) { - ht.ignoreBlocks.add(newmat) + val block = Block.getBlockFromName(args[2].toString())!! + if (block !in ht!!.ignoreBlocks) { + ht.ignoreBlocks.add(block) ht.printSettings() - MessageSendHelper.sendChatMessage("Added &7${newmat.localizedName}&r to ignore list.") + MessageSendHelper.sendChatMessage("Added &7${block.localizedName}&r to ignore list.") } else { - MessageSendHelper.sendChatMessage("&7${newmat.localizedName}&r is already ignored.") + MessageSendHelper.sendChatMessage("&7${block.localizedName}&r is already ignored.") } } catch (e: Exception) { MessageSendHelper.sendChatMessage("&7${args[1]}&r is not a valid block.") @@ -62,13 +62,13 @@ class HighwayToolsCommand : Command("highwaytools", ChunkBuilder() SubCommands.IGNORE_DEL -> { try { - val newmat = Block.getBlockFromName(args[2].toString())!! - if (newmat !in ht!!.ignoreBlocks) { - ht.ignoreBlocks.remove(newmat) + val block = Block.getBlockFromName(args[2].toString())!! + if (block !in ht!!.ignoreBlocks) { + ht.ignoreBlocks.remove(block) ht.printSettings() - MessageSendHelper.sendChatMessage("Removed &7${newmat.localizedName}&r from ignore list.") + MessageSendHelper.sendChatMessage("Removed &7${block.localizedName}&r from ignore list.") } else { - MessageSendHelper.sendChatMessage("&7${newmat.localizedName}&r is not yet ignored.") + MessageSendHelper.sendChatMessage("&7${block.localizedName}&r is not yet ignored.") } } catch (e: Exception) { MessageSendHelper.sendChatMessage("&7${args[1]}&r is not a valid block.") @@ -84,7 +84,7 @@ class HighwayToolsCommand : Command("highwaytools", ChunkBuilder() private fun getSubCommand(args: Array): SubCommands { return when { - args[0].isNullOrBlank() -> SubCommands.SHOWSETTINGS + args[0].isNullOrBlank() -> SubCommands.SETTINGS args[1].isNullOrBlank() -> SubCommands.NULL @@ -103,7 +103,7 @@ class HighwayToolsCommand : Command("highwaytools", ChunkBuilder() } private enum class SubCommands { - MATERIAL, FILLER, IGNORE_ADD, IGNORE_DEL, SHOWSETTINGS, NULL + MATERIAL, FILLER, IGNORE_ADD, IGNORE_DEL, SETTINGS, NULL } init { diff --git a/src/main/java/me/zeroeightsix/kami/gui/kami/KamiGUI.java b/src/main/java/me/zeroeightsix/kami/gui/kami/KamiGUI.java index b073b3e170..020ca60797 100644 --- a/src/main/java/me/zeroeightsix/kami/gui/kami/KamiGUI.java +++ b/src/main/java/me/zeroeightsix/kami/gui/kami/KamiGUI.java @@ -483,7 +483,7 @@ public void onTick() { ); coordsLabel.setText(""); coordsLabel.addLine(ow); - coordsLabel.addLine(MathUtils.getPlayerCardinal(mc).cardinalName + colouredSeparator + nether); + coordsLabel.addLine(MathUtils.getPlayerCardinal(mc).getDirectionName() + colouredSeparator + nether); } }); frame.addChild(coordsLabel); diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index ff5ddf1a71..e7d5ae3e22 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -1,12 +1,12 @@ package me.zeroeightsix.kami.module.modules.misc import baritone.api.BaritoneAPI -import me.zeroeightsix.kami.KamiMod import me.zeroeightsix.kami.event.events.RenderEvent import me.zeroeightsix.kami.module.Module import me.zeroeightsix.kami.module.ModuleManager import me.zeroeightsix.kami.module.modules.player.LagNotifier import me.zeroeightsix.kami.module.modules.player.NoBreakAnimation +import me.zeroeightsix.kami.process.HighwayToolsProcess import me.zeroeightsix.kami.setting.Settings import me.zeroeightsix.kami.util.BlockUtils import me.zeroeightsix.kami.util.InventoryUtils @@ -14,28 +14,33 @@ import me.zeroeightsix.kami.util.color.ColorHolder import me.zeroeightsix.kami.util.graphics.ESPRenderer import me.zeroeightsix.kami.util.graphics.GeometryMasks import me.zeroeightsix.kami.util.math.CoordinateConverter.asString +import me.zeroeightsix.kami.util.math.MathUtils.Cardinal +import me.zeroeightsix.kami.util.math.MathUtils.getPlayerCardinal +import me.zeroeightsix.kami.util.math.MathUtils.mcPlayerPosFloored import me.zeroeightsix.kami.util.math.RotationUtils import me.zeroeightsix.kami.util.math.VectorUtils import me.zeroeightsix.kami.util.text.MessageSendHelper -import net.minecraft.block.* +import net.minecraft.block.Block import net.minecraft.block.Block.getBlockById import net.minecraft.block.Block.getIdFromBlock +import net.minecraft.block.BlockAir +import net.minecraft.block.BlockLiquid +import net.minecraft.block.state.IBlockState import net.minecraft.client.audio.PositionedSoundRecord -import net.minecraft.entity.item.EntityItem -import net.minecraft.entity.item.EntityXPOrb import net.minecraft.init.Blocks import net.minecraft.init.SoundEvents -import net.minecraft.network.play.client.CPacketEntityAction -import net.minecraft.network.play.client.CPacketPlayerDigging +import net.minecraft.item.ItemBlock +import net.minecraft.item.ItemStack +import net.minecraft.network.play.client.* 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.MathHelper import net.minecraft.util.math.Vec3d import java.util.* import java.util.stream.IntStream.range -import kotlin.math.floor -import kotlin.math.roundToInt +import kotlin.math.atan2 +import kotlin.math.sqrt /** * @author Avanatiker @@ -44,12 +49,13 @@ import kotlin.math.roundToInt @Module.Info( name = "HighwayTools", - description = "Even Better High-ways for the greater good.", + description = "Be the grief a step a head.", category = Module.Category.MISC ) class HighwayTools : Module() { private val mode = register(Settings.e("Mode", Mode.HIGHWAY)) + private val debugMessages = register(Settings.e("DebugMessages", DebugMessages.IMPORTANT)) private val page = register(Settings.e("Page", Page.MAIN)) // settings for module @@ -58,8 +64,11 @@ class HighwayTools : Module() { private val tickDelay = register(Settings.integerBuilder("TickDelayPlace").withMinimum(0).withValue(0).withMaximum(10).withVisibility { page.value == Page.MAIN }.build()) private val tickDelayBreak = register(Settings.integerBuilder("TickDelayBreak").withMinimum(0).withValue(0).withMaximum(10).withVisibility { page.value == Page.MAIN }.build()) private val noViewReset = register(Settings.booleanBuilder("NoViewReset").withValue(false).withVisibility { page.value == Page.MAIN }.build()) - private val rotate = register(Settings.booleanBuilder("Rotate").withValue(true).withVisibility { page.value == Page.MAIN }.build()) + private val spoofRotations = register(Settings.booleanBuilder("SpoofRotations").withValue(true).withVisibility { page.value == Page.MAIN }.build()) + private val spoofHotbar = register(Settings.booleanBuilder("SpoofRotations").withValue(true).withVisibility { page.value == Page.MAIN }.build()) private val info = register(Settings.booleanBuilder("ShowInfo").withValue(true).withVisibility { page.value == Page.MAIN }.build()) + private val printDebug = register(Settings.booleanBuilder("ShowDebug").withValue(false).withVisibility { page.value == Page.MAIN }.build()) + private val placeAnimation = register(Settings.booleanBuilder("PlaceAnimation").withValue(false).withVisibility { page.value == Page.MAIN }.build()) private val filled = register(Settings.booleanBuilder("Filled").withValue(true).withVisibility { page.value == Page.MAIN }.build()) private val outline = register(Settings.booleanBuilder("Outline").withValue(true).withVisibility { page.value == Page.MAIN }.build()) private val aFilled = register(Settings.integerBuilder("FilledAlpha").withMinimum(0).withValue(31).withMaximum(255).withVisibility { filled.value && page.value == Page.MAIN }.build()) @@ -81,16 +90,13 @@ class HighwayTools : Module() { private var isSneaking = false var pathing = true private var stuckDetector = 0 - private var buildDirectionSaved = 0 - private var buildDirectionCoordinate = 0 - private val directions = listOf("North", "North-East", "East", "South-East", "South", "South-West", "West", "North-West") + private lateinit var buildDirectionSaved: Cardinal // stats private var totalBlocksPlaced = 0 private var totalBlocksDestroyed = 0 private var totalBlocksDistance = 0 - //val blockQueue = PriorityQueue(TaskComparator()) var blockQueue: Queue = LinkedList() private val doneQueue: Queue = LinkedList() private var blockOffsets = mutableListOf>() @@ -99,6 +105,10 @@ class HighwayTools : Module() { private lateinit var currentBlockPos: BlockPos private lateinit var startingBlockPos: BlockPos + private enum class DebugMessages { + NONE, IMPORTANT, ALL + } + fun isDone(): Boolean { return blockQueue.size == 0 } @@ -108,20 +118,13 @@ class HighwayTools : Module() { disable() return } - buildDirectionSaved = getPlayerDirection() - startingBlockPos = BlockPos(floor(mc.player.posX).toInt(), floor(mc.player.posY).toInt(), floor(mc.player.posZ).toInt()) + startingBlockPos = mcPlayerPosFloored(mc) currentBlockPos = startingBlockPos playerHotbarSlot = mc.player.inventory.currentItem lastHotbarSlot = -1 + buildDirectionSaved = getPlayerCardinal(mc) playerHotbarSlot = mc.player.inventory.currentItem - buildDirectionCoordinate = if (buildDirectionSaved == 0 || buildDirectionSaved == 4) { - startingBlockPos.getX() - } else if (buildDirectionSaved == 2 || buildDirectionSaved == 6) { - startingBlockPos.getZ() - } else { - 0 - } refreshData() printEnable() @@ -141,6 +144,7 @@ class HighwayTools : Module() { playerHotbarSlot = -1 lastHotbarSlot = -1 + BaritoneAPI.getProvider().primaryBaritone.pathingBehavior.cancelEverything() printDisable() totalBlocksPlaced = 0 @@ -152,9 +156,7 @@ class HighwayTools : Module() { if (mc.playerController == null) return if (!isDone()) { - if (!BaritoneAPI.getProvider().primaryBaritone.pathingBehavior.isPathing) { - pathing = false - } + if (!BaritoneAPI.getProvider().primaryBaritone.pathingBehavior.isPathing) pathing = false if (!doTask()) { if (!pathing && !ModuleManager.getModuleT(LagNotifier::class.java)!!.paused) { stuckDetector += 1 @@ -181,11 +183,13 @@ class HighwayTools : Module() { updateTasks() } } - //printDebug() + if (printDebug.value) { + printDebug() + } } - private fun addTask(blockPos: BlockPos, taskState: TaskState, material: Block, prio: Int) { - blockQueue.add(BlockTask(blockPos, taskState, material, prio)) + private fun addTask(blockPos: BlockPos, taskState: TaskState, material: Block, priority: Int) { + blockQueue.add(BlockTask(blockPos, taskState, material, priority)) } private fun checkTasks(): Boolean { @@ -211,7 +215,7 @@ class HighwayTools : Module() { private fun doTask(): Boolean { if (!isDone() && !pathing && !ModuleManager.getModuleT(LagNotifier::class.java)!!.paused && !ModuleManager.getModuleT(AutoObsidian::class.java)!!.active) { - BaritoneAPI.getProvider().primaryBaritone.pathingControlManager.registerProcess(KamiMod.highwayToolsProcess) + BaritoneAPI.getProvider().primaryBaritone.pathingControlManager.registerProcess(HighwayToolsProcess) if (waitTicks == 0) { val blockAction = blockQueue.peek() @@ -318,6 +322,7 @@ class HighwayTools : Module() { } else { blocksPlaced = 0 } + waitTicks = tickDelay.value totalBlocksPlaced++ } else { @@ -359,18 +364,13 @@ class HighwayTools : Module() { updateBlockArray() for ((a, b) in blockOffsets) { val block = mc.world.getBlockState(a).block - if (!b && block in ignoreBlocks) { - addTask(a, TaskState.DONE, getBlockById(0), 4) - } else if (b && block is BlockAir) { - addTask(a, TaskState.PLACE, material, 3) - } else if (b && block !is BlockAir && block::class != material::class) { - addTask(a, TaskState.BREAK, material, 2) - } else if (!b && block !is BlockAir) { - addTask(a, TaskState.BREAK, getBlockById(0), 2) - } else if (b && block::class == material::class) { - addTask(a, TaskState.DONE, material, 4) - } else if (!b && block is BlockAir) { - addTask(a, TaskState.DONE, getBlockById(0), 4) + when { + (!b && block in ignoreBlocks) -> addTask(a, TaskState.DONE, getBlockById(0), 4) + (b && block is BlockAir) -> addTask(a, TaskState.PLACE, material, 3) + (b && block !is BlockAir && block::class != material::class) -> addTask(a, TaskState.BREAK, material, 2) + (!b && block !is BlockAir) -> addTask(a, TaskState.BREAK, getBlockById(0), 2) + (b && block::class == material::class) -> addTask(a, TaskState.DONE, material, 4) + (!b && block is BlockAir) -> addTask(a, TaskState.DONE, getBlockById(0), 4) } } } @@ -396,80 +396,157 @@ class HighwayTools : Module() { mc.player.swingArm(EnumHand.MAIN_HAND) } - private fun placeBlock(pos: BlockPos, mat: Block): Boolean { - // check if block is already placed - val block = mc.world.getBlockState(pos).block - if (block !is BlockAir && block !is BlockLiquid) { - return false + private fun findMaterialInHotbar(material: Block): Int { + var slot = -1 + for (i in 0..8) { + val stack = mc.player.inventory.getStackInSlot(i) + if (stack != ItemStack.EMPTY && stack.getItem() is ItemBlock) { + val block = (stack.getItem() as ItemBlock).block + if (block::class == material::class) { + slot = i + break + } + } } + return slot + } - // check if entity blocks placing - for (entity in mc.world.getEntitiesWithinAABBExcludingEntity(null, AxisAlignedBB(pos))) { - if (entity !is EntityItem && entity !is EntityXPOrb) { + private fun placeBlock(blockPos: BlockPos, material: Block): Boolean { + if (!mc.world.getBlockState(blockPos).material.isReplaceable) { + if (debugMessages.value == DebugMessages.ALL) { + MessageSendHelper.sendChatMessage("$chatName Block is already placed, skipping") return false } + } else if (!BlockUtils.checkForNeighbours(blockPos) && debugMessages.value == DebugMessages.ALL) { + MessageSendHelper.sendChatMessage("$chatName No adjacent blocks found") + return false + } else { + if (placeAnimation.value) mc.player.connection.sendPacket(CPacketAnimation(mc.player.activeHand)) + if (!placeBlockExecute(blockPos, material)) return false } - val side = getPlaceableSide(pos) ?: return false - // check if we have a block adjacent to blockpos to click at - val neighbour = pos.offset(side) - val opposite = side.opposite - - // check if neighbor can be right clicked - if (!BlockUtils.canBeClicked(neighbour)) { - return false + val noBreakAnimation = ModuleManager.getModuleT(NoBreakAnimation::class.java)!! + if (noBreakAnimation.isEnabled) { + noBreakAnimation.resetMining() } + return true + } + + private fun placeBlockExecute(pos: BlockPos, material: Block): Boolean { + val eyesPos = Vec3d(mc.player.posX, mc.player.posY + mc.player.getEyeHeight().toDouble(), mc.player.posZ) + val var3 = EnumFacing.values() + for (side in var3) { + val neighbor = pos.offset(side) + val side2 = side.opposite + + if (!canBeClicked(neighbor)) { + if (debugMessages.value == DebugMessages.ALL) { + MessageSendHelper.sendChatMessage("$chatName No neighbor to click at!") + return false + } + } else { + val hitVec = Vec3d(neighbor).add(0.5, 0.5, 0.5).add(Vec3d(side2.directionVec).scale(0.5)) + + if (eyesPos.squareDistanceTo(hitVec) <= 18.0625) { + if (spoofRotations.value) { + faceVectorPacketInstant(hitVec) + } + + var needSneak = false + val blockBelow = mc.world.getBlockState(neighbor).block + + if (BlockUtils.blackList.contains(blockBelow) || BlockUtils.shulkerList.contains(blockBelow)) { + if (debugMessages.value == DebugMessages.IMPORTANT) { + MessageSendHelper.sendChatMessage("$chatName Sneak enabled!") + } + needSneak = true + } + + if (needSneak) { + mc.player.connection.sendPacket(CPacketEntityAction(mc.player, CPacketEntityAction.Action.START_SNEAKING)) + } + + // swap to material in Hotbar or get from inventory + if (InventoryUtils.getSlotsHotbar(getIdFromBlock(material)) == null && InventoryUtils.getSlotsNoHotbar(getIdFromBlock(material)) != null) { + //InventoryUtils.moveToHotbar(getIdFromBlock(material), 130, (tickDelay.value * 16).toLong()) + for (x in InventoryUtils.getSlotsNoHotbar(getIdFromBlock(material))!!) { + InventoryUtils.quickMoveSlot(x, (tickDelay.value * 16).toLong()) + } + //InventoryUtils.quickMoveSlot(1, (tickDelay.value * 16).toLong()) + } else if (InventoryUtils.getSlots(0, 35, getIdFromBlock(material)) == null) { + MessageSendHelper.sendChatMessage("$chatName No ${material.localizedName} was found in inventory") + mc.getSoundHandler().playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) + disable() + return false + } + InventoryUtils.swapSlotToItem(getIdFromBlock(material)) + val materialSlot = findMaterialInHotbar(material) + + if (lastHotbarSlot != materialSlot) { + if (debugMessages.value == DebugMessages.ALL) { + MessageSendHelper.sendChatMessage("$chatName Setting Slot to obsidian at = $materialSlot") + } + + if (spoofHotbar.value) { + mc.player.connection.sendPacket(CPacketHeldItemChange(materialSlot)) + } else { + mc.player.inventory.currentItem = materialSlot + } + lastHotbarSlot = materialSlot + } + + mc.playerController.processRightClickBlock(mc.player, mc.world, neighbor, side2, hitVec, EnumHand.MAIN_HAND) + mc.player.connection.sendPacket(CPacketAnimation(EnumHand.MAIN_HAND)) - // swap to material in Hotbar or get from inventory - if (InventoryUtils.getSlotsHotbar(getIdFromBlock(mat)) == null && InventoryUtils.getSlotsNoHotbar(getIdFromBlock(mat)) != null) { - //InventoryUtils.moveToHotbar(getIdFromBlock(mat), 130, (tickDelay.value * 16).toLong()) - for (x in InventoryUtils.getSlotsNoHotbar(getIdFromBlock(mat))!!) { - InventoryUtils.quickMoveSlot(x, (tickDelay.value * 16).toLong()) + if (needSneak) { + if (debugMessages.value == DebugMessages.IMPORTANT) { + MessageSendHelper.sendChatMessage("$chatName Sneak disabled!") + } + mc.player.connection.sendPacket(CPacketEntityAction(mc.player, CPacketEntityAction.Action.STOP_SNEAKING)) + } + } + + if (debugMessages.value == DebugMessages.ALL) { + MessageSendHelper.sendChatMessage("$chatName Distance > 4.25 blocks!") + } } - //InventoryUtils.quickMoveSlot(1, (tickDelay.value * 16).toLong()) - } else if (InventoryUtils.getSlots(0, 35, getIdFromBlock(mat)) == null) { - MessageSendHelper.sendChatMessage("$chatName No ${mat.localizedName} was found in inventory") - mc.getSoundHandler().playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) - disable() - return false } - InventoryUtils.swapSlotToItem(getIdFromBlock(mat)) - - val hitVec = Vec3d(neighbour).add(0.5, 0.5, 0.5).add(Vec3d(opposite.directionVec).scale(0.5)) - val neighbourBlock = mc.world.getBlockState(neighbour).block + return true + } - if (!isSneaking && BlockUtils.blackList.contains(neighbourBlock) || BlockUtils.shulkerList.contains(neighbourBlock)) { - mc.player.connection.sendPacket(CPacketEntityAction(mc.player, CPacketEntityAction.Action.START_SNEAKING)) - isSneaking = true + companion object { + private fun canBeClicked(pos: BlockPos): Boolean { + return getBlock(pos).canCollideCheck(getState(pos), false) } - if (rotate.value) { - BlockUtils.faceVectorPacketInstant(hitVec) + fun getBlock(pos: BlockPos): Block { + return getState(pos).block } - mc.playerController.processRightClickBlock(mc.player, mc.world, neighbour, opposite, hitVec, EnumHand.MAIN_HAND) - mc.player.swingArm(EnumHand.MAIN_HAND) - mc.rightClickDelayTimer = 4 + private fun getState(pos: BlockPos): IBlockState { + return mc.world.getBlockState(pos) + } - val noBreakAnimation = ModuleManager.getModuleT(NoBreakAnimation::class.java)!! - if (noBreakAnimation.isEnabled) { - noBreakAnimation.resetMining() + private fun faceVectorPacketInstant(vec: Vec3d) { + val rotations = getLegitRotations(vec) + mc.player.connection.sendPacket(CPacketPlayer.Rotation(rotations[0], rotations[1], mc.player.onGround)) } - return true - } - private fun getPlaceableSide(pos: BlockPos): EnumFacing? { - for (side in EnumFacing.values()) { - val neighbour = pos.offset(side) - if (!mc.world.getBlockState(neighbour).block.canCollideCheck(mc.world.getBlockState(neighbour), false)) { - continue - } - val blockState = mc.world.getBlockState(neighbour) - if (!blockState.material.isReplaceable) { - return side - } + private fun getLegitRotations(vec: Vec3d): FloatArray { + val eyesPos = eyesPos + val diffX = vec.x - eyesPos.x + val diffY = vec.y - eyesPos.y + val diffZ = vec.z - eyesPos.z + + val diffXZ = sqrt(diffX * diffX + diffZ * diffZ) + val yaw = Math.toDegrees(atan2(diffZ, diffX)).toFloat() - 90.0f + val pitch = (-Math.toDegrees(atan2(diffY, diffXZ))).toFloat() + + return floatArrayOf(mc.player.rotationYaw + MathHelper.wrapDegrees(yaw - mc.player.rotationYaw), mc.player.rotationPitch + MathHelper.wrapDegrees(pitch - mc.player.rotationPitch)) } - return null + + private val eyesPos: Vec3d + get() = Vec3d(mc.player.posX, mc.player.posY + mc.player.getEyeHeight().toDouble(), mc.player.posZ) } private fun lookAtBlock(pos: BlockPos) { @@ -479,18 +556,6 @@ class HighwayTools : Module() { mc.player.rotationPitch = lookAt.y.toFloat() } - fun getPlayerDirection(): Int { - val yaw = (mc.player.rotationYaw % 360 + 360) % 360 - return if (yaw >= 158 && yaw < 203) 0 //NORTH - else if (yaw >= 203 && yaw < 258) 1 //NORTH-EAST - else if (yaw >= 258 && yaw < 293) 2 //EAST - else if (yaw >= 293 && yaw < 338) 3 //SOUTH-EAST - else if (yaw >= 338 || yaw < 23) 4 //SOUTH - else if (yaw >= 23 && yaw < 68) 5 //SOUTH-WEST - else if (yaw >= 68 && yaw < 113) 6 //WEST - else 7 //NORTH-WEST - } - private fun updateRenderer(renderer: ESPRenderer): ESPRenderer { val side = GeometryMasks.Quad.ALL for (blockTask in blockQueue) { @@ -519,11 +584,11 @@ class HighwayTools : Module() { var message = "\n\n" message += "-------------------- QUEUE -------------------" for (blockTask in blockQueue) { - message += "\n" + blockTask.block.localizedName + "@(" + blockTask.blockPos.asString() + ") State: " + blockTask.taskState.toString() + " Prio: " + blockTask.priority + message += "\n" + blockTask.block.localizedName + "@(" + blockTask.blockPos.asString() + ") Priority: " + blockTask.priority + " State: " + blockTask.taskState.toString() } message += "\n-------------------- DONE --------------------" for (blockTask in doneQueue) { - message += "\n" + blockTask.block.localizedName + "@(" + blockTask.blockPos.asString() + ") State: " + blockTask.taskState.toString() + " Prio: " + blockTask.priority + message += "\n" + blockTask.block.localizedName + "@(" + blockTask.blockPos.asString() + ") Priority: " + blockTask.priority + " State: " + blockTask.taskState.toString() } MessageSendHelper.sendChatMessage(message) } @@ -534,75 +599,76 @@ class HighwayTools : Module() { "\n §9> §rBaritone: §7${baritoneMode.value}" + "\n §9> §rIgnored Blocks:" for (b in ignoreBlocks) { - message += "\n §9> §7${b!!.localizedName}" + message += "\n §9> §7${b!!.registryName}" } MessageSendHelper.sendChatMessage(message) } private fun printEnable() { + var message = "" if (info.value) { - if (buildDirectionSaved == 1 || buildDirectionSaved == 3 || buildDirectionSaved == 5 || buildDirectionSaved == 5 || buildDirectionSaved == 7) { - MessageSendHelper.sendChatMessage("$chatName Module started." + - "\n §9> §7Direction: §a" + directions[buildDirectionSaved] + "§r" + - "\n §9> §7Coordinates: §a" + mc.player.positionVector.x.roundToInt() + ", " + mc.player.positionVector.z.roundToInt() + "§r" + - "\n §9> §7Baritone mode: §a" + baritoneMode.value + "§r") + message += "$chatName Module started." + + "\n §9> §7Direction: §a" + buildDirectionSaved.cardinalName + "§r" + + message += if (buildDirectionSaved.isDiagonal) { + "\n §9> §7Coordinates: §a" + startingBlockPos.x + ", " + startingBlockPos.z + "§r" } else { - MessageSendHelper.sendChatMessage("$chatName Module started." + - "\n §9> §7Direction: §a" + directions[buildDirectionSaved] + "§r" + - "\n §9> §7Coordinate: §a" + buildDirectionCoordinate + "§r" + - "\n §9> §7Baritone mode: §a" + baritoneMode.value + "§r") + if (buildDirectionSaved == Cardinal.NEG_Z || buildDirectionSaved == Cardinal.POS_Z) { + "\n §9> §7Coordinate: §a" + startingBlockPos.z + "§r" + } else { + "\n §9> §7Coordinate: §a" + startingBlockPos.x + "§r" + } } } else { - MessageSendHelper.sendChatMessage("$chatName Module started.") + message += "$chatName Module started." } + MessageSendHelper.sendChatMessage(message) } private fun printDisable() { - if (info.value) { - MessageSendHelper.sendChatMessage("$chatName Module stopped." + + var message = "" + message += if (info.value) { + "$chatName Module stopped." + "\n §9> §7Placed blocks: §a" + totalBlocksPlaced + "§r" + "\n §9> §7Destroyed blocks: §a" + totalBlocksDestroyed + "§r" + - "\n §9> §7Distance: §a" + totalBlocksDistance + "§r") + "\n §9> §7Distance: §a" + totalBlocksDistance + "§r" } else { - MessageSendHelper.sendChatMessage("$chatName Module stopped.") + "$chatName Module stopped." } + MessageSendHelper.sendChatMessage(message) } fun getNextBlock(): BlockPos { return when (buildDirectionSaved) { - 0 -> currentBlockPos.north() - 1 -> currentBlockPos.north().east() - 2 -> currentBlockPos.east() - 3 -> currentBlockPos.south().east() - 4 -> currentBlockPos.south() - 5 -> currentBlockPos.south().west() - 6 -> currentBlockPos.west() - else -> { - currentBlockPos.north().west() - } + Cardinal.NEG_Z -> currentBlockPos.north() + Cardinal.POS_X_NEG_Z -> currentBlockPos.north().east() + Cardinal.POS_X -> currentBlockPos.east() + Cardinal.POS_X_POS_Z -> currentBlockPos.south().east() + Cardinal.POS_Z -> currentBlockPos.south() + Cardinal.NEG_X_POS_Z -> currentBlockPos.south().west() + Cardinal.NEG_X -> currentBlockPos.west() + else -> currentBlockPos.north().west() } } private fun lookInWalkDirection() { // set head rotation to get max walking speed when (buildDirectionSaved) { - 0 -> mc.player.rotationYaw = -180F - 1 -> mc.player.rotationYaw = -135F - 2 -> mc.player.rotationYaw = -90F - 3 -> mc.player.rotationYaw = -45F - 4 -> mc.player.rotationYaw = 0F - 5 -> mc.player.rotationYaw = 45F - 6 -> mc.player.rotationYaw = 90F - else -> { - mc.player.rotationYaw = 135F - } + Cardinal.NEG_Z -> mc.player.rotationYaw = -180F + Cardinal.POS_X_NEG_Z -> mc.player.rotationYaw = -135F + Cardinal.POS_X -> mc.player.rotationYaw = -90F + Cardinal.POS_X_POS_Z -> mc.player.rotationYaw = -45F + Cardinal.POS_Z -> mc.player.rotationYaw = 0F + Cardinal.NEG_X_POS_Z -> mc.player.rotationYaw = 45F + Cardinal.NEG_X -> mc.player.rotationYaw = 90F + else -> mc.player.rotationYaw = 135F } mc.player.rotationPitch = 0F } private fun relativeDirection(curs: BlockPos, steps: Int, turn: Int): BlockPos { var c = curs - var d = (buildDirectionSaved + turn).rem(8) + var d = (buildDirectionSaved.ordinal + turn).rem(8) if (d < 0) d += 8 when (d) { 0 -> c = c.north(steps) @@ -617,16 +683,6 @@ class HighwayTools : Module() { return c } - private fun isDiagonal(): Boolean { - return when (buildDirectionSaved) { - 1 -> true - 3 -> true - 5 -> true - 7 -> true - else -> false - } - } - private fun refreshData() { doneQueue.clear() blockQueue.clear() @@ -654,7 +710,7 @@ class HighwayTools : Module() { 1 } - if (isDiagonal()) { + if (buildDirectionSaved.isDiagonal) { if (x != 1) { blockOffsets.add(Pair(relativeDirection(relativeDirection(cursor, x / 2 - 1, 1 * alterDirection), x / 2, 3 * alterDirection), true)) } @@ -759,15 +815,6 @@ class HighwayTools : Module() { data class BlockTask(val blockPos: BlockPos, var taskState: TaskState, var block: Block, var priority: Int) - private class TaskComparator : Comparator { - override fun compare(o1: BlockTask?, o2: BlockTask?): Int { - if (o1 == null || o2 == null) { - return 0 - } - return o1.priority.compareTo(o2.priority) - } - } - enum class TaskState(val color: ColorHolder) { BREAK(ColorHolder(222, 0, 0)), BREAKING(ColorHolder(240, 222, 60)), diff --git a/src/main/java/me/zeroeightsix/kami/process/HighwayToolsProcess.kt b/src/main/java/me/zeroeightsix/kami/process/HighwayToolsProcess.kt index 86819570ce..95a3b0f8e4 100644 --- a/src/main/java/me/zeroeightsix/kami/process/HighwayToolsProcess.kt +++ b/src/main/java/me/zeroeightsix/kami/process/HighwayToolsProcess.kt @@ -14,9 +14,7 @@ import me.zeroeightsix.kami.util.math.CoordinateConverter.asString * @author Avanatiker * @since 26/08/20 */ -class HighwayToolsProcess : IBaritoneProcess { - - private lateinit var baritone: IBaritone +object HighwayToolsProcess : IBaritoneProcess { override fun isTemporary(): Boolean { return true @@ -31,7 +29,7 @@ class HighwayToolsProcess : IBaritoneProcess { override fun displayName0(): String { val highwayTools = ModuleManager.getModuleT(HighwayTools::class.java)!! val processName = if (highwayTools.blockQueue.size > 0 && !highwayTools.pathing) { - "Block: " + highwayTools.blockQueue.peek().block.localizedName + " @ Position: (" + highwayTools.blockQueue.peek().blockPos.asString() + ") Prio: " + highwayTools.blockQueue.peek().priority + " State: " + highwayTools.blockQueue.peek().taskState.toString() + "Block: " + highwayTools.blockQueue.peek().block.localizedName + " @ Position: (" + highwayTools.blockQueue.peek().blockPos.asString() + ") Priority: " + highwayTools.blockQueue.peek().priority + " State: " + highwayTools.blockQueue.peek().taskState.toString() } else { "Moving to Position: (${highwayTools.getNextBlock().asString()})" } @@ -43,7 +41,6 @@ class HighwayToolsProcess : IBaritoneProcess { } override fun onTick(p0: Boolean, p1: Boolean): PathingCommand? { - baritone = BaritoneAPI.getProvider().primaryBaritone val highwayTools = ModuleManager.getModuleT(HighwayTools::class.java)!! return if (highwayTools.baritoneMode.value && highwayTools.pathing) { PathingCommand(GoalNear(highwayTools.getNextBlock(), 0), PathingCommandType.SET_GOAL_AND_PATH) diff --git a/src/main/java/me/zeroeightsix/kami/util/math/MathUtils.kt b/src/main/java/me/zeroeightsix/kami/util/math/MathUtils.kt index 2c0ed2e053..6d2c7f4fe1 100644 --- a/src/main/java/me/zeroeightsix/kami/util/math/MathUtils.kt +++ b/src/main/java/me/zeroeightsix/kami/util/math/MathUtils.kt @@ -8,6 +8,7 @@ import kotlin.math.* /** * Created by Dewy on the 17th of April, 2020 * Updated by Xiaro on 18/08/20 + * Cleaned up by Avanatiker on 14/09/20 */ object MathUtils { @JvmStatic @@ -49,24 +50,17 @@ object MathUtils { @JvmStatic fun getPlayerCardinal(mc: Minecraft): Cardinal { - return if (isBetween(-22.5, 22.5, normalizeAngle(mc.player.rotationYaw.toDouble()))) { - Cardinal.POS_Z - } else if (isBetween(22.6, 67.5, normalizeAngle(mc.player.rotationYaw.toDouble()))) { - Cardinal.NEG_X_POS_Z - } else if (isBetween(67.6, 112.5, normalizeAngle(mc.player.rotationYaw.toDouble()))) { - Cardinal.NEG_X - } else if (isBetween(112.6, 157.5, normalizeAngle(mc.player.rotationYaw.toDouble()))) { - Cardinal.NEG_X_NEG_Z - } else if (normalizeAngle(mc.player.rotationYaw.toDouble()) >= 157.6 || normalizeAngle(mc.player.rotationYaw.toDouble()) <= -157.5) { - Cardinal.NEG_Z - } else if (isBetween(-157.6, -112.5, normalizeAngle(mc.player.rotationYaw.toDouble()))) { - Cardinal.POS_X_NEG_Z - } else if (isBetween(-112.5, -67.5, normalizeAngle(mc.player.rotationYaw.toDouble()))) { - Cardinal.POS_X - } else if (isBetween(-67.6, -22.6, normalizeAngle(mc.player.rotationYaw.toDouble()))) { - Cardinal.POS_X_POS_Z - } else { - Cardinal.ERROR + val angle = normalizeAngle(mc.player.rotationYaw.toDouble()) + return when { + (angle >= 157.6 || angle <= -157.5) -> Cardinal.NEG_Z //NORTH + isBetween(-157.6, -112.5, angle) -> Cardinal.POS_X_NEG_Z //NORTH-EAST + isBetween(-112.5, -67.5, angle) -> Cardinal.POS_X //EAST + isBetween(-67.6, -22.6, angle) -> Cardinal.POS_X_POS_Z //SOUTH-EAST + isBetween(-22.5, 22.5, angle) -> Cardinal.POS_Z //SOUTH + isBetween(22.6, 67.5, angle) -> Cardinal.NEG_X_POS_Z //SOUTH-WEST + isBetween(67.6, 112.5, angle) -> Cardinal.NEG_X //WEST + isBetween(112.6, 157.5, angle) -> Cardinal.NEG_X_NEG_Z //NORTH-WEST + else -> Cardinal.ERROR } } @@ -74,8 +68,8 @@ object MathUtils { fun getPlayerMainCardinal(mc: Minecraft): CardinalMain { return when (Character.toUpperCase(mc.player.horizontalFacing.toString()[0])) { 'N' -> CardinalMain.NEG_Z - 'S' -> CardinalMain.POS_Z 'E' -> CardinalMain.POS_X + 'S' -> CardinalMain.POS_Z 'W' -> CardinalMain.NEG_X else -> CardinalMain.NULL } @@ -101,23 +95,23 @@ object MathUtils { return min(max(convertedIn, actualMin), actualMax) } - enum class Cardinal(@JvmField var cardinalName: String) { - POS_Z("+Z"), - NEG_X_POS_Z("-X / +Z"), - NEG_X("-X"), - NEG_X_NEG_Z("-X / -Z"), - NEG_Z("-Z"), - POS_X_NEG_Z("+X / -Z"), - POS_X("+X"), - POS_X_POS_Z("+X / +Z"), - ERROR("ERROR_CALC_DIRECT"); + enum class Cardinal(val directionName: String, @JvmField val cardinalName: String, val isDiagonal: Boolean) { + NEG_Z("-Z", "North", false), + POS_X_NEG_Z("+X / -Z", "North East", true), + POS_X("+X", "East", false), + POS_X_POS_Z("+X / +Z", "South East", true), + POS_Z("+Z", "South", false), + NEG_X_POS_Z("-X / +Z", "South West", true), + NEG_X("-X", "West", false), + NEG_X_NEG_Z("-X / -Z", "North West", true), + ERROR("ERROR_CALC_DIRECT", "ERROR_CALC_DIRECT", true) } - enum class CardinalMain(@JvmField var cardinalName: String) { - POS_Z("+Z"), - NEG_X("-X"), - NEG_Z("-Z"), - POS_X("+X"), - NULL("N/A"); + enum class CardinalMain(val directionName: String, val cardinalName: String) { + NEG_Z("-Z", "North"), + POS_X("+X", "East"), + POS_Z("+Z", "South"), + NEG_X("-X", "West"), + NULL("N/A", "N/A") } } \ No newline at end of file From 38c080fa55905d6ff082daed0341718e021a0567 Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 15 Sep 2020 05:27:15 +0200 Subject: [PATCH 024/390] Fixed last break - Old placeBlock back --- .../kami/module/modules/misc/HighwayTools.kt | 217 ++++++------------ .../kami/process/HighwayToolsProcess.kt | 2 +- 2 files changed, 70 insertions(+), 149 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index e7d5ae3e22..7df1b7fec9 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -25,22 +25,19 @@ import net.minecraft.block.Block.getBlockById import net.minecraft.block.Block.getIdFromBlock import net.minecraft.block.BlockAir import net.minecraft.block.BlockLiquid -import net.minecraft.block.state.IBlockState import net.minecraft.client.audio.PositionedSoundRecord +import net.minecraft.entity.item.EntityItem +import net.minecraft.entity.item.EntityXPOrb import net.minecraft.init.Blocks import net.minecraft.init.SoundEvents -import net.minecraft.item.ItemBlock -import net.minecraft.item.ItemStack import net.minecraft.network.play.client.* 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.MathHelper import net.minecraft.util.math.Vec3d import java.util.* import java.util.stream.IntStream.range -import kotlin.math.atan2 -import kotlin.math.sqrt /** * @author Avanatiker @@ -145,7 +142,10 @@ class HighwayTools : Module() { lastHotbarSlot = -1 - BaritoneAPI.getProvider().primaryBaritone.pathingBehavior.cancelEverything() + val baritoneProcess = BaritoneAPI.getProvider().primaryBaritone.pathingControlManager.mostRecentInControl() + if (baritoneProcess.isPresent && baritoneProcess.get() == HighwayToolsProcess) { + baritoneProcess.get().onLostControl() + } printDisable() totalBlocksPlaced = 0 totalBlocksDestroyed = 0 @@ -154,15 +154,21 @@ class HighwayTools : Module() { override fun onUpdate() { if (mc.playerController == null) return + pathing = BaritoneAPI.getProvider().primaryBaritone.pathingBehavior.isPathing if (!isDone()) { - if (!BaritoneAPI.getProvider().primaryBaritone.pathingBehavior.isPathing) pathing = false - if (!doTask()) { - if (!pathing && !ModuleManager.getModuleT(LagNotifier::class.java)!!.paused) { + if (!doTask() && !pathing) { + if (!ModuleManager.getModuleT(LagNotifier::class.java)!!.paused) { stuckDetector += 1 blockQueue = LinkedList(blockQueue.shuffled()) + if (debugMessages.value == DebugMessages.ALL) { + MessageSendHelper.sendChatMessage("$chatName Shuffled tasks") + } if (stuckDetector > 20) { refreshData() + if (debugMessages.value == DebugMessages.IMPORTANT) { + MessageSendHelper.sendChatMessage("$chatName You got stuck, retry") + } } } else { refreshData() @@ -176,7 +182,6 @@ class HighwayTools : Module() { totalBlocksDistance++ doneQueue.clear() updateTasks() - pathing = true if (!noViewReset.value) lookInWalkDirection() } else { doneQueue.clear() @@ -396,35 +401,54 @@ class HighwayTools : Module() { mc.player.swingArm(EnumHand.MAIN_HAND) } - private fun findMaterialInHotbar(material: Block): Int { - var slot = -1 - for (i in 0..8) { - val stack = mc.player.inventory.getStackInSlot(i) - if (stack != ItemStack.EMPTY && stack.getItem() is ItemBlock) { - val block = (stack.getItem() as ItemBlock).block - if (block::class == material::class) { - slot = i - break - } - } + private fun placeBlock(pos: BlockPos, mat: Block): Boolean + { + // check if block is already placed + val block = mc.world.getBlockState(pos).block + if (block !is BlockAir && block !is BlockLiquid) { + return false } - return slot - } - - private fun placeBlock(blockPos: BlockPos, material: Block): Boolean { - if (!mc.world.getBlockState(blockPos).material.isReplaceable) { - if (debugMessages.value == DebugMessages.ALL) { - MessageSendHelper.sendChatMessage("$chatName Block is already placed, skipping") + // check if entity blocks placing + for (entity in mc.world.getEntitiesWithinAABBExcludingEntity(null, AxisAlignedBB(pos))) { + if (entity !is EntityItem && entity !is EntityXPOrb) { return false } - } else if (!BlockUtils.checkForNeighbours(blockPos) && debugMessages.value == DebugMessages.ALL) { - MessageSendHelper.sendChatMessage("$chatName No adjacent blocks found") + } + val side = getPlaceableSide(pos) ?: return false + // check if we have a block adjacent to blockpos to click at + val neighbour = pos.offset(side) + val opposite = side.opposite + // check if neighbor can be right clicked + if (!BlockUtils.canBeClicked(neighbour)) { return false - } else { - if (placeAnimation.value) mc.player.connection.sendPacket(CPacketAnimation(mc.player.activeHand)) - if (!placeBlockExecute(blockPos, material)) return false } - + //Swap to material in Hotbar or get from inventory + if (InventoryUtils.getSlotsHotbar(getIdFromBlock(mat)) == null && InventoryUtils.getSlotsNoHotbar(getIdFromBlock(mat)) != null) { + //InventoryUtils.moveToHotbar(getIdFromBlock(mat), 130, (tickDelay.value * 16).toLong()) + for (x in InventoryUtils.getSlotsNoHotbar(getIdFromBlock(mat))!!) { + InventoryUtils.quickMoveSlot(x, (tickDelay.value * 16).toLong()) + } + //InventoryUtils.quickMoveSlot(1, (tickDelay.value * 16).toLong()) + } else if (InventoryUtils.getSlots(0, 35, getIdFromBlock(mat)) == null) { + MessageSendHelper.sendChatMessage("$chatName No ${mat.localizedName} was found in inventory") + mc.getSoundHandler().playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) + disable() + return false + } + InventoryUtils.swapSlotToItem(getIdFromBlock(mat)) + val hitVec = Vec3d(neighbour).add(0.5, 0.5, 0.5).add(Vec3d(opposite.directionVec).scale(0.5)) + val neighbourBlock = mc.world.getBlockState(neighbour).block + if (!isSneaking && BlockUtils.blackList.contains(neighbourBlock) || BlockUtils.shulkerList.contains(neighbourBlock)) { + mc.player.connection.sendPacket(CPacketEntityAction(mc.player, CPacketEntityAction.Action.START_SNEAKING)) + isSneaking = true + } + if (spoofRotations.value) { + BlockUtils.faceVectorPacketInstant(hitVec) + } + //PlayerPacketManager.addPacket(this, PlayerPacketManager.PlayerPacket(rotating = true, rotation = Vec2f(mc.player.rotationYaw, mc.player.rotationPitch))) + mc.playerController.processRightClickBlock(mc.player, mc.world, neighbour, opposite, hitVec, EnumHand.MAIN_HAND) + mc.player.swingArm(EnumHand.MAIN_HAND) + mc.rightClickDelayTimer = 4 val noBreakAnimation = ModuleManager.getModuleT(NoBreakAnimation::class.java)!! if (noBreakAnimation.isEnabled) { noBreakAnimation.resetMining() @@ -432,121 +456,18 @@ class HighwayTools : Module() { return true } - private fun placeBlockExecute(pos: BlockPos, material: Block): Boolean { - val eyesPos = Vec3d(mc.player.posX, mc.player.posY + mc.player.getEyeHeight().toDouble(), mc.player.posZ) - val var3 = EnumFacing.values() - for (side in var3) { - val neighbor = pos.offset(side) - val side2 = side.opposite - - if (!canBeClicked(neighbor)) { - if (debugMessages.value == DebugMessages.ALL) { - MessageSendHelper.sendChatMessage("$chatName No neighbor to click at!") - return false - } - } else { - val hitVec = Vec3d(neighbor).add(0.5, 0.5, 0.5).add(Vec3d(side2.directionVec).scale(0.5)) - - if (eyesPos.squareDistanceTo(hitVec) <= 18.0625) { - if (spoofRotations.value) { - faceVectorPacketInstant(hitVec) - } - - var needSneak = false - val blockBelow = mc.world.getBlockState(neighbor).block - - if (BlockUtils.blackList.contains(blockBelow) || BlockUtils.shulkerList.contains(blockBelow)) { - if (debugMessages.value == DebugMessages.IMPORTANT) { - MessageSendHelper.sendChatMessage("$chatName Sneak enabled!") - } - needSneak = true - } - - if (needSneak) { - mc.player.connection.sendPacket(CPacketEntityAction(mc.player, CPacketEntityAction.Action.START_SNEAKING)) - } - - // swap to material in Hotbar or get from inventory - if (InventoryUtils.getSlotsHotbar(getIdFromBlock(material)) == null && InventoryUtils.getSlotsNoHotbar(getIdFromBlock(material)) != null) { - //InventoryUtils.moveToHotbar(getIdFromBlock(material), 130, (tickDelay.value * 16).toLong()) - for (x in InventoryUtils.getSlotsNoHotbar(getIdFromBlock(material))!!) { - InventoryUtils.quickMoveSlot(x, (tickDelay.value * 16).toLong()) - } - //InventoryUtils.quickMoveSlot(1, (tickDelay.value * 16).toLong()) - } else if (InventoryUtils.getSlots(0, 35, getIdFromBlock(material)) == null) { - MessageSendHelper.sendChatMessage("$chatName No ${material.localizedName} was found in inventory") - mc.getSoundHandler().playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) - disable() - return false - } - InventoryUtils.swapSlotToItem(getIdFromBlock(material)) - val materialSlot = findMaterialInHotbar(material) - - if (lastHotbarSlot != materialSlot) { - if (debugMessages.value == DebugMessages.ALL) { - MessageSendHelper.sendChatMessage("$chatName Setting Slot to obsidian at = $materialSlot") - } - - if (spoofHotbar.value) { - mc.player.connection.sendPacket(CPacketHeldItemChange(materialSlot)) - } else { - mc.player.inventory.currentItem = materialSlot - } - lastHotbarSlot = materialSlot - } - - mc.playerController.processRightClickBlock(mc.player, mc.world, neighbor, side2, hitVec, EnumHand.MAIN_HAND) - mc.player.connection.sendPacket(CPacketAnimation(EnumHand.MAIN_HAND)) - - if (needSneak) { - if (debugMessages.value == DebugMessages.IMPORTANT) { - MessageSendHelper.sendChatMessage("$chatName Sneak disabled!") - } - mc.player.connection.sendPacket(CPacketEntityAction(mc.player, CPacketEntityAction.Action.STOP_SNEAKING)) - } - } - - if (debugMessages.value == DebugMessages.ALL) { - MessageSendHelper.sendChatMessage("$chatName Distance > 4.25 blocks!") - } + private fun getPlaceableSide(pos: BlockPos): EnumFacing? { + for (side in EnumFacing.values()) { + val neighbour = pos.offset(side) + if (!mc.world.getBlockState(neighbour).block.canCollideCheck(mc.world.getBlockState(neighbour), false)) { + continue + } + val blockState = mc.world.getBlockState(neighbour) + if (!blockState.material.isReplaceable) { + return side } } - return true - } - - companion object { - private fun canBeClicked(pos: BlockPos): Boolean { - return getBlock(pos).canCollideCheck(getState(pos), false) - } - - fun getBlock(pos: BlockPos): Block { - return getState(pos).block - } - - private fun getState(pos: BlockPos): IBlockState { - return mc.world.getBlockState(pos) - } - - private fun faceVectorPacketInstant(vec: Vec3d) { - val rotations = getLegitRotations(vec) - mc.player.connection.sendPacket(CPacketPlayer.Rotation(rotations[0], rotations[1], mc.player.onGround)) - } - - private fun getLegitRotations(vec: Vec3d): FloatArray { - val eyesPos = eyesPos - val diffX = vec.x - eyesPos.x - val diffY = vec.y - eyesPos.y - val diffZ = vec.z - eyesPos.z - - val diffXZ = sqrt(diffX * diffX + diffZ * diffZ) - val yaw = Math.toDegrees(atan2(diffZ, diffX)).toFloat() - 90.0f - val pitch = (-Math.toDegrees(atan2(diffY, diffXZ))).toFloat() - - return floatArrayOf(mc.player.rotationYaw + MathHelper.wrapDegrees(yaw - mc.player.rotationYaw), mc.player.rotationPitch + MathHelper.wrapDegrees(pitch - mc.player.rotationPitch)) - } - - private val eyesPos: Vec3d - get() = Vec3d(mc.player.posX, mc.player.posY + mc.player.getEyeHeight().toDouble(), mc.player.posZ) + return null } private fun lookAtBlock(pos: BlockPos) { diff --git a/src/main/java/me/zeroeightsix/kami/process/HighwayToolsProcess.kt b/src/main/java/me/zeroeightsix/kami/process/HighwayToolsProcess.kt index 95a3b0f8e4..4616748b13 100644 --- a/src/main/java/me/zeroeightsix/kami/process/HighwayToolsProcess.kt +++ b/src/main/java/me/zeroeightsix/kami/process/HighwayToolsProcess.kt @@ -42,7 +42,7 @@ object HighwayToolsProcess : IBaritoneProcess { override fun onTick(p0: Boolean, p1: Boolean): PathingCommand? { val highwayTools = ModuleManager.getModuleT(HighwayTools::class.java)!! - return if (highwayTools.baritoneMode.value && highwayTools.pathing) { + return if (highwayTools.baritoneMode.value) { PathingCommand(GoalNear(highwayTools.getNextBlock(), 0), PathingCommandType.SET_GOAL_AND_PATH) } else PathingCommand(null, PathingCommandType.REQUEST_PAUSE) } From c837ad6c2b78b9824ff2964ea2a545732b06c166 Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 15 Sep 2020 06:15:33 +0200 Subject: [PATCH 025/390] Pathing fix --- .../me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 7df1b7fec9..e19a61ee3b 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -157,8 +157,8 @@ class HighwayTools : Module() { pathing = BaritoneAPI.getProvider().primaryBaritone.pathingBehavior.isPathing if (!isDone()) { - if (!doTask() && !pathing) { - if (!ModuleManager.getModuleT(LagNotifier::class.java)!!.paused) { + if (!doTask()) { + if (!pathing && !ModuleManager.getModuleT(LagNotifier::class.java)!!.paused && !ModuleManager.getModuleT(AutoObsidian::class.java)!!.active) { stuckDetector += 1 blockQueue = LinkedList(blockQueue.shuffled()) if (debugMessages.value == DebugMessages.ALL) { From 7ef3c682f83afe3e38f79e0b577d6633d3d5d9d7 Mon Sep 17 00:00:00 2001 From: Christian Date: Wed, 16 Sep 2020 07:54:01 +0200 Subject: [PATCH 026/390] Huge overhaul - The manual mode is back! (Disable Automatic) - No more view locking. Now only server side - Settings reworked - Finally PriorityQueue with better task selection algorithm - Way faster and better liquid handling - Optical improvements - Pathing fixes - Runtime optimizations - Formatting upgrades --- .../kami/module/modules/misc/AutoObsidian.kt | 2 +- .../kami/module/modules/misc/HighwayTools.kt | 271 +++++++++++------- .../kami/process/HighwayToolsProcess.kt | 6 +- 3 files changed, 166 insertions(+), 113 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt index 1f147a2399..6de19293ac 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt @@ -49,7 +49,7 @@ object AutoObsidian : Module() { var goal: BlockPos? = null var state = State.SEARCHING - private var active = false + var active = false private var searchingState = SearchingState.PLACING private var playerPos = BlockPos(0, -1, 0) private var placingPos = BlockPos(0, -1, 0) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index e19a61ee3b..d2a23d00a2 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -2,6 +2,7 @@ package me.zeroeightsix.kami.module.modules.misc import baritone.api.BaritoneAPI import me.zeroeightsix.kami.event.events.RenderEvent +import me.zeroeightsix.kami.manager.mangers.PlayerPacketManager import me.zeroeightsix.kami.module.Module import me.zeroeightsix.kami.module.ModuleManager import me.zeroeightsix.kami.module.modules.player.LagNotifier @@ -18,6 +19,7 @@ import me.zeroeightsix.kami.util.math.MathUtils.Cardinal import me.zeroeightsix.kami.util.math.MathUtils.getPlayerCardinal import me.zeroeightsix.kami.util.math.MathUtils.mcPlayerPosFloored import me.zeroeightsix.kami.util.math.RotationUtils +import me.zeroeightsix.kami.util.math.Vec2f import me.zeroeightsix.kami.util.math.VectorUtils import me.zeroeightsix.kami.util.text.MessageSendHelper import net.minecraft.block.Block @@ -38,6 +40,8 @@ import net.minecraft.util.math.BlockPos import net.minecraft.util.math.Vec3d import java.util.* import java.util.stream.IntStream.range +import kotlin.math.abs +import kotlin.math.sqrt /** * @author Avanatiker @@ -49,29 +53,22 @@ import java.util.stream.IntStream.range description = "Be the grief a step a head.", category = Module.Category.MISC ) -class HighwayTools : Module() { +object HighwayTools : Module() { private val mode = register(Settings.e("Mode", Mode.HIGHWAY)) - private val debugMessages = register(Settings.e("DebugMessages", DebugMessages.IMPORTANT)) private val page = register(Settings.e("Page", Page.MAIN)) - // settings for module - val baritoneMode = register(Settings.booleanBuilder("Baritone").withValue(true).withVisibility { false }.build()) - private val blocksPerTick = register(Settings.integerBuilder("BlocksPerTick").withMinimum(1).withValue(1).withMaximum(9).withVisibility { page.value == Page.MAIN }.build()) - private val tickDelay = register(Settings.integerBuilder("TickDelayPlace").withMinimum(0).withValue(0).withMaximum(10).withVisibility { page.value == Page.MAIN }.build()) - private val tickDelayBreak = register(Settings.integerBuilder("TickDelayBreak").withMinimum(0).withValue(0).withMaximum(10).withVisibility { page.value == Page.MAIN }.build()) + // main settings + private val blocksPerTick = register(Settings.integerBuilder("BlocksPerTick").withMinimum(1).withValue(1).withMaximum(10).withVisibility { page.value == Page.MAIN }.build()) + private val tickDelayPlace = register(Settings.integerBuilder("TickDelayPlace").withMinimum(0).withValue(0).withMaximum(15).withVisibility { page.value == Page.MAIN }.build()) + private val tickDelayBreak = register(Settings.integerBuilder("TickDelayBreak").withMinimum(0).withValue(0).withMaximum(15).withVisibility { page.value == Page.MAIN }.build()) + val baritoneMode = register(Settings.booleanBuilder("Automatic").withValue(true).withVisibility { page.value == Page.MAIN }.build()) + private val maxReach = register(Settings.doubleBuilder("Reach").withValue(4.4).withMinimum(1.0).withVisibility { page.value == Page.MAIN }.build()) private val noViewReset = register(Settings.booleanBuilder("NoViewReset").withValue(false).withVisibility { page.value == Page.MAIN }.build()) private val spoofRotations = register(Settings.booleanBuilder("SpoofRotations").withValue(true).withVisibility { page.value == Page.MAIN }.build()) - private val spoofHotbar = register(Settings.booleanBuilder("SpoofRotations").withValue(true).withVisibility { page.value == Page.MAIN }.build()) - private val info = register(Settings.booleanBuilder("ShowInfo").withValue(true).withVisibility { page.value == Page.MAIN }.build()) - private val printDebug = register(Settings.booleanBuilder("ShowDebug").withValue(false).withVisibility { page.value == Page.MAIN }.build()) - private val placeAnimation = register(Settings.booleanBuilder("PlaceAnimation").withValue(false).withVisibility { page.value == Page.MAIN }.build()) - private val filled = register(Settings.booleanBuilder("Filled").withValue(true).withVisibility { page.value == Page.MAIN }.build()) - private val outline = register(Settings.booleanBuilder("Outline").withValue(true).withVisibility { page.value == Page.MAIN }.build()) - private val aFilled = register(Settings.integerBuilder("FilledAlpha").withMinimum(0).withValue(31).withMaximum(255).withVisibility { filled.value && page.value == Page.MAIN }.build()) - private val aOutline = register(Settings.integerBuilder("OutlineAlpha").withMinimum(0).withValue(127).withMaximum(255).withVisibility { outline.value && page.value == Page.MAIN }.build()) - - // custom build settings + private val spoofLookAt = register(Settings.booleanBuilder("SpoofLookAt").withValue(true).withVisibility { page.value == Page.MAIN }.build()) + + // build settings val clearSpace = register(Settings.booleanBuilder("ClearSpace").withValue(true).withVisibility { page.value == Page.BUILD }.build()) var clearHeight = register(Settings.integerBuilder("ClearHeight").withMinimum(1).withValue(4).withMaximum(6).withVisibility { page.value == Page.BUILD && clearSpace.value }.build()) private var buildWidth = register(Settings.integerBuilder("BuildWidth").withMinimum(1).withValue(7).withMaximum(9).withVisibility { page.value == Page.BUILD }.build()) @@ -79,29 +76,44 @@ class HighwayTools : Module() { private var rimHeight = register(Settings.integerBuilder("RimHeight").withMinimum(1).withValue(1).withMaximum(clearHeight.value).withVisibility { rims.value && page.value == Page.BUILD }.build()) private val cornerBlock = register(Settings.booleanBuilder("CornerBlock").withValue(true).withVisibility { page.value == Page.BUILD }.build()) + // config settings + private val info = register(Settings.booleanBuilder("ShowInfo").withValue(true).withVisibility { page.value == Page.CONFIG }.build()) + private val printDebug = register(Settings.booleanBuilder("ShowQueue").withValue(false).withVisibility { page.value == Page.CONFIG }.build()) + private val debugMessages = register(Settings.enumBuilder(DebugMessages::class.java).withName("Debug").withValue(DebugMessages.IMPORTANT).withVisibility { page.value == Page.CONFIG }.build()) + private val goalRender = register(Settings.booleanBuilder("GoalRender").withValue(false).withVisibility { page.value == Page.CONFIG }.build()) + private val filled = register(Settings.booleanBuilder("Filled").withValue(true).withVisibility { page.value == Page.CONFIG }.build()) + private val outline = register(Settings.booleanBuilder("Outline").withValue(true).withVisibility { page.value == Page.CONFIG }.build()) + private val aFilled = register(Settings.integerBuilder("FilledAlpha").withMinimum(0).withValue(31).withMaximum(255).withVisibility { filled.value && page.value == Page.CONFIG }.build()) + private val aOutline = register(Settings.integerBuilder("OutlineAlpha").withMinimum(0).withValue(127).withMaximum(255).withVisibility { outline.value && page.value == Page.CONFIG }.build()) + + // other settings var ignoreBlocks = mutableListOf(Blocks.STANDING_SIGN, Blocks.WALL_SIGN, Blocks.STANDING_BANNER, Blocks.WALL_BANNER, Blocks.BEDROCK, Blocks.PORTAL) var material: Block = Blocks.OBSIDIAN var fillerMat: Block = Blocks.NETHERRACK private var playerHotbarSlot = -1 private var lastHotbarSlot = -1 - private var isSneaking = false - var pathing = true - private var stuckDetector = 0 private lateinit var buildDirectionSaved: Cardinal + private var baritoneSettingAllowPlace = false + private var baritoneSettingRenderGoal = false - // stats - private var totalBlocksPlaced = 0 - private var totalBlocksDestroyed = 0 - private var totalBlocksDistance = 0 - - var blockQueue: Queue = LinkedList() + // runtime vars + private val compareByPriority: Comparator = compareBy { it.priority } + var blockQueue: PriorityQueue = PriorityQueue(compareByPriority) private val doneQueue: Queue = LinkedList() private var blockOffsets = mutableListOf>() private var waitTicks = 0 private var blocksPlaced = 0 + var pathing = false + private var isSneaking = false + private var stuckDetector = 0 private lateinit var currentBlockPos: BlockPos private lateinit var startingBlockPos: BlockPos + // stats + private var totalBlocksPlaced = 0 + private var totalBlocksDestroyed = 0 + private var totalBlocksDistance = 0 + private enum class DebugMessages { NONE, IMPORTANT, ALL } @@ -121,6 +133,15 @@ class HighwayTools : Module() { lastHotbarSlot = -1 buildDirectionSaved = getPlayerCardinal(mc) + if (baritoneMode.value) { + baritoneSettingAllowPlace = BaritoneAPI.getSettings().allowPlace.value + BaritoneAPI.getSettings().allowPlace.value = false + if (!goalRender.value) { + baritoneSettingRenderGoal = BaritoneAPI.getSettings().renderGoal.value + BaritoneAPI.getSettings().renderGoal.value = false + } + } + playerHotbarSlot = mc.player.inventory.currentItem refreshData() @@ -142,9 +163,13 @@ class HighwayTools : Module() { lastHotbarSlot = -1 - val baritoneProcess = BaritoneAPI.getProvider().primaryBaritone.pathingControlManager.mostRecentInControl() - if (baritoneProcess.isPresent && baritoneProcess.get() == HighwayToolsProcess) { - baritoneProcess.get().onLostControl() + if (baritoneMode.value) { + BaritoneAPI.getSettings().allowPlace.value = baritoneSettingAllowPlace + if (!goalRender.value) BaritoneAPI.getSettings().renderGoal.value = baritoneSettingRenderGoal + val baritoneProcess = BaritoneAPI.getProvider().primaryBaritone.pathingControlManager.mostRecentInControl() + if (baritoneProcess.isPresent && baritoneProcess.get() == HighwayToolsProcess) { + baritoneProcess.get().onLostControl() + } } printDisable() totalBlocksPlaced = 0 @@ -154,40 +179,59 @@ class HighwayTools : Module() { override fun onUpdate() { if (mc.playerController == null) return - pathing = BaritoneAPI.getProvider().primaryBaritone.pathingBehavior.isPathing - - if (!isDone()) { - if (!doTask()) { - if (!pathing && !ModuleManager.getModuleT(LagNotifier::class.java)!!.paused && !ModuleManager.getModuleT(AutoObsidian::class.java)!!.active) { - stuckDetector += 1 - blockQueue = LinkedList(blockQueue.shuffled()) - if (debugMessages.value == DebugMessages.ALL) { - MessageSendHelper.sendChatMessage("$chatName Shuffled tasks") - } - if (stuckDetector > 20) { - refreshData() - if (debugMessages.value == DebugMessages.IMPORTANT) { - MessageSendHelper.sendChatMessage("$chatName You got stuck, retry") + + if (baritoneMode.value) { + pathing = BaritoneAPI.getProvider().primaryBaritone.pathingBehavior.isPathing + if (!isDone()) { + if (!doTask()) { + if (!pathing && !ModuleManager.getModuleT(LagNotifier::class.java)!!.paused && !ModuleManager.getModuleT(AutoObsidian::class.java)!!.active) { + stuckDetector += 1 + var tmpQueue: Queue = LinkedList(blockQueue) + tmpQueue = LinkedList(tmpQueue.shuffled()) + blockQueue.clear() + blockQueue.addAll(tmpQueue) + if (debugMessages.value == DebugMessages.ALL) { + MessageSendHelper.sendChatMessage("$chatName Shuffled tasks") } + if (stuckDetector > 20) { + refreshData() + if (debugMessages.value == DebugMessages.IMPORTANT) { + MessageSendHelper.sendChatMessage("$chatName You got stuck, retry") + } + } + } else { + refreshData() } } else { - refreshData() + stuckDetector = 0 } } else { - stuckDetector = 0 + if (checkTasks() && !pathing) { + currentBlockPos = getNextBlock() + totalBlocksDistance++ + doneQueue.clear() + updateTasks() + if (!noViewReset.value) lookInWalkDirection() + } else { + doneQueue.clear() + updateTasks() + } } } else { - if (checkTasks()) { - currentBlockPos = getNextBlock() - totalBlocksDistance++ - doneQueue.clear() - updateTasks() - if (!noViewReset.value) lookInWalkDirection() + if (currentBlockPos == mcPlayerPosFloored(mc)) { + if (!doTask()) { + var tmpQueue: Queue = LinkedList(blockQueue) + tmpQueue = LinkedList(tmpQueue.shuffled()) + blockQueue.clear() + blockQueue.addAll(tmpQueue) + } } else { - doneQueue.clear() - updateTasks() + currentBlockPos = mcPlayerPosFloored(mc) + if (abs((buildDirectionSaved.ordinal - getPlayerCardinal(mc).ordinal) % 8) == 4) buildDirectionSaved = getPlayerCardinal(mc) + refreshData() } } + if (printDebug.value) { printDebug() } @@ -197,6 +241,10 @@ class HighwayTools : Module() { blockQueue.add(BlockTask(blockPos, taskState, material, priority)) } + private fun addDoneTask(blockPos: BlockPos, material: Block) { + doneQueue.add(BlockTask(blockPos, TaskState.DONE, material, 1)) + } + private fun checkTasks(): Boolean { for (blockTask in doneQueue) { val block = mc.world.getBlockState(blockTask.blockPos).block @@ -231,8 +279,10 @@ class HighwayTools : Module() { for (b in ignoreBlocks) { if (block::class == b!!::class) { + blockQueue.poll() blockAction.taskState = TaskState.DONE - blockAction.priority = 4 + blockAction.priority = 1 + doneQueue.add(blockAction) doTask() } } @@ -249,21 +299,7 @@ class HighwayTools : Module() { } } - if (!found) { - var insideBuild = false - - for ((pos, _) in blockOffsets) { - if (neighbour == pos) { - insideBuild = true - } - } - - if (insideBuild) { - addTask(neighbour, TaskState.PLACE, fillerMat, 1) - } else { - addTask(neighbour, TaskState.PLACE, material, 1) - } - } + if (!found && BlockUtils.hasNeighbour(neighbour) && sqrt(mc.player.getDistanceSqToCenter(neighbour)) < maxReach.value) addTask(neighbour, TaskState.PLACE, fillerMat, 2) } } @@ -273,8 +309,23 @@ class HighwayTools : Module() { doTask() } is BlockLiquid -> { + + var insideBuild = false + for ((pos, build) in blockOffsets) { + if (blockAction.blockPos == pos && build) { + insideBuild = true + } + } + + blockQueue.poll() blockAction.taskState = TaskState.PLACE - blockAction.priority = 3 + blockAction.priority = 2 + if (insideBuild) { + blockAction.block = Blocks.OBSIDIAN + } else { + blockAction.block = Blocks.NETHERRACK + } + blockQueue.add(blockAction) doTask() } else -> { @@ -295,11 +346,15 @@ class HighwayTools : Module() { waitTicks = tickDelayBreak.value if (blockAction.block::class == material::class) { + blockQueue.poll() blockAction.taskState = TaskState.PLACE - blockAction.priority = 3 + blockAction.priority = 4 + blockQueue.add(blockAction) } else { + blockQueue.poll() blockAction.taskState = TaskState.DONE - blockAction.priority = 4 + blockAction.priority = 1 + doneQueue.add(blockAction) } doTask() @@ -315,10 +370,6 @@ class HighwayTools : Module() { return true } - if (block is BlockLiquid) { - blockAction.block = fillerMat - } - if (placeBlock(blockAction.blockPos, blockAction.block)) { blockAction.taskState = TaskState.PLACED if (blocksPerTick.value > blocksPlaced + 1) { @@ -328,7 +379,7 @@ class HighwayTools : Module() { blocksPlaced = 0 } - waitTicks = tickDelay.value + waitTicks = tickDelayPlace.value totalBlocksPlaced++ } else { return false @@ -339,14 +390,18 @@ class HighwayTools : Module() { val block = mc.world.getBlockState(blockAction.blockPos).block if (block !is BlockAir) { + blockQueue.poll() blockAction.taskState = TaskState.DONE - blockAction.priority = 4 + blockAction.priority = 1 + doneQueue.add(blockAction) } else { blockAction.taskState = TaskState.PLACE } } else { + blockQueue.poll() blockAction.taskState = TaskState.BREAK - blockAction.priority = 2 + blockAction.priority = 3 + blockQueue.add(blockAction) } doTask() } @@ -370,19 +425,19 @@ class HighwayTools : Module() { for ((a, b) in blockOffsets) { val block = mc.world.getBlockState(a).block when { - (!b && block in ignoreBlocks) -> addTask(a, TaskState.DONE, getBlockById(0), 4) - (b && block is BlockAir) -> addTask(a, TaskState.PLACE, material, 3) - (b && block !is BlockAir && block::class != material::class) -> addTask(a, TaskState.BREAK, material, 2) - (!b && block !is BlockAir) -> addTask(a, TaskState.BREAK, getBlockById(0), 2) - (b && block::class == material::class) -> addTask(a, TaskState.DONE, material, 4) - (!b && block is BlockAir) -> addTask(a, TaskState.DONE, getBlockById(0), 4) + (!b && block in ignoreBlocks) -> addDoneTask(a, getBlockById(0)) + (b && block::class == material::class) -> addDoneTask(a, material) + (!b && block is BlockAir) -> addDoneTask(a, getBlockById(0)) + (b && block !is BlockAir && block::class != material::class) -> addTask(a, TaskState.BREAK, material, 3) + (!b && block !is BlockAir) -> addTask(a, TaskState.BREAK, getBlockById(0), 3) + (b && block is BlockAir) -> addTask(a, TaskState.PLACE, material, 4) } } } private fun mineBlock(pos: BlockPos, pre: Boolean) { if (InventoryUtils.getSlotsHotbar(278) == null && InventoryUtils.getSlotsNoHotbar(278) != null) { - InventoryUtils.moveToHotbar(278, 130, (tickDelay.value * 16).toLong()) + InventoryUtils.moveToHotbar(278, 130) return } else if (InventoryUtils.getSlots(0, 35, 278) == null) { MessageSendHelper.sendChatMessage("$chatName No Pickaxe was found in inventory") @@ -391,7 +446,10 @@ class HighwayTools : Module() { return } InventoryUtils.swapSlotToItem(278) - lookAtBlock(pos) + if (spoofLookAt.value) { + val lookAt = RotationUtils.getRotationTo(Vec3d(pos).add(0.5, 0.0, 0.5), true) + PlayerPacketManager.addPacket(this, PlayerPacketManager.PlayerPacket(rotating = true, rotation = Vec2f(lookAt.x.toFloat(), lookAt.y.toFloat()))) + } if (pre) { mc.connection!!.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, pos, mc.objectMouseOver.sideHit)) @@ -426,7 +484,7 @@ class HighwayTools : Module() { if (InventoryUtils.getSlotsHotbar(getIdFromBlock(mat)) == null && InventoryUtils.getSlotsNoHotbar(getIdFromBlock(mat)) != null) { //InventoryUtils.moveToHotbar(getIdFromBlock(mat), 130, (tickDelay.value * 16).toLong()) for (x in InventoryUtils.getSlotsNoHotbar(getIdFromBlock(mat))!!) { - InventoryUtils.quickMoveSlot(x, (tickDelay.value * 16).toLong()) + InventoryUtils.quickMoveSlot(x) } //InventoryUtils.quickMoveSlot(1, (tickDelay.value * 16).toLong()) } else if (InventoryUtils.getSlots(0, 35, getIdFromBlock(mat)) == null) { @@ -470,13 +528,6 @@ class HighwayTools : Module() { return null } - private fun lookAtBlock(pos: BlockPos) { - val vec3d = Vec3d(pos).add(0.5, 0.0, 0.5) - val lookAt = RotationUtils.getRotationTo(vec3d, true) - mc.player.rotationYaw = lookAt.x.toFloat() - mc.player.rotationPitch = lookAt.y.toFloat() - } - private fun updateRenderer(renderer: ESPRenderer): ESPRenderer { val side = GeometryMasks.Quad.ALL for (blockTask in blockQueue) { @@ -529,15 +580,15 @@ class HighwayTools : Module() { var message = "" if (info.value) { message += "$chatName Module started." + - "\n §9> §7Direction: §a" + buildDirectionSaved.cardinalName + "§r" + "\n §9> §7Direction: §a${buildDirectionSaved.cardinalName}§r" message += if (buildDirectionSaved.isDiagonal) { - "\n §9> §7Coordinates: §a" + startingBlockPos.x + ", " + startingBlockPos.z + "§r" + "\n §9> §7Coordinates: §a${startingBlockPos.x} ${startingBlockPos.z}§r" } else { if (buildDirectionSaved == Cardinal.NEG_Z || buildDirectionSaved == Cardinal.POS_Z) { - "\n §9> §7Coordinate: §a" + startingBlockPos.z + "§r" + "\n §9> §7Coordinate: §a${startingBlockPos.x}§r" } else { - "\n §9> §7Coordinate: §a" + startingBlockPos.x + "§r" + "\n §9> §7Coordinate: §a${startingBlockPos.z}§r" } } } else { @@ -548,13 +599,13 @@ class HighwayTools : Module() { private fun printDisable() { var message = "" - message += if (info.value) { - "$chatName Module stopped." + - "\n §9> §7Placed blocks: §a" + totalBlocksPlaced + "§r" + - "\n §9> §7Destroyed blocks: §a" + totalBlocksDestroyed + "§r" + - "\n §9> §7Distance: §a" + totalBlocksDistance + "§r" + if (info.value) { + message += "$chatName Module stopped." + + "\n §9> §7Placed blocks: §a$totalBlocksPlaced§r" + + "\n §9> §7Destroyed blocks: §a$totalBlocksDestroyed§r" + if (baritoneMode.value) message += "\n §9> §7Distance: §a$totalBlocksDistance§r" } else { - "$chatName Module stopped." + message += "$chatName Module stopped." } MessageSendHelper.sendChatMessage(message) } @@ -619,8 +670,10 @@ class HighwayTools : Module() { var cursor = b cursor = cursor.down() - cursor = relativeDirection(cursor, 1, 0) - blockOffsets.add(Pair(cursor, true)) + if (baritoneMode.value) { + cursor = relativeDirection(cursor, 1, 0) + blockOffsets.add(Pair(cursor, true)) + } cursor = relativeDirection(cursor, 1, 0) var flip = false @@ -727,11 +780,11 @@ class HighwayTools : Module() { } private enum class Mode { - FLAT, HIGHWAY + HIGHWAY, FLAT } private enum class Page { - MAIN, BUILD + MAIN, BUILD, CONFIG } data class BlockTask(val blockPos: BlockPos, var taskState: TaskState, var block: Block, var priority: Int) diff --git a/src/main/java/me/zeroeightsix/kami/process/HighwayToolsProcess.kt b/src/main/java/me/zeroeightsix/kami/process/HighwayToolsProcess.kt index 4616748b13..2621e8050b 100644 --- a/src/main/java/me/zeroeightsix/kami/process/HighwayToolsProcess.kt +++ b/src/main/java/me/zeroeightsix/kami/process/HighwayToolsProcess.kt @@ -1,7 +1,5 @@ package me.zeroeightsix.kami.process -import baritone.api.BaritoneAPI -import baritone.api.IBaritone import baritone.api.pathing.goals.GoalNear import baritone.api.process.IBaritoneProcess import baritone.api.process.PathingCommand @@ -30,8 +28,10 @@ object HighwayToolsProcess : IBaritoneProcess { val highwayTools = ModuleManager.getModuleT(HighwayTools::class.java)!! val processName = if (highwayTools.blockQueue.size > 0 && !highwayTools.pathing) { "Block: " + highwayTools.blockQueue.peek().block.localizedName + " @ Position: (" + highwayTools.blockQueue.peek().blockPos.asString() + ") Priority: " + highwayTools.blockQueue.peek().priority + " State: " + highwayTools.blockQueue.peek().taskState.toString() - } else { + } else if (highwayTools.pathing) { "Moving to Position: (${highwayTools.getNextBlock().asString()})" + } else { + "Manual mode" } return "HighwayTools: $processName" } From 193e57d37ee852384836cf5416a2a927f22007f4 Mon Sep 17 00:00:00 2001 From: Christian Date: Thu, 17 Sep 2020 00:37:17 +0200 Subject: [PATCH 027/390] First AntiCheat fixes --- .../kami/module/modules/misc/HighwayTools.kt | 56 ++++++++++++++----- 1 file changed, 42 insertions(+), 14 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index d2a23d00a2..56a602a1db 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -65,8 +65,9 @@ object HighwayTools : Module() { val baritoneMode = register(Settings.booleanBuilder("Automatic").withValue(true).withVisibility { page.value == Page.MAIN }.build()) private val maxReach = register(Settings.doubleBuilder("Reach").withValue(4.4).withMinimum(1.0).withVisibility { page.value == Page.MAIN }.build()) private val noViewReset = register(Settings.booleanBuilder("NoViewReset").withValue(false).withVisibility { page.value == Page.MAIN }.build()) - private val spoofRotations = register(Settings.booleanBuilder("SpoofRotations").withValue(true).withVisibility { page.value == Page.MAIN }.build()) - private val spoofLookAt = register(Settings.booleanBuilder("SpoofLookAt").withValue(true).withVisibility { page.value == Page.MAIN }.build()) + //private val spoofRotations = register(Settings.booleanBuilder("SpoofRotations").withValue(true).withVisibility { page.value == Page.MAIN }.build()) + private val spoofing = register(Settings.enumBuilder(SpoofMode::class.java).withName("SpoofMode").withValue(SpoofMode.VIEWLOCK).withVisibility { page.value == Page.CONFIG }.build()) + //private val spoofLookAt = register(Settings.booleanBuilder("SpoofLookAt").withValue(true).withVisibility { page.value == Page.MAIN }.build()) // build settings val clearSpace = register(Settings.booleanBuilder("ClearSpace").withValue(true).withVisibility { page.value == Page.BUILD }.build()) @@ -275,6 +276,8 @@ object HighwayTools : Module() { when (blockAction.taskState) { TaskState.BREAK -> { + if (mc.world.rayTraceBlocks(mc.player.getPositionEyes(1f), Vec3d(blockAction.blockPos).add(0.5, 0.5, 0.5)) == null) return false + val block = mc.world.getBlockState(blockAction.blockPos).block for (b in ignoreBlocks) { @@ -329,7 +332,7 @@ object HighwayTools : Module() { doTask() } else -> { - mineBlock(blockAction.blockPos, true) + if(!mineBlock(blockAction.blockPos, true)) return false blockAction.taskState = TaskState.BREAKING } } @@ -363,6 +366,8 @@ object HighwayTools : Module() { } } TaskState.PLACE -> { + if (mc.world.rayTraceBlocks(mc.player.getPositionEyes(1f), Vec3d(blockAction.blockPos).add(0.5, 0.5, 0.5)) == null) return false + val block = mc.world.getBlockState(blockAction.blockPos).block if (blockAction.block is BlockAir && block !is BlockLiquid) { @@ -435,28 +440,38 @@ object HighwayTools : Module() { } } - private fun mineBlock(pos: BlockPos, pre: Boolean) { + private fun mineBlock(pos: BlockPos, pre: Boolean): Boolean { if (InventoryUtils.getSlotsHotbar(278) == null && InventoryUtils.getSlotsNoHotbar(278) != null) { InventoryUtils.moveToHotbar(278, 130) - return + return false } else if (InventoryUtils.getSlots(0, 35, 278) == null) { MessageSendHelper.sendChatMessage("$chatName No Pickaxe was found in inventory") mc.getSoundHandler().playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) disable() - return + return false } InventoryUtils.swapSlotToItem(278) - if (spoofLookAt.value) { - val lookAt = RotationUtils.getRotationTo(Vec3d(pos).add(0.5, 0.0, 0.5), true) - PlayerPacketManager.addPacket(this, PlayerPacketManager.PlayerPacket(rotating = true, rotation = Vec2f(lookAt.x.toFloat(), lookAt.y.toFloat()))) + + val rayTrace = mc.world.rayTraceBlocks(mc.player.getPositionEyes(1f), Vec3d(pos).add(0.5, 0.5, 0.5)) ?: return false + when (spoofing.value) { + SpoofMode.SPOOF -> { + val lookAt = RotationUtils.getRotationTo(Vec3d(pos).add(0.5, 0.5, 0.5).add(Vec3d(rayTrace.sideHit.directionVec).scale(0.5)), true) + PlayerPacketManager.addPacket(this, PlayerPacketManager.PlayerPacket(rotating = true, rotation = Vec2f(lookAt.x.toFloat(), lookAt.y.toFloat()))) + } + SpoofMode.VIEWLOCK -> { + val lookAt = RotationUtils.getRotationTo(Vec3d(pos).add(0.5, 0.5, 0.5).add(Vec3d(rayTrace.sideHit.directionVec).scale(0.5)), true) + mc.player.rotationYaw = lookAt.x.toFloat() + mc.player.rotationPitch = lookAt.y.toFloat() + } } if (pre) { - mc.connection!!.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, pos, mc.objectMouseOver.sideHit)) + mc.connection!!.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, pos, rayTrace.sideHit)) } else { - mc.connection!!.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, pos, mc.objectMouseOver.sideHit)) + mc.connection!!.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, pos, rayTrace.sideHit)) } mc.player.swingArm(EnumHand.MAIN_HAND) + return true } private fun placeBlock(pos: BlockPos, mat: Block): Boolean @@ -494,16 +509,25 @@ object HighwayTools : Module() { return false } InventoryUtils.swapSlotToItem(getIdFromBlock(mat)) + //val hitVec = Vec3d(neighbour).add(0.5, 0.5, 0.5).add(Vec3d(opposite.directionVec).scale(0.5)) val hitVec = Vec3d(neighbour).add(0.5, 0.5, 0.5).add(Vec3d(opposite.directionVec).scale(0.5)) val neighbourBlock = mc.world.getBlockState(neighbour).block if (!isSneaking && BlockUtils.blackList.contains(neighbourBlock) || BlockUtils.shulkerList.contains(neighbourBlock)) { mc.player.connection.sendPacket(CPacketEntityAction(mc.player, CPacketEntityAction.Action.START_SNEAKING)) isSneaking = true } - if (spoofRotations.value) { - BlockUtils.faceVectorPacketInstant(hitVec) + + when (spoofing.value) { + SpoofMode.SPOOF -> { + val lookAt = RotationUtils.getRotationTo(hitVec, true) + PlayerPacketManager.addPacket(this, PlayerPacketManager.PlayerPacket(rotating = true, rotation = Vec2f(lookAt.x.toFloat(), lookAt.y.toFloat()))) + } + SpoofMode.VIEWLOCK -> { + val lookAt = RotationUtils.getRotationTo(hitVec, true) + mc.player.rotationYaw = lookAt.x.toFloat() + mc.player.rotationPitch = lookAt.y.toFloat() + } } - //PlayerPacketManager.addPacket(this, PlayerPacketManager.PlayerPacket(rotating = true, rotation = Vec2f(mc.player.rotationYaw, mc.player.rotationPitch))) mc.playerController.processRightClickBlock(mc.player, mc.world, neighbour, opposite, hitVec, EnumHand.MAIN_HAND) mc.player.swingArm(EnumHand.MAIN_HAND) mc.rightClickDelayTimer = 4 @@ -783,6 +807,10 @@ object HighwayTools : Module() { HIGHWAY, FLAT } + private enum class SpoofMode { + NONE, SPOOF, VIEWLOCK + } + private enum class Page { MAIN, BUILD, CONFIG } From 903ccbfc782daf5a7d1f14846541daffb09c1fff Mon Sep 17 00:00:00 2001 From: Christian Date: Mon, 28 Sep 2020 04:52:03 +0200 Subject: [PATCH 028/390] All kind of stuff - Updated to new master - Liquid handling fixes - Anti anti cheat revert (Needs more time first) - Updated deprecated snippets --- .../command/commands/HighwayToolsCommand.kt | 15 +- .../kami/module/modules/misc/HighwayTools.kt | 344 ++++++++---------- .../kami/process/HighwayToolsProcess.kt | 19 +- 3 files changed, 170 insertions(+), 208 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/command/commands/HighwayToolsCommand.kt b/src/main/java/me/zeroeightsix/kami/command/commands/HighwayToolsCommand.kt index a798b950d0..ce124fa7ca 100644 --- a/src/main/java/me/zeroeightsix/kami/command/commands/HighwayToolsCommand.kt +++ b/src/main/java/me/zeroeightsix/kami/command/commands/HighwayToolsCommand.kt @@ -3,7 +3,6 @@ package me.zeroeightsix.kami.command.commands import me.zeroeightsix.kami.command.Command import me.zeroeightsix.kami.command.syntax.ChunkBuilder import me.zeroeightsix.kami.command.syntax.parsers.EnumParser -import me.zeroeightsix.kami.module.ModuleManager import me.zeroeightsix.kami.module.modules.misc.HighwayTools import me.zeroeightsix.kami.util.text.MessageSendHelper import net.minecraft.block.Block @@ -19,16 +18,16 @@ class HighwayToolsCommand : Command("highwaytools", ChunkBuilder() override fun call(args: Array) { val subCommand = getSubCommand(args) - val ht = ModuleManager.getModuleT(HighwayTools::class.java) + val ht = HighwayTools when (subCommand) { SubCommands.SETTINGS -> { - ht!!.printSettings() + ht.printSettings() } SubCommands.MATERIAL -> { try { val block = Block.getBlockFromName(args[1].toString())!! - ht!!.material = block + ht.material = block MessageSendHelper.sendChatMessage("Set your building material to &7${block.localizedName}&r.") } catch (e: Exception) { MessageSendHelper.sendChatMessage("&7${args[1]}&r is not a valid block.") @@ -38,7 +37,7 @@ class HighwayToolsCommand : Command("highwaytools", ChunkBuilder() SubCommands.FILLER -> { try { val block = Block.getBlockFromName(args[1].toString())!! - ht!!.fillerMat = block + ht.fillerMat = block MessageSendHelper.sendChatMessage("Set your filling material to &7${block.localizedName}&r.") } catch (e: Exception) { MessageSendHelper.sendChatMessage("&7${args[1]}&r is not a valid block.") @@ -48,7 +47,7 @@ class HighwayToolsCommand : Command("highwaytools", ChunkBuilder() SubCommands.IGNORE_ADD -> { try { val block = Block.getBlockFromName(args[2].toString())!! - if (block !in ht!!.ignoreBlocks) { + if (block !in ht.ignoreBlocks) { ht.ignoreBlocks.add(block) ht.printSettings() MessageSendHelper.sendChatMessage("Added &7${block.localizedName}&r to ignore list.") @@ -63,7 +62,7 @@ class HighwayToolsCommand : Command("highwaytools", ChunkBuilder() SubCommands.IGNORE_DEL -> { try { val block = Block.getBlockFromName(args[2].toString())!! - if (block !in ht!!.ignoreBlocks) { + if (block !in ht.ignoreBlocks) { ht.ignoreBlocks.remove(block) ht.printSettings() MessageSendHelper.sendChatMessage("Removed &7${block.localizedName}&r from ignore list.") @@ -88,6 +87,8 @@ class HighwayToolsCommand : Command("highwaytools", ChunkBuilder() args[1].isNullOrBlank() -> SubCommands.NULL + args[0].equals("settings", ignoreCase = true) -> SubCommands.SETTINGS + args[0].equals("material", ignoreCase = true) -> SubCommands.MATERIAL args[0].equals("filler", ignoreCase = true) -> SubCommands.FILLER diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 56a602a1db..ba540e52d7 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -4,7 +4,6 @@ import baritone.api.BaritoneAPI import me.zeroeightsix.kami.event.events.RenderEvent import me.zeroeightsix.kami.manager.mangers.PlayerPacketManager import me.zeroeightsix.kami.module.Module -import me.zeroeightsix.kami.module.ModuleManager import me.zeroeightsix.kami.module.modules.player.LagNotifier import me.zeroeightsix.kami.module.modules.player.NoBreakAnimation import me.zeroeightsix.kami.process.HighwayToolsProcess @@ -23,9 +22,7 @@ import me.zeroeightsix.kami.util.math.Vec2f import me.zeroeightsix.kami.util.math.VectorUtils import me.zeroeightsix.kami.util.text.MessageSendHelper import net.minecraft.block.Block -import net.minecraft.block.Block.getBlockById import net.minecraft.block.Block.getIdFromBlock -import net.minecraft.block.BlockAir import net.minecraft.block.BlockLiquid import net.minecraft.client.audio.PositionedSoundRecord import net.minecraft.entity.item.EntityItem @@ -62,12 +59,9 @@ object HighwayTools : Module() { private val blocksPerTick = register(Settings.integerBuilder("BlocksPerTick").withMinimum(1).withValue(1).withMaximum(10).withVisibility { page.value == Page.MAIN }.build()) private val tickDelayPlace = register(Settings.integerBuilder("TickDelayPlace").withMinimum(0).withValue(0).withMaximum(15).withVisibility { page.value == Page.MAIN }.build()) private val tickDelayBreak = register(Settings.integerBuilder("TickDelayBreak").withMinimum(0).withValue(0).withMaximum(15).withVisibility { page.value == Page.MAIN }.build()) - val baritoneMode = register(Settings.booleanBuilder("Automatic").withValue(true).withVisibility { page.value == Page.MAIN }.build()) + val baritoneMode = register(Settings.booleanBuilder("Baritone").withValue(true).withVisibility { page.value == Page.MAIN }.build()) private val maxReach = register(Settings.doubleBuilder("Reach").withValue(4.4).withMinimum(1.0).withVisibility { page.value == Page.MAIN }.build()) - private val noViewReset = register(Settings.booleanBuilder("NoViewReset").withValue(false).withVisibility { page.value == Page.MAIN }.build()) - //private val spoofRotations = register(Settings.booleanBuilder("SpoofRotations").withValue(true).withVisibility { page.value == Page.MAIN }.build()) - private val spoofing = register(Settings.enumBuilder(SpoofMode::class.java).withName("SpoofMode").withValue(SpoofMode.VIEWLOCK).withVisibility { page.value == Page.CONFIG }.build()) - //private val spoofLookAt = register(Settings.booleanBuilder("SpoofLookAt").withValue(true).withVisibility { page.value == Page.MAIN }.build()) + private val interacting = register(Settings.enumBuilder(InteractMode::class.java).withName("InteractMode").withValue(InteractMode.SPOOF).withVisibility { page.value == Page.MAIN }.build()) // build settings val clearSpace = register(Settings.booleanBuilder("ClearSpace").withValue(true).withVisibility { page.value == Page.BUILD }.build()) @@ -76,6 +70,7 @@ object HighwayTools : Module() { private val rims = register(Settings.booleanBuilder("Rims").withValue(true).withVisibility { page.value == Page.BUILD }.build()) private var rimHeight = register(Settings.integerBuilder("RimHeight").withMinimum(1).withValue(1).withMaximum(clearHeight.value).withVisibility { rims.value && page.value == Page.BUILD }.build()) private val cornerBlock = register(Settings.booleanBuilder("CornerBlock").withValue(true).withVisibility { page.value == Page.BUILD }.build()) + private val fillCorner = register(Settings.booleanBuilder("FillCorner").withValue(true).withVisibility { page.value == Page.BUILD && !cornerBlock.value }.build()) // config settings private val info = register(Settings.booleanBuilder("ShowInfo").withValue(true).withVisibility { page.value == Page.CONFIG }.build()) @@ -84,8 +79,8 @@ object HighwayTools : Module() { private val goalRender = register(Settings.booleanBuilder("GoalRender").withValue(false).withVisibility { page.value == Page.CONFIG }.build()) private val filled = register(Settings.booleanBuilder("Filled").withValue(true).withVisibility { page.value == Page.CONFIG }.build()) private val outline = register(Settings.booleanBuilder("Outline").withValue(true).withVisibility { page.value == Page.CONFIG }.build()) - private val aFilled = register(Settings.integerBuilder("FilledAlpha").withMinimum(0).withValue(31).withMaximum(255).withVisibility { filled.value && page.value == Page.CONFIG }.build()) - private val aOutline = register(Settings.integerBuilder("OutlineAlpha").withMinimum(0).withValue(127).withMaximum(255).withVisibility { outline.value && page.value == Page.CONFIG }.build()) + private val aFilled = register(Settings.integerBuilder("FilledAlpha").withMinimum(0).withValue(26).withMaximum(255).withVisibility { filled.value && page.value == Page.CONFIG }.build()) + private val aOutline = register(Settings.integerBuilder("OutlineAlpha").withMinimum(0).withValue(91).withMaximum(255).withVisibility { outline.value && page.value == Page.CONFIG }.build()) // other settings var ignoreBlocks = mutableListOf(Blocks.STANDING_SIGN, Blocks.WALL_SIGN, Blocks.STANDING_BANNER, Blocks.WALL_BANNER, Blocks.BEDROCK, Blocks.PORTAL) @@ -98,7 +93,7 @@ object HighwayTools : Module() { private var baritoneSettingRenderGoal = false // runtime vars - private val compareByPriority: Comparator = compareBy { it.priority } + private val compareByPriority: Comparator = compareBy { it.taskState.ordinal } var blockQueue: PriorityQueue = PriorityQueue(compareByPriority) private val doneQueue: Queue = LinkedList() private var blockOffsets = mutableListOf>() @@ -115,10 +110,6 @@ object HighwayTools : Module() { private var totalBlocksDestroyed = 0 private var totalBlocksDistance = 0 - private enum class DebugMessages { - NONE, IMPORTANT, ALL - } - fun isDone(): Boolean { return blockQueue.size == 0 } @@ -185,16 +176,16 @@ object HighwayTools : Module() { pathing = BaritoneAPI.getProvider().primaryBaritone.pathingBehavior.isPathing if (!isDone()) { if (!doTask()) { - if (!pathing && !ModuleManager.getModuleT(LagNotifier::class.java)!!.paused && !ModuleManager.getModuleT(AutoObsidian::class.java)!!.active) { + if (!pathing && !LagNotifier.paused && !AutoObsidian.active) { stuckDetector += 1 var tmpQueue: Queue = LinkedList(blockQueue) tmpQueue = LinkedList(tmpQueue.shuffled()) blockQueue.clear() blockQueue.addAll(tmpQueue) if (debugMessages.value == DebugMessages.ALL) { - MessageSendHelper.sendChatMessage("$chatName Shuffled tasks") + MessageSendHelper.sendChatMessage("$chatName Shuffled tasks (x$stuckDetector)") } - if (stuckDetector > 20) { + if (stuckDetector > blockOffsets.size) { refreshData() if (debugMessages.value == DebugMessages.IMPORTANT) { MessageSendHelper.sendChatMessage("$chatName You got stuck, retry") @@ -212,7 +203,6 @@ object HighwayTools : Module() { totalBlocksDistance++ doneQueue.clear() updateTasks() - if (!noViewReset.value) lookInWalkDirection() } else { doneQueue.clear() updateTasks() @@ -232,18 +222,30 @@ object HighwayTools : Module() { refreshData() } } + } - if (printDebug.value) { - printDebug() - } + private fun addTask(blockPos: BlockPos, taskState: TaskState, material: Block) { + blockQueue.add(BlockTask(blockPos, taskState, material)) } - private fun addTask(blockPos: BlockPos, taskState: TaskState, material: Block, priority: Int) { - blockQueue.add(BlockTask(blockPos, taskState, material, priority)) + private fun addTask(blockPos: BlockPos, material: Block) { + doneQueue.add(BlockTask(blockPos, TaskState.DONE, material)) } - private fun addDoneTask(blockPos: BlockPos, material: Block) { - doneQueue.add(BlockTask(blockPos, TaskState.DONE, material, 1)) + private fun updateTask(blockTask: BlockTask, taskState: TaskState) { + blockQueue.poll() + blockTask.taskState = taskState + if (taskState == TaskState.DONE) { + doneQueue.add(blockTask) + } else { + blockQueue.add(blockTask) + } + } + + private fun updateTask(blockTask: BlockTask, material: Block) { + blockQueue.poll() + blockTask.block = material + doneQueue.add(blockTask) } private fun checkTasks(): Boolean { @@ -251,16 +253,16 @@ object HighwayTools : Module() { val block = mc.world.getBlockState(blockTask.blockPos).block var cont = false for (b in ignoreBlocks) { - if (b!!::class == block::class) { + if (b == block) { cont = true } } if (cont) { continue } - if (blockTask.block::class == material::class && block is BlockAir) { + if (blockTask.block == material && block == Blocks.AIR) { return false - } else if (blockTask.block::class == BlockAir::class && block !is BlockAir) { + } else if (blockTask.block == Blocks.AIR && block != Blocks.AIR) { return false } } @@ -268,115 +270,129 @@ object HighwayTools : Module() { } private fun doTask(): Boolean { - if (!isDone() && !pathing && !ModuleManager.getModuleT(LagNotifier::class.java)!!.paused && !ModuleManager.getModuleT(AutoObsidian::class.java)!!.active) { + if (!isDone() && !pathing && !LagNotifier.paused && !AutoObsidian.active) { BaritoneAPI.getProvider().primaryBaritone.pathingControlManager.registerProcess(HighwayToolsProcess) if (waitTicks == 0) { - val blockAction = blockQueue.peek() + if (printDebug.value) printDebug() - when (blockAction.taskState) { - TaskState.BREAK -> { - if (mc.world.rayTraceBlocks(mc.player.getPositionEyes(1f), Vec3d(blockAction.blockPos).add(0.5, 0.5, 0.5)) == null) return false + val blockTask = blockQueue.peek() + + when (blockTask.taskState) { + TaskState.DONE -> { + blockQueue.poll() + doneQueue.add(blockTask) + doTask() + } + TaskState.BREAKING -> { + mineBlock(blockTask.blockPos, false) + + val block = mc.world.getBlockState(blockTask.blockPos).block + if (block == Blocks.AIR) { + totalBlocksDestroyed++ + waitTicks = tickDelayBreak.value + + if (blockTask.block == material) { + updateTask(blockTask, TaskState.PLACE) + } else { + updateTask(blockTask, TaskState.DONE) + } + } + } + TaskState.PLACED -> { + if (blockTask.block == material) { + val block = mc.world.getBlockState(blockTask.blockPos).block - val block = mc.world.getBlockState(blockAction.blockPos).block + if (block != Blocks.AIR) { + updateTask(blockTask, TaskState.DONE) + } else { + updateTask(blockTask, TaskState.PLACE) + } + } else { + updateTask(blockTask, TaskState.BREAK) + } + doTask() + } + TaskState.BREAK -> { + val block = mc.world.getBlockState(blockTask.blockPos).block + // ignore blocks for (b in ignoreBlocks) { if (block::class == b!!::class) { - blockQueue.poll() - blockAction.taskState = TaskState.DONE - blockAction.priority = 1 - doneQueue.add(blockAction) + updateTask(blockTask, TaskState.DONE) doTask() } } + // liquid search around the breaking block for (side in EnumFacing.values()) { - val neighbour = blockAction.blockPos.offset(side) - var found = false + val neighbour = blockTask.blockPos.offset(side) + if (!BlockUtils.hasNeighbour(neighbour) && sqrt(mc.player.getDistanceSqToCenter(neighbour)) > maxReach.value) continue if (mc.world.getBlockState(neighbour).block is BlockLiquid) { - + var found = false for (bt in blockQueue) { if (bt.blockPos == neighbour) { + MessageSendHelper.sendChatMessage("Found") + updateTask(bt, TaskState.LIQUID_SOURCE) + updateTask(bt, fillerMat) found = true } } - - if (!found && BlockUtils.hasNeighbour(neighbour) && sqrt(mc.player.getDistanceSqToCenter(neighbour)) < maxReach.value) addTask(neighbour, TaskState.PLACE, fillerMat, 2) + if (!found) { + MessageSendHelper.sendChatMessage("Not Found: " + neighbour.asString()) + addTask(neighbour, TaskState.LIQUID_SOURCE, fillerMat) + } + return false } } + // last check before breaking when (block) { - is BlockAir -> { - blockAction.taskState = TaskState.BROKE + Blocks.AIR -> { + updateTask(blockTask, TaskState.DONE) doTask() } is BlockLiquid -> { var insideBuild = false for ((pos, build) in blockOffsets) { - if (blockAction.blockPos == pos && build) { + if (blockTask.blockPos == pos && build) { insideBuild = true } } - blockQueue.poll() - blockAction.taskState = TaskState.PLACE - blockAction.priority = 2 + when (block) { + Blocks.LAVA -> { + updateTask(blockTask, TaskState.LIQUID_SOURCE) + } + Blocks.FLOWING_LAVA -> { + updateTask(blockTask, TaskState.LIQUID_FLOW) + } + } if (insideBuild) { - blockAction.block = Blocks.OBSIDIAN + updateTask(blockTask, Blocks.OBSIDIAN) } else { - blockAction.block = Blocks.NETHERRACK + updateTask(blockTask, Blocks.NETHERRACK) } - blockQueue.add(blockAction) doTask() } else -> { - if(!mineBlock(blockAction.blockPos, true)) return false - blockAction.taskState = TaskState.BREAKING - } - } - } - TaskState.BREAKING -> { - mineBlock(blockAction.blockPos, false) - blockAction.taskState = TaskState.BROKE - } - TaskState.BROKE -> { - val block = mc.world.getBlockState(blockAction.blockPos).block - - if (block is BlockAir) { - totalBlocksDestroyed++ - waitTicks = tickDelayBreak.value - - if (blockAction.block::class == material::class) { - blockQueue.poll() - blockAction.taskState = TaskState.PLACE - blockAction.priority = 4 - blockQueue.add(blockAction) - } else { - blockQueue.poll() - blockAction.taskState = TaskState.DONE - blockAction.priority = 1 - doneQueue.add(blockAction) + mineBlock(blockTask.blockPos, true) + updateTask(blockTask, TaskState.BREAKING) } - - doTask() - } else { - blockAction.taskState = TaskState.BREAK } } - TaskState.PLACE -> { - if (mc.world.rayTraceBlocks(mc.player.getPositionEyes(1f), Vec3d(blockAction.blockPos).add(0.5, 0.5, 0.5)) == null) return false + TaskState.PLACE, TaskState.LIQUID_SOURCE, TaskState.LIQUID_FLOW -> { + val block = mc.world.getBlockState(blockTask.blockPos).block - val block = mc.world.getBlockState(blockAction.blockPos).block - - if (blockAction.block is BlockAir && block !is BlockLiquid) { + if (blockTask.block == Blocks.AIR && block !is BlockLiquid) { blockQueue.poll() return true } - if (placeBlock(blockAction.blockPos, blockAction.block)) { - blockAction.taskState = TaskState.PLACED + if (placeBlock(blockTask.blockPos, blockTask.block)) { + updateTask(blockTask, TaskState.PLACED) if (blocksPerTick.value > blocksPlaced + 1) { blocksPlaced++ doTask() @@ -390,31 +406,6 @@ object HighwayTools : Module() { return false } } - TaskState.PLACED -> { - if (blockAction.block::class == material::class) { - val block = mc.world.getBlockState(blockAction.blockPos).block - - if (block !is BlockAir) { - blockQueue.poll() - blockAction.taskState = TaskState.DONE - blockAction.priority = 1 - doneQueue.add(blockAction) - } else { - blockAction.taskState = TaskState.PLACE - } - } else { - blockQueue.poll() - blockAction.taskState = TaskState.BREAK - blockAction.priority = 3 - blockQueue.add(blockAction) - } - doTask() - } - TaskState.DONE -> { - blockQueue.poll() - doneQueue.add(blockAction) - doTask() - } } } else { waitTicks-- @@ -430,55 +421,54 @@ object HighwayTools : Module() { for ((a, b) in blockOffsets) { val block = mc.world.getBlockState(a).block when { - (!b && block in ignoreBlocks) -> addDoneTask(a, getBlockById(0)) - (b && block::class == material::class) -> addDoneTask(a, material) - (!b && block is BlockAir) -> addDoneTask(a, getBlockById(0)) - (b && block !is BlockAir && block::class != material::class) -> addTask(a, TaskState.BREAK, material, 3) - (!b && block !is BlockAir) -> addTask(a, TaskState.BREAK, getBlockById(0), 3) - (b && block is BlockAir) -> addTask(a, TaskState.PLACE, material, 4) + (block == Blocks.LAVA || block == Blocks.WATER) -> addTask(a, TaskState.LIQUID_SOURCE, fillerMat) + (block == Blocks.FLOWING_LAVA || block == Blocks.FLOWING_WATER) -> addTask(a, TaskState.LIQUID_FLOW, fillerMat) + (!b && block in ignoreBlocks) -> addTask(a, Blocks.AIR) + (b && block == material) -> addTask(a, material) + (!b && block == Blocks.AIR) -> addTask(a, Blocks.AIR) + (b && block != Blocks.AIR && block != material) -> addTask(a, TaskState.BREAK, material) + (!b && block != Blocks.AIR) -> addTask(a, TaskState.BREAK, Blocks.AIR) + (b && block == Blocks.AIR) -> addTask(a, TaskState.PLACE, material) } } } - private fun mineBlock(pos: BlockPos, pre: Boolean): Boolean { + private fun mineBlock(pos: BlockPos, pre: Boolean) { if (InventoryUtils.getSlotsHotbar(278) == null && InventoryUtils.getSlotsNoHotbar(278) != null) { InventoryUtils.moveToHotbar(278, 130) - return false + return } else if (InventoryUtils.getSlots(0, 35, 278) == null) { MessageSendHelper.sendChatMessage("$chatName No Pickaxe was found in inventory") mc.getSoundHandler().playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) disable() - return false + return } InventoryUtils.swapSlotToItem(278) - - val rayTrace = mc.world.rayTraceBlocks(mc.player.getPositionEyes(1f), Vec3d(pos).add(0.5, 0.5, 0.5)) ?: return false - when (spoofing.value) { - SpoofMode.SPOOF -> { - val lookAt = RotationUtils.getRotationTo(Vec3d(pos).add(0.5, 0.5, 0.5).add(Vec3d(rayTrace.sideHit.directionVec).scale(0.5)), true) + when (interacting.value) { + InteractMode.SPOOF -> { + val lookAt = RotationUtils.getRotationTo(Vec3d(pos).add(0.5, 0.0, 0.5), true) PlayerPacketManager.addPacket(this, PlayerPacketManager.PlayerPacket(rotating = true, rotation = Vec2f(lookAt.x.toFloat(), lookAt.y.toFloat()))) } - SpoofMode.VIEWLOCK -> { - val lookAt = RotationUtils.getRotationTo(Vec3d(pos).add(0.5, 0.5, 0.5).add(Vec3d(rayTrace.sideHit.directionVec).scale(0.5)), true) + InteractMode.VIEWLOCK -> { + val lookAt = RotationUtils.getRotationTo(Vec3d(pos).add(0.5, 0.5, 0.5), true) mc.player.rotationYaw = lookAt.x.toFloat() mc.player.rotationPitch = lookAt.y.toFloat() } } if (pre) { - mc.connection!!.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, pos, rayTrace.sideHit)) + mc.connection!!.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, pos, mc.objectMouseOver.sideHit)) } else { - mc.connection!!.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, pos, rayTrace.sideHit)) + mc.connection!!.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, pos, mc.objectMouseOver.sideHit)) } mc.player.swingArm(EnumHand.MAIN_HAND) - return true } private fun placeBlock(pos: BlockPos, mat: Block): Boolean { // check if block is already placed val block = mc.world.getBlockState(pos).block - if (block !is BlockAir && block !is BlockLiquid) { + if (block != Blocks.AIR && block !is BlockLiquid) { return false } // check if entity blocks placing @@ -495,13 +485,13 @@ object HighwayTools : Module() { if (!BlockUtils.canBeClicked(neighbour)) { return false } - //Swap to material in Hotbar or get from inventory + // swap to material in Hotbar or get from inventory if (InventoryUtils.getSlotsHotbar(getIdFromBlock(mat)) == null && InventoryUtils.getSlotsNoHotbar(getIdFromBlock(mat)) != null) { - //InventoryUtils.moveToHotbar(getIdFromBlock(mat), 130, (tickDelay.value * 16).toLong()) + // InventoryUtils.moveToHotbar(getIdFromBlock(mat), 130, (tickDelay.value * 16).toLong()) for (x in InventoryUtils.getSlotsNoHotbar(getIdFromBlock(mat))!!) { InventoryUtils.quickMoveSlot(x) } - //InventoryUtils.quickMoveSlot(1, (tickDelay.value * 16).toLong()) + // InventoryUtils.quickMoveSlot(1, (tickDelay.value * 16).toLong()) } else if (InventoryUtils.getSlots(0, 35, getIdFromBlock(mat)) == null) { MessageSendHelper.sendChatMessage("$chatName No ${mat.localizedName} was found in inventory") mc.getSoundHandler().playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) @@ -509,7 +499,6 @@ object HighwayTools : Module() { return false } InventoryUtils.swapSlotToItem(getIdFromBlock(mat)) - //val hitVec = Vec3d(neighbour).add(0.5, 0.5, 0.5).add(Vec3d(opposite.directionVec).scale(0.5)) val hitVec = Vec3d(neighbour).add(0.5, 0.5, 0.5).add(Vec3d(opposite.directionVec).scale(0.5)) val neighbourBlock = mc.world.getBlockState(neighbour).block if (!isSneaking && BlockUtils.blackList.contains(neighbourBlock) || BlockUtils.shulkerList.contains(neighbourBlock)) { @@ -517,12 +506,12 @@ object HighwayTools : Module() { isSneaking = true } - when (spoofing.value) { - SpoofMode.SPOOF -> { + when (interacting.value) { + InteractMode.SPOOF -> { val lookAt = RotationUtils.getRotationTo(hitVec, true) PlayerPacketManager.addPacket(this, PlayerPacketManager.PlayerPacket(rotating = true, rotation = Vec2f(lookAt.x.toFloat(), lookAt.y.toFloat()))) } - SpoofMode.VIEWLOCK -> { + InteractMode.VIEWLOCK -> { val lookAt = RotationUtils.getRotationTo(hitVec, true) mc.player.rotationYaw = lookAt.x.toFloat() mc.player.rotationPitch = lookAt.y.toFloat() @@ -531,23 +520,16 @@ object HighwayTools : Module() { mc.playerController.processRightClickBlock(mc.player, mc.world, neighbour, opposite, hitVec, EnumHand.MAIN_HAND) mc.player.swingArm(EnumHand.MAIN_HAND) mc.rightClickDelayTimer = 4 - val noBreakAnimation = ModuleManager.getModuleT(NoBreakAnimation::class.java)!! - if (noBreakAnimation.isEnabled) { - noBreakAnimation.resetMining() - } + if (NoBreakAnimation.isEnabled) NoBreakAnimation.resetMining() return true } private fun getPlaceableSide(pos: BlockPos): EnumFacing? { for (side in EnumFacing.values()) { val neighbour = pos.offset(side) - if (!mc.world.getBlockState(neighbour).block.canCollideCheck(mc.world.getBlockState(neighbour), false)) { - continue - } + if (!mc.world.getBlockState(neighbour).block.canCollideCheck(mc.world.getBlockState(neighbour), false)) continue val blockState = mc.world.getBlockState(neighbour) - if (!blockState.material.isReplaceable) { - return side - } + if (!blockState.material.isReplaceable) return side } return null } @@ -555,14 +537,10 @@ object HighwayTools : Module() { private fun updateRenderer(renderer: ESPRenderer): ESPRenderer { val side = GeometryMasks.Quad.ALL for (blockTask in blockQueue) { - if (blockTask.taskState != TaskState.DONE) { - renderer.add(blockTask.blockPos, blockTask.taskState.color, side) - } + if (blockTask.taskState != TaskState.DONE) renderer.add(blockTask.blockPos, blockTask.taskState.color, side) } for (blockTask in doneQueue) { - if (blockTask.block::class != BlockAir::class) { - renderer.add(blockTask.blockPos, blockTask.taskState.color, side) - } + if (blockTask.block != Blocks.AIR) renderer.add(blockTask.blockPos, blockTask.taskState.color, side) } return renderer } @@ -579,13 +557,9 @@ object HighwayTools : Module() { private fun printDebug() { var message = "\n\n" message += "-------------------- QUEUE -------------------" - for (blockTask in blockQueue) { - message += "\n" + blockTask.block.localizedName + "@(" + blockTask.blockPos.asString() + ") Priority: " + blockTask.priority + " State: " + blockTask.taskState.toString() - } + for (blockTask in blockQueue) message += "\n" + blockTask.block.localizedName + "@(" + blockTask.blockPos.asString() + ") Priority: " + blockTask.taskState.ordinal + " State: " + blockTask.taskState.toString() message += "\n-------------------- DONE --------------------" - for (blockTask in doneQueue) { - message += "\n" + blockTask.block.localizedName + "@(" + blockTask.blockPos.asString() + ") Priority: " + blockTask.priority + " State: " + blockTask.taskState.toString() - } + for (blockTask in doneQueue) message += "\n" + blockTask.block.localizedName + "@(" + blockTask.blockPos.asString() + ") Priority: " + blockTask.taskState.ordinal + " State: " + blockTask.taskState.toString() MessageSendHelper.sendChatMessage(message) } @@ -594,9 +568,7 @@ object HighwayTools : Module() { "\n §9> §rMaterial: §7${material.localizedName}" + "\n §9> §rBaritone: §7${baritoneMode.value}" + "\n §9> §rIgnored Blocks:" - for (b in ignoreBlocks) { - message += "\n §9> §7${b!!.registryName}" - } + for (b in ignoreBlocks) message += "\n §9> §7${b!!.registryName}" MessageSendHelper.sendChatMessage(message) } @@ -647,21 +619,6 @@ object HighwayTools : Module() { } } - private fun lookInWalkDirection() { - // set head rotation to get max walking speed - when (buildDirectionSaved) { - Cardinal.NEG_Z -> mc.player.rotationYaw = -180F - Cardinal.POS_X_NEG_Z -> mc.player.rotationYaw = -135F - Cardinal.POS_X -> mc.player.rotationYaw = -90F - Cardinal.POS_X_POS_Z -> mc.player.rotationYaw = -45F - Cardinal.POS_Z -> mc.player.rotationYaw = 0F - Cardinal.NEG_X_POS_Z -> mc.player.rotationYaw = 45F - Cardinal.NEG_X -> mc.player.rotationYaw = 90F - else -> mc.player.rotationYaw = 135F - } - mc.player.rotationPitch = 0F - } - private fun relativeDirection(curs: BlockPos, steps: Int, turn: Int): BlockPos { var c = curs var d = (buildDirectionSaved.ordinal + turn).rem(8) @@ -803,27 +760,32 @@ object HighwayTools : Module() { } } - private enum class Mode { - HIGHWAY, FLAT + private enum class DebugMessages { + NONE, IMPORTANT, ALL } - private enum class SpoofMode { - NONE, SPOOF, VIEWLOCK + private enum class Mode { + HIGHWAY, FLAT } private enum class Page { MAIN, BUILD, CONFIG } - data class BlockTask(val blockPos: BlockPos, var taskState: TaskState, var block: Block, var priority: Int) + private enum class InteractMode { + NONE, SPOOF, VIEWLOCK + } + + data class BlockTask(val blockPos: BlockPos, var taskState: TaskState, var block: Block) enum class TaskState(val color: ColorHolder) { - BREAK(ColorHolder(222, 0, 0)), + DONE(ColorHolder(50, 50, 50)), BREAKING(ColorHolder(240, 222, 60)), - BROKE(ColorHolder(240, 77, 60)), - PLACE(ColorHolder(35, 188, 254)), PLACED(ColorHolder(53, 222, 66)), - DONE(ColorHolder(50, 50, 50)) + LIQUID_SOURCE(ColorHolder(120, 41, 240)), + LIQUID_FLOW(ColorHolder(120, 41, 240)), + BREAK(ColorHolder(222, 0, 0)), + PLACE(ColorHolder(35, 188, 254)) } } diff --git a/src/main/java/me/zeroeightsix/kami/process/HighwayToolsProcess.kt b/src/main/java/me/zeroeightsix/kami/process/HighwayToolsProcess.kt index 2621e8050b..24896e13e5 100644 --- a/src/main/java/me/zeroeightsix/kami/process/HighwayToolsProcess.kt +++ b/src/main/java/me/zeroeightsix/kami/process/HighwayToolsProcess.kt @@ -4,7 +4,6 @@ import baritone.api.pathing.goals.GoalNear import baritone.api.process.IBaritoneProcess import baritone.api.process.PathingCommand import baritone.api.process.PathingCommandType -import me.zeroeightsix.kami.module.ModuleManager import me.zeroeightsix.kami.module.modules.misc.HighwayTools import me.zeroeightsix.kami.util.math.CoordinateConverter.asString @@ -25,11 +24,11 @@ object HighwayToolsProcess : IBaritoneProcess { override fun onLostControl() {} override fun displayName0(): String { - val highwayTools = ModuleManager.getModuleT(HighwayTools::class.java)!! - val processName = if (highwayTools.blockQueue.size > 0 && !highwayTools.pathing) { - "Block: " + highwayTools.blockQueue.peek().block.localizedName + " @ Position: (" + highwayTools.blockQueue.peek().blockPos.asString() + ") Priority: " + highwayTools.blockQueue.peek().priority + " State: " + highwayTools.blockQueue.peek().taskState.toString() - } else if (highwayTools.pathing) { - "Moving to Position: (${highwayTools.getNextBlock().asString()})" + val ht = HighwayTools + val processName = if (ht.blockQueue.size > 0 && !ht.pathing) { + "Block: " + ht.blockQueue.peek().block.localizedName + " @ Position: (" + ht.blockQueue.peek().blockPos.asString() + ") Priority: " + ht.blockQueue.peek().taskState.ordinal + " State: " + ht.blockQueue.peek().taskState.toString() + } else if (ht.pathing) { + "Moving to Position: (${ht.getNextBlock().asString()})" } else { "Manual mode" } @@ -37,13 +36,13 @@ object HighwayToolsProcess : IBaritoneProcess { } override fun isActive(): Boolean { - return (ModuleManager.isModuleEnabled(HighwayTools::class.java)) + return (HighwayTools.isEnabled) } override fun onTick(p0: Boolean, p1: Boolean): PathingCommand? { - val highwayTools = ModuleManager.getModuleT(HighwayTools::class.java)!! - return if (highwayTools.baritoneMode.value) { - PathingCommand(GoalNear(highwayTools.getNextBlock(), 0), PathingCommandType.SET_GOAL_AND_PATH) + val ht = HighwayTools + return if (ht.baritoneMode.value) { + PathingCommand(GoalNear(ht.getNextBlock(), 0), PathingCommandType.SET_GOAL_AND_PATH) } else PathingCommand(null, PathingCommandType.REQUEST_PAUSE) } } \ No newline at end of file From 8cc400db3fc3624d654067e4f5298a019e76232f Mon Sep 17 00:00:00 2001 From: Christian Date: Mon, 28 Sep 2020 06:27:44 +0200 Subject: [PATCH 029/390] Some suggestions --- .../kami/module/modules/misc/HighwayTools.kt | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index ba540e52d7..3590cd4e92 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -59,8 +59,8 @@ object HighwayTools : Module() { private val blocksPerTick = register(Settings.integerBuilder("BlocksPerTick").withMinimum(1).withValue(1).withMaximum(10).withVisibility { page.value == Page.MAIN }.build()) private val tickDelayPlace = register(Settings.integerBuilder("TickDelayPlace").withMinimum(0).withValue(0).withMaximum(15).withVisibility { page.value == Page.MAIN }.build()) private val tickDelayBreak = register(Settings.integerBuilder("TickDelayBreak").withMinimum(0).withValue(0).withMaximum(15).withVisibility { page.value == Page.MAIN }.build()) - val baritoneMode = register(Settings.booleanBuilder("Baritone").withValue(true).withVisibility { page.value == Page.MAIN }.build()) - private val maxReach = register(Settings.doubleBuilder("Reach").withValue(4.4).withMinimum(1.0).withVisibility { page.value == Page.MAIN }.build()) + val baritoneMode = register(Settings.booleanBuilder("AutoMode").withValue(true).withVisibility { page.value == Page.MAIN }.build()) + private val maxReach = register(Settings.doubleBuilder("MaxReach").withValue(4.4).withMinimum(2.0).withVisibility { page.value == Page.MAIN }.build()) private val interacting = register(Settings.enumBuilder(InteractMode::class.java).withName("InteractMode").withValue(InteractMode.SPOOF).withVisibility { page.value == Page.MAIN }.build()) // build settings @@ -83,7 +83,7 @@ object HighwayTools : Module() { private val aOutline = register(Settings.integerBuilder("OutlineAlpha").withMinimum(0).withValue(91).withMaximum(255).withVisibility { outline.value && page.value == Page.CONFIG }.build()) // other settings - var ignoreBlocks = mutableListOf(Blocks.STANDING_SIGN, Blocks.WALL_SIGN, Blocks.STANDING_BANNER, Blocks.WALL_BANNER, Blocks.BEDROCK, Blocks.PORTAL) + val ignoreBlocks = mutableListOf(Blocks.STANDING_SIGN, Blocks.WALL_SIGN, Blocks.STANDING_BANNER, Blocks.WALL_BANNER, Blocks.BEDROCK, Blocks.PORTAL) var material: Block = Blocks.OBSIDIAN var fillerMat: Block = Blocks.NETHERRACK private var playerHotbarSlot = -1 @@ -93,9 +93,8 @@ object HighwayTools : Module() { private var baritoneSettingRenderGoal = false // runtime vars - private val compareByPriority: Comparator = compareBy { it.taskState.ordinal } - var blockQueue: PriorityQueue = PriorityQueue(compareByPriority) - private val doneQueue: Queue = LinkedList() + val blockQueue: PriorityQueue = PriorityQueue(compareBy { it.taskState.ordinal }) + private val doneQueue: Queue = LinkedList() private var blockOffsets = mutableListOf>() private var waitTicks = 0 private var blocksPlaced = 0 From 392bc2afeb12ad5a554e178d61f4f92edc5e902e Mon Sep 17 00:00:00 2001 From: Christian Date: Mon, 28 Sep 2020 06:36:29 +0200 Subject: [PATCH 030/390] Parentheses fixes --- .../kami/module/modules/misc/HighwayTools.kt | 24 +++++++++---------- .../kami/process/HighwayToolsProcess.kt | 2 +- .../zeroeightsix/kami/util/math/MathUtils.kt | 2 +- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 3590cd4e92..bc6eb279af 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -420,14 +420,14 @@ object HighwayTools : Module() { for ((a, b) in blockOffsets) { val block = mc.world.getBlockState(a).block when { - (block == Blocks.LAVA || block == Blocks.WATER) -> addTask(a, TaskState.LIQUID_SOURCE, fillerMat) - (block == Blocks.FLOWING_LAVA || block == Blocks.FLOWING_WATER) -> addTask(a, TaskState.LIQUID_FLOW, fillerMat) - (!b && block in ignoreBlocks) -> addTask(a, Blocks.AIR) - (b && block == material) -> addTask(a, material) - (!b && block == Blocks.AIR) -> addTask(a, Blocks.AIR) - (b && block != Blocks.AIR && block != material) -> addTask(a, TaskState.BREAK, material) - (!b && block != Blocks.AIR) -> addTask(a, TaskState.BREAK, Blocks.AIR) - (b && block == Blocks.AIR) -> addTask(a, TaskState.PLACE, material) + block == Blocks.LAVA || block == Blocks.WATER -> addTask(a, TaskState.LIQUID_SOURCE, fillerMat) + block == Blocks.FLOWING_LAVA || block == Blocks.FLOWING_WATER -> addTask(a, TaskState.LIQUID_FLOW, fillerMat) + !b && block in ignoreBlocks -> addTask(a, Blocks.AIR) + b && block == material -> addTask(a, material) + !b && block == Blocks.AIR -> addTask(a, Blocks.AIR) + b && block != Blocks.AIR && block != material -> addTask(a, TaskState.BREAK, material) + !b && block != Blocks.AIR -> addTask(a, TaskState.BREAK, Blocks.AIR) + b && block == Blocks.AIR -> addTask(a, TaskState.PLACE, material) } } } @@ -677,10 +677,10 @@ object HighwayTools : Module() { c = c.up() if (buildWidth.value % 2 != 0) { blockOffsets.add(Pair(relativeDirection(c, x / 2, 2 * alterDirection), true)) - blockOffsets.add(Pair(relativeDirection(c, x / 2, 2 * alterDirection * (-1)), true)) + blockOffsets.add(Pair(relativeDirection(c, x / 2, 2 * alterDirection * -1), true)) } else { blockOffsets.add(Pair(relativeDirection(c, x / 2, 2 * alterDirection), true)) - blockOffsets.add(Pair(relativeDirection(c, x / 2 - 1, 2 * alterDirection * (-1)), true)) + blockOffsets.add(Pair(relativeDirection(c, x / 2 - 1, 2 * alterDirection * -1), true)) } } } @@ -722,10 +722,10 @@ object HighwayTools : Module() { if (buildWidth.value % 2 != 0) { blockOffsets.add(Pair(relativeDirection(c, x / 2, 2 * alterDirection), true)) - blockOffsets.add(Pair(relativeDirection(c, x / 2, 2 * alterDirection * (-1)), true)) + blockOffsets.add(Pair(relativeDirection(c, x / 2, 2 * alterDirection * -1), true)) } else { blockOffsets.add(Pair(relativeDirection(c, x / 2, 2 * alterDirection), true)) - blockOffsets.add(Pair(relativeDirection(c, x / 2 - 1, 2 * alterDirection * (-1)), true)) + blockOffsets.add(Pair(relativeDirection(c, x / 2 - 1, 2 * alterDirection * -1), true)) } } } diff --git a/src/main/java/me/zeroeightsix/kami/process/HighwayToolsProcess.kt b/src/main/java/me/zeroeightsix/kami/process/HighwayToolsProcess.kt index 24896e13e5..a1264f6ac2 100644 --- a/src/main/java/me/zeroeightsix/kami/process/HighwayToolsProcess.kt +++ b/src/main/java/me/zeroeightsix/kami/process/HighwayToolsProcess.kt @@ -36,7 +36,7 @@ object HighwayToolsProcess : IBaritoneProcess { } override fun isActive(): Boolean { - return (HighwayTools.isEnabled) + return HighwayTools.isEnabled } override fun onTick(p0: Boolean, p1: Boolean): PathingCommand? { diff --git a/src/main/java/me/zeroeightsix/kami/util/math/MathUtils.kt b/src/main/java/me/zeroeightsix/kami/util/math/MathUtils.kt index 6d2c7f4fe1..6ddd113683 100644 --- a/src/main/java/me/zeroeightsix/kami/util/math/MathUtils.kt +++ b/src/main/java/me/zeroeightsix/kami/util/math/MathUtils.kt @@ -52,7 +52,7 @@ object MathUtils { fun getPlayerCardinal(mc: Minecraft): Cardinal { val angle = normalizeAngle(mc.player.rotationYaw.toDouble()) return when { - (angle >= 157.6 || angle <= -157.5) -> Cardinal.NEG_Z //NORTH + angle >= 157.6 || angle <= -157.5 -> Cardinal.NEG_Z //NORTH isBetween(-157.6, -112.5, angle) -> Cardinal.POS_X_NEG_Z //NORTH-EAST isBetween(-112.5, -67.5, angle) -> Cardinal.POS_X //EAST isBetween(-67.6, -22.6, angle) -> Cardinal.POS_X_POS_Z //SOUTH-EAST From 1d7dcf7ef1c533ffe7344d568a489cd9d61f0aa3 Mon Sep 17 00:00:00 2001 From: Christian Date: Fri, 2 Oct 2020 06:32:43 +0200 Subject: [PATCH 031/390] Went crazy doin this - Mining is now completely compatible with 2b2t - Placing still in optimize phase - Better position detection - Minimized the blueprint generator - Better situation handling with stuck detectors - Fixed compatibility with new masters - Rewrote full logic check - Added an even more intelligent liquid handler with sense of physics - Better function layout - Some master fixes --- .../command/commands/HighwayToolsCommand.kt | 15 +- .../zeroeightsix/kami/gui/kami/KamiGUI.java | 2 +- .../kami/module/modules/misc/HighwayTools.kt | 569 ++++++++++-------- .../module/modules/player/InventoryManager.kt | 4 +- .../zeroeightsix/kami/util/math/MathUtils.kt | 4 +- 5 files changed, 322 insertions(+), 272 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/command/commands/HighwayToolsCommand.kt b/src/main/java/me/zeroeightsix/kami/command/commands/HighwayToolsCommand.kt index ce124fa7ca..f5b4e966d0 100644 --- a/src/main/java/me/zeroeightsix/kami/command/commands/HighwayToolsCommand.kt +++ b/src/main/java/me/zeroeightsix/kami/command/commands/HighwayToolsCommand.kt @@ -12,7 +12,7 @@ import net.minecraft.block.Block * @since 01/09/2020 */ class HighwayToolsCommand : Command("highwaytools", ChunkBuilder() - .append("mode", true, EnumParser(arrayOf("material", "filler", "ignore", "settings"))) + .append("mode", true, EnumParser(arrayOf("material", "filler", "ignore", "reach", "settings"))) .append("value") .build(), "ht") { @@ -74,6 +74,15 @@ class HighwayToolsCommand : Command("highwaytools", ChunkBuilder() } } + SubCommands.MAX_REACH -> { + try { + ht.maxReach.value = args[1]!!.toFloatOrNull() + MessageSendHelper.sendChatMessage("Set your max reach to &7${ht.maxReach.value}&r.") + } catch (e: Exception) { + MessageSendHelper.sendChatMessage("&7${args[1]}&r is not a valid number (eg: 5.5).") + } + } + SubCommands.NULL -> { val commands = args.joinToString(separator = " ") MessageSendHelper.sendChatMessage("Invalid command &7${commandPrefix.value}${label} $commands&f!") @@ -93,6 +102,8 @@ class HighwayToolsCommand : Command("highwaytools", ChunkBuilder() args[0].equals("filler", ignoreCase = true) -> SubCommands.FILLER + args[0].equals("reach", ignoreCase = true) -> SubCommands.MAX_REACH + args[0].equals("ignore", ignoreCase = true) && args[2].isNullOrBlank() -> SubCommands.IGNORE_ADD args[0].equals("ignore", ignoreCase = true) && args[1].equals("add", ignoreCase = true) -> SubCommands.IGNORE_ADD @@ -104,7 +115,7 @@ class HighwayToolsCommand : Command("highwaytools", ChunkBuilder() } private enum class SubCommands { - MATERIAL, FILLER, IGNORE_ADD, IGNORE_DEL, SETTINGS, NULL + MATERIAL, FILLER, IGNORE_ADD, IGNORE_DEL, MAX_REACH, SETTINGS, NULL } init { diff --git a/src/main/java/me/zeroeightsix/kami/gui/kami/KamiGUI.java b/src/main/java/me/zeroeightsix/kami/gui/kami/KamiGUI.java index 86e871c6d8..ab9e9eb679 100644 --- a/src/main/java/me/zeroeightsix/kami/gui/kami/KamiGUI.java +++ b/src/main/java/me/zeroeightsix/kami/gui/kami/KamiGUI.java @@ -532,7 +532,7 @@ public void onTick() { ); coordsLabel.setText(""); coordsLabel.addLine(ow); - coordsLabel.addLine(MathUtils.getPlayerCardinal(player).cardinalName + colouredSeparator + nether); + coordsLabel.addLine(MathUtils.getPlayerCardinal(player).getDirectionName() + colouredSeparator + nether); }); frame.addChild(coordsLabel); coordsLabel.setShadow(true); diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index bc6eb279af..b63fadc844 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -9,6 +9,7 @@ import me.zeroeightsix.kami.module.modules.player.NoBreakAnimation import me.zeroeightsix.kami.process.HighwayToolsProcess import me.zeroeightsix.kami.setting.Settings import me.zeroeightsix.kami.util.BlockUtils +import me.zeroeightsix.kami.util.CenterPlayer import me.zeroeightsix.kami.util.InventoryUtils import me.zeroeightsix.kami.util.color.ColorHolder import me.zeroeightsix.kami.util.graphics.ESPRenderer @@ -16,10 +17,12 @@ import me.zeroeightsix.kami.util.graphics.GeometryMasks import me.zeroeightsix.kami.util.math.CoordinateConverter.asString import me.zeroeightsix.kami.util.math.MathUtils.Cardinal import me.zeroeightsix.kami.util.math.MathUtils.getPlayerCardinal -import me.zeroeightsix.kami.util.math.MathUtils.mcPlayerPosFloored import me.zeroeightsix.kami.util.math.RotationUtils import me.zeroeightsix.kami.util.math.Vec2f import me.zeroeightsix.kami.util.math.VectorUtils +import me.zeroeightsix.kami.util.math.VectorUtils.getDistance +import me.zeroeightsix.kami.util.math.VectorUtils.toBlockPos +import me.zeroeightsix.kami.util.math.VectorUtils.toVec3d import me.zeroeightsix.kami.util.text.MessageSendHelper import net.minecraft.block.Block import net.minecraft.block.Block.getIdFromBlock @@ -36,7 +39,6 @@ import net.minecraft.util.math.AxisAlignedBB import net.minecraft.util.math.BlockPos import net.minecraft.util.math.Vec3d import java.util.* -import java.util.stream.IntStream.range import kotlin.math.abs import kotlin.math.sqrt @@ -48,29 +50,30 @@ import kotlin.math.sqrt @Module.Info( name = "HighwayTools", description = "Be the grief a step a head.", - category = Module.Category.MISC + category = Module.Category.MISC, + modulePriority = 10 ) object HighwayTools : Module() { private val mode = register(Settings.e("Mode", Mode.HIGHWAY)) - private val page = register(Settings.e("Page", Page.MAIN)) - - // main settings - private val blocksPerTick = register(Settings.integerBuilder("BlocksPerTick").withMinimum(1).withValue(1).withMaximum(10).withVisibility { page.value == Page.MAIN }.build()) - private val tickDelayPlace = register(Settings.integerBuilder("TickDelayPlace").withMinimum(0).withValue(0).withMaximum(15).withVisibility { page.value == Page.MAIN }.build()) - private val tickDelayBreak = register(Settings.integerBuilder("TickDelayBreak").withMinimum(0).withValue(0).withMaximum(15).withVisibility { page.value == Page.MAIN }.build()) - val baritoneMode = register(Settings.booleanBuilder("AutoMode").withValue(true).withVisibility { page.value == Page.MAIN }.build()) - private val maxReach = register(Settings.doubleBuilder("MaxReach").withValue(4.4).withMinimum(2.0).withVisibility { page.value == Page.MAIN }.build()) - private val interacting = register(Settings.enumBuilder(InteractMode::class.java).withName("InteractMode").withValue(InteractMode.SPOOF).withVisibility { page.value == Page.MAIN }.build()) + private val page = register(Settings.e("Page", Page.BUILD)) // build settings val clearSpace = register(Settings.booleanBuilder("ClearSpace").withValue(true).withVisibility { page.value == Page.BUILD }.build()) var clearHeight = register(Settings.integerBuilder("ClearHeight").withMinimum(1).withValue(4).withMaximum(6).withVisibility { page.value == Page.BUILD && clearSpace.value }.build()) - private var buildWidth = register(Settings.integerBuilder("BuildWidth").withMinimum(1).withValue(7).withMaximum(9).withVisibility { page.value == Page.BUILD }.build()) - private val rims = register(Settings.booleanBuilder("Rims").withValue(true).withVisibility { page.value == Page.BUILD }.build()) - private var rimHeight = register(Settings.integerBuilder("RimHeight").withMinimum(1).withValue(1).withMaximum(clearHeight.value).withVisibility { rims.value && page.value == Page.BUILD }.build()) + private var buildWidth = register(Settings.integerBuilder("BuildWidth").withMinimum(1).withValue(5).withMaximum(9).withVisibility { page.value == Page.BUILD }.build()) + private val railing = register(Settings.booleanBuilder("Railing").withValue(true).withVisibility { page.value == Page.BUILD }.build()) + private var railingHeight = register(Settings.integerBuilder("RailingHeight").withMinimum(0).withValue(1).withMaximum(clearHeight.value).withVisibility { railing.value && page.value == Page.BUILD }.build()) private val cornerBlock = register(Settings.booleanBuilder("CornerBlock").withValue(true).withVisibility { page.value == Page.BUILD }.build()) - private val fillCorner = register(Settings.booleanBuilder("FillCorner").withValue(true).withVisibility { page.value == Page.BUILD && !cornerBlock.value }.build()) + + // config settings + val baritoneMode = register(Settings.booleanBuilder("AutoMode").withValue(true).withVisibility { page.value == Page.MAIN }.build()) + private val blocksPerTick = register(Settings.integerBuilder("BlocksPerTick").withMinimum(1).withValue(1).withMaximum(10).withVisibility { page.value == Page.MAIN }.build()) + private val tickDelayPlace = register(Settings.integerBuilder("TickDelayPlace").withMinimum(0).withValue(1).withMaximum(25).withVisibility { page.value == Page.MAIN }.build()) + private val tickDelayBreak = register(Settings.integerBuilder("TickDelayBreak").withMinimum(0).withValue(1).withMaximum(25).withVisibility { page.value == Page.MAIN }.build()) + private val interacting = register(Settings.enumBuilder(InteractMode::class.java).withName("InteractMode").withValue(InteractMode.SPOOF).withVisibility { page.value == Page.MAIN }.build()) + private val stuckDelay = register(Settings.integerBuilder("TickDelayStuck").withMinimum(1).withValue(250).withMaximum(1000).withVisibility { page.value == Page.MAIN }.build()) + val maxReach = register(Settings.floatBuilder("MaxReach").withMinimum(2.0F).withValue(5.4F).withVisibility { page.value == Page.MAIN }.build()) // config settings private val info = register(Settings.booleanBuilder("ShowInfo").withValue(true).withVisibility { page.value == Page.CONFIG }.build()) @@ -95,19 +98,19 @@ object HighwayTools : Module() { // runtime vars val blockQueue: PriorityQueue = PriorityQueue(compareBy { it.taskState.ordinal }) private val doneQueue: Queue = LinkedList() - private var blockOffsets = mutableListOf>() + private var blockOffsets = mutableListOf>() private var waitTicks = 0 private var blocksPlaced = 0 var pathing = false private var isSneaking = false - private var stuckDetector = 0 + private var stuckBuilding = 0 + private var stuckMining = 0 private lateinit var currentBlockPos: BlockPos private lateinit var startingBlockPos: BlockPos // stats private var totalBlocksPlaced = 0 private var totalBlocksDestroyed = 0 - private var totalBlocksDistance = 0 fun isDone(): Boolean { return blockQueue.size == 0 @@ -118,11 +121,12 @@ object HighwayTools : Module() { disable() return } - startingBlockPos = mcPlayerPosFloored(mc) + + startingBlockPos = mc.player.positionVector.toBlockPos() currentBlockPos = startingBlockPos playerHotbarSlot = mc.player.inventory.currentItem lastHotbarSlot = -1 - buildDirectionSaved = getPlayerCardinal(mc) + buildDirectionSaved = getPlayerCardinal(mc.player) if (baritoneMode.value) { baritoneSettingAllowPlace = BaritoneAPI.getSettings().allowPlace.value @@ -158,14 +162,11 @@ object HighwayTools : Module() { BaritoneAPI.getSettings().allowPlace.value = baritoneSettingAllowPlace if (!goalRender.value) BaritoneAPI.getSettings().renderGoal.value = baritoneSettingRenderGoal val baritoneProcess = BaritoneAPI.getProvider().primaryBaritone.pathingControlManager.mostRecentInControl() - if (baritoneProcess.isPresent && baritoneProcess.get() == HighwayToolsProcess) { - baritoneProcess.get().onLostControl() - } + if (baritoneProcess.isPresent && baritoneProcess.get() == HighwayToolsProcess) baritoneProcess.get().onLostControl() } printDisable() totalBlocksPlaced = 0 totalBlocksDestroyed = 0 - totalBlocksDistance = 0 } override fun onUpdate() { @@ -176,48 +177,35 @@ object HighwayTools : Module() { if (!isDone()) { if (!doTask()) { if (!pathing && !LagNotifier.paused && !AutoObsidian.active) { - stuckDetector += 1 - var tmpQueue: Queue = LinkedList(blockQueue) - tmpQueue = LinkedList(tmpQueue.shuffled()) - blockQueue.clear() - blockQueue.addAll(tmpQueue) - if (debugMessages.value == DebugMessages.ALL) { - MessageSendHelper.sendChatMessage("$chatName Shuffled tasks (x$stuckDetector)") - } - if (stuckDetector > blockOffsets.size) { + stuckBuilding += 1 + shuffleTasks() + if (debugMessages.value == DebugMessages.ALL) MessageSendHelper.sendChatMessage("$chatName Shuffled tasks (x$stuckBuilding)") + if (stuckBuilding > blockOffsets.size) { refreshData() - if (debugMessages.value == DebugMessages.IMPORTANT) { - MessageSendHelper.sendChatMessage("$chatName You got stuck, retry") - } + if (debugMessages.value == DebugMessages.IMPORTANT) MessageSendHelper.sendChatMessage("$chatName You got stuck, retry") } } else { refreshData() } } else { - stuckDetector = 0 + stuckBuilding = 0 } } else { + refreshData() if (checkTasks() && !pathing) { currentBlockPos = getNextBlock() - totalBlocksDistance++ - doneQueue.clear() - updateTasks() - } else { doneQueue.clear() updateTasks() } } } else { - if (currentBlockPos == mcPlayerPosFloored(mc)) { + if (currentBlockPos == mc.player.positionVector.toBlockPos()) { if (!doTask()) { - var tmpQueue: Queue = LinkedList(blockQueue) - tmpQueue = LinkedList(tmpQueue.shuffled()) - blockQueue.clear() - blockQueue.addAll(tmpQueue) + shuffleTasks() } } else { - currentBlockPos = mcPlayerPosFloored(mc) - if (abs((buildDirectionSaved.ordinal - getPlayerCardinal(mc).ordinal) % 8) == 4) buildDirectionSaved = getPlayerCardinal(mc) + currentBlockPos = mc.player.positionVector.toBlockPos() + if (abs((buildDirectionSaved.ordinal - getPlayerCardinal(mc.player).ordinal) % 8) == 4) buildDirectionSaved = getPlayerCardinal(mc.player) refreshData() } } @@ -247,32 +235,11 @@ object HighwayTools : Module() { doneQueue.add(blockTask) } - private fun checkTasks(): Boolean { - for (blockTask in doneQueue) { - val block = mc.world.getBlockState(blockTask.blockPos).block - var cont = false - for (b in ignoreBlocks) { - if (b == block) { - cont = true - } - } - if (cont) { - continue - } - if (blockTask.block == material && block == Blocks.AIR) { - return false - } else if (blockTask.block == Blocks.AIR && block != Blocks.AIR) { - return false - } - } - return true - } - private fun doTask(): Boolean { + BaritoneAPI.getProvider().primaryBaritone.pathingControlManager.registerProcess(HighwayToolsProcess) if (!isDone() && !pathing && !LagNotifier.paused && !AutoObsidian.active) { - BaritoneAPI.getProvider().primaryBaritone.pathingControlManager.registerProcess(HighwayToolsProcess) - if (waitTicks == 0) { + if (mc.player.posX != CenterPlayer.getPosX(1.0f) || mc.player.posZ != CenterPlayer.getPosZ(1.0f)) CenterPlayer.centerPlayer(1.0f) if (printDebug.value) printDebug() val blockTask = blockQueue.peek() @@ -284,31 +251,47 @@ object HighwayTools : Module() { doTask() } TaskState.BREAKING -> { - mineBlock(blockTask.blockPos, false) - - val block = mc.world.getBlockState(blockTask.blockPos).block - if (block == Blocks.AIR) { - totalBlocksDestroyed++ - waitTicks = tickDelayBreak.value + if (stuckMining > stuckDelay.value) { + stuckMining = 0 + updateTask(blockTask, TaskState.BREAK) + refreshData() + shuffleTasks() + if (debugMessages.value == DebugMessages.IMPORTANT) MessageSendHelper.sendChatMessage("Shuffled because of mining issue.") + } - if (blockTask.block == material) { - updateTask(blockTask, TaskState.PLACE) - } else { - updateTask(blockTask, TaskState.DONE) + when (mc.world.getBlockState(blockTask.blockPos).block) { + Blocks.AIR -> { + stuckMining = 0 + totalBlocksDestroyed++ + waitTicks = tickDelayBreak.value + if (blockTask.block == material || blockTask.block == fillerMat) { + updateTask(blockTask, TaskState.PLACE) + } else { + updateTask(blockTask, TaskState.DONE) + doTask() + } + } + Blocks.LAVA -> { + updateTask(blockTask, TaskState.LIQUID_SOURCE) + updateTask(blockTask, fillerMat) + } + Blocks.FLOWING_LAVA -> { + updateTask(blockTask, TaskState.LIQUID_FLOW) + updateTask(blockTask, fillerMat) + } + else -> { + mineBlock(blockTask.blockPos, false) + stuckMining++ } } } TaskState.PLACED -> { - if (blockTask.block == material) { - val block = mc.world.getBlockState(blockTask.blockPos).block + val block = mc.world.getBlockState(blockTask.blockPos).block - if (block != Blocks.AIR) { - updateTask(blockTask, TaskState.DONE) - } else { - updateTask(blockTask, TaskState.PLACE) - } - } else { - updateTask(blockTask, TaskState.BREAK) + when { + blockTask.block == block && block != Blocks.AIR -> updateTask(blockTask, TaskState.DONE) + blockTask.block == Blocks.AIR && block != Blocks.AIR -> updateTask(blockTask, TaskState.BREAK) + else -> updateTask(blockTask, TaskState.PLACE) } doTask() } @@ -317,34 +300,14 @@ object HighwayTools : Module() { // ignore blocks for (b in ignoreBlocks) { - if (block::class == b!!::class) { + if (block == b) { updateTask(blockTask, TaskState.DONE) doTask() } } // liquid search around the breaking block - for (side in EnumFacing.values()) { - val neighbour = blockTask.blockPos.offset(side) - - if (!BlockUtils.hasNeighbour(neighbour) && sqrt(mc.player.getDistanceSqToCenter(neighbour)) > maxReach.value) continue - if (mc.world.getBlockState(neighbour).block is BlockLiquid) { - var found = false - for (bt in blockQueue) { - if (bt.blockPos == neighbour) { - MessageSendHelper.sendChatMessage("Found") - updateTask(bt, TaskState.LIQUID_SOURCE) - updateTask(bt, fillerMat) - found = true - } - } - if (!found) { - MessageSendHelper.sendChatMessage("Not Found: " + neighbour.asString()) - addTask(neighbour, TaskState.LIQUID_SOURCE, fillerMat) - } - return false - } - } + if (liquidHandler(blockTask.blockPos)) return false // last check before breaking when (block) { @@ -352,33 +315,20 @@ object HighwayTools : Module() { updateTask(blockTask, TaskState.DONE) doTask() } - is BlockLiquid -> { - - var insideBuild = false - for ((pos, build) in blockOffsets) { - if (blockTask.blockPos == pos && build) { - insideBuild = true - } - } - - when (block) { - Blocks.LAVA -> { - updateTask(blockTask, TaskState.LIQUID_SOURCE) - } - Blocks.FLOWING_LAVA -> { - updateTask(blockTask, TaskState.LIQUID_FLOW) - } - } - if (insideBuild) { - updateTask(blockTask, Blocks.OBSIDIAN) - } else { - updateTask(blockTask, Blocks.NETHERRACK) - } - doTask() + Blocks.LAVA -> { + updateTask(blockTask, TaskState.LIQUID_SOURCE) + updateTask(blockTask, fillerMat) + } + Blocks.FLOWING_LAVA -> { + updateTask(blockTask, TaskState.LIQUID_FLOW) + updateTask(blockTask, fillerMat) } else -> { - mineBlock(blockTask.blockPos, true) - updateTask(blockTask, TaskState.BREAKING) + if (!mineBlock(blockTask.blockPos, true)) { + shuffleTasks() + } else { + updateTask(blockTask, TaskState.BREAKING) + } } } } @@ -390,20 +340,18 @@ object HighwayTools : Module() { return true } - if (placeBlock(blockTask.blockPos, blockTask.block)) { - updateTask(blockTask, TaskState.PLACED) - if (blocksPerTick.value > blocksPlaced + 1) { - blocksPlaced++ - doTask() - } else { - blocksPlaced = 0 - } - - waitTicks = tickDelayPlace.value - totalBlocksPlaced++ + if (!placeBlock(blockTask.blockPos, blockTask.block)) return false + if (blockTask.taskState != TaskState.PLACE && isInsideBuild(blockTask.blockPos)) updateTask(blockTask, Blocks.AIR) + updateTask(blockTask, TaskState.PLACED) + if (blocksPerTick.value > blocksPlaced + 1) { + blocksPlaced++ + doTask() } else { - return false + blocksPlaced = 0 } + + waitTicks = tickDelayPlace.value + totalBlocksPlaced++ } } } else { @@ -415,52 +363,156 @@ object HighwayTools : Module() { } } + private fun checkTasks(): Boolean { + loop@ for (blockTask in doneQueue) { + val block = mc.world.getBlockState(blockTask.blockPos).block + for (b in ignoreBlocks) { + if (b == block) continue@loop + } + when { + blockTask.block == material && block == Blocks.AIR -> return false + blockTask.block == Blocks.AIR && block != Blocks.AIR -> return false + } + } + return true + } + private fun updateTasks() { updateBlockArray() - for ((a, b) in blockOffsets) { - val block = mc.world.getBlockState(a).block - when { - block == Blocks.LAVA || block == Blocks.WATER -> addTask(a, TaskState.LIQUID_SOURCE, fillerMat) - block == Blocks.FLOWING_LAVA || block == Blocks.FLOWING_WATER -> addTask(a, TaskState.LIQUID_FLOW, fillerMat) - !b && block in ignoreBlocks -> addTask(a, Blocks.AIR) - b && block == material -> addTask(a, material) - !b && block == Blocks.AIR -> addTask(a, Blocks.AIR) - b && block != Blocks.AIR && block != material -> addTask(a, TaskState.BREAK, material) - !b && block != Blocks.AIR -> addTask(a, TaskState.BREAK, Blocks.AIR) - b && block == Blocks.AIR -> addTask(a, TaskState.PLACE, material) + for ((blockPos, blockType) in blockOffsets) { + when (val block = mc.world.getBlockState(blockPos).block) { + Blocks.LAVA, Blocks.WATER -> addTask(blockPos, TaskState.LIQUID_SOURCE, fillerMat) + Blocks.FLOWING_LAVA, Blocks.FLOWING_WATER -> addTask(blockPos, TaskState.LIQUID_FLOW, fillerMat) + else -> { + when (blockType) { + Blocks.AIR -> { + when { + block in ignoreBlocks -> addTask(blockPos, Blocks.AIR) + block == Blocks.AIR -> addTask(blockPos, Blocks.AIR) + block != Blocks.AIR -> addTask(blockPos, TaskState.BREAK, Blocks.AIR) + } + } + material -> { + when { + block == material -> addTask(blockPos, material) + block != Blocks.AIR && block != material -> addTask(blockPos, TaskState.BREAK, material) + block == Blocks.AIR -> addTask(blockPos, TaskState.PLACE, material) + } + } + fillerMat -> { + when { + getPlaceableSide(blockPos.up()) == null -> addTask(blockPos, TaskState.PLACE, fillerMat) + getPlaceableSide(blockPos.up()) != null -> addTask(blockPos, fillerMat) + } + } + } + } } } } - private fun mineBlock(pos: BlockPos, pre: Boolean) { + private fun shuffleTasks() { + var tmpQueue: Queue = LinkedList(blockQueue) + tmpQueue = LinkedList(tmpQueue.shuffled()) + blockQueue.clear() + blockQueue.addAll(tmpQueue) + } + + private fun liquidHandler(blockPos: BlockPos): Boolean { + var foundLiquid = false + for (side in EnumFacing.values()) { + val neighbour = blockPos.offset(side) + val neighbourBlock = mc.world.getBlockState(neighbour).block + + if (neighbourBlock == Blocks.LAVA || neighbourBlock == Blocks.FLOWING_LAVA) { + if (sqrt(mc.player.getDistanceSqToCenter(neighbour)) > maxReach.value) continue + foundLiquid = true + val found = mutableListOf>() + for (bt in blockQueue) { + if (bt.blockPos == neighbour) { + when (neighbourBlock) { + Blocks.LAVA, Blocks.WATER -> found.add(Triple(bt, TaskState.LIQUID_SOURCE, fillerMat)) + Blocks.FLOWING_LAVA, Blocks.FLOWING_WATER -> found.add(Triple(bt, TaskState.LIQUID_FLOW, fillerMat)) + } + } + } + if (found.isEmpty()) { + when (neighbourBlock) { + Blocks.LAVA, Blocks.WATER -> { + addTask(neighbour, TaskState.LIQUID_SOURCE, fillerMat) + } + Blocks.FLOWING_LAVA, Blocks.FLOWING_WATER -> { + addTask(neighbour, TaskState.LIQUID_FLOW, fillerMat) + } + } + } else { + for (x in found) { + updateTask(x.first, x.second) + updateTask(x.first, x.third) + } + } + } + } + return foundLiquid + } + + private fun mineBlock(pos: BlockPos, pre: Boolean): Boolean { if (InventoryUtils.getSlotsHotbar(278) == null && InventoryUtils.getSlotsNoHotbar(278) != null) { InventoryUtils.moveToHotbar(278, 130) - return + return true } else if (InventoryUtils.getSlots(0, 35, 278) == null) { MessageSendHelper.sendChatMessage("$chatName No Pickaxe was found in inventory") mc.getSoundHandler().playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) disable() - return + return false } InventoryUtils.swapSlotToItem(278) + + var rayTrace = mc.world.rayTraceBlocks(mc.player.getPositionEyes(1f), Vec3d(pos).add(0.5, 0.5, 0.5)) + if (rayTrace == null) { + refreshData() + return false + } + if (rayTrace.blockPos != pos) { + var found = false + for (side in EnumFacing.values()) { + if (mc.world.getBlockState(pos.offset(side)).block == Blocks.AIR) { + rayTrace = mc.world.rayTraceBlocks(mc.player.getPositionEyes(1f), Vec3d(pos).add(0.5, 0.5, 0.5).add(Vec3d(side.directionVec).scale(0.5))) + //MessageSendHelper.sendChatMessage(pos.offset(side).toString() + " - " + rayTrace.toString()) + //val lookAt = RotationUtils.getRotationTo(Vec3d(pos).add(0.5, 0.5, 0.5).add(Vec3d(side.directionVec).scale(0.5)), true) + //mc.player.rotationYaw = lookAt.x.toFloat() + //mc.player.rotationPitch = lookAt.y.toFloat() + if (rayTrace != null && rayTrace.blockPos == pos.offset(side)) { + found = true + break + } + } + } + if (!found) { + refreshData() + shuffleTasks() + return false + } + } + val facing = rayTrace?.sideHit ?: return false + val lookAt = RotationUtils.getRotationTo(Vec3d(pos).add(0.5, 0.5, 0.5).add(Vec3d(facing.directionVec).scale(0.5)), true) when (interacting.value) { InteractMode.SPOOF -> { - val lookAt = RotationUtils.getRotationTo(Vec3d(pos).add(0.5, 0.0, 0.5), true) PlayerPacketManager.addPacket(this, PlayerPacketManager.PlayerPacket(rotating = true, rotation = Vec2f(lookAt.x.toFloat(), lookAt.y.toFloat()))) } InteractMode.VIEWLOCK -> { - val lookAt = RotationUtils.getRotationTo(Vec3d(pos).add(0.5, 0.5, 0.5), true) mc.player.rotationYaw = lookAt.x.toFloat() mc.player.rotationPitch = lookAt.y.toFloat() } } if (pre) { - mc.connection!!.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, pos, mc.objectMouseOver.sideHit)) + mc.connection!!.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, pos, facing)) } else { - mc.connection!!.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, pos, mc.objectMouseOver.sideHit)) + mc.connection!!.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, pos, facing)) } mc.player.swingArm(EnumHand.MAIN_HAND) + return true } private fun placeBlock(pos: BlockPos, mat: Block): Boolean @@ -470,6 +522,7 @@ object HighwayTools : Module() { if (block != Blocks.AIR && block !is BlockLiquid) { return false } + // check if entity blocks placing for (entity in mc.world.getEntitiesWithinAABBExcludingEntity(null, AxisAlignedBB(pos))) { if (entity !is EntityItem && entity !is EntityXPOrb) { @@ -477,13 +530,14 @@ object HighwayTools : Module() { } } val side = getPlaceableSide(pos) ?: return false + // check if we have a block adjacent to blockpos to click at val neighbour = pos.offset(side) val opposite = side.opposite + // check if neighbor can be right clicked - if (!BlockUtils.canBeClicked(neighbour)) { - return false - } + if (!BlockUtils.canBeClicked(neighbour)) return false + // swap to material in Hotbar or get from inventory if (InventoryUtils.getSlotsHotbar(getIdFromBlock(mat)) == null && InventoryUtils.getSlotsNoHotbar(getIdFromBlock(mat)) != null) { // InventoryUtils.moveToHotbar(getIdFromBlock(mat), 130, (tickDelay.value * 16).toLong()) @@ -517,7 +571,7 @@ object HighwayTools : Module() { } } mc.playerController.processRightClickBlock(mc.player, mc.world, neighbour, opposite, hitVec, EnumHand.MAIN_HAND) - mc.player.swingArm(EnumHand.MAIN_HAND) + mc.player.connection.sendPacket(CPacketAnimation(EnumHand.MAIN_HAND)) mc.rightClickDelayTimer = 4 if (NoBreakAnimation.isEnabled) NoBreakAnimation.resetMining() return true @@ -533,6 +587,13 @@ object HighwayTools : Module() { return null } + private fun isInsideBuild(blockPos: BlockPos): Boolean { + for (bt in blockQueue) { + if (bt.blockPos == blockPos) return true + } + return false + } + private fun updateRenderer(renderer: ESPRenderer): ESPRenderer { val side = GeometryMasks.Quad.ALL for (blockTask in blockQueue) { @@ -598,7 +659,7 @@ object HighwayTools : Module() { message += "$chatName Module stopped." + "\n §9> §7Placed blocks: §a$totalBlocksPlaced§r" + "\n §9> §7Destroyed blocks: §a$totalBlocksDestroyed§r" - if (baritoneMode.value) message += "\n §9> §7Distance: §a$totalBlocksDistance§r" + if (baritoneMode.value) message += "\n §9> §7Distance: §a${getDistance(startingBlockPos.toVec3d(), currentBlockPos.toVec3d()).toInt()}§r" } else { message += "$chatName Module stopped." } @@ -635,121 +696,99 @@ object HighwayTools : Module() { return c } + private fun addOffset(cursor: BlockPos, height: Int, width: Int, mat: Block, turn: Boolean) { + var turnValue = 1 + if (turn) turnValue = -1 + if (mat != fillerMat) { + if (height > 1) { + blockOffsets.add(Pair(relativeDirection(relativeDirection(cursor, 1, 3 * turnValue), width - 1, 2 * turnValue), Blocks.AIR)) + } else { + blockOffsets.add(Pair(relativeDirection(relativeDirection(cursor, 1, 3 * turnValue), width - 1, 2 * turnValue), mat)) + } + } else { + blockOffsets.add(Pair(relativeDirection(relativeDirection(cursor, 1, 3 * turnValue), width - 1, 2 * turnValue), material)) + } + } + + private fun genOffset(cursor: BlockPos, height: Int, width: Int, mat: Block, isOdd: Boolean) { + blockOffsets.add(Pair(relativeDirection(cursor, width, -2), mat)) + if (buildDirectionSaved.isDiagonal) { + addOffset(cursor, height, width, mat, true) + } + when { + isOdd -> { + blockOffsets.add(Pair(relativeDirection(cursor, width, 2), mat)) + if (buildDirectionSaved.isDiagonal) { + addOffset(cursor, height, width, mat, false) + } + } + else -> { + val evenCursor = relativeDirection(cursor, 1, 2) + blockOffsets.add(Pair(relativeDirection(evenCursor, width, 2), mat)) + if (buildDirectionSaved.isDiagonal) { + addOffset(cursor, height, width, mat, false) + } + } + } + } + private fun refreshData() { doneQueue.clear() blockQueue.clear() updateTasks() + shuffleTasks() } private fun updateBlockArray() { blockOffsets.clear() - val b = currentBlockPos + var cursor = currentBlockPos.down() when (mode.value) { Mode.HIGHWAY -> { - var cursor = b - cursor = cursor.down() - if (baritoneMode.value) { cursor = relativeDirection(cursor, 1, 0) - blockOffsets.add(Pair(cursor, true)) + blockOffsets.add(Pair(cursor, material)) } cursor = relativeDirection(cursor, 1, 0) - var flip = false - - for (x in range(1, buildWidth.value + 1)) { - val alterDirection = if (flip) { - -1 - } else { - 1 - } - - if (buildDirectionSaved.isDiagonal) { - if (x != 1) { - blockOffsets.add(Pair(relativeDirection(relativeDirection(cursor, x / 2 - 1, 1 * alterDirection), x / 2, 3 * alterDirection), true)) - } - - blockOffsets.add(Pair(relativeDirection(cursor, x / 2, 2 * alterDirection), true)) - if (rims.value && x == buildWidth.value) { - var c = cursor - - for (y in range(1, rimHeight.value + 1)) { - c = c.up() - if (buildWidth.value % 2 != 0) { - blockOffsets.add(Pair(relativeDirection(c, x / 2, 2 * alterDirection), true)) - blockOffsets.add(Pair(relativeDirection(c, x / 2, 2 * alterDirection * -1), true)) - } else { - blockOffsets.add(Pair(relativeDirection(c, x / 2, 2 * alterDirection), true)) - blockOffsets.add(Pair(relativeDirection(c, x / 2 - 1, 2 * alterDirection * -1), true)) - } - } - } - - if (clearSpace.value) { - var c = cursor - - for (y in range(1, clearHeight.value)) { - c = c.up() - - if (rims.value) { - if (!((x == buildWidth.value || x == buildWidth.value - 1) && y <= rimHeight.value)) { - blockOffsets.add(Pair(relativeDirection(relativeDirection(c, x / 2 - 1, 1 * alterDirection), x / 2, 3 * alterDirection), false)) - blockOffsets.add(Pair(relativeDirection(c, x / 2, 2 * alterDirection), false)) - } else { - blockOffsets.add(Pair(relativeDirection(relativeDirection(c, x / 2 - 1, 1 * alterDirection), x / 2, 3 * alterDirection), false)) - } - } else { - if (x != 1) { - blockOffsets.add(Pair(relativeDirection(relativeDirection(c, x / 2 - 1, 1 * alterDirection), x / 2, 3 * alterDirection), false)) - } - blockOffsets.add(Pair(relativeDirection(c, x / 2, 2 * alterDirection), false)) - } + blockOffsets.add(Pair(cursor, material)) + var buildIterationsWidth = buildWidth.value / 2 + var evenCursor = relativeDirection(cursor, 1, 2) + var isOdd = false + if (buildWidth.value % 2 == 1) { + isOdd = true + buildIterationsWidth++ + } else { + blockOffsets.add(Pair(evenCursor, material)) + } + for (i in 1 until clearHeight.value + 1) { + for (j in 1 until buildIterationsWidth) { + if (i == 1) { + if (j == buildIterationsWidth - 1 && !cornerBlock.value) { + genOffset(cursor, i, j, fillerMat, isOdd) + } else { + genOffset(cursor, i, j, material, isOdd) } - } - } else { - if (cornerBlock.value) { - blockOffsets.add(Pair(relativeDirection(cursor, x / 2, 2 * alterDirection), true)) } else { - if (!(x == buildWidth.value || x == buildWidth.value - 1)) { - blockOffsets.add(Pair(relativeDirection(cursor, x / 2, 2 * alterDirection), true)) - } - } - - if (rims.value && x == buildWidth.value) { - var c = cursor - for (y in range(1, rimHeight.value + 1)) { - c = c.up() - - if (buildWidth.value % 2 != 0) { - blockOffsets.add(Pair(relativeDirection(c, x / 2, 2 * alterDirection), true)) - blockOffsets.add(Pair(relativeDirection(c, x / 2, 2 * alterDirection * -1), true)) - } else { - blockOffsets.add(Pair(relativeDirection(c, x / 2, 2 * alterDirection), true)) - blockOffsets.add(Pair(relativeDirection(c, x / 2 - 1, 2 * alterDirection * -1), true)) - } - } - } - - if (clearSpace.value) { - var c = cursor - for (y in range(1, clearHeight.value)) { - c = c.up() - if (rims.value) { - if (!((x == buildWidth.value || x == buildWidth.value - 1) && y <= rimHeight.value)) { - blockOffsets.add(Pair(relativeDirection(c, x / 2, 2 * alterDirection), false)) - } - } else { - blockOffsets.add(Pair(relativeDirection(c, x / 2, 2 * alterDirection), false)) + if (i <= railingHeight.value + 1 && j == buildIterationsWidth - 1) { + genOffset(cursor, i, j, material, isOdd) + } else { + if (clearSpace.value) { + genOffset(cursor, i, j, Blocks.AIR, isOdd) } } } } - flip = !flip + cursor = cursor.up() + evenCursor = evenCursor.up() + if (clearSpace.value && i < clearHeight.value) { + blockOffsets.add(Pair(cursor, Blocks.AIR)) + if (!isOdd) blockOffsets.add(Pair(evenCursor, Blocks.AIR)) + } } } Mode.FLAT -> { - for (bp in VectorUtils.getBlockPositionsInArea(b.down().north(buildWidth.value).west(buildWidth.value), b.down().south(buildWidth.value).east(buildWidth.value))) { - blockOffsets.add(Pair(bp, true)) + for (bp in VectorUtils.getBlockPositionsInArea(cursor.north(buildWidth.value).west(buildWidth.value), cursor.south(buildWidth.value).east(buildWidth.value))) { + blockOffsets.add(Pair(bp, material)) } } null -> { @@ -768,7 +807,7 @@ object HighwayTools : Module() { } private enum class Page { - MAIN, BUILD, CONFIG + BUILD, MAIN, CONFIG } private enum class InteractMode { diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/player/InventoryManager.kt b/src/main/java/me/zeroeightsix/kami/module/modules/player/InventoryManager.kt index bddf998016..0719a956d6 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/player/InventoryManager.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/player/InventoryManager.kt @@ -30,10 +30,10 @@ object InventoryManager : Module() { private val itemSaver = register(Settings.b("ItemSaver", false)) private val duraThreshold = register(Settings.integerBuilder("DurabilityThreshold").withValue(5).withRange(1, 50).withVisibility { itemSaver.value }.build()) val autoEject = register(Settings.b("AutoEject", false)) - private val fullOnly = register(Settings.booleanBuilder("OnlyAtFull").withValue(false).withVisibility { autoEject.value }) + private val fullOnly = register(Settings.booleanBuilder("OnlyAtFull").withValue(false).withVisibility { autoEject.value }.build()) private val pauseMovement: Setting = register(Settings.b("PauseMovement", true)) private val ejectList = register(Settings.stringBuilder("EjectList").withValue(defaultEjectList).withVisibility { false }.build()) - private val delay = register(Settings.integerBuilder("DelayTicks").withValue(1).withRange(0, 20)) + private val delay = register(Settings.integerBuilder("DelayTicks").withValue(1).withRange(0, 20).build()) /* Eject list */ var ejectArrayList = ejectGetArrayList() diff --git a/src/main/java/me/zeroeightsix/kami/util/math/MathUtils.kt b/src/main/java/me/zeroeightsix/kami/util/math/MathUtils.kt index 8ad2bdfc49..d1bfd3ef39 100644 --- a/src/main/java/me/zeroeightsix/kami/util/math/MathUtils.kt +++ b/src/main/java/me/zeroeightsix/kami/util/math/MathUtils.kt @@ -64,8 +64,8 @@ object MathUtils { } @JvmStatic - fun getPlayerCardinal(mc: Minecraft): Cardinal { - val angle = normalizeAngle(mc.player.rotationYaw.toDouble()) + fun getPlayerCardinal(player: EntityPlayer): Cardinal { + val angle = normalizeAngle(player.rotationYaw.toDouble()) return when { angle >= 157.6 || angle <= -157.5 -> Cardinal.NEG_Z //NORTH isBetween(-157.6, -112.5, angle) -> Cardinal.POS_X_NEG_Z //NORTH-EAST From 9c0666afcbd0fe1064dad7f010d3147e454cf87f Mon Sep 17 00:00:00 2001 From: Christian Date: Mon, 19 Oct 2020 06:27:29 +0200 Subject: [PATCH 032/390] Raytrace block breaking and placing - Works with NCP still needs improvements - Fixed even width diagonals - Still messed up positioning on even width --- .../kami/module/modules/misc/HighwayTools.kt | 623 ++++++++++-------- 1 file changed, 360 insertions(+), 263 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index b63fadc844..c50efe6b37 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -1,24 +1,25 @@ package me.zeroeightsix.kami.module.modules.misc import baritone.api.BaritoneAPI -import me.zeroeightsix.kami.event.events.RenderEvent -import me.zeroeightsix.kami.manager.mangers.PlayerPacketManager +import me.zeroeightsix.kami.event.events.RenderWorldEvent +import me.zeroeightsix.kami.event.events.SafeTickEvent import me.zeroeightsix.kami.module.Module +import me.zeroeightsix.kami.module.modules.combat.Surround import me.zeroeightsix.kami.module.modules.player.LagNotifier import me.zeroeightsix.kami.module.modules.player.NoBreakAnimation import me.zeroeightsix.kami.process.HighwayToolsProcess import me.zeroeightsix.kami.setting.Settings import me.zeroeightsix.kami.util.BlockUtils -import me.zeroeightsix.kami.util.CenterPlayer import me.zeroeightsix.kami.util.InventoryUtils import me.zeroeightsix.kami.util.color.ColorHolder +import me.zeroeightsix.kami.util.combat.SurroundUtils +import me.zeroeightsix.kami.util.event.listener import me.zeroeightsix.kami.util.graphics.ESPRenderer import me.zeroeightsix.kami.util.graphics.GeometryMasks import me.zeroeightsix.kami.util.math.CoordinateConverter.asString import me.zeroeightsix.kami.util.math.MathUtils.Cardinal import me.zeroeightsix.kami.util.math.MathUtils.getPlayerCardinal import me.zeroeightsix.kami.util.math.RotationUtils -import me.zeroeightsix.kami.util.math.Vec2f import me.zeroeightsix.kami.util.math.VectorUtils import me.zeroeightsix.kami.util.math.VectorUtils.getDistance import me.zeroeightsix.kami.util.math.VectorUtils.toBlockPos @@ -28,15 +29,13 @@ import net.minecraft.block.Block import net.minecraft.block.Block.getIdFromBlock import net.minecraft.block.BlockLiquid import net.minecraft.client.audio.PositionedSoundRecord -import net.minecraft.entity.item.EntityItem -import net.minecraft.entity.item.EntityXPOrb import net.minecraft.init.Blocks import net.minecraft.init.SoundEvents import net.minecraft.network.play.client.* 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.RayTraceResult import net.minecraft.util.math.Vec3d import java.util.* import kotlin.math.abs @@ -59,33 +58,34 @@ object HighwayTools : Module() { private val page = register(Settings.e("Page", Page.BUILD)) // build settings - val clearSpace = register(Settings.booleanBuilder("ClearSpace").withValue(true).withVisibility { page.value == Page.BUILD }.build()) - var clearHeight = register(Settings.integerBuilder("ClearHeight").withMinimum(1).withValue(4).withMaximum(6).withVisibility { page.value == Page.BUILD && clearSpace.value }.build()) - private var buildWidth = register(Settings.integerBuilder("BuildWidth").withMinimum(1).withValue(5).withMaximum(9).withVisibility { page.value == Page.BUILD }.build()) - private val railing = register(Settings.booleanBuilder("Railing").withValue(true).withVisibility { page.value == Page.BUILD }.build()) - private var railingHeight = register(Settings.integerBuilder("RailingHeight").withMinimum(0).withValue(1).withMaximum(clearHeight.value).withVisibility { railing.value && page.value == Page.BUILD }.build()) - private val cornerBlock = register(Settings.booleanBuilder("CornerBlock").withValue(true).withVisibility { page.value == Page.BUILD }.build()) - - // config settings - val baritoneMode = register(Settings.booleanBuilder("AutoMode").withValue(true).withVisibility { page.value == Page.MAIN }.build()) - private val blocksPerTick = register(Settings.integerBuilder("BlocksPerTick").withMinimum(1).withValue(1).withMaximum(10).withVisibility { page.value == Page.MAIN }.build()) - private val tickDelayPlace = register(Settings.integerBuilder("TickDelayPlace").withMinimum(0).withValue(1).withMaximum(25).withVisibility { page.value == Page.MAIN }.build()) - private val tickDelayBreak = register(Settings.integerBuilder("TickDelayBreak").withMinimum(0).withValue(1).withMaximum(25).withVisibility { page.value == Page.MAIN }.build()) - private val interacting = register(Settings.enumBuilder(InteractMode::class.java).withName("InteractMode").withValue(InteractMode.SPOOF).withVisibility { page.value == Page.MAIN }.build()) - private val stuckDelay = register(Settings.integerBuilder("TickDelayStuck").withMinimum(1).withValue(250).withMaximum(1000).withVisibility { page.value == Page.MAIN }.build()) - val maxReach = register(Settings.floatBuilder("MaxReach").withMinimum(2.0F).withValue(5.4F).withVisibility { page.value == Page.MAIN }.build()) - - // config settings - private val info = register(Settings.booleanBuilder("ShowInfo").withValue(true).withVisibility { page.value == Page.CONFIG }.build()) - private val printDebug = register(Settings.booleanBuilder("ShowQueue").withValue(false).withVisibility { page.value == Page.CONFIG }.build()) - private val debugMessages = register(Settings.enumBuilder(DebugMessages::class.java).withName("Debug").withValue(DebugMessages.IMPORTANT).withVisibility { page.value == Page.CONFIG }.build()) - private val goalRender = register(Settings.booleanBuilder("GoalRender").withValue(false).withVisibility { page.value == Page.CONFIG }.build()) - private val filled = register(Settings.booleanBuilder("Filled").withValue(true).withVisibility { page.value == Page.CONFIG }.build()) - private val outline = register(Settings.booleanBuilder("Outline").withValue(true).withVisibility { page.value == Page.CONFIG }.build()) - private val aFilled = register(Settings.integerBuilder("FilledAlpha").withMinimum(0).withValue(26).withMaximum(255).withVisibility { filled.value && page.value == Page.CONFIG }.build()) - private val aOutline = register(Settings.integerBuilder("OutlineAlpha").withMinimum(0).withValue(91).withMaximum(255).withVisibility { outline.value && page.value == Page.CONFIG }.build()) - - // other settings + val clearSpace = register(Settings.booleanBuilder("ClearSpace").withValue(true).withVisibility { page.value == Page.BUILD }) + var clearHeight = register(Settings.integerBuilder("ClearHeight").withMinimum(1).withValue(4).withMaximum(6).withVisibility { page.value == Page.BUILD && clearSpace.value }) + private var buildWidth = register(Settings.integerBuilder("BuildWidth").withMinimum(1).withValue(5).withMaximum(9).withVisibility { page.value == Page.BUILD }) + private val railing = register(Settings.booleanBuilder("Railing").withValue(true).withVisibility { page.value == Page.BUILD }) + private var railingHeight = register(Settings.integerBuilder("RailingHeight").withMinimum(0).withValue(1).withMaximum(clearHeight.value).withVisibility { railing.value && page.value == Page.BUILD }) + private val cornerBlock = register(Settings.booleanBuilder("CornerBlock").withValue(true).withVisibility { page.value == Page.BUILD }) + + // behavior settings + val baritoneMode = register(Settings.booleanBuilder("AutoMode").withValue(true).withVisibility { page.value == Page.BEHAVIOR }) + private val blocksPerTick = register(Settings.integerBuilder("BlocksPerTick").withMinimum(1).withValue(1).withMaximum(10).withVisibility { page.value == Page.BEHAVIOR }) + private val tickDelayPlace = register(Settings.integerBuilder("TickDelayPlace").withMinimum(0).withValue(1).withMaximum(32).withVisibility { page.value == Page.BEHAVIOR }) + private val tickDelayBreak = register(Settings.integerBuilder("TickDelayBreak").withMinimum(0).withValue(1).withMaximum(32).withVisibility { page.value == Page.BEHAVIOR }) + private val interacting = register(Settings.enumBuilder(InteractMode::class.java).withName("InteractMode").withValue(InteractMode.SPOOF).withVisibility { page.value == Page.BEHAVIOR }) + private val autoCenter = register(Settings.enumBuilder(AutoCenterMode::class.java).withName("AutoCenter").withValue(AutoCenterMode.MOTION).withVisibility { page.value == Page.BEHAVIOR }) + private val stuckDelay = register(Settings.integerBuilder("TickDelayStuck").withMinimum(1).withValue(250).withMaximum(1000).withVisibility { page.value == Page.BEHAVIOR }) + val maxReach = register(Settings.floatBuilder("MaxReach").withMinimum(2.0F).withValue(5.4F).withVisibility { page.value == Page.BEHAVIOR }) + + // config + private val info = register(Settings.booleanBuilder("ShowInfo").withValue(true).withVisibility { page.value == Page.CONFIG }) + private val printDebug = register(Settings.booleanBuilder("ShowQueue").withValue(false).withVisibility { page.value == Page.CONFIG }) + private val debugMessages = register(Settings.enumBuilder(DebugMessages::class.java).withName("Debug").withValue(DebugMessages.IMPORTANT).withVisibility { page.value == Page.CONFIG }) + private val goalRender = register(Settings.booleanBuilder("GoalRender").withValue(false).withVisibility { page.value == Page.CONFIG }) + private val filled = register(Settings.booleanBuilder("Filled").withValue(true).withVisibility { page.value == Page.CONFIG }) + private val outline = register(Settings.booleanBuilder("Outline").withValue(true).withVisibility { page.value == Page.CONFIG }) + private val aFilled = register(Settings.integerBuilder("FilledAlpha").withMinimum(0).withValue(26).withMaximum(255).withVisibility { filled.value && page.value == Page.CONFIG }) + private val aOutline = register(Settings.integerBuilder("OutlineAlpha").withMinimum(0).withValue(91).withMaximum(255).withVisibility { outline.value && page.value == Page.CONFIG }) + + // internal settings val ignoreBlocks = mutableListOf(Blocks.STANDING_SIGN, Blocks.WALL_SIGN, Blocks.STANDING_BANNER, Blocks.WALL_BANNER, Blocks.BEDROCK, Blocks.PORTAL) var material: Block = Blocks.OBSIDIAN var fillerMat: Block = Blocks.NETHERRACK @@ -102,7 +102,6 @@ object HighwayTools : Module() { private var waitTicks = 0 private var blocksPlaced = 0 var pathing = false - private var isSneaking = false private var stuckBuilding = 0 private var stuckMining = 0 private lateinit var currentBlockPos: BlockPos @@ -112,6 +111,60 @@ object HighwayTools : Module() { private var totalBlocksPlaced = 0 private var totalBlocksDestroyed = 0 + init { + listener { + if (mc.playerController == null) return@listener + BaritoneAPI.getProvider().primaryBaritone.pathingControlManager.registerProcess(HighwayToolsProcess) + + if (baritoneMode.value) { + pathing = BaritoneAPI.getProvider().primaryBaritone.pathingBehavior.isPathing + if (!isDone()) { + if (!doTask()) { + if (!pathing && !LagNotifier.paused && !AutoObsidian.active) { + stuckBuilding += 1 + shuffleTasks() + if (debugMessages.value == DebugMessages.ALL) MessageSendHelper.sendChatMessage("$chatName Shuffled tasks (x$stuckBuilding)") + if (stuckBuilding > blockOffsets.size) { + refreshData() + if (debugMessages.value == DebugMessages.IMPORTANT) MessageSendHelper.sendChatMessage("$chatName You got stuck, retry") + } + } else { + refreshData() + } + } else { + stuckBuilding = 0 + } + } else { + refreshData() + if (checkTasks() && !pathing) { + currentBlockPos = getNextBlock() + doneQueue.clear() + updateTasks() + } + } + } else { + if (currentBlockPos == mc.player.positionVector.toBlockPos()) { + if (!doTask()) { + shuffleTasks() + } + } else { + currentBlockPos = mc.player.positionVector.toBlockPos() + if (abs((buildDirectionSaved.ordinal - getPlayerCardinal(mc.player).ordinal) % 8) == 4) buildDirectionSaved = getPlayerCardinal(mc.player) + refreshData() + } + } + } + + listener { + if (mc.player == null) return@listener + val renderer = ESPRenderer() + renderer.aFilled = if (filled.value) aFilled.value else 0 + renderer.aOutline = if (outline.value) aOutline.value else 0 + updateRenderer(renderer) + renderer.render(true) + } + } + fun isDone(): Boolean { return blockQueue.size == 0 } @@ -150,10 +203,6 @@ object HighwayTools : Module() { if (lastHotbarSlot != playerHotbarSlot && playerHotbarSlot != -1) { mc.player.inventory.currentItem = playerHotbarSlot } - if (isSneaking) { - mc.player.connection.sendPacket(CPacketEntityAction(mc.player, CPacketEntityAction.Action.STOP_SNEAKING)) - isSneaking = false - } playerHotbarSlot = -1 lastHotbarSlot = -1 @@ -169,48 +218,6 @@ object HighwayTools : Module() { totalBlocksDestroyed = 0 } - override fun onUpdate() { - if (mc.playerController == null) return - - if (baritoneMode.value) { - pathing = BaritoneAPI.getProvider().primaryBaritone.pathingBehavior.isPathing - if (!isDone()) { - if (!doTask()) { - if (!pathing && !LagNotifier.paused && !AutoObsidian.active) { - stuckBuilding += 1 - shuffleTasks() - if (debugMessages.value == DebugMessages.ALL) MessageSendHelper.sendChatMessage("$chatName Shuffled tasks (x$stuckBuilding)") - if (stuckBuilding > blockOffsets.size) { - refreshData() - if (debugMessages.value == DebugMessages.IMPORTANT) MessageSendHelper.sendChatMessage("$chatName You got stuck, retry") - } - } else { - refreshData() - } - } else { - stuckBuilding = 0 - } - } else { - refreshData() - if (checkTasks() && !pathing) { - currentBlockPos = getNextBlock() - doneQueue.clear() - updateTasks() - } - } - } else { - if (currentBlockPos == mc.player.positionVector.toBlockPos()) { - if (!doTask()) { - shuffleTasks() - } - } else { - currentBlockPos = mc.player.positionVector.toBlockPos() - if (abs((buildDirectionSaved.ordinal - getPlayerCardinal(mc.player).ordinal) % 8) == 4) buildDirectionSaved = getPlayerCardinal(mc.player) - refreshData() - } - } - } - private fun addTask(blockPos: BlockPos, taskState: TaskState, material: Block) { blockQueue.add(BlockTask(blockPos, taskState, material)) } @@ -236,133 +243,163 @@ object HighwayTools : Module() { } private fun doTask(): Boolean { - BaritoneAPI.getProvider().primaryBaritone.pathingControlManager.registerProcess(HighwayToolsProcess) if (!isDone() && !pathing && !LagNotifier.paused && !AutoObsidian.active) { if (waitTicks == 0) { - if (mc.player.posX != CenterPlayer.getPosX(1.0f) || mc.player.posZ != CenterPlayer.getPosZ(1.0f)) CenterPlayer.centerPlayer(1.0f) - if (printDebug.value) printDebug() - val blockTask = blockQueue.peek() + centerPlayer() + if (printDebug.value) printDebug() when (blockTask.taskState) { - TaskState.DONE -> { - blockQueue.poll() - doneQueue.add(blockTask) - doTask() - } - TaskState.BREAKING -> { - if (stuckMining > stuckDelay.value) { - stuckMining = 0 - updateTask(blockTask, TaskState.BREAK) - refreshData() - shuffleTasks() - if (debugMessages.value == DebugMessages.IMPORTANT) MessageSendHelper.sendChatMessage("Shuffled because of mining issue.") - } + TaskState.DONE -> doDONE(blockTask) + TaskState.BREAKING -> doBREAKING(blockTask) + TaskState.PLACED -> doPLACED(blockTask) + TaskState.BREAK -> if(!doBREAK(blockTask)) return false + TaskState.PLACE, TaskState.LIQUID_SOURCE, TaskState.LIQUID_FLOW -> if(!doPLACE(blockTask)) return false + } + } else { + waitTicks-- + } + return true + } else { + return false + } + } - when (mc.world.getBlockState(blockTask.blockPos).block) { - Blocks.AIR -> { - stuckMining = 0 - totalBlocksDestroyed++ - waitTicks = tickDelayBreak.value - if (blockTask.block == material || blockTask.block == fillerMat) { - updateTask(blockTask, TaskState.PLACE) - } else { - updateTask(blockTask, TaskState.DONE) - doTask() - } - } - Blocks.LAVA -> { - updateTask(blockTask, TaskState.LIQUID_SOURCE) - updateTask(blockTask, fillerMat) - } - Blocks.FLOWING_LAVA -> { - updateTask(blockTask, TaskState.LIQUID_FLOW) - updateTask(blockTask, fillerMat) - } - else -> { - mineBlock(blockTask.blockPos, false) - stuckMining++ - } - } - } - TaskState.PLACED -> { - val block = mc.world.getBlockState(blockTask.blockPos).block + private fun doDONE(blockTask: BlockTask) { + blockQueue.poll() + doneQueue.add(blockTask) + doTask() + } - when { - blockTask.block == block && block != Blocks.AIR -> updateTask(blockTask, TaskState.DONE) - blockTask.block == Blocks.AIR && block != Blocks.AIR -> updateTask(blockTask, TaskState.BREAK) - else -> updateTask(blockTask, TaskState.PLACE) - } - doTask() - } - TaskState.BREAK -> { - val block = mc.world.getBlockState(blockTask.blockPos).block - - // ignore blocks - for (b in ignoreBlocks) { - if (block == b) { - updateTask(blockTask, TaskState.DONE) - doTask() - } - } + private fun doBREAKING(blockTask: BlockTask) { + if (stuckMining > stuckDelay.value) { - // liquid search around the breaking block - if (liquidHandler(blockTask.blockPos)) return false + // ToDo: Make this more reliable for high TPS - // last check before breaking - when (block) { - Blocks.AIR -> { - updateTask(blockTask, TaskState.DONE) - doTask() - } - Blocks.LAVA -> { - updateTask(blockTask, TaskState.LIQUID_SOURCE) - updateTask(blockTask, fillerMat) - } - Blocks.FLOWING_LAVA -> { - updateTask(blockTask, TaskState.LIQUID_FLOW) - updateTask(blockTask, fillerMat) - } - else -> { - if (!mineBlock(blockTask.blockPos, true)) { - shuffleTasks() - } else { - updateTask(blockTask, TaskState.BREAKING) - } - } - } - } - TaskState.PLACE, TaskState.LIQUID_SOURCE, TaskState.LIQUID_FLOW -> { - val block = mc.world.getBlockState(blockTask.blockPos).block + stuckMining = 0 + updateTask(blockTask, TaskState.BREAK) + refreshData() + shuffleTasks() + if (debugMessages.value == DebugMessages.IMPORTANT) MessageSendHelper.sendChatMessage("Shuffled because of mining issue.") + } - if (blockTask.block == Blocks.AIR && block !is BlockLiquid) { - blockQueue.poll() - return true - } + when (mc.world.getBlockState(blockTask.blockPos).block) { + Blocks.AIR -> { + stuckMining = 0 + totalBlocksDestroyed++ + waitTicks = tickDelayBreak.value + if (blockTask.block == material || blockTask.block == fillerMat) { + updateTask(blockTask, TaskState.PLACE) + } else { + updateTask(blockTask, TaskState.DONE) + doTask() + } + } + Blocks.LAVA -> { + updateTask(blockTask, TaskState.LIQUID_SOURCE) + updateTask(blockTask, fillerMat) + } + Blocks.FLOWING_LAVA -> { + updateTask(blockTask, TaskState.LIQUID_FLOW) + updateTask(blockTask, fillerMat) + } + else -> { + mineBlock(blockTask.blockPos, false) + stuckMining++ + } + } + } - if (!placeBlock(blockTask.blockPos, blockTask.block)) return false - if (blockTask.taskState != TaskState.PLACE && isInsideBuild(blockTask.blockPos)) updateTask(blockTask, Blocks.AIR) - updateTask(blockTask, TaskState.PLACED) - if (blocksPerTick.value > blocksPlaced + 1) { - blocksPlaced++ - doTask() - } else { - blocksPlaced = 0 - } + private fun doPLACED(blockTask: BlockTask) { + val block = mc.world.getBlockState(blockTask.blockPos).block - waitTicks = tickDelayPlace.value - totalBlocksPlaced++ - } + when { + blockTask.block == block && block != Blocks.AIR -> updateTask(blockTask, TaskState.DONE) + blockTask.block == Blocks.AIR && block != Blocks.AIR -> updateTask(blockTask, TaskState.BREAK) + else -> updateTask(blockTask, TaskState.PLACE) + } + doTask() + } + + private fun doBREAK(blockTask: BlockTask): Boolean { + val block = mc.world.getBlockState(blockTask.blockPos).block + + // ignore blocks + for (b in ignoreBlocks) { + if (block == b) { + updateTask(blockTask, TaskState.DONE) + doTask() + } + } + + // last check before breaking + when (block) { + Blocks.AIR -> { + updateTask(blockTask, TaskState.DONE) + doTask() + } + Blocks.LAVA -> { + updateTask(blockTask, TaskState.LIQUID_SOURCE) + updateTask(blockTask, fillerMat) + } + Blocks.FLOWING_LAVA -> { + updateTask(blockTask, TaskState.LIQUID_FLOW) + updateTask(blockTask, fillerMat) + } + else -> { + // liquid search around the breaking block + if (liquidHandler(blockTask.blockPos)) return false + + // ToDo: inventory management function + + if (!mineBlock(blockTask.blockPos, true)) { + shuffleTasks() + } else { + updateTask(blockTask, TaskState.BREAKING) } - } else { - waitTicks-- } + } + return true + } + + private fun doPLACE(blockTask: BlockTask): Boolean { + val block = mc.world.getBlockState(blockTask.blockPos).block + + if (blockTask.block == Blocks.AIR && block !is BlockLiquid) { + blockQueue.poll() return true - } else { - return false } + + when { + block == material && block == blockTask.block -> updateTask(blockTask, TaskState.PLACED) + block == fillerMat && block == blockTask.block -> updateTask(blockTask, TaskState.PLACED) + else -> { + + // ToDo: inventory management function + //if (!placeBlock(blockTask.blockPos, blockTask.block)) return false + if (!BlockUtils.isPlaceable(blockTask.blockPos)) { + if (debugMessages.value == DebugMessages.ALL) MessageSendHelper.sendChatMessage("Error: " + blockTask.blockPos + " is not a valid position to place a block.") + return false + } + + placeBlock(blockTask.blockPos, blockTask.block) + if (blockTask.taskState != TaskState.PLACE && isInsideBuild(blockTask.blockPos)) updateTask(blockTask, Blocks.AIR) + updateTask(blockTask, TaskState.PLACED) + if (blocksPerTick.value > blocksPlaced + 1) { + blocksPlaced++ + doTask() + } else { + blocksPlaced = 0 + } + + waitTicks = tickDelayPlace.value + totalBlocksPlaced++ + } + } + return true } + private fun checkTasks(): Boolean { loop@ for (blockTask in doneQueue) { val block = mc.world.getBlockState(blockTask.blockPos).block @@ -457,16 +494,18 @@ object HighwayTools : Module() { } private fun mineBlock(pos: BlockPos, pre: Boolean): Boolean { - if (InventoryUtils.getSlotsHotbar(278) == null && InventoryUtils.getSlotsNoHotbar(278) != null) { - InventoryUtils.moveToHotbar(278, 130) - return true - } else if (InventoryUtils.getSlots(0, 35, 278) == null) { - MessageSendHelper.sendChatMessage("$chatName No Pickaxe was found in inventory") - mc.getSoundHandler().playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) - disable() - return false + if (pre) { + if (InventoryUtils.getSlotsHotbar(278) == null && InventoryUtils.getSlotsNoHotbar(278) != null) { + InventoryUtils.moveToHotbar(278, 130) + return true + } else if (InventoryUtils.getSlots(0, 35, 278) == null) { + MessageSendHelper.sendChatMessage("$chatName No Pickaxe was found in inventory") + mc.getSoundHandler().playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) + disable() + return false + } + InventoryUtils.swapSlotToItem(278) } - InventoryUtils.swapSlotToItem(278) var rayTrace = mc.world.rayTraceBlocks(mc.player.getPositionEyes(1f), Vec3d(pos).add(0.5, 0.5, 0.5)) if (rayTrace == null) { @@ -477,12 +516,8 @@ object HighwayTools : Module() { var found = false for (side in EnumFacing.values()) { if (mc.world.getBlockState(pos.offset(side)).block == Blocks.AIR) { - rayTrace = mc.world.rayTraceBlocks(mc.player.getPositionEyes(1f), Vec3d(pos).add(0.5, 0.5, 0.5).add(Vec3d(side.directionVec).scale(0.5))) - //MessageSendHelper.sendChatMessage(pos.offset(side).toString() + " - " + rayTrace.toString()) - //val lookAt = RotationUtils.getRotationTo(Vec3d(pos).add(0.5, 0.5, 0.5).add(Vec3d(side.directionVec).scale(0.5)), true) - //mc.player.rotationYaw = lookAt.x.toFloat() - //mc.player.rotationPitch = lookAt.y.toFloat() - if (rayTrace != null && rayTrace.blockPos == pos.offset(side)) { + rayTrace = mc.world.rayTraceBlocks(mc.player.getPositionEyes(1f), Vec3d(pos).add(0.5, 0.5, 0.5).add(Vec3d(side.directionVec).scale(0.499)))?: continue + if (rayTrace.blockPos == pos) { found = true break } @@ -495,50 +530,69 @@ object HighwayTools : Module() { } } val facing = rayTrace?.sideHit ?: return false - val lookAt = RotationUtils.getRotationTo(Vec3d(pos).add(0.5, 0.5, 0.5).add(Vec3d(facing.directionVec).scale(0.5)), true) + val rotation = RotationUtils.getRotationTo(Vec3d(pos).add(0.5, 0.5, 0.5).add(Vec3d(facing.directionVec).scale(0.499)), true) when (interacting.value) { InteractMode.SPOOF -> { - PlayerPacketManager.addPacket(this, PlayerPacketManager.PlayerPacket(rotating = true, rotation = Vec2f(lookAt.x.toFloat(), lookAt.y.toFloat()))) + val rotationPacket = CPacketPlayer.PositionRotation(mc.player.posX, mc.player.posY, mc.player.posZ, rotation.x.toFloat(), rotation.y.toFloat(), mc.player.onGround) + mc.connection!!.sendPacket(rotationPacket) } InteractMode.VIEWLOCK -> { - mc.player.rotationYaw = lookAt.x.toFloat() - mc.player.rotationPitch = lookAt.y.toFloat() + mc.player.rotationYaw = rotation.x.toFloat() + mc.player.rotationPitch = rotation.y.toFloat() } } - if (pre) { - mc.connection!!.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, pos, facing)) - } else { - mc.connection!!.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, pos, facing)) - } - mc.player.swingArm(EnumHand.MAIN_HAND) + Thread { + Thread.sleep(25L) + if (pre) { + mc.connection!!.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, pos, facing)) + } else { + mc.connection!!.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, pos, facing)) + } + mc.player.swingArm(EnumHand.MAIN_HAND) + }.start() return true } - private fun placeBlock(pos: BlockPos, mat: Block): Boolean - { - // check if block is already placed - val block = mc.world.getBlockState(pos).block - if (block != Blocks.AIR && block !is BlockLiquid) { - return false - } - - // check if entity blocks placing - for (entity in mc.world.getEntitiesWithinAABBExcludingEntity(null, AxisAlignedBB(pos))) { - if (entity !is EntityItem && entity !is EntityXPOrb) { - return false + // Only temporary till we found solution to avoid untraceable blocks + private fun placeBlockWall(pos: BlockPos, mat: Block) { + if (InventoryUtils.getSlotsHotbar(getIdFromBlock(mat)) == null && InventoryUtils.getSlotsNoHotbar(getIdFromBlock(mat)) != null) { + for (x in InventoryUtils.getSlotsNoHotbar(getIdFromBlock(mat))!!) { + InventoryUtils.quickMoveSlot(x) } + } else if (InventoryUtils.getSlots(0, 35, getIdFromBlock(mat)) == null) { + MessageSendHelper.sendChatMessage("$chatName No ${mat.localizedName} was found in inventory") + mc.getSoundHandler().playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) + disable() } - val side = getPlaceableSide(pos) ?: return false + InventoryUtils.swapSlotToItem(getIdFromBlock(mat)) - // check if we have a block adjacent to blockpos to click at + val side = getPlaceableSide(pos) ?: return val neighbour = pos.offset(side) - val opposite = side.opposite + val hitVec = Vec3d(neighbour).add(0.5, 0.5, 0.5).add(Vec3d(side.opposite.directionVec).scale(0.5)) + + val rotation = RotationUtils.getRotationTo(hitVec, true) + when (interacting.value) { + InteractMode.SPOOF -> { + val rotationPacket = CPacketPlayer.PositionRotation(mc.player.posX, mc.player.posY, mc.player.posZ, rotation.x.toFloat(), rotation.y.toFloat(), mc.player.onGround) + mc.connection!!.sendPacket(rotationPacket) + } + InteractMode.VIEWLOCK -> { + mc.player.rotationYaw = rotation.x.toFloat() + mc.player.rotationPitch = rotation.y.toFloat() + } + } - // check if neighbor can be right clicked - if (!BlockUtils.canBeClicked(neighbour)) return false + Thread{ + Thread.sleep(25L) + val placePacket = CPacketPlayerTryUseItemOnBlock(neighbour, side.opposite, EnumHand.MAIN_HAND, hitVec.x.toFloat(), hitVec.y.toFloat(), hitVec.z.toFloat()) + mc.connection!!.sendPacket(placePacket) + mc.player.swingArm(EnumHand.MAIN_HAND) + if (NoBreakAnimation.isEnabled) NoBreakAnimation.resetMining() + }.start() + } - // swap to material in Hotbar or get from inventory + private fun placeBlock(pos: BlockPos, mat: Block) { if (InventoryUtils.getSlotsHotbar(getIdFromBlock(mat)) == null && InventoryUtils.getSlotsNoHotbar(getIdFromBlock(mat)) != null) { // InventoryUtils.moveToHotbar(getIdFromBlock(mat), 130, (tickDelay.value * 16).toLong()) for (x in InventoryUtils.getSlotsNoHotbar(getIdFromBlock(mat))!!) { @@ -549,32 +603,60 @@ object HighwayTools : Module() { MessageSendHelper.sendChatMessage("$chatName No ${mat.localizedName} was found in inventory") mc.getSoundHandler().playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) disable() - return false } InventoryUtils.swapSlotToItem(getIdFromBlock(mat)) - val hitVec = Vec3d(neighbour).add(0.5, 0.5, 0.5).add(Vec3d(opposite.directionVec).scale(0.5)) - val neighbourBlock = mc.world.getBlockState(neighbour).block - if (!isSneaking && BlockUtils.blackList.contains(neighbourBlock) || BlockUtils.shulkerList.contains(neighbourBlock)) { - mc.player.connection.sendPacket(CPacketEntityAction(mc.player, CPacketEntityAction.Action.START_SNEAKING)) - isSneaking = true + + val rayTraces = mutableListOf() + for (side in EnumFacing.values()) { + val offPos = pos.offset(side) + if (mc.world.getBlockState(offPos).material.isReplaceable) continue + if (mc.player.getPositionEyes(1f).distanceTo(Vec3d(offPos).add(BlockUtils.getHitVecOffset(side))) > maxReach.value) continue + val rotationVector = Vec3d(offPos).add(0.5, 0.5, 0.5).add(Vec3d(side.opposite.directionVec).scale(0.499)) + val rt = mc.world.rayTraceBlocks(mc.player.getPositionEyes(1f), rotationVector)?: continue + if (rt.typeOfHit != RayTraceResult.Type.BLOCK) continue + if (rt.blockPos == offPos && offPos.offset(rt.sideHit) == pos) { + rayTraces.add(rt) + } + } + if (rayTraces.size == 0) { + MessageSendHelper.sendChatMessage("Trying to place through wall $pos") + placeBlockWall(pos, mat) + return + } + + var rayTrace: RayTraceResult? = null + var shortestRT = 99.0 + for (rt in rayTraces) { + if (mc.player.getPositionEyes(1f).distanceTo(Vec3d(rt.blockPos).add(BlockUtils.getHitVecOffset(rt.sideHit))) < shortestRT) { + shortestRT = mc.player.getPositionEyes(1f).distanceTo(Vec3d(rt.blockPos).add(BlockUtils.getHitVecOffset(rt.sideHit))) + rayTrace = rt + } + } + if (rayTrace == null) { + MessageSendHelper.sendChatMessage("Can't find any vector?") + return } + val hitVecOffset = rayTrace.hitVec + val rotation = RotationUtils.getRotationTo(hitVecOffset, true) when (interacting.value) { InteractMode.SPOOF -> { - val lookAt = RotationUtils.getRotationTo(hitVec, true) - PlayerPacketManager.addPacket(this, PlayerPacketManager.PlayerPacket(rotating = true, rotation = Vec2f(lookAt.x.toFloat(), lookAt.y.toFloat()))) + val rotationPacket = CPacketPlayer.PositionRotation(mc.player.posX, mc.player.posY, mc.player.posZ, rotation.x.toFloat(), rotation.y.toFloat(), mc.player.onGround) + mc.connection!!.sendPacket(rotationPacket) } InteractMode.VIEWLOCK -> { - val lookAt = RotationUtils.getRotationTo(hitVec, true) - mc.player.rotationYaw = lookAt.x.toFloat() - mc.player.rotationPitch = lookAt.y.toFloat() + mc.player.rotationYaw = rotation.x.toFloat() + mc.player.rotationPitch = rotation.y.toFloat() } } - mc.playerController.processRightClickBlock(mc.player, mc.world, neighbour, opposite, hitVec, EnumHand.MAIN_HAND) - mc.player.connection.sendPacket(CPacketAnimation(EnumHand.MAIN_HAND)) - mc.rightClickDelayTimer = 4 - if (NoBreakAnimation.isEnabled) NoBreakAnimation.resetMining() - return true + + Thread{ + Thread.sleep(25L) + val placePacket = CPacketPlayerTryUseItemOnBlock(rayTrace.blockPos, rayTrace.sideHit, EnumHand.MAIN_HAND, hitVecOffset.x.toFloat(), hitVecOffset.y.toFloat(), hitVecOffset.z.toFloat()) + mc.connection!!.sendPacket(placePacket) + mc.player.swingArm(EnumHand.MAIN_HAND) + if (NoBreakAnimation.isEnabled) NoBreakAnimation.resetMining() + }.start() } private fun getPlaceableSide(pos: BlockPos): EnumFacing? { @@ -594,6 +676,14 @@ object HighwayTools : Module() { return false } + private fun centerPlayer(): Boolean { + return if (autoCenter.value == Surround.AutoCenterMode.OFF) { + true + } else { + SurroundUtils.centerPlayer(autoCenter.value == Surround.AutoCenterMode.TP) + } + } + private fun updateRenderer(renderer: ESPRenderer): ESPRenderer { val side = GeometryMasks.Quad.ALL for (blockTask in blockQueue) { @@ -605,15 +695,6 @@ object HighwayTools : Module() { return renderer } - override fun onWorldRender(event: RenderEvent) { - if (mc.player == null) return - val renderer = ESPRenderer() - renderer.aFilled = if (filled.value) aFilled.value else 0 - renderer.aOutline = if (outline.value) aOutline.value else 0 - updateRenderer(renderer) - renderer.render(true) - } - private fun printDebug() { var message = "\n\n" message += "-------------------- QUEUE -------------------" @@ -724,9 +805,12 @@ object HighwayTools : Module() { } else -> { val evenCursor = relativeDirection(cursor, 1, 2) - blockOffsets.add(Pair(relativeDirection(evenCursor, width, 2), mat)) if (buildDirectionSaved.isDiagonal) { + blockOffsets.add(Pair(relativeDirection(evenCursor, width, 2), mat)) addOffset(cursor, height, width, mat, false) + addOffset(evenCursor, height, width, mat, false) + } else { + blockOffsets.add(Pair(relativeDirection(evenCursor, width, 2), mat)) } } } @@ -799,19 +883,32 @@ object HighwayTools : Module() { } private enum class DebugMessages { - NONE, IMPORTANT, ALL + OFF, + IMPORTANT, + ALL } private enum class Mode { - HIGHWAY, FLAT + HIGHWAY, + FLAT } private enum class Page { - BUILD, MAIN, CONFIG + BUILD, + BEHAVIOR, + CONFIG } private enum class InteractMode { - NONE, SPOOF, VIEWLOCK + OFF, + SPOOF, + VIEWLOCK + } + + enum class AutoCenterMode { + OFF, + TP, + MOTION } data class BlockTask(val blockPos: BlockPos, var taskState: TaskState, var block: Block) From 8d25a58d908e5d30bd8a9cff7f1b5cb11ee303d5 Mon Sep 17 00:00:00 2001 From: Christian Date: Mon, 19 Oct 2020 08:17:01 +0200 Subject: [PATCH 033/390] Improvements --- .../kami/module/modules/misc/HighwayTools.kt | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index c50efe6b37..865257b901 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -34,6 +34,7 @@ import net.minecraft.init.SoundEvents import net.minecraft.network.play.client.* 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.RayTraceResult import net.minecraft.util.math.Vec3d @@ -68,8 +69,8 @@ object HighwayTools : Module() { // behavior settings val baritoneMode = register(Settings.booleanBuilder("AutoMode").withValue(true).withVisibility { page.value == Page.BEHAVIOR }) private val blocksPerTick = register(Settings.integerBuilder("BlocksPerTick").withMinimum(1).withValue(1).withMaximum(10).withVisibility { page.value == Page.BEHAVIOR }) - private val tickDelayPlace = register(Settings.integerBuilder("TickDelayPlace").withMinimum(0).withValue(1).withMaximum(32).withVisibility { page.value == Page.BEHAVIOR }) - private val tickDelayBreak = register(Settings.integerBuilder("TickDelayBreak").withMinimum(0).withValue(1).withMaximum(32).withVisibility { page.value == Page.BEHAVIOR }) + private val tickDelayPlace = register(Settings.integerBuilder("TickDelayPlace").withMinimum(0).withValue(1).withMaximum(16).withVisibility { page.value == Page.BEHAVIOR }) + private val tickDelayBreak = register(Settings.integerBuilder("TickDelayBreak").withMinimum(0).withValue(1).withMaximum(16).withVisibility { page.value == Page.BEHAVIOR }) private val interacting = register(Settings.enumBuilder(InteractMode::class.java).withName("InteractMode").withValue(InteractMode.SPOOF).withVisibility { page.value == Page.BEHAVIOR }) private val autoCenter = register(Settings.enumBuilder(AutoCenterMode::class.java).withName("AutoCenter").withValue(AutoCenterMode.MOTION).withVisibility { page.value == Page.BEHAVIOR }) private val stuckDelay = register(Settings.integerBuilder("TickDelayStuck").withMinimum(1).withValue(250).withMaximum(1000).withVisibility { page.value == Page.BEHAVIOR }) @@ -123,7 +124,7 @@ object HighwayTools : Module() { if (!pathing && !LagNotifier.paused && !AutoObsidian.active) { stuckBuilding += 1 shuffleTasks() - if (debugMessages.value == DebugMessages.ALL) MessageSendHelper.sendChatMessage("$chatName Shuffled tasks (x$stuckBuilding)") + if (debugMessages.value == DebugMessages.ALL) MessageSendHelper.sendChatMessage("$chatName Shuffled tasks (${stuckBuilding}x)") if (stuckBuilding > blockOffsets.size) { refreshData() if (debugMessages.value == DebugMessages.IMPORTANT) MessageSendHelper.sendChatMessage("$chatName You got stuck, retry") @@ -376,9 +377,10 @@ object HighwayTools : Module() { else -> { // ToDo: inventory management function - //if (!placeBlock(blockTask.blockPos, blockTask.block)) return false + if (!BlockUtils.isPlaceable(blockTask.blockPos)) { - if (debugMessages.value == DebugMessages.ALL) MessageSendHelper.sendChatMessage("Error: " + blockTask.blockPos + " is not a valid position to place a block.") + if (debugMessages.value != DebugMessages.OFF) MessageSendHelper.sendChatMessage("Error: " + blockTask.blockPos + " is not a valid position to place a block, removing task.") + blockQueue.remove(blockTask) return false } From 4a96ce7937a380336a730356d6781ec3a9d380a3 Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 20 Oct 2020 08:52:00 +0200 Subject: [PATCH 034/390] First experiments with ray trace support and view spoofing --- .../kami/module/modules/misc/AutoObsidian.kt | 243 +++++++++++------- .../module/modules/player/NoBreakAnimation.kt | 2 +- 2 files changed, 157 insertions(+), 88 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt index dd1a12662a..faed216675 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt @@ -3,8 +3,10 @@ package me.zeroeightsix.kami.module.modules.misc import baritone.api.BaritoneAPI import me.zeroeightsix.kami.event.events.SafeTickEvent import me.zeroeightsix.kami.module.Module +import me.zeroeightsix.kami.module.modules.player.NoBreakAnimation import me.zeroeightsix.kami.process.AutoObsidianProcess import me.zeroeightsix.kami.setting.Settings +import me.zeroeightsix.kami.util.BlockUtils import me.zeroeightsix.kami.util.BlockUtils.isPlaceableForChest import me.zeroeightsix.kami.util.EntityUtils.getDroppedItem import me.zeroeightsix.kami.util.InventoryUtils @@ -14,20 +16,29 @@ import me.zeroeightsix.kami.util.text.MessageSendHelper.sendChatMessage import net.minecraft.block.BlockShulkerBox import net.minecraft.client.audio.PositionedSoundRecord import net.minecraft.client.gui.inventory.GuiShulkerBox +import net.minecraft.init.Blocks import net.minecraft.init.SoundEvents import net.minecraft.inventory.ClickType import net.minecraft.item.Item.getIdFromItem +import net.minecraft.network.play.client.CPacketPlayer import net.minecraft.network.play.client.CPacketPlayerDigging +import net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock import net.minecraft.util.EnumFacing import net.minecraft.util.EnumHand import net.minecraft.util.math.BlockPos +import net.minecraft.util.math.RayTraceResult import net.minecraft.util.math.Vec3d -import net.minecraftforge.fml.common.gameevent.TickEvent import java.util.concurrent.Executors import java.util.concurrent.TimeUnit import kotlin.math.ceil import kotlin.math.floor + +/** + * @author Xiaro? + * @updated by Avanatiker + * @since 19/10/2020 + */ @Module.Info( name = "AutoObsidian", category = Module.Category.MISC, @@ -39,12 +50,14 @@ object AutoObsidian : Module() { private val threshold = register(Settings.integerBuilder("RefillThreshold").withValue(8).withRange(1, 56).withVisibility { autoRefill.value }) private val targetStacks = register(Settings.integerBuilder("TargetStacks").withValue(1).withRange(1, 20)) private val delayTicks = register(Settings.integerBuilder("DelayTicks").withValue(5).withRange(0, 10)) + private val interacting = register(Settings.enumBuilder(InteractMode::class.java).withName("InteractMode").withValue(InteractMode.SPOOF)) + private val maxReach = register(Settings.floatBuilder("MaxReach").withMinimum(2.0F).withValue(5.4F)) enum class State { SEARCHING, PLACING, PRE_MINING, MINING, COLLECTING, DONE } - private enum class SearchingState { + enum class SearchingState { PLACING, OPENING, PRE_MINING, MINING, COLLECTING, DONE } @@ -73,8 +86,7 @@ object AutoObsidian : Module() { init { listener { - if (it.phase != TickEvent.Phase.END || mc.playerController == null) return@listener - + if (mc.playerController == null) return@listener /* Just a delay */ if (tickCount < delayTicks.value) { tickCount++ @@ -159,69 +171,46 @@ object AutoObsidian : Module() { } /* Updates main state */ - updateMainState() - - /* Updates searching state */ - if (state == State.SEARCHING && searchingState != SearchingState.DONE) { - updateSearchingState() - } else if (state != State.SEARCHING) { - searchingState = SearchingState.PLACING - } - } - - private fun updateMainState() { val placedEnderChest = enderChestCount - InventoryUtils.countItem(0, 35, 130) val targetEnderChest = (targetStacks.value * 64 - obsidianCount) / 8 state = when { - state == State.DONE && autoRefill.value && InventoryUtils.countItem(0, 35, 49) <= threshold.value -> { - State.SEARCHING - } - state == State.COLLECTING && getDroppedItem(49, 16.0f) == null -> { - State.DONE - } - state != State.DONE && mc.world.isAirBlock(placingPos) && placedEnderChest >= targetEnderChest -> { - State.COLLECTING - } - state == State.MINING && mc.world.isAirBlock(placingPos) -> { - State.PLACING - } - state == State.PLACING && !mc.world.isAirBlock(placingPos) -> { - State.PRE_MINING - } - state == State.SEARCHING && searchingState == SearchingState.DONE && placedEnderChest < targetEnderChest -> { - State.PLACING - } + state == State.DONE && autoRefill.value && InventoryUtils.countItem(0, 35, 49) <= threshold.value -> State.SEARCHING + state == State.COLLECTING && getDroppedItem(49, 16.0f) == null -> State.DONE + state != State.DONE && mc.world.isAirBlock(placingPos) && placedEnderChest >= targetEnderChest -> State.COLLECTING + state == State.MINING && mc.world.isAirBlock(placingPos) -> State.PLACING + state == State.PLACING && !mc.world.isAirBlock(placingPos) -> State.PRE_MINING + state == State.SEARCHING && searchingState == SearchingState.DONE && placedEnderChest < targetEnderChest -> State.PLACING else -> state } - } - private fun updateSearchingState() { - searchingState = when { - searchingState == SearchingState.PLACING && InventoryUtils.countItem(0, 35, 130) > 0 -> { - SearchingState.DONE - } - searchingState == SearchingState.COLLECTING && getDroppedItem(shulkerBoxId, 16.0f) == null -> { - SearchingState.DONE - } - searchingState == SearchingState.MINING && mc.world.isAirBlock(placingPos) -> { - if (InventoryUtils.countItem(0, 35, 130) > 0) { - SearchingState.COLLECTING - } else { /* In case if the shulker wasn't placed due to server lag */ - SearchingState.PLACING + /* Updates searching state */ + if (state == State.SEARCHING && searchingState != SearchingState.DONE) { + searchingState = when { + searchingState == SearchingState.PLACING && InventoryUtils.countItem(0, 35, 130) > 0 -> SearchingState.DONE + searchingState == SearchingState.COLLECTING && getDroppedItem(shulkerBoxId, 16.0f) == null -> SearchingState.DONE + searchingState == SearchingState.MINING && mc.world.isAirBlock(placingPos) -> { + if (InventoryUtils.countItem(0, 35, 130) > 0) { + SearchingState.COLLECTING + } else { /* In case if the shulker wasn't placed due to server lag */ + SearchingState.PLACING + } } - } - searchingState == SearchingState.OPENING && (InventoryUtils.countItem(0, 35, 130) >= 64 || InventoryUtils.getSlots(0, 35, 0) == null) -> { - SearchingState.PRE_MINING - } - searchingState == SearchingState.PLACING && !mc.world.isAirBlock(placingPos) -> { - if (mc.world.getBlockState(placingPos).block is BlockShulkerBox) { - SearchingState.OPENING - } else { /* In case if the shulker wasn't placed due to server lag */ - SearchingState.PRE_MINING + searchingState == SearchingState.OPENING && (InventoryUtils.countItem(0, 35, 130) >= 64 || InventoryUtils.getSlots(0, 35, 0) == null) -> SearchingState.PRE_MINING + searchingState == SearchingState.PLACING && !mc.world.isAirBlock(placingPos) -> { + if (mc.world.getBlockState(placingPos).block is BlockShulkerBox) { + SearchingState.OPENING + } else { /* In case if the shulker wasn't placed due to server lag */ + SearchingState.PRE_MINING + } } + else -> searchingState } - else -> searchingState - } + } else if (state != State.SEARCHING) searchingState = SearchingState.PLACING + + } + + private fun countObsidian(): Int { + return ceil(InventoryUtils.countItem(0, 35, 49).toDouble() / 8.0).toInt() * 8 } private fun setPlacingPos() { @@ -235,10 +224,6 @@ object AutoObsidian : Module() { } } - private fun countObsidian(): Int { - return ceil(InventoryUtils.countItem(0, 35, 49).toDouble() / 8.0).toInt() * 8 - } - private fun getPlacingPos(): BlockPos { val pos = playerPos var facing = EnumFacing.NORTH @@ -280,11 +265,7 @@ object AutoObsidian : Module() { } if (mc.world.getBlockState(pos).block !is BlockShulkerBox) { - lookAtBlock(pos) - mc.player.isSneaking = true - mc.playerController.processRightClickBlock(mc.player, mc.world, pos.down(), EnumFacing.UP, mc.objectMouseOver.hitVec, EnumHand.MAIN_HAND) - mc.player.swingArm(EnumHand.MAIN_HAND) - mc.rightClickDelayTimer = 4 + placeBlock(pos) } } @@ -304,11 +285,7 @@ object AutoObsidian : Module() { } InventoryUtils.swapSlotToItem(130) - lookAtBlock(pos) - mc.player.isSneaking = true - mc.playerController.processRightClickBlock(mc.player, mc.world, pos.down(), mc.objectMouseOver.sideHit, mc.objectMouseOver.hitVec, EnumHand.MAIN_HAND) - mc.player.swingArm(EnumHand.MAIN_HAND) - mc.rightClickDelayTimer = 4 + placeBlock(pos) } @@ -341,27 +318,113 @@ object AutoObsidian : Module() { } } - private fun mineBlock(pos: BlockPos, pre: Boolean) { - if (InventoryUtils.getSlotsHotbar(278) == null && InventoryUtils.getSlotsNoHotbar(278) != null) { - InventoryUtils.moveToHotbar(278, 130) + private fun placeBlock(pos: BlockPos) { + val rayTraces = mutableListOf() + for (side in EnumFacing.values()) { + val offPos = pos.offset(side) + if (mc.world.getBlockState(offPos).material.isReplaceable) continue + if (mc.player.getPositionEyes(1f).distanceTo(Vec3d(offPos).add(BlockUtils.getHitVecOffset(side))) > maxReach.value) continue + val rotationVector = Vec3d(offPos).add(0.5, 0.5, 0.5).add(Vec3d(side.opposite.directionVec).scale(0.499)) + val rt = mc.world.rayTraceBlocks(mc.player.getPositionEyes(1f), rotationVector)?: continue + if (rt.typeOfHit != RayTraceResult.Type.BLOCK) continue + if (rt.blockPos == offPos && offPos.offset(rt.sideHit) == pos) { + rayTraces.add(rt) + } + } + if (rayTraces.size == 0) { + sendChatMessage("Trying to place through wall $pos") + // placeBlockWall(pos, mat) return - } else if (InventoryUtils.getSlots(0, 35, 278) == null) { - sendChatMessage("$chatName No pickaxe was found in inventory, disabling.") - mc.getSoundHandler().playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) - this.disable() + } + + var rayTrace: RayTraceResult? = null + var shortestRT = 99.0 + for (rt in rayTraces) { + if (mc.player.getPositionEyes(1f).distanceTo(Vec3d(rt.blockPos).add(BlockUtils.getHitVecOffset(rt.sideHit))) < shortestRT) { + shortestRT = mc.player.getPositionEyes(1f).distanceTo(Vec3d(rt.blockPos).add(BlockUtils.getHitVecOffset(rt.sideHit))) + rayTrace = rt + } + } + if (rayTrace == null) { + sendChatMessage("Can't find any vector?") return } - InventoryUtils.swapSlotToItem(278) - lookAtBlock(pos) - /* Packet mining lol */ + val hitVecOffset = rayTrace.hitVec + val rotation = getRotationTo(hitVecOffset, true) + when (interacting.value) { + InteractMode.SPOOF -> { + val rotationPacket = CPacketPlayer.PositionRotation(mc.player.posX, mc.player.posY, mc.player.posZ, rotation.x.toFloat(), rotation.y.toFloat(), mc.player.onGround) + mc.connection!!.sendPacket(rotationPacket) + } + InteractMode.VIEWLOCK -> { + mc.player.rotationYaw = rotation.x.toFloat() + mc.player.rotationPitch = rotation.y.toFloat() + } + } + + Thread{ + Thread.sleep(25L) + val placePacket = CPacketPlayerTryUseItemOnBlock(rayTrace.blockPos, rayTrace.sideHit, EnumHand.MAIN_HAND, hitVecOffset.x.toFloat(), hitVecOffset.y.toFloat(), hitVecOffset.z.toFloat()) + mc.connection!!.sendPacket(placePacket) + mc.player.swingArm(EnumHand.MAIN_HAND) + if (NoBreakAnimation.isEnabled) NoBreakAnimation.resetMining() + }.start() + } + + private fun mineBlock(pos: BlockPos, pre: Boolean): Boolean { if (pre) { - mc.connection!!.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, pos, mc.objectMouseOver.sideHit)) - if (state != State.SEARCHING) state = State.MINING else searchingState = SearchingState.MINING - } else { - mc.connection!!.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, pos, mc.objectMouseOver.sideHit)) + if (InventoryUtils.getSlotsHotbar(278) == null && InventoryUtils.getSlotsNoHotbar(278) != null) { + InventoryUtils.moveToHotbar(278, 130) + return false + } else if (InventoryUtils.getSlots(0, 35, 278) == null) { + sendChatMessage("No pickaxe was found in inventory.") + mc.getSoundHandler().playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) + return false + } + InventoryUtils.swapSlotToItem(278) } - mc.player.swingArm(EnumHand.MAIN_HAND) + + var rayTrace = mc.world.rayTraceBlocks(mc.player.getPositionEyes(1f), Vec3d(pos).add(0.5, 0.5, 0.5)) ?: return false + if (rayTrace.blockPos != pos) { + var found = false + for (side in EnumFacing.values()) { + if (mc.world.getBlockState(pos.offset(side)).block == Blocks.AIR) { + rayTrace = mc.world.rayTraceBlocks(mc.player.getPositionEyes(1f), Vec3d(pos).add(0.5, 0.5, 0.5).add(Vec3d(side.directionVec).scale(0.499)))?: continue + if (rayTrace.blockPos == pos) { + found = true + break + } + } + } + if (!found) { + return false + } + } + val facing = rayTrace.sideHit ?: return false + val rotation = getRotationTo(Vec3d(pos).add(0.5, 0.5, 0.5).add(Vec3d(facing.directionVec).scale(0.499)), true) + when (interacting.value) { + InteractMode.SPOOF -> { + val rotationPacket = CPacketPlayer.PositionRotation(mc.player.posX, mc.player.posY, mc.player.posZ, rotation.x.toFloat(), rotation.y.toFloat(), mc.player.onGround) + mc.connection!!.sendPacket(rotationPacket) + } + InteractMode.VIEWLOCK -> { + mc.player.rotationYaw = rotation.x.toFloat() + mc.player.rotationPitch = rotation.y.toFloat() + } + } + + Thread { + Thread.sleep(25L) + if (pre) { + mc.connection!!.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, pos, facing)) + if (state != State.SEARCHING) state = State.MINING else searchingState = SearchingState.MINING + } else { + mc.connection!!.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, pos, facing)) + } + mc.player.swingArm(EnumHand.MAIN_HAND) + }.start() + return true } private fun collectDroppedItem(itemId: Int) { @@ -382,4 +445,10 @@ object AutoObsidian : Module() { tickCount = 0 } /* End of tasks */ + + private enum class InteractMode { + OFF, + SPOOF, + VIEWLOCK + } } \ No newline at end of file diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/player/NoBreakAnimation.kt b/src/main/java/me/zeroeightsix/kami/module/modules/player/NoBreakAnimation.kt index 9f89fe0fb0..04d0a6d98b 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/player/NoBreakAnimation.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/player/NoBreakAnimation.kt @@ -57,7 +57,7 @@ object NoBreakAnimation : Module() { } } - private fun resetMining() { + fun resetMining() { isMining = false lastPos = null lastFacing = null From 109aec0496b37e6a0bfba2776be08ec07f80bc04 Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 20 Oct 2020 09:08:37 +0200 Subject: [PATCH 035/390] Full spoof mode with ray trace --- .../kami/module/modules/misc/AutoObsidian.kt | 46 +++++++++++++++---- 1 file changed, 37 insertions(+), 9 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt index faed216675..b4f9aa2a4b 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt @@ -241,13 +241,6 @@ object AutoObsidian : Module() { return BlockPos(0, -1, 0) } - private fun lookAtBlock(pos: BlockPos) { - val vec3d = Vec3d(pos).add(0.5, 0.0, 0.5) - val lookAt = getRotationTo(vec3d, true) - mc.player.rotationYaw = lookAt.x.toFloat() - mc.player.rotationPitch = lookAt.y.toFloat() - } - /* Tasks */ private fun placeShulker(pos: BlockPos) { for (i in 219..234) { @@ -290,12 +283,47 @@ object AutoObsidian : Module() { private fun openShulker(pos: BlockPos) { - lookAtBlock(pos) + var rayTrace = mc.world.rayTraceBlocks(mc.player.getPositionEyes(1f), Vec3d(pos).add(0.5, 0.5, 0.5)) ?: return + if (rayTrace.blockPos != pos) { + var found = false + for (side in EnumFacing.values()) { + if (mc.world.getBlockState(pos.offset(side)).block == Blocks.AIR) { + rayTrace = mc.world.rayTraceBlocks(mc.player.getPositionEyes(1f), Vec3d(pos).add(0.5, 0.5, 0.5).add(Vec3d(side.directionVec).scale(0.499)))?: continue + if (rayTrace.blockPos == pos) { + found = true + break + } + } + } + if (!found) { + return + } + } + val facing = rayTrace.sideHit ?: return + val hitVecOffset = rayTrace.hitVec + val rotation = getRotationTo(Vec3d(pos).add(0.5, 0.5, 0.5).add(Vec3d(facing.directionVec).scale(0.499)), true) + when (interacting.value) { + InteractMode.SPOOF -> { + val rotationPacket = CPacketPlayer.PositionRotation(mc.player.posX, mc.player.posY, mc.player.posZ, rotation.x.toFloat(), rotation.y.toFloat(), mc.player.onGround) + mc.connection!!.sendPacket(rotationPacket) + } + InteractMode.VIEWLOCK -> { + mc.player.rotationYaw = rotation.x.toFloat() + mc.player.rotationPitch = rotation.y.toFloat() + } + } + if (mc.currentScreen !is GuiShulkerBox) { /* Added a delay here so it doesn't spam right click and get you kicked */ if (System.currentTimeMillis() >= openTime + 2000L) { openTime = System.currentTimeMillis() - mc.playerController.processRightClickBlock(mc.player, mc.world, pos, mc.objectMouseOver.sideHit, mc.objectMouseOver.hitVec, EnumHand.MAIN_HAND) + Thread{ + Thread.sleep(25L) + val placePacket = CPacketPlayerTryUseItemOnBlock(rayTrace.blockPos, rayTrace.sideHit, EnumHand.MAIN_HAND, hitVecOffset.x.toFloat(), hitVecOffset.y.toFloat(), hitVecOffset.z.toFloat()) + mc.connection!!.sendPacket(placePacket) + mc.player.swingArm(EnumHand.MAIN_HAND) + if (NoBreakAnimation.isEnabled) NoBreakAnimation.resetMining() + }.start() } } else { /* Extra delay here to wait for the item list to be loaded */ From 3ed83befa0c58cc3cfbe393ea283499bd7e27d96 Mon Sep 17 00:00:00 2001 From: Christian Date: Wed, 21 Oct 2020 03:47:47 +0200 Subject: [PATCH 036/390] LagNotifier and filler block fix --- .../zeroeightsix/kami/module/modules/misc/HighwayTools.kt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 865257b901..7803404077 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -9,6 +9,7 @@ import me.zeroeightsix.kami.module.modules.player.LagNotifier import me.zeroeightsix.kami.module.modules.player.NoBreakAnimation import me.zeroeightsix.kami.process.HighwayToolsProcess import me.zeroeightsix.kami.setting.Settings +import me.zeroeightsix.kami.util.BaritoneUtils import me.zeroeightsix.kami.util.BlockUtils import me.zeroeightsix.kami.util.InventoryUtils import me.zeroeightsix.kami.util.color.ColorHolder @@ -34,7 +35,6 @@ import net.minecraft.init.SoundEvents import net.minecraft.network.play.client.* 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.RayTraceResult import net.minecraft.util.math.Vec3d @@ -121,7 +121,7 @@ object HighwayTools : Module() { pathing = BaritoneAPI.getProvider().primaryBaritone.pathingBehavior.isPathing if (!isDone()) { if (!doTask()) { - if (!pathing && !LagNotifier.paused && !AutoObsidian.active) { + if (!pathing && !BaritoneUtils.paused && !AutoObsidian.isActive()) { stuckBuilding += 1 shuffleTasks() if (debugMessages.value == DebugMessages.ALL) MessageSendHelper.sendChatMessage("$chatName Shuffled tasks (${stuckBuilding}x)") @@ -439,8 +439,9 @@ object HighwayTools : Module() { } } fillerMat -> { + val blockUp = mc.world.getBlockState(blockPos.up()).block when { - getPlaceableSide(blockPos.up()) == null -> addTask(blockPos, TaskState.PLACE, fillerMat) + getPlaceableSide(blockPos.up()) == null && blockUp != material -> addTask(blockPos, TaskState.PLACE, fillerMat) getPlaceableSide(blockPos.up()) != null -> addTask(blockPos, fillerMat) } } From 38998d7514a037740246ff74381c164376420d7f Mon Sep 17 00:00:00 2001 From: Christian Date: Wed, 21 Oct 2020 04:36:21 +0200 Subject: [PATCH 037/390] Pathing goal fix --- .../kami/module/modules/misc/HighwayTools.kt | 37 ++++++++++--------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 7803404077..3cf7e119a2 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -119,28 +119,31 @@ object HighwayTools : Module() { if (baritoneMode.value) { pathing = BaritoneAPI.getProvider().primaryBaritone.pathingBehavior.isPathing - if (!isDone()) { - if (!doTask()) { - if (!pathing && !BaritoneUtils.paused && !AutoObsidian.isActive()) { - stuckBuilding += 1 - shuffleTasks() - if (debugMessages.value == DebugMessages.ALL) MessageSendHelper.sendChatMessage("$chatName Shuffled tasks (${stuckBuilding}x)") - if (stuckBuilding > blockOffsets.size) { + + if (relativeDirection(currentBlockPos, 1, 0) == mc.player.positionVector.toBlockPos()) { + if (!isDone()) { + if (!doTask()) { + if (!pathing && !BaritoneUtils.paused && !AutoObsidian.isActive()) { + stuckBuilding += 1 + shuffleTasks() + if (debugMessages.value == DebugMessages.ALL) MessageSendHelper.sendChatMessage("$chatName Shuffled tasks (${stuckBuilding}x)") + if (stuckBuilding > blockOffsets.size) { + refreshData() + if (debugMessages.value == DebugMessages.IMPORTANT) MessageSendHelper.sendChatMessage("$chatName You got stuck, retry") + } + } else { refreshData() - if (debugMessages.value == DebugMessages.IMPORTANT) MessageSendHelper.sendChatMessage("$chatName You got stuck, retry") } } else { - refreshData() + stuckBuilding = 0 } } else { - stuckBuilding = 0 - } - } else { - refreshData() - if (checkTasks() && !pathing) { - currentBlockPos = getNextBlock() - doneQueue.clear() - updateTasks() + refreshData() + if (checkTasks() && !pathing) { + currentBlockPos = getNextBlock() + doneQueue.clear() + updateTasks() + } } } } else { From b48f5fe299f4a41feebc34554ce9366746e4a3a1 Mon Sep 17 00:00:00 2001 From: Christian Date: Wed, 21 Oct 2020 07:37:22 +0200 Subject: [PATCH 038/390] Removed a lot of usage bugs PS: Please fix SaveTickEvent not to trigger twice each tick --- .../kami/module/modules/misc/HighwayTools.kt | 169 ++++++++++-------- .../module/modules/player/NoBreakAnimation.kt | 2 +- 2 files changed, 92 insertions(+), 79 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 3cf7e119a2..636e1896ac 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -5,7 +5,6 @@ import me.zeroeightsix.kami.event.events.RenderWorldEvent import me.zeroeightsix.kami.event.events.SafeTickEvent import me.zeroeightsix.kami.module.Module import me.zeroeightsix.kami.module.modules.combat.Surround -import me.zeroeightsix.kami.module.modules.player.LagNotifier import me.zeroeightsix.kami.module.modules.player.NoBreakAnimation import me.zeroeightsix.kami.process.HighwayToolsProcess import me.zeroeightsix.kami.setting.Settings @@ -25,7 +24,7 @@ import me.zeroeightsix.kami.util.math.VectorUtils import me.zeroeightsix.kami.util.math.VectorUtils.getDistance import me.zeroeightsix.kami.util.math.VectorUtils.toBlockPos import me.zeroeightsix.kami.util.math.VectorUtils.toVec3d -import me.zeroeightsix.kami.util.text.MessageSendHelper +import me.zeroeightsix.kami.util.text.MessageSendHelper.sendChatMessage import net.minecraft.block.Block import net.minecraft.block.Block.getIdFromBlock import net.minecraft.block.BlockLiquid @@ -64,16 +63,16 @@ object HighwayTools : Module() { private var buildWidth = register(Settings.integerBuilder("BuildWidth").withMinimum(1).withValue(5).withMaximum(9).withVisibility { page.value == Page.BUILD }) private val railing = register(Settings.booleanBuilder("Railing").withValue(true).withVisibility { page.value == Page.BUILD }) private var railingHeight = register(Settings.integerBuilder("RailingHeight").withMinimum(0).withValue(1).withMaximum(clearHeight.value).withVisibility { railing.value && page.value == Page.BUILD }) - private val cornerBlock = register(Settings.booleanBuilder("CornerBlock").withValue(true).withVisibility { page.value == Page.BUILD }) + private val cornerBlock = register(Settings.booleanBuilder("CornerBlock").withValue(false).withVisibility { page.value == Page.BUILD }) // behavior settings val baritoneMode = register(Settings.booleanBuilder("AutoMode").withValue(true).withVisibility { page.value == Page.BEHAVIOR }) private val blocksPerTick = register(Settings.integerBuilder("BlocksPerTick").withMinimum(1).withValue(1).withMaximum(10).withVisibility { page.value == Page.BEHAVIOR }) - private val tickDelayPlace = register(Settings.integerBuilder("TickDelayPlace").withMinimum(0).withValue(1).withMaximum(16).withVisibility { page.value == Page.BEHAVIOR }) - private val tickDelayBreak = register(Settings.integerBuilder("TickDelayBreak").withMinimum(0).withValue(1).withMaximum(16).withVisibility { page.value == Page.BEHAVIOR }) + private val tickDelayPlace = register(Settings.integerBuilder("TickDelayPlace").withMinimum(0).withValue(3).withMaximum(16).withVisibility { page.value == Page.BEHAVIOR }) + private val tickDelayBreak = register(Settings.integerBuilder("TickDelayBreak").withMinimum(0).withValue(0).withMaximum(16).withVisibility { page.value == Page.BEHAVIOR }) private val interacting = register(Settings.enumBuilder(InteractMode::class.java).withName("InteractMode").withValue(InteractMode.SPOOF).withVisibility { page.value == Page.BEHAVIOR }) private val autoCenter = register(Settings.enumBuilder(AutoCenterMode::class.java).withName("AutoCenter").withValue(AutoCenterMode.MOTION).withVisibility { page.value == Page.BEHAVIOR }) - private val stuckDelay = register(Settings.integerBuilder("TickDelayStuck").withMinimum(1).withValue(250).withMaximum(1000).withVisibility { page.value == Page.BEHAVIOR }) + private val stuckDelay = register(Settings.integerBuilder("TickDelayStuck").withMinimum(1).withValue(200).withMaximum(500).withVisibility { page.value == Page.BEHAVIOR }) val maxReach = register(Settings.floatBuilder("MaxReach").withMinimum(2.0F).withValue(5.4F).withVisibility { page.value == Page.BEHAVIOR }) // config @@ -105,8 +104,10 @@ object HighwayTools : Module() { var pathing = false private var stuckBuilding = 0 private var stuckMining = 0 - private lateinit var currentBlockPos: BlockPos + private var currentBlockPos = BlockPos(0, 0, 0) private lateinit var startingBlockPos: BlockPos + private var lastViewVec: RayTraceResult? = null + private var ticks = true // stats private var totalBlocksPlaced = 0 @@ -114,48 +115,54 @@ object HighwayTools : Module() { init { listener { - if (mc.playerController == null) return@listener - BaritoneAPI.getProvider().primaryBaritone.pathingControlManager.registerProcess(HighwayToolsProcess) - - if (baritoneMode.value) { - pathing = BaritoneAPI.getProvider().primaryBaritone.pathingBehavior.isPathing + if (ticks) { + ticks = !ticks + } else { + ticks = !ticks + if (mc.playerController == null) return@listener + BaritoneAPI.getProvider().primaryBaritone.pathingControlManager.registerProcess(HighwayToolsProcess) - if (relativeDirection(currentBlockPos, 1, 0) == mc.player.positionVector.toBlockPos()) { - if (!isDone()) { - if (!doTask()) { - if (!pathing && !BaritoneUtils.paused && !AutoObsidian.isActive()) { - stuckBuilding += 1 - shuffleTasks() - if (debugMessages.value == DebugMessages.ALL) MessageSendHelper.sendChatMessage("$chatName Shuffled tasks (${stuckBuilding}x)") - if (stuckBuilding > blockOffsets.size) { + if (baritoneMode.value) { + pathing = BaritoneAPI.getProvider().primaryBaritone.pathingBehavior.isPathing + + if (relativeDirection(currentBlockPos, 1, 0) == mc.player.positionVector.toBlockPos()) { + if (!isDone()) { + centerPlayer() + if (!doTask()) { + if (!pathing && !BaritoneUtils.paused && !AutoObsidian.isActive()) { + stuckBuilding += 1 + shuffleTasks() + if (debugMessages.value == DebugMessages.ALL) sendChatMessage("$chatName Shuffled tasks (${stuckBuilding}x)") + if (stuckBuilding > blockOffsets.size) { + refreshData() + if (debugMessages.value == DebugMessages.IMPORTANT) sendChatMessage("$chatName You got stuck, retry") + } + } else { refreshData() - if (debugMessages.value == DebugMessages.IMPORTANT) MessageSendHelper.sendChatMessage("$chatName You got stuck, retry") } } else { - refreshData() + stuckBuilding = 0 } } else { - stuckBuilding = 0 + refreshData() + if (checkTasks() && !pathing) { + currentBlockPos = getNextBlock() + doneQueue.clear() + updateTasks() + } + } + } + } else { + if (currentBlockPos == mc.player.positionVector.toBlockPos()) { + if (!doTask()) { + shuffleTasks() } } else { + currentBlockPos = mc.player.positionVector.toBlockPos() + if (abs((buildDirectionSaved.ordinal - getPlayerCardinal(mc.player).ordinal) % 8) == 4) buildDirectionSaved = getPlayerCardinal(mc.player) refreshData() - if (checkTasks() && !pathing) { - currentBlockPos = getNextBlock() - doneQueue.clear() - updateTasks() - } } } - } else { - if (currentBlockPos == mc.player.positionVector.toBlockPos()) { - if (!doTask()) { - shuffleTasks() - } - } else { - currentBlockPos = mc.player.positionVector.toBlockPos() - if (abs((buildDirectionSaved.ordinal - getPlayerCardinal(mc.player).ordinal) % 8) == 4) buildDirectionSaved = getPlayerCardinal(mc.player) - refreshData() - } } } @@ -247,11 +254,10 @@ object HighwayTools : Module() { } private fun doTask(): Boolean { - if (!isDone() && !pathing && !LagNotifier.paused && !AutoObsidian.active) { + if (!isDone() && !pathing && !BaritoneUtils.paused && !AutoObsidian.isActive()) { if (waitTicks == 0) { val blockTask = blockQueue.peek() - centerPlayer() if (printDebug.value) printDebug() when (blockTask.taskState) { TaskState.DONE -> doDONE(blockTask) @@ -284,7 +290,7 @@ object HighwayTools : Module() { updateTask(blockTask, TaskState.BREAK) refreshData() shuffleTasks() - if (debugMessages.value == DebugMessages.IMPORTANT) MessageSendHelper.sendChatMessage("Shuffled because of mining issue.") + if (debugMessages.value == DebugMessages.IMPORTANT) sendChatMessage("Shuffled because of mining issue.") } when (mc.world.getBlockState(blockTask.blockPos).block) { @@ -382,12 +388,12 @@ object HighwayTools : Module() { // ToDo: inventory management function if (!BlockUtils.isPlaceable(blockTask.blockPos)) { - if (debugMessages.value != DebugMessages.OFF) MessageSendHelper.sendChatMessage("Error: " + blockTask.blockPos + " is not a valid position to place a block, removing task.") + if (debugMessages.value != DebugMessages.OFF) sendChatMessage("Error: " + blockTask.blockPos + " is not a valid position to place a block, removing task.") blockQueue.remove(blockTask) return false } - placeBlock(blockTask.blockPos, blockTask.block) + if (!placeBlock(blockTask.blockPos, blockTask.block)) return false if (blockTask.taskState != TaskState.PLACE && isInsideBuild(blockTask.blockPos)) updateTask(blockTask, Blocks.AIR) updateTask(blockTask, TaskState.PLACED) if (blocksPerTick.value > blocksPlaced + 1) { @@ -500,43 +506,49 @@ object HighwayTools : Module() { } private fun mineBlock(pos: BlockPos, pre: Boolean): Boolean { + var rayTrace: RayTraceResult? if (pre) { if (InventoryUtils.getSlotsHotbar(278) == null && InventoryUtils.getSlotsNoHotbar(278) != null) { InventoryUtils.moveToHotbar(278, 130) return true } else if (InventoryUtils.getSlots(0, 35, 278) == null) { - MessageSendHelper.sendChatMessage("$chatName No Pickaxe was found in inventory") + sendChatMessage("$chatName No Pickaxe was found in inventory") mc.getSoundHandler().playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) disable() return false } InventoryUtils.swapSlotToItem(278) - } - var rayTrace = mc.world.rayTraceBlocks(mc.player.getPositionEyes(1f), Vec3d(pos).add(0.5, 0.5, 0.5)) - if (rayTrace == null) { - refreshData() - return false - } - if (rayTrace.blockPos != pos) { - var found = false - for (side in EnumFacing.values()) { - if (mc.world.getBlockState(pos.offset(side)).block == Blocks.AIR) { - rayTrace = mc.world.rayTraceBlocks(mc.player.getPositionEyes(1f), Vec3d(pos).add(0.5, 0.5, 0.5).add(Vec3d(side.directionVec).scale(0.499)))?: continue - if (rayTrace.blockPos == pos) { - found = true - break - } - } - } - if (!found) { + rayTrace = mc.world.rayTraceBlocks(mc.player.getPositionEyes(1f), Vec3d(pos).add(0.5, 0.5, 0.5)) + if (rayTrace == null) { refreshData() - shuffleTasks() return false } + if (rayTrace.blockPos != pos) { + var found = false + for (side in EnumFacing.values()) { + if (mc.world.getBlockState(pos.offset(side)).block == Blocks.AIR) { + rayTrace = mc.world.rayTraceBlocks(mc.player.getPositionEyes(1f), Vec3d(pos).add(0.5, 0.5, 0.5).add(Vec3d(side.directionVec).scale(0.499)))?: continue + if (rayTrace.blockPos == pos) { + found = true + break + } + } + } + if (!found) { + refreshData() + shuffleTasks() + return false + } + } + lastViewVec = rayTrace + } else { + rayTrace = lastViewVec } + val facing = rayTrace?.sideHit ?: return false val rotation = RotationUtils.getRotationTo(Vec3d(pos).add(0.5, 0.5, 0.5).add(Vec3d(facing.directionVec).scale(0.499)), true) + when (interacting.value) { InteractMode.SPOOF -> { val rotationPacket = CPacketPlayer.PositionRotation(mc.player.posX, mc.player.posY, mc.player.posZ, rotation.x.toFloat(), rotation.y.toFloat(), mc.player.onGround) @@ -561,19 +573,19 @@ object HighwayTools : Module() { } // Only temporary till we found solution to avoid untraceable blocks - private fun placeBlockWall(pos: BlockPos, mat: Block) { + private fun placeBlockWall(pos: BlockPos, mat: Block): Boolean { if (InventoryUtils.getSlotsHotbar(getIdFromBlock(mat)) == null && InventoryUtils.getSlotsNoHotbar(getIdFromBlock(mat)) != null) { for (x in InventoryUtils.getSlotsNoHotbar(getIdFromBlock(mat))!!) { InventoryUtils.quickMoveSlot(x) } } else if (InventoryUtils.getSlots(0, 35, getIdFromBlock(mat)) == null) { - MessageSendHelper.sendChatMessage("$chatName No ${mat.localizedName} was found in inventory") + sendChatMessage("$chatName No ${mat.localizedName} was found in inventory") mc.getSoundHandler().playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) disable() } InventoryUtils.swapSlotToItem(getIdFromBlock(mat)) - val side = getPlaceableSide(pos) ?: return + val side = getPlaceableSide(pos) ?: return false val neighbour = pos.offset(side) val hitVec = Vec3d(neighbour).add(0.5, 0.5, 0.5).add(Vec3d(side.opposite.directionVec).scale(0.5)) @@ -596,9 +608,10 @@ object HighwayTools : Module() { mc.player.swingArm(EnumHand.MAIN_HAND) if (NoBreakAnimation.isEnabled) NoBreakAnimation.resetMining() }.start() + return true } - private fun placeBlock(pos: BlockPos, mat: Block) { + private fun placeBlock(pos: BlockPos, mat: Block): Boolean { if (InventoryUtils.getSlotsHotbar(getIdFromBlock(mat)) == null && InventoryUtils.getSlotsNoHotbar(getIdFromBlock(mat)) != null) { // InventoryUtils.moveToHotbar(getIdFromBlock(mat), 130, (tickDelay.value * 16).toLong()) for (x in InventoryUtils.getSlotsNoHotbar(getIdFromBlock(mat))!!) { @@ -606,7 +619,7 @@ object HighwayTools : Module() { } // InventoryUtils.quickMoveSlot(1, (tickDelay.value * 16).toLong()) } else if (InventoryUtils.getSlots(0, 35, getIdFromBlock(mat)) == null) { - MessageSendHelper.sendChatMessage("$chatName No ${mat.localizedName} was found in inventory") + sendChatMessage("$chatName No ${mat.localizedName} was found in inventory") mc.getSoundHandler().playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) disable() } @@ -625,9 +638,8 @@ object HighwayTools : Module() { } } if (rayTraces.size == 0) { - MessageSendHelper.sendChatMessage("Trying to place through wall $pos") - placeBlockWall(pos, mat) - return + if(debugMessages.value == DebugMessages.ALL) sendChatMessage("Trying to place through wall $pos") + return placeBlockWall(pos, mat) } var rayTrace: RayTraceResult? = null @@ -639,8 +651,8 @@ object HighwayTools : Module() { } } if (rayTrace == null) { - MessageSendHelper.sendChatMessage("Can't find any vector?") - return + sendChatMessage("Can't find any vector?") + return false } val hitVecOffset = rayTrace.hitVec @@ -663,6 +675,7 @@ object HighwayTools : Module() { mc.player.swingArm(EnumHand.MAIN_HAND) if (NoBreakAnimation.isEnabled) NoBreakAnimation.resetMining() }.start() + return true } private fun getPlaceableSide(pos: BlockPos): EnumFacing? { @@ -707,7 +720,7 @@ object HighwayTools : Module() { for (blockTask in blockQueue) message += "\n" + blockTask.block.localizedName + "@(" + blockTask.blockPos.asString() + ") Priority: " + blockTask.taskState.ordinal + " State: " + blockTask.taskState.toString() message += "\n-------------------- DONE --------------------" for (blockTask in doneQueue) message += "\n" + blockTask.block.localizedName + "@(" + blockTask.blockPos.asString() + ") Priority: " + blockTask.taskState.ordinal + " State: " + blockTask.taskState.toString() - MessageSendHelper.sendChatMessage(message) + sendChatMessage(message) } fun printSettings() { @@ -716,7 +729,7 @@ object HighwayTools : Module() { "\n §9> §rBaritone: §7${baritoneMode.value}" + "\n §9> §rIgnored Blocks:" for (b in ignoreBlocks) message += "\n §9> §7${b!!.registryName}" - MessageSendHelper.sendChatMessage(message) + sendChatMessage(message) } private fun printEnable() { @@ -737,7 +750,7 @@ object HighwayTools : Module() { } else { message += "$chatName Module started." } - MessageSendHelper.sendChatMessage(message) + sendChatMessage(message) } private fun printDisable() { @@ -750,7 +763,7 @@ object HighwayTools : Module() { } else { message += "$chatName Module stopped." } - MessageSendHelper.sendChatMessage(message) + sendChatMessage(message) } fun getNextBlock(): BlockPos { @@ -882,7 +895,7 @@ object HighwayTools : Module() { } } null -> { - MessageSendHelper.sendChatMessage("Module logic is a lie.") + sendChatMessage("Module logic is a lie.") disable() } } diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/player/NoBreakAnimation.kt b/src/main/java/me/zeroeightsix/kami/module/modules/player/NoBreakAnimation.kt index 9f89fe0fb0..04d0a6d98b 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/player/NoBreakAnimation.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/player/NoBreakAnimation.kt @@ -57,7 +57,7 @@ object NoBreakAnimation : Module() { } } - private fun resetMining() { + fun resetMining() { isMining = false lastPos = null lastFacing = null From a686f1bef19112fcd9d4118f5cadf401d5e4f6b3 Mon Sep 17 00:00:00 2001 From: Christian Date: Wed, 21 Oct 2020 07:38:47 +0200 Subject: [PATCH 039/390] SaveTickEvent fix to get right packet timings --- .../kami/module/modules/misc/AutoObsidian.kt | 84 ++++++++++--------- 1 file changed, 45 insertions(+), 39 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt index b4f9aa2a4b..95924b1a5f 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt @@ -74,6 +74,7 @@ object AutoObsidian : Module() { private var obsidianCount = -1 private var tickCount = 0 private var openTime = 0L + private var ticks = true override fun isActive(): Boolean { return isEnabled && active @@ -86,47 +87,52 @@ object AutoObsidian : Module() { init { listener { - if (mc.playerController == null) return@listener - /* Just a delay */ - if (tickCount < delayTicks.value) { - tickCount++ - return@listener - } else tickCount = 0 - - updateState() - when (state) { - - /* Searching states */ - State.SEARCHING -> { - if (searchShulker.value) { - when (searchingState) { - SearchingState.PLACING -> placeShulker(placingPos) - SearchingState.OPENING -> openShulker(placingPos) - SearchingState.PRE_MINING -> mineBlock(placingPos, true) - SearchingState.MINING -> mineBlock(placingPos, false) - SearchingState.COLLECTING -> collectDroppedItem(shulkerBoxId) - SearchingState.DONE -> { - /* Positions need to be updated after moving while collecting dropped shulker box */ - val currentPos = BlockPos(floor(mc.player.posX).toInt(), floor(mc.player.posY).toInt(), floor(mc.player.posZ).toInt()) - playerPos = currentPos - setPlacingPos() + if (ticks) { + ticks = !ticks + } else { + ticks = !ticks + if (mc.playerController == null) return@listener + /* Just a delay */ + if (tickCount < delayTicks.value) { + tickCount++ + return@listener + } else tickCount = 0 + + updateState() + when (state) { + + /* Searching states */ + State.SEARCHING -> { + if (searchShulker.value) { + when (searchingState) { + SearchingState.PLACING -> placeShulker(placingPos) + SearchingState.OPENING -> openShulker(placingPos) + SearchingState.PRE_MINING -> mineBlock(placingPos, true) + SearchingState.MINING -> mineBlock(placingPos, false) + SearchingState.COLLECTING -> collectDroppedItem(shulkerBoxId) + SearchingState.DONE -> { + /* Positions need to be updated after moving while collecting dropped shulker box */ + val currentPos = BlockPos(floor(mc.player.posX).toInt(), floor(mc.player.posY).toInt(), floor(mc.player.posZ).toInt()) + playerPos = currentPos + setPlacingPos() + } } - } - } else searchingState = SearchingState.DONE - } + } else searchingState = SearchingState.DONE + } - /* Main states */ - State.PLACING -> placeEnderChest(placingPos) - State.PRE_MINING -> mineBlock(placingPos, true) - State.MINING -> mineBlock(placingPos, false) - State.COLLECTING -> collectDroppedItem(49) - State.DONE -> { - if (!autoRefill.value) { - sendChatMessage("$chatName Reached target stacks, disabling.") - this.disable() - } else { - if (active) sendChatMessage("$chatName Reached target stacks, stopping.") - reset() + /* Main states */ + State.PLACING -> placeEnderChest(placingPos) + State.PRE_MINING -> mineBlock(placingPos, true) + State.MINING -> mineBlock(placingPos, false) + State.COLLECTING -> collectDroppedItem(49) + State.DONE -> { + if (!autoRefill.value) { + sendChatMessage("$chatName Reached target stacks, disabling.") + this.disable() + } else { + if (active) sendChatMessage("$chatName Reached target stacks, stopping.") + reset() + } } } } From ac8f699c17f96485c6e79add764b8da1bdfb52e2 Mon Sep 17 00:00:00 2001 From: Christian Date: Wed, 21 Oct 2020 07:53:23 +0200 Subject: [PATCH 040/390] Fixed shulker option --- .../kami/module/modules/misc/AutoObsidian.kt | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt index 95924b1a5f..c1a6633931 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt @@ -34,11 +34,6 @@ import kotlin.math.ceil import kotlin.math.floor -/** - * @author Xiaro? - * @updated by Avanatiker - * @since 19/10/2020 - */ @Module.Info( name = "AutoObsidian", category = Module.Category.MISC, @@ -333,7 +328,8 @@ object AutoObsidian : Module() { } } else { /* Extra delay here to wait for the item list to be loaded */ - Executors.newSingleThreadScheduledExecutor().schedule({ + Thread{ + Thread.sleep(delayTicks.value * 50L) val currentContainer = mc.player.openContainer var enderChestSlot = -1 for (i in 0..26) { @@ -348,7 +344,7 @@ object AutoObsidian : Module() { mc.getSoundHandler().playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) this.disable() } - }, delayTicks.value * 50L, TimeUnit.MILLISECONDS) + }.start() } } From 5159dc3b57f03eeff33d1c9497c7173bd766bfb0 Mon Sep 17 00:00:00 2001 From: Christian Date: Fri, 23 Oct 2020 06:26:33 +0200 Subject: [PATCH 041/390] Added pre InventoryManager - Fixed some fatal crashes - Cleaned up some logic - Added option for illegal placements --- .../kami/module/modules/misc/HighwayTools.kt | 151 ++++++++++-------- 1 file changed, 80 insertions(+), 71 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 636e1896ac..68ae8841cc 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -3,6 +3,7 @@ package me.zeroeightsix.kami.module.modules.misc import baritone.api.BaritoneAPI import me.zeroeightsix.kami.event.events.RenderWorldEvent import me.zeroeightsix.kami.event.events.SafeTickEvent +import me.zeroeightsix.kami.manager.mangers.PlayerInventoryManager import me.zeroeightsix.kami.module.Module import me.zeroeightsix.kami.module.modules.combat.Surround import me.zeroeightsix.kami.module.modules.player.NoBreakAnimation @@ -37,6 +38,7 @@ import net.minecraft.util.EnumHand import net.minecraft.util.math.BlockPos import net.minecraft.util.math.RayTraceResult import net.minecraft.util.math.Vec3d +import net.minecraftforge.fml.common.gameevent.TickEvent import java.util.* import kotlin.math.abs import kotlin.math.sqrt @@ -71,6 +73,7 @@ object HighwayTools : Module() { private val tickDelayPlace = register(Settings.integerBuilder("TickDelayPlace").withMinimum(0).withValue(3).withMaximum(16).withVisibility { page.value == Page.BEHAVIOR }) private val tickDelayBreak = register(Settings.integerBuilder("TickDelayBreak").withMinimum(0).withValue(0).withMaximum(16).withVisibility { page.value == Page.BEHAVIOR }) private val interacting = register(Settings.enumBuilder(InteractMode::class.java).withName("InteractMode").withValue(InteractMode.SPOOF).withVisibility { page.value == Page.BEHAVIOR }) + private val illegalPlacements = register(Settings.booleanBuilder("IllegalPlacements").withValue(true).withVisibility { page.value == Page.BEHAVIOR }) private val autoCenter = register(Settings.enumBuilder(AutoCenterMode::class.java).withName("AutoCenter").withValue(AutoCenterMode.MOTION).withVisibility { page.value == Page.BEHAVIOR }) private val stuckDelay = register(Settings.integerBuilder("TickDelayStuck").withMinimum(1).withValue(200).withMaximum(500).withVisibility { page.value == Page.BEHAVIOR }) val maxReach = register(Settings.floatBuilder("MaxReach").withMinimum(2.0F).withValue(5.4F).withVisibility { page.value == Page.BEHAVIOR }) @@ -91,7 +94,7 @@ object HighwayTools : Module() { var fillerMat: Block = Blocks.NETHERRACK private var playerHotbarSlot = -1 private var lastHotbarSlot = -1 - private lateinit var buildDirectionSaved: Cardinal + private var buildDirectionSaved = Cardinal.ERROR private var baritoneSettingAllowPlace = false private var baritoneSettingRenderGoal = false @@ -104,10 +107,10 @@ object HighwayTools : Module() { var pathing = false private var stuckBuilding = 0 private var stuckMining = 0 - private var currentBlockPos = BlockPos(0, 0, 0) - private lateinit var startingBlockPos: BlockPos + private var currentBlockPos = BlockPos(0, -1, 0) + private var startingBlockPos = BlockPos(0, -1, 0) private var lastViewVec: RayTraceResult? = null - private var ticks = true + private var lastTask = PlayerInventoryManager.TaskState(true) // stats private var totalBlocksPlaced = 0 @@ -115,10 +118,7 @@ object HighwayTools : Module() { init { listener { - if (ticks) { - ticks = !ticks - } else { - ticks = !ticks + if (it.phase != TickEvent.Phase.END) { if (mc.playerController == null) return@listener BaritoneAPI.getProvider().primaryBaritone.pathingControlManager.registerProcess(HighwayToolsProcess) @@ -126,10 +126,10 @@ object HighwayTools : Module() { pathing = BaritoneAPI.getProvider().primaryBaritone.pathingBehavior.isPathing if (relativeDirection(currentBlockPos, 1, 0) == mc.player.positionVector.toBlockPos()) { - if (!isDone()) { + if (!isDone() && !BaritoneUtils.paused && !AutoObsidian.isActive()) { centerPlayer() if (!doTask()) { - if (!pathing && !BaritoneUtils.paused && !AutoObsidian.isActive()) { + if (!pathing) { stuckBuilding += 1 shuffleTasks() if (debugMessages.value == DebugMessages.ALL) sendChatMessage("$chatName Shuffled tasks (${stuckBuilding}x)") @@ -163,6 +163,8 @@ object HighwayTools : Module() { refreshData() } } + } else { + return@listener } } @@ -261,7 +263,7 @@ object HighwayTools : Module() { if (printDebug.value) printDebug() when (blockTask.taskState) { TaskState.DONE -> doDONE(blockTask) - TaskState.BREAKING -> doBREAKING(blockTask) + TaskState.BREAKING -> if(!doBREAKING(blockTask)) return false TaskState.PLACED -> doPLACED(blockTask) TaskState.BREAK -> if(!doBREAK(blockTask)) return false TaskState.PLACE, TaskState.LIQUID_SOURCE, TaskState.LIQUID_FLOW -> if(!doPLACE(blockTask)) return false @@ -281,7 +283,7 @@ object HighwayTools : Module() { doTask() } - private fun doBREAKING(blockTask: BlockTask) { + private fun doBREAKING(blockTask: BlockTask): Boolean { if (stuckMining > stuckDelay.value) { // ToDo: Make this more reliable for high TPS @@ -314,10 +316,11 @@ object HighwayTools : Module() { updateTask(blockTask, fillerMat) } else -> { - mineBlock(blockTask.blockPos, false) + if (!mineBlock(blockTask)) return false stuckMining++ } } + return true } private fun doPLACED(blockTask: BlockTask) { @@ -362,7 +365,8 @@ object HighwayTools : Module() { // ToDo: inventory management function - if (!mineBlock(blockTask.blockPos, true)) { + if (!inventoryManager(blockTask)) return false + if (!mineBlock(blockTask)) { shuffleTasks() } else { updateTask(blockTask, TaskState.BREAKING) @@ -393,7 +397,8 @@ object HighwayTools : Module() { return false } - if (!placeBlock(blockTask.blockPos, blockTask.block)) return false + if (!inventoryManager(blockTask)) return false + if (!placeBlock(blockTask)) return false if (blockTask.taskState != TaskState.PLACE && isInsideBuild(blockTask.blockPos)) updateTask(blockTask, Blocks.AIR) updateTask(blockTask, TaskState.PLACED) if (blocksPerTick.value > blocksPlaced + 1) { @@ -467,6 +472,39 @@ object HighwayTools : Module() { blockQueue.addAll(tmpQueue) } + private fun inventoryManager(blockTask: BlockTask): Boolean { + when (blockTask.taskState) { + TaskState.BREAK -> { + if (InventoryUtils.getSlotsHotbar(278) == null && InventoryUtils.getSlotsNoHotbar(278) != null) { + InventoryUtils.moveToHotbar(278, 130) + return true + } else if (InventoryUtils.getSlots(0, 35, 278) == null) { + sendChatMessage("$chatName No Pickaxe was found in inventory") + mc.getSoundHandler().playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) + disable() + return false + } + InventoryUtils.swapSlotToItem(278) + } + TaskState.PLACE -> { + if (InventoryUtils.getSlotsHotbar(getIdFromBlock(blockTask.block)) == null && + InventoryUtils.getSlotsNoHotbar(getIdFromBlock(blockTask.block)) != null) { + for (x in InventoryUtils.getSlotsNoHotbar(getIdFromBlock(blockTask.block))!!) { + InventoryUtils.quickMoveSlot(x) + } + } else if (InventoryUtils.getSlots(0, 35, getIdFromBlock(blockTask.block)) == null) { + sendChatMessage("$chatName No ${blockTask.block.localizedName} was found in inventory") + mc.getSoundHandler().playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) + disable() + } + InventoryUtils.swapSlotToItem(getIdFromBlock(blockTask.block)) + } + else -> return false + } + return true + } + + // ToDo: Needs to get updated for raytrace private fun liquidHandler(blockPos: BlockPos): Boolean { var foundLiquid = false for (side in EnumFacing.values()) { @@ -505,31 +543,21 @@ object HighwayTools : Module() { return foundLiquid } - private fun mineBlock(pos: BlockPos, pre: Boolean): Boolean { + private fun mineBlock(blockTask: BlockTask): Boolean { var rayTrace: RayTraceResult? - if (pre) { - if (InventoryUtils.getSlotsHotbar(278) == null && InventoryUtils.getSlotsNoHotbar(278) != null) { - InventoryUtils.moveToHotbar(278, 130) - return true - } else if (InventoryUtils.getSlots(0, 35, 278) == null) { - sendChatMessage("$chatName No Pickaxe was found in inventory") - mc.getSoundHandler().playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) - disable() - return false - } - InventoryUtils.swapSlotToItem(278) - - rayTrace = mc.world.rayTraceBlocks(mc.player.getPositionEyes(1f), Vec3d(pos).add(0.5, 0.5, 0.5)) + if (blockTask.taskState == TaskState.BREAK) { + rayTrace = mc.world.rayTraceBlocks(mc.player.getPositionEyes(1f), Vec3d(blockTask.blockPos).add(0.5, 0.5, 0.5)) if (rayTrace == null) { refreshData() return false } - if (rayTrace.blockPos != pos) { + if (rayTrace.blockPos != blockTask.blockPos) { var found = false for (side in EnumFacing.values()) { - if (mc.world.getBlockState(pos.offset(side)).block == Blocks.AIR) { - rayTrace = mc.world.rayTraceBlocks(mc.player.getPositionEyes(1f), Vec3d(pos).add(0.5, 0.5, 0.5).add(Vec3d(side.directionVec).scale(0.499)))?: continue - if (rayTrace.blockPos == pos) { + if (mc.world.getBlockState(blockTask.blockPos.offset(side)).block == Blocks.AIR) { + rayTrace = mc.world.rayTraceBlocks(mc.player.getPositionEyes(1f), + Vec3d(blockTask.blockPos).add(0.5, 0.5, 0.5).add(Vec3d(side.directionVec).scale(0.499)))?: continue + if (rayTrace.blockPos == blockTask.blockPos) { found = true break } @@ -547,7 +575,7 @@ object HighwayTools : Module() { } val facing = rayTrace?.sideHit ?: return false - val rotation = RotationUtils.getRotationTo(Vec3d(pos).add(0.5, 0.5, 0.5).add(Vec3d(facing.directionVec).scale(0.499)), true) + val rotation = RotationUtils.getRotationTo(Vec3d(blockTask.blockPos).add(0.5, 0.5, 0.5).add(Vec3d(facing.directionVec).scale(0.499)), true) when (interacting.value) { InteractMode.SPOOF -> { @@ -560,33 +588,23 @@ object HighwayTools : Module() { } } + val digPacket: CPacketPlayerDigging = when (blockTask.taskState) { + TaskState.BREAK -> CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, blockTask.blockPos, facing) + TaskState.BREAKING -> CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, blockTask.blockPos, facing) + else -> CPacketPlayerDigging() + } Thread { Thread.sleep(25L) - if (pre) { - mc.connection!!.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, pos, facing)) - } else { - mc.connection!!.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, pos, facing)) - } + mc.connection!!.sendPacket(digPacket) mc.player.swingArm(EnumHand.MAIN_HAND) }.start() return true } // Only temporary till we found solution to avoid untraceable blocks - private fun placeBlockWall(pos: BlockPos, mat: Block): Boolean { - if (InventoryUtils.getSlotsHotbar(getIdFromBlock(mat)) == null && InventoryUtils.getSlotsNoHotbar(getIdFromBlock(mat)) != null) { - for (x in InventoryUtils.getSlotsNoHotbar(getIdFromBlock(mat))!!) { - InventoryUtils.quickMoveSlot(x) - } - } else if (InventoryUtils.getSlots(0, 35, getIdFromBlock(mat)) == null) { - sendChatMessage("$chatName No ${mat.localizedName} was found in inventory") - mc.getSoundHandler().playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) - disable() - } - InventoryUtils.swapSlotToItem(getIdFromBlock(mat)) - - val side = getPlaceableSide(pos) ?: return false - val neighbour = pos.offset(side) + private fun placeBlockWall(blockTask: BlockTask): Boolean { + val side = getPlaceableSide(blockTask.blockPos) ?: return false + val neighbour = blockTask.blockPos.offset(side) val hitVec = Vec3d(neighbour).add(0.5, 0.5, 0.5).add(Vec3d(side.opposite.directionVec).scale(0.5)) val rotation = RotationUtils.getRotationTo(hitVec, true) @@ -611,35 +629,26 @@ object HighwayTools : Module() { return true } - private fun placeBlock(pos: BlockPos, mat: Block): Boolean { - if (InventoryUtils.getSlotsHotbar(getIdFromBlock(mat)) == null && InventoryUtils.getSlotsNoHotbar(getIdFromBlock(mat)) != null) { - // InventoryUtils.moveToHotbar(getIdFromBlock(mat), 130, (tickDelay.value * 16).toLong()) - for (x in InventoryUtils.getSlotsNoHotbar(getIdFromBlock(mat))!!) { - InventoryUtils.quickMoveSlot(x) - } - // InventoryUtils.quickMoveSlot(1, (tickDelay.value * 16).toLong()) - } else if (InventoryUtils.getSlots(0, 35, getIdFromBlock(mat)) == null) { - sendChatMessage("$chatName No ${mat.localizedName} was found in inventory") - mc.getSoundHandler().playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) - disable() - } - InventoryUtils.swapSlotToItem(getIdFromBlock(mat)) - + private fun placeBlock(blockTask: BlockTask): Boolean { val rayTraces = mutableListOf() for (side in EnumFacing.values()) { - val offPos = pos.offset(side) + val offPos = blockTask.blockPos.offset(side) if (mc.world.getBlockState(offPos).material.isReplaceable) continue if (mc.player.getPositionEyes(1f).distanceTo(Vec3d(offPos).add(BlockUtils.getHitVecOffset(side))) > maxReach.value) continue val rotationVector = Vec3d(offPos).add(0.5, 0.5, 0.5).add(Vec3d(side.opposite.directionVec).scale(0.499)) val rt = mc.world.rayTraceBlocks(mc.player.getPositionEyes(1f), rotationVector)?: continue if (rt.typeOfHit != RayTraceResult.Type.BLOCK) continue - if (rt.blockPos == offPos && offPos.offset(rt.sideHit) == pos) { + if (rt.blockPos == offPos && offPos.offset(rt.sideHit) == blockTask.blockPos) { rayTraces.add(rt) } } if (rayTraces.size == 0) { - if(debugMessages.value == DebugMessages.ALL) sendChatMessage("Trying to place through wall $pos") - return placeBlockWall(pos, mat) + return if (illegalPlacements.value) { + if(debugMessages.value == DebugMessages.ALL) sendChatMessage("Trying to place through wall ${blockTask.blockPos}") + placeBlockWall(blockTask) + } else { + true + } } var rayTrace: RayTraceResult? = null From fe5094bc6a9c1b8c49d7c99c1c839cb655174e4a Mon Sep 17 00:00:00 2001 From: Christian Date: Fri, 23 Oct 2020 08:20:40 +0200 Subject: [PATCH 042/390] Added tunnel mode --- .../kami/module/modules/misc/HighwayTools.kt | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 68ae8841cc..b4ce11867d 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -898,6 +898,38 @@ object HighwayTools : Module() { } } } + Mode.TUNNEL -> { + if (baritoneMode.value) { + cursor = relativeDirection(cursor, 1, 0) + blockOffsets.add(Pair(cursor, material)) + } + cursor = relativeDirection(cursor, 1, 0) + blockOffsets.add(Pair(cursor, material)) + var buildIterationsWidth = buildWidth.value / 2 + var evenCursor = relativeDirection(cursor, 1, 2) + var isOdd = false + if (buildWidth.value % 2 == 1) { + isOdd = true + buildIterationsWidth++ + } else { + blockOffsets.add(Pair(evenCursor, material)) + } + for (i in 1 until clearHeight.value + 2) { + for (j in 1 until buildIterationsWidth) { + var mat = Blocks.AIR + if (i == 1) mat = material + blockOffsets.add(Pair(relativeDirection(cursor, j, -2), mat)) + if (isOdd) blockOffsets.add(Pair(relativeDirection(cursor, j, 2), mat)) + else blockOffsets.add(Pair(relativeDirection(evenCursor, j, 2), mat)) + } + cursor = cursor.up() + evenCursor = evenCursor.up() + if (clearSpace.value && i < clearHeight.value + 1) { + blockOffsets.add(Pair(cursor, Blocks.AIR)) + if (!isOdd) blockOffsets.add(Pair(evenCursor, Blocks.AIR)) + } + } + } Mode.FLAT -> { for (bp in VectorUtils.getBlockPositionsInArea(cursor.north(buildWidth.value).west(buildWidth.value), cursor.south(buildWidth.value).east(buildWidth.value))) { blockOffsets.add(Pair(bp, material)) @@ -918,7 +950,8 @@ object HighwayTools : Module() { private enum class Mode { HIGHWAY, - FLAT + FLAT, + TUNNEL } private enum class Page { From e60a0ec3fcd2d9f609acd02f8492392951320809 Mon Sep 17 00:00:00 2001 From: Christian Date: Fri, 23 Oct 2020 08:21:19 +0200 Subject: [PATCH 043/390] Removed PlayerInventoryManager --- .../me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index b4ce11867d..3a9e6299e5 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -3,7 +3,6 @@ package me.zeroeightsix.kami.module.modules.misc import baritone.api.BaritoneAPI import me.zeroeightsix.kami.event.events.RenderWorldEvent import me.zeroeightsix.kami.event.events.SafeTickEvent -import me.zeroeightsix.kami.manager.mangers.PlayerInventoryManager import me.zeroeightsix.kami.module.Module import me.zeroeightsix.kami.module.modules.combat.Surround import me.zeroeightsix.kami.module.modules.player.NoBreakAnimation @@ -110,7 +109,6 @@ object HighwayTools : Module() { private var currentBlockPos = BlockPos(0, -1, 0) private var startingBlockPos = BlockPos(0, -1, 0) private var lastViewVec: RayTraceResult? = null - private var lastTask = PlayerInventoryManager.TaskState(true) // stats private var totalBlocksPlaced = 0 From 4aaaa00dfbdccc10d8d3e8b9c0f729fb1f52432b Mon Sep 17 00:00:00 2001 From: Christian Date: Fri, 23 Oct 2020 08:29:53 +0200 Subject: [PATCH 044/390] Fix tunnel logic --- .../me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 3a9e6299e5..2a2ab1c89c 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -897,6 +897,7 @@ object HighwayTools : Module() { } } Mode.TUNNEL -> { + material = Blocks.NETHERRACK if (baritoneMode.value) { cursor = relativeDirection(cursor, 1, 0) blockOffsets.add(Pair(cursor, material)) From 80889d8bdb81b8024f55ab58d0e37dec5a8f2b00 Mon Sep 17 00:00:00 2001 From: Christian Date: Mon, 26 Oct 2020 06:05:23 +0100 Subject: [PATCH 045/390] Added Statistics window --- .../zeroeightsix/kami/gui/kami/KamiGUI.java | 23 ++++++++++++ .../kami/module/modules/misc/HighwayTools.kt | 35 +++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/src/main/java/me/zeroeightsix/kami/gui/kami/KamiGUI.java b/src/main/java/me/zeroeightsix/kami/gui/kami/KamiGUI.java index 1d8013859c..9e4e35569c 100644 --- a/src/main/java/me/zeroeightsix/kami/gui/kami/KamiGUI.java +++ b/src/main/java/me/zeroeightsix/kami/gui/kami/KamiGUI.java @@ -21,6 +21,7 @@ import me.zeroeightsix.kami.module.Module; import me.zeroeightsix.kami.module.ModuleManager; import me.zeroeightsix.kami.module.modules.client.InfoOverlay; +import me.zeroeightsix.kami.module.modules.misc.HighwayTools; import me.zeroeightsix.kami.module.modules.movement.AutoWalk; import me.zeroeightsix.kami.process.TemporaryPauseProcess; import me.zeroeightsix.kami.util.Wrapper; @@ -521,6 +522,28 @@ public void onTick() { coords.setHeight(20); frames.add(coords); + /* + * HighwayTools statistics + */ + Frame ht = new Frame(getTheme(), new Stretcherlayout(1), "HighwayTools"); + ht.setCloseable(false); + ht.setPinnable(true); + Label htLabel = new Label(""); + htLabel.addTickListener(() -> { + htLabel.setText(""); + if (HighwayTools.INSTANCE.isEnabled()) { + List statistics = HighwayTools.INSTANCE.gatherStatistics(); + for (String line: statistics) { + htLabel.addLine(line); + } + } + }); + ht.addChild(htLabel); + htLabel.setShadow(true); + ht.setMinimumHeight(60); + ht.setMinimumWidth(100); + frames.add(ht); + /* * Radar */ diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 2a2ab1c89c..ed631fa212 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -109,6 +109,8 @@ object HighwayTools : Module() { private var currentBlockPos = BlockPos(0, -1, 0) private var startingBlockPos = BlockPos(0, -1, 0) private var lastViewVec: RayTraceResult? = null + private var startTime: Long = 0L + private var runtimeSec: Double = 0.0 // stats private var totalBlocksPlaced = 0 @@ -119,6 +121,7 @@ object HighwayTools : Module() { if (it.phase != TickEvent.Phase.END) { if (mc.playerController == null) return@listener BaritoneAPI.getProvider().primaryBaritone.pathingControlManager.registerProcess(HighwayToolsProcess) + runtimeSec = ((System.currentTimeMillis() - startTime) / 1000).toDouble() if (baritoneMode.value) { pathing = BaritoneAPI.getProvider().primaryBaritone.pathingBehavior.isPathing @@ -191,6 +194,8 @@ object HighwayTools : Module() { playerHotbarSlot = mc.player.inventory.currentItem lastHotbarSlot = -1 buildDirectionSaved = getPlayerCardinal(mc.player) + startTime = System.currentTimeMillis() + runtimeSec = 0.1 if (baritoneMode.value) { baritoneSettingAllowPlace = BaritoneAPI.getSettings().allowPlace.value @@ -773,6 +778,36 @@ object HighwayTools : Module() { sendChatMessage(message) } + fun gatherStatistics(): List { + val currentTask: BlockTask? = if (isDone()) { + null + } else { + blockQueue.peek() + } + + val seconds = (runtimeSec % 60).toInt().toString().padStart(2,'0') + val minutes = ((runtimeSec % 3600) / 60).toInt().toString().padStart(2,'0') + val hours = (runtimeSec / 3600).toInt().toString().padStart(2,'0') + + return listOf( + "§rStatistics", + " §9> §rRuntime: §7$hours:$minutes:$seconds", + " §9> §rPlacements per second: §7%.2f (%.2f)".format(totalBlocksPlaced / runtimeSec, (totalBlocksPlaced / runtimeSec) * 2), + " §9> §rBreaks per second: §7%.2f (%.2f)".format(totalBlocksDestroyed / runtimeSec, (totalBlocksDestroyed / runtimeSec) * 2), + " §9> §rDistance per hour: §7%.2f".format((getDistance(startingBlockPos.toVec3d(), currentBlockPos.toVec3d()).toInt() / runtimeSec) * 60 * 60), + "§rInfo", + " §9> §rStatus: §7${currentTask?.taskState}", + " §9> §rTarget state: §7${currentTask?.block}", + " §9> §rPosition: §7${currentTask?.blockPos}", + "§rEstimations", + " §9> §rTheoretical material left: §7${12345} ${material.localizedName}", + " §9> §rTheoretical block breakings left: §7${232344}", + " §9> §rTheoretical distance left: §7${62944}", + " §9> §rEstimated time left: §704:13:11", + " §9> §rEstimated destination: §7BlockPos{x=-125533, y=119, z=125533}" + ) + } + fun getNextBlock(): BlockPos { return when (buildDirectionSaved) { Cardinal.NEG_Z -> currentBlockPos.north() From f38a2f20f7dd0bd4bb00d9d61b337968f1ca2d2a Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 27 Oct 2020 07:37:38 +0100 Subject: [PATCH 046/390] New faster block breaking Needs a lot of fixes though --- .../zeroeightsix/kami/gui/kami/KamiGUI.java | 4 +- .../kami/module/modules/misc/HighwayTools.kt | 178 +++++++++++------- 2 files changed, 111 insertions(+), 71 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/gui/kami/KamiGUI.java b/src/main/java/me/zeroeightsix/kami/gui/kami/KamiGUI.java index 1db57815c9..94647b0f62 100644 --- a/src/main/java/me/zeroeightsix/kami/gui/kami/KamiGUI.java +++ b/src/main/java/me/zeroeightsix/kami/gui/kami/KamiGUI.java @@ -540,8 +540,8 @@ public void onTick() { }); ht.addChild(htLabel); htLabel.setShadow(true); - ht.setMinimumHeight(60); - ht.setMinimumWidth(100); + ht.setMinimumHeight(20); + ht.setMinimumWidth(80); frames.add(ht); /* diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index ed631fa212..c0c0559d9c 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -73,6 +73,7 @@ object HighwayTools : Module() { private val tickDelayBreak = register(Settings.integerBuilder("TickDelayBreak").withMinimum(0).withValue(0).withMaximum(16).withVisibility { page.value == Page.BEHAVIOR }) private val interacting = register(Settings.enumBuilder(InteractMode::class.java).withName("InteractMode").withValue(InteractMode.SPOOF).withVisibility { page.value == Page.BEHAVIOR }) private val illegalPlacements = register(Settings.booleanBuilder("IllegalPlacements").withValue(true).withVisibility { page.value == Page.BEHAVIOR }) + private val abundanceBreaking = register(Settings.booleanBuilder("AbundanceBreaking").withValue(true).withVisibility { page.value == Page.BEHAVIOR }) private val autoCenter = register(Settings.enumBuilder(AutoCenterMode::class.java).withName("AutoCenter").withValue(AutoCenterMode.MOTION).withVisibility { page.value == Page.BEHAVIOR }) private val stuckDelay = register(Settings.integerBuilder("TickDelayStuck").withMinimum(1).withValue(200).withMaximum(500).withVisibility { page.value == Page.BEHAVIOR }) val maxReach = register(Settings.floatBuilder("MaxReach").withMinimum(2.0F).withValue(5.4F).withVisibility { page.value == Page.BEHAVIOR }) @@ -263,11 +264,12 @@ object HighwayTools : Module() { if (waitTicks == 0) { val blockTask = blockQueue.peek() - if (printDebug.value) printDebug() when (blockTask.taskState) { TaskState.DONE -> doDONE(blockTask) TaskState.BREAKING -> if(!doBREAKING(blockTask)) return false + TaskState.BROKEN -> doBROKEN(blockTask) TaskState.PLACED -> doPLACED(blockTask) + TaskState.LIQUID_BREAK -> if(!mineBlock(blockTask)) return false TaskState.BREAK -> if(!doBREAK(blockTask)) return false TaskState.PLACE, TaskState.LIQUID_SOURCE, TaskState.LIQUID_FLOW -> if(!doPLACE(blockTask)) return false } @@ -288,9 +290,6 @@ object HighwayTools : Module() { private fun doBREAKING(blockTask: BlockTask): Boolean { if (stuckMining > stuckDelay.value) { - - // ToDo: Make this more reliable for high TPS - stuckMining = 0 updateTask(blockTask, TaskState.BREAK) refreshData() @@ -326,6 +325,23 @@ object HighwayTools : Module() { return true } + private fun doBROKEN(blockTask: BlockTask) { + when (mc.world.getBlockState(blockTask.blockPos).block) { + Blocks.AIR -> { + totalBlocksDestroyed++ + if (blockTask.block == material || blockTask.block == fillerMat) { + updateTask(blockTask, TaskState.PLACE) + } else { + updateTask(blockTask, TaskState.DONE) + } + } + else -> { + updateTask(blockTask, TaskState.BREAK) + } + } + doTask() + } + private fun doPLACED(blockTask: BlockTask) { val block = mc.world.getBlockState(blockTask.blockPos).block @@ -350,10 +366,6 @@ object HighwayTools : Module() { // last check before breaking when (block) { - Blocks.AIR -> { - updateTask(blockTask, TaskState.DONE) - doTask() - } Blocks.LAVA -> { updateTask(blockTask, TaskState.LIQUID_SOURCE) updateTask(blockTask, fillerMat) @@ -362,18 +374,21 @@ object HighwayTools : Module() { updateTask(blockTask, TaskState.LIQUID_FLOW) updateTask(blockTask, fillerMat) } + Blocks.AIR -> { + updateTask(blockTask, TaskState.DONE) + doTask() + } else -> { // liquid search around the breaking block - if (liquidHandler(blockTask.blockPos)) return false - - // ToDo: inventory management function - - if (!inventoryManager(blockTask)) return false - if (!mineBlock(blockTask)) { - shuffleTasks() - } else { - updateTask(blockTask, TaskState.BREAKING) + if (blockTask.taskState != TaskState.LIQUID_BREAK) { + if (liquidHandler(blockTask)) { + updateTask(blockTask, TaskState.LIQUID_BREAK) + doTask() + return false + } } + if (!inventoryManager(blockTask)) return false + if (!mineBlock(blockTask)) shuffleTasks() } } return true @@ -391,9 +406,6 @@ object HighwayTools : Module() { block == material && block == blockTask.block -> updateTask(blockTask, TaskState.PLACED) block == fillerMat && block == blockTask.block -> updateTask(blockTask, TaskState.PLACED) else -> { - - // ToDo: inventory management function - if (!BlockUtils.isPlaceable(blockTask.blockPos)) { if (debugMessages.value != DebugMessages.OFF) sendChatMessage("Error: " + blockTask.blockPos + " is not a valid position to place a block, removing task.") blockQueue.remove(blockTask) @@ -507,11 +519,10 @@ object HighwayTools : Module() { return true } - // ToDo: Needs to get updated for raytrace - private fun liquidHandler(blockPos: BlockPos): Boolean { + private fun liquidHandler(blockTask: BlockTask): Boolean { var foundLiquid = false for (side in EnumFacing.values()) { - val neighbour = blockPos.offset(side) + val neighbour = blockTask.blockPos.offset(side) val neighbourBlock = mc.world.getBlockState(neighbour).block if (neighbourBlock == Blocks.LAVA || neighbourBlock == Blocks.FLOWING_LAVA) { @@ -548,7 +559,7 @@ object HighwayTools : Module() { private fun mineBlock(blockTask: BlockTask): Boolean { var rayTrace: RayTraceResult? - if (blockTask.taskState == TaskState.BREAK) { + if (blockTask.taskState != TaskState.BREAKING) { rayTrace = mc.world.rayTraceBlocks(mc.player.getPositionEyes(1f), Vec3d(blockTask.blockPos).add(0.5, 0.5, 0.5)) if (rayTrace == null) { refreshData() @@ -580,27 +591,46 @@ object HighwayTools : Module() { val facing = rayTrace?.sideHit ?: return false val rotation = RotationUtils.getRotationTo(Vec3d(blockTask.blockPos).add(0.5, 0.5, 0.5).add(Vec3d(facing.directionVec).scale(0.499)), true) - when (interacting.value) { - InteractMode.SPOOF -> { - val rotationPacket = CPacketPlayer.PositionRotation(mc.player.posX, mc.player.posY, mc.player.posZ, rotation.x.toFloat(), rotation.y.toFloat(), mc.player.onGround) - mc.connection!!.sendPacket(rotationPacket) - } - InteractMode.VIEWLOCK -> { - mc.player.rotationYaw = rotation.x.toFloat() - mc.player.rotationPitch = rotation.y.toFloat() + if (blockTask.taskState != TaskState.BREAKING) { + when (interacting.value) { + InteractMode.SPOOF -> { + val rotationPacket = CPacketPlayer.PositionRotation(mc.player.posX, mc.player.posY, mc.player.posZ, rotation.x.toFloat(), rotation.y.toFloat(), mc.player.onGround) + mc.connection!!.sendPacket(rotationPacket) + } + InteractMode.VIEWLOCK -> { + mc.player.rotationYaw = rotation.x.toFloat() + mc.player.rotationPitch = rotation.y.toFloat() + } } } - val digPacket: CPacketPlayerDigging = when (blockTask.taskState) { - TaskState.BREAK -> CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, blockTask.blockPos, facing) - TaskState.BREAKING -> CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, blockTask.blockPos, facing) - else -> CPacketPlayerDigging() + when (mc.world.getBlockState(blockTask.blockPos).block) { + Blocks.NETHERRACK -> { + updateTask(blockTask, TaskState.BROKEN) + Thread { + Thread.sleep(16L) + mc.connection!!.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, blockTask.blockPos, facing)) + Thread.sleep(16L) + mc.connection!!.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, blockTask.blockPos, facing)) + mc.player.swingArm(EnumHand.MAIN_HAND) + }.start() + } + else -> { + val digPacket: CPacketPlayerDigging = when (blockTask.taskState) { + TaskState.BREAK -> CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, blockTask.blockPos, facing) + TaskState.BREAKING -> CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, blockTask.blockPos, facing) + else -> CPacketPlayerDigging() + } + if (blockTask.taskState == TaskState.BREAK) updateTask(blockTask, TaskState.BREAKING) + Thread { + Thread.sleep(25L) + mc.connection!!.sendPacket(digPacket) + mc.player.swingArm(EnumHand.MAIN_HAND) + }.start() + } } - Thread { - Thread.sleep(25L) - mc.connection!!.sendPacket(digPacket) - mc.player.swingArm(EnumHand.MAIN_HAND) - }.start() + + return true } @@ -639,7 +669,8 @@ object HighwayTools : Module() { if (mc.world.getBlockState(offPos).material.isReplaceable) continue if (mc.player.getPositionEyes(1f).distanceTo(Vec3d(offPos).add(BlockUtils.getHitVecOffset(side))) > maxReach.value) continue val rotationVector = Vec3d(offPos).add(0.5, 0.5, 0.5).add(Vec3d(side.opposite.directionVec).scale(0.499)) - val rt = mc.world.rayTraceBlocks(mc.player.getPositionEyes(1f), rotationVector)?: continue + val rt = mc.world.rayTraceBlocks(mc.player.getPositionEyes(1f), rotationVector, false)?: continue + sendChatMessage(rt.toString()) if (rt.typeOfHit != RayTraceResult.Type.BLOCK) continue if (rt.blockPos == offPos && offPos.offset(rt.sideHit) == blockTask.blockPos) { rayTraces.add(rt) @@ -726,13 +757,13 @@ object HighwayTools : Module() { return renderer } - private fun printDebug() { - var message = "\n\n" - message += "-------------------- QUEUE -------------------" - for (blockTask in blockQueue) message += "\n" + blockTask.block.localizedName + "@(" + blockTask.blockPos.asString() + ") Priority: " + blockTask.taskState.ordinal + " State: " + blockTask.taskState.toString() - message += "\n-------------------- DONE --------------------" - for (blockTask in doneQueue) message += "\n" + blockTask.block.localizedName + "@(" + blockTask.blockPos.asString() + ") Priority: " + blockTask.taskState.ordinal + " State: " + blockTask.taskState.toString() - sendChatMessage(message) + private fun getQueue(): List { + val message: MutableList = mutableListOf() + message.add("QUEUE:") + for (blockTask in blockQueue) message.add(" " + blockTask.block.localizedName + "@(" + blockTask.blockPos.asString() + ") Priority: " + blockTask.taskState.ordinal + " State: " + blockTask.taskState.toString()) + message.add("DONE:") + for (blockTask in doneQueue) message.add(" " + blockTask.block.localizedName + "@(" + blockTask.blockPos.asString() + ") Priority: " + blockTask.taskState.ordinal + " State: " + blockTask.taskState.toString()) + return message } fun printSettings() { @@ -778,7 +809,7 @@ object HighwayTools : Module() { sendChatMessage(message) } - fun gatherStatistics(): List { + fun gatherStatistics(): MutableList { val currentTask: BlockTask? = if (isDone()) { null } else { @@ -789,23 +820,30 @@ object HighwayTools : Module() { val minutes = ((runtimeSec % 3600) / 60).toInt().toString().padStart(2,'0') val hours = (runtimeSec / 3600).toInt().toString().padStart(2,'0') - return listOf( - "§rStatistics", - " §9> §rRuntime: §7$hours:$minutes:$seconds", - " §9> §rPlacements per second: §7%.2f (%.2f)".format(totalBlocksPlaced / runtimeSec, (totalBlocksPlaced / runtimeSec) * 2), - " §9> §rBreaks per second: §7%.2f (%.2f)".format(totalBlocksDestroyed / runtimeSec, (totalBlocksDestroyed / runtimeSec) * 2), - " §9> §rDistance per hour: §7%.2f".format((getDistance(startingBlockPos.toVec3d(), currentBlockPos.toVec3d()).toInt() / runtimeSec) * 60 * 60), - "§rInfo", - " §9> §rStatus: §7${currentTask?.taskState}", - " §9> §rTarget state: §7${currentTask?.block}", - " §9> §rPosition: §7${currentTask?.blockPos}", - "§rEstimations", - " §9> §rTheoretical material left: §7${12345} ${material.localizedName}", - " §9> §rTheoretical block breakings left: §7${232344}", - " §9> §rTheoretical distance left: §7${62944}", - " §9> §rEstimated time left: §704:13:11", - " §9> §rEstimated destination: §7BlockPos{x=-125533, y=119, z=125533}" - ) + val statistics = mutableListOf() + + statistics.addAll(listOf("§rStatistic", + " §7Runtime: §9$hours:$minutes:$seconds", + " §7Placements per second: §9%.2f".format(totalBlocksPlaced / runtimeSec), + " §7Breaks per second: §9%.2f".format(totalBlocksDestroyed / runtimeSec), + " §7Distance per hour: §9%.2f".format((getDistance(startingBlockPos.toVec3d(), currentBlockPos.toVec3d()).toInt() / runtimeSec) * 60 * 60), + "§rTask information", + " §7Status: §9${currentTask?.taskState}", + " §7Target state: §9${currentTask?.block}", + " §7Position: §9${currentTask?.blockPos}")) +// "§rEstimation", +// " §9> §rTheoretical material left: §7${12345} ${material.localizedName}", +// " §9> §rTheoretical block breakings left: §7${232344}", +// " §9> §rTheoretical distance left: §7${62944}", +// " §9> §rEstimated time left: §704:13:11", +// " §9> §rEstimated destination: §7BlockPos{x=-125533, y=119, z=125533}")) + + if (printDebug.value) { + for (x in getQueue()) sendChatMessage(x) + statistics.addAll(getQueue()) + } + + return statistics } fun getNextBlock(): BlockPos { @@ -1011,11 +1049,13 @@ object HighwayTools : Module() { enum class TaskState(val color: ColorHolder) { DONE(ColorHolder(50, 50, 50)), BREAKING(ColorHolder(240, 222, 60)), - PLACED(ColorHolder(53, 222, 66)), + LIQUID_BREAK(ColorHolder(220, 41, 140)), LIQUID_SOURCE(ColorHolder(120, 41, 240)), LIQUID_FLOW(ColorHolder(120, 41, 240)), BREAK(ColorHolder(222, 0, 0)), - PLACE(ColorHolder(35, 188, 254)) + BROKEN(ColorHolder(111, 0, 0)), + PLACE(ColorHolder(35, 188, 254)), + PLACED(ColorHolder(53, 222, 66)) } } From ac0a45f389c8b7aed3f73efaad46e2e56074b593 Mon Sep 17 00:00:00 2001 From: Christian Date: Wed, 28 Oct 2020 05:48:02 +0100 Subject: [PATCH 047/390] Logic fixes --- .../kami/module/modules/misc/HighwayTools.kt | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index c0c0559d9c..63f792d5ea 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -489,7 +489,7 @@ object HighwayTools : Module() { private fun inventoryManager(blockTask: BlockTask): Boolean { when (blockTask.taskState) { - TaskState.BREAK -> { + TaskState.BREAK, TaskState.LIQUID_BREAK -> { if (InventoryUtils.getSlotsHotbar(278) == null && InventoryUtils.getSlotsNoHotbar(278) != null) { InventoryUtils.moveToHotbar(278, 130) return true @@ -501,7 +501,7 @@ object HighwayTools : Module() { } InventoryUtils.swapSlotToItem(278) } - TaskState.PLACE -> { + TaskState.PLACE, TaskState.LIQUID_FLOW, TaskState.LIQUID_SOURCE -> { if (InventoryUtils.getSlotsHotbar(getIdFromBlock(blockTask.block)) == null && InventoryUtils.getSlotsNoHotbar(getIdFromBlock(blockTask.block)) != null) { for (x in InventoryUtils.getSlotsNoHotbar(getIdFromBlock(blockTask.block))!!) { @@ -670,7 +670,6 @@ object HighwayTools : Module() { if (mc.player.getPositionEyes(1f).distanceTo(Vec3d(offPos).add(BlockUtils.getHitVecOffset(side))) > maxReach.value) continue val rotationVector = Vec3d(offPos).add(0.5, 0.5, 0.5).add(Vec3d(side.opposite.directionVec).scale(0.499)) val rt = mc.world.rayTraceBlocks(mc.player.getPositionEyes(1f), rotationVector, false)?: continue - sendChatMessage(rt.toString()) if (rt.typeOfHit != RayTraceResult.Type.BLOCK) continue if (rt.blockPos == offPos && offPos.offset(rt.sideHit) == blockTask.blockPos) { rayTraces.add(rt) @@ -739,10 +738,10 @@ object HighwayTools : Module() { } private fun centerPlayer(): Boolean { - return if (autoCenter.value == Surround.AutoCenterMode.OFF) { + return if (autoCenter.value == AutoCenterMode.OFF) { true } else { - SurroundUtils.centerPlayer(autoCenter.value == Surround.AutoCenterMode.TP) + SurroundUtils.centerPlayer(autoCenter.value == AutoCenterMode.TP) } } @@ -822,15 +821,27 @@ object HighwayTools : Module() { val statistics = mutableListOf() - statistics.addAll(listOf("§rStatistic", + statistics.addAll(listOf( + "§rPerformance", " §7Runtime: §9$hours:$minutes:$seconds", " §7Placements per second: §9%.2f".format(totalBlocksPlaced / runtimeSec), " §7Breaks per second: §9%.2f".format(totalBlocksDestroyed / runtimeSec), " §7Distance per hour: §9%.2f".format((getDistance(startingBlockPos.toVec3d(), currentBlockPos.toVec3d()).toInt() / runtimeSec) * 60 * 60), - "§rTask information", + "§rEnvironment", + " §7Starting coordinates: §9$startingBlockPos", + " §7Direction: §9${buildDirectionSaved.cardinalName}", + " §7Blocks destroyed: §9$totalBlocksDestroyed", + " §7Blocks placed: §9$totalBlocksPlaced", + " §7Material: §9${material.localizedName}", + " §7Filler: §9${fillerMat.localizedName}", + "§rTask", " §7Status: §9${currentTask?.taskState}", " §7Target state: §9${currentTask?.block}", - " §7Position: §9${currentTask?.blockPos}")) + " §7Position: §9${currentTask?.blockPos}", + "§rDebug", + " §7Mining stuck: §9$stuckMining", + " §7Building stuck: §9$stuckBuilding", + " §7Pathing: §9$pathing")) // "§rEstimation", // " §9> §rTheoretical material left: §7${12345} ${material.localizedName}", // " §9> §rTheoretical block breakings left: §7${232344}", @@ -839,7 +850,7 @@ object HighwayTools : Module() { // " §9> §rEstimated destination: §7BlockPos{x=-125533, y=119, z=125533}")) if (printDebug.value) { - for (x in getQueue()) sendChatMessage(x) + // for (x in getQueue()) sendChatMessage(x) statistics.addAll(getQueue()) } From 5d4d10d4e0a0041ec6b56df7af21b76af62e8136 Mon Sep 17 00:00:00 2001 From: Christian Date: Wed, 28 Oct 2020 05:52:12 +0100 Subject: [PATCH 048/390] Added autocenter and fix TickEvent --- .../kami/module/modules/misc/AutoObsidian.kt | 46 +++++++++++-------- 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt index c1a6633931..7d8662fef9 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt @@ -10,6 +10,7 @@ import me.zeroeightsix.kami.util.BlockUtils import me.zeroeightsix.kami.util.BlockUtils.isPlaceableForChest import me.zeroeightsix.kami.util.EntityUtils.getDroppedItem import me.zeroeightsix.kami.util.InventoryUtils +import me.zeroeightsix.kami.util.combat.SurroundUtils import me.zeroeightsix.kami.util.event.listener import me.zeroeightsix.kami.util.math.RotationUtils.getRotationTo import me.zeroeightsix.kami.util.text.MessageSendHelper.sendChatMessage @@ -28,8 +29,7 @@ import net.minecraft.util.EnumHand import net.minecraft.util.math.BlockPos import net.minecraft.util.math.RayTraceResult import net.minecraft.util.math.Vec3d -import java.util.concurrent.Executors -import java.util.concurrent.TimeUnit +import net.minecraftforge.fml.common.gameevent.TickEvent import kotlin.math.ceil import kotlin.math.floor @@ -46,6 +46,7 @@ object AutoObsidian : Module() { private val targetStacks = register(Settings.integerBuilder("TargetStacks").withValue(1).withRange(1, 20)) private val delayTicks = register(Settings.integerBuilder("DelayTicks").withValue(5).withRange(0, 10)) private val interacting = register(Settings.enumBuilder(InteractMode::class.java).withName("InteractMode").withValue(InteractMode.SPOOF)) + private val autoCenter = register(Settings.enumBuilder(AutoCenterMode::class.java).withName("AutoCenter").withValue(AutoCenterMode.MOTION)) private val maxReach = register(Settings.floatBuilder("MaxReach").withMinimum(2.0F).withValue(5.4F)) enum class State { @@ -56,6 +57,14 @@ object AutoObsidian : Module() { PLACING, OPENING, PRE_MINING, MINING, COLLECTING, DONE } + private enum class InteractMode { + OFF, SPOOF, VIEWLOCK + } + + enum class AutoCenterMode { + OFF, TP, MOTION + } + var pathing = false var goal: BlockPos? = null var state = State.SEARCHING @@ -69,7 +78,6 @@ object AutoObsidian : Module() { private var obsidianCount = -1 private var tickCount = 0 private var openTime = 0L - private var ticks = true override fun isActive(): Boolean { return isEnabled && active @@ -82,12 +90,9 @@ object AutoObsidian : Module() { init { listener { - if (ticks) { - ticks = !ticks - } else { - ticks = !ticks + if (it.phase != TickEvent.Phase.END) { if (mc.playerController == null) return@listener - /* Just a delay */ + if (tickCount < delayTicks.value) { tickCount++ return@listener @@ -109,6 +114,7 @@ object AutoObsidian : Module() { /* Positions need to be updated after moving while collecting dropped shulker box */ val currentPos = BlockPos(floor(mc.player.posX).toInt(), floor(mc.player.posY).toInt(), floor(mc.player.posZ).toInt()) playerPos = currentPos + centerPlayer() setPlacingPos() } } @@ -130,6 +136,8 @@ object AutoObsidian : Module() { } } } + } else { + return@listener } } } @@ -319,7 +327,7 @@ object AutoObsidian : Module() { if (System.currentTimeMillis() >= openTime + 2000L) { openTime = System.currentTimeMillis() Thread{ - Thread.sleep(25L) + Thread.sleep(delayTicks.value * 25L) val placePacket = CPacketPlayerTryUseItemOnBlock(rayTrace.blockPos, rayTrace.sideHit, EnumHand.MAIN_HAND, hitVecOffset.x.toFloat(), hitVecOffset.y.toFloat(), hitVecOffset.z.toFloat()) mc.connection!!.sendPacket(placePacket) mc.player.swingArm(EnumHand.MAIN_HAND) @@ -362,7 +370,7 @@ object AutoObsidian : Module() { } } if (rayTraces.size == 0) { - sendChatMessage("Trying to place through wall $pos") + sendChatMessage("Position: $pos not available") // placeBlockWall(pos, mat) return } @@ -394,7 +402,7 @@ object AutoObsidian : Module() { } Thread{ - Thread.sleep(25L) + Thread.sleep(delayTicks.value * 25L) val placePacket = CPacketPlayerTryUseItemOnBlock(rayTrace.blockPos, rayTrace.sideHit, EnumHand.MAIN_HAND, hitVecOffset.x.toFloat(), hitVecOffset.y.toFloat(), hitVecOffset.z.toFloat()) mc.connection!!.sendPacket(placePacket) mc.player.swingArm(EnumHand.MAIN_HAND) @@ -445,7 +453,7 @@ object AutoObsidian : Module() { } Thread { - Thread.sleep(25L) + Thread.sleep(delayTicks.value * 25L) if (pre) { mc.connection!!.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, pos, facing)) if (state != State.SEARCHING) state = State.MINING else searchingState = SearchingState.MINING @@ -464,6 +472,14 @@ object AutoObsidian : Module() { } else false } + private fun centerPlayer(): Boolean { + return if (autoCenter.value == AutoCenterMode.OFF) { + true + } else { + SurroundUtils.centerPlayer(autoCenter.value == AutoCenterMode.TP) + } + } + private fun reset() { active = false pathing = false @@ -475,10 +491,4 @@ object AutoObsidian : Module() { tickCount = 0 } /* End of tasks */ - - private enum class InteractMode { - OFF, - SPOOF, - VIEWLOCK - } } \ No newline at end of file From 42edc6dd4ce6e657251923625394d6648cf33979 Mon Sep 17 00:00:00 2001 From: Christian Date: Wed, 28 Oct 2020 06:12:01 +0100 Subject: [PATCH 049/390] Fixed tunnel filler material --- .../kami/module/modules/misc/HighwayTools.kt | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 63f792d5ea..d59418ee08 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -73,7 +73,7 @@ object HighwayTools : Module() { private val tickDelayBreak = register(Settings.integerBuilder("TickDelayBreak").withMinimum(0).withValue(0).withMaximum(16).withVisibility { page.value == Page.BEHAVIOR }) private val interacting = register(Settings.enumBuilder(InteractMode::class.java).withName("InteractMode").withValue(InteractMode.SPOOF).withVisibility { page.value == Page.BEHAVIOR }) private val illegalPlacements = register(Settings.booleanBuilder("IllegalPlacements").withValue(true).withVisibility { page.value == Page.BEHAVIOR }) - private val abundanceBreaking = register(Settings.booleanBuilder("AbundanceBreaking").withValue(true).withVisibility { page.value == Page.BEHAVIOR }) + // private val abundanceBreaking = register(Settings.booleanBuilder("AbundanceBreaking").withValue(true).withVisibility { page.value == Page.BEHAVIOR }) private val autoCenter = register(Settings.enumBuilder(AutoCenterMode::class.java).withName("AutoCenter").withValue(AutoCenterMode.MOTION).withVisibility { page.value == Page.BEHAVIOR }) private val stuckDelay = register(Settings.integerBuilder("TickDelayStuck").withMinimum(1).withValue(200).withMaximum(500).withVisibility { page.value == Page.BEHAVIOR }) val maxReach = register(Settings.floatBuilder("MaxReach").withMinimum(2.0F).withValue(5.4F).withVisibility { page.value == Page.BEHAVIOR }) @@ -981,13 +981,12 @@ object HighwayTools : Module() { } } Mode.TUNNEL -> { - material = Blocks.NETHERRACK if (baritoneMode.value) { cursor = relativeDirection(cursor, 1, 0) - blockOffsets.add(Pair(cursor, material)) + blockOffsets.add(Pair(cursor, fillerMat)) } cursor = relativeDirection(cursor, 1, 0) - blockOffsets.add(Pair(cursor, material)) + blockOffsets.add(Pair(cursor, fillerMat)) var buildIterationsWidth = buildWidth.value / 2 var evenCursor = relativeDirection(cursor, 1, 2) var isOdd = false @@ -995,12 +994,12 @@ object HighwayTools : Module() { isOdd = true buildIterationsWidth++ } else { - blockOffsets.add(Pair(evenCursor, material)) + blockOffsets.add(Pair(evenCursor, fillerMat)) } for (i in 1 until clearHeight.value + 2) { for (j in 1 until buildIterationsWidth) { var mat = Blocks.AIR - if (i == 1) mat = material + if (i == 1) mat = fillerMat blockOffsets.add(Pair(relativeDirection(cursor, j, -2), mat)) if (isOdd) blockOffsets.add(Pair(relativeDirection(cursor, j, 2), mat)) else blockOffsets.add(Pair(relativeDirection(evenCursor, j, 2), mat)) @@ -1015,7 +1014,7 @@ object HighwayTools : Module() { } Mode.FLAT -> { for (bp in VectorUtils.getBlockPositionsInArea(cursor.north(buildWidth.value).west(buildWidth.value), cursor.south(buildWidth.value).east(buildWidth.value))) { - blockOffsets.add(Pair(bp, material)) + blockOffsets.add(Pair(bp, fillerMat)) } } null -> { From ca2b40468792076da4294afcce6270b306d459da Mon Sep 17 00:00:00 2001 From: Christian Date: Thu, 29 Oct 2020 07:53:08 +0100 Subject: [PATCH 050/390] Better stats --- .../java/me/zeroeightsix/kami/module/modules/player/Freecam.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/player/Freecam.kt b/src/main/java/me/zeroeightsix/kami/module/modules/player/Freecam.kt index 144cc4fc1d..d9a928de37 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/player/Freecam.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/player/Freecam.kt @@ -32,7 +32,7 @@ import kotlin.math.sin object Freecam : Module() { private val horizontalSpeed = register(Settings.floatBuilder("HorizontalSpeed").withValue(20f).withRange(1f, 50f).withStep(1f)) private val verticalSpeed = register(Settings.floatBuilder("VerticalSpeed").withValue(20f).withRange(1f, 50f).withStep(1f)) - private val autoRotate = register(Settings.b("AutoRotate", true)) + private val autoRotate = register(Settings.b("AutoRotate", false)) private val arrowKeyMove = register(Settings.b("ArrowKeyMove", true)) private val disableOnDisconnect = register(Settings.b("DisconnectDisable", true)) From 8306d28ee0494bcd2373a23036e1d7cc710f5c87 Mon Sep 17 00:00:00 2001 From: Christian Date: Thu, 29 Oct 2020 07:54:24 +0100 Subject: [PATCH 051/390] Missing changes --- .../zeroeightsix/kami/gui/kami/KamiGUI.java | 8 ++-- .../kami/module/modules/misc/HighwayTools.kt | 39 +++++++++++-------- 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/gui/kami/KamiGUI.java b/src/main/java/me/zeroeightsix/kami/gui/kami/KamiGUI.java index 94647b0f62..29377ab916 100644 --- a/src/main/java/me/zeroeightsix/kami/gui/kami/KamiGUI.java +++ b/src/main/java/me/zeroeightsix/kami/gui/kami/KamiGUI.java @@ -531,11 +531,9 @@ public void onTick() { Label htLabel = new Label(""); htLabel.addTickListener(() -> { htLabel.setText(""); - if (HighwayTools.INSTANCE.isEnabled()) { - List statistics = HighwayTools.INSTANCE.gatherStatistics(); - for (String line: statistics) { - htLabel.addLine(line); - } + List statistics = HighwayTools.INSTANCE.gatherStatistics(); + for (String line: statistics) { + htLabel.addLine(line); } }); ht.addChild(htLabel); diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index d59418ee08..93bd38afd3 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -4,7 +4,6 @@ import baritone.api.BaritoneAPI import me.zeroeightsix.kami.event.events.RenderWorldEvent import me.zeroeightsix.kami.event.events.SafeTickEvent import me.zeroeightsix.kami.module.Module -import me.zeroeightsix.kami.module.modules.combat.Surround import me.zeroeightsix.kami.module.modules.player.NoBreakAnimation import me.zeroeightsix.kami.process.HighwayToolsProcess import me.zeroeightsix.kami.setting.Settings @@ -59,12 +58,12 @@ object HighwayTools : Module() { private val page = register(Settings.e("Page", Page.BUILD)) // build settings - val clearSpace = register(Settings.booleanBuilder("ClearSpace").withValue(true).withVisibility { page.value == Page.BUILD }) - var clearHeight = register(Settings.integerBuilder("ClearHeight").withMinimum(1).withValue(4).withMaximum(6).withVisibility { page.value == Page.BUILD && clearSpace.value }) - private var buildWidth = register(Settings.integerBuilder("BuildWidth").withMinimum(1).withValue(5).withMaximum(9).withVisibility { page.value == Page.BUILD }) - private val railing = register(Settings.booleanBuilder("Railing").withValue(true).withVisibility { page.value == Page.BUILD }) - private var railingHeight = register(Settings.integerBuilder("RailingHeight").withMinimum(0).withValue(1).withMaximum(clearHeight.value).withVisibility { railing.value && page.value == Page.BUILD }) - private val cornerBlock = register(Settings.booleanBuilder("CornerBlock").withValue(false).withVisibility { page.value == Page.BUILD }) + val clearSpace = register(Settings.booleanBuilder("ClearSpace").withValue(true).withVisibility { page.value == Page.BUILD && mode.value == Mode.HIGHWAY }) + var clearHeight = register(Settings.integerBuilder("Height").withMinimum(1).withValue(4).withMaximum(6).withVisibility { page.value == Page.BUILD && clearSpace.value }) + private var buildWidth = register(Settings.integerBuilder("Width").withMinimum(1).withValue(5).withMaximum(9).withVisibility { page.value == Page.BUILD }) + private val railing = register(Settings.booleanBuilder("Railing").withValue(true).withVisibility { page.value == Page.BUILD && mode.value == Mode.HIGHWAY }) + private var railingHeight = register(Settings.integerBuilder("RailingHeight").withMinimum(0).withValue(1).withMaximum(clearHeight.value).withVisibility { railing.value && page.value == Page.BUILD && mode.value == Mode.HIGHWAY }) + private val cornerBlock = register(Settings.booleanBuilder("CornerBlock").withValue(false).withVisibility { page.value == Page.BUILD && mode.value == Mode.HIGHWAY }) // behavior settings val baritoneMode = register(Settings.booleanBuilder("AutoMode").withValue(true).withVisibility { page.value == Page.BEHAVIOR }) @@ -74,6 +73,7 @@ object HighwayTools : Module() { private val interacting = register(Settings.enumBuilder(InteractMode::class.java).withName("InteractMode").withValue(InteractMode.SPOOF).withVisibility { page.value == Page.BEHAVIOR }) private val illegalPlacements = register(Settings.booleanBuilder("IllegalPlacements").withValue(true).withVisibility { page.value == Page.BEHAVIOR }) // private val abundanceBreaking = register(Settings.booleanBuilder("AbundanceBreaking").withValue(true).withVisibility { page.value == Page.BEHAVIOR }) + private val sloppyDigging = register(Settings.booleanBuilder("SloppyDigging").withValue(true).withVisibility { page.value == Page.BEHAVIOR && mode.value == Mode.TUNNEL}) private val autoCenter = register(Settings.enumBuilder(AutoCenterMode::class.java).withName("AutoCenter").withValue(AutoCenterMode.MOTION).withVisibility { page.value == Page.BEHAVIOR }) private val stuckDelay = register(Settings.integerBuilder("TickDelayStuck").withMinimum(1).withValue(200).withMaximum(500).withVisibility { page.value == Page.BEHAVIOR }) val maxReach = register(Settings.floatBuilder("MaxReach").withMinimum(2.0F).withValue(5.4F).withVisibility { page.value == Page.BEHAVIOR }) @@ -112,7 +112,9 @@ object HighwayTools : Module() { private var lastViewVec: RayTraceResult? = null private var startTime: Long = 0L private var runtimeSec: Double = 0.0 - + private var prevFood: Int = 0 + private var foodLoss: Int = 1 + private var lastStats: List = listOf() // stats private var totalBlocksPlaced = 0 private var totalBlocksDestroyed = 0 @@ -130,6 +132,11 @@ object HighwayTools : Module() { if (relativeDirection(currentBlockPos, 1, 0) == mc.player.positionVector.toBlockPos()) { if (!isDone() && !BaritoneUtils.paused && !AutoObsidian.isActive()) { centerPlayer() + val currentFood = mc.player.getFoodStats().foodLevel + if (currentFood != prevFood) { + prevFood = currentFood + foodLoss++ + } if (!doTask()) { if (!pathing) { stuckBuilding += 1 @@ -197,6 +204,8 @@ object HighwayTools : Module() { buildDirectionSaved = getPlayerCardinal(mc.player) startTime = System.currentTimeMillis() runtimeSec = 0.1 + totalBlocksPlaced = 0 + totalBlocksDestroyed = 0 if (baritoneMode.value) { baritoneSettingAllowPlace = BaritoneAPI.getSettings().allowPlace.value @@ -223,7 +232,6 @@ object HighwayTools : Module() { playerHotbarSlot = -1 lastHotbarSlot = -1 - if (baritoneMode.value) { BaritoneAPI.getSettings().allowPlace.value = baritoneSettingAllowPlace if (!goalRender.value) BaritoneAPI.getSettings().renderGoal.value = baritoneSettingRenderGoal @@ -231,8 +239,6 @@ object HighwayTools : Module() { if (baritoneProcess.isPresent && baritoneProcess.get() == HighwayToolsProcess) baritoneProcess.get().onLostControl() } printDisable() - totalBlocksPlaced = 0 - totalBlocksDestroyed = 0 } private fun addTask(blockPos: BlockPos, taskState: TaskState, material: Block) { @@ -827,6 +833,7 @@ object HighwayTools : Module() { " §7Placements per second: §9%.2f".format(totalBlocksPlaced / runtimeSec), " §7Breaks per second: §9%.2f".format(totalBlocksDestroyed / runtimeSec), " §7Distance per hour: §9%.2f".format((getDistance(startingBlockPos.toVec3d(), currentBlockPos.toVec3d()).toInt() / runtimeSec) * 60 * 60), + " §7One food loss per §9${totalBlocksDestroyed / foodLoss}§7 blocks", "§rEnvironment", " §7Starting coordinates: §9$startingBlockPos", " §7Direction: §9${buildDirectionSaved.cardinalName}", @@ -998,11 +1005,11 @@ object HighwayTools : Module() { } for (i in 1 until clearHeight.value + 2) { for (j in 1 until buildIterationsWidth) { - var mat = Blocks.AIR - if (i == 1) mat = fillerMat - blockOffsets.add(Pair(relativeDirection(cursor, j, -2), mat)) - if (isOdd) blockOffsets.add(Pair(relativeDirection(cursor, j, 2), mat)) - else blockOffsets.add(Pair(relativeDirection(evenCursor, j, 2), mat)) + if (i > 1) { + blockOffsets.add(Pair(relativeDirection(cursor, j, -2), Blocks.AIR)) + if (isOdd) blockOffsets.add(Pair(relativeDirection(cursor, j, 2), Blocks.AIR)) + else blockOffsets.add(Pair(relativeDirection(evenCursor, j, 2), Blocks.AIR)) + } } cursor = cursor.up() evenCursor = evenCursor.up() From 6e2ae355dfe4b5ed3b7fae32d3b3a718e088a4f2 Mon Sep 17 00:00:00 2001 From: Christian Date: Fri, 30 Oct 2020 09:44:54 +0100 Subject: [PATCH 052/390] Structure refactor and experiments --- .../kami/module/modules/misc/HighwayTools.kt | 172 +++++++++++------- 1 file changed, 104 insertions(+), 68 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 93bd38afd3..e31bb9acd1 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -26,6 +26,7 @@ import me.zeroeightsix.kami.util.math.VectorUtils.toVec3d import me.zeroeightsix.kami.util.text.MessageSendHelper.sendChatMessage import net.minecraft.block.Block import net.minecraft.block.Block.getIdFromBlock +import net.minecraft.block.BlockDynamicLiquid import net.minecraft.block.BlockLiquid import net.minecraft.client.audio.PositionedSoundRecord import net.minecraft.init.Blocks @@ -73,7 +74,8 @@ object HighwayTools : Module() { private val interacting = register(Settings.enumBuilder(InteractMode::class.java).withName("InteractMode").withValue(InteractMode.SPOOF).withVisibility { page.value == Page.BEHAVIOR }) private val illegalPlacements = register(Settings.booleanBuilder("IllegalPlacements").withValue(true).withVisibility { page.value == Page.BEHAVIOR }) // private val abundanceBreaking = register(Settings.booleanBuilder("AbundanceBreaking").withValue(true).withVisibility { page.value == Page.BEHAVIOR }) - private val sloppyDigging = register(Settings.booleanBuilder("SloppyDigging").withValue(true).withVisibility { page.value == Page.BEHAVIOR && mode.value == Mode.TUNNEL}) + // private val sloppyDigging = register(Settings.booleanBuilder("SloppyDigging").withValue(true).withVisibility { page.value == Page.BEHAVIOR && mode.value == Mode.TUNNEL}) + private val gapple = register(Settings.booleanBuilder("GappleLava").withValue(true).withVisibility { page.value == Page.BEHAVIOR }) private val autoCenter = register(Settings.enumBuilder(AutoCenterMode::class.java).withName("AutoCenter").withValue(AutoCenterMode.MOTION).withVisibility { page.value == Page.BEHAVIOR }) private val stuckDelay = register(Settings.integerBuilder("TickDelayStuck").withMinimum(1).withValue(200).withMaximum(500).withVisibility { page.value == Page.BEHAVIOR }) val maxReach = register(Settings.floatBuilder("MaxReach").withMinimum(2.0F).withValue(5.4F).withVisibility { page.value == Page.BEHAVIOR }) @@ -110,14 +112,14 @@ object HighwayTools : Module() { private var currentBlockPos = BlockPos(0, -1, 0) private var startingBlockPos = BlockPos(0, -1, 0) private var lastViewVec: RayTraceResult? = null + // stats + private var totalBlocksPlaced = 0 + private var totalBlocksDestroyed = 0 private var startTime: Long = 0L private var runtimeSec: Double = 0.0 private var prevFood: Int = 0 private var foodLoss: Int = 1 private var lastStats: List = listOf() - // stats - private var totalBlocksPlaced = 0 - private var totalBlocksDestroyed = 0 init { listener { @@ -128,14 +130,13 @@ object HighwayTools : Module() { if (baritoneMode.value) { pathing = BaritoneAPI.getProvider().primaryBaritone.pathingBehavior.isPathing - if (relativeDirection(currentBlockPos, 1, 0) == mc.player.positionVector.toBlockPos()) { if (!isDone() && !BaritoneUtils.paused && !AutoObsidian.isActive()) { centerPlayer() val currentFood = mc.player.getFoodStats().foodLevel if (currentFood != prevFood) { + if (currentFood < prevFood) foodLoss++ prevFood = currentFood - foodLoss++ } if (!doTask()) { if (!pathing) { @@ -153,11 +154,13 @@ object HighwayTools : Module() { stuckBuilding = 0 } } else { - refreshData() - if (checkTasks() && !pathing) { - currentBlockPos = getNextBlock() - doneQueue.clear() - updateTasks() + if (isDone()) { + refreshData() + if (checkTasks() && !pathing) { + currentBlockPos = getNextBlock() + doneQueue.clear() + updateTasks() + } } } } @@ -242,11 +245,11 @@ object HighwayTools : Module() { } private fun addTask(blockPos: BlockPos, taskState: TaskState, material: Block) { - blockQueue.add(BlockTask(blockPos, taskState, material)) + blockQueue.add(BlockTask(blockPos, taskState, material, 0)) } private fun addTask(blockPos: BlockPos, material: Block) { - doneQueue.add(BlockTask(blockPos, TaskState.DONE, material)) + doneQueue.add(BlockTask(blockPos, TaskState.DONE, material, 0)) } private fun updateTask(blockTask: BlockTask, taskState: TaskState) { @@ -266,7 +269,7 @@ object HighwayTools : Module() { } private fun doTask(): Boolean { - if (!isDone() && !pathing && !BaritoneUtils.paused && !AutoObsidian.isActive()) { + if (!isDone() && !BaritoneUtils.paused && !AutoObsidian.isActive()) { if (waitTicks == 0) { val blockTask = blockQueue.peek() @@ -275,7 +278,7 @@ object HighwayTools : Module() { TaskState.BREAKING -> if(!doBREAKING(blockTask)) return false TaskState.BROKEN -> doBROKEN(blockTask) TaskState.PLACED -> doPLACED(blockTask) - TaskState.LIQUID_BREAK -> if(!mineBlock(blockTask)) return false + TaskState.LIQUID_BREAK -> if(!doBREAK(blockTask)) return false TaskState.BREAK -> if(!doBREAK(blockTask)) return false TaskState.PLACE, TaskState.LIQUID_SOURCE, TaskState.LIQUID_FLOW -> if(!doPLACE(blockTask)) return false } @@ -303,7 +306,7 @@ object HighwayTools : Module() { if (debugMessages.value == DebugMessages.IMPORTANT) sendChatMessage("Shuffled because of mining issue.") } - when (mc.world.getBlockState(blockTask.blockPos).block) { + when (val block = mc.world.getBlockState(blockTask.blockPos).block) { Blocks.AIR -> { stuckMining = 0 totalBlocksDestroyed++ @@ -315,13 +318,14 @@ object HighwayTools : Module() { doTask() } } - Blocks.LAVA -> { - updateTask(blockTask, TaskState.LIQUID_SOURCE) - updateTask(blockTask, fillerMat) - } - Blocks.FLOWING_LAVA -> { - updateTask(blockTask, TaskState.LIQUID_FLOW) - updateTask(blockTask, fillerMat) + is BlockLiquid -> { + if (block is BlockDynamicLiquid) { + updateTask(blockTask, TaskState.LIQUID_FLOW) + updateTask(blockTask, fillerMat) + } else { + updateTask(blockTask, TaskState.LIQUID_SOURCE) + updateTask(blockTask, fillerMat) + } } else -> { if (!mineBlock(blockTask)) return false @@ -356,7 +360,7 @@ object HighwayTools : Module() { blockTask.block == Blocks.AIR && block != Blocks.AIR -> updateTask(blockTask, TaskState.BREAK) else -> updateTask(blockTask, TaskState.PLACE) } - doTask() + // doTask() } private fun doBREAK(blockTask: BlockTask): Boolean { @@ -372,18 +376,19 @@ object HighwayTools : Module() { // last check before breaking when (block) { - Blocks.LAVA -> { - updateTask(blockTask, TaskState.LIQUID_SOURCE) - updateTask(blockTask, fillerMat) - } - Blocks.FLOWING_LAVA -> { - updateTask(blockTask, TaskState.LIQUID_FLOW) - updateTask(blockTask, fillerMat) - } Blocks.AIR -> { updateTask(blockTask, TaskState.DONE) doTask() } + is BlockLiquid -> { + if (block is BlockDynamicLiquid) { + updateTask(blockTask, TaskState.LIQUID_FLOW) + updateTask(blockTask, fillerMat) + } else { + updateTask(blockTask, TaskState.LIQUID_SOURCE) + updateTask(blockTask, fillerMat) + } + } else -> { // liquid search around the breaking block if (blockTask.taskState != TaskState.LIQUID_BREAK) { @@ -403,11 +408,6 @@ object HighwayTools : Module() { private fun doPLACE(blockTask: BlockTask): Boolean { val block = mc.world.getBlockState(blockTask.blockPos).block - if (blockTask.block == Blocks.AIR && block !is BlockLiquid) { - blockQueue.poll() - return true - } - when { block == material && block == blockTask.block -> updateTask(blockTask, TaskState.PLACED) block == fillerMat && block == blockTask.block -> updateTask(blockTask, TaskState.PLACED) @@ -444,8 +444,18 @@ object HighwayTools : Module() { if (b == block) continue@loop } when { - blockTask.block == material && block == Blocks.AIR -> return false - blockTask.block == Blocks.AIR && block != Blocks.AIR -> return false + blockTask.block == material && block == Blocks.AIR -> { + sendChatMessage("1") + return false + } + mode.value == Mode.TUNNEL && blockTask.block == fillerMat && block == Blocks.AIR -> { + sendChatMessage("2") + return false + } + blockTask.block == Blocks.AIR && block != Blocks.AIR -> { + sendChatMessage("3") + return false + } } } return true @@ -454,9 +464,14 @@ object HighwayTools : Module() { private fun updateTasks() { updateBlockArray() for ((blockPos, blockType) in blockOffsets) { + val isReplaceable = mc.world.getBlockState(blockPos).material.isReplaceable when (val block = mc.world.getBlockState(blockPos).block) { - Blocks.LAVA, Blocks.WATER -> addTask(blockPos, TaskState.LIQUID_SOURCE, fillerMat) - Blocks.FLOWING_LAVA, Blocks.FLOWING_WATER -> addTask(blockPos, TaskState.LIQUID_FLOW, fillerMat) + is BlockLiquid -> { + when (block is BlockDynamicLiquid) { + true -> addTask(blockPos, TaskState.LIQUID_FLOW, fillerMat) + false -> addTask(blockPos, TaskState.LIQUID_SOURCE, fillerMat) + } + } else -> { when (blockType) { Blocks.AIR -> { @@ -469,15 +484,23 @@ object HighwayTools : Module() { material -> { when { block == material -> addTask(blockPos, material) - block != Blocks.AIR && block != material -> addTask(blockPos, TaskState.BREAK, material) - block == Blocks.AIR -> addTask(blockPos, TaskState.PLACE, material) + !isReplaceable && block != material -> addTask(blockPos, TaskState.BREAK, material) + isReplaceable -> addTask(blockPos, TaskState.PLACE, material) } } fillerMat -> { - val blockUp = mc.world.getBlockState(blockPos.up()).block - when { - getPlaceableSide(blockPos.up()) == null && blockUp != material -> addTask(blockPos, TaskState.PLACE, fillerMat) - getPlaceableSide(blockPos.up()) != null -> addTask(blockPos, fillerMat) + if (mode.value == Mode.HIGHWAY) { + val blockUp = mc.world.getBlockState(blockPos.up()).block + when { + getPlaceableSide(blockPos.up()) == null && blockUp != material -> addTask(blockPos, TaskState.PLACE, fillerMat) + getPlaceableSide(blockPos.up()) != null -> addTask(blockPos, fillerMat) + } + } else { + when { + block == fillerMat -> addTask(blockPos, fillerMat) + !isReplaceable && block != fillerMat -> addTask(blockPos, TaskState.BREAK, fillerMat) + isReplaceable -> addTask(blockPos, TaskState.PLACE, fillerMat) + } } } } @@ -498,7 +521,6 @@ object HighwayTools : Module() { TaskState.BREAK, TaskState.LIQUID_BREAK -> { if (InventoryUtils.getSlotsHotbar(278) == null && InventoryUtils.getSlotsNoHotbar(278) != null) { InventoryUtils.moveToHotbar(278, 130) - return true } else if (InventoryUtils.getSlots(0, 35, 278) == null) { sendChatMessage("$chatName No Pickaxe was found in inventory") mc.getSoundHandler().playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) @@ -530,27 +552,24 @@ object HighwayTools : Module() { for (side in EnumFacing.values()) { val neighbour = blockTask.blockPos.offset(side) val neighbourBlock = mc.world.getBlockState(neighbour).block - - if (neighbourBlock == Blocks.LAVA || neighbourBlock == Blocks.FLOWING_LAVA) { + var flowing = false + if (neighbourBlock is BlockLiquid) { + if (neighbourBlock is BlockDynamicLiquid) flowing = true if (sqrt(mc.player.getDistanceSqToCenter(neighbour)) > maxReach.value) continue foundLiquid = true val found = mutableListOf>() for (bt in blockQueue) { if (bt.blockPos == neighbour) { - when (neighbourBlock) { - Blocks.LAVA, Blocks.WATER -> found.add(Triple(bt, TaskState.LIQUID_SOURCE, fillerMat)) - Blocks.FLOWING_LAVA, Blocks.FLOWING_WATER -> found.add(Triple(bt, TaskState.LIQUID_FLOW, fillerMat)) + when (flowing) { + false -> found.add(Triple(bt, TaskState.LIQUID_SOURCE, fillerMat)) + true -> found.add(Triple(bt, TaskState.LIQUID_FLOW, fillerMat)) } } } if (found.isEmpty()) { - when (neighbourBlock) { - Blocks.LAVA, Blocks.WATER -> { - addTask(neighbour, TaskState.LIQUID_SOURCE, fillerMat) - } - Blocks.FLOWING_LAVA, Blocks.FLOWING_WATER -> { - addTask(neighbour, TaskState.LIQUID_FLOW, fillerMat) - } + when (flowing) { + false -> addTask(neighbour, TaskState.LIQUID_SOURCE, fillerMat) + true -> addTask(neighbour, TaskState.LIQUID_FLOW, fillerMat) } } else { for (x in found) { @@ -669,7 +688,8 @@ object HighwayTools : Module() { } private fun placeBlock(blockTask: BlockTask): Boolean { - val rayTraces = mutableListOf() + val directHits = mutableListOf() +// val emergencyHits = mutableListOf() for (side in EnumFacing.values()) { val offPos = blockTask.blockPos.offset(side) if (mc.world.getBlockState(offPos).material.isReplaceable) continue @@ -677,11 +697,22 @@ object HighwayTools : Module() { val rotationVector = Vec3d(offPos).add(0.5, 0.5, 0.5).add(Vec3d(side.opposite.directionVec).scale(0.499)) val rt = mc.world.rayTraceBlocks(mc.player.getPositionEyes(1f), rotationVector, false)?: continue if (rt.typeOfHit != RayTraceResult.Type.BLOCK) continue - if (rt.blockPos == offPos && offPos.offset(rt.sideHit) == blockTask.blockPos) { - rayTraces.add(rt) - } + if (rt.blockPos == offPos && offPos.offset(rt.sideHit) == blockTask.blockPos) directHits.add(rt) +// if (rt.blockPos == offPos && offPos.offset(rt.sideHit) != blockTask.blockPos) emergencyHits.add(rt) } - if (rayTraces.size == 0) { + if (directHits.size == 0) { +// if (emergencyHits.size > 0) { +// var rayTrace = emergencyHits[0] +// var shortestRT = 99.0 +// for (rt in emergencyHits) { +// if (mc.player.getPositionEyes(1f).distanceTo(Vec3d(rt.blockPos).add(BlockUtils.getHitVecOffset(rt.sideHit))) < shortestRT) { +// shortestRT = mc.player.getPositionEyes(1f).distanceTo(Vec3d(rt.blockPos).add(BlockUtils.getHitVecOffset(rt.sideHit))) +// rayTrace = rt +// } +// } +// addTask(rayTrace.blockPos, TaskState.LIQUID_BREAK, Blocks.AIR) +// return true +// } return if (illegalPlacements.value) { if(debugMessages.value == DebugMessages.ALL) sendChatMessage("Trying to place through wall ${blockTask.blockPos}") placeBlockWall(blockTask) @@ -692,7 +723,7 @@ object HighwayTools : Module() { var rayTrace: RayTraceResult? = null var shortestRT = 99.0 - for (rt in rayTraces) { + for (rt in directHits) { if (mc.player.getPositionEyes(1f).distanceTo(Vec3d(rt.blockPos).add(BlockUtils.getHitVecOffset(rt.sideHit))) < shortestRT) { shortestRT = mc.player.getPositionEyes(1f).distanceTo(Vec3d(rt.blockPos).add(BlockUtils.getHitVecOffset(rt.sideHit))) rayTrace = rt @@ -1009,6 +1040,11 @@ object HighwayTools : Module() { blockOffsets.add(Pair(relativeDirection(cursor, j, -2), Blocks.AIR)) if (isOdd) blockOffsets.add(Pair(relativeDirection(cursor, j, 2), Blocks.AIR)) else blockOffsets.add(Pair(relativeDirection(evenCursor, j, 2), Blocks.AIR)) + if (buildDirectionSaved.isDiagonal) { + blockOffsets.add(Pair(relativeDirection(cursor, j, -3), Blocks.AIR)) + if (isOdd) blockOffsets.add(Pair(relativeDirection(cursor, j, 3), Blocks.AIR)) + else blockOffsets.add(Pair(relativeDirection(evenCursor, j, 3), Blocks.AIR)) + } } } cursor = cursor.up() @@ -1021,7 +1057,7 @@ object HighwayTools : Module() { } Mode.FLAT -> { for (bp in VectorUtils.getBlockPositionsInArea(cursor.north(buildWidth.value).west(buildWidth.value), cursor.south(buildWidth.value).east(buildWidth.value))) { - blockOffsets.add(Pair(bp, fillerMat)) + blockOffsets.add(Pair(bp, material)) } } null -> { @@ -1061,7 +1097,7 @@ object HighwayTools : Module() { MOTION } - data class BlockTask(val blockPos: BlockPos, var taskState: TaskState, var block: Block) + data class BlockTask(val blockPos: BlockPos, var taskState: TaskState, var block: Block, var age: Int) enum class TaskState(val color: ColorHolder) { DONE(ColorHolder(50, 50, 50)), From f093811af33133737853d567d5f719a7d1c93b42 Mon Sep 17 00:00:00 2001 From: Christian Date: Sat, 31 Oct 2020 03:36:34 +0100 Subject: [PATCH 053/390] Fixed some logic --- .../kami/module/modules/misc/HighwayTools.kt | 46 ++++++++----------- 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index e31bb9acd1..ee45e10177 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -155,11 +155,12 @@ object HighwayTools : Module() { } } else { if (isDone()) { - refreshData() if (checkTasks() && !pathing) { currentBlockPos = getNextBlock() doneQueue.clear() updateTasks() + } else { + refreshData() } } } @@ -349,7 +350,6 @@ object HighwayTools : Module() { updateTask(blockTask, TaskState.BREAK) } } - doTask() } private fun doPLACED(blockTask: BlockTask) { @@ -360,7 +360,6 @@ object HighwayTools : Module() { blockTask.block == Blocks.AIR && block != Blocks.AIR -> updateTask(blockTask, TaskState.BREAK) else -> updateTask(blockTask, TaskState.PLACE) } - // doTask() } private fun doBREAK(blockTask: BlockTask): Boolean { @@ -377,7 +376,11 @@ object HighwayTools : Module() { // last check before breaking when (block) { Blocks.AIR -> { - updateTask(blockTask, TaskState.DONE) + if (blockTask.block == Blocks.AIR) { + updateTask(blockTask, TaskState.DONE) + } else { + updateTask(blockTask, TaskState.PLACE) + } doTask() } is BlockLiquid -> { @@ -394,11 +397,10 @@ object HighwayTools : Module() { if (blockTask.taskState != TaskState.LIQUID_BREAK) { if (liquidHandler(blockTask)) { updateTask(blockTask, TaskState.LIQUID_BREAK) - doTask() - return false + return true } } - if (!inventoryManager(blockTask)) return false + if (!inventoryProcessor(blockTask)) return false if (!mineBlock(blockTask)) shuffleTasks() } } @@ -418,7 +420,7 @@ object HighwayTools : Module() { return false } - if (!inventoryManager(blockTask)) return false + if (!inventoryProcessor(blockTask)) return false if (!placeBlock(blockTask)) return false if (blockTask.taskState != TaskState.PLACE && isInsideBuild(blockTask.blockPos)) updateTask(blockTask, Blocks.AIR) updateTask(blockTask, TaskState.PLACED) @@ -444,18 +446,9 @@ object HighwayTools : Module() { if (b == block) continue@loop } when { - blockTask.block == material && block == Blocks.AIR -> { - sendChatMessage("1") - return false - } - mode.value == Mode.TUNNEL && blockTask.block == fillerMat && block == Blocks.AIR -> { - sendChatMessage("2") - return false - } - blockTask.block == Blocks.AIR && block != Blocks.AIR -> { - sendChatMessage("3") - return false - } + blockTask.block == material && block != material -> return false + mode.value == Mode.TUNNEL && blockTask.block == fillerMat && block != fillerMat -> return false + blockTask.block == Blocks.AIR && block != Blocks.AIR -> return false } } return true @@ -516,7 +509,7 @@ object HighwayTools : Module() { blockQueue.addAll(tmpQueue) } - private fun inventoryManager(blockTask: BlockTask): Boolean { + private fun inventoryProcessor(blockTask: BlockTask): Boolean { when (blockTask.taskState) { TaskState.BREAK, TaskState.LIQUID_BREAK -> { if (InventoryUtils.getSlotsHotbar(278) == null && InventoryUtils.getSlotsNoHotbar(278) != null) { @@ -530,17 +523,18 @@ object HighwayTools : Module() { InventoryUtils.swapSlotToItem(278) } TaskState.PLACE, TaskState.LIQUID_FLOW, TaskState.LIQUID_SOURCE -> { - if (InventoryUtils.getSlotsHotbar(getIdFromBlock(blockTask.block)) == null && - InventoryUtils.getSlotsNoHotbar(getIdFromBlock(blockTask.block)) != null) { - for (x in InventoryUtils.getSlotsNoHotbar(getIdFromBlock(blockTask.block))!!) { + val blockID = getIdFromBlock(blockTask.block) + if (InventoryUtils.getSlotsHotbar(blockID) == null && + InventoryUtils.getSlotsNoHotbar(blockID) != null) { + for (x in InventoryUtils.getSlotsNoHotbar(blockID)!!) { InventoryUtils.quickMoveSlot(x) } - } else if (InventoryUtils.getSlots(0, 35, getIdFromBlock(blockTask.block)) == null) { + } else if (InventoryUtils.getSlots(0, 35, blockID) == null) { sendChatMessage("$chatName No ${blockTask.block.localizedName} was found in inventory") mc.getSoundHandler().playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) disable() } - InventoryUtils.swapSlotToItem(getIdFromBlock(blockTask.block)) + InventoryUtils.swapSlotToItem(blockID) } else -> return false } From e06dd6b281bf2ffae52db52a6f5f38cae0985465 Mon Sep 17 00:00:00 2001 From: Christian Date: Sun, 1 Nov 2020 03:54:02 +0100 Subject: [PATCH 054/390] Build depth, bug fixes, more stats --- .../kami/module/modules/misc/HighwayTools.kt | 168 ++++++++++++------ .../kami/process/HighwayToolsProcess.kt | 4 +- 2 files changed, 118 insertions(+), 54 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index ee45e10177..c5e8a66d58 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -26,7 +26,6 @@ import me.zeroeightsix.kami.util.math.VectorUtils.toVec3d import me.zeroeightsix.kami.util.text.MessageSendHelper.sendChatMessage import net.minecraft.block.Block import net.minecraft.block.Block.getIdFromBlock -import net.minecraft.block.BlockDynamicLiquid import net.minecraft.block.BlockLiquid import net.minecraft.client.audio.PositionedSoundRecord import net.minecraft.init.Blocks @@ -119,7 +118,8 @@ object HighwayTools : Module() { private var runtimeSec: Double = 0.0 private var prevFood: Int = 0 private var foodLoss: Int = 1 - private var lastStats: List = listOf() + private var materialLeft = 0 + private var fillerMatLeft = 0 init { listener { @@ -130,7 +130,7 @@ object HighwayTools : Module() { if (baritoneMode.value) { pathing = BaritoneAPI.getProvider().primaryBaritone.pathingBehavior.isPathing - if (relativeDirection(currentBlockPos, 1, 0) == mc.player.positionVector.toBlockPos()) { + if (getNextWalkableBlock() == mc.player.positionVector.toBlockPos()) { if (!isDone() && !BaritoneUtils.paused && !AutoObsidian.isActive()) { centerPlayer() val currentFood = mc.player.getFoodStats().foodLevel @@ -156,9 +156,9 @@ object HighwayTools : Module() { } else { if (isDone()) { if (checkTasks() && !pathing) { - currentBlockPos = getNextBlock() + currentBlockPos = getNextBlock(getNextBlock()) doneQueue.clear() - updateTasks() + updateTasks(currentBlockPos) } else { refreshData() } @@ -246,11 +246,11 @@ object HighwayTools : Module() { } private fun addTask(blockPos: BlockPos, taskState: TaskState, material: Block) { - blockQueue.add(BlockTask(blockPos, taskState, material, 0)) + blockQueue.add(BlockTask(blockPos, taskState, material)) } private fun addTask(blockPos: BlockPos, material: Block) { - doneQueue.add(BlockTask(blockPos, TaskState.DONE, material, 0)) + doneQueue.add(BlockTask(blockPos, TaskState.DONE, material)) } private fun updateTask(blockTask: BlockTask, taskState: TaskState) { @@ -307,7 +307,7 @@ object HighwayTools : Module() { if (debugMessages.value == DebugMessages.IMPORTANT) sendChatMessage("Shuffled because of mining issue.") } - when (val block = mc.world.getBlockState(blockTask.blockPos).block) { + when (mc.world.getBlockState(blockTask.blockPos).block) { Blocks.AIR -> { stuckMining = 0 totalBlocksDestroyed++ @@ -320,12 +320,14 @@ object HighwayTools : Module() { } } is BlockLiquid -> { - if (block is BlockDynamicLiquid) { + var filler = fillerMat + if (isInsideBuild(blockTask.blockPos)) filler = material + if (mc.world.getBlockState(blockTask.blockPos).getValue(BlockLiquid.LEVEL) != 0) { updateTask(blockTask, TaskState.LIQUID_FLOW) - updateTask(blockTask, fillerMat) + updateTask(blockTask, filler) } else { updateTask(blockTask, TaskState.LIQUID_SOURCE) - updateTask(blockTask, fillerMat) + updateTask(blockTask, filler) } } else -> { @@ -350,6 +352,7 @@ object HighwayTools : Module() { updateTask(blockTask, TaskState.BREAK) } } + doTask() } private fun doPLACED(blockTask: BlockTask) { @@ -358,8 +361,10 @@ object HighwayTools : Module() { when { blockTask.block == block && block != Blocks.AIR -> updateTask(blockTask, TaskState.DONE) blockTask.block == Blocks.AIR && block != Blocks.AIR -> updateTask(blockTask, TaskState.BREAK) + blockTask.block == block && block == Blocks.AIR -> updateTask(blockTask, TaskState.BREAK) else -> updateTask(blockTask, TaskState.PLACE) } + doTask() } private fun doBREAK(blockTask: BlockTask): Boolean { @@ -384,12 +389,14 @@ object HighwayTools : Module() { doTask() } is BlockLiquid -> { - if (block is BlockDynamicLiquid) { + var filler = fillerMat + if (isInsideBuild(blockTask.blockPos)) filler = material + if (mc.world.getBlockState(blockTask.blockPos).getValue(BlockLiquid.LEVEL) != 0) { updateTask(blockTask, TaskState.LIQUID_FLOW) - updateTask(blockTask, fillerMat) + updateTask(blockTask, filler) } else { updateTask(blockTask, TaskState.LIQUID_SOURCE) - updateTask(blockTask, fillerMat) + updateTask(blockTask, filler) } } else -> { @@ -422,7 +429,7 @@ object HighwayTools : Module() { if (!inventoryProcessor(blockTask)) return false if (!placeBlock(blockTask)) return false - if (blockTask.taskState != TaskState.PLACE && isInsideBuild(blockTask.blockPos)) updateTask(blockTask, Blocks.AIR) + if (blockTask.taskState != TaskState.PLACE && isInsideSelection(blockTask.blockPos)) updateTask(blockTask, Blocks.AIR) updateTask(blockTask, TaskState.PLACED) if (blocksPerTick.value > blocksPlaced + 1) { blocksPlaced++ @@ -454,15 +461,19 @@ object HighwayTools : Module() { return true } - private fun updateTasks() { - updateBlockArray() + private fun updateTasks(originPos: BlockPos) { + blockOffsets.clear() + updateBlockArray(originPos) + updateBlockArray(getNextBlock(originPos)) for ((blockPos, blockType) in blockOffsets) { val isReplaceable = mc.world.getBlockState(blockPos).material.isReplaceable when (val block = mc.world.getBlockState(blockPos).block) { is BlockLiquid -> { - when (block is BlockDynamicLiquid) { - true -> addTask(blockPos, TaskState.LIQUID_FLOW, fillerMat) - false -> addTask(blockPos, TaskState.LIQUID_SOURCE, fillerMat) + var filler = fillerMat + if (isInsideBuild(blockPos)) filler = material + when (mc.world.getBlockState(blockPos).getValue(BlockLiquid.LEVEL) != 0) { + true -> addTask(blockPos, TaskState.LIQUID_FLOW, filler) + false -> addTask(blockPos, TaskState.LIQUID_SOURCE, filler) } } else -> { @@ -533,6 +544,7 @@ object HighwayTools : Module() { sendChatMessage("$chatName No ${blockTask.block.localizedName} was found in inventory") mc.getSoundHandler().playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) disable() + return false } InventoryUtils.swapSlotToItem(blockID) } @@ -546,24 +558,29 @@ object HighwayTools : Module() { for (side in EnumFacing.values()) { val neighbour = blockTask.blockPos.offset(side) val neighbourBlock = mc.world.getBlockState(neighbour).block - var flowing = false if (neighbourBlock is BlockLiquid) { - if (neighbourBlock is BlockDynamicLiquid) flowing = true + var flowing = false + try { + flowing = mc.world.getBlockState(blockTask.blockPos).getValue(BlockLiquid.LEVEL) != 0 + } catch (e: Exception) { + } if (sqrt(mc.player.getDistanceSqToCenter(neighbour)) > maxReach.value) continue foundLiquid = true val found = mutableListOf>() + var filler = fillerMat + if (isInsideBuild(neighbour)) filler = material for (bt in blockQueue) { if (bt.blockPos == neighbour) { when (flowing) { - false -> found.add(Triple(bt, TaskState.LIQUID_SOURCE, fillerMat)) - true -> found.add(Triple(bt, TaskState.LIQUID_FLOW, fillerMat)) + false -> found.add(Triple(bt, TaskState.LIQUID_SOURCE, filler)) + true -> found.add(Triple(bt, TaskState.LIQUID_FLOW, filler)) } } } if (found.isEmpty()) { when (flowing) { - false -> addTask(neighbour, TaskState.LIQUID_SOURCE, fillerMat) - true -> addTask(neighbour, TaskState.LIQUID_FLOW, fillerMat) + false -> addTask(neighbour, TaskState.LIQUID_SOURCE, filler) + true -> addTask(neighbour, TaskState.LIQUID_FLOW, filler) } } else { for (x in found) { @@ -761,13 +778,20 @@ object HighwayTools : Module() { return null } - private fun isInsideBuild(blockPos: BlockPos): Boolean { + private fun isInsideSelection(blockPos: BlockPos): Boolean { for (bt in blockQueue) { if (bt.blockPos == blockPos) return true } return false } + private fun isInsideBuild(blockPos: BlockPos): Boolean { + for (bt in blockQueue) { + if (bt.blockPos == blockPos && bt.block == material) return true + } + return false + } + private fun centerPlayer(): Boolean { return if (autoCenter.value == AutoCenterMode.OFF) { true @@ -839,6 +863,19 @@ object HighwayTools : Module() { sendChatMessage(message) } + fun getBlueprintStats(): Pair { + var materialUsed = 0 + var fillerMatUsed = 0 + for ((bp, b) in blockOffsets) { + when (b) { + material -> materialUsed++ + fillerMat -> fillerMatUsed++ + } + } + // TODO: Make it dynamic for several depth layers + return Pair(materialUsed / 2, fillerMatUsed / 2) + } + fun gatherStatistics(): MutableList { val currentTask: BlockTask? = if (isDone()) { null @@ -846,10 +883,30 @@ object HighwayTools : Module() { blockQueue.peek() } + materialLeft = InventoryUtils.countItemAll(getIdFromBlock(material)) + fillerMatLeft = InventoryUtils.countItemAll(getIdFromBlock(fillerMat)) + val indirectMaterialLeft = 8 * InventoryUtils.countItemAll(130) + + val blueprintStats = getBlueprintStats() + + val pavingLeft = materialLeft / (blueprintStats.first + 1) + val pavingLeftAll = (materialLeft + indirectMaterialLeft) / (blueprintStats.first + 1) + val seconds = (runtimeSec % 60).toInt().toString().padStart(2,'0') val minutes = ((runtimeSec % 3600) / 60).toInt().toString().padStart(2,'0') val hours = (runtimeSec / 3600).toInt().toString().padStart(2,'0') + val distanceDone = getDistance(startingBlockPos.toVec3d(), currentBlockPos.toVec3d()).toInt() + + val secLeft = runtimeSec / distanceDone * pavingLeftAll + val secondsLeft = (secLeft % 60).toInt().toString().padStart(2,'0') + val minutesLeft = ((secLeft % 3600) / 60).toInt().toString().padStart(2,'0') + val hoursLeft = (secLeft / 3600).toInt().toString().padStart(2,'0') + + + + + val statistics = mutableListOf() statistics.addAll(listOf( @@ -860,7 +917,7 @@ object HighwayTools : Module() { " §7Distance per hour: §9%.2f".format((getDistance(startingBlockPos.toVec3d(), currentBlockPos.toVec3d()).toInt() / runtimeSec) * 60 * 60), " §7One food loss per §9${totalBlocksDestroyed / foodLoss}§7 blocks", "§rEnvironment", - " §7Starting coordinates: §9$startingBlockPos", + " §7Starting coordinates: §9(${startingBlockPos.asString()})", " §7Direction: §9${buildDirectionSaved.cardinalName}", " §7Blocks destroyed: §9$totalBlocksDestroyed", " §7Blocks placed: §9$totalBlocksPlaced", @@ -868,18 +925,18 @@ object HighwayTools : Module() { " §7Filler: §9${fillerMat.localizedName}", "§rTask", " §7Status: §9${currentTask?.taskState}", - " §7Target state: §9${currentTask?.block}", - " §7Position: §9${currentTask?.blockPos}", + " §7Target state: §9${currentTask?.block?.localizedName}", + " §7Position: §9(${currentTask?.blockPos?.asString()})", "§rDebug", " §7Mining stuck: §9$stuckMining", " §7Building stuck: §9$stuckBuilding", - " §7Pathing: §9$pathing")) -// "§rEstimation", -// " §9> §rTheoretical material left: §7${12345} ${material.localizedName}", -// " §9> §rTheoretical block breakings left: §7${232344}", -// " §9> §rTheoretical distance left: §7${62944}", -// " §9> §rEstimated time left: §704:13:11", -// " §9> §rEstimated destination: §7BlockPos{x=-125533, y=119, z=125533}")) + " §7Pathing: §9$pathing", + "§rEstimations", + " §7${material.localizedName} (main material): §9$materialLeft + ($indirectMaterialLeft)", + " §7${fillerMat.localizedName} (filler material): §9$fillerMatLeft", + " §7Paving distance left: §9$pavingLeftAll", + " §7Estimated destination: §9(${relativeDirection(currentBlockPos, pavingLeft, 0).asString()})", + " §7ETA: §9$hoursLeft:$minutesLeft:$secondsLeft")) if (printDebug.value) { // for (x in getQueue()) sendChatMessage(x) @@ -889,17 +946,25 @@ object HighwayTools : Module() { return statistics } - fun getNextBlock(): BlockPos { - return when (buildDirectionSaved) { - Cardinal.NEG_Z -> currentBlockPos.north() - Cardinal.POS_X_NEG_Z -> currentBlockPos.north().east() - Cardinal.POS_X -> currentBlockPos.east() - Cardinal.POS_X_POS_Z -> currentBlockPos.south().east() - Cardinal.POS_Z -> currentBlockPos.south() - Cardinal.NEG_X_POS_Z -> currentBlockPos.south().west() - Cardinal.NEG_X -> currentBlockPos.west() - else -> currentBlockPos.north().west() + fun getNextWalkableBlock(): BlockPos { + if (mode.value == Mode.HIGHWAY) { + if (mc.world.getBlockState(getNextBlock().down()).block == material) { + if (mc.world.getBlockState(getNextBlock(getNextBlock()).down()).block == material) { + if (mc.world.getBlockState(getNextBlock(getNextBlock(getNextBlock())).down()).block == material) return getNextBlock(getNextBlock(getNextBlock())) + return getNextBlock(getNextBlock()) + } + return getNextBlock() + } } + return getNextBlock() + } + + private fun getNextBlock(): BlockPos { + return getNextBlock(currentBlockPos) + } + + private fun getNextBlock(blockPos: BlockPos): BlockPos { + return relativeDirection(blockPos, 1, 0) } private fun relativeDirection(curs: BlockPos, steps: Int, turn: Int): BlockPos { @@ -961,13 +1026,12 @@ object HighwayTools : Module() { private fun refreshData() { doneQueue.clear() blockQueue.clear() - updateTasks() + updateTasks(currentBlockPos) shuffleTasks() } - private fun updateBlockArray() { - blockOffsets.clear() - var cursor = currentBlockPos.down() + private fun updateBlockArray(blockPos: BlockPos) { + var cursor = blockPos.down() when (mode.value) { Mode.HIGHWAY -> { @@ -1091,7 +1155,7 @@ object HighwayTools : Module() { MOTION } - data class BlockTask(val blockPos: BlockPos, var taskState: TaskState, var block: Block, var age: Int) + data class BlockTask(val blockPos: BlockPos, var taskState: TaskState, var block: Block) enum class TaskState(val color: ColorHolder) { DONE(ColorHolder(50, 50, 50)), diff --git a/src/main/java/me/zeroeightsix/kami/process/HighwayToolsProcess.kt b/src/main/java/me/zeroeightsix/kami/process/HighwayToolsProcess.kt index a1264f6ac2..efd67a346b 100644 --- a/src/main/java/me/zeroeightsix/kami/process/HighwayToolsProcess.kt +++ b/src/main/java/me/zeroeightsix/kami/process/HighwayToolsProcess.kt @@ -28,7 +28,7 @@ object HighwayToolsProcess : IBaritoneProcess { val processName = if (ht.blockQueue.size > 0 && !ht.pathing) { "Block: " + ht.blockQueue.peek().block.localizedName + " @ Position: (" + ht.blockQueue.peek().blockPos.asString() + ") Priority: " + ht.blockQueue.peek().taskState.ordinal + " State: " + ht.blockQueue.peek().taskState.toString() } else if (ht.pathing) { - "Moving to Position: (${ht.getNextBlock().asString()})" + "Moving to Position: (${ht.getNextWalkableBlock().asString()})" } else { "Manual mode" } @@ -42,7 +42,7 @@ object HighwayToolsProcess : IBaritoneProcess { override fun onTick(p0: Boolean, p1: Boolean): PathingCommand? { val ht = HighwayTools return if (ht.baritoneMode.value) { - PathingCommand(GoalNear(ht.getNextBlock(), 0), PathingCommandType.SET_GOAL_AND_PATH) + PathingCommand(GoalNear(ht.getNextWalkableBlock(), 0), PathingCommandType.SET_GOAL_AND_PATH) } else PathingCommand(null, PathingCommandType.REQUEST_PAUSE) } } \ No newline at end of file From b29c09ee3c9cd5dd65abbdd4c24a50dc81f09002 Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 3 Nov 2020 05:29:26 +0100 Subject: [PATCH 055/390] Dynamic hitbox raytracing and refactor --- .../kami/module/modules/misc/HighwayTools.kt | 191 +++++++++++------- .../kami/process/HighwayToolsProcess.kt | 2 +- 2 files changed, 118 insertions(+), 75 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index c5e8a66d58..96147091e1 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -19,6 +19,7 @@ import me.zeroeightsix.kami.util.math.CoordinateConverter.asString import me.zeroeightsix.kami.util.math.MathUtils.Cardinal import me.zeroeightsix.kami.util.math.MathUtils.getPlayerCardinal import me.zeroeightsix.kami.util.math.RotationUtils +import me.zeroeightsix.kami.util.math.Vec2d import me.zeroeightsix.kami.util.math.VectorUtils import me.zeroeightsix.kami.util.math.VectorUtils.getDistance import me.zeroeightsix.kami.util.math.VectorUtils.toBlockPos @@ -33,6 +34,8 @@ import net.minecraft.init.SoundEvents import net.minecraft.network.play.client.* import net.minecraft.util.EnumFacing import net.minecraft.util.EnumHand +import net.minecraft.util.Rotation +import net.minecraft.util.math.AxisAlignedBB import net.minecraft.util.math.BlockPos import net.minecraft.util.math.RayTraceResult import net.minecraft.util.math.Vec3d @@ -72,9 +75,11 @@ object HighwayTools : Module() { private val tickDelayBreak = register(Settings.integerBuilder("TickDelayBreak").withMinimum(0).withValue(0).withMaximum(16).withVisibility { page.value == Page.BEHAVIOR }) private val interacting = register(Settings.enumBuilder(InteractMode::class.java).withName("InteractMode").withValue(InteractMode.SPOOF).withVisibility { page.value == Page.BEHAVIOR }) private val illegalPlacements = register(Settings.booleanBuilder("IllegalPlacements").withValue(true).withVisibility { page.value == Page.BEHAVIOR }) - // private val abundanceBreaking = register(Settings.booleanBuilder("AbundanceBreaking").withValue(true).withVisibility { page.value == Page.BEHAVIOR }) - // private val sloppyDigging = register(Settings.booleanBuilder("SloppyDigging").withValue(true).withVisibility { page.value == Page.BEHAVIOR && mode.value == Mode.TUNNEL}) - private val gapple = register(Settings.booleanBuilder("GappleLava").withValue(true).withVisibility { page.value == Page.BEHAVIOR }) +// private val depth = register(Settings.integerBuilder("Depth").withMinimum(0).withValue(1).withMaximum(10).withVisibility { page.value == Page.BEHAVIOR }) +// private val overburden = register(Settings.integerBuilder("Overburden").withMinimum(0).withValue(64).withMaximum(1000).withVisibility { page.value == Page.BEHAVIOR }) +// private val abundanceBreaking = register(Settings.booleanBuilder("AbundanceBreaking").withValue(true).withVisibility { page.value == Page.BEHAVIOR }) +// private val sloppyDigging = register(Settings.booleanBuilder("SloppyDigging").withValue(true).withVisibility { page.value == Page.BEHAVIOR && mode.value == Mode.TUNNEL}) +// private val gapple = register(Settings.booleanBuilder("GappleLava").withValue(true).withVisibility { page.value == Page.BEHAVIOR }) private val autoCenter = register(Settings.enumBuilder(AutoCenterMode::class.java).withName("AutoCenter").withValue(AutoCenterMode.MOTION).withVisibility { page.value == Page.BEHAVIOR }) private val stuckDelay = register(Settings.integerBuilder("TickDelayStuck").withMinimum(1).withValue(200).withMaximum(500).withVisibility { page.value == Page.BEHAVIOR }) val maxReach = register(Settings.floatBuilder("MaxReach").withMinimum(2.0F).withValue(5.4F).withVisibility { page.value == Page.BEHAVIOR }) @@ -90,7 +95,13 @@ object HighwayTools : Module() { private val aOutline = register(Settings.integerBuilder("OutlineAlpha").withMinimum(0).withValue(91).withMaximum(255).withVisibility { outline.value && page.value == Page.CONFIG }) // internal settings - val ignoreBlocks = mutableListOf(Blocks.STANDING_SIGN, Blocks.WALL_SIGN, Blocks.STANDING_BANNER, Blocks.WALL_BANNER, Blocks.BEDROCK, Blocks.PORTAL) + val ignoreBlocks = mutableListOf( + Blocks.STANDING_SIGN, + Blocks.WALL_SIGN, + Blocks.STANDING_BANNER, + Blocks.WALL_BANNER, + Blocks.BEDROCK, + Blocks.PORTAL) var material: Block = Blocks.OBSIDIAN var fillerMat: Block = Blocks.NETHERRACK private var playerHotbarSlot = -1 @@ -130,7 +141,13 @@ object HighwayTools : Module() { if (baritoneMode.value) { pathing = BaritoneAPI.getProvider().primaryBaritone.pathingBehavior.isPathing - if (getNextWalkableBlock() == mc.player.positionVector.toBlockPos()) { + var taskDistance = BlockPos(0, -1, 0) + if (blockQueue.size > 0) { + taskDistance = blockQueue.peek().blockPos + } else { + if (doneQueue.size > 0) taskDistance = doneQueue.peek().blockPos + } + if (getDistance(mc.player.positionVector, taskDistance.toVec3d()) < maxReach.value ) { if (!isDone() && !BaritoneUtils.paused && !AutoObsidian.isActive()) { centerPlayer() val currentFood = mc.player.getFoodStats().foodLevel @@ -311,7 +328,7 @@ object HighwayTools : Module() { Blocks.AIR -> { stuckMining = 0 totalBlocksDestroyed++ - waitTicks = tickDelayBreak.value + waitTicks = tickDelayPlace.value if (blockTask.block == material || blockTask.block == fillerMat) { updateTask(blockTask, TaskState.PLACE) } else { @@ -372,7 +389,7 @@ object HighwayTools : Module() { // ignore blocks for (b in ignoreBlocks) { - if (block == b) { + if (block == b && blockTask.block != Blocks.AIR) { updateTask(blockTask, TaskState.DONE) doTask() } @@ -523,8 +540,10 @@ object HighwayTools : Module() { private fun inventoryProcessor(blockTask: BlockTask): Boolean { when (blockTask.taskState) { TaskState.BREAK, TaskState.LIQUID_BREAK -> { - if (InventoryUtils.getSlotsHotbar(278) == null && InventoryUtils.getSlotsNoHotbar(278) != null) { - InventoryUtils.moveToHotbar(278, 130) + val noHotbar = InventoryUtils.getSlotsNoHotbar(278) + if (InventoryUtils.getSlotsHotbar(278) == null && noHotbar != null) { +// InventoryUtils.moveToHotbar(278, 130) + InventoryUtils.moveToSlot(noHotbar[0], 36) } else if (InventoryUtils.getSlots(0, 35, 278) == null) { sendChatMessage("$chatName No Pickaxe was found in inventory") mc.getSoundHandler().playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) @@ -535,11 +554,20 @@ object HighwayTools : Module() { } TaskState.PLACE, TaskState.LIQUID_FLOW, TaskState.LIQUID_SOURCE -> { val blockID = getIdFromBlock(blockTask.block) + val noHotbar = InventoryUtils.getSlotsNoHotbar(blockID) +// fillerMatLeft = InventoryUtils.countItemAll(getIdFromBlock(fillerMat)) +// if (fillerMatLeft > overburden.value) { +// for (x in InventoryUtils.getSlots(0, 35, blockID)!!) InventoryUtils.throwAllInSlot(x) +// } if (InventoryUtils.getSlotsHotbar(blockID) == null && - InventoryUtils.getSlotsNoHotbar(blockID) != null) { - for (x in InventoryUtils.getSlotsNoHotbar(blockID)!!) { - InventoryUtils.quickMoveSlot(x) + noHotbar != null) { + when (blockTask.block) { + fillerMat -> InventoryUtils.moveToSlot(noHotbar[0], 37) + material -> InventoryUtils.moveToSlot(noHotbar[0], 38) } +// for (x in InventoryUtils.getSlotsNoHotbar(blockID)!!) { +// InventoryUtils.quickMoveSlot(x) +// } } else if (InventoryUtils.getSlots(0, 35, blockID) == null) { sendChatMessage("$chatName No ${blockTask.block.localizedName} was found in inventory") mc.getSoundHandler().playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) @@ -595,54 +623,49 @@ object HighwayTools : Module() { private fun mineBlock(blockTask: BlockTask): Boolean { var rayTrace: RayTraceResult? - if (blockTask.taskState != TaskState.BREAKING) { - rayTrace = mc.world.rayTraceBlocks(mc.player.getPositionEyes(1f), Vec3d(blockTask.blockPos).add(0.5, 0.5, 0.5)) - if (rayTrace == null) { - refreshData() - return false - } - if (rayTrace.blockPos != blockTask.blockPos) { - var found = false - for (side in EnumFacing.values()) { - if (mc.world.getBlockState(blockTask.blockPos.offset(side)).block == Blocks.AIR) { - rayTrace = mc.world.rayTraceBlocks(mc.player.getPositionEyes(1f), - Vec3d(blockTask.blockPos).add(0.5, 0.5, 0.5).add(Vec3d(side.directionVec).scale(0.499)))?: continue - if (rayTrace.blockPos == blockTask.blockPos) { - found = true - break - } + val bb = mc.world.getBlockState(blockTask.blockPos).getSelectedBoundingBox(mc.world, blockTask.blockPos) + rayTrace = mc.world.rayTraceBlocks(mc.player.getPositionEyes(1f), bb.center) + if (rayTrace == null) { + shuffleTasks() + doTask() + return false + } + if (rayTrace.blockPos != blockTask.blockPos) { + var found = false + for (side in EnumFacing.values()) { + if (mc.world.getBlockState(blockTask.blockPos.offset(side)).block == Blocks.AIR) { + rayTrace = mc.world.rayTraceBlocks(mc.player.getPositionEyes(1f), + bb.center.add(Vec3d(side.directionVec).scale(getAABBSide(bb, side))))?: continue + if (rayTrace.blockPos == blockTask.blockPos) { + found = true + break } } - if (!found) { - refreshData() - shuffleTasks() - return false - } } - lastViewVec = rayTrace - } else { - rayTrace = lastViewVec + if (!found) { + refreshData() + shuffleTasks() + doTask() + return false + } } + if (rayTrace == null) return false +// if (lastViewVec != null && rayTrace.sideHit != lastViewVec!!.sideHit) { +// lastViewVec = rayTrace +// updateTask(blockTask, TaskState.BREAK) +// return false +// } + lastViewVec = rayTrace - val facing = rayTrace?.sideHit ?: return false - val rotation = RotationUtils.getRotationTo(Vec3d(blockTask.blockPos).add(0.5, 0.5, 0.5).add(Vec3d(facing.directionVec).scale(0.499)), true) + val facing = rayTrace.sideHit ?: return false + val rotation = RotationUtils.getRotationTo(rayTrace.hitVec, true) - if (blockTask.taskState != TaskState.BREAKING) { - when (interacting.value) { - InteractMode.SPOOF -> { - val rotationPacket = CPacketPlayer.PositionRotation(mc.player.posX, mc.player.posY, mc.player.posZ, rotation.x.toFloat(), rotation.y.toFloat(), mc.player.onGround) - mc.connection!!.sendPacket(rotationPacket) - } - InteractMode.VIEWLOCK -> { - mc.player.rotationYaw = rotation.x.toFloat() - mc.player.rotationPitch = rotation.y.toFloat() - } - } - } + lookAtBlock(rotation) when (mc.world.getBlockState(blockTask.blockPos).block) { Blocks.NETHERRACK -> { updateTask(blockTask, TaskState.BROKEN) + waitTicks = tickDelayPlace.value Thread { Thread.sleep(16L) mc.connection!!.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, blockTask.blockPos, facing)) @@ -677,16 +700,7 @@ object HighwayTools : Module() { val hitVec = Vec3d(neighbour).add(0.5, 0.5, 0.5).add(Vec3d(side.opposite.directionVec).scale(0.5)) val rotation = RotationUtils.getRotationTo(hitVec, true) - when (interacting.value) { - InteractMode.SPOOF -> { - val rotationPacket = CPacketPlayer.PositionRotation(mc.player.posX, mc.player.posY, mc.player.posZ, rotation.x.toFloat(), rotation.y.toFloat(), mc.player.onGround) - mc.connection!!.sendPacket(rotationPacket) - } - InteractMode.VIEWLOCK -> { - mc.player.rotationYaw = rotation.x.toFloat() - mc.player.rotationPitch = rotation.y.toFloat() - } - } + lookAtBlock(rotation) Thread{ Thread.sleep(25L) @@ -747,6 +761,19 @@ object HighwayTools : Module() { val hitVecOffset = rayTrace.hitVec val rotation = RotationUtils.getRotationTo(hitVecOffset, true) + lookAtBlock(rotation) + + Thread{ + Thread.sleep(25L) + val placePacket = CPacketPlayerTryUseItemOnBlock(rayTrace.blockPos, rayTrace.sideHit, EnumHand.MAIN_HAND, hitVecOffset.x.toFloat(), hitVecOffset.y.toFloat(), hitVecOffset.z.toFloat()) + mc.connection!!.sendPacket(placePacket) + mc.player.swingArm(EnumHand.MAIN_HAND) + if (NoBreakAnimation.isEnabled) NoBreakAnimation.resetMining() + }.start() + return true + } + + private fun lookAtBlock(rotation: Vec2d) { when (interacting.value) { InteractMode.SPOOF -> { val rotationPacket = CPacketPlayer.PositionRotation(mc.player.posX, mc.player.posY, mc.player.posZ, rotation.x.toFloat(), rotation.y.toFloat(), mc.player.onGround) @@ -757,15 +784,6 @@ object HighwayTools : Module() { mc.player.rotationPitch = rotation.y.toFloat() } } - - Thread{ - Thread.sleep(25L) - val placePacket = CPacketPlayerTryUseItemOnBlock(rayTrace.blockPos, rayTrace.sideHit, EnumHand.MAIN_HAND, hitVecOffset.x.toFloat(), hitVecOffset.y.toFloat(), hitVecOffset.z.toFloat()) - mc.connection!!.sendPacket(placePacket) - mc.player.swingArm(EnumHand.MAIN_HAND) - if (NoBreakAnimation.isEnabled) NoBreakAnimation.resetMining() - }.start() - return true } private fun getPlaceableSide(pos: BlockPos): EnumFacing? { @@ -866,7 +884,7 @@ object HighwayTools : Module() { fun getBlueprintStats(): Pair { var materialUsed = 0 var fillerMatUsed = 0 - for ((bp, b) in blockOffsets) { + for ((_, b) in blockOffsets) { when (b) { material -> materialUsed++ fillerMat -> fillerMatUsed++ @@ -948,9 +966,15 @@ object HighwayTools : Module() { fun getNextWalkableBlock(): BlockPos { if (mode.value == Mode.HIGHWAY) { - if (mc.world.getBlockState(getNextBlock().down()).block == material) { - if (mc.world.getBlockState(getNextBlock(getNextBlock()).down()).block == material) { - if (mc.world.getBlockState(getNextBlock(getNextBlock(getNextBlock())).down()).block == material) return getNextBlock(getNextBlock(getNextBlock())) + if (mc.world.getBlockState(getNextBlock().down()).block == material && + mc.world.getBlockState(getNextBlock()).block == Blocks.AIR && + mc.world.getBlockState(getNextBlock().up()).block == Blocks.AIR) { + if (mc.world.getBlockState(getNextBlock(getNextBlock().down())).block == material && + mc.world.getBlockState(getNextBlock(getNextBlock())).block == Blocks.AIR && + mc.world.getBlockState(getNextBlock(getNextBlock().up())).block == Blocks.AIR) { + if (mc.world.getBlockState(getNextBlock(getNextBlock(getNextBlock().down()))).block == material && + mc.world.getBlockState(getNextBlock(getNextBlock(getNextBlock()))).block == Blocks.AIR && + mc.world.getBlockState(getNextBlock(getNextBlock(getNextBlock().up()))).block == Blocks.AIR) return getNextBlock(getNextBlock(getNextBlock())) return getNextBlock(getNextBlock()) } return getNextBlock() @@ -984,6 +1008,17 @@ object HighwayTools : Module() { return c } + private fun getAABBSide(bb: AxisAlignedBB, side: EnumFacing): Double { + return when (side) { + EnumFacing.UP -> bb.maxY + EnumFacing.NORTH -> bb.minZ + EnumFacing.EAST -> bb.maxX + EnumFacing.SOUTH -> bb.maxZ + EnumFacing.WEST -> bb.minZ + EnumFacing.DOWN -> bb.minY + } + } + private fun addOffset(cursor: BlockPos, height: Int, width: Int, mat: Block, turn: Boolean) { var turnValue = 1 if (turn) turnValue = -1 @@ -1155,7 +1190,15 @@ object HighwayTools : Module() { MOTION } - data class BlockTask(val blockPos: BlockPos, var taskState: TaskState, var block: Block) + data class BlockTask( + val blockPos: BlockPos, + var taskState: TaskState, + var block: Block + ) { + override fun toString(): String { + return "Block: " + block.localizedName + " @ Position: (" + blockPos.asString() + ") Priority: " + taskState.ordinal + " State: " + taskState.toString() + } + } enum class TaskState(val color: ColorHolder) { DONE(ColorHolder(50, 50, 50)), diff --git a/src/main/java/me/zeroeightsix/kami/process/HighwayToolsProcess.kt b/src/main/java/me/zeroeightsix/kami/process/HighwayToolsProcess.kt index efd67a346b..2c9ab2fc05 100644 --- a/src/main/java/me/zeroeightsix/kami/process/HighwayToolsProcess.kt +++ b/src/main/java/me/zeroeightsix/kami/process/HighwayToolsProcess.kt @@ -26,7 +26,7 @@ object HighwayToolsProcess : IBaritoneProcess { override fun displayName0(): String { val ht = HighwayTools val processName = if (ht.blockQueue.size > 0 && !ht.pathing) { - "Block: " + ht.blockQueue.peek().block.localizedName + " @ Position: (" + ht.blockQueue.peek().blockPos.asString() + ") Priority: " + ht.blockQueue.peek().taskState.ordinal + " State: " + ht.blockQueue.peek().taskState.toString() + ht.blockQueue.peek().toString() } else if (ht.pathing) { "Moving to Position: (${ht.getNextWalkableBlock().asString()})" } else { From da751cf78b69c55dbe6e01dc4acb5a293ddf5a96 Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 3 Nov 2020 05:31:49 +0100 Subject: [PATCH 056/390] Update syntax --- .../zeroeightsix/kami/module/modules/misc/AutoObsidian.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt index 7d8662fef9..b86e59cd3a 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt @@ -1,11 +1,11 @@ package me.zeroeightsix.kami.module.modules.misc -import baritone.api.BaritoneAPI import me.zeroeightsix.kami.event.events.SafeTickEvent import me.zeroeightsix.kami.module.Module import me.zeroeightsix.kami.module.modules.player.NoBreakAnimation import me.zeroeightsix.kami.process.AutoObsidianProcess import me.zeroeightsix.kami.setting.Settings +import me.zeroeightsix.kami.util.BaritoneUtils import me.zeroeightsix.kami.util.BlockUtils import me.zeroeightsix.kami.util.BlockUtils.isPlaceableForChest import me.zeroeightsix.kami.util.EntityUtils.getDroppedItem @@ -37,7 +37,7 @@ import kotlin.math.floor @Module.Info( name = "AutoObsidian", category = Module.Category.MISC, - description = "Mines ender chest automatically to fill inventory with obsidian" + description = "Breaks down Ender Chests to restock obsidian" ) object AutoObsidian : Module() { private val searchShulker = register(Settings.b("SearchShulker", false)) @@ -143,7 +143,7 @@ object AutoObsidian : Module() { } override fun onDisable() { - val baritoneProcess = BaritoneAPI.getProvider().primaryBaritone.pathingControlManager.mostRecentInControl() + val baritoneProcess = BaritoneUtils.primary?.pathingControlManager!!.mostRecentInControl() if (baritoneProcess.isPresent && baritoneProcess.get() == AutoObsidianProcess) { baritoneProcess.get().onLostControl() } @@ -159,7 +159,7 @@ object AutoObsidian : Module() { if (!active && state != State.DONE) { active = true - BaritoneAPI.getProvider().primaryBaritone.pathingControlManager.registerProcess(AutoObsidianProcess) + BaritoneUtils.primary?.pathingControlManager!!.registerProcess(AutoObsidianProcess) } /* Tell baritone to get you back to position */ From f420ad72127fd7d384c2497710e4f8424fc301ef Mon Sep 17 00:00:00 2001 From: Christian Date: Wed, 4 Nov 2020 05:44:43 +0100 Subject: [PATCH 057/390] Fixed center scaling and smol bugs --- .../kami/module/modules/misc/HighwayTools.kt | 94 +++++++++---------- 1 file changed, 44 insertions(+), 50 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 96147091e1..1b854771f9 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -34,7 +34,6 @@ import net.minecraft.init.SoundEvents import net.minecraft.network.play.client.* import net.minecraft.util.EnumFacing import net.minecraft.util.EnumHand -import net.minecraft.util.Rotation import net.minecraft.util.math.AxisAlignedBB import net.minecraft.util.math.BlockPos import net.minecraft.util.math.RayTraceResult @@ -121,7 +120,6 @@ object HighwayTools : Module() { private var stuckMining = 0 private var currentBlockPos = BlockPos(0, -1, 0) private var startingBlockPos = BlockPos(0, -1, 0) - private var lastViewVec: RayTraceResult? = null // stats private var totalBlocksPlaced = 0 private var totalBlocksDestroyed = 0 @@ -156,16 +154,12 @@ object HighwayTools : Module() { prevFood = currentFood } if (!doTask()) { - if (!pathing) { - stuckBuilding += 1 - shuffleTasks() - if (debugMessages.value == DebugMessages.ALL) sendChatMessage("$chatName Shuffled tasks (${stuckBuilding}x)") - if (stuckBuilding > blockOffsets.size) { - refreshData() - if (debugMessages.value == DebugMessages.IMPORTANT) sendChatMessage("$chatName You got stuck, retry") - } - } else { + stuckBuilding += 1 + shuffleTasks() + if (debugMessages.value == DebugMessages.ALL) sendChatMessage("$chatName Shuffled tasks (${stuckBuilding}x)") + if (stuckBuilding > blockOffsets.size) { refreshData() + if (debugMessages.value == DebugMessages.IMPORTANT) sendChatMessage("$chatName You got stuck, retry") } } else { stuckBuilding = 0 @@ -328,7 +322,7 @@ object HighwayTools : Module() { Blocks.AIR -> { stuckMining = 0 totalBlocksDestroyed++ - waitTicks = tickDelayPlace.value + waitTicks = tickDelayBreak.value if (blockTask.block == material || blockTask.block == fillerMat) { updateTask(blockTask, TaskState.PLACE) } else { @@ -622,50 +616,51 @@ object HighwayTools : Module() { } private fun mineBlock(blockTask: BlockTask): Boolean { - var rayTrace: RayTraceResult? + if (blockTask.blockPos == mc.player.positionVector.toBlockPos().down()) { + updateTask(blockTask, TaskState.DONE) + return true + } + + val directHits = mutableListOf() val bb = mc.world.getBlockState(blockTask.blockPos).getSelectedBoundingBox(mc.world, blockTask.blockPos) - rayTrace = mc.world.rayTraceBlocks(mc.player.getPositionEyes(1f), bb.center) - if (rayTrace == null) { + val playerEyeVec = mc.player.getPositionEyes(1f) + + for (side in EnumFacing.values()) { + val sideVec = bb.center.add(Vec3d(side.directionVec).scale(getAABBSide(bb, side) - 0.001)) + if (playerEyeVec.distanceTo(sideVec) > maxReach.value) continue + if (mc.world.getBlockState(blockTask.blockPos.offset(side)).block != Blocks.AIR) continue + val rt = mc.world.rayTraceBlocks(playerEyeVec, sideVec, false) ?: continue + if (rt.blockPos == blockTask.blockPos && rt.sideHit == side) directHits.add(rt) + } + + if (directHits.size == 0) { + refreshData() shuffleTasks() doTask() return false } - if (rayTrace.blockPos != blockTask.blockPos) { - var found = false - for (side in EnumFacing.values()) { - if (mc.world.getBlockState(blockTask.blockPos.offset(side)).block == Blocks.AIR) { - rayTrace = mc.world.rayTraceBlocks(mc.player.getPositionEyes(1f), - bb.center.add(Vec3d(side.directionVec).scale(getAABBSide(bb, side))))?: continue - if (rayTrace.blockPos == blockTask.blockPos) { - found = true - break - } - } - } - if (!found) { - refreshData() - shuffleTasks() - doTask() - return false + + var rayTrace: RayTraceResult? = null + var shortestRT = 999.0 + for (rt in directHits) { + val distance = playerEyeVec.distanceTo(rt.hitVec) + if (distance < shortestRT) { + shortestRT = distance + rayTrace = rt } } + if (rayTrace == null) return false -// if (lastViewVec != null && rayTrace.sideHit != lastViewVec!!.sideHit) { -// lastViewVec = rayTrace -// updateTask(blockTask, TaskState.BREAK) -// return false -// } - lastViewVec = rayTrace val facing = rayTrace.sideHit ?: return false val rotation = RotationUtils.getRotationTo(rayTrace.hitVec, true) - lookAtBlock(rotation) + setRotation(rotation) when (mc.world.getBlockState(blockTask.blockPos).block) { Blocks.NETHERRACK -> { updateTask(blockTask, TaskState.BROKEN) - waitTicks = tickDelayPlace.value + waitTicks = tickDelayBreak.value Thread { Thread.sleep(16L) mc.connection!!.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, blockTask.blockPos, facing)) @@ -689,7 +684,6 @@ object HighwayTools : Module() { } } - return true } @@ -700,7 +694,7 @@ object HighwayTools : Module() { val hitVec = Vec3d(neighbour).add(0.5, 0.5, 0.5).add(Vec3d(side.opposite.directionVec).scale(0.5)) val rotation = RotationUtils.getRotationTo(hitVec, true) - lookAtBlock(rotation) + setRotation(rotation) Thread{ Thread.sleep(25L) @@ -761,7 +755,7 @@ object HighwayTools : Module() { val hitVecOffset = rayTrace.hitVec val rotation = RotationUtils.getRotationTo(hitVecOffset, true) - lookAtBlock(rotation) + setRotation(rotation) Thread{ Thread.sleep(25L) @@ -773,7 +767,7 @@ object HighwayTools : Module() { return true } - private fun lookAtBlock(rotation: Vec2d) { + private fun setRotation(rotation: Vec2d) { when (interacting.value) { InteractMode.SPOOF -> { val rotationPacket = CPacketPlayer.PositionRotation(mc.player.posX, mc.player.posY, mc.player.posZ, rotation.x.toFloat(), rotation.y.toFloat(), mc.player.onGround) @@ -1010,12 +1004,12 @@ object HighwayTools : Module() { private fun getAABBSide(bb: AxisAlignedBB, side: EnumFacing): Double { return when (side) { - EnumFacing.UP -> bb.maxY - EnumFacing.NORTH -> bb.minZ - EnumFacing.EAST -> bb.maxX - EnumFacing.SOUTH -> bb.maxZ - EnumFacing.WEST -> bb.minZ - EnumFacing.DOWN -> bb.minY + EnumFacing.UP -> bb.maxY - bb.center.y + EnumFacing.NORTH -> bb.center.z - bb.minZ + EnumFacing.EAST -> bb.maxX - bb.center.x + EnumFacing.SOUTH -> bb.maxZ - bb.center.z + EnumFacing.WEST -> bb.center.x - bb.minX + EnumFacing.DOWN -> bb.center.y - bb.minY } } From a73d5ef8e157a59264ec7b2ec8798cc014b4c513 Mon Sep 17 00:00:00 2001 From: Christian Date: Thu, 5 Nov 2020 09:20:00 +0100 Subject: [PATCH 058/390] Fixed logic fails --- .../kami/module/modules/misc/HighwayTools.kt | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 1b854771f9..c7bf4b6214 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -147,7 +147,7 @@ object HighwayTools : Module() { } if (getDistance(mc.player.positionVector, taskDistance.toVec3d()) < maxReach.value ) { if (!isDone() && !BaritoneUtils.paused && !AutoObsidian.isActive()) { - centerPlayer() + if (!pathing) centerPlayer() val currentFood = mc.player.getFoodStats().foodLevel if (currentFood != prevFood) { if (currentFood < prevFood) foodLoss++ @@ -175,6 +175,8 @@ object HighwayTools : Module() { } } } + } else { + refreshData() } } else { if (currentBlockPos == mc.player.positionVector.toBlockPos()) { @@ -478,6 +480,7 @@ object HighwayTools : Module() { updateBlockArray(getNextBlock(originPos)) for ((blockPos, blockType) in blockOffsets) { val isReplaceable = mc.world.getBlockState(blockPos).material.isReplaceable + if (blockPos == mc.player.positionVector.toBlockPos().down()) continue when (val block = mc.world.getBlockState(blockPos).block) { is BlockLiquid -> { var filler = fillerMat @@ -505,10 +508,12 @@ object HighwayTools : Module() { } fillerMat -> { if (mode.value == Mode.HIGHWAY) { - val blockUp = mc.world.getBlockState(blockPos.up()).block - when { - getPlaceableSide(blockPos.up()) == null && blockUp != material -> addTask(blockPos, TaskState.PLACE, fillerMat) - getPlaceableSide(blockPos.up()) != null -> addTask(blockPos, fillerMat) + if (buildDirectionSaved.isDiagonal) { + val blockUp = mc.world.getBlockState(blockPos.up()).block + when { + getPlaceableSide(blockPos.up()) == null && blockUp != material -> addTask(blockPos, TaskState.PLACE, fillerMat) + getPlaceableSide(blockPos.up()) != null -> addTask(blockPos, fillerMat) + } } } else { when { @@ -622,7 +627,7 @@ object HighwayTools : Module() { } val directHits = mutableListOf() - val bb = mc.world.getBlockState(blockTask.blockPos).getSelectedBoundingBox(mc.world, blockTask.blockPos) + val bb = AxisAlignedBB(blockTask.blockPos) val playerEyeVec = mc.player.getPositionEyes(1f) for (side in EnumFacing.values()) { From 86b605a029f9c79141c8daffd5ce84516aa59dec Mon Sep 17 00:00:00 2001 From: Christian Date: Fri, 6 Nov 2020 07:22:13 +0100 Subject: [PATCH 059/390] Stability improvements - Even more advanced ray tracing. Now supports stairs and half slabs - Fixed chest crash - AutoEat support - Updated block rendering --- .../kami/module/modules/misc/HighwayTools.kt | 54 +++++++++++-------- 1 file changed, 31 insertions(+), 23 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index c7bf4b6214..57c6bfe3c8 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -4,6 +4,7 @@ import baritone.api.BaritoneAPI import me.zeroeightsix.kami.event.events.RenderWorldEvent import me.zeroeightsix.kami.event.events.SafeTickEvent import me.zeroeightsix.kami.module.Module +import me.zeroeightsix.kami.module.modules.player.AutoEat import me.zeroeightsix.kami.module.modules.player.NoBreakAnimation import me.zeroeightsix.kami.process.HighwayToolsProcess import me.zeroeightsix.kami.setting.Settings @@ -14,13 +15,12 @@ import me.zeroeightsix.kami.util.color.ColorHolder import me.zeroeightsix.kami.util.combat.SurroundUtils import me.zeroeightsix.kami.util.event.listener import me.zeroeightsix.kami.util.graphics.ESPRenderer -import me.zeroeightsix.kami.util.graphics.GeometryMasks import me.zeroeightsix.kami.util.math.CoordinateConverter.asString import me.zeroeightsix.kami.util.math.MathUtils.Cardinal import me.zeroeightsix.kami.util.math.MathUtils.getPlayerCardinal import me.zeroeightsix.kami.util.math.RotationUtils import me.zeroeightsix.kami.util.math.Vec2d -import me.zeroeightsix.kami.util.math.VectorUtils +import me.zeroeightsix.kami.util.math.VectorUtils.getBlockPositionsInArea import me.zeroeightsix.kami.util.math.VectorUtils.getDistance import me.zeroeightsix.kami.util.math.VectorUtils.toBlockPos import me.zeroeightsix.kami.util.math.VectorUtils.toVec3d @@ -81,7 +81,7 @@ object HighwayTools : Module() { // private val gapple = register(Settings.booleanBuilder("GappleLava").withValue(true).withVisibility { page.value == Page.BEHAVIOR }) private val autoCenter = register(Settings.enumBuilder(AutoCenterMode::class.java).withName("AutoCenter").withValue(AutoCenterMode.MOTION).withVisibility { page.value == Page.BEHAVIOR }) private val stuckDelay = register(Settings.integerBuilder("TickDelayStuck").withMinimum(1).withValue(200).withMaximum(500).withVisibility { page.value == Page.BEHAVIOR }) - val maxReach = register(Settings.floatBuilder("MaxReach").withMinimum(2.0F).withValue(5.4F).withVisibility { page.value == Page.BEHAVIOR }) + val maxReach = register(Settings.floatBuilder("MaxReach").withMinimum(2.0F).withValue(4.8F).withVisibility { page.value == Page.BEHAVIOR }) // config private val info = register(Settings.booleanBuilder("ShowInfo").withValue(true).withVisibility { page.value == Page.CONFIG }) @@ -146,7 +146,7 @@ object HighwayTools : Module() { if (doneQueue.size > 0) taskDistance = doneQueue.peek().blockPos } if (getDistance(mc.player.positionVector, taskDistance.toVec3d()) < maxReach.value ) { - if (!isDone() && !BaritoneUtils.paused && !AutoObsidian.isActive()) { + if (!isDone() && !BaritoneUtils.paused && !AutoObsidian.isActive() && !AutoEat.eating) { if (!pathing) centerPlayer() val currentFood = mc.player.getFoodStats().foodLevel if (currentFood != prevFood) { @@ -312,14 +312,6 @@ object HighwayTools : Module() { } private fun doBREAKING(blockTask: BlockTask): Boolean { - if (stuckMining > stuckDelay.value) { - stuckMining = 0 - updateTask(blockTask, TaskState.BREAK) - refreshData() - shuffleTasks() - if (debugMessages.value == DebugMessages.IMPORTANT) sendChatMessage("Shuffled because of mining issue.") - } - when (mc.world.getBlockState(blockTask.blockPos).block) { Blocks.AIR -> { stuckMining = 0 @@ -621,24 +613,41 @@ object HighwayTools : Module() { } private fun mineBlock(blockTask: BlockTask): Boolean { + if (stuckMining > stuckDelay.value) { + stuckMining = 0 + updateTask(blockTask, TaskState.BREAK) + return true + } + if (blockTask.blockPos == mc.player.positionVector.toBlockPos().down()) { updateTask(blockTask, TaskState.DONE) return true } val directHits = mutableListOf() - val bb = AxisAlignedBB(blockTask.blockPos) + val bb = mc.world.getBlockState(blockTask.blockPos).getSelectedBoundingBox(mc.world, blockTask.blockPos) val playerEyeVec = mc.player.getPositionEyes(1f) for (side in EnumFacing.values()) { - val sideVec = bb.center.add(Vec3d(side.directionVec).scale(getAABBSide(bb, side) - 0.001)) - if (playerEyeVec.distanceTo(sideVec) > maxReach.value) continue - if (mc.world.getBlockState(blockTask.blockPos.offset(side)).block != Blocks.AIR) continue - val rt = mc.world.rayTraceBlocks(playerEyeVec, sideVec, false) ?: continue - if (rt.blockPos == blockTask.blockPos && rt.sideHit == side) directHits.add(rt) + loop@ for (direction in EnumFacing.values()) { + when (side) { + EnumFacing.UP -> if (direction == EnumFacing.DOWN || direction == EnumFacing.UP) continue@loop + EnumFacing.DOWN -> if (direction == EnumFacing.UP || direction == EnumFacing.DOWN) continue@loop + EnumFacing.NORTH -> if (direction == EnumFacing.SOUTH || direction == EnumFacing.NORTH) continue@loop + EnumFacing.EAST -> if (direction == EnumFacing.WEST || direction == EnumFacing.EAST) continue@loop + EnumFacing.SOUTH -> if (direction == EnumFacing.NORTH || direction == EnumFacing.SOUTH) continue@loop + EnumFacing.WEST -> if (direction == EnumFacing.EAST || direction == EnumFacing.WEST) continue@loop + } + val sideVec = bb.center.add(Vec3d(side.directionVec).scale(getAABBSide(bb, side) * 0.9).add(Vec3d(direction.directionVec)).scale(getAABBSide(bb, direction) - 0.001)) + if (playerEyeVec.distanceTo(sideVec) > maxReach.value) continue + if (mc.world.getBlockState(blockTask.blockPos.offset(side)).block != Blocks.AIR) continue + val rt = mc.world.rayTraceBlocks(playerEyeVec, sideVec, false) ?: continue + if (rt.blockPos == blockTask.blockPos && rt.sideHit == side) directHits.add(rt) + } } if (directHits.size == 0) { + stuckMining++ refreshData() shuffleTasks() doTask() @@ -818,12 +827,11 @@ object HighwayTools : Module() { } private fun updateRenderer(renderer: ESPRenderer): ESPRenderer { - val side = GeometryMasks.Quad.ALL for (blockTask in blockQueue) { - if (blockTask.taskState != TaskState.DONE) renderer.add(blockTask.blockPos, blockTask.taskState.color, side) + if (blockTask.taskState != TaskState.DONE) renderer.add(mc.world.getBlockState(blockTask.blockPos).getSelectedBoundingBox(mc.world, blockTask.blockPos), blockTask.taskState.color) } for (blockTask in doneQueue) { - if (blockTask.block != Blocks.AIR) renderer.add(blockTask.blockPos, blockTask.taskState.color, side) + if (blockTask.block != Blocks.AIR) renderer.add(mc.world.getBlockState(blockTask.blockPos).getSelectedBoundingBox(mc.world, blockTask.blockPos), blockTask.taskState.color) } return renderer } @@ -932,7 +940,7 @@ object HighwayTools : Module() { " §7Placements per second: §9%.2f".format(totalBlocksPlaced / runtimeSec), " §7Breaks per second: §9%.2f".format(totalBlocksDestroyed / runtimeSec), " §7Distance per hour: §9%.2f".format((getDistance(startingBlockPos.toVec3d(), currentBlockPos.toVec3d()).toInt() / runtimeSec) * 60 * 60), - " §7One food loss per §9${totalBlocksDestroyed / foodLoss}§7 blocks", + " §7One food loss per §9${totalBlocksDestroyed / foodLoss}§7 blocks mined", "§rEnvironment", " §7Starting coordinates: §9(${startingBlockPos.asString()})", " §7Direction: §9${buildDirectionSaved.cardinalName}", @@ -1148,7 +1156,7 @@ object HighwayTools : Module() { } } Mode.FLAT -> { - for (bp in VectorUtils.getBlockPositionsInArea(cursor.north(buildWidth.value).west(buildWidth.value), cursor.south(buildWidth.value).east(buildWidth.value))) { + for (bp in getBlockPositionsInArea(cursor.north(buildWidth.value).west(buildWidth.value), cursor.south(buildWidth.value).east(buildWidth.value))) { blockOffsets.add(Pair(bp, material)) } } From 0e59a15f030558174199d21e782b1e1b0e5bae7a Mon Sep 17 00:00:00 2001 From: natan <66911017+natan515@users.noreply.github.com> Date: Mon, 9 Nov 2020 11:21:00 +0200 Subject: [PATCH 060/390] test1 test1 --- .../kami/module/modules/misc/HighwayTools.kt | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 57c6bfe3c8..8c8d67ba1e 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -95,11 +95,25 @@ object HighwayTools : Module() { // internal settings val ignoreBlocks = mutableListOf( - Blocks.STANDING_SIGN, + Blocks.STANDING_SIGN, Blocks.WALL_SIGN, Blocks.STANDING_BANNER, Blocks.WALL_BANNER, Blocks.BEDROCK, + // Added more blocks i hope its good. + Blocks.GOLDEN_RAIL, + Blocks.DETECTOR_RAIL, + Blocks.RAIL, + Blocks.ACTIVATOR_RAIL, + Blocks.ITEM_FRAME, + Blocks.HEAVY_WEIGHTED_PRESSURE_PLATE, + Blocks.LIGHT_WEIGHTED_PRESSURE_PLATE, + Blocks.LEVER, + Blocks.REDSTONE_TORCH, + Blocks.STONE_PRESSURE_PLATE, + Blocks.WOODEN_PRESSURE_PLATE, + Blocks.STONE_BUTTON, + Blocks.END_PORTAL_FRAME, Blocks.PORTAL) var material: Block = Blocks.OBSIDIAN var fillerMat: Block = Blocks.NETHERRACK From 9724da6430debea34b4e584452636d4fa6ee24c1 Mon Sep 17 00:00:00 2001 From: natan <66911017+natan515@users.noreply.github.com> Date: Mon, 9 Nov 2020 19:52:29 +0200 Subject: [PATCH 061/390] Update HighwayTools.kt --- .../kami/module/modules/misc/HighwayTools.kt | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 8c8d67ba1e..1d1ca03a18 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -95,24 +95,12 @@ object HighwayTools : Module() { // internal settings val ignoreBlocks = mutableListOf( - Blocks.STANDING_SIGN, + Blocks.STANDING_SIGN, Blocks.WALL_SIGN, Blocks.STANDING_BANNER, Blocks.WALL_BANNER, Blocks.BEDROCK, - // Added more blocks i hope its good. - Blocks.GOLDEN_RAIL, - Blocks.DETECTOR_RAIL, - Blocks.RAIL, - Blocks.ACTIVATOR_RAIL, - Blocks.ITEM_FRAME, - Blocks.HEAVY_WEIGHTED_PRESSURE_PLATE, - Blocks.LIGHT_WEIGHTED_PRESSURE_PLATE, - Blocks.LEVER, - Blocks.REDSTONE_TORCH, - Blocks.STONE_PRESSURE_PLATE, - Blocks.WOODEN_PRESSURE_PLATE, - Blocks.STONE_BUTTON, + Blocks.END_PORTAL, Blocks.END_PORTAL_FRAME, Blocks.PORTAL) var material: Block = Blocks.OBSIDIAN From eb240afc092b9f4da4e5648a5bde1129fcf02d4a Mon Sep 17 00:00:00 2001 From: Christian Date: Fri, 13 Nov 2020 08:47:11 +0100 Subject: [PATCH 062/390] First iteration of stuck management --- .../kami/module/modules/misc/HighwayTools.kt | 301 ++++++++++-------- .../zeroeightsix/kami/util/math/Direction.kt | 18 +- .../zeroeightsix/kami/util/math/MathUtils.kt | 58 ---- 3 files changed, 175 insertions(+), 202 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 1d1ca03a18..d4f075c385 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -12,12 +12,10 @@ import me.zeroeightsix.kami.util.BaritoneUtils import me.zeroeightsix.kami.util.BlockUtils import me.zeroeightsix.kami.util.InventoryUtils import me.zeroeightsix.kami.util.color.ColorHolder -import me.zeroeightsix.kami.util.combat.SurroundUtils import me.zeroeightsix.kami.util.event.listener import me.zeroeightsix.kami.util.graphics.ESPRenderer import me.zeroeightsix.kami.util.math.CoordinateConverter.asString -import me.zeroeightsix.kami.util.math.MathUtils.Cardinal -import me.zeroeightsix.kami.util.math.MathUtils.getPlayerCardinal +import me.zeroeightsix.kami.util.math.Direction import me.zeroeightsix.kami.util.math.RotationUtils import me.zeroeightsix.kami.util.math.Vec2d import me.zeroeightsix.kami.util.math.VectorUtils.getBlockPositionsInArea @@ -34,13 +32,11 @@ import net.minecraft.init.SoundEvents import net.minecraft.network.play.client.* 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.RayTraceResult -import net.minecraft.util.math.Vec3d +import net.minecraft.util.math.* import net.minecraftforge.fml.common.gameevent.TickEvent import java.util.* import kotlin.math.abs +import kotlin.math.round import kotlin.math.sqrt /** @@ -74,13 +70,6 @@ object HighwayTools : Module() { private val tickDelayBreak = register(Settings.integerBuilder("TickDelayBreak").withMinimum(0).withValue(0).withMaximum(16).withVisibility { page.value == Page.BEHAVIOR }) private val interacting = register(Settings.enumBuilder(InteractMode::class.java).withName("InteractMode").withValue(InteractMode.SPOOF).withVisibility { page.value == Page.BEHAVIOR }) private val illegalPlacements = register(Settings.booleanBuilder("IllegalPlacements").withValue(true).withVisibility { page.value == Page.BEHAVIOR }) -// private val depth = register(Settings.integerBuilder("Depth").withMinimum(0).withValue(1).withMaximum(10).withVisibility { page.value == Page.BEHAVIOR }) -// private val overburden = register(Settings.integerBuilder("Overburden").withMinimum(0).withValue(64).withMaximum(1000).withVisibility { page.value == Page.BEHAVIOR }) -// private val abundanceBreaking = register(Settings.booleanBuilder("AbundanceBreaking").withValue(true).withVisibility { page.value == Page.BEHAVIOR }) -// private val sloppyDigging = register(Settings.booleanBuilder("SloppyDigging").withValue(true).withVisibility { page.value == Page.BEHAVIOR && mode.value == Mode.TUNNEL}) -// private val gapple = register(Settings.booleanBuilder("GappleLava").withValue(true).withVisibility { page.value == Page.BEHAVIOR }) - private val autoCenter = register(Settings.enumBuilder(AutoCenterMode::class.java).withName("AutoCenter").withValue(AutoCenterMode.MOTION).withVisibility { page.value == Page.BEHAVIOR }) - private val stuckDelay = register(Settings.integerBuilder("TickDelayStuck").withMinimum(1).withValue(200).withMaximum(500).withVisibility { page.value == Page.BEHAVIOR }) val maxReach = register(Settings.floatBuilder("MaxReach").withMinimum(2.0F).withValue(4.8F).withVisibility { page.value == Page.BEHAVIOR }) // config @@ -107,7 +96,7 @@ object HighwayTools : Module() { var fillerMat: Block = Blocks.NETHERRACK private var playerHotbarSlot = -1 private var lastHotbarSlot = -1 - private var buildDirectionSaved = Cardinal.ERROR + private var buildDirectionSaved = Direction.NORTH private var baritoneSettingAllowPlace = false private var baritoneSettingRenderGoal = false @@ -118,10 +107,9 @@ object HighwayTools : Module() { private var waitTicks = 0 private var blocksPlaced = 0 var pathing = false - private var stuckBuilding = 0 - private var stuckMining = 0 private var currentBlockPos = BlockPos(0, -1, 0) private var startingBlockPos = BlockPos(0, -1, 0) + private var stuckManager = StuckManagement(StuckLevel.NONE, 0) // stats private var totalBlocksPlaced = 0 private var totalBlocksDestroyed = 0 @@ -149,23 +137,13 @@ object HighwayTools : Module() { } if (getDistance(mc.player.positionVector, taskDistance.toVec3d()) < maxReach.value ) { if (!isDone() && !BaritoneUtils.paused && !AutoObsidian.isActive() && !AutoEat.eating) { - if (!pathing) centerPlayer() + if (!pathing) adjustPlayerPosition(Direction.NORTH) val currentFood = mc.player.getFoodStats().foodLevel if (currentFood != prevFood) { if (currentFood < prevFood) foodLoss++ prevFood = currentFood } - if (!doTask()) { - stuckBuilding += 1 - shuffleTasks() - if (debugMessages.value == DebugMessages.ALL) sendChatMessage("$chatName Shuffled tasks (${stuckBuilding}x)") - if (stuckBuilding > blockOffsets.size) { - refreshData() - if (debugMessages.value == DebugMessages.IMPORTANT) sendChatMessage("$chatName You got stuck, retry") - } - } else { - stuckBuilding = 0 - } + doTask() } else { if (isDone()) { if (checkTasks() && !pathing) { @@ -182,12 +160,10 @@ object HighwayTools : Module() { } } else { if (currentBlockPos == mc.player.positionVector.toBlockPos()) { - if (!doTask()) { - shuffleTasks() - } + doTask() } else { currentBlockPos = mc.player.positionVector.toBlockPos() - if (abs((buildDirectionSaved.ordinal - getPlayerCardinal(mc.player).ordinal) % 8) == 4) buildDirectionSaved = getPlayerCardinal(mc.player) + if (abs((buildDirectionSaved.ordinal - Direction.fromEntity(mc.player).ordinal) % 8) == 4) buildDirectionSaved = Direction.fromEntity(mc.player) refreshData() } } @@ -220,7 +196,7 @@ object HighwayTools : Module() { currentBlockPos = startingBlockPos playerHotbarSlot = mc.player.inventory.currentItem lastHotbarSlot = -1 - buildDirectionSaved = getPlayerCardinal(mc.player) + buildDirectionSaved = Direction.fromEntity(mc.player) startTime = System.currentTimeMillis() runtimeSec = 0.1 totalBlocksPlaced = 0 @@ -284,26 +260,37 @@ object HighwayTools : Module() { doneQueue.add(blockTask) } - private fun doTask(): Boolean { + private fun doTask() { if (!isDone() && !BaritoneUtils.paused && !AutoObsidian.isActive()) { if (waitTicks == 0) { val blockTask = blockQueue.peek() when (blockTask.taskState) { TaskState.DONE -> doDONE(blockTask) - TaskState.BREAKING -> if(!doBREAKING(blockTask)) return false + TaskState.BREAKING -> if(!doBREAKING(blockTask)) { + stuckManager.increase(blockTask) + return + } TaskState.BROKEN -> doBROKEN(blockTask) TaskState.PLACED -> doPLACED(blockTask) - TaskState.LIQUID_BREAK -> if(!doBREAK(blockTask)) return false - TaskState.BREAK -> if(!doBREAK(blockTask)) return false - TaskState.PLACE, TaskState.LIQUID_SOURCE, TaskState.LIQUID_FLOW -> if(!doPLACE(blockTask)) return false + TaskState.EMERGENCY_BREAK -> if(!doBREAK(blockTask)) { + stuckManager.increase(blockTask) + return + } + TaskState.BREAK -> if(!doBREAK(blockTask)) { + stuckManager.increase(blockTask) + return + } + TaskState.PLACE, TaskState.LIQUID_SOURCE, TaskState.LIQUID_FLOW -> if(!doPLACE(blockTask)) { + stuckManager.increase(blockTask) + return + } } + + if (blockTask.taskState != TaskState.BREAKING) stuckManager.reset() } else { waitTicks-- } - return true - } else { - return false } } @@ -316,7 +303,6 @@ object HighwayTools : Module() { private fun doBREAKING(blockTask: BlockTask): Boolean { when (mc.world.getBlockState(blockTask.blockPos).block) { Blocks.AIR -> { - stuckMining = 0 totalBlocksDestroyed++ waitTicks = tickDelayBreak.value if (blockTask.block == material || blockTask.block == fillerMat) { @@ -338,8 +324,7 @@ object HighwayTools : Module() { } } else -> { - if (!mineBlock(blockTask)) return false - stuckMining++ + mineBlock(blockTask) } } return true @@ -378,10 +363,12 @@ object HighwayTools : Module() { val block = mc.world.getBlockState(blockTask.blockPos).block // ignore blocks - for (b in ignoreBlocks) { - if (block == b && blockTask.block != Blocks.AIR) { - updateTask(blockTask, TaskState.DONE) - doTask() + if (blockTask.taskState != TaskState.EMERGENCY_BREAK) { + for (b in ignoreBlocks) { + if (block == b && blockTask.block != Blocks.AIR) { + updateTask(blockTask, TaskState.DONE) + doTask() + } } } @@ -408,14 +395,14 @@ object HighwayTools : Module() { } else -> { // liquid search around the breaking block - if (blockTask.taskState != TaskState.LIQUID_BREAK) { + if (blockTask.taskState != TaskState.EMERGENCY_BREAK) { if (liquidHandler(blockTask)) { - updateTask(blockTask, TaskState.LIQUID_BREAK) + updateTask(blockTask, TaskState.EMERGENCY_BREAK) return true } } if (!inventoryProcessor(blockTask)) return false - if (!mineBlock(blockTask)) shuffleTasks() + mineBlock(blockTask) } } return true @@ -429,8 +416,10 @@ object HighwayTools : Module() { block == fillerMat && block == blockTask.block -> updateTask(blockTask, TaskState.PLACED) else -> { if (!BlockUtils.isPlaceable(blockTask.blockPos)) { - if (debugMessages.value != DebugMessages.OFF) sendChatMessage("Error: " + blockTask.blockPos + " is not a valid position to place a block, removing task.") - blockQueue.remove(blockTask) +// if (debugMessages.value != DebugMessages.OFF) sendChatMessage("Error: " + blockTask.blockPos + " is not a valid position to place a block, removing task.") +// blockQueue.remove(blockTask) + if (debugMessages.value != DebugMessages.OFF) sendChatMessage("Invalid place position: " + blockTask.blockPos) + refreshData() return false } @@ -532,7 +521,7 @@ object HighwayTools : Module() { private fun inventoryProcessor(blockTask: BlockTask): Boolean { when (blockTask.taskState) { - TaskState.BREAK, TaskState.LIQUID_BREAK -> { + TaskState.BREAK, TaskState.EMERGENCY_BREAK -> { val noHotbar = InventoryUtils.getSlotsNoHotbar(278) if (InventoryUtils.getSlotsHotbar(278) == null && noHotbar != null) { // InventoryUtils.moveToHotbar(278, 130) @@ -614,16 +603,10 @@ object HighwayTools : Module() { return foundLiquid } - private fun mineBlock(blockTask: BlockTask): Boolean { - if (stuckMining > stuckDelay.value) { - stuckMining = 0 - updateTask(blockTask, TaskState.BREAK) - return true - } - + private fun mineBlock(blockTask: BlockTask) { if (blockTask.blockPos == mc.player.positionVector.toBlockPos().down()) { updateTask(blockTask, TaskState.DONE) - return true + return } val directHits = mutableListOf() @@ -649,11 +632,9 @@ object HighwayTools : Module() { } if (directHits.size == 0) { - stuckMining++ - refreshData() - shuffleTasks() - doTask() - return false + stuckManager.increase(blockTask) + if (stuckManager.stuckLevel == StuckLevel.NONE) doTask() + return } var rayTrace: RayTraceResult? = null @@ -666,9 +647,9 @@ object HighwayTools : Module() { } } - if (rayTrace == null) return false + if (rayTrace == null) return - val facing = rayTrace.sideHit ?: return false + val facing = rayTrace.sideHit val rotation = RotationUtils.getRotationTo(rayTrace.hitVec, true) setRotation(rotation) @@ -687,11 +668,11 @@ object HighwayTools : Module() { } else -> { val digPacket: CPacketPlayerDigging = when (blockTask.taskState) { - TaskState.BREAK -> CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, blockTask.blockPos, facing) + TaskState.BREAK, TaskState.EMERGENCY_BREAK -> CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, blockTask.blockPos, facing) TaskState.BREAKING -> CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, blockTask.blockPos, facing) else -> CPacketPlayerDigging() } - if (blockTask.taskState == TaskState.BREAK) updateTask(blockTask, TaskState.BREAKING) + if (blockTask.taskState == TaskState.BREAK || blockTask.taskState == TaskState.EMERGENCY_BREAK) updateTask(blockTask, TaskState.BREAKING) Thread { Thread.sleep(25L) mc.connection!!.sendPacket(digPacket) @@ -699,8 +680,6 @@ object HighwayTools : Module() { }.start() } } - - return true } // Only temporary till we found solution to avoid untraceable blocks @@ -724,7 +703,7 @@ object HighwayTools : Module() { private fun placeBlock(blockTask: BlockTask): Boolean { val directHits = mutableListOf() -// val emergencyHits = mutableListOf() + val emergencyHits = mutableListOf() for (side in EnumFacing.values()) { val offPos = blockTask.blockPos.offset(side) if (mc.world.getBlockState(offPos).material.isReplaceable) continue @@ -732,27 +711,30 @@ object HighwayTools : Module() { val rotationVector = Vec3d(offPos).add(0.5, 0.5, 0.5).add(Vec3d(side.opposite.directionVec).scale(0.499)) val rt = mc.world.rayTraceBlocks(mc.player.getPositionEyes(1f), rotationVector, false)?: continue if (rt.typeOfHit != RayTraceResult.Type.BLOCK) continue - if (rt.blockPos == offPos && offPos.offset(rt.sideHit) == blockTask.blockPos) directHits.add(rt) -// if (rt.blockPos == offPos && offPos.offset(rt.sideHit) != blockTask.blockPos) emergencyHits.add(rt) + if (rt.blockPos == offPos && offPos.offset(rt.sideHit) == blockTask.blockPos) { + directHits.add(rt) + } else { + emergencyHits.add(rt) + } } if (directHits.size == 0) { -// if (emergencyHits.size > 0) { -// var rayTrace = emergencyHits[0] -// var shortestRT = 99.0 -// for (rt in emergencyHits) { -// if (mc.player.getPositionEyes(1f).distanceTo(Vec3d(rt.blockPos).add(BlockUtils.getHitVecOffset(rt.sideHit))) < shortestRT) { -// shortestRT = mc.player.getPositionEyes(1f).distanceTo(Vec3d(rt.blockPos).add(BlockUtils.getHitVecOffset(rt.sideHit))) -// rayTrace = rt -// } -// } -// addTask(rayTrace.blockPos, TaskState.LIQUID_BREAK, Blocks.AIR) -// return true -// } + if (emergencyHits.size > 0 && stuckManager.stuckLevel.ordinal > 0) { + var rayTrace = emergencyHits[0] + var shortestRT = 99.0 + for (rt in emergencyHits) { + if (mc.player.getPositionEyes(1f).distanceTo(Vec3d(rt.blockPos).add(BlockUtils.getHitVecOffset(rt.sideHit))) < shortestRT) { + shortestRT = mc.player.getPositionEyes(1f).distanceTo(Vec3d(rt.blockPos).add(BlockUtils.getHitVecOffset(rt.sideHit))) + rayTrace = rt + } + } + addTask(rayTrace.blockPos, TaskState.EMERGENCY_BREAK, Blocks.AIR) + return false + } return if (illegalPlacements.value) { if(debugMessages.value == DebugMessages.ALL) sendChatMessage("Trying to place through wall ${blockTask.blockPos}") placeBlockWall(blockTask) } else { - true + false } } @@ -820,12 +802,14 @@ object HighwayTools : Module() { return false } - private fun centerPlayer(): Boolean { - return if (autoCenter.value == AutoCenterMode.OFF) { - true - } else { - SurroundUtils.centerPlayer(autoCenter.value == AutoCenterMode.TP) - } + private fun adjustPlayerPosition(direction: Direction) { + val vec = Vec3d(roundToCenter(mc.player.posX), mc.player.posY, roundToCenter(mc.player.posZ)).subtract(mc.player.positionVector) + mc.player.motionX = MathHelper.clamp(vec.x / 2.0, -0.2, 0.2) + mc.player.motionZ = MathHelper.clamp(vec.z / 2.0, -0.2, 0.2) + } + + private fun roundToCenter(doubleIn: Double): Double { + return round(doubleIn + 0.5) - 0.5 } private fun updateRenderer(renderer: ESPRenderer): ESPRenderer { @@ -857,37 +841,34 @@ object HighwayTools : Module() { } private fun printEnable() { - var message = "" if (info.value) { + var message = "" message += "$chatName Module started." + - "\n §9> §7Direction: §a${buildDirectionSaved.cardinalName}§r" + "\n §9> §7Direction: §a${buildDirectionSaved.displayName}§r" message += if (buildDirectionSaved.isDiagonal) { "\n §9> §7Coordinates: §a${startingBlockPos.x} ${startingBlockPos.z}§r" } else { - if (buildDirectionSaved == Cardinal.NEG_Z || buildDirectionSaved == Cardinal.POS_Z) { + if (buildDirectionSaved == Direction.NORTH || buildDirectionSaved == Direction.SOUTH) { "\n §9> §7Coordinate: §a${startingBlockPos.x}§r" } else { "\n §9> §7Coordinate: §a${startingBlockPos.z}§r" } } - } else { - message += "$chatName Module started." + sendChatMessage(message) } - sendChatMessage(message) } private fun printDisable() { - var message = "" if (info.value) { + var message = "" message += "$chatName Module stopped." + "\n §9> §7Placed blocks: §a$totalBlocksPlaced§r" + "\n §9> §7Destroyed blocks: §a$totalBlocksDestroyed§r" if (baritoneMode.value) message += "\n §9> §7Distance: §a${getDistance(startingBlockPos.toVec3d(), currentBlockPos.toVec3d()).toInt()}§r" - } else { - message += "$chatName Module stopped." + sendChatMessage(message) } - sendChatMessage(message) + } fun getBlueprintStats(): Pair { @@ -945,7 +926,7 @@ object HighwayTools : Module() { " §7One food loss per §9${totalBlocksDestroyed / foodLoss}§7 blocks mined", "§rEnvironment", " §7Starting coordinates: §9(${startingBlockPos.asString()})", - " §7Direction: §9${buildDirectionSaved.cardinalName}", + " §7Direction: §9${buildDirectionSaved.displayName}", " §7Blocks destroyed: §9$totalBlocksDestroyed", " §7Blocks placed: §9$totalBlocksPlaced", " §7Material: §9${material.localizedName}", @@ -955,8 +936,7 @@ object HighwayTools : Module() { " §7Target state: §9${currentTask?.block?.localizedName}", " §7Position: §9(${currentTask?.blockPos?.asString()})", "§rDebug", - " §7Mining stuck: §9$stuckMining", - " §7Building stuck: §9$stuckBuilding", + " §7Stuck manager: §9${stuckManager}", " §7Pathing: §9$pathing", "§rEstimations", " §7${material.localizedName} (main material): §9$materialLeft + ($indirectMaterialLeft)", @@ -1169,34 +1149,54 @@ object HighwayTools : Module() { } } - private enum class DebugMessages { - OFF, - IMPORTANT, - ALL - } - - private enum class Mode { - HIGHWAY, - FLAT, - TUNNEL - } + data class StuckManagement( + var stuckLevel: StuckLevel, + var stuckValue: Int + ) { + fun increase(blockTask: BlockTask) { + + when (blockTask.taskState) { + TaskState.BREAK -> stuckValue += 30 + TaskState.EMERGENCY_BREAK -> stuckValue += 30 + TaskState.PLACE, TaskState.LIQUID_SOURCE, TaskState.LIQUID_FLOW -> stuckValue += 10 + else -> stuckValue++ + } + when { + stuckValue < 100 -> { + if (blockTask.taskState != TaskState.BREAKING) { + shuffleTasks() + if (debugMessages.value == DebugMessages.ALL) sendChatMessage("$chatName Shuffled tasks $stuckValue") + } + } + stuckValue in 100..200 -> { + stuckLevel = StuckLevel.MINOR + shuffleTasks() + // Jump etc? + } + stuckValue in 200..500 -> { + stuckLevel = StuckLevel.MODERATE + refreshData() + if (debugMessages.value != DebugMessages.OFF) sendChatMessage("$chatName Refreshing data") + } + stuckValue > 500 -> { + stuckLevel = StuckLevel.MAYOR +// reset() +// disable() +// enable() - private enum class Page { - BUILD, - BEHAVIOR, - CONFIG - } + // Scaffold + } + } + } - private enum class InteractMode { - OFF, - SPOOF, - VIEWLOCK - } + fun reset() { + stuckLevel = StuckLevel.NONE + stuckValue = 0 + } - enum class AutoCenterMode { - OFF, - TP, - MOTION + override fun toString(): String { + return "Level: $stuckLevel Value: $stuckValue" + } } data class BlockTask( @@ -1212,7 +1212,7 @@ object HighwayTools : Module() { enum class TaskState(val color: ColorHolder) { DONE(ColorHolder(50, 50, 50)), BREAKING(ColorHolder(240, 222, 60)), - LIQUID_BREAK(ColorHolder(220, 41, 140)), + EMERGENCY_BREAK(ColorHolder(220, 41, 140)), LIQUID_SOURCE(ColorHolder(120, 41, 240)), LIQUID_FLOW(ColorHolder(120, 41, 240)), BREAK(ColorHolder(222, 0, 0)), @@ -1220,5 +1220,36 @@ object HighwayTools : Module() { PLACE(ColorHolder(35, 188, 254)), PLACED(ColorHolder(53, 222, 66)) } + + private enum class DebugMessages { + OFF, + IMPORTANT, + ALL + } + + private enum class Mode { + HIGHWAY, + FLAT, + TUNNEL + } + + private enum class Page { + BUILD, + BEHAVIOR, + CONFIG + } + + private enum class InteractMode { + OFF, + SPOOF, + VIEWLOCK + } + + enum class StuckLevel { + NONE, + MINOR, + MODERATE, + MAYOR + } } diff --git a/src/main/java/me/zeroeightsix/kami/util/math/Direction.kt b/src/main/java/me/zeroeightsix/kami/util/math/Direction.kt index e61e17121b..3dfeb55128 100644 --- a/src/main/java/me/zeroeightsix/kami/util/math/Direction.kt +++ b/src/main/java/me/zeroeightsix/kami/util/math/Direction.kt @@ -9,15 +9,15 @@ import kotlin.math.roundToInt * [EnumFacing] but with 45° directions */ @Suppress("UNUSED") -enum class Direction(val displayName: String, val displayNameXY: String, val directionVec: Vec3i) { - NORTH("North", "-Z", Vec3i(0, 0, -1)), - NORTH_EAST("North East", "+X -Z", Vec3i(1, 0, -1)), - EAST("East", "+X", Vec3i(1, 0, 0)), - SOUTH_EAST("South East", "+X +Z", Vec3i(1, 0, 1)), - SOUTH("South", "+Z", Vec3i(0, 0, 1)), - SOUTH_WEST("South West", "-X +Z", Vec3i(-1, 0, 1)), - WEST("West", "-X", Vec3i(-1, 0, 0)), - NORTH_WEST("North West", "-X -Z", Vec3i(-1, 0, -1)); +enum class Direction(val displayName: String, val displayNameXY: String, val directionVec: Vec3i, val isDiagonal: Boolean) { + NORTH("North", "-Z", Vec3i(0, 0, -1), false), + NORTH_EAST("North East", "+X -Z", Vec3i(1, 0, -1), true), + EAST("East", "+X", Vec3i(1, 0, 0), false), + SOUTH_EAST("South East", "+X +Z", Vec3i(1, 0, 1), true), + SOUTH("South", "+Z", Vec3i(0, 0, 1), false), + SOUTH_WEST("South West", "-X +Z", Vec3i(-1, 0, 1), true), + WEST("West", "-X", Vec3i(-1, 0, 0), false), + NORTH_WEST("North West", "-X -Z", Vec3i(-1, 0, -1), true); companion object { diff --git a/src/main/java/me/zeroeightsix/kami/util/math/MathUtils.kt b/src/main/java/me/zeroeightsix/kami/util/math/MathUtils.kt index 4ffd324957..2a231d21b2 100644 --- a/src/main/java/me/zeroeightsix/kami/util/math/MathUtils.kt +++ b/src/main/java/me/zeroeightsix/kami/util/math/MathUtils.kt @@ -8,7 +8,6 @@ import kotlin.math.round /** * Created by Dewy on the 17th of April, 2020 * Updated by Xiaro on 18/08/20 - * Cleaned up by Avanatiker on 14/09/20 */ object MathUtils { @@ -48,43 +47,6 @@ object MathUtils { return max + min - num } - @JvmStatic - fun isBetween(min: Int, max: Int, value: Int): Boolean { - return value in min..max - } - - @JvmStatic - fun isBetween(min: Double, max: Double, value: Double): Boolean { - return value in min..max - } - - @JvmStatic - fun getPlayerCardinal(player: EntityPlayer): Cardinal { - val angle = normalizeAngle(player.rotationYaw.toDouble()) - return when { - angle >= 157.6 || angle <= -157.5 -> Cardinal.NEG_Z //NORTH - isBetween(-157.6, -112.5, angle) -> Cardinal.POS_X_NEG_Z //NORTH-EAST - isBetween(-112.5, -67.5, angle) -> Cardinal.POS_X //EAST - isBetween(-67.6, -22.6, angle) -> Cardinal.POS_X_POS_Z //SOUTH-EAST - isBetween(-22.5, 22.5, angle) -> Cardinal.POS_Z //SOUTH - isBetween(22.6, 67.5, angle) -> Cardinal.NEG_X_POS_Z //SOUTH-WEST - isBetween(67.6, 112.5, angle) -> Cardinal.NEG_X //WEST - isBetween(112.6, 157.5, angle) -> Cardinal.NEG_X_NEG_Z //NORTH-WEST - else -> Cardinal.ERROR - } - } - - @JvmStatic - fun getPlayerMainCardinal(player: EntityPlayer): CardinalMain { - return when (Character.toUpperCase(player.horizontalFacing.toString()[0])) { - 'N' -> CardinalMain.NEG_Z - 'E' -> CardinalMain.POS_X - 'S' -> CardinalMain.POS_Z - 'W' -> CardinalMain.NEG_X - else -> CardinalMain.NULL - } - } - @JvmStatic fun convertRange(valueIn: Int, minIn: Int, maxIn: Int, minOut: Int, maxOut: Int): Int { return convertRange(valueIn.toDouble(), minIn.toDouble(), maxIn.toDouble(), minOut.toDouble(), maxOut.toDouble()).toInt() @@ -104,24 +66,4 @@ object MathUtils { val actualMax = max(minOut, maxOut) return min(max(convertedIn, actualMin), actualMax) } - - enum class Cardinal(@JvmField var cardinalName: String) { - POS_Z("+Z"), - NEG_X_POS_Z("-X / +Z"), - NEG_X("-X"), - NEG_X_NEG_Z("-X / -Z"), - NEG_Z("-Z"), - POS_X_NEG_Z("+X / -Z"), - POS_X("+X"), - POS_X_POS_Z("+X / +Z"), - ERROR("ERROR_CALC_DIRECT"); - } - - enum class CardinalMain(@JvmField var cardinalName: String) { - POS_Z("+Z"), - NEG_X("-X"), - NEG_Z("-Z"), - POS_X("+X"), - NULL("N/A"); - } } \ No newline at end of file From 3564be2f0717415df4564c76a0bbc67db6105adc Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Sat, 21 Nov 2020 21:01:00 -0500 Subject: [PATCH 063/390] Fixed mutability and visibility for settings --- .../kami/module/modules/misc/HighwayTools.kt | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index d4f075c385..4c0fbd9ab9 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -29,7 +29,9 @@ import net.minecraft.block.BlockLiquid import net.minecraft.client.audio.PositionedSoundRecord import net.minecraft.init.Blocks import net.minecraft.init.SoundEvents -import net.minecraft.network.play.client.* +import net.minecraft.network.play.client.CPacketPlayer +import net.minecraft.network.play.client.CPacketPlayerDigging +import net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock import net.minecraft.util.EnumFacing import net.minecraft.util.EnumHand import net.minecraft.util.math.* @@ -56,11 +58,11 @@ object HighwayTools : Module() { private val page = register(Settings.e("Page", Page.BUILD)) // build settings - val clearSpace = register(Settings.booleanBuilder("ClearSpace").withValue(true).withVisibility { page.value == Page.BUILD && mode.value == Mode.HIGHWAY }) - var clearHeight = register(Settings.integerBuilder("Height").withMinimum(1).withValue(4).withMaximum(6).withVisibility { page.value == Page.BUILD && clearSpace.value }) - private var buildWidth = register(Settings.integerBuilder("Width").withMinimum(1).withValue(5).withMaximum(9).withVisibility { page.value == Page.BUILD }) + private val clearSpace = register(Settings.booleanBuilder("ClearSpace").withValue(true).withVisibility { page.value == Page.BUILD && mode.value == Mode.HIGHWAY }) + private val clearHeight = register(Settings.integerBuilder("Height").withMinimum(1).withValue(4).withMaximum(6).withVisibility { page.value == Page.BUILD && clearSpace.value }) + private val buildWidth = register(Settings.integerBuilder("Width").withMinimum(1).withValue(5).withMaximum(9).withVisibility { page.value == Page.BUILD }) private val railing = register(Settings.booleanBuilder("Railing").withValue(true).withVisibility { page.value == Page.BUILD && mode.value == Mode.HIGHWAY }) - private var railingHeight = register(Settings.integerBuilder("RailingHeight").withMinimum(0).withValue(1).withMaximum(clearHeight.value).withVisibility { railing.value && page.value == Page.BUILD && mode.value == Mode.HIGHWAY }) + private val railingHeight = register(Settings.integerBuilder("RailingHeight").withMinimum(0).withValue(1).withMaximum(clearHeight.value).withVisibility { railing.value && page.value == Page.BUILD && mode.value == Mode.HIGHWAY }) private val cornerBlock = register(Settings.booleanBuilder("CornerBlock").withValue(false).withVisibility { page.value == Page.BUILD && mode.value == Mode.HIGHWAY }) // behavior settings From 9de0f24b48727841f59c41d09567dcb4933e9b57 Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Sat, 21 Nov 2020 21:04:00 -0500 Subject: [PATCH 064/390] Removed unbounded settings, specific step for all settings --- .../kami/module/modules/misc/HighwayTools.kt | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 4c0fbd9ab9..078cfa6298 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -59,30 +59,30 @@ object HighwayTools : Module() { // build settings private val clearSpace = register(Settings.booleanBuilder("ClearSpace").withValue(true).withVisibility { page.value == Page.BUILD && mode.value == Mode.HIGHWAY }) - private val clearHeight = register(Settings.integerBuilder("Height").withMinimum(1).withValue(4).withMaximum(6).withVisibility { page.value == Page.BUILD && clearSpace.value }) - private val buildWidth = register(Settings.integerBuilder("Width").withMinimum(1).withValue(5).withMaximum(9).withVisibility { page.value == Page.BUILD }) + private val clearHeight = register(Settings.integerBuilder("Height").withValue(4).withRange(1, 6).withStep(1).withVisibility { page.value == Page.BUILD && clearSpace.value }) + private val buildWidth = register(Settings.integerBuilder("Width").withValue(5).withRange(1, 9).withStep(1).withVisibility { page.value == Page.BUILD }) private val railing = register(Settings.booleanBuilder("Railing").withValue(true).withVisibility { page.value == Page.BUILD && mode.value == Mode.HIGHWAY }) - private val railingHeight = register(Settings.integerBuilder("RailingHeight").withMinimum(0).withValue(1).withMaximum(clearHeight.value).withVisibility { railing.value && page.value == Page.BUILD && mode.value == Mode.HIGHWAY }) + private val railingHeight = register(Settings.integerBuilder("RailingHeight").withValue(1).withRange(0, 4).withStep(1).withMaximum(clearHeight.value).withVisibility { railing.value && page.value == Page.BUILD && mode.value == Mode.HIGHWAY }) private val cornerBlock = register(Settings.booleanBuilder("CornerBlock").withValue(false).withVisibility { page.value == Page.BUILD && mode.value == Mode.HIGHWAY }) // behavior settings val baritoneMode = register(Settings.booleanBuilder("AutoMode").withValue(true).withVisibility { page.value == Page.BEHAVIOR }) - private val blocksPerTick = register(Settings.integerBuilder("BlocksPerTick").withMinimum(1).withValue(1).withMaximum(10).withVisibility { page.value == Page.BEHAVIOR }) - private val tickDelayPlace = register(Settings.integerBuilder("TickDelayPlace").withMinimum(0).withValue(3).withMaximum(16).withVisibility { page.value == Page.BEHAVIOR }) - private val tickDelayBreak = register(Settings.integerBuilder("TickDelayBreak").withMinimum(0).withValue(0).withMaximum(16).withVisibility { page.value == Page.BEHAVIOR }) - private val interacting = register(Settings.enumBuilder(InteractMode::class.java).withName("InteractMode").withValue(InteractMode.SPOOF).withVisibility { page.value == Page.BEHAVIOR }) + private val blocksPerTick = register(Settings.integerBuilder("BlocksPerTick").withValue(1).withRange(1, 10).withStep(1).withVisibility { page.value == Page.BEHAVIOR }) + private val tickDelayPlace = register(Settings.integerBuilder("TickDelayPlace").withValue(3).withRange(0, 16).withStep(1).withVisibility { page.value == Page.BEHAVIOR }) + private val tickDelayBreak = register(Settings.integerBuilder("TickDelayBreak").withValue(0).withRange(0, 16).withStep(1).withVisibility { page.value == Page.BEHAVIOR }) + private val interacting = register(Settings.enumBuilder(InteractMode::class.java, "InteractMode").withValue(InteractMode.SPOOF).withVisibility { page.value == Page.BEHAVIOR }) private val illegalPlacements = register(Settings.booleanBuilder("IllegalPlacements").withValue(true).withVisibility { page.value == Page.BEHAVIOR }) - val maxReach = register(Settings.floatBuilder("MaxReach").withMinimum(2.0F).withValue(4.8F).withVisibility { page.value == Page.BEHAVIOR }) + val maxReach = register(Settings.floatBuilder("MaxReach").withValue(4.0F).withRange(1.0f, 5.0f).withStep(0.1f).withVisibility { page.value == Page.BEHAVIOR }) // config private val info = register(Settings.booleanBuilder("ShowInfo").withValue(true).withVisibility { page.value == Page.CONFIG }) private val printDebug = register(Settings.booleanBuilder("ShowQueue").withValue(false).withVisibility { page.value == Page.CONFIG }) - private val debugMessages = register(Settings.enumBuilder(DebugMessages::class.java).withName("Debug").withValue(DebugMessages.IMPORTANT).withVisibility { page.value == Page.CONFIG }) + private val debugMessages = register(Settings.enumBuilder(DebugMessages::class.java, "Debug").withValue(DebugMessages.IMPORTANT).withVisibility { page.value == Page.CONFIG }) private val goalRender = register(Settings.booleanBuilder("GoalRender").withValue(false).withVisibility { page.value == Page.CONFIG }) private val filled = register(Settings.booleanBuilder("Filled").withValue(true).withVisibility { page.value == Page.CONFIG }) private val outline = register(Settings.booleanBuilder("Outline").withValue(true).withVisibility { page.value == Page.CONFIG }) - private val aFilled = register(Settings.integerBuilder("FilledAlpha").withMinimum(0).withValue(26).withMaximum(255).withVisibility { filled.value && page.value == Page.CONFIG }) - private val aOutline = register(Settings.integerBuilder("OutlineAlpha").withMinimum(0).withValue(91).withMaximum(255).withVisibility { outline.value && page.value == Page.CONFIG }) + private val aFilled = register(Settings.integerBuilder("FilledAlpha").withValue(26).withRange(0, 255).withStep(1).withVisibility { filled.value && page.value == Page.CONFIG }) + private val aOutline = register(Settings.integerBuilder("OutlineAlpha").withValue(91).withRange(0, 255).withStep(1).withVisibility { outline.value && page.value == Page.CONFIG }) // internal settings val ignoreBlocks = mutableListOf( From f2d4df2c687740d73d1c82992aa70e60f61256ac Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Sat, 21 Nov 2020 21:05:46 -0500 Subject: [PATCH 065/390] Fixed method namings --- .../kami/module/modules/misc/HighwayTools.kt | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 078cfa6298..b428e602eb 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -268,18 +268,18 @@ object HighwayTools : Module() { val blockTask = blockQueue.peek() when (blockTask.taskState) { - TaskState.DONE -> doDONE(blockTask) - TaskState.BREAKING -> if(!doBREAKING(blockTask)) { + TaskState.DONE -> doDone(blockTask) + TaskState.BREAKING -> if(!doBreaking(blockTask)) { stuckManager.increase(blockTask) return } - TaskState.BROKEN -> doBROKEN(blockTask) - TaskState.PLACED -> doPLACED(blockTask) - TaskState.EMERGENCY_BREAK -> if(!doBREAK(blockTask)) { + TaskState.BROKEN -> dpBroken(blockTask) + TaskState.PLACED -> doPlaced(blockTask) + TaskState.EMERGENCY_BREAK -> if(!doBreak(blockTask)) { stuckManager.increase(blockTask) return } - TaskState.BREAK -> if(!doBREAK(blockTask)) { + TaskState.BREAK -> if(!doBreak(blockTask)) { stuckManager.increase(blockTask) return } @@ -296,13 +296,13 @@ object HighwayTools : Module() { } } - private fun doDONE(blockTask: BlockTask) { + private fun doDone(blockTask: BlockTask) { blockQueue.poll() doneQueue.add(blockTask) doTask() } - private fun doBREAKING(blockTask: BlockTask): Boolean { + private fun doBreaking(blockTask: BlockTask): Boolean { when (mc.world.getBlockState(blockTask.blockPos).block) { Blocks.AIR -> { totalBlocksDestroyed++ @@ -332,7 +332,7 @@ object HighwayTools : Module() { return true } - private fun doBROKEN(blockTask: BlockTask) { + private fun dpBroken(blockTask: BlockTask) { when (mc.world.getBlockState(blockTask.blockPos).block) { Blocks.AIR -> { totalBlocksDestroyed++ @@ -349,7 +349,7 @@ object HighwayTools : Module() { doTask() } - private fun doPLACED(blockTask: BlockTask) { + private fun doPlaced(blockTask: BlockTask) { val block = mc.world.getBlockState(blockTask.blockPos).block when { @@ -361,7 +361,7 @@ object HighwayTools : Module() { doTask() } - private fun doBREAK(blockTask: BlockTask): Boolean { + private fun doBreak(blockTask: BlockTask): Boolean { val block = mc.world.getBlockState(blockTask.blockPos).block // ignore blocks From dff1412fb812ba93e6c895dd1202d593c217a4ab Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Sat, 21 Nov 2020 21:11:18 -0500 Subject: [PATCH 066/390] Fixed variable mutability, collection performance and null safety --- .../kami/module/modules/misc/HighwayTools.kt | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index b428e602eb..ace83f8b05 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -37,6 +37,7 @@ import net.minecraft.util.EnumHand import net.minecraft.util.math.* import net.minecraftforge.fml.common.gameevent.TickEvent import java.util.* +import kotlin.collections.ArrayList import kotlin.math.abs import kotlin.math.round import kotlin.math.sqrt @@ -93,7 +94,8 @@ object HighwayTools : Module() { Blocks.BEDROCK, Blocks.END_PORTAL, Blocks.END_PORTAL_FRAME, - Blocks.PORTAL) + Blocks.PORTAL + ) var material: Block = Blocks.OBSIDIAN var fillerMat: Block = Blocks.NETHERRACK private var playerHotbarSlot = -1 @@ -103,28 +105,29 @@ object HighwayTools : Module() { private var baritoneSettingRenderGoal = false // runtime vars - val blockQueue: PriorityQueue = PriorityQueue(compareBy { it.taskState.ordinal }) - private val doneQueue: Queue = LinkedList() - private var blockOffsets = mutableListOf>() + val blockQueue = PriorityQueue(compareBy { it.taskState.ordinal }) + private val doneQueue = ArrayList() + private val blockOffsets = ArrayList>() private var waitTicks = 0 private var blocksPlaced = 0 var pathing = false private var currentBlockPos = BlockPos(0, -1, 0) private var startingBlockPos = BlockPos(0, -1, 0) - private var stuckManager = StuckManagement(StuckLevel.NONE, 0) + private val stuckManager = StuckManagement(StuckLevel.NONE, 0) + // stats private var totalBlocksPlaced = 0 private var totalBlocksDestroyed = 0 - private var startTime: Long = 0L - private var runtimeSec: Double = 0.0 - private var prevFood: Int = 0 - private var foodLoss: Int = 1 + private var startTime = 0L + private var runtimeSec = 0.0 + private var prevFood = 0 + private var foodLoss = 1 private var materialLeft = 0 private var fillerMatLeft = 0 init { - listener { - if (it.phase != TickEvent.Phase.END) { + listener { event -> + if (event.phase != TickEvent.Phase.END) { if (mc.playerController == null) return@listener BaritoneAPI.getProvider().primaryBaritone.pathingControlManager.registerProcess(HighwayToolsProcess) runtimeSec = ((System.currentTimeMillis() - startTime) / 1000).toDouble() @@ -132,10 +135,8 @@ object HighwayTools : Module() { if (baritoneMode.value) { pathing = BaritoneAPI.getProvider().primaryBaritone.pathingBehavior.isPathing var taskDistance = BlockPos(0, -1, 0) - if (blockQueue.size > 0) { - taskDistance = blockQueue.peek().blockPos - } else { - if (doneQueue.size > 0) taskDistance = doneQueue.peek().blockPos + blockQueue.firstOrNull() ?: doneQueue.firstOrNull()?.let { + taskDistance = it.blockPos } if (getDistance(mc.player.positionVector, taskDistance.toVec3d()) < maxReach.value ) { if (!isDone() && !BaritoneUtils.paused && !AutoObsidian.isActive() && !AutoEat.eating) { From 996a0f32e74762dd69cc17b0032f51348eec8655 Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Sat, 21 Nov 2020 21:12:34 -0500 Subject: [PATCH 067/390] Optimized ignoreBlocks performance --- .../command/commands/HighwayToolsCommand.kt | 26 +++++++++---------- .../kami/module/modules/misc/HighwayTools.kt | 2 +- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/command/commands/HighwayToolsCommand.kt b/src/main/java/me/zeroeightsix/kami/command/commands/HighwayToolsCommand.kt index f5b4e966d0..d3f20333bd 100644 --- a/src/main/java/me/zeroeightsix/kami/command/commands/HighwayToolsCommand.kt +++ b/src/main/java/me/zeroeightsix/kami/command/commands/HighwayToolsCommand.kt @@ -17,17 +17,15 @@ class HighwayToolsCommand : Command("highwaytools", ChunkBuilder() .build(), "ht") { override fun call(args: Array) { - val subCommand = getSubCommand(args) - val ht = HighwayTools - when (subCommand) { + when (getSubCommand(args)) { SubCommands.SETTINGS -> { - ht.printSettings() + HighwayTools.printSettings() } SubCommands.MATERIAL -> { try { val block = Block.getBlockFromName(args[1].toString())!! - ht.material = block + HighwayTools.material = block MessageSendHelper.sendChatMessage("Set your building material to &7${block.localizedName}&r.") } catch (e: Exception) { MessageSendHelper.sendChatMessage("&7${args[1]}&r is not a valid block.") @@ -37,7 +35,7 @@ class HighwayToolsCommand : Command("highwaytools", ChunkBuilder() SubCommands.FILLER -> { try { val block = Block.getBlockFromName(args[1].toString())!! - ht.fillerMat = block + HighwayTools.fillerMat = block MessageSendHelper.sendChatMessage("Set your filling material to &7${block.localizedName}&r.") } catch (e: Exception) { MessageSendHelper.sendChatMessage("&7${args[1]}&r is not a valid block.") @@ -47,9 +45,9 @@ class HighwayToolsCommand : Command("highwaytools", ChunkBuilder() SubCommands.IGNORE_ADD -> { try { val block = Block.getBlockFromName(args[2].toString())!! - if (block !in ht.ignoreBlocks) { - ht.ignoreBlocks.add(block) - ht.printSettings() + if (block !in HighwayTools.ignoreBlocks) { + HighwayTools.ignoreBlocks.add(block) + HighwayTools.printSettings() MessageSendHelper.sendChatMessage("Added &7${block.localizedName}&r to ignore list.") } else { MessageSendHelper.sendChatMessage("&7${block.localizedName}&r is already ignored.") @@ -62,9 +60,9 @@ class HighwayToolsCommand : Command("highwaytools", ChunkBuilder() SubCommands.IGNORE_DEL -> { try { val block = Block.getBlockFromName(args[2].toString())!! - if (block !in ht.ignoreBlocks) { - ht.ignoreBlocks.remove(block) - ht.printSettings() + if (block !in HighwayTools.ignoreBlocks) { + HighwayTools.ignoreBlocks.remove(block) + HighwayTools.printSettings() MessageSendHelper.sendChatMessage("Removed &7${block.localizedName}&r from ignore list.") } else { MessageSendHelper.sendChatMessage("&7${block.localizedName}&r is not yet ignored.") @@ -76,8 +74,8 @@ class HighwayToolsCommand : Command("highwaytools", ChunkBuilder() SubCommands.MAX_REACH -> { try { - ht.maxReach.value = args[1]!!.toFloatOrNull() - MessageSendHelper.sendChatMessage("Set your max reach to &7${ht.maxReach.value}&r.") + HighwayTools.maxReach.value = args[1]!!.toFloatOrNull() + MessageSendHelper.sendChatMessage("Set your max reach to &7${HighwayTools.maxReach.value}&r.") } catch (e: Exception) { MessageSendHelper.sendChatMessage("&7${args[1]}&r is not a valid number (eg: 5.5).") } diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index ace83f8b05..65ef83eaa3 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -86,7 +86,7 @@ object HighwayTools : Module() { private val aOutline = register(Settings.integerBuilder("OutlineAlpha").withValue(91).withRange(0, 255).withStep(1).withVisibility { outline.value && page.value == Page.CONFIG }) // internal settings - val ignoreBlocks = mutableListOf( + val ignoreBlocks = hashSetOf( Blocks.STANDING_SIGN, Blocks.WALL_SIGN, Blocks.STANDING_BANNER, From 1a8723e678aebc6885a29e15025b91af56a00d83 Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Sat, 21 Nov 2020 21:20:00 -0500 Subject: [PATCH 068/390] Cleaned up HighwayToolsCommand --- .../command/commands/HighwayToolsCommand.kt | 76 +++++++++---------- 1 file changed, 37 insertions(+), 39 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/command/commands/HighwayToolsCommand.kt b/src/main/java/me/zeroeightsix/kami/command/commands/HighwayToolsCommand.kt index d3f20333bd..13986effa5 100644 --- a/src/main/java/me/zeroeightsix/kami/command/commands/HighwayToolsCommand.kt +++ b/src/main/java/me/zeroeightsix/kami/command/commands/HighwayToolsCommand.kt @@ -12,9 +12,9 @@ import net.minecraft.block.Block * @since 01/09/2020 */ class HighwayToolsCommand : Command("highwaytools", ChunkBuilder() - .append("mode", true, EnumParser(arrayOf("material", "filler", "ignore", "reach", "settings"))) - .append("value") - .build(), "ht") { + .append("mode", true, EnumParser(arrayOf("material", "filler", "ignore", "reach", "settings"))) + .append("value") + .build(), "ht") { override fun call(args: Array) { when (getSubCommand(args)) { @@ -23,97 +23,95 @@ class HighwayToolsCommand : Command("highwaytools", ChunkBuilder() } SubCommands.MATERIAL -> { - try { - val block = Block.getBlockFromName(args[1].toString())!! + val block = Block.getBlockFromName(args[1].toString()) + + if (block != null) { HighwayTools.material = block MessageSendHelper.sendChatMessage("Set your building material to &7${block.localizedName}&r.") - } catch (e: Exception) { + } else { MessageSendHelper.sendChatMessage("&7${args[1]}&r is not a valid block.") } } SubCommands.FILLER -> { - try { - val block = Block.getBlockFromName(args[1].toString())!! + val block = Block.getBlockFromName(args[1].toString()) + + if (block != null) { HighwayTools.fillerMat = block MessageSendHelper.sendChatMessage("Set your filling material to &7${block.localizedName}&r.") - } catch (e: Exception) { + } else { MessageSendHelper.sendChatMessage("&7${args[1]}&r is not a valid block.") } } SubCommands.IGNORE_ADD -> { - try { - val block = Block.getBlockFromName(args[2].toString())!! - if (block !in HighwayTools.ignoreBlocks) { - HighwayTools.ignoreBlocks.add(block) + val block = Block.getBlockFromName(args[1].toString()) + + if (block != null) { + val added = HighwayTools.ignoreBlocks.add(block) + if (added) { HighwayTools.printSettings() MessageSendHelper.sendChatMessage("Added &7${block.localizedName}&r to ignore list.") } else { + MessageSendHelper.sendChatMessage("&7${block.localizedName}&r is already ignored.") } - } catch (e: Exception) { + } else { MessageSendHelper.sendChatMessage("&7${args[1]}&r is not a valid block.") } } SubCommands.IGNORE_DEL -> { - try { - val block = Block.getBlockFromName(args[2].toString())!! - if (block !in HighwayTools.ignoreBlocks) { - HighwayTools.ignoreBlocks.remove(block) + val block = Block.getBlockFromName(args[1].toString()) + + if (block != null) { + val removed = HighwayTools.ignoreBlocks.remove(block) + if (removed) { HighwayTools.printSettings() MessageSendHelper.sendChatMessage("Removed &7${block.localizedName}&r from ignore list.") } else { MessageSendHelper.sendChatMessage("&7${block.localizedName}&r is not yet ignored.") } - } catch (e: Exception) { + } else { MessageSendHelper.sendChatMessage("&7${args[1]}&r is not a valid block.") } } - SubCommands.MAX_REACH -> { - try { - HighwayTools.maxReach.value = args[1]!!.toFloatOrNull() - MessageSendHelper.sendChatMessage("Set your max reach to &7${HighwayTools.maxReach.value}&r.") - } catch (e: Exception) { - MessageSendHelper.sendChatMessage("&7${args[1]}&r is not a valid number (eg: 5.5).") - } - } - - SubCommands.NULL -> { + else -> { val commands = args.joinToString(separator = " ") MessageSendHelper.sendChatMessage("Invalid command &7${commandPrefix.value}${label} $commands&f!") } } } - private fun getSubCommand(args: Array): SubCommands { + private fun getSubCommand(args: Array): SubCommands? { return when { args[0].isNullOrBlank() -> SubCommands.SETTINGS - args[1].isNullOrBlank() -> SubCommands.NULL - args[0].equals("settings", ignoreCase = true) -> SubCommands.SETTINGS + args[1].isNullOrBlank() -> null + args[0].equals("material", ignoreCase = true) -> SubCommands.MATERIAL args[0].equals("filler", ignoreCase = true) -> SubCommands.FILLER - args[0].equals("reach", ignoreCase = true) -> SubCommands.MAX_REACH + args[0].equals("ignore", ignoreCase = true) -> { + when { + args[1].equals("add", ignoreCase = true) -> SubCommands.IGNORE_ADD - args[0].equals("ignore", ignoreCase = true) && args[2].isNullOrBlank() -> SubCommands.IGNORE_ADD + args[1].equals("del", ignoreCase = true) -> SubCommands.IGNORE_DEL - args[0].equals("ignore", ignoreCase = true) && args[1].equals("add", ignoreCase = true) -> SubCommands.IGNORE_ADD - - args[0].equals("ignore", ignoreCase = true) && args[1].equals("del", ignoreCase = true) -> SubCommands.IGNORE_DEL + else -> null + } + } - else -> SubCommands.NULL + else -> null } } private enum class SubCommands { - MATERIAL, FILLER, IGNORE_ADD, IGNORE_DEL, MAX_REACH, SETTINGS, NULL + MATERIAL, FILLER, IGNORE_ADD, IGNORE_DEL, SETTINGS } init { From 67b295461da2ebbd8f4457356a01d530a9354f6d Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Sat, 21 Nov 2020 21:23:56 -0500 Subject: [PATCH 069/390] Use Baritone utils for BaritoneAPI calls --- .../kami/module/modules/misc/HighwayTools.kt | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 65ef83eaa3..24b51086da 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -1,6 +1,5 @@ package me.zeroeightsix.kami.module.modules.misc -import baritone.api.BaritoneAPI import me.zeroeightsix.kami.event.events.RenderWorldEvent import me.zeroeightsix.kami.event.events.SafeTickEvent import me.zeroeightsix.kami.module.Module @@ -129,11 +128,11 @@ object HighwayTools : Module() { listener { event -> if (event.phase != TickEvent.Phase.END) { if (mc.playerController == null) return@listener - BaritoneAPI.getProvider().primaryBaritone.pathingControlManager.registerProcess(HighwayToolsProcess) + BaritoneUtils.primary?.pathingControlManager?.registerProcess(HighwayToolsProcess) runtimeSec = ((System.currentTimeMillis() - startTime) / 1000).toDouble() if (baritoneMode.value) { - pathing = BaritoneAPI.getProvider().primaryBaritone.pathingBehavior.isPathing + pathing = BaritoneUtils.isPathing var taskDistance = BlockPos(0, -1, 0) blockQueue.firstOrNull() ?: doneQueue.firstOrNull()?.let { taskDistance = it.blockPos @@ -206,11 +205,12 @@ object HighwayTools : Module() { totalBlocksDestroyed = 0 if (baritoneMode.value) { - baritoneSettingAllowPlace = BaritoneAPI.getSettings().allowPlace.value - BaritoneAPI.getSettings().allowPlace.value = false + baritoneSettingAllowPlace = BaritoneUtils.settings?.allowPlace?.value ?: true + BaritoneUtils.settings?.allowPlace?.value = false + if (!goalRender.value) { - baritoneSettingRenderGoal = BaritoneAPI.getSettings().renderGoal.value - BaritoneAPI.getSettings().renderGoal.value = false + baritoneSettingRenderGoal = BaritoneUtils.settings?.renderGoal?.value ?: true + BaritoneUtils.settings?.renderGoal?.value = false } } @@ -231,10 +231,11 @@ object HighwayTools : Module() { lastHotbarSlot = -1 if (baritoneMode.value) { - BaritoneAPI.getSettings().allowPlace.value = baritoneSettingAllowPlace - if (!goalRender.value) BaritoneAPI.getSettings().renderGoal.value = baritoneSettingRenderGoal - val baritoneProcess = BaritoneAPI.getProvider().primaryBaritone.pathingControlManager.mostRecentInControl() - if (baritoneProcess.isPresent && baritoneProcess.get() == HighwayToolsProcess) baritoneProcess.get().onLostControl() + BaritoneUtils.settings?.allowPlace?.value = baritoneSettingAllowPlace + if (!goalRender.value) BaritoneUtils.settings?.renderGoal?.value = baritoneSettingRenderGoal + val process = BaritoneUtils.primary?.pathingControlManager?.mostRecentInControl() + + if (process != null && process.isPresent && process.get() == HighwayToolsProcess) process.get().onLostControl() } printDisable() } From 494d885a8276d78b135df44fecadaae7a708d7df Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Sat, 21 Nov 2020 21:25:59 -0500 Subject: [PATCH 070/390] Fixed warnings --- .../zeroeightsix/kami/module/modules/misc/HighwayTools.kt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 24b51086da..3e78d3c2da 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -139,7 +139,7 @@ object HighwayTools : Module() { } if (getDistance(mc.player.positionVector, taskDistance.toVec3d()) < maxReach.value ) { if (!isDone() && !BaritoneUtils.paused && !AutoObsidian.isActive() && !AutoEat.eating) { - if (!pathing) adjustPlayerPosition(Direction.NORTH) + if (!pathing) adjustPlayerPosition() val currentFood = mc.player.getFoodStats().foodLevel if (currentFood != prevFood) { if (currentFood < prevFood) foodLoss++ @@ -779,6 +779,9 @@ object HighwayTools : Module() { mc.player.rotationYaw = rotation.x.toFloat() mc.player.rotationPitch = rotation.y.toFloat() } + else -> { + + } } } @@ -806,7 +809,7 @@ object HighwayTools : Module() { return false } - private fun adjustPlayerPosition(direction: Direction) { + private fun adjustPlayerPosition() { val vec = Vec3d(roundToCenter(mc.player.posX), mc.player.posY, roundToCenter(mc.player.posZ)).subtract(mc.player.positionVector) mc.player.motionX = MathHelper.clamp(vec.x / 2.0, -0.2, 0.2) mc.player.motionZ = MathHelper.clamp(vec.z / 2.0, -0.2, 0.2) @@ -1243,6 +1246,7 @@ object HighwayTools : Module() { CONFIG } + @Suppress("UNUSED") private enum class InteractMode { OFF, SPOOF, From 73bf9bc67187cea468ae44ae9ba6ddbc4e0a5aa1 Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Sat, 21 Nov 2020 21:26:27 -0500 Subject: [PATCH 071/390] Make maxReach private --- .../me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 3e78d3c2da..6852536e81 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -72,7 +72,7 @@ object HighwayTools : Module() { private val tickDelayBreak = register(Settings.integerBuilder("TickDelayBreak").withValue(0).withRange(0, 16).withStep(1).withVisibility { page.value == Page.BEHAVIOR }) private val interacting = register(Settings.enumBuilder(InteractMode::class.java, "InteractMode").withValue(InteractMode.SPOOF).withVisibility { page.value == Page.BEHAVIOR }) private val illegalPlacements = register(Settings.booleanBuilder("IllegalPlacements").withValue(true).withVisibility { page.value == Page.BEHAVIOR }) - val maxReach = register(Settings.floatBuilder("MaxReach").withValue(4.0F).withRange(1.0f, 5.0f).withStep(0.1f).withVisibility { page.value == Page.BEHAVIOR }) + private val maxReach = register(Settings.floatBuilder("MaxReach").withValue(4.0F).withRange(1.0f, 5.0f).withStep(0.1f).withVisibility { page.value == Page.BEHAVIOR }) // config private val info = register(Settings.booleanBuilder("ShowInfo").withValue(true).withVisibility { page.value == Page.CONFIG }) From 78d079891465c90ca34e45fcff66db42f4769005 Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Sat, 21 Nov 2020 21:33:51 -0500 Subject: [PATCH 072/390] Optimized statistics list --- .../kami/module/modules/misc/HighwayTools.kt | 61 +++++++++---------- 1 file changed, 28 insertions(+), 33 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 6852536e81..2b7e086bf7 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -918,39 +918,34 @@ object HighwayTools : Module() { val minutesLeft = ((secLeft % 3600) / 60).toInt().toString().padStart(2,'0') val hoursLeft = (secLeft / 3600).toInt().toString().padStart(2,'0') - - - - - val statistics = mutableListOf() - - statistics.addAll(listOf( - "§rPerformance", - " §7Runtime: §9$hours:$minutes:$seconds", - " §7Placements per second: §9%.2f".format(totalBlocksPlaced / runtimeSec), - " §7Breaks per second: §9%.2f".format(totalBlocksDestroyed / runtimeSec), - " §7Distance per hour: §9%.2f".format((getDistance(startingBlockPos.toVec3d(), currentBlockPos.toVec3d()).toInt() / runtimeSec) * 60 * 60), - " §7One food loss per §9${totalBlocksDestroyed / foodLoss}§7 blocks mined", - "§rEnvironment", - " §7Starting coordinates: §9(${startingBlockPos.asString()})", - " §7Direction: §9${buildDirectionSaved.displayName}", - " §7Blocks destroyed: §9$totalBlocksDestroyed", - " §7Blocks placed: §9$totalBlocksPlaced", - " §7Material: §9${material.localizedName}", - " §7Filler: §9${fillerMat.localizedName}", - "§rTask", - " §7Status: §9${currentTask?.taskState}", - " §7Target state: §9${currentTask?.block?.localizedName}", - " §7Position: §9(${currentTask?.blockPos?.asString()})", - "§rDebug", - " §7Stuck manager: §9${stuckManager}", - " §7Pathing: §9$pathing", - "§rEstimations", - " §7${material.localizedName} (main material): §9$materialLeft + ($indirectMaterialLeft)", - " §7${fillerMat.localizedName} (filler material): §9$fillerMatLeft", - " §7Paving distance left: §9$pavingLeftAll", - " §7Estimated destination: §9(${relativeDirection(currentBlockPos, pavingLeft, 0).asString()})", - " §7ETA: §9$hoursLeft:$minutesLeft:$secondsLeft")) + val statistics = mutableListOf( + "§rPerformance", + " §7Runtime: §9$hours:$minutes:$seconds", + " §7Placements per second: §9%.2f".format(totalBlocksPlaced / runtimeSec), + " §7Breaks per second: §9%.2f".format(totalBlocksDestroyed / runtimeSec), + " §7Distance per hour: §9%.2f".format((getDistance(startingBlockPos.toVec3d(), currentBlockPos.toVec3d()).toInt() / runtimeSec) * 60 * 60), + " §7One food loss per §9${totalBlocksDestroyed / foodLoss}§7 blocks mined", + "§rEnvironment", + " §7Starting coordinates: §9(${startingBlockPos.asString()})", + " §7Direction: §9${buildDirectionSaved.displayName}", + " §7Blocks destroyed: §9$totalBlocksDestroyed", + " §7Blocks placed: §9$totalBlocksPlaced", + " §7Material: §9${material.localizedName}", + " §7Filler: §9${fillerMat.localizedName}", + "§rTask", + " §7Status: §9${currentTask?.taskState}", + " §7Target state: §9${currentTask?.block?.localizedName}", + " §7Position: §9(${currentTask?.blockPos?.asString()})", + "§rDebug", + " §7Stuck manager: §9${stuckManager}", + " §7Pathing: §9$pathing", + "§rEstimations", + " §7${material.localizedName} (main material): §9$materialLeft + ($indirectMaterialLeft)", + " §7${fillerMat.localizedName} (filler material): §9$fillerMatLeft", + " §7Paving distance left: §9$pavingLeftAll", + " §7Estimated destination: §9(${relativeDirection(currentBlockPos, pavingLeft, 0).asString()})", + " §7ETA: §9$hoursLeft:$minutesLeft:$secondsLeft" + ) if (printDebug.value) { // for (x in getQueue()) sendChatMessage(x) From 04801f5bc280032a9c20ff354c01bbe369c83aca Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Sat, 21 Nov 2020 21:46:33 -0500 Subject: [PATCH 073/390] Optimized getNextWalkableBlock() --- .../kami/module/modules/misc/HighwayTools.kt | 43 ++++++------------- .../kami/util/math/VectorUtils.kt | 5 +++ 2 files changed, 19 insertions(+), 29 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 2b7e086bf7..3615b5cc81 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -19,6 +19,7 @@ import me.zeroeightsix.kami.util.math.RotationUtils import me.zeroeightsix.kami.util.math.Vec2d import me.zeroeightsix.kami.util.math.VectorUtils.getBlockPositionsInArea import me.zeroeightsix.kami.util.math.VectorUtils.getDistance +import me.zeroeightsix.kami.util.math.VectorUtils.multiply import me.zeroeightsix.kami.util.math.VectorUtils.toBlockPos import me.zeroeightsix.kami.util.math.VectorUtils.toVec3d import me.zeroeightsix.kami.util.text.MessageSendHelper.sendChatMessage @@ -956,22 +957,17 @@ object HighwayTools : Module() { } fun getNextWalkableBlock(): BlockPos { - if (mode.value == Mode.HIGHWAY) { + var lastWalkable = getNextBlock() + + for (step in 1..4) { + val pos = relativeDirection(currentBlockPos, step, 0) if (mc.world.getBlockState(getNextBlock().down()).block == material && - mc.world.getBlockState(getNextBlock()).block == Blocks.AIR && - mc.world.getBlockState(getNextBlock().up()).block == Blocks.AIR) { - if (mc.world.getBlockState(getNextBlock(getNextBlock().down())).block == material && - mc.world.getBlockState(getNextBlock(getNextBlock())).block == Blocks.AIR && - mc.world.getBlockState(getNextBlock(getNextBlock().up())).block == Blocks.AIR) { - if (mc.world.getBlockState(getNextBlock(getNextBlock(getNextBlock().down()))).block == material && - mc.world.getBlockState(getNextBlock(getNextBlock(getNextBlock()))).block == Blocks.AIR && - mc.world.getBlockState(getNextBlock(getNextBlock(getNextBlock().up()))).block == Blocks.AIR) return getNextBlock(getNextBlock(getNextBlock())) - return getNextBlock(getNextBlock()) - } - return getNextBlock() - } + mc.world.getBlockState(getNextBlock()).block == Blocks.AIR && + mc.world.getBlockState(getNextBlock().up()).block == Blocks.AIR) lastWalkable = pos + else break } - return getNextBlock() + + return lastWalkable } private fun getNextBlock(): BlockPos { @@ -982,21 +978,10 @@ object HighwayTools : Module() { return relativeDirection(blockPos, 1, 0) } - private fun relativeDirection(curs: BlockPos, steps: Int, turn: Int): BlockPos { - var c = curs - var d = (buildDirectionSaved.ordinal + turn).rem(8) - if (d < 0) d += 8 - when (d) { - 0 -> c = c.north(steps) - 1 -> c = c.north(steps).east(steps) - 2 -> c = c.east(steps) - 3 -> c = c.south(steps).east(steps) - 4 -> c = c.south(steps) - 5 -> c = c.south(steps).west(steps) - 6 -> c = c.west(steps) - 7 -> c = c.north(steps).west(steps) - } - return c + private fun relativeDirection(current: BlockPos, steps: Int, turn: Int): BlockPos { + val index = buildDirectionSaved.ordinal + turn + val direction = Direction.values()[index % 8] + return current.add(direction.directionVec.multiply(steps)) } private fun getAABBSide(bb: AxisAlignedBB, side: EnumFacing): Double { diff --git a/src/main/java/me/zeroeightsix/kami/util/math/VectorUtils.kt b/src/main/java/me/zeroeightsix/kami/util/math/VectorUtils.kt index 0d8c192e05..aad8d7ddae 100644 --- a/src/main/java/me/zeroeightsix/kami/util/math/VectorUtils.kt +++ b/src/main/java/me/zeroeightsix/kami/util/math/VectorUtils.kt @@ -4,6 +4,7 @@ import me.zeroeightsix.kami.util.Wrapper import net.minecraft.block.BlockAir import net.minecraft.util.math.BlockPos import net.minecraft.util.math.Vec3d +import net.minecraft.util.math.Vec3i import kotlin.math.* /** @@ -150,4 +151,8 @@ object VectorUtils { fun BlockPos.toVec3d(): Vec3d { return Vec3d(this).add(0.5, 0.5, 0.5) } + + fun Vec3i.multiply(multiplier: Int): Vec3i { + return Vec3i(x * multiplier, y * multiplier, z * multiplier) + } } From 6fc90c29a7a9869eb7fa5f3dd8952e04131bbd41 Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Sat, 21 Nov 2020 21:50:13 -0500 Subject: [PATCH 074/390] No need to update runTimeSec on tick --- .../me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 3615b5cc81..7e9818f0f0 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -119,7 +119,6 @@ object HighwayTools : Module() { private var totalBlocksPlaced = 0 private var totalBlocksDestroyed = 0 private var startTime = 0L - private var runtimeSec = 0.0 private var prevFood = 0 private var foodLoss = 1 private var materialLeft = 0 @@ -130,7 +129,6 @@ object HighwayTools : Module() { if (event.phase != TickEvent.Phase.END) { if (mc.playerController == null) return@listener BaritoneUtils.primary?.pathingControlManager?.registerProcess(HighwayToolsProcess) - runtimeSec = ((System.currentTimeMillis() - startTime) / 1000).toDouble() if (baritoneMode.value) { pathing = BaritoneUtils.isPathing @@ -201,7 +199,6 @@ object HighwayTools : Module() { lastHotbarSlot = -1 buildDirectionSaved = Direction.fromEntity(mc.player) startTime = System.currentTimeMillis() - runtimeSec = 0.1 totalBlocksPlaced = 0 totalBlocksDestroyed = 0 @@ -908,6 +905,7 @@ object HighwayTools : Module() { val pavingLeft = materialLeft / (blueprintStats.first + 1) val pavingLeftAll = (materialLeft + indirectMaterialLeft) / (blueprintStats.first + 1) + val runtimeSec = (System.currentTimeMillis() - startTime) / 1000 val seconds = (runtimeSec % 60).toInt().toString().padStart(2,'0') val minutes = ((runtimeSec % 3600) / 60).toInt().toString().padStart(2,'0') val hours = (runtimeSec / 3600).toInt().toString().padStart(2,'0') From 7aac654a6722a871649b830ec6bdee7f3ad1629f Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Sat, 21 Nov 2020 21:53:45 -0500 Subject: [PATCH 075/390] Use any for blockQueue check --- .../kami/module/modules/misc/HighwayTools.kt | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 7e9818f0f0..bb258d983d 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -794,17 +794,11 @@ object HighwayTools : Module() { } private fun isInsideSelection(blockPos: BlockPos): Boolean { - for (bt in blockQueue) { - if (bt.blockPos == blockPos) return true - } - return false + return blockQueue.any { it.blockPos == blockPos } } private fun isInsideBuild(blockPos: BlockPos): Boolean { - for (bt in blockQueue) { - if (bt.blockPos == blockPos && bt.block == material) return true - } - return false + return blockQueue.any { it.blockPos == blockPos && it.block == material } } private fun adjustPlayerPosition() { From 8a8d8e8f4f888ee117e1bbe6332b20fab59ccda1 Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Sat, 21 Nov 2020 21:59:43 -0500 Subject: [PATCH 076/390] Use StringBuilder instead of adding up strings --- .../kami/module/modules/misc/HighwayTools.kt | 46 +++++++++++-------- 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index bb258d983d..a397a377bb 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -831,41 +831,51 @@ object HighwayTools : Module() { } fun printSettings() { - var message = "$chatName Settings" + + StringBuilder(ignoreBlocks.size + 1).run { + append("$chatName Settings" + "\n §9> §rMaterial: §7${material.localizedName}" + "\n §9> §rBaritone: §7${baritoneMode.value}" + - "\n §9> §rIgnored Blocks:" - for (b in ignoreBlocks) message += "\n §9> §7${b!!.registryName}" - sendChatMessage(message) + "\n §9> §rIgnored Blocks:") + for (b in ignoreBlocks) append("\n §9> §7${b!!.registryName}") + + sendChatMessage(toString()) + } } private fun printEnable() { if (info.value) { - var message = "" - message += "$chatName Module started." + - "\n §9> §7Direction: §a${buildDirectionSaved.displayName}§r" + StringBuilder(2).run { + append("$chatName Module started." + + "\n §9> §7Direction: §a${buildDirectionSaved.displayName}§r") - message += if (buildDirectionSaved.isDiagonal) { - "\n §9> §7Coordinates: §a${startingBlockPos.x} ${startingBlockPos.z}§r" - } else { - if (buildDirectionSaved == Direction.NORTH || buildDirectionSaved == Direction.SOUTH) { - "\n §9> §7Coordinate: §a${startingBlockPos.x}§r" + if (buildDirectionSaved.isDiagonal) { + append("\n §9> §7Coordinates: §a${startingBlockPos.x} ${startingBlockPos.z}§r") } else { - "\n §9> §7Coordinate: §a${startingBlockPos.z}§r" + if (buildDirectionSaved == Direction.NORTH || buildDirectionSaved == Direction.SOUTH) { + append("\n §9> §7Coordinate: §a${startingBlockPos.x}§r") + } else { + append("\n §9> §7Coordinate: §a${startingBlockPos.z}§r") + } } + + sendChatMessage(toString()) } - sendChatMessage(message) } } private fun printDisable() { if (info.value) { - var message = "" - message += "$chatName Module stopped." + + StringBuilder(2).run { + append( + "$chatName Module stopped." + "\n §9> §7Placed blocks: §a$totalBlocksPlaced§r" + "\n §9> §7Destroyed blocks: §a$totalBlocksDestroyed§r" - if (baritoneMode.value) message += "\n §9> §7Distance: §a${getDistance(startingBlockPos.toVec3d(), currentBlockPos.toVec3d()).toInt()}§r" - sendChatMessage(message) + ) + + if (baritoneMode.value) append("\n §9> §7Distance: §a${getDistance(startingBlockPos.toVec3d(), currentBlockPos.toVec3d()).toInt()}§r") + + sendChatMessage(toString()) + } } } From 1cd8334277d8840b0df504c1d1d9410b66f166fd Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Sat, 21 Nov 2020 22:01:28 -0500 Subject: [PATCH 077/390] Optimized task shuffling --- .../me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index a397a377bb..75b399f73e 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -515,10 +515,9 @@ object HighwayTools : Module() { } private fun shuffleTasks() { - var tmpQueue: Queue = LinkedList(blockQueue) - tmpQueue = LinkedList(tmpQueue.shuffled()) + val shuffled = blockQueue.shuffled() blockQueue.clear() - blockQueue.addAll(tmpQueue) + blockQueue.addAll(shuffled) } private fun inventoryProcessor(blockTask: BlockTask): Boolean { From 4d8da660b009fea10e5ca0328530cf5a6a66a12a Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Sat, 21 Nov 2020 22:06:55 -0500 Subject: [PATCH 078/390] Optimized renderer updating --- .../kami/module/modules/misc/HighwayTools.kt | 135 +++++++++--------- 1 file changed, 69 insertions(+), 66 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 75b399f73e..e635f2fbf9 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -114,6 +114,7 @@ object HighwayTools : Module() { private var currentBlockPos = BlockPos(0, -1, 0) private var startingBlockPos = BlockPos(0, -1, 0) private val stuckManager = StuckManagement(StuckLevel.NONE, 0) + private val renderer = ESPRenderer() // stats private var totalBlocksPlaced = 0 @@ -124,10 +125,67 @@ object HighwayTools : Module() { private var materialLeft = 0 private var fillerMatLeft = 0 + override fun onEnable() { + if (mc.player == null) { + disable() + return + } + + startingBlockPos = mc.player.positionVector.toBlockPos() + currentBlockPos = startingBlockPos + playerHotbarSlot = mc.player.inventory.currentItem + lastHotbarSlot = -1 + buildDirectionSaved = Direction.fromEntity(mc.player) + startTime = System.currentTimeMillis() + totalBlocksPlaced = 0 + totalBlocksDestroyed = 0 + + if (baritoneMode.value) { + baritoneSettingAllowPlace = BaritoneUtils.settings?.allowPlace?.value ?: true + BaritoneUtils.settings?.allowPlace?.value = false + + if (!goalRender.value) { + baritoneSettingRenderGoal = BaritoneUtils.settings?.renderGoal?.value ?: true + BaritoneUtils.settings?.renderGoal?.value = false + } + } + + playerHotbarSlot = mc.player.inventory.currentItem + + refreshData() + printEnable() + } + + override fun onDisable() { + if (mc.player == null) return + + // load initial player hand + if (lastHotbarSlot != playerHotbarSlot && playerHotbarSlot != -1) { + mc.player.inventory.currentItem = playerHotbarSlot + } + playerHotbarSlot = -1 + lastHotbarSlot = -1 + + if (baritoneMode.value) { + BaritoneUtils.settings?.allowPlace?.value = baritoneSettingAllowPlace + if (!goalRender.value) BaritoneUtils.settings?.renderGoal?.value = baritoneSettingRenderGoal + val process = BaritoneUtils.primary?.pathingControlManager?.mostRecentInControl() + + if (process != null && process.isPresent && process.get() == HighwayToolsProcess) process.get().onLostControl() + } + printDisable() + } + + fun isDone(): Boolean { + return blockQueue.size == 0 + } + init { listener { event -> if (event.phase != TickEvent.Phase.END) { if (mc.playerController == null) return@listener + + updateRenderer() BaritoneUtils.primary?.pathingControlManager?.registerProcess(HighwayToolsProcess) if (baritoneMode.value) { @@ -175,67 +233,22 @@ object HighwayTools : Module() { listener { if (mc.player == null) return@listener - val renderer = ESPRenderer() - renderer.aFilled = if (filled.value) aFilled.value else 0 - renderer.aOutline = if (outline.value) aOutline.value else 0 - updateRenderer(renderer) - renderer.render(true) + renderer.render(false) } } - fun isDone(): Boolean { - return blockQueue.size == 0 - } - - override fun onEnable() { - if (mc.player == null) { - disable() - return - } - - startingBlockPos = mc.player.positionVector.toBlockPos() - currentBlockPos = startingBlockPos - playerHotbarSlot = mc.player.inventory.currentItem - lastHotbarSlot = -1 - buildDirectionSaved = Direction.fromEntity(mc.player) - startTime = System.currentTimeMillis() - totalBlocksPlaced = 0 - totalBlocksDestroyed = 0 - - if (baritoneMode.value) { - baritoneSettingAllowPlace = BaritoneUtils.settings?.allowPlace?.value ?: true - BaritoneUtils.settings?.allowPlace?.value = false - - if (!goalRender.value) { - baritoneSettingRenderGoal = BaritoneUtils.settings?.renderGoal?.value ?: true - BaritoneUtils.settings?.renderGoal?.value = false - } - } - - playerHotbarSlot = mc.player.inventory.currentItem - - refreshData() - printEnable() - } - - override fun onDisable() { - if (mc.player == null) return - - // load initial player hand - if (lastHotbarSlot != playerHotbarSlot && playerHotbarSlot != -1) { - mc.player.inventory.currentItem = playerHotbarSlot + private fun updateRenderer() { + renderer.clear() + renderer.aFilled = if (filled.value) aFilled.value else 0 + renderer.aOutline = if (outline.value) aOutline.value else 0 + for (blockTask in blockQueue) { + if (blockTask.taskState == TaskState.DONE) continue + renderer.add(AxisAlignedBB(blockTask.blockPos), blockTask.taskState.color) } - playerHotbarSlot = -1 - lastHotbarSlot = -1 - - if (baritoneMode.value) { - BaritoneUtils.settings?.allowPlace?.value = baritoneSettingAllowPlace - if (!goalRender.value) BaritoneUtils.settings?.renderGoal?.value = baritoneSettingRenderGoal - val process = BaritoneUtils.primary?.pathingControlManager?.mostRecentInControl() - - if (process != null && process.isPresent && process.get() == HighwayToolsProcess) process.get().onLostControl() + for (blockTask in doneQueue) { + if (blockTask.block != Blocks.AIR) continue + renderer.add(AxisAlignedBB(blockTask.blockPos), blockTask.taskState.color) } - printDisable() } private fun addTask(blockPos: BlockPos, taskState: TaskState, material: Block) { @@ -810,16 +823,6 @@ object HighwayTools : Module() { return round(doubleIn + 0.5) - 0.5 } - private fun updateRenderer(renderer: ESPRenderer): ESPRenderer { - for (blockTask in blockQueue) { - if (blockTask.taskState != TaskState.DONE) renderer.add(mc.world.getBlockState(blockTask.blockPos).getSelectedBoundingBox(mc.world, blockTask.blockPos), blockTask.taskState.color) - } - for (blockTask in doneQueue) { - if (blockTask.block != Blocks.AIR) renderer.add(mc.world.getBlockState(blockTask.blockPos).getSelectedBoundingBox(mc.world, blockTask.blockPos), blockTask.taskState.color) - } - return renderer - } - private fun getQueue(): List { val message: MutableList = mutableListOf() message.add("QUEUE:") From 6ac5652b760e67dd15c23486cd35e7385f6ada25 Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Sat, 21 Nov 2020 22:12:47 -0500 Subject: [PATCH 079/390] Use contains to check ignored block instead of iterating through --- .../kami/module/modules/misc/HighwayTools.kt | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index e635f2fbf9..7d81123399 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -379,11 +379,9 @@ object HighwayTools : Module() { // ignore blocks if (blockTask.taskState != TaskState.EMERGENCY_BREAK) { - for (b in ignoreBlocks) { - if (block == b && blockTask.block != Blocks.AIR) { - updateTask(blockTask, TaskState.DONE) - doTask() - } + if (blockTask.block != Blocks.AIR && ignoreBlocks.contains(blockTask.block)) { + updateTask(blockTask, TaskState.DONE) + doTask() } } @@ -458,11 +456,9 @@ object HighwayTools : Module() { private fun checkTasks(): Boolean { - loop@ for (blockTask in doneQueue) { + for (blockTask in doneQueue) { val block = mc.world.getBlockState(blockTask.blockPos).block - for (b in ignoreBlocks) { - if (b == block) continue@loop - } + if (ignoreBlocks.contains(block)) continue when { blockTask.block == material && block != material -> return false mode.value == Mode.TUNNEL && blockTask.block == fillerMat && block != fillerMat -> return false From ba1b5398803e0df94d461befb38d5e184ebf5233 Mon Sep 17 00:00:00 2001 From: Christian Date: Thu, 26 Nov 2020 00:07:54 +0100 Subject: [PATCH 080/390] Runtime fixes --- .../kami/module/modules/misc/HighwayTools.kt | 33 +++++++++---------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 7d81123399..bf2d1fb917 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -191,7 +191,7 @@ object HighwayTools : Module() { if (baritoneMode.value) { pathing = BaritoneUtils.isPathing var taskDistance = BlockPos(0, -1, 0) - blockQueue.firstOrNull() ?: doneQueue.firstOrNull()?.let { + (blockQueue.firstOrNull() ?: doneQueue.firstOrNull())?.let { taskDistance = it.blockPos } if (getDistance(mc.player.positionVector, taskDistance.toVec3d()) < maxReach.value ) { @@ -242,12 +242,12 @@ object HighwayTools : Module() { renderer.aFilled = if (filled.value) aFilled.value else 0 renderer.aOutline = if (outline.value) aOutline.value else 0 for (blockTask in blockQueue) { - if (blockTask.taskState == TaskState.DONE) continue - renderer.add(AxisAlignedBB(blockTask.blockPos), blockTask.taskState.color) + if (blockTask.taskState == TaskState.DONE) continue + renderer.add(mc.world.getBlockState(blockTask.blockPos).getSelectedBoundingBox(mc.world, blockTask.blockPos), blockTask.taskState.color) } for (blockTask in doneQueue) { - if (blockTask.block != Blocks.AIR) continue - renderer.add(AxisAlignedBB(blockTask.blockPos), blockTask.taskState.color) + if (blockTask.block == Blocks.AIR) continue + renderer.add(mc.world.getBlockState(blockTask.blockPos).getSelectedBoundingBox(mc.world, blockTask.blockPos), blockTask.taskState.color) } } @@ -286,7 +286,7 @@ object HighwayTools : Module() { stuckManager.increase(blockTask) return } - TaskState.BROKEN -> dpBroken(blockTask) + TaskState.BROKEN -> doBroken(blockTask) TaskState.PLACED -> doPlaced(blockTask) TaskState.EMERGENCY_BREAK -> if(!doBreak(blockTask)) { stuckManager.increase(blockTask) @@ -296,7 +296,7 @@ object HighwayTools : Module() { stuckManager.increase(blockTask) return } - TaskState.PLACE, TaskState.LIQUID_SOURCE, TaskState.LIQUID_FLOW -> if(!doPLACE(blockTask)) { + TaskState.PLACE, TaskState.LIQUID_SOURCE, TaskState.LIQUID_FLOW -> if(!doPlace(blockTask)) { stuckManager.increase(blockTask) return } @@ -345,7 +345,7 @@ object HighwayTools : Module() { return true } - private fun dpBroken(blockTask: BlockTask) { + private fun doBroken(blockTask: BlockTask) { when (mc.world.getBlockState(blockTask.blockPos).block) { Blocks.AIR -> { totalBlocksDestroyed++ @@ -375,7 +375,6 @@ object HighwayTools : Module() { } private fun doBreak(blockTask: BlockTask): Boolean { - val block = mc.world.getBlockState(blockTask.blockPos).block // ignore blocks if (blockTask.taskState != TaskState.EMERGENCY_BREAK) { @@ -386,7 +385,7 @@ object HighwayTools : Module() { } // last check before breaking - when (block) { + when (mc.world.getBlockState(blockTask.blockPos).block) { Blocks.AIR -> { if (blockTask.block == Blocks.AIR) { updateTask(blockTask, TaskState.DONE) @@ -421,7 +420,7 @@ object HighwayTools : Module() { return true } - private fun doPLACE(blockTask: BlockTask): Boolean { + private fun doPlace(blockTask: BlockTask): Boolean { val block = mc.world.getBlockState(blockTask.blockPos).block when { @@ -907,14 +906,14 @@ object HighwayTools : Module() { val pavingLeft = materialLeft / (blueprintStats.first + 1) val pavingLeftAll = (materialLeft + indirectMaterialLeft) / (blueprintStats.first + 1) - val runtimeSec = (System.currentTimeMillis() - startTime) / 1000 + val runtimeSec = ((System.currentTimeMillis() - startTime) / 1000) + 0.0001 val seconds = (runtimeSec % 60).toInt().toString().padStart(2,'0') val minutes = ((runtimeSec % 3600) / 60).toInt().toString().padStart(2,'0') val hours = (runtimeSec / 3600).toInt().toString().padStart(2,'0') val distanceDone = getDistance(startingBlockPos.toVec3d(), currentBlockPos.toVec3d()).toInt() - val secLeft = runtimeSec / distanceDone * pavingLeftAll + val secLeft = runtimeSec / (distanceDone * pavingLeftAll + 0.0001) val secondsLeft = (secLeft % 60).toInt().toString().padStart(2,'0') val minutesLeft = ((secLeft % 3600) / 60).toInt().toString().padStart(2,'0') val hoursLeft = (secLeft / 3600).toInt().toString().padStart(2,'0') @@ -961,9 +960,9 @@ object HighwayTools : Module() { for (step in 1..4) { val pos = relativeDirection(currentBlockPos, step, 0) - if (mc.world.getBlockState(getNextBlock().down()).block == material && - mc.world.getBlockState(getNextBlock()).block == Blocks.AIR && - mc.world.getBlockState(getNextBlock().up()).block == Blocks.AIR) lastWalkable = pos + if (mc.world.getBlockState(pos.down()).block == material && + mc.world.getBlockState(pos).block == Blocks.AIR && + mc.world.getBlockState(pos.up()).block == Blocks.AIR) lastWalkable = pos else break } @@ -980,7 +979,7 @@ object HighwayTools : Module() { private fun relativeDirection(current: BlockPos, steps: Int, turn: Int): BlockPos { val index = buildDirectionSaved.ordinal + turn - val direction = Direction.values()[index % 8] + val direction = Direction.values()[Math.floorMod(index, 8)] return current.add(direction.directionVec.multiply(steps)) } From 21a0401242f16c34ff5eef0b2d66619fcd8fed9b Mon Sep 17 00:00:00 2001 From: Christian Date: Thu, 26 Nov 2020 03:04:04 +0100 Subject: [PATCH 081/390] Corner block for tunnel mode --- .../kami/module/modules/misc/AutoObsidian.kt | 13 +- .../kami/module/modules/misc/HighwayTools.kt | 192 ++++++++++-------- .../kami/process/HighwayToolsProcess.kt | 4 +- 3 files changed, 115 insertions(+), 94 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt index 9b6e43e1ac..232d7bdddd 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt @@ -1,7 +1,6 @@ package me.zeroeightsix.kami.module.modules.misc import me.zeroeightsix.kami.event.events.SafeTickEvent -import me.zeroeightsix.kami.mixin.extension.rightClickDelayTimer import me.zeroeightsix.kami.module.Module import me.zeroeightsix.kami.module.modules.player.NoBreakAnimation import me.zeroeightsix.kami.process.AutoObsidianProcess @@ -229,7 +228,7 @@ object AutoObsidian : Module() { placingPos = getPlacingPos() } else { sendChatMessage("$chatName No valid position for placing shulker box / ender chest nearby, disabling.") - mc.getSoundHandler().playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) + mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) this.disable() return } @@ -258,7 +257,7 @@ object AutoObsidian : Module() { if (InventoryUtils.getSlotsHotbar(i) == null) { if (i != 234) continue else { sendChatMessage("$chatName No shulker box was found in hotbar, disabling.") - mc.getSoundHandler().playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) + mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) this.disable() return } @@ -282,7 +281,7 @@ object AutoObsidian : Module() { state = State.SEARCHING } else { sendChatMessage("$chatName No ender chest was found in inventory, disabling.") - mc.getSoundHandler().playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) + mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) this.disable() return } @@ -343,7 +342,7 @@ object AutoObsidian : Module() { val currentContainer = mc.player.openContainer var enderChestSlot = -1 for (i in 0..26) { - if (getIdFromItem(currentContainer.inventory[i].getItem()) == 130) { + if (getIdFromItem(currentContainer.inventory[i].item) == 130) { enderChestSlot = i } } @@ -351,7 +350,7 @@ object AutoObsidian : Module() { mc.playerController.windowClick(currentContainer.windowId, enderChestSlot, 0, ClickType.QUICK_MOVE, mc.player) } else { sendChatMessage("$chatName No ender chest was found in shulker, disabling.") - mc.getSoundHandler().playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) + mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) this.disable() } }.start() @@ -419,7 +418,7 @@ object AutoObsidian : Module() { return false } else if (InventoryUtils.getSlots(0, 35, 278) == null) { sendChatMessage("No pickaxe was found in inventory.") - mc.getSoundHandler().playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) + mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) return false } InventoryUtils.swapSlotToItem(278) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index bf2d1fb917..1022487a7d 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -64,7 +64,7 @@ object HighwayTools : Module() { private val buildWidth = register(Settings.integerBuilder("Width").withValue(5).withRange(1, 9).withStep(1).withVisibility { page.value == Page.BUILD }) private val railing = register(Settings.booleanBuilder("Railing").withValue(true).withVisibility { page.value == Page.BUILD && mode.value == Mode.HIGHWAY }) private val railingHeight = register(Settings.integerBuilder("RailingHeight").withValue(1).withRange(0, 4).withStep(1).withMaximum(clearHeight.value).withVisibility { railing.value && page.value == Page.BUILD && mode.value == Mode.HIGHWAY }) - private val cornerBlock = register(Settings.booleanBuilder("CornerBlock").withValue(false).withVisibility { page.value == Page.BUILD && mode.value == Mode.HIGHWAY }) + private val cornerBlock = register(Settings.booleanBuilder("CornerBlock").withValue(false).withVisibility { page.value == Page.BUILD && (mode.value == Mode.HIGHWAY || mode.value == Mode.TUNNEL) }) // behavior settings val baritoneMode = register(Settings.booleanBuilder("AutoMode").withValue(true).withVisibility { page.value == Page.BEHAVIOR }) @@ -105,9 +105,9 @@ object HighwayTools : Module() { private var baritoneSettingRenderGoal = false // runtime vars - val blockQueue = PriorityQueue(compareBy { it.taskState.ordinal }) - private val doneQueue = ArrayList() - private val blockOffsets = ArrayList>() + val pendingTasks = PriorityQueue(BlockTaskComparator) + private val doneTasks = ArrayList() + private val blueprint = ArrayList>() private var waitTicks = 0 private var blocksPlaced = 0 var pathing = false @@ -177,7 +177,7 @@ object HighwayTools : Module() { } fun isDone(): Boolean { - return blockQueue.size == 0 + return pendingTasks.size == 0 } init { @@ -191,27 +191,27 @@ object HighwayTools : Module() { if (baritoneMode.value) { pathing = BaritoneUtils.isPathing var taskDistance = BlockPos(0, -1, 0) - (blockQueue.firstOrNull() ?: doneQueue.firstOrNull())?.let { + (pendingTasks.firstOrNull() ?: doneTasks.firstOrNull())?.let { taskDistance = it.blockPos } if (getDistance(mc.player.positionVector, taskDistance.toVec3d()) < maxReach.value ) { - if (!isDone() && !BaritoneUtils.paused && !AutoObsidian.isActive() && !AutoEat.eating) { - if (!pathing) adjustPlayerPosition() - val currentFood = mc.player.getFoodStats().foodLevel - if (currentFood != prevFood) { - if (currentFood < prevFood) foodLoss++ - prevFood = currentFood + if (!isDone()) { + if (!BaritoneUtils.paused && !AutoObsidian.isActive() && !AutoEat.eating) { + if (!pathing) adjustPlayerPosition() + val currentFood = mc.player.foodStats.foodLevel + if (currentFood != prevFood) { + if (currentFood < prevFood) foodLoss++ + prevFood = currentFood + } + doTask() } - doTask() } else { - if (isDone()) { - if (checkTasks() && !pathing) { - currentBlockPos = getNextBlock(getNextBlock()) - doneQueue.clear() - updateTasks(currentBlockPos) - } else { - refreshData() - } + if (checkTasks() && !pathing) { + currentBlockPos = getNextBlock(getNextBlock()) + doneTasks.clear() + updateTasks(currentBlockPos) + } else { + refreshData() } } } else { @@ -241,44 +241,44 @@ object HighwayTools : Module() { renderer.clear() renderer.aFilled = if (filled.value) aFilled.value else 0 renderer.aOutline = if (outline.value) aOutline.value else 0 - for (blockTask in blockQueue) { + for (blockTask in pendingTasks) { if (blockTask.taskState == TaskState.DONE) continue renderer.add(mc.world.getBlockState(blockTask.blockPos).getSelectedBoundingBox(mc.world, blockTask.blockPos), blockTask.taskState.color) } - for (blockTask in doneQueue) { + for (blockTask in doneTasks) { if (blockTask.block == Blocks.AIR) continue renderer.add(mc.world.getBlockState(blockTask.blockPos).getSelectedBoundingBox(mc.world, blockTask.blockPos), blockTask.taskState.color) } } private fun addTask(blockPos: BlockPos, taskState: TaskState, material: Block) { - blockQueue.add(BlockTask(blockPos, taskState, material)) + pendingTasks.add(BlockTask(blockPos, taskState, material)) } private fun addTask(blockPos: BlockPos, material: Block) { - doneQueue.add(BlockTask(blockPos, TaskState.DONE, material)) + doneTasks.add(BlockTask(blockPos, TaskState.DONE, material)) } private fun updateTask(blockTask: BlockTask, taskState: TaskState) { - blockQueue.poll() + pendingTasks.poll() blockTask.taskState = taskState if (taskState == TaskState.DONE) { - doneQueue.add(blockTask) + doneTasks.add(blockTask) } else { - blockQueue.add(blockTask) + pendingTasks.add(blockTask) } } private fun updateTask(blockTask: BlockTask, material: Block) { - blockQueue.poll() + pendingTasks.poll() blockTask.block = material - doneQueue.add(blockTask) + doneTasks.add(blockTask) } private fun doTask() { if (!isDone() && !BaritoneUtils.paused && !AutoObsidian.isActive()) { if (waitTicks == 0) { - val blockTask = blockQueue.peek() + val blockTask = pendingTasks.peek() when (blockTask.taskState) { TaskState.DONE -> doDone(blockTask) @@ -310,8 +310,8 @@ object HighwayTools : Module() { } private fun doDone(blockTask: BlockTask) { - blockQueue.poll() - doneQueue.add(blockTask) + pendingTasks.poll() + doneTasks.add(blockTask) doTask() } @@ -455,7 +455,7 @@ object HighwayTools : Module() { private fun checkTasks(): Boolean { - for (blockTask in doneQueue) { + for (blockTask in doneTasks) { val block = mc.world.getBlockState(blockTask.blockPos).block if (ignoreBlocks.contains(block)) continue when { @@ -468,10 +468,10 @@ object HighwayTools : Module() { } private fun updateTasks(originPos: BlockPos) { - blockOffsets.clear() + blueprint.clear() updateBlockArray(originPos) updateBlockArray(getNextBlock(originPos)) - for ((blockPos, blockType) in blockOffsets) { + for ((blockPos, blockType) in blueprint) { val isReplaceable = mc.world.getBlockState(blockPos).material.isReplaceable if (blockPos == mc.player.positionVector.toBlockPos().down()) continue when (val block = mc.world.getBlockState(blockPos).block) { @@ -523,9 +523,9 @@ object HighwayTools : Module() { } private fun shuffleTasks() { - val shuffled = blockQueue.shuffled() - blockQueue.clear() - blockQueue.addAll(shuffled) + val shuffled = pendingTasks.shuffled() + pendingTasks.clear() + pendingTasks.addAll(shuffled) } private fun inventoryProcessor(blockTask: BlockTask): Boolean { @@ -537,7 +537,7 @@ object HighwayTools : Module() { InventoryUtils.moveToSlot(noHotbar[0], 36) } else if (InventoryUtils.getSlots(0, 35, 278) == null) { sendChatMessage("$chatName No Pickaxe was found in inventory") - mc.getSoundHandler().playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) + mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) disable() return false } @@ -561,7 +561,7 @@ object HighwayTools : Module() { // } } else if (InventoryUtils.getSlots(0, 35, blockID) == null) { sendChatMessage("$chatName No ${blockTask.block.localizedName} was found in inventory") - mc.getSoundHandler().playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) + mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) disable() return false } @@ -588,7 +588,7 @@ object HighwayTools : Module() { val found = mutableListOf>() var filler = fillerMat if (isInsideBuild(neighbour)) filler = material - for (bt in blockQueue) { + for (bt in pendingTasks) { if (bt.blockPos == neighbour) { when (flowing) { false -> found.add(Triple(bt, TaskState.LIQUID_SOURCE, filler)) @@ -784,9 +784,7 @@ object HighwayTools : Module() { mc.player.rotationYaw = rotation.x.toFloat() mc.player.rotationPitch = rotation.y.toFloat() } - else -> { - - } + else -> {} } } @@ -801,11 +799,11 @@ object HighwayTools : Module() { } private fun isInsideSelection(blockPos: BlockPos): Boolean { - return blockQueue.any { it.blockPos == blockPos } + return pendingTasks.any { it.blockPos == blockPos } } private fun isInsideBuild(blockPos: BlockPos): Boolean { - return blockQueue.any { it.blockPos == blockPos && it.block == material } + return pendingTasks.any { it.blockPos == blockPos && it.block == material } } private fun adjustPlayerPosition() { @@ -821,9 +819,9 @@ object HighwayTools : Module() { private fun getQueue(): List { val message: MutableList = mutableListOf() message.add("QUEUE:") - for (blockTask in blockQueue) message.add(" " + blockTask.block.localizedName + "@(" + blockTask.blockPos.asString() + ") Priority: " + blockTask.taskState.ordinal + " State: " + blockTask.taskState.toString()) + for (blockTask in pendingTasks) message.add(" " + blockTask.block.localizedName + "@(" + blockTask.blockPos.asString() + ") Priority: " + blockTask.taskState.ordinal + " State: " + blockTask.taskState.toString()) message.add("DONE:") - for (blockTask in doneQueue) message.add(" " + blockTask.block.localizedName + "@(" + blockTask.blockPos.asString() + ") Priority: " + blockTask.taskState.ordinal + " State: " + blockTask.taskState.toString()) + for (blockTask in doneTasks) message.add(" " + blockTask.block.localizedName + "@(" + blockTask.blockPos.asString() + ") Priority: " + blockTask.taskState.ordinal + " State: " + blockTask.taskState.toString()) return message } @@ -880,7 +878,7 @@ object HighwayTools : Module() { fun getBlueprintStats(): Pair { var materialUsed = 0 var fillerMatUsed = 0 - for ((_, b) in blockOffsets) { + for ((_, b) in blueprint) { when (b) { material -> materialUsed++ fillerMat -> fillerMatUsed++ @@ -894,7 +892,7 @@ object HighwayTools : Module() { val currentTask: BlockTask? = if (isDone()) { null } else { - blockQueue.peek() + pendingTasks.peek() } materialLeft = InventoryUtils.countItemAll(getIdFromBlock(material)) @@ -928,8 +926,8 @@ object HighwayTools : Module() { "§rEnvironment", " §7Starting coordinates: §9(${startingBlockPos.asString()})", " §7Direction: §9${buildDirectionSaved.displayName}", - " §7Blocks destroyed: §9$totalBlocksDestroyed", - " §7Blocks placed: §9$totalBlocksPlaced", + " §7Blocks destroyed: §9$totalBlocksDestroyed".padStart(6,'0'), + " §7Blocks placed: §9$totalBlocksPlaced".padStart(6,'0'), " §7Material: §9${material.localizedName}", " §7Filler: §9${fillerMat.localizedName}", "§rTask", @@ -958,12 +956,26 @@ object HighwayTools : Module() { fun getNextWalkableBlock(): BlockPos { var lastWalkable = getNextBlock() - for (step in 1..4) { - val pos = relativeDirection(currentBlockPos, step, 0) - if (mc.world.getBlockState(pos.down()).block == material && - mc.world.getBlockState(pos).block == Blocks.AIR && - mc.world.getBlockState(pos.up()).block == Blocks.AIR) lastWalkable = pos - else break + when (mode.value) { + Mode.HIGHWAY -> { + for (step in 1..3) { + val pos = relativeDirection(currentBlockPos, step, 0) + if (mc.world.getBlockState(pos.down()).block == material && + mc.world.getBlockState(pos).block == Blocks.AIR && + mc.world.getBlockState(pos.up()).block == Blocks.AIR) lastWalkable = pos + else break + } + } + Mode.TUNNEL -> { + for (step in 1..3) { + val pos = relativeDirection(currentBlockPos, step, 0) + if (mc.world.getBlockState(pos.down()).block == fillerMat && + mc.world.getBlockState(pos).block == Blocks.AIR && + mc.world.getBlockState(pos.up()).block == Blocks.AIR) lastWalkable = pos + else break + } + } + else -> {} } return lastWalkable @@ -999,23 +1011,23 @@ object HighwayTools : Module() { if (turn) turnValue = -1 if (mat != fillerMat) { if (height > 1) { - blockOffsets.add(Pair(relativeDirection(relativeDirection(cursor, 1, 3 * turnValue), width - 1, 2 * turnValue), Blocks.AIR)) + blueprint.add(Pair(relativeDirection(relativeDirection(cursor, 1, 3 * turnValue), width - 1, 2 * turnValue), Blocks.AIR)) } else { - blockOffsets.add(Pair(relativeDirection(relativeDirection(cursor, 1, 3 * turnValue), width - 1, 2 * turnValue), mat)) + blueprint.add(Pair(relativeDirection(relativeDirection(cursor, 1, 3 * turnValue), width - 1, 2 * turnValue), mat)) } } else { - blockOffsets.add(Pair(relativeDirection(relativeDirection(cursor, 1, 3 * turnValue), width - 1, 2 * turnValue), material)) + blueprint.add(Pair(relativeDirection(relativeDirection(cursor, 1, 3 * turnValue), width - 1, 2 * turnValue), material)) } } private fun genOffset(cursor: BlockPos, height: Int, width: Int, mat: Block, isOdd: Boolean) { - blockOffsets.add(Pair(relativeDirection(cursor, width, -2), mat)) + blueprint.add(Pair(relativeDirection(cursor, width, -2), mat)) if (buildDirectionSaved.isDiagonal) { addOffset(cursor, height, width, mat, true) } when { isOdd -> { - blockOffsets.add(Pair(relativeDirection(cursor, width, 2), mat)) + blueprint.add(Pair(relativeDirection(cursor, width, 2), mat)) if (buildDirectionSaved.isDiagonal) { addOffset(cursor, height, width, mat, false) } @@ -1023,19 +1035,19 @@ object HighwayTools : Module() { else -> { val evenCursor = relativeDirection(cursor, 1, 2) if (buildDirectionSaved.isDiagonal) { - blockOffsets.add(Pair(relativeDirection(evenCursor, width, 2), mat)) + blueprint.add(Pair(relativeDirection(evenCursor, width, 2), mat)) addOffset(cursor, height, width, mat, false) addOffset(evenCursor, height, width, mat, false) } else { - blockOffsets.add(Pair(relativeDirection(evenCursor, width, 2), mat)) + blueprint.add(Pair(relativeDirection(evenCursor, width, 2), mat)) } } } } private fun refreshData() { - doneQueue.clear() - blockQueue.clear() + doneTasks.clear() + pendingTasks.clear() updateTasks(currentBlockPos) shuffleTasks() } @@ -1047,10 +1059,10 @@ object HighwayTools : Module() { Mode.HIGHWAY -> { if (baritoneMode.value) { cursor = relativeDirection(cursor, 1, 0) - blockOffsets.add(Pair(cursor, material)) + blueprint.add(Pair(cursor, material)) } cursor = relativeDirection(cursor, 1, 0) - blockOffsets.add(Pair(cursor, material)) + blueprint.add(Pair(cursor, material)) var buildIterationsWidth = buildWidth.value / 2 var evenCursor = relativeDirection(cursor, 1, 2) var isOdd = false @@ -1058,7 +1070,7 @@ object HighwayTools : Module() { isOdd = true buildIterationsWidth++ } else { - blockOffsets.add(Pair(evenCursor, material)) + blueprint.add(Pair(evenCursor, material)) } for (i in 1 until clearHeight.value + 1) { for (j in 1 until buildIterationsWidth) { @@ -1081,18 +1093,18 @@ object HighwayTools : Module() { cursor = cursor.up() evenCursor = evenCursor.up() if (clearSpace.value && i < clearHeight.value) { - blockOffsets.add(Pair(cursor, Blocks.AIR)) - if (!isOdd) blockOffsets.add(Pair(evenCursor, Blocks.AIR)) + blueprint.add(Pair(cursor, Blocks.AIR)) + if (!isOdd) blueprint.add(Pair(evenCursor, Blocks.AIR)) } } } Mode.TUNNEL -> { if (baritoneMode.value) { cursor = relativeDirection(cursor, 1, 0) - blockOffsets.add(Pair(cursor, fillerMat)) + blueprint.add(Pair(cursor, fillerMat)) } cursor = relativeDirection(cursor, 1, 0) - blockOffsets.add(Pair(cursor, fillerMat)) + blueprint.add(Pair(cursor, fillerMat)) var buildIterationsWidth = buildWidth.value / 2 var evenCursor = relativeDirection(cursor, 1, 2) var isOdd = false @@ -1100,32 +1112,33 @@ object HighwayTools : Module() { isOdd = true buildIterationsWidth++ } else { - blockOffsets.add(Pair(evenCursor, fillerMat)) + blueprint.add(Pair(evenCursor, fillerMat)) } for (i in 1 until clearHeight.value + 2) { for (j in 1 until buildIterationsWidth) { if (i > 1) { - blockOffsets.add(Pair(relativeDirection(cursor, j, -2), Blocks.AIR)) - if (isOdd) blockOffsets.add(Pair(relativeDirection(cursor, j, 2), Blocks.AIR)) - else blockOffsets.add(Pair(relativeDirection(evenCursor, j, 2), Blocks.AIR)) + if (cornerBlock.value && i == 2 && j == buildIterationsWidth - 1) continue + blueprint.add(Pair(relativeDirection(cursor, j, -2), Blocks.AIR)) + if (isOdd) blueprint.add(Pair(relativeDirection(cursor, j, 2), Blocks.AIR)) + else blueprint.add(Pair(relativeDirection(evenCursor, j, 2), Blocks.AIR)) if (buildDirectionSaved.isDiagonal) { - blockOffsets.add(Pair(relativeDirection(cursor, j, -3), Blocks.AIR)) - if (isOdd) blockOffsets.add(Pair(relativeDirection(cursor, j, 3), Blocks.AIR)) - else blockOffsets.add(Pair(relativeDirection(evenCursor, j, 3), Blocks.AIR)) + blueprint.add(Pair(relativeDirection(cursor, j, -3), Blocks.AIR)) + if (isOdd) blueprint.add(Pair(relativeDirection(cursor, j, 3), Blocks.AIR)) + else blueprint.add(Pair(relativeDirection(evenCursor, j, 3), Blocks.AIR)) } } } cursor = cursor.up() evenCursor = evenCursor.up() if (clearSpace.value && i < clearHeight.value + 1) { - blockOffsets.add(Pair(cursor, Blocks.AIR)) - if (!isOdd) blockOffsets.add(Pair(evenCursor, Blocks.AIR)) + blueprint.add(Pair(cursor, Blocks.AIR)) + if (!isOdd) blueprint.add(Pair(evenCursor, Blocks.AIR)) } } } Mode.FLAT -> { for (bp in getBlockPositionsInArea(cursor.north(buildWidth.value).west(buildWidth.value), cursor.south(buildWidth.value).east(buildWidth.value))) { - blockOffsets.add(Pair(bp, material)) + blueprint.add(Pair(bp, material)) } } null -> { @@ -1207,6 +1220,15 @@ object HighwayTools : Module() { PLACED(ColorHolder(53, 222, 66)) } + class BlockTaskComparator { + companion object : Comparator { + override fun compare(a: BlockTask, b: BlockTask): Int = when { + a.taskState.ordinal != b.taskState.ordinal -> a.taskState.ordinal - b.taskState.ordinal + else -> getDistance(mc.player.positionVector, a.blockPos.toVec3d()).toInt() - getDistance(mc.player.positionVector, b.blockPos.toVec3d()).toInt() + } + } + } + private enum class DebugMessages { OFF, IMPORTANT, diff --git a/src/main/java/me/zeroeightsix/kami/process/HighwayToolsProcess.kt b/src/main/java/me/zeroeightsix/kami/process/HighwayToolsProcess.kt index 2c9ab2fc05..f4eea8b915 100644 --- a/src/main/java/me/zeroeightsix/kami/process/HighwayToolsProcess.kt +++ b/src/main/java/me/zeroeightsix/kami/process/HighwayToolsProcess.kt @@ -25,8 +25,8 @@ object HighwayToolsProcess : IBaritoneProcess { override fun displayName0(): String { val ht = HighwayTools - val processName = if (ht.blockQueue.size > 0 && !ht.pathing) { - ht.blockQueue.peek().toString() + val processName = if (ht.pendingTasks.size > 0 && !ht.pathing) { + ht.pendingTasks.peek().toString() } else if (ht.pathing) { "Moving to Position: (${ht.getNextWalkableBlock().asString()})" } else { From d2120ed783f5847535a267ec916c6fb639dad657 Mon Sep 17 00:00:00 2001 From: Christian Date: Fri, 27 Nov 2020 05:41:51 +0100 Subject: [PATCH 082/390] Bridging and command fixes Added bridging as problem solving action --- .../command/commands/HighwayToolsCommand.kt | 8 +++--- .../kami/module/modules/misc/HighwayTools.kt | 28 ++++++++++++------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/command/commands/HighwayToolsCommand.kt b/src/main/java/me/zeroeightsix/kami/command/commands/HighwayToolsCommand.kt index 13986effa5..0faa6ab623 100644 --- a/src/main/java/me/zeroeightsix/kami/command/commands/HighwayToolsCommand.kt +++ b/src/main/java/me/zeroeightsix/kami/command/commands/HighwayToolsCommand.kt @@ -45,7 +45,7 @@ class HighwayToolsCommand : Command("highwaytools", ChunkBuilder() } SubCommands.IGNORE_ADD -> { - val block = Block.getBlockFromName(args[1].toString()) + val block = Block.getBlockFromName(args[2].toString()) if (block != null) { val added = HighwayTools.ignoreBlocks.add(block) @@ -57,12 +57,12 @@ class HighwayToolsCommand : Command("highwaytools", ChunkBuilder() MessageSendHelper.sendChatMessage("&7${block.localizedName}&r is already ignored.") } } else { - MessageSendHelper.sendChatMessage("&7${args[1]}&r is not a valid block.") + MessageSendHelper.sendChatMessage("&7${args[2]}&r is not a valid block.") } } SubCommands.IGNORE_DEL -> { - val block = Block.getBlockFromName(args[1].toString()) + val block = Block.getBlockFromName(args[2].toString()) if (block != null) { val removed = HighwayTools.ignoreBlocks.remove(block) @@ -73,7 +73,7 @@ class HighwayToolsCommand : Command("highwaytools", ChunkBuilder() MessageSendHelper.sendChatMessage("&7${block.localizedName}&r is not yet ignored.") } } else { - MessageSendHelper.sendChatMessage("&7${args[1]}&r is not a valid block.") + MessageSendHelper.sendChatMessage("&7${args[2]}&r is not a valid block.") } } diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 1022487a7d..b87ba5022a 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -11,6 +11,7 @@ import me.zeroeightsix.kami.util.BaritoneUtils import me.zeroeightsix.kami.util.BlockUtils import me.zeroeightsix.kami.util.InventoryUtils import me.zeroeightsix.kami.util.color.ColorHolder +import me.zeroeightsix.kami.util.combat.SurroundUtils import me.zeroeightsix.kami.util.event.listener import me.zeroeightsix.kami.util.graphics.ESPRenderer import me.zeroeightsix.kami.util.math.CoordinateConverter.asString @@ -197,7 +198,7 @@ object HighwayTools : Module() { if (getDistance(mc.player.positionVector, taskDistance.toVec3d()) < maxReach.value ) { if (!isDone()) { if (!BaritoneUtils.paused && !AutoObsidian.isActive() && !AutoEat.eating) { - if (!pathing) adjustPlayerPosition() + if (!pathing) adjustPlayerPosition(false) val currentFood = mc.player.foodStats.foodLevel if (currentFood != prevFood) { if (currentFood < prevFood) foodLoss++ @@ -241,6 +242,8 @@ object HighwayTools : Module() { renderer.clear() renderer.aFilled = if (filled.value) aFilled.value else 0 renderer.aOutline = if (outline.value) aOutline.value else 0 +// renderer.add(currentBlockPos, ColorHolder(255, 255, 255)) +// renderer.add(getNextWalkableBlock(), ColorHolder(0, 0, 0)) for (blockTask in pendingTasks) { if (blockTask.taskState == TaskState.DONE) continue renderer.add(mc.world.getBlockState(blockTask.blockPos).getSelectedBoundingBox(mc.world, blockTask.blockPos), blockTask.taskState.color) @@ -727,7 +730,7 @@ object HighwayTools : Module() { } } if (directHits.size == 0) { - if (emergencyHits.size > 0 && stuckManager.stuckLevel.ordinal > 0) { + if (emergencyHits.size > 0 && stuckManager.stuckLevel.ordinal > 0 && (blockTask.taskState == TaskState.LIQUID_SOURCE || blockTask.taskState == TaskState.LIQUID_FLOW)) { var rayTrace = emergencyHits[0] var shortestRT = 99.0 for (rt in emergencyHits) { @@ -806,16 +809,13 @@ object HighwayTools : Module() { return pendingTasks.any { it.blockPos == blockPos && it.block == material } } - private fun adjustPlayerPosition() { - val vec = Vec3d(roundToCenter(mc.player.posX), mc.player.posY, roundToCenter(mc.player.posZ)).subtract(mc.player.positionVector) + private fun adjustPlayerPosition(bridge: Boolean) { + var vec = Vec3d(getNextWalkableBlock()).add(0.5, 0.5, 0.5).subtract(mc.player.positionVector) + if (bridge) vec = vec.add(Vec3d(buildDirectionSaved.directionVec).scale(0.51)) mc.player.motionX = MathHelper.clamp(vec.x / 2.0, -0.2, 0.2) mc.player.motionZ = MathHelper.clamp(vec.z / 2.0, -0.2, 0.2) } - private fun roundToCenter(doubleIn: Double): Double { - return round(doubleIn + 0.5) - 0.5 - } - private fun getQueue(): List { val message: MutableList = mutableListOf() message.add("QUEUE:") @@ -1162,6 +1162,7 @@ object HighwayTools : Module() { } when { stuckValue < 100 -> { + if (!pathing) adjustPlayerPosition(true) if (blockTask.taskState != TaskState.BREAKING) { shuffleTasks() if (debugMessages.value == DebugMessages.ALL) sendChatMessage("$chatName Shuffled tasks $stuckValue") @@ -1169,16 +1170,22 @@ object HighwayTools : Module() { } stuckValue in 100..200 -> { stuckLevel = StuckLevel.MINOR + if (!pathing) adjustPlayerPosition(true) shuffleTasks() +// shuffleTasks() // Jump etc? } stuckValue in 200..500 -> { stuckLevel = StuckLevel.MODERATE - refreshData() - if (debugMessages.value != DebugMessages.OFF) sendChatMessage("$chatName Refreshing data") + if (!pathing) adjustPlayerPosition(true) + shuffleTasks() +// refreshData() +// if (debugMessages.value != DebugMessages.OFF) sendChatMessage("$chatName Refreshing data") } stuckValue > 500 -> { stuckLevel = StuckLevel.MAYOR + if (!pathing) adjustPlayerPosition(true) + shuffleTasks() // reset() // disable() // enable() @@ -1224,6 +1231,7 @@ object HighwayTools : Module() { companion object : Comparator { override fun compare(a: BlockTask, b: BlockTask): Int = when { a.taskState.ordinal != b.taskState.ordinal -> a.taskState.ordinal - b.taskState.ordinal + a.taskState.ordinal == b.taskState.ordinal && stuckManager.stuckLevel != StuckLevel.NONE -> a.taskState.ordinal - b.taskState.ordinal else -> getDistance(mc.player.positionVector, a.blockPos.toVec3d()).toInt() - getDistance(mc.player.positionVector, b.blockPos.toVec3d()).toInt() } } From 715aff32a11eae43955ee58c93824455c5750926 Mon Sep 17 00:00:00 2001 From: Christian Date: Fri, 27 Nov 2020 06:04:23 +0100 Subject: [PATCH 083/390] Smol fix --- .../me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index b87ba5022a..bf426b45ba 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -1162,7 +1162,7 @@ object HighwayTools : Module() { } when { stuckValue < 100 -> { - if (!pathing) adjustPlayerPosition(true) +// if (!pathing) adjustPlayerPosition(true) if (blockTask.taskState != TaskState.BREAKING) { shuffleTasks() if (debugMessages.value == DebugMessages.ALL) sendChatMessage("$chatName Shuffled tasks $stuckValue") From 9239e9702dda9eae7e4534422350926de5542103 Mon Sep 17 00:00:00 2001 From: Christian Date: Sun, 29 Nov 2020 20:03:21 +0100 Subject: [PATCH 084/390] Diagonal fix try --- .../me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index bf426b45ba..7f8651895a 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -811,7 +811,10 @@ object HighwayTools : Module() { private fun adjustPlayerPosition(bridge: Boolean) { var vec = Vec3d(getNextWalkableBlock()).add(0.5, 0.5, 0.5).subtract(mc.player.positionVector) - if (bridge) vec = vec.add(Vec3d(buildDirectionSaved.directionVec).scale(0.51)) + when { + bridge && !buildDirectionSaved.isDiagonal -> vec = vec.add(Vec3d(buildDirectionSaved.directionVec).scale(0.51)) + bridge && buildDirectionSaved.isDiagonal -> vec = vec.add(Vec3d(buildDirectionSaved.directionVec).scale(0.525)) + } mc.player.motionX = MathHelper.clamp(vec.x / 2.0, -0.2, 0.2) mc.player.motionZ = MathHelper.clamp(vec.z / 2.0, -0.2, 0.2) } From a5e32c618997b3f6512add5a8e59f36af0374657 Mon Sep 17 00:00:00 2001 From: theredstoner Date: Tue, 8 Dec 2020 18:16:05 -0700 Subject: [PATCH 085/390] Fallback to using obsidian to fill in lava If we are out of fillermaterial, fallback to using obsidian. This is useful for when using inventory manager which automatically throws all netherrack on the ground. --- .../zeroeightsix/kami/module/modules/misc/HighwayTools.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 7f8651895a..3a39a00636 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -332,7 +332,7 @@ object HighwayTools : Module() { } is BlockLiquid -> { var filler = fillerMat - if (isInsideBuild(blockTask.blockPos)) filler = material + if (isInsideBuild(blockTask.blockPos) || fillerMatLeft == 0) filler = material if (mc.world.getBlockState(blockTask.blockPos).getValue(BlockLiquid.LEVEL) != 0) { updateTask(blockTask, TaskState.LIQUID_FLOW) updateTask(blockTask, filler) @@ -399,7 +399,7 @@ object HighwayTools : Module() { } is BlockLiquid -> { var filler = fillerMat - if (isInsideBuild(blockTask.blockPos)) filler = material + if (isInsideBuild(blockTask.blockPos) || fillerMatLeft == 0) filler = material if (mc.world.getBlockState(blockTask.blockPos).getValue(BlockLiquid.LEVEL) != 0) { updateTask(blockTask, TaskState.LIQUID_FLOW) updateTask(blockTask, filler) @@ -480,7 +480,7 @@ object HighwayTools : Module() { when (val block = mc.world.getBlockState(blockPos).block) { is BlockLiquid -> { var filler = fillerMat - if (isInsideBuild(blockPos)) filler = material + if (isInsideBuild(blockPos) || fillerMatLeft == 0) filler = material when (mc.world.getBlockState(blockPos).getValue(BlockLiquid.LEVEL) != 0) { true -> addTask(blockPos, TaskState.LIQUID_FLOW, filler) false -> addTask(blockPos, TaskState.LIQUID_SOURCE, filler) From c7f4c778aeeb3ad5393cf5ac9202165a5cc9df1f Mon Sep 17 00:00:00 2001 From: natan <66911017+natan515@users.noreply.github.com> Date: Thu, 10 Dec 2020 18:46:18 +0200 Subject: [PATCH 086/390] Just update the version --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 9088c690dd..6703982720 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ org.gradle.jvmargs=-Xmx3G modGroup=me.zeroeightsix -modVersion=1.1.7-beta +modVersion=1.12.01 modBaseName=kamiblue forgeVersion=1.12.2-14.23.5.2847 mcpVersion=stable_39 From 259688ef45b22c3ebbc5df1bc903bf91ef382202 Mon Sep 17 00:00:00 2001 From: theredstoner Date: Fri, 11 Dec 2020 19:21:29 -0700 Subject: [PATCH 087/390] Allow toggling inventory manager automatically Add a toggle to control inventory manager --- .../kami/module/modules/misc/HighwayTools.kt | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 3a39a00636..fcee44c660 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -4,6 +4,7 @@ import me.zeroeightsix.kami.event.events.RenderWorldEvent import me.zeroeightsix.kami.event.events.SafeTickEvent import me.zeroeightsix.kami.module.Module import me.zeroeightsix.kami.module.modules.player.AutoEat +import me.zeroeightsix.kami.module.modules.player.InventoryManager import me.zeroeightsix.kami.module.modules.player.NoBreakAnimation import me.zeroeightsix.kami.process.HighwayToolsProcess import me.zeroeightsix.kami.setting.Settings @@ -11,7 +12,6 @@ import me.zeroeightsix.kami.util.BaritoneUtils import me.zeroeightsix.kami.util.BlockUtils import me.zeroeightsix.kami.util.InventoryUtils import me.zeroeightsix.kami.util.color.ColorHolder -import me.zeroeightsix.kami.util.combat.SurroundUtils import me.zeroeightsix.kami.util.event.listener import me.zeroeightsix.kami.util.graphics.ESPRenderer import me.zeroeightsix.kami.util.math.CoordinateConverter.asString @@ -40,7 +40,6 @@ import net.minecraftforge.fml.common.gameevent.TickEvent import java.util.* import kotlin.collections.ArrayList import kotlin.math.abs -import kotlin.math.round import kotlin.math.sqrt /** @@ -75,6 +74,7 @@ object HighwayTools : Module() { private val interacting = register(Settings.enumBuilder(InteractMode::class.java, "InteractMode").withValue(InteractMode.SPOOF).withVisibility { page.value == Page.BEHAVIOR }) private val illegalPlacements = register(Settings.booleanBuilder("IllegalPlacements").withValue(true).withVisibility { page.value == Page.BEHAVIOR }) private val maxReach = register(Settings.floatBuilder("MaxReach").withValue(4.0F).withRange(1.0f, 5.0f).withStep(0.1f).withVisibility { page.value == Page.BEHAVIOR }) + private val toggleInventoryManager = register(Settings.booleanBuilder("ToggleInventoryManager").withValue(true).withVisibility { page.value == Page.BEHAVIOR }) // config private val info = register(Settings.booleanBuilder("ShowInfo").withValue(true).withVisibility { page.value == Page.CONFIG }) @@ -132,6 +132,11 @@ object HighwayTools : Module() { return } + /* Turn on inventory manager if the users wants us to control it */ + if(toggleInventoryManager.value && InventoryManager.isDisabled) { + InventoryManager.enable() + } + startingBlockPos = mc.player.positionVector.toBlockPos() currentBlockPos = startingBlockPos playerHotbarSlot = mc.player.inventory.currentItem @@ -174,6 +179,12 @@ object HighwayTools : Module() { if (process != null && process.isPresent && process.get() == HighwayToolsProcess) process.get().onLostControl() } + + /* Turn off inventory manager if the users wants us to control it */ + if(toggleInventoryManager.value && InventoryManager.isEnabled) { + InventoryManager.disable() + } + printDisable() } From 6acbda6d691286ec461a9e5e3bfbd5d4c0346be6 Mon Sep 17 00:00:00 2001 From: theredstoner Date: Fri, 11 Dec 2020 21:02:02 -0700 Subject: [PATCH 088/390] Fix AutoObsidian not checking the hotbar Fix autoObsidian not searching the hotbar in some cases. This was causing auto-obsidian to incorrectly mine ender chests even though there were some stacks of obsidian in the hotbar. Also changed the obsidian and enderchest itemIds to an enum. --- .../kami/module/modules/misc/AutoObsidian.kt | 40 ++++++++++++------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt index 232d7bdddd..de229d6c20 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt @@ -20,7 +20,9 @@ import net.minecraft.client.gui.inventory.GuiShulkerBox import net.minecraft.init.Blocks import net.minecraft.init.SoundEvents import net.minecraft.inventory.ClickType +import net.minecraft.item.Item import net.minecraft.item.Item.getIdFromItem +import net.minecraft.item.ItemStack import net.minecraft.network.play.client.CPacketPlayer import net.minecraft.network.play.client.CPacketPlayerDigging import net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock @@ -64,6 +66,10 @@ object AutoObsidian : Module() { enum class AutoCenterMode { OFF, TP, MOTION } + private enum class ItemID(val id: Int) { + OBSIDIAN(49), + ENDERCHEST(130) + } var pathing = false var goal: BlockPos? = null @@ -125,7 +131,7 @@ object AutoObsidian : Module() { State.PLACING -> placeEnderChest(placingPos) State.PRE_MINING -> mineBlock(placingPos, true) State.MINING -> mineBlock(placingPos, false) - State.COLLECTING -> collectDroppedItem(49) + State.COLLECTING -> collectDroppedItem(ItemID.OBSIDIAN.id) State.DONE -> { if (!autoRefill.value) { sendChatMessage("$chatName Reached target stacks, disabling.") @@ -176,16 +182,16 @@ object AutoObsidian : Module() { /* Updates ender chest and obsidian counts before placing and mining ender chest */ if (state == State.SEARCHING) { - enderChestCount = InventoryUtils.countItem(0, 35, 130) + enderChestCount = InventoryUtils.countItemAll(ItemID.ENDERCHEST.id) obsidianCount = countObsidian() } /* Updates main state */ - val placedEnderChest = enderChestCount - InventoryUtils.countItem(0, 35, 130) + val placedEnderChest = enderChestCount - InventoryUtils.countItemAll(ItemID.ENDERCHEST.id) val targetEnderChest = (targetStacks.value * 64 - obsidianCount) / 8 state = when { - state == State.DONE && autoRefill.value && InventoryUtils.countItem(0, 35, 49) <= threshold.value -> State.SEARCHING - state == State.COLLECTING && getDroppedItem(49, 16.0f) == null -> State.DONE + state == State.DONE && autoRefill.value && InventoryUtils.countItemAll(ItemID.OBSIDIAN.id) <= threshold.value -> State.SEARCHING + state == State.COLLECTING && getDroppedItem(ItemID.OBSIDIAN.id, 16.0f) == null -> State.DONE state != State.DONE && mc.world.isAirBlock(placingPos) && placedEnderChest >= targetEnderChest -> State.COLLECTING state == State.MINING && mc.world.isAirBlock(placingPos) -> State.PLACING state == State.PLACING && !mc.world.isAirBlock(placingPos) -> State.PRE_MINING @@ -196,16 +202,16 @@ object AutoObsidian : Module() { /* Updates searching state */ if (state == State.SEARCHING && searchingState != SearchingState.DONE) { searchingState = when { - searchingState == SearchingState.PLACING && InventoryUtils.countItem(0, 35, 130) > 0 -> SearchingState.DONE + searchingState == SearchingState.PLACING && InventoryUtils.countItemAll(ItemID.ENDERCHEST.id) > 0 -> SearchingState.DONE searchingState == SearchingState.COLLECTING && getDroppedItem(shulkerBoxId, 16.0f) == null -> SearchingState.DONE searchingState == SearchingState.MINING && mc.world.isAirBlock(placingPos) -> { - if (InventoryUtils.countItem(0, 35, 130) > 0) { + if (InventoryUtils.countItemAll(ItemID.ENDERCHEST.id) > 0) { SearchingState.COLLECTING } else { /* In case if the shulker wasn't placed due to server lag */ SearchingState.PLACING } } - searchingState == SearchingState.OPENING && (InventoryUtils.countItem(0, 35, 130) >= 64 || InventoryUtils.getSlots(0, 35, 0) == null) -> SearchingState.PRE_MINING + searchingState == SearchingState.OPENING && (InventoryUtils.countItemAll(ItemID.ENDERCHEST.id) >= 64 || InventoryUtils.getSlots(0, 35, 0) == null) -> SearchingState.PRE_MINING searchingState == SearchingState.PLACING && !mc.world.isAirBlock(placingPos) -> { if (mc.world.getBlockState(placingPos).block is BlockShulkerBox) { SearchingState.OPENING @@ -219,8 +225,9 @@ object AutoObsidian : Module() { } + /* Return the obsidian count, rounded up to the nearest 8th */ private fun countObsidian(): Int { - return ceil(InventoryUtils.countItem(0, 35, 49).toDouble() / 8.0).toInt() * 8 + return ceil(InventoryUtils.countItemAll(ItemID.OBSIDIAN.id).toDouble() / 8.0).toInt() * 8 } private fun setPlacingPos() { @@ -273,10 +280,12 @@ object AutoObsidian : Module() { } private fun placeEnderChest(pos: BlockPos) { - if (InventoryUtils.getSlotsHotbar(130) == null && InventoryUtils.getSlotsNoHotbar(130) != null) { - InventoryUtils.moveToHotbar(130, 278) + /* Case where we need to move ender chests into the hotbar */ + if (InventoryUtils.getSlotsHotbar(ItemID.ENDERCHEST.id) == null && InventoryUtils.getSlotsNoHotbar(ItemID.ENDERCHEST.id) != null) { + InventoryUtils.moveToHotbar(ItemID.ENDERCHEST.id, 278) return - } else if (InventoryUtils.getSlots(0, 35, 130) == null) { + } else if (InventoryUtils.getSlots(0, 35, ItemID.ENDERCHEST.id) == null) { + /* Case where we are out of ender chests */ if (searchShulker.value) { state = State.SEARCHING } else { @@ -286,7 +295,8 @@ object AutoObsidian : Module() { return } } - InventoryUtils.swapSlotToItem(130) + /* Else, we already have enderchests in the hostbar */ + InventoryUtils.swapSlotToItem(ItemID.ENDERCHEST.id) placeBlock(pos) } @@ -342,7 +352,7 @@ object AutoObsidian : Module() { val currentContainer = mc.player.openContainer var enderChestSlot = -1 for (i in 0..26) { - if (getIdFromItem(currentContainer.inventory[i].item) == 130) { + if (getIdFromItem(currentContainer.inventory[i].item) == ItemID.ENDERCHEST.id) { enderChestSlot = i } } @@ -414,7 +424,7 @@ object AutoObsidian : Module() { private fun mineBlock(pos: BlockPos, pre: Boolean): Boolean { if (pre) { if (InventoryUtils.getSlotsHotbar(278) == null && InventoryUtils.getSlotsNoHotbar(278) != null) { - InventoryUtils.moveToHotbar(278, 130) + InventoryUtils.moveToHotbar(278, ItemID.ENDERCHEST.id) return false } else if (InventoryUtils.getSlots(0, 35, 278) == null) { sendChatMessage("No pickaxe was found in inventory.") From 070b51f69e6ae08a0b5156eaceeb6186d73c18ac Mon Sep 17 00:00:00 2001 From: Christian Date: Sun, 13 Dec 2020 04:03:42 +0100 Subject: [PATCH 089/390] Syntax fixes --- .../me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 3a39a00636..0e1df3731b 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -11,7 +11,6 @@ import me.zeroeightsix.kami.util.BaritoneUtils import me.zeroeightsix.kami.util.BlockUtils import me.zeroeightsix.kami.util.InventoryUtils import me.zeroeightsix.kami.util.color.ColorHolder -import me.zeroeightsix.kami.util.combat.SurroundUtils import me.zeroeightsix.kami.util.event.listener import me.zeroeightsix.kami.util.graphics.ESPRenderer import me.zeroeightsix.kami.util.math.CoordinateConverter.asString @@ -40,7 +39,6 @@ import net.minecraftforge.fml.common.gameevent.TickEvent import java.util.* import kotlin.collections.ArrayList import kotlin.math.abs -import kotlin.math.round import kotlin.math.sqrt /** @@ -106,7 +104,7 @@ object HighwayTools : Module() { private var baritoneSettingRenderGoal = false // runtime vars - val pendingTasks = PriorityQueue(BlockTaskComparator) + val pendingTasks = PriorityQueue(BlockTaskComparator) private val doneTasks = ArrayList() private val blueprint = ArrayList>() private var waitTicks = 0 From 3cd246202b6cf9236c5d7be0780953d40d872aba Mon Sep 17 00:00:00 2001 From: Christian Date: Sun, 13 Dec 2020 05:14:12 +0100 Subject: [PATCH 090/390] Stability improvements and format changes --- .../zeroeightsix/kami/gui/kami/KamiGUI.java | 2 +- .../kami/module/modules/misc/AutoObsidian.kt | 28 +++++++++---------- .../kami/module/modules/misc/HighwayTools.kt | 15 +++++----- 3 files changed, 21 insertions(+), 24 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/gui/kami/KamiGUI.java b/src/main/java/me/zeroeightsix/kami/gui/kami/KamiGUI.java index 4efb0def3e..145ce57ec2 100644 --- a/src/main/java/me/zeroeightsix/kami/gui/kami/KamiGUI.java +++ b/src/main/java/me/zeroeightsix/kami/gui/kami/KamiGUI.java @@ -125,7 +125,7 @@ public void initializeGUI() { Stretcherlayout stretcherlayout = new Stretcherlayout(1); stretcherlayout.setComponentOffsetWidth(0); Scrollpane scrollpane = new Scrollpane(getTheme(), stretcherlayout, 300, 260); - scrollpane.setMaximumHeight(180); + scrollpane.setMaximumHeight(500); categoryScrollpaneHashMap.put(moduleCategory, new Pair<>(scrollpane, new SettingsPanel(getTheme(), null))); } diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt index de229d6c20..f8205591ff 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt @@ -20,9 +20,7 @@ import net.minecraft.client.gui.inventory.GuiShulkerBox import net.minecraft.init.Blocks import net.minecraft.init.SoundEvents import net.minecraft.inventory.ClickType -import net.minecraft.item.Item import net.minecraft.item.Item.getIdFromItem -import net.minecraft.item.ItemStack import net.minecraft.network.play.client.CPacketPlayer import net.minecraft.network.play.client.CPacketPlayerDigging import net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock @@ -49,7 +47,7 @@ object AutoObsidian : Module() { private val delayTicks = register(Settings.integerBuilder("DelayTicks").withValue(5).withRange(0, 10)) private val interacting = register(Settings.enumBuilder(InteractMode::class.java).withName("InteractMode").withValue(InteractMode.SPOOF)) private val autoCenter = register(Settings.enumBuilder(AutoCenterMode::class.java).withName("AutoCenter").withValue(AutoCenterMode.MOTION)) - private val maxReach = register(Settings.floatBuilder("MaxReach").withMinimum(2.0F).withValue(5.4F)) + private val maxReach = register(Settings.floatBuilder("MaxReach").withValue(4.5F).withRange(1.0f, 6.0f).withStep(0.1f)) enum class State { SEARCHING, PLACING, PRE_MINING, MINING, COLLECTING, DONE @@ -68,7 +66,7 @@ object AutoObsidian : Module() { } private enum class ItemID(val id: Int) { OBSIDIAN(49), - ENDERCHEST(130) + ENDER_CHEST(130) } var pathing = false @@ -182,12 +180,12 @@ object AutoObsidian : Module() { /* Updates ender chest and obsidian counts before placing and mining ender chest */ if (state == State.SEARCHING) { - enderChestCount = InventoryUtils.countItemAll(ItemID.ENDERCHEST.id) + enderChestCount = InventoryUtils.countItemAll(ItemID.ENDER_CHEST.id) obsidianCount = countObsidian() } /* Updates main state */ - val placedEnderChest = enderChestCount - InventoryUtils.countItemAll(ItemID.ENDERCHEST.id) + val placedEnderChest = enderChestCount - InventoryUtils.countItemAll(ItemID.ENDER_CHEST.id) val targetEnderChest = (targetStacks.value * 64 - obsidianCount) / 8 state = when { state == State.DONE && autoRefill.value && InventoryUtils.countItemAll(ItemID.OBSIDIAN.id) <= threshold.value -> State.SEARCHING @@ -202,16 +200,16 @@ object AutoObsidian : Module() { /* Updates searching state */ if (state == State.SEARCHING && searchingState != SearchingState.DONE) { searchingState = when { - searchingState == SearchingState.PLACING && InventoryUtils.countItemAll(ItemID.ENDERCHEST.id) > 0 -> SearchingState.DONE + searchingState == SearchingState.PLACING && InventoryUtils.countItemAll(ItemID.ENDER_CHEST.id) > 0 -> SearchingState.DONE searchingState == SearchingState.COLLECTING && getDroppedItem(shulkerBoxId, 16.0f) == null -> SearchingState.DONE searchingState == SearchingState.MINING && mc.world.isAirBlock(placingPos) -> { - if (InventoryUtils.countItemAll(ItemID.ENDERCHEST.id) > 0) { + if (InventoryUtils.countItemAll(ItemID.ENDER_CHEST.id) > 0) { SearchingState.COLLECTING } else { /* In case if the shulker wasn't placed due to server lag */ SearchingState.PLACING } } - searchingState == SearchingState.OPENING && (InventoryUtils.countItemAll(ItemID.ENDERCHEST.id) >= 64 || InventoryUtils.getSlots(0, 35, 0) == null) -> SearchingState.PRE_MINING + searchingState == SearchingState.OPENING && (InventoryUtils.countItemAll(ItemID.ENDER_CHEST.id) >= 64 || InventoryUtils.getSlots(0, 35, 0) == null) -> SearchingState.PRE_MINING searchingState == SearchingState.PLACING && !mc.world.isAirBlock(placingPos) -> { if (mc.world.getBlockState(placingPos).block is BlockShulkerBox) { SearchingState.OPENING @@ -281,10 +279,10 @@ object AutoObsidian : Module() { private fun placeEnderChest(pos: BlockPos) { /* Case where we need to move ender chests into the hotbar */ - if (InventoryUtils.getSlotsHotbar(ItemID.ENDERCHEST.id) == null && InventoryUtils.getSlotsNoHotbar(ItemID.ENDERCHEST.id) != null) { - InventoryUtils.moveToHotbar(ItemID.ENDERCHEST.id, 278) + if (InventoryUtils.getSlotsHotbar(ItemID.ENDER_CHEST.id) == null && InventoryUtils.getSlotsNoHotbar(ItemID.ENDER_CHEST.id) != null) { + InventoryUtils.moveToHotbar(ItemID.ENDER_CHEST.id, 278) return - } else if (InventoryUtils.getSlots(0, 35, ItemID.ENDERCHEST.id) == null) { + } else if (InventoryUtils.getSlots(0, 35, ItemID.ENDER_CHEST.id) == null) { /* Case where we are out of ender chests */ if (searchShulker.value) { state = State.SEARCHING @@ -296,7 +294,7 @@ object AutoObsidian : Module() { } } /* Else, we already have enderchests in the hostbar */ - InventoryUtils.swapSlotToItem(ItemID.ENDERCHEST.id) + InventoryUtils.swapSlotToItem(ItemID.ENDER_CHEST.id) placeBlock(pos) } @@ -352,7 +350,7 @@ object AutoObsidian : Module() { val currentContainer = mc.player.openContainer var enderChestSlot = -1 for (i in 0..26) { - if (getIdFromItem(currentContainer.inventory[i].item) == ItemID.ENDERCHEST.id) { + if (getIdFromItem(currentContainer.inventory[i].item) == ItemID.ENDER_CHEST.id) { enderChestSlot = i } } @@ -424,7 +422,7 @@ object AutoObsidian : Module() { private fun mineBlock(pos: BlockPos, pre: Boolean): Boolean { if (pre) { if (InventoryUtils.getSlotsHotbar(278) == null && InventoryUtils.getSlotsNoHotbar(278) != null) { - InventoryUtils.moveToHotbar(278, ItemID.ENDERCHEST.id) + InventoryUtils.moveToHotbar(278, ItemID.ENDER_CHEST.id) return false } else if (InventoryUtils.getSlots(0, 35, 278) == null) { sendChatMessage("No pickaxe was found in inventory.") diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index f2380d3fe4..300895e715 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -72,9 +72,9 @@ object HighwayTools : Module() { private val tickDelayPlace = register(Settings.integerBuilder("TickDelayPlace").withValue(3).withRange(0, 16).withStep(1).withVisibility { page.value == Page.BEHAVIOR }) private val tickDelayBreak = register(Settings.integerBuilder("TickDelayBreak").withValue(0).withRange(0, 16).withStep(1).withVisibility { page.value == Page.BEHAVIOR }) private val interacting = register(Settings.enumBuilder(InteractMode::class.java, "InteractMode").withValue(InteractMode.SPOOF).withVisibility { page.value == Page.BEHAVIOR }) - private val illegalPlacements = register(Settings.booleanBuilder("IllegalPlacements").withValue(true).withVisibility { page.value == Page.BEHAVIOR }) - private val maxReach = register(Settings.floatBuilder("MaxReach").withValue(4.0F).withRange(1.0f, 5.0f).withStep(0.1f).withVisibility { page.value == Page.BEHAVIOR }) - private val toggleInventoryManager = register(Settings.booleanBuilder("ToggleInventoryManager").withValue(true).withVisibility { page.value == Page.BEHAVIOR }) + private val illegalPlacements = register(Settings.booleanBuilder("IllegalPlacements").withValue(false).withVisibility { page.value == Page.BEHAVIOR }) + private val maxReach = register(Settings.floatBuilder("MaxReach").withValue(4.5F).withRange(1.0f, 6.0f).withStep(0.1f).withVisibility { page.value == Page.BEHAVIOR }) + private val toggleInventoryManager = register(Settings.booleanBuilder("ToggleInvManager").withValue(true).withVisibility { page.value == Page.BEHAVIOR }) // config private val info = register(Settings.booleanBuilder("ShowInfo").withValue(true).withVisibility { page.value == Page.CONFIG }) @@ -656,6 +656,7 @@ object HighwayTools : Module() { if (directHits.size == 0) { stuckManager.increase(blockTask) + refreshData() if (stuckManager.stuckLevel == StuckLevel.NONE) doTask() return } @@ -1186,20 +1187,18 @@ object HighwayTools : Module() { stuckLevel = StuckLevel.MINOR if (!pathing) adjustPlayerPosition(true) shuffleTasks() -// shuffleTasks() // Jump etc? } stuckValue in 200..500 -> { stuckLevel = StuckLevel.MODERATE if (!pathing) adjustPlayerPosition(true) - shuffleTasks() -// refreshData() -// if (debugMessages.value != DebugMessages.OFF) sendChatMessage("$chatName Refreshing data") + refreshData() + if (debugMessages.value != DebugMessages.OFF) sendChatMessage("$chatName Refreshing data") } stuckValue > 500 -> { stuckLevel = StuckLevel.MAYOR if (!pathing) adjustPlayerPosition(true) - shuffleTasks() + refreshData() // reset() // disable() // enable() From 98aba420972a7355e0938338b90dd4ec6f49f722 Mon Sep 17 00:00:00 2001 From: theredstoner Date: Sun, 13 Dec 2020 22:17:21 -0700 Subject: [PATCH 091/390] Allow toggling Auto Obsidian automatically Allow turning on Auto Obsidian from highway tools. --- .../kami/module/modules/misc/HighwayTools.kt | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 300895e715..d1dd690e5b 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -39,6 +39,7 @@ import net.minecraft.util.math.* import net.minecraftforge.fml.common.gameevent.TickEvent import java.util.* import kotlin.collections.ArrayList +import kotlin.concurrent.thread import kotlin.math.abs import kotlin.math.sqrt @@ -75,6 +76,7 @@ object HighwayTools : Module() { private val illegalPlacements = register(Settings.booleanBuilder("IllegalPlacements").withValue(false).withVisibility { page.value == Page.BEHAVIOR }) private val maxReach = register(Settings.floatBuilder("MaxReach").withValue(4.5F).withRange(1.0f, 6.0f).withStep(0.1f).withVisibility { page.value == Page.BEHAVIOR }) private val toggleInventoryManager = register(Settings.booleanBuilder("ToggleInvManager").withValue(true).withVisibility { page.value == Page.BEHAVIOR }) + private val toggleAutoObsidian = register(Settings.booleanBuilder("ToggleAutoObsidian").withValue(true).withVisibility { page.value == Page.BEHAVIOR }) // config private val info = register(Settings.booleanBuilder("ShowInfo").withValue(true).withVisibility { page.value == Page.CONFIG }) @@ -137,6 +139,21 @@ object HighwayTools : Module() { InventoryManager.enable() } + /* Turn on Auto Obsidian if the user wants us to control it. */ + if(toggleAutoObsidian.value && AutoObsidian.isDisabled) { + /* If we have no obsidian, immediately turn on Auto Obsidian */ + if(InventoryUtils.countItemAll(49) == 0) { + AutoObsidian.enable() + } + else { + thread { + /* Wait 1 second because turning both on simultaneously is buggy */ + Thread.sleep(1000) + AutoObsidian.enable() + } + } + } + startingBlockPos = mc.player.positionVector.toBlockPos() currentBlockPos = startingBlockPos playerHotbarSlot = mc.player.inventory.currentItem @@ -185,6 +202,11 @@ object HighwayTools : Module() { InventoryManager.disable() } + /* Turn off auto obsidian if the user wants us to control it */ + if(toggleAutoObsidian.value && AutoObsidian.isEnabled) { + AutoObsidian.disable() + } + printDisable() } From 7b4fe63b947627f53248d18f747f87a8222a6b1b Mon Sep 17 00:00:00 2001 From: Christian Date: Mon, 14 Dec 2020 06:33:06 +0100 Subject: [PATCH 092/390] Change default tickdelay on 1 --- .../me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 300895e715..b0e9a697f1 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -70,7 +70,7 @@ object HighwayTools : Module() { val baritoneMode = register(Settings.booleanBuilder("AutoMode").withValue(true).withVisibility { page.value == Page.BEHAVIOR }) private val blocksPerTick = register(Settings.integerBuilder("BlocksPerTick").withValue(1).withRange(1, 10).withStep(1).withVisibility { page.value == Page.BEHAVIOR }) private val tickDelayPlace = register(Settings.integerBuilder("TickDelayPlace").withValue(3).withRange(0, 16).withStep(1).withVisibility { page.value == Page.BEHAVIOR }) - private val tickDelayBreak = register(Settings.integerBuilder("TickDelayBreak").withValue(0).withRange(0, 16).withStep(1).withVisibility { page.value == Page.BEHAVIOR }) + private val tickDelayBreak = register(Settings.integerBuilder("TickDelayBreak").withValue(1).withRange(0, 16).withStep(1).withVisibility { page.value == Page.BEHAVIOR }) private val interacting = register(Settings.enumBuilder(InteractMode::class.java, "InteractMode").withValue(InteractMode.SPOOF).withVisibility { page.value == Page.BEHAVIOR }) private val illegalPlacements = register(Settings.booleanBuilder("IllegalPlacements").withValue(false).withVisibility { page.value == Page.BEHAVIOR }) private val maxReach = register(Settings.floatBuilder("MaxReach").withValue(4.5F).withRange(1.0f, 6.0f).withStep(0.1f).withVisibility { page.value == Page.BEHAVIOR }) From fb0c35612564eef7266f940e971fc6417cd8374e Mon Sep 17 00:00:00 2001 From: Christian Date: Thu, 17 Dec 2020 00:02:12 +0100 Subject: [PATCH 093/390] Stuck detection --- .../kami/module/modules/misc/HighwayTools.kt | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index a0a39f15ae..28b18d7bfa 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -1199,7 +1199,7 @@ object HighwayTools : Module() { } when { stuckValue < 100 -> { -// if (!pathing) adjustPlayerPosition(true) +// if (!pathing && blockTask.taskState == TaskState.PLACE && !buildDirectionSaved.isDiagonal) adjustPlayerPosition(true) if (blockTask.taskState != TaskState.BREAKING) { shuffleTasks() if (debugMessages.value == DebugMessages.ALL) sendChatMessage("$chatName Shuffled tasks $stuckValue") @@ -1207,20 +1207,24 @@ object HighwayTools : Module() { } stuckValue in 100..200 -> { stuckLevel = StuckLevel.MINOR - if (!pathing) adjustPlayerPosition(true) - shuffleTasks() + if (!pathing && blockTask.taskState == TaskState.PLACE && !buildDirectionSaved.isDiagonal) adjustPlayerPosition(true) + if (blockTask.taskState != TaskState.BREAKING) { + shuffleTasks() + if (debugMessages.value == DebugMessages.ALL) sendChatMessage("$chatName Shuffled tasks $stuckValue") + } // Jump etc? } stuckValue in 200..500 -> { stuckLevel = StuckLevel.MODERATE - if (!pathing) adjustPlayerPosition(true) + if (!pathing && blockTask.taskState == TaskState.PLACE && !buildDirectionSaved.isDiagonal) adjustPlayerPosition(true) refreshData() if (debugMessages.value != DebugMessages.OFF) sendChatMessage("$chatName Refreshing data") } stuckValue > 500 -> { stuckLevel = StuckLevel.MAYOR - if (!pathing) adjustPlayerPosition(true) + if (!pathing && blockTask.taskState == TaskState.PLACE && !buildDirectionSaved.isDiagonal) adjustPlayerPosition(true) refreshData() + if (debugMessages.value != DebugMessages.OFF) sendChatMessage("$chatName Refreshing data") // reset() // disable() // enable() From cb11e46e53bcf330601504c2ff5d2e0f897e1984 Mon Sep 17 00:00:00 2001 From: theredstoner Date: Wed, 16 Dec 2020 19:48:01 -0700 Subject: [PATCH 094/390] Minor Optimization for AutoObsidian When searching a shulker break after the first Echest stack is found --- .../me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt index 03765fd17c..b7545f01a0 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt @@ -352,6 +352,7 @@ object AutoObsidian : Module() { for (i in 0..26) { if (getIdFromItem(currentContainer.inventory[i].item) == ItemID.ENDER_CHEST.id) { enderChestSlot = i + break } } if (enderChestSlot != -1) { From bb56fafd0482d87a98cc5d343e79f7c23609713b Mon Sep 17 00:00:00 2001 From: theredstoner Date: Wed, 16 Dec 2020 19:48:36 -0700 Subject: [PATCH 095/390] Fix breaking fire blocks Aim at the bottom of the fire block and break. This should not cause us to get stuck as we will cycle to other blocks if this one is not visible. --- .../kami/module/modules/misc/HighwayTools.kt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index ee488d4ccb..ba89aba381 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -35,6 +35,7 @@ import net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock import net.minecraft.util.EnumFacing import net.minecraft.util.EnumHand import net.minecraft.util.math.* +import net.minecraftforge.client.event.ColorHandlerEvent import net.minecraftforge.fml.common.gameevent.TickEvent import org.kamiblue.event.listener.listener import java.util.* @@ -525,6 +526,7 @@ object HighwayTools : Module() { when { block in ignoreBlocks -> addTask(blockPos, Blocks.AIR) block == Blocks.AIR -> addTask(blockPos, Blocks.AIR) + block == Blocks.FIRE -> addTask(blockPos, TaskState.BREAK, Blocks.FIRE) block != Blocks.AIR -> addTask(blockPos, TaskState.BREAK, Blocks.AIR) } } @@ -654,6 +656,14 @@ object HighwayTools : Module() { return } + /* For fire, we just need to mine the bottom of the block */ + if (blockTask.block == Blocks.FIRE) { + mc.connection!!.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, blockTask.blockPos, EnumFacing.DOWN)) + mc.connection!!.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, blockTask.blockPos, EnumFacing.DOWN)) + updateTask(blockTask, TaskState.DONE) + return + } + val directHits = mutableListOf() val bb = mc.world.getBlockState(blockTask.blockPos).getSelectedBoundingBox(mc.world, blockTask.blockPos) val playerEyeVec = mc.player.getPositionEyes(1f) From 05eb80a69e512980cf82edce5c1ad75db79a3cf9 Mon Sep 17 00:00:00 2001 From: theredstoner Date: Wed, 16 Dec 2020 20:05:57 -0700 Subject: [PATCH 096/390] Set Fire breaking state to breaking not done --- .../me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index ba89aba381..e182d0aa31 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -660,7 +660,7 @@ object HighwayTools : Module() { if (blockTask.block == Blocks.FIRE) { mc.connection!!.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, blockTask.blockPos, EnumFacing.DOWN)) mc.connection!!.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, blockTask.blockPos, EnumFacing.DOWN)) - updateTask(blockTask, TaskState.DONE) + updateTask(blockTask, TaskState.BREAKING) return } From e2c4934a6636d7da739dc07c9c8383e0f8594d51 Mon Sep 17 00:00:00 2001 From: theredstoner Date: Wed, 16 Dec 2020 21:29:47 -0700 Subject: [PATCH 097/390] Replace hardcoded int with enum in AutoObsidian Makes it a little bit easier to read --- .../kami/module/modules/misc/AutoObsidian.kt | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt index b7545f01a0..ec6c5c81b5 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt @@ -66,7 +66,8 @@ object AutoObsidian : Module() { } private enum class ItemID(val id: Int) { OBSIDIAN(49), - ENDER_CHEST(130) + ENDER_CHEST(130), + DIAMOND_PICKAXE(278) } var pathing = false @@ -280,7 +281,7 @@ object AutoObsidian : Module() { private fun placeEnderChest(pos: BlockPos) { /* Case where we need to move ender chests into the hotbar */ if (InventoryUtils.getSlotsHotbar(ItemID.ENDER_CHEST.id) == null && InventoryUtils.getSlotsNoHotbar(ItemID.ENDER_CHEST.id) != null) { - InventoryUtils.moveToHotbar(ItemID.ENDER_CHEST.id, 278) + InventoryUtils.moveToHotbar(ItemID.ENDER_CHEST.id, ItemID.DIAMOND_PICKAXE.id) return } else if (InventoryUtils.getSlots(0, 35, ItemID.ENDER_CHEST.id) == null) { /* Case where we are out of ender chests */ @@ -422,15 +423,15 @@ object AutoObsidian : Module() { private fun mineBlock(pos: BlockPos, pre: Boolean): Boolean { if (pre) { - if (InventoryUtils.getSlotsHotbar(278) == null && InventoryUtils.getSlotsNoHotbar(278) != null) { - InventoryUtils.moveToHotbar(278, ItemID.ENDER_CHEST.id) + if (InventoryUtils.getSlotsHotbar(ItemID.DIAMOND_PICKAXE.id) == null && InventoryUtils.getSlotsNoHotbar(ItemID.DIAMOND_PICKAXE.id) != null) { + InventoryUtils.moveToHotbar(ItemID.DIAMOND_PICKAXE.id, ItemID.ENDER_CHEST.id) return false - } else if (InventoryUtils.getSlots(0, 35, 278) == null) { + } else if (InventoryUtils.getSlots(0, 35, ItemID.DIAMOND_PICKAXE.id) == null) { sendChatMessage("No pickaxe was found in inventory.") mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) return false } - InventoryUtils.swapSlotToItem(278) + InventoryUtils.swapSlotToItem(ItemID.DIAMOND_PICKAXE.id) } var rayTrace = mc.world.rayTraceBlocks(mc.player.getPositionEyes(1f), Vec3d(pos).add(0.5, 0.5, 0.5)) ?: return false From 53007af54f34d9b0fbe4ede0ece399a2e31ac27d Mon Sep 17 00:00:00 2001 From: theredstoner Date: Wed, 16 Dec 2020 22:00:51 -0700 Subject: [PATCH 098/390] Add swing for breaking fire blocks --- .../me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index e182d0aa31..62c86e789b 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -660,6 +660,7 @@ object HighwayTools : Module() { if (blockTask.block == Blocks.FIRE) { mc.connection!!.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, blockTask.blockPos, EnumFacing.DOWN)) mc.connection!!.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, blockTask.blockPos, EnumFacing.DOWN)) + mc.player.swingArm(EnumHand.MAIN_HAND) updateTask(blockTask, TaskState.BREAKING) return } From 4530d8b3feb83c300a38f8d4fedb924073710964 Mon Sep 17 00:00:00 2001 From: theredstoner Date: Thu, 17 Dec 2020 15:53:21 -0700 Subject: [PATCH 099/390] Fix overfilling inventory when using AutoObsidian Check the maximum possible ender chests we can break, then pick the minimum from that and the target stacks. Also continually check if our inventory is full, and if it is transition to the done state (this is mainly only useful if we somehow pick up other items while breaking echests). --- .../kami/module/modules/misc/AutoObsidian.kt | 53 ++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt index ec6c5c81b5..a69884c993 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt @@ -19,6 +19,7 @@ import net.minecraft.client.gui.inventory.GuiShulkerBox import net.minecraft.init.Blocks import net.minecraft.init.SoundEvents import net.minecraft.inventory.ClickType +import net.minecraft.item.Item import net.minecraft.item.Item.getIdFromItem import net.minecraft.network.play.client.CPacketPlayer import net.minecraft.network.play.client.CPacketPlayerDigging @@ -32,6 +33,7 @@ import net.minecraftforge.fml.common.gameevent.TickEvent import org.kamiblue.event.listener.listener import kotlin.math.ceil import kotlin.math.floor +import kotlin.math.min @Module.Info( @@ -65,6 +67,7 @@ object AutoObsidian : Module() { OFF, TP, MOTION } private enum class ItemID(val id: Int) { + AIR(0), OBSIDIAN(49), ENDER_CHEST(130), DIAMOND_PICKAXE(278) @@ -80,6 +83,7 @@ object AutoObsidian : Module() { private var placingPos = BlockPos(0, -1, 0) private var shulkerBoxId = 0 private var enderChestCount = -1 + private var maxEnderChests = -1 /* The number of ender chests required to completely fill an inventory */ private var obsidianCount = -1 private var tickCount = 0 private var openTime = 0L @@ -182,13 +186,15 @@ object AutoObsidian : Module() { /* Updates ender chest and obsidian counts before placing and mining ender chest */ if (state == State.SEARCHING) { enderChestCount = InventoryUtils.countItemAll(ItemID.ENDER_CHEST.id) + maxEnderChests = maxPossibleEnderChests() obsidianCount = countObsidian() } /* Updates main state */ val placedEnderChest = enderChestCount - InventoryUtils.countItemAll(ItemID.ENDER_CHEST.id) - val targetEnderChest = (targetStacks.value * 64 - obsidianCount) / 8 + val targetEnderChest = min((targetStacks.value * 64 - obsidianCount) / 8, maxEnderChests) state = when { + !canPickUpObsidian() -> State.DONE state == State.DONE && autoRefill.value && InventoryUtils.countItemAll(ItemID.OBSIDIAN.id) <= threshold.value -> State.SEARCHING state == State.COLLECTING && getDroppedItem(ItemID.OBSIDIAN.id, 16.0f) == null -> State.DONE state != State.DONE && mc.world.isAirBlock(placingPos) && placedEnderChest >= targetEnderChest -> State.COLLECTING @@ -224,6 +230,51 @@ object AutoObsidian : Module() { } + /* + Calculate the maximum possible ender chests we can break given the current space in our inventory + */ + private fun maxPossibleEnderChests(): Int { + var maxEnderChests = 0 + mc.player?.inventory?.mainInventory.let { + val clonedList = ArrayList(it) + for (itemStack in clonedList) { + if(getIdFromItem(itemStack.item) == ItemID.AIR.id) { + maxEnderChests += 8 + } + else if(getIdFromItem(itemStack.item) == ItemID.OBSIDIAN.id) { + /* Pick floor: It is better to have an unfilled stack then overfill and get stuck trying to pick + up extra obsidian + */ + maxEnderChests = floor((64.0 - itemStack.count) / 8.0).toInt() + } + } + } + return maxEnderChests + } + + /* + Check if we can pick up more obsidian: + There must be at least one slot which is either empty, or contains a stack of obsidian less than 64 + */ + private fun canPickUpObsidian(): Boolean { + mc.player?.inventory?.mainInventory?.let { + val clonedList = ArrayList(it) + for (itemStack in clonedList) { + /* If there is an air block slot, we have an open inventory slot */ + if(getIdFromItem(itemStack.item) == ItemID.AIR.id) { + return true + } + /* If there is a non-full stack of obsidian, we have an open inventory slot */ + if((getIdFromItem(itemStack.item) == ItemID.OBSIDIAN.id) && itemStack.count < 64) { + return true + } + } + } + + /* No matches to eligible slots, we can not pick up any more items */ + return false + } + /* Return the obsidian count, rounded up to the nearest 8th */ private fun countObsidian(): Int { return ceil(InventoryUtils.countItemAll(ItemID.OBSIDIAN.id).toDouble() / 8.0).toInt() * 8 From d49a39564f7f509dd46728b4e671b26249a3e47b Mon Sep 17 00:00:00 2001 From: theredstoner Date: Thu, 17 Dec 2020 19:59:43 -0700 Subject: [PATCH 100/390] Remove wall sign from ignoreblocks Wall signs are sometimes attached to blocks we need to mine, remove them from the ignoreblocks list. --- .../me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 62c86e789b..07be02d25f 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -92,7 +92,6 @@ object HighwayTools : Module() { // internal settings val ignoreBlocks = hashSetOf( Blocks.STANDING_SIGN, - Blocks.WALL_SIGN, Blocks.STANDING_BANNER, Blocks.WALL_BANNER, Blocks.BEDROCK, From 7e9d0e57c986156b950c2c98ca3de5f8bcf57822 Mon Sep 17 00:00:00 2001 From: theredstoner Date: Thu, 17 Dec 2020 22:19:14 -0700 Subject: [PATCH 101/390] Just punch the block below fire blocks This often ends up in us mining the block below the fire block, but it works on 2b2t. --- .../kami/module/modules/misc/HighwayTools.kt | 37 +++++++++++-------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 07be02d25f..86a5ad0dd4 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -25,6 +25,7 @@ import me.zeroeightsix.kami.util.math.VectorUtils.toVec3d import me.zeroeightsix.kami.util.text.MessageSendHelper.sendChatMessage import net.minecraft.block.Block import net.minecraft.block.Block.getIdFromBlock +import net.minecraft.block.Block.registerBlocks import net.minecraft.block.BlockLiquid import net.minecraft.client.audio.PositionedSoundRecord import net.minecraft.init.Blocks @@ -655,10 +656,11 @@ object HighwayTools : Module() { return } - /* For fire, we just need to mine the bottom of the block */ + /* For fire, we just need to mine the top of the block below the fire */ + /* TODO: This will not work if the top of the block which the fire is on is not visible */ if (blockTask.block == Blocks.FIRE) { - mc.connection!!.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, blockTask.blockPos, EnumFacing.DOWN)) - mc.connection!!.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, blockTask.blockPos, EnumFacing.DOWN)) + val blockBelowFire = BlockPos(blockTask.blockPos.x, blockTask.blockPos.y - 1, blockTask.blockPos.z) + mc.playerController.clickBlock(blockBelowFire, EnumFacing.UP) mc.player.swingArm(EnumHand.MAIN_HAND) updateTask(blockTask, TaskState.BREAKING) return @@ -722,22 +724,25 @@ object HighwayTools : Module() { mc.player.swingArm(EnumHand.MAIN_HAND) }.start() } - else -> { - val digPacket: CPacketPlayerDigging = when (blockTask.taskState) { - TaskState.BREAK, TaskState.EMERGENCY_BREAK -> CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, blockTask.blockPos, facing) - TaskState.BREAKING -> CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, blockTask.blockPos, facing) - else -> CPacketPlayerDigging() - } - if (blockTask.taskState == TaskState.BREAK || blockTask.taskState == TaskState.EMERGENCY_BREAK) updateTask(blockTask, TaskState.BREAKING) - Thread { - Thread.sleep(25L) - mc.connection!!.sendPacket(digPacket) - mc.player.swingArm(EnumHand.MAIN_HAND) - }.start() - } + else -> dispatchGenericMineThread(blockTask, facing) } } + /* Dispatches a thread to mine any non-netherrack blocks generically */ + private fun dispatchGenericMineThread(blockTask: BlockTask, facing: EnumFacing) { + val digPacket: CPacketPlayerDigging = when (blockTask.taskState) { + TaskState.BREAK, TaskState.EMERGENCY_BREAK -> CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, blockTask.blockPos, facing) + TaskState.BREAKING -> CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, blockTask.blockPos, facing) + else -> CPacketPlayerDigging() + } + if (blockTask.taskState == TaskState.BREAK || blockTask.taskState == TaskState.EMERGENCY_BREAK) updateTask(blockTask, TaskState.BREAKING) + Thread { + Thread.sleep(25L) + mc.connection!!.sendPacket(digPacket) + mc.player.swingArm(EnumHand.MAIN_HAND) + }.start() + } + // Only temporary till we found solution to avoid untraceable blocks private fun placeBlockWall(blockTask: BlockTask): Boolean { val side = getPlaceableSide(blockTask.blockPos) ?: return false From 33a2e7a2e87be484bbfe5ebbc1385ba1b1f76801 Mon Sep 17 00:00:00 2001 From: theredstoner Date: Fri, 18 Dec 2020 23:06:44 -0700 Subject: [PATCH 102/390] Refactor pausing logic Just cleans it up a bit --- .../kami/module/modules/misc/HighwayTools.kt | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 86a5ad0dd4..16cf442f28 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -231,7 +231,7 @@ object HighwayTools : Module() { } if (getDistance(mc.player.positionVector, taskDistance.toVec3d()) < maxReach.value ) { if (!isDone()) { - if (!BaritoneUtils.paused && !AutoObsidian.isActive() && !AutoEat.eating) { + if(canDoTask()) { if (!pathing) adjustPlayerPosition(false) val currentFood = mc.player.foodStats.foodLevel if (currentFood != prevFood) { @@ -312,8 +312,13 @@ object HighwayTools : Module() { doneTasks.add(blockTask) } + /* Returns true if we can do a task, else returns false */ + private fun canDoTask(): Boolean { + return !BaritoneUtils.paused && !AutoObsidian.isActive() && !AutoEat.eating + } + private fun doTask() { - if (!isDone() && !BaritoneUtils.paused && !AutoObsidian.isActive()) { + if (!isDone() && canDoTask()) { if (waitTicks == 0) { val blockTask = pendingTasks.peek() @@ -924,7 +929,6 @@ object HighwayTools : Module() { sendChatMessage(toString()) } } - } fun getBlueprintStats(): Pair { From d1ca3bb52c59cff0fab8a96707b20a6bb3ee2b28 Mon Sep 17 00:00:00 2001 From: theredstoner Date: Sat, 19 Dec 2020 00:50:30 -0700 Subject: [PATCH 103/390] Only register HighwayTools baritone process once We don't need to re-register it on every tick if its already registered --- .../kami/module/modules/misc/HighwayTools.kt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 16cf442f28..781a330c46 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -119,6 +119,7 @@ object HighwayTools : Module() { private var startingBlockPos = BlockPos(0, -1, 0) private val stuckManager = StuckManagement(StuckLevel.NONE, 0) private val renderer = ESPRenderer() + private var active = false // stats private var totalBlocksPlaced = 0 @@ -183,6 +184,8 @@ object HighwayTools : Module() { override fun onDisable() { if (mc.player == null) return + active = false + // load initial player hand if (lastHotbarSlot != playerHotbarSlot && playerHotbarSlot != -1) { mc.player.inventory.currentItem = playerHotbarSlot @@ -221,7 +224,11 @@ object HighwayTools : Module() { if (mc.playerController == null) return@listener updateRenderer() - BaritoneUtils.primary?.pathingControlManager?.registerProcess(HighwayToolsProcess) + + if (!active) { + active = true + BaritoneUtils.primary?.pathingControlManager?.registerProcess(HighwayToolsProcess) + } if (baritoneMode.value) { pathing = BaritoneUtils.isPathing @@ -1256,6 +1263,7 @@ object HighwayTools : Module() { fun reset() { stuckLevel = StuckLevel.NONE stuckValue = 0 + active = false } override fun toString(): String { From 276b718130b63128acf9a11ba14f672ffabee348 Mon Sep 17 00:00:00 2001 From: theredstoner Date: Sat, 19 Dec 2020 00:51:32 -0700 Subject: [PATCH 104/390] Remove unnecessary check in canDoTask() We don't need to check if BaritoneUtils is paused. This fixes HighwayTools with AutoEat, and allows HighwayTools to unpause after AutoEating. --- .../me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 781a330c46..4845fd6211 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -321,7 +321,7 @@ object HighwayTools : Module() { /* Returns true if we can do a task, else returns false */ private fun canDoTask(): Boolean { - return !BaritoneUtils.paused && !AutoObsidian.isActive() && !AutoEat.eating + return !AutoObsidian.isActive() && !AutoEat.eating } private fun doTask() { From 60cd878780053ca4cd637eca05edf6bca3c90b77 Mon Sep 17 00:00:00 2001 From: theredstoner Date: Sun, 20 Dec 2020 20:47:23 -0700 Subject: [PATCH 105/390] Fix searchShulker There was a race condition and we were sometimes checking for a rayTrace hit when we were in the opened shulker (which we don't need to do). --- .../kami/module/modules/misc/AutoObsidian.kt | 94 +++++++++---------- 1 file changed, 47 insertions(+), 47 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt index a69884c993..ede6cdf301 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt @@ -353,51 +353,9 @@ object AutoObsidian : Module() { private fun openShulker(pos: BlockPos) { - var rayTrace = mc.world.rayTraceBlocks(mc.player.getPositionEyes(1f), Vec3d(pos).add(0.5, 0.5, 0.5)) ?: return - if (rayTrace.blockPos != pos) { - var found = false - for (side in EnumFacing.values()) { - if (mc.world.getBlockState(pos.offset(side)).block == Blocks.AIR) { - rayTrace = mc.world.rayTraceBlocks(mc.player.getPositionEyes(1f), Vec3d(pos).add(0.5, 0.5, 0.5).add(Vec3d(side.directionVec).scale(0.499)))?: continue - if (rayTrace.blockPos == pos) { - found = true - break - } - } - } - if (!found) { - return - } - } - val facing = rayTrace.sideHit ?: return - val hitVecOffset = rayTrace.hitVec - val rotation = getRotationTo(Vec3d(pos).add(0.5, 0.5, 0.5).add(Vec3d(facing.directionVec).scale(0.499)), true) - when (interacting.value) { - InteractMode.SPOOF -> { - val rotationPacket = CPacketPlayer.PositionRotation(mc.player.posX, mc.player.posY, mc.player.posZ, rotation.x.toFloat(), rotation.y.toFloat(), mc.player.onGround) - mc.connection!!.sendPacket(rotationPacket) - } - InteractMode.VIEWLOCK -> { - mc.player.rotationYaw = rotation.x.toFloat() - mc.player.rotationPitch = rotation.y.toFloat() - } - } - - if (mc.currentScreen !is GuiShulkerBox) { - /* Added a delay here so it doesn't spam right click and get you kicked */ - if (System.currentTimeMillis() >= openTime + 2000L) { - openTime = System.currentTimeMillis() - Thread{ - Thread.sleep(delayTicks.value * 25L) - val placePacket = CPacketPlayerTryUseItemOnBlock(rayTrace.blockPos, rayTrace.sideHit, EnumHand.MAIN_HAND, hitVecOffset.x.toFloat(), hitVecOffset.y.toFloat(), hitVecOffset.z.toFloat()) - mc.connection!!.sendPacket(placePacket) - mc.player.swingArm(EnumHand.MAIN_HAND) - if (NoBreakAnimation.isEnabled) NoBreakAnimation.resetMining() - }.start() - } - } else { - /* Extra delay here to wait for the item list to be loaded */ - Thread{ + if(mc.currentScreen is GuiShulkerBox) { + Thread { + /* Extra delay here to wait for the item list to be loaded */ Thread.sleep(delayTicks.value * 50L) val currentContainer = mc.player.openContainer var enderChestSlot = -1 @@ -409,12 +367,54 @@ object AutoObsidian : Module() { } if (enderChestSlot != -1) { mc.playerController.windowClick(currentContainer.windowId, enderChestSlot, 0, ClickType.QUICK_MOVE, mc.player) + mc.player.closeScreen() } else { sendChatMessage("$chatName No ender chest was found in shulker, disabling.") mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) this.disable() } }.start() + } else { + var rayTrace = mc.world.rayTraceBlocks(mc.player.getPositionEyes(1f), Vec3d(pos).add(0.5, 0.5, 0.5)) ?: return + if (rayTrace.blockPos != pos) { + var found = false + for (side in EnumFacing.values()) { + if (mc.world.getBlockState(pos.offset(side)).block == Blocks.AIR) { + rayTrace = mc.world.rayTraceBlocks(mc.player.getPositionEyes(1f), Vec3d(pos).add(0.5, 0.5, 0.5).add(Vec3d(side.directionVec).scale(0.499)))?: continue + if (rayTrace.blockPos == pos) { + found = true + break + } + } + } + if (!found) { + return + } + } + val hitVecOffset = rayTrace.hitVec + val rotation = getRotationTo(hitVecOffset, true) + when (interacting.value) { + InteractMode.SPOOF -> { + val rotationPacket = CPacketPlayer.PositionRotation(mc.player.posX, mc.player.posY, mc.player.posZ, rotation.x.toFloat(), rotation.y.toFloat(), mc.player.onGround) + mc.connection!!.sendPacket(rotationPacket) + } + InteractMode.VIEWLOCK -> { + mc.player.rotationYaw = rotation.x.toFloat() + mc.player.rotationPitch = rotation.y.toFloat() + } + } + + /* Added a delay here so it doesn't spam right click and get you kicked */ + if (System.currentTimeMillis() >= openTime + 2000L) { + openTime = System.currentTimeMillis() + Thread{ + Thread.sleep(delayTicks.value * 25L) + val placePacket = CPacketPlayerTryUseItemOnBlock(rayTrace.blockPos, rayTrace.sideHit, EnumHand.MAIN_HAND, hitVecOffset.x.toFloat(), hitVecOffset.y.toFloat(), hitVecOffset.z.toFloat()) + mc.connection!!.sendPacket(placePacket) + mc.player.swingArm(EnumHand.MAIN_HAND) + if (NoBreakAnimation.isEnabled) NoBreakAnimation.resetMining() + }.start() + } } } @@ -485,7 +485,7 @@ object AutoObsidian : Module() { InventoryUtils.swapSlotToItem(ItemID.DIAMOND_PICKAXE.id) } - var rayTrace = mc.world.rayTraceBlocks(mc.player.getPositionEyes(1f), Vec3d(pos).add(0.5, 0.5, 0.5)) ?: return false + var rayTrace = mc.world.rayTraceBlocks(mc.player.getPositionEyes(1f), Vec3d(pos).add(0.5, 0.5, 0.5), false, true, false) ?: return false if (rayTrace.blockPos != pos) { var found = false for (side in EnumFacing.values()) { @@ -502,7 +502,7 @@ object AutoObsidian : Module() { } } val facing = rayTrace.sideHit ?: return false - val rotation = getRotationTo(Vec3d(pos).add(0.5, 0.5, 0.5).add(Vec3d(facing.directionVec).scale(0.499)), true) + val rotation = getRotationTo(rayTrace.hitVec, true) when (interacting.value) { InteractMode.SPOOF -> { val rotationPacket = CPacketPlayer.PositionRotation(mc.player.posX, mc.player.posY, mc.player.posZ, rotation.x.toFloat(), rotation.y.toFloat(), mc.player.onGround) From d12eb5622d961035c3072c2a2c881db20d9b7ef9 Mon Sep 17 00:00:00 2001 From: theredstoner Date: Mon, 21 Dec 2020 11:29:05 -0700 Subject: [PATCH 106/390] Re-add wallsigns to ignoreblocks --- .../me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 4845fd6211..0db3945beb 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -95,6 +95,7 @@ object HighwayTools : Module() { Blocks.STANDING_SIGN, Blocks.STANDING_BANNER, Blocks.WALL_BANNER, + Blocks.WALL_SIGN, Blocks.BEDROCK, Blocks.END_PORTAL, Blocks.END_PORTAL_FRAME, From 313633f0865e6ee11d42030107bce89d34abc9a9 Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 22 Dec 2020 05:52:01 +0100 Subject: [PATCH 107/390] Refactor of commands for merge --- .../command/commands/HighwayToolsCommand.kt | 125 +++++------------- .../kami/module/modules/misc/HighwayTools.kt | 3 +- 2 files changed, 37 insertions(+), 91 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/command/commands/HighwayToolsCommand.kt b/src/main/java/me/zeroeightsix/kami/command/commands/HighwayToolsCommand.kt index 0faa6ab623..174af1286f 100644 --- a/src/main/java/me/zeroeightsix/kami/command/commands/HighwayToolsCommand.kt +++ b/src/main/java/me/zeroeightsix/kami/command/commands/HighwayToolsCommand.kt @@ -1,120 +1,65 @@ package me.zeroeightsix.kami.command.commands -import me.zeroeightsix.kami.command.Command -import me.zeroeightsix.kami.command.syntax.ChunkBuilder -import me.zeroeightsix.kami.command.syntax.parsers.EnumParser +import me.zeroeightsix.kami.command.ClientCommand import me.zeroeightsix.kami.module.modules.misc.HighwayTools import me.zeroeightsix.kami.util.text.MessageSendHelper import net.minecraft.block.Block -/** - * @author Avanatiker - * @since 01/09/2020 - */ -class HighwayToolsCommand : Command("highwaytools", ChunkBuilder() - .append("mode", true, EnumParser(arrayOf("material", "filler", "ignore", "reach", "settings"))) - .append("value") - .build(), "ht") { +object HighwayToolsCommand : ClientCommand( + name = "highwaytools", + alias = arrayOf("ht"), + description = "Customize settings of HighwayTools." +) { - override fun call(args: Array) { - when (getSubCommand(args)) { - SubCommands.SETTINGS -> { - HighwayTools.printSettings() - } - - SubCommands.MATERIAL -> { - val block = Block.getBlockFromName(args[1].toString()) - - if (block != null) { - HighwayTools.material = block - MessageSendHelper.sendChatMessage("Set your building material to &7${block.localizedName}&r.") - } else { - MessageSendHelper.sendChatMessage("&7${args[1]}&r is not a valid block.") - } - } - - SubCommands.FILLER -> { - val block = Block.getBlockFromName(args[1].toString()) - - if (block != null) { - HighwayTools.fillerMat = block - MessageSendHelper.sendChatMessage("Set your filling material to &7${block.localizedName}&r.") - } else { - MessageSendHelper.sendChatMessage("&7${args[1]}&r is not a valid block.") - } - } - - SubCommands.IGNORE_ADD -> { - val block = Block.getBlockFromName(args[2].toString()) - - if (block != null) { - val added = HighwayTools.ignoreBlocks.add(block) + init { + literal("add", "new", "+") { + block("block") { blockArg -> + execute("Add a block to ignore list") { + val added = HighwayTools.ignoreBlocks.add(blockArg.value) if (added) { HighwayTools.printSettings() - MessageSendHelper.sendChatMessage("Added &7${block.localizedName}&r to ignore list.") + MessageSendHelper.sendChatMessage("Added &7${blockArg.value.localizedName}&r to ignore list.") } else { - - MessageSendHelper.sendChatMessage("&7${block.localizedName}&r is already ignored.") + MessageSendHelper.sendChatMessage("&7${blockArg.value.localizedName}&r is already ignored.") } - } else { - MessageSendHelper.sendChatMessage("&7${args[2]}&r is not a valid block.") } } + } - SubCommands.IGNORE_DEL -> { - val block = Block.getBlockFromName(args[2].toString()) - - if (block != null) { - val removed = HighwayTools.ignoreBlocks.remove(block) + literal("del", "rem", "-") { + block("block") { blockArg -> + execute("Remove a block from ignore list") { + val removed = HighwayTools.ignoreBlocks.remove(blockArg.value) if (removed) { HighwayTools.printSettings() - MessageSendHelper.sendChatMessage("Removed &7${block.localizedName}&r from ignore list.") + MessageSendHelper.sendChatMessage("Removed &7${blockArg.value.localizedName}&r from ignore list.") } else { - MessageSendHelper.sendChatMessage("&7${block.localizedName}&r is not yet ignored.") + MessageSendHelper.sendChatMessage("&7${blockArg.value.localizedName}&r is not yet ignored.") } - } else { - MessageSendHelper.sendChatMessage("&7${args[2]}&r is not a valid block.") } } + } - else -> { - val commands = args.joinToString(separator = " ") - MessageSendHelper.sendChatMessage("Invalid command &7${commandPrefix.value}${label} $commands&f!") + literal("material", "mat") { + block("block") { blockArg -> + execute("Set a block as main material") { + HighwayTools.material = blockArg.value + MessageSendHelper.sendChatMessage("Set your building material to &7${blockArg.value.localizedName}&r.") + } } } - } - - private fun getSubCommand(args: Array): SubCommands? { - return when { - args[0].isNullOrBlank() -> SubCommands.SETTINGS - - args[0].equals("settings", ignoreCase = true) -> SubCommands.SETTINGS - - args[1].isNullOrBlank() -> null - - args[0].equals("material", ignoreCase = true) -> SubCommands.MATERIAL - - args[0].equals("filler", ignoreCase = true) -> SubCommands.FILLER - - args[0].equals("ignore", ignoreCase = true) -> { - when { - args[1].equals("add", ignoreCase = true) -> SubCommands.IGNORE_ADD - args[1].equals("del", ignoreCase = true) -> SubCommands.IGNORE_DEL - - else -> null + literal("filler", "fil") { + block("block") { blockArg -> + execute("Set a block as filler material") { + HighwayTools.fillerMat = blockArg.value + MessageSendHelper.sendChatMessage("Set your filling material to &7${blockArg.value.localizedName}&r.") } } - - else -> null } - } - private enum class SubCommands { - MATERIAL, FILLER, IGNORE_ADD, IGNORE_DEL, SETTINGS - } - - init { - setDescription("Customize HighwayTools settings.") + execute("Print the settings") { + HighwayTools.printSettings() + } } } \ No newline at end of file diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index ee488d4ccb..ff5a444a57 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -865,7 +865,8 @@ object HighwayTools : Module() { fun printSettings() { StringBuilder(ignoreBlocks.size + 1).run { append("$chatName Settings" + - "\n §9> §rMaterial: §7${material.localizedName}" + + "\n §9> §rMain material: §7${material.localizedName}" + + "\n §9> §rFiller material: §7${fillerMat.localizedName}" + "\n §9> §rBaritone: §7${baritoneMode.value}" + "\n §9> §rIgnored Blocks:") for (b in ignoreBlocks) append("\n §9> §7${b!!.registryName}") From bb3dbcc6bce372f713415c1fc1ea8d1882afb676 Mon Sep 17 00:00:00 2001 From: Christian Date: Wed, 23 Dec 2020 19:44:10 +0100 Subject: [PATCH 108/390] Fix syntax and GUI --- .../me/zeroeightsix/kami/gui/kami/KamiGUI.java | 2 +- .../kami/module/modules/misc/HighwayTools.kt | 15 ++++++--------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/gui/kami/KamiGUI.java b/src/main/java/me/zeroeightsix/kami/gui/kami/KamiGUI.java index 145ce57ec2..4efb0def3e 100644 --- a/src/main/java/me/zeroeightsix/kami/gui/kami/KamiGUI.java +++ b/src/main/java/me/zeroeightsix/kami/gui/kami/KamiGUI.java @@ -125,7 +125,7 @@ public void initializeGUI() { Stretcherlayout stretcherlayout = new Stretcherlayout(1); stretcherlayout.setComponentOffsetWidth(0); Scrollpane scrollpane = new Scrollpane(getTheme(), stretcherlayout, 300, 260); - scrollpane.setMaximumHeight(500); + scrollpane.setMaximumHeight(180); categoryScrollpaneHashMap.put(moduleCategory, new Pair<>(scrollpane, new SettingsPanel(getTheme(), null))); } diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index ff5a444a57..56d5bff339 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -39,7 +39,6 @@ import net.minecraftforge.fml.common.gameevent.TickEvent import org.kamiblue.event.listener.listener import java.util.* import kotlin.collections.ArrayList -import kotlin.concurrent.thread import kotlin.math.abs import kotlin.math.sqrt @@ -135,9 +134,7 @@ object HighwayTools : Module() { } /* Turn on inventory manager if the users wants us to control it */ - if(toggleInventoryManager.value && InventoryManager.isDisabled) { - InventoryManager.enable() - } + if(toggleInventoryManager.value && InventoryManager.isDisabled) InventoryManager.enable() /* Turn on Auto Obsidian if the user wants us to control it. */ if(toggleAutoObsidian.value && AutoObsidian.isDisabled) { @@ -146,7 +143,7 @@ object HighwayTools : Module() { AutoObsidian.enable() } else { - thread { + Thread { /* Wait 1 second because turning both on simultaneously is buggy */ Thread.sleep(1000) AutoObsidian.enable() @@ -225,8 +222,8 @@ object HighwayTools : Module() { if (baritoneMode.value) { pathing = BaritoneUtils.isPathing var taskDistance = BlockPos(0, -1, 0) - (pendingTasks.firstOrNull() ?: doneTasks.firstOrNull())?.let { - taskDistance = it.blockPos + (pendingTasks.firstOrNull() ?: doneTasks.firstOrNull())?.let { element -> + taskDistance = element.blockPos } if (getDistance(mc.player.positionVector, taskDistance.toVec3d()) < maxReach.value ) { if (!isDone()) { @@ -737,7 +734,7 @@ object HighwayTools : Module() { val rotation = RotationUtils.getRotationTo(hitVec, true) setRotation(rotation) - Thread{ + Thread { Thread.sleep(25L) val placePacket = CPacketPlayerTryUseItemOnBlock(neighbour, side.opposite, EnumHand.MAIN_HAND, hitVec.x.toFloat(), hitVec.y.toFloat(), hitVec.z.toFloat()) mc.connection!!.sendPacket(placePacket) @@ -801,7 +798,7 @@ object HighwayTools : Module() { val rotation = RotationUtils.getRotationTo(hitVecOffset, true) setRotation(rotation) - Thread{ + Thread { Thread.sleep(25L) val placePacket = CPacketPlayerTryUseItemOnBlock(rayTrace.blockPos, rayTrace.sideHit, EnumHand.MAIN_HAND, hitVecOffset.x.toFloat(), hitVecOffset.y.toFloat(), hitVecOffset.z.toFloat()) mc.connection!!.sendPacket(placePacket) From 2827898353d4f02912ad0437720a0b3edd528f04 Mon Sep 17 00:00:00 2001 From: Christian Date: Thu, 24 Dec 2020 04:17:11 +0100 Subject: [PATCH 109/390] Merge fixes and new version name --- gradle.properties | 2 +- .../kami/module/modules/misc/HighwayTools.kt | 10 +++------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/gradle.properties b/gradle.properties index 3d419b2bd0..c762c5b684 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ org.gradle.jvmargs=-Xmx3G modGroup=me.zeroeightsix -modVersion=1.12.xx-dev +modVersion=1.12.xx-dev-ht-v06 kotlin_version=1.4.20 kotlinx_coroutines_version=1.4.1 \ No newline at end of file diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index fd9b7d1c51..e261aa3ae6 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -25,7 +25,6 @@ import me.zeroeightsix.kami.util.math.VectorUtils.toVec3d import me.zeroeightsix.kami.util.text.MessageSendHelper.sendChatMessage import net.minecraft.block.Block import net.minecraft.block.Block.getIdFromBlock -import net.minecraft.block.Block.registerBlocks import net.minecraft.block.BlockLiquid import net.minecraft.client.audio.PositionedSoundRecord import net.minecraft.init.Blocks @@ -36,7 +35,6 @@ import net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock import net.minecraft.util.EnumFacing import net.minecraft.util.EnumHand import net.minecraft.util.math.* -import net.minecraftforge.client.event.ColorHandlerEvent import net.minecraftforge.fml.common.gameevent.TickEvent import org.kamiblue.event.listener.listener import java.util.* @@ -92,9 +90,9 @@ object HighwayTools : Module() { // internal settings val ignoreBlocks = hashSetOf( Blocks.STANDING_SIGN, + Blocks.WALL_SIGN, Blocks.STANDING_BANNER, Blocks.WALL_BANNER, - Blocks.WALL_SIGN, Blocks.BEDROCK, Blocks.END_PORTAL, Blocks.END_PORTAL_FRAME, @@ -200,9 +198,7 @@ object HighwayTools : Module() { } /* Turn off inventory manager if the users wants us to control it */ - if(toggleInventoryManager.value && InventoryManager.isEnabled) { - InventoryManager.disable() - } + if(toggleInventoryManager.value && InventoryManager.isEnabled) InventoryManager.disable() /* Turn off auto obsidian if the user wants us to control it */ if(toggleAutoObsidian.value && AutoObsidian.isEnabled) { @@ -319,7 +315,7 @@ object HighwayTools : Module() { /* Returns true if we can do a task, else returns false */ private fun canDoTask(): Boolean { - return !AutoObsidian.isActive() && !AutoEat.eating + return !BaritoneUtils.paused && !AutoObsidian.isActive() && !AutoEat.eating } private fun doTask() { From 691ce973383f5ba3294b66f5ce86f760ee3b7ddf Mon Sep 17 00:00:00 2001 From: theredstoner Date: Wed, 23 Dec 2020 23:45:22 -0700 Subject: [PATCH 110/390] Add fillInventory + infinite mode to AutoObsidian - fillInventory: Mine E-chests until the user's inventory is full - infinite: Continually mine E-chests until we run out --- .../kami/module/modules/misc/AutoObsidian.kt | 63 ++++++++++++++----- 1 file changed, 47 insertions(+), 16 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt index ede6cdf301..d6df59bd37 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt @@ -19,7 +19,6 @@ import net.minecraft.client.gui.inventory.GuiShulkerBox import net.minecraft.init.Blocks import net.minecraft.init.SoundEvents import net.minecraft.inventory.ClickType -import net.minecraft.item.Item import net.minecraft.item.Item.getIdFromItem import net.minecraft.network.play.client.CPacketPlayer import net.minecraft.network.play.client.CPacketPlayerDigging @@ -42,29 +41,51 @@ import kotlin.math.min description = "Breaks down Ender Chests to restock obsidian" ) object AutoObsidian : Module() { + private val mode = register(Settings.e("Mode", Mode.TARGETSTACKS)) + private val searchShulker = register(Settings.b("SearchShulker", false)) - private val autoRefill = register(Settings.b("AutoRefill", false)) - private val threshold = register(Settings.integerBuilder("RefillThreshold").withValue(8).withRange(1, 56).withVisibility { autoRefill.value }) - private val targetStacks = register(Settings.integerBuilder("TargetStacks").withValue(1).withRange(1, 20)) + private val autoRefill = register(Settings.booleanBuilder("AutoRefill").withValue(false).withVisibility { mode.value != Mode.INFINITE }) + private val threshold = register(Settings.integerBuilder("RefillThreshold").withValue(8).withRange(1, 56).withVisibility { autoRefill.value && mode.value != Mode.INFINITE }) + private val targetStacks = register(Settings.integerBuilder("TargetStacks").withValue(1).withRange(1, 20).withVisibility { mode.value == Mode.TARGETSTACKS }) private val delayTicks = register(Settings.integerBuilder("DelayTicks").withValue(5).withRange(0, 10)) private val interacting = register(Settings.enumBuilder(InteractMode::class.java).withName("InteractMode").withValue(InteractMode.SPOOF)) private val autoCenter = register(Settings.enumBuilder(AutoCenterMode::class.java).withName("AutoCenter").withValue(AutoCenterMode.MOTION)) private val maxReach = register(Settings.floatBuilder("MaxReach").withValue(4.5F).withRange(1.0f, 6.0f).withStep(0.1f)) + private enum class Mode { + TARGETSTACKS, + INFINITE, + FILLINVENTORY + } + enum class State { - SEARCHING, PLACING, PRE_MINING, MINING, COLLECTING, DONE + SEARCHING, + PLACING, + PRE_MINING, + MINING, + COLLECTING, + DONE } - enum class SearchingState { - PLACING, OPENING, PRE_MINING, MINING, COLLECTING, DONE + private enum class SearchingState { + PLACING, + OPENING, + PRE_MINING, + MINING, + COLLECTING, + DONE } private enum class InteractMode { - OFF, SPOOF, VIEWLOCK + OFF, + SPOOF, + VIEWLOCK } - enum class AutoCenterMode { - OFF, TP, MOTION + private enum class AutoCenterMode { + OFF, + TP, + MOTION } private enum class ItemID(val id: Int) { AIR(0), @@ -77,7 +98,7 @@ object AutoObsidian : Module() { var goal: BlockPos? = null var state = State.SEARCHING - var active = false + private var active = false private var searchingState = SearchingState.PLACING private var playerPos = BlockPos(0, -1, 0) private var placingPos = BlockPos(0, -1, 0) @@ -191,16 +212,26 @@ object AutoObsidian : Module() { } /* Updates main state */ - val placedEnderChest = enderChestCount - InventoryUtils.countItemAll(ItemID.ENDER_CHEST.id) - val targetEnderChest = min((targetStacks.value * 64 - obsidianCount) / 8, maxEnderChests) + var placedEnderChest = -1 + var targetEnderChest = -1 + when(mode.value) { + Mode.TARGETSTACKS -> { + placedEnderChest = enderChestCount - InventoryUtils.countItemAll(ItemID.ENDER_CHEST.id) + targetEnderChest = min((targetStacks.value * 64 - obsidianCount) / 8, maxEnderChests) + } + Mode.FILLINVENTORY -> { + placedEnderChest = enderChestCount - InventoryUtils.countItemAll(ItemID.ENDER_CHEST.id) + targetEnderChest = maxEnderChests + } + } state = when { - !canPickUpObsidian() -> State.DONE + (!canPickUpObsidian() && mode.value != Mode.INFINITE) -> State.DONE /* Never transition to done when in INFINITE mode */ state == State.DONE && autoRefill.value && InventoryUtils.countItemAll(ItemID.OBSIDIAN.id) <= threshold.value -> State.SEARCHING state == State.COLLECTING && getDroppedItem(ItemID.OBSIDIAN.id, 16.0f) == null -> State.DONE - state != State.DONE && mc.world.isAirBlock(placingPos) && placedEnderChest >= targetEnderChest -> State.COLLECTING + state != State.DONE && mc.world.isAirBlock(placingPos) && placedEnderChest >= targetEnderChest && mode.value != Mode.INFINITE -> State.COLLECTING state == State.MINING && mc.world.isAirBlock(placingPos) -> State.PLACING state == State.PLACING && !mc.world.isAirBlock(placingPos) -> State.PRE_MINING - state == State.SEARCHING && searchingState == SearchingState.DONE && placedEnderChest < targetEnderChest -> State.PLACING + state == State.SEARCHING && searchingState == SearchingState.DONE && (placedEnderChest < targetEnderChest || mode.value == Mode.INFINITE) -> State.PLACING else -> state } From afb46d3f31cae93a3d92dce2484054cef34ece4a Mon Sep 17 00:00:00 2001 From: theredstoner Date: Thu, 24 Dec 2020 17:10:45 -0700 Subject: [PATCH 111/390] Remove duplicated code INIFITE mode overrides the stack-tracking logic. We can move some duplicated code out of the conditional. --- .../me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt index d6df59bd37..dec0237161 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt @@ -212,15 +212,13 @@ object AutoObsidian : Module() { } /* Updates main state */ - var placedEnderChest = -1 + var placedEnderChest = enderChestCount - InventoryUtils.countItemAll(ItemID.ENDER_CHEST.id) var targetEnderChest = -1 when(mode.value) { Mode.TARGETSTACKS -> { - placedEnderChest = enderChestCount - InventoryUtils.countItemAll(ItemID.ENDER_CHEST.id) targetEnderChest = min((targetStacks.value * 64 - obsidianCount) / 8, maxEnderChests) } Mode.FILLINVENTORY -> { - placedEnderChest = enderChestCount - InventoryUtils.countItemAll(ItemID.ENDER_CHEST.id) targetEnderChest = maxEnderChests } } From 2a5f289feea50419391ed58929c49804378a1fba Mon Sep 17 00:00:00 2001 From: theredstoner Date: Thu, 24 Dec 2020 23:44:59 -0700 Subject: [PATCH 112/390] Fix not starting AutoObsidian start Thread We changed from using thread to using Thread (with a capitol T). thread does not require calling .start(), Thread does. --- .../me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index fd9b7d1c51..2b545c516d 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -148,9 +148,9 @@ object HighwayTools : Module() { else { Thread { /* Wait 1 second because turning both on simultaneously is buggy */ - Thread.sleep(1000) + Thread.sleep(1000L) AutoObsidian.enable() - } + }.start() } } From a7909aa45425d05082e7f84eec5e6d6048f858c1 Mon Sep 17 00:00:00 2001 From: theredstoner Date: Fri, 25 Dec 2020 13:47:19 -0700 Subject: [PATCH 113/390] Fix some clown code I added extra parameters to this function call but they are unneeded and cause ViewLock mode to fail. --- .../me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt index dec0237161..f07b1b2fd3 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt @@ -514,7 +514,7 @@ object AutoObsidian : Module() { InventoryUtils.swapSlotToItem(ItemID.DIAMOND_PICKAXE.id) } - var rayTrace = mc.world.rayTraceBlocks(mc.player.getPositionEyes(1f), Vec3d(pos).add(0.5, 0.5, 0.5), false, true, false) ?: return false + var rayTrace = mc.world.rayTraceBlocks(mc.player.getPositionEyes(1f), Vec3d(pos).add(0.5, 0.5, 0.5)) ?: return false if (rayTrace.blockPos != pos) { var found = false for (side in EnumFacing.values()) { From 985ad51651fa8cf5d6c5a6be2755c1bc1ba893c9 Mon Sep 17 00:00:00 2001 From: Natan <66911017+natan515@users.noreply.github.com> Date: Sat, 26 Dec 2020 23:46:36 +0200 Subject: [PATCH 114/390] Some update to make life easiar No more of those anoying refresh messages when u open ur GUI with HT on, and it tells players if they are not in the right Y LVL for the bot. --- .../zeroeightsix/kami/module/modules/misc/HighwayTools.kt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index e261aa3ae6..16ddd77e12 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -2,6 +2,7 @@ package me.zeroeightsix.kami.module.modules.misc import me.zeroeightsix.kami.event.events.RenderWorldEvent import me.zeroeightsix.kami.event.events.SafeTickEvent +import me.zeroeightsix.kami.gui.kami.DisplayGuiScreen import me.zeroeightsix.kami.module.Module import me.zeroeightsix.kami.module.modules.player.AutoEat import me.zeroeightsix.kami.module.modules.player.InventoryManager @@ -911,6 +912,7 @@ object HighwayTools : Module() { append("\n §9> §7Coordinate: §a${startingBlockPos.z}§r") } } + if (startingBlockPos.y >= 118 && startingBlockPos.x < 120) append("\n §9> §7You should move to Y 120 to build proper highways") sendChatMessage(toString()) } @@ -1239,13 +1241,13 @@ object HighwayTools : Module() { stuckLevel = StuckLevel.MODERATE if (!pathing && blockTask.taskState == TaskState.PLACE && !buildDirectionSaved.isDiagonal) adjustPlayerPosition(true) refreshData() - if (debugMessages.value != DebugMessages.OFF) sendChatMessage("$chatName Refreshing data") + if (debugMessages.value != DebugMessages.OFF && mc.currentScreen !is DisplayGuiScreen) sendChatMessage("$chatName Refreshing data") } stuckValue > 500 -> { stuckLevel = StuckLevel.MAYOR if (!pathing && blockTask.taskState == TaskState.PLACE && !buildDirectionSaved.isDiagonal) adjustPlayerPosition(true) refreshData() - if (debugMessages.value != DebugMessages.OFF) sendChatMessage("$chatName Refreshing data") + if (debugMessages.value != DebugMessages.OFF && mc.currentScreen !is DisplayGuiScreen) sendChatMessage("$chatName Refreshing data") // reset() // disable() // enable() From d3061fb812548c737bb20c1270b697a930f357a1 Mon Sep 17 00:00:00 2001 From: Natan <66911017+natan515@users.noreply.github.com> Date: Sun, 27 Dec 2020 12:41:54 +0200 Subject: [PATCH 115/390] Update HighwayTools.kt --- .../kami/module/modules/misc/HighwayTools.kt | 53 +++++++++---------- 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 16ddd77e12..5220ffc8e8 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -49,10 +49,10 @@ import kotlin.math.sqrt */ @Module.Info( - name = "HighwayTools", - description = "Be the grief a step a head.", - category = Module.Category.MISC, - modulePriority = 10 + name = "HighwayTools", + description = "Be the grief a step a head.", + category = Module.Category.MISC, + modulePriority = 10 ) object HighwayTools : Module() { @@ -90,14 +90,14 @@ object HighwayTools : Module() { // internal settings val ignoreBlocks = hashSetOf( - Blocks.STANDING_SIGN, - Blocks.WALL_SIGN, - Blocks.STANDING_BANNER, - Blocks.WALL_BANNER, - Blocks.BEDROCK, - Blocks.END_PORTAL, - Blocks.END_PORTAL_FRAME, - Blocks.PORTAL + Blocks.STANDING_SIGN, + Blocks.WALL_SIGN, + Blocks.STANDING_BANNER, + Blocks.WALL_BANNER, + Blocks.BEDROCK, + Blocks.END_PORTAL, + Blocks.END_PORTAL_FRAME, + Blocks.PORTAL ) var material: Block = Blocks.OBSIDIAN var fillerMat: Block = Blocks.NETHERRACK @@ -596,7 +596,7 @@ object HighwayTools : Module() { // for (x in InventoryUtils.getSlots(0, 35, blockID)!!) InventoryUtils.throwAllInSlot(x) // } if (InventoryUtils.getSlotsHotbar(blockID) == null && - noHotbar != null) { + noHotbar != null) { when (blockTask.block) { fillerMat -> InventoryUtils.moveToSlot(noHotbar[0], 37) material -> InventoryUtils.moveToSlot(noHotbar[0], 38) @@ -924,8 +924,8 @@ object HighwayTools : Module() { StringBuilder(2).run { append( "$chatName Module stopped." + - "\n §9> §7Placed blocks: §a$totalBlocksPlaced§r" + - "\n §9> §7Destroyed blocks: §a$totalBlocksDestroyed§r" + "\n §9> §7Placed blocks: §a$totalBlocksPlaced§r" + + "\n §9> §7Destroyed blocks: §a$totalBlocksDestroyed§r" ) if (baritoneMode.value) append("\n §9> §7Distance: §a${getDistance(startingBlockPos.toVec3d(), currentBlockPos.toVec3d()).toInt()}§r") @@ -1021,8 +1021,8 @@ object HighwayTools : Module() { for (step in 1..3) { val pos = relativeDirection(currentBlockPos, step, 0) if (mc.world.getBlockState(pos.down()).block == material && - mc.world.getBlockState(pos).block == Blocks.AIR && - mc.world.getBlockState(pos.up()).block == Blocks.AIR) lastWalkable = pos + mc.world.getBlockState(pos).block == Blocks.AIR && + mc.world.getBlockState(pos.up()).block == Blocks.AIR) lastWalkable = pos else break } } @@ -1030,8 +1030,8 @@ object HighwayTools : Module() { for (step in 1..3) { val pos = relativeDirection(currentBlockPos, step, 0) if (mc.world.getBlockState(pos.down()).block == fillerMat && - mc.world.getBlockState(pos).block == Blocks.AIR && - mc.world.getBlockState(pos.up()).block == Blocks.AIR) lastWalkable = pos + mc.world.getBlockState(pos).block == Blocks.AIR && + mc.world.getBlockState(pos.up()).block == Blocks.AIR) lastWalkable = pos else break } } @@ -1209,8 +1209,8 @@ object HighwayTools : Module() { } data class StuckManagement( - var stuckLevel: StuckLevel, - var stuckValue: Int + var stuckLevel: StuckLevel, + var stuckValue: Int ) { fun increase(blockTask: BlockTask) { @@ -1241,13 +1241,13 @@ object HighwayTools : Module() { stuckLevel = StuckLevel.MODERATE if (!pathing && blockTask.taskState == TaskState.PLACE && !buildDirectionSaved.isDiagonal) adjustPlayerPosition(true) refreshData() - if (debugMessages.value != DebugMessages.OFF && mc.currentScreen !is DisplayGuiScreen) sendChatMessage("$chatName Refreshing data") + if (debugMessages.value != DebugMessages.OFF && (mc.currentScreen !is DisplayGuiScreen || mc.currentServerData != null)) sendChatMessage("$chatName Refreshing data") } stuckValue > 500 -> { stuckLevel = StuckLevel.MAYOR if (!pathing && blockTask.taskState == TaskState.PLACE && !buildDirectionSaved.isDiagonal) adjustPlayerPosition(true) refreshData() - if (debugMessages.value != DebugMessages.OFF && mc.currentScreen !is DisplayGuiScreen) sendChatMessage("$chatName Refreshing data") + if (debugMessages.value != DebugMessages.OFF && (mc.currentScreen !is DisplayGuiScreen || mc.currentServerData != null)) sendChatMessage("$chatName Refreshing data") // reset() // disable() // enable() @@ -1269,9 +1269,9 @@ object HighwayTools : Module() { } data class BlockTask( - val blockPos: BlockPos, - var taskState: TaskState, - var block: Block + val blockPos: BlockPos, + var taskState: TaskState, + var block: Block ) { override fun toString(): String { return "Block: " + block.localizedName + " @ Position: (" + blockPos.asString() + ") Priority: " + taskState.ordinal + " State: " + taskState.toString() @@ -1332,4 +1332,3 @@ object HighwayTools : Module() { MAYOR } } - From 356857992258fce10992ea0c36a59b7f30e31cb7 Mon Sep 17 00:00:00 2001 From: Natan <66911017+natan515@users.noreply.github.com> Date: Sun, 27 Dec 2020 19:13:39 +0200 Subject: [PATCH 116/390] Update HighwayTools.kt --- .../kami/module/modules/misc/HighwayTools.kt | 108 +++++++++--------- 1 file changed, 54 insertions(+), 54 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 5220ffc8e8..2c04e0dae1 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -49,10 +49,10 @@ import kotlin.math.sqrt */ @Module.Info( - name = "HighwayTools", - description = "Be the grief a step a head.", - category = Module.Category.MISC, - modulePriority = 10 + name = "HighwayTools", + description = "Be the grief a step a head.", + category = Module.Category.MISC, + modulePriority = 10 ) object HighwayTools : Module() { @@ -90,14 +90,14 @@ object HighwayTools : Module() { // internal settings val ignoreBlocks = hashSetOf( - Blocks.STANDING_SIGN, - Blocks.WALL_SIGN, - Blocks.STANDING_BANNER, - Blocks.WALL_BANNER, - Blocks.BEDROCK, - Blocks.END_PORTAL, - Blocks.END_PORTAL_FRAME, - Blocks.PORTAL + Blocks.STANDING_SIGN, + Blocks.WALL_SIGN, + Blocks.STANDING_BANNER, + Blocks.WALL_BANNER, + Blocks.BEDROCK, + Blocks.END_PORTAL, + Blocks.END_PORTAL_FRAME, + Blocks.PORTAL ) var material: Block = Blocks.OBSIDIAN var fillerMat: Block = Blocks.NETHERRACK @@ -110,7 +110,7 @@ object HighwayTools : Module() { // runtime vars val pendingTasks = PriorityQueue(BlockTaskComparator) private val doneTasks = ArrayList() - private val blueprint = ArrayList>() + private val bluePrint = ArrayList>() private var waitTicks = 0 private var blocksPlaced = 0 var pathing = false @@ -512,10 +512,10 @@ object HighwayTools : Module() { } private fun updateTasks(originPos: BlockPos) { - blueprint.clear() + bluePrint.clear() updateBlockArray(originPos) updateBlockArray(getNextBlock(originPos)) - for ((blockPos, blockType) in blueprint) { + for ((blockPos, blockType) in bluePrint) { val isReplaceable = mc.world.getBlockState(blockPos).material.isReplaceable if (blockPos == mc.player.positionVector.toBlockPos().down()) continue when (val block = mc.world.getBlockState(blockPos).block) { @@ -596,7 +596,7 @@ object HighwayTools : Module() { // for (x in InventoryUtils.getSlots(0, 35, blockID)!!) InventoryUtils.throwAllInSlot(x) // } if (InventoryUtils.getSlotsHotbar(blockID) == null && - noHotbar != null) { + noHotbar != null) { when (blockTask.block) { fillerMat -> InventoryUtils.moveToSlot(noHotbar[0], 37) material -> InventoryUtils.moveToSlot(noHotbar[0], 38) @@ -912,8 +912,7 @@ object HighwayTools : Module() { append("\n §9> §7Coordinate: §a${startingBlockPos.z}§r") } } - if (startingBlockPos.y >= 118 && startingBlockPos.x < 120) append("\n §9> §7You should move to Y 120 to build proper highways") - + if (startingBlockPos.y >= 118 && startingBlockPos.x < 120) append("\n §9> §7You should move to Y 120 to build proper highways") sendChatMessage(toString()) } } @@ -924,8 +923,8 @@ object HighwayTools : Module() { StringBuilder(2).run { append( "$chatName Module stopped." + - "\n §9> §7Placed blocks: §a$totalBlocksPlaced§r" + - "\n §9> §7Destroyed blocks: §a$totalBlocksDestroyed§r" + "\n §9> §7Placed blocks: §a$totalBlocksPlaced§r" + + "\n §9> §7Destroyed blocks: §a$totalBlocksDestroyed§r" ) if (baritoneMode.value) append("\n §9> §7Distance: §a${getDistance(startingBlockPos.toVec3d(), currentBlockPos.toVec3d()).toInt()}§r") @@ -938,7 +937,7 @@ object HighwayTools : Module() { fun getBlueprintStats(): Pair { var materialUsed = 0 var fillerMatUsed = 0 - for ((_, b) in blueprint) { + for ((_, b) in bluePrint) { when (b) { material -> materialUsed++ fillerMat -> fillerMatUsed++ @@ -1021,8 +1020,8 @@ object HighwayTools : Module() { for (step in 1..3) { val pos = relativeDirection(currentBlockPos, step, 0) if (mc.world.getBlockState(pos.down()).block == material && - mc.world.getBlockState(pos).block == Blocks.AIR && - mc.world.getBlockState(pos.up()).block == Blocks.AIR) lastWalkable = pos + mc.world.getBlockState(pos).block == Blocks.AIR && + mc.world.getBlockState(pos.up()).block == Blocks.AIR) lastWalkable = pos else break } } @@ -1030,8 +1029,8 @@ object HighwayTools : Module() { for (step in 1..3) { val pos = relativeDirection(currentBlockPos, step, 0) if (mc.world.getBlockState(pos.down()).block == fillerMat && - mc.world.getBlockState(pos).block == Blocks.AIR && - mc.world.getBlockState(pos.up()).block == Blocks.AIR) lastWalkable = pos + mc.world.getBlockState(pos).block == Blocks.AIR && + mc.world.getBlockState(pos.up()).block == Blocks.AIR) lastWalkable = pos else break } } @@ -1071,23 +1070,23 @@ object HighwayTools : Module() { if (turn) turnValue = -1 if (mat != fillerMat) { if (height > 1) { - blueprint.add(Pair(relativeDirection(relativeDirection(cursor, 1, 3 * turnValue), width - 1, 2 * turnValue), Blocks.AIR)) + bluePrint.add(Pair(relativeDirection(relativeDirection(cursor, 1, 3 * turnValue), width - 1, 2 * turnValue), Blocks.AIR)) } else { - blueprint.add(Pair(relativeDirection(relativeDirection(cursor, 1, 3 * turnValue), width - 1, 2 * turnValue), mat)) + bluePrint.add(Pair(relativeDirection(relativeDirection(cursor, 1, 3 * turnValue), width - 1, 2 * turnValue), mat)) } } else { - blueprint.add(Pair(relativeDirection(relativeDirection(cursor, 1, 3 * turnValue), width - 1, 2 * turnValue), material)) + bluePrint.add(Pair(relativeDirection(relativeDirection(cursor, 1, 3 * turnValue), width - 1, 2 * turnValue), material)) } } private fun genOffset(cursor: BlockPos, height: Int, width: Int, mat: Block, isOdd: Boolean) { - blueprint.add(Pair(relativeDirection(cursor, width, -2), mat)) + bluePrint.add(Pair(relativeDirection(cursor, width, -2), mat)) if (buildDirectionSaved.isDiagonal) { addOffset(cursor, height, width, mat, true) } when { isOdd -> { - blueprint.add(Pair(relativeDirection(cursor, width, 2), mat)) + bluePrint.add(Pair(relativeDirection(cursor, width, 2), mat)) if (buildDirectionSaved.isDiagonal) { addOffset(cursor, height, width, mat, false) } @@ -1095,11 +1094,11 @@ object HighwayTools : Module() { else -> { val evenCursor = relativeDirection(cursor, 1, 2) if (buildDirectionSaved.isDiagonal) { - blueprint.add(Pair(relativeDirection(evenCursor, width, 2), mat)) + bluePrint.add(Pair(relativeDirection(evenCursor, width, 2), mat)) addOffset(cursor, height, width, mat, false) addOffset(evenCursor, height, width, mat, false) } else { - blueprint.add(Pair(relativeDirection(evenCursor, width, 2), mat)) + bluePrint.add(Pair(relativeDirection(evenCursor, width, 2), mat)) } } } @@ -1119,10 +1118,10 @@ object HighwayTools : Module() { Mode.HIGHWAY -> { if (baritoneMode.value) { cursor = relativeDirection(cursor, 1, 0) - blueprint.add(Pair(cursor, material)) + bluePrint.add(Pair(cursor, material)) } cursor = relativeDirection(cursor, 1, 0) - blueprint.add(Pair(cursor, material)) + bluePrint.add(Pair(cursor, material)) var buildIterationsWidth = buildWidth.value / 2 var evenCursor = relativeDirection(cursor, 1, 2) var isOdd = false @@ -1130,7 +1129,7 @@ object HighwayTools : Module() { isOdd = true buildIterationsWidth++ } else { - blueprint.add(Pair(evenCursor, material)) + bluePrint.add(Pair(evenCursor, material)) } for (i in 1 until clearHeight.value + 1) { for (j in 1 until buildIterationsWidth) { @@ -1153,18 +1152,18 @@ object HighwayTools : Module() { cursor = cursor.up() evenCursor = evenCursor.up() if (clearSpace.value && i < clearHeight.value) { - blueprint.add(Pair(cursor, Blocks.AIR)) - if (!isOdd) blueprint.add(Pair(evenCursor, Blocks.AIR)) + bluePrint.add(Pair(cursor, Blocks.AIR)) + if (!isOdd) bluePrint.add(Pair(evenCursor, Blocks.AIR)) } } } Mode.TUNNEL -> { if (baritoneMode.value) { cursor = relativeDirection(cursor, 1, 0) - blueprint.add(Pair(cursor, fillerMat)) + bluePrint.add(Pair(cursor, fillerMat)) } cursor = relativeDirection(cursor, 1, 0) - blueprint.add(Pair(cursor, fillerMat)) + bluePrint.add(Pair(cursor, fillerMat)) var buildIterationsWidth = buildWidth.value / 2 var evenCursor = relativeDirection(cursor, 1, 2) var isOdd = false @@ -1172,33 +1171,33 @@ object HighwayTools : Module() { isOdd = true buildIterationsWidth++ } else { - blueprint.add(Pair(evenCursor, fillerMat)) + bluePrint.add(Pair(evenCursor, fillerMat)) } for (i in 1 until clearHeight.value + 2) { for (j in 1 until buildIterationsWidth) { if (i > 1) { if (cornerBlock.value && i == 2 && j == buildIterationsWidth - 1) continue - blueprint.add(Pair(relativeDirection(cursor, j, -2), Blocks.AIR)) - if (isOdd) blueprint.add(Pair(relativeDirection(cursor, j, 2), Blocks.AIR)) - else blueprint.add(Pair(relativeDirection(evenCursor, j, 2), Blocks.AIR)) + bluePrint.add(Pair(relativeDirection(cursor, j, -2), Blocks.AIR)) + if (isOdd) bluePrint.add(Pair(relativeDirection(cursor, j, 2), Blocks.AIR)) + else bluePrint.add(Pair(relativeDirection(evenCursor, j, 2), Blocks.AIR)) if (buildDirectionSaved.isDiagonal) { - blueprint.add(Pair(relativeDirection(cursor, j, -3), Blocks.AIR)) - if (isOdd) blueprint.add(Pair(relativeDirection(cursor, j, 3), Blocks.AIR)) - else blueprint.add(Pair(relativeDirection(evenCursor, j, 3), Blocks.AIR)) + bluePrint.add(Pair(relativeDirection(cursor, j, -3), Blocks.AIR)) + if (isOdd) bluePrint.add(Pair(relativeDirection(cursor, j, 3), Blocks.AIR)) + else bluePrint.add(Pair(relativeDirection(evenCursor, j, 3), Blocks.AIR)) } } } cursor = cursor.up() evenCursor = evenCursor.up() if (clearSpace.value && i < clearHeight.value + 1) { - blueprint.add(Pair(cursor, Blocks.AIR)) - if (!isOdd) blueprint.add(Pair(evenCursor, Blocks.AIR)) + bluePrint.add(Pair(cursor, Blocks.AIR)) + if (!isOdd) bluePrint.add(Pair(evenCursor, Blocks.AIR)) } } } Mode.FLAT -> { for (bp in getBlockPositionsInArea(cursor.north(buildWidth.value).west(buildWidth.value), cursor.south(buildWidth.value).east(buildWidth.value))) { - blueprint.add(Pair(bp, material)) + bluePrint.add(Pair(bp, material)) } } null -> { @@ -1209,8 +1208,8 @@ object HighwayTools : Module() { } data class StuckManagement( - var stuckLevel: StuckLevel, - var stuckValue: Int + var stuckLevel: StuckLevel, + var stuckValue: Int ) { fun increase(blockTask: BlockTask) { @@ -1269,9 +1268,9 @@ object HighwayTools : Module() { } data class BlockTask( - val blockPos: BlockPos, - var taskState: TaskState, - var block: Block + val blockPos: BlockPos, + var taskState: TaskState, + var block: Block ) { override fun toString(): String { return "Block: " + block.localizedName + " @ Position: (" + blockPos.asString() + ") Priority: " + taskState.ordinal + " State: " + taskState.toString() @@ -1332,3 +1331,4 @@ object HighwayTools : Module() { MAYOR } } + From c96d1519843ff9c391fe121426595c66423662ca Mon Sep 17 00:00:00 2001 From: Natan <66911017+natan515@users.noreply.github.com> Date: Mon, 28 Dec 2020 07:45:40 +0200 Subject: [PATCH 117/390] fix --- .../me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 2c04e0dae1..2ab3ce31e2 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -912,7 +912,7 @@ object HighwayTools : Module() { append("\n §9> §7Coordinate: §a${startingBlockPos.z}§r") } } - if (startingBlockPos.y >= 118 && startingBlockPos.x < 120) append("\n §9> §7You should move to Y 120 to build proper highways") + if (startingBlockPos.y >= 118 && startingBlockPos.y < 120) append("\n §9> §7You should move to Y 120 to build proper highways") sendChatMessage(toString()) } } From afe6cf88ddef8148b2f3aae3db5e1893446fa8c5 Mon Sep 17 00:00:00 2001 From: Natan <66911017+natan515@users.noreply.github.com> Date: Mon, 28 Dec 2020 07:50:13 +0200 Subject: [PATCH 118/390] Update HighwayTools.kt --- .../me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 2ab3ce31e2..dc570f673d 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -912,7 +912,7 @@ object HighwayTools : Module() { append("\n §9> §7Coordinate: §a${startingBlockPos.z}§r") } } - if (startingBlockPos.y >= 118 && startingBlockPos.y < 120) append("\n §9> §7You should move to Y 120 to build proper highways") + if (startingBlockPos.y >= 117 && startingBlockPos.y < 120) append("\n §9> §7You should move to Y 120 to build proper highways") sendChatMessage(toString()) } } From 0290c8872028af98ec7b032fcb5d34a98b9559b3 Mon Sep 17 00:00:00 2001 From: Natan <66911017+natan515@users.noreply.github.com> Date: Mon, 28 Dec 2020 08:07:17 +0200 Subject: [PATCH 119/390] Wait sorry lol. this is the last edit. --- .../me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index dc570f673d..4d25e4b2d2 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -912,7 +912,7 @@ object HighwayTools : Module() { append("\n §9> §7Coordinate: §a${startingBlockPos.z}§r") } } - if (startingBlockPos.y >= 117 && startingBlockPos.y < 120) append("\n §9> §7You should move to Y 120 to build proper highways") + if (startingBlockPos.y in 117..119) append("\n §9> §7You should move to Y 120 to build proper highways") sendChatMessage(toString()) } } From 4c050101fc833ab96ecf13463867281f8faa4104 Mon Sep 17 00:00:00 2001 From: theredstoner Date: Sun, 27 Dec 2020 23:35:44 -0700 Subject: [PATCH 120/390] Show mode-specific exit message in AutoObsidian --- .../me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt index f07b1b2fd3..f866712052 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt @@ -42,6 +42,7 @@ import kotlin.math.min ) object AutoObsidian : Module() { private val mode = register(Settings.e("Mode", Mode.TARGETSTACKS)) + private val modeExitStrings = mapOf(Mode.FILLINVENTORY to "Inventory filled", Mode.TARGETSTACKS to "Target Stacks Reached") private val searchShulker = register(Settings.b("SearchShulker", false)) private val autoRefill = register(Settings.booleanBuilder("AutoRefill").withValue(false).withVisibility { mode.value != Mode.INFINITE }) @@ -158,10 +159,10 @@ object AutoObsidian : Module() { State.COLLECTING -> collectDroppedItem(ItemID.OBSIDIAN.id) State.DONE -> { if (!autoRefill.value) { - sendChatMessage("$chatName Reached target stacks, disabling.") + sendChatMessage("$chatName ".plus(modeExitStrings[mode.value]).plus(", disabling.")) this.disable() } else { - if (active) sendChatMessage("$chatName Reached target stacks, stopping.") + if (active) sendChatMessage("$chatName ".plus(modeExitStrings[mode.value]).plus(", stopping.")) reset() } } From 6ba352b08fb7ddf5c5b7a51771299a1dac89424e Mon Sep 17 00:00:00 2001 From: theredstoner Date: Mon, 28 Dec 2020 15:13:00 -0700 Subject: [PATCH 121/390] Fix fillInventory mode - Replace an assignment to an addition - Take into account the fact that every 64 ender chests gives us an additional slot to fill --- .../zeroeightsix/kami/module/modules/misc/AutoObsidian.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt index f866712052..a1b154bb51 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt @@ -275,10 +275,16 @@ object AutoObsidian : Module() { /* Pick floor: It is better to have an unfilled stack then overfill and get stuck trying to pick up extra obsidian */ - maxEnderChests = floor((64.0 - itemStack.count) / 8.0).toInt() + maxEnderChests += floor((64.0 - itemStack.count) / 8.0).toInt() } } } + /* Here we assume ender chests are stacked the most efficiently possible. For every 64 ender chests + mined, another item slot is freed, which allows us to mine an additional 8 ender chests to fill + that slot with obsidian. + */ + maxEnderChests += floor(maxEnderChests / 64.0).toInt() * 8 + return maxEnderChests } From e338f428d0f445405868e7f678b4ec2c79ec6675 Mon Sep 17 00:00:00 2001 From: zincodrone <59712311+zincodrone@users.noreply.github.com> Date: Mon, 28 Dec 2020 18:37:16 -0600 Subject: [PATCH 122/390] Possible Fix for AutoObsidian [Not able to Test] AutoObby has an issue where it will continue to pick up Obsidian. Even if your inventory is full so if there is extra obby it will keep you stuck standing over the obby. At line(s) 238: mc.player?.inventory?.mainInventory.let At line(s) 260: mc.player?.inventory?.mainInventory?.let Possible fix being instead of mc.player?.inventory?.mainInventory.let insert a another question mark mc.player?.inventory?.mainInventory?.let Otherwise, remove null values [?] or add a confirmation statement. If no changes work then I will attempt to start a testing process. --- .../me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt index ede6cdf301..e808a9f378 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt @@ -235,7 +235,7 @@ object AutoObsidian : Module() { */ private fun maxPossibleEnderChests(): Int { var maxEnderChests = 0 - mc.player?.inventory?.mainInventory.let { + mc.player?.inventory?.mainInventory?.let { val clonedList = ArrayList(it) for (itemStack in clonedList) { if(getIdFromItem(itemStack.item) == ItemID.AIR.id) { @@ -553,4 +553,4 @@ object AutoObsidian : Module() { tickCount = 0 } /* End of tasks */ -} \ No newline at end of file +} From e3ed0d0760a3ce0e2f3b26ea6451c5fd82cd63bc Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 29 Dec 2020 05:55:03 +0100 Subject: [PATCH 123/390] Blueprint name revert --- .../kami/module/modules/misc/HighwayTools.kt | 56 +++++++++---------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 6b038d969f..0e5c30e1de 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -110,7 +110,7 @@ object HighwayTools : Module() { // runtime vars val pendingTasks = PriorityQueue(BlockTaskComparator) private val doneTasks = ArrayList() - private val bluePrint = ArrayList>() + private val blueprint = ArrayList>() private var waitTicks = 0 private var blocksPlaced = 0 var pathing = false @@ -512,10 +512,10 @@ object HighwayTools : Module() { } private fun updateTasks(originPos: BlockPos) { - bluePrint.clear() + blueprint.clear() updateBlockArray(originPos) updateBlockArray(getNextBlock(originPos)) - for ((blockPos, blockType) in bluePrint) { + for ((blockPos, blockType) in blueprint) { val isReplaceable = mc.world.getBlockState(blockPos).material.isReplaceable if (blockPos == mc.player.positionVector.toBlockPos().down()) continue when (val block = mc.world.getBlockState(blockPos).block) { @@ -937,7 +937,7 @@ object HighwayTools : Module() { fun getBlueprintStats(): Pair { var materialUsed = 0 var fillerMatUsed = 0 - for ((_, b) in bluePrint) { + for ((_, b) in blueprint) { when (b) { material -> materialUsed++ fillerMat -> fillerMatUsed++ @@ -1070,23 +1070,23 @@ object HighwayTools : Module() { if (turn) turnValue = -1 if (mat != fillerMat) { if (height > 1) { - bluePrint.add(Pair(relativeDirection(relativeDirection(cursor, 1, 3 * turnValue), width - 1, 2 * turnValue), Blocks.AIR)) + blueprint.add(Pair(relativeDirection(relativeDirection(cursor, 1, 3 * turnValue), width - 1, 2 * turnValue), Blocks.AIR)) } else { - bluePrint.add(Pair(relativeDirection(relativeDirection(cursor, 1, 3 * turnValue), width - 1, 2 * turnValue), mat)) + blueprint.add(Pair(relativeDirection(relativeDirection(cursor, 1, 3 * turnValue), width - 1, 2 * turnValue), mat)) } } else { - bluePrint.add(Pair(relativeDirection(relativeDirection(cursor, 1, 3 * turnValue), width - 1, 2 * turnValue), material)) + blueprint.add(Pair(relativeDirection(relativeDirection(cursor, 1, 3 * turnValue), width - 1, 2 * turnValue), material)) } } private fun genOffset(cursor: BlockPos, height: Int, width: Int, mat: Block, isOdd: Boolean) { - bluePrint.add(Pair(relativeDirection(cursor, width, -2), mat)) + blueprint.add(Pair(relativeDirection(cursor, width, -2), mat)) if (buildDirectionSaved.isDiagonal) { addOffset(cursor, height, width, mat, true) } when { isOdd -> { - bluePrint.add(Pair(relativeDirection(cursor, width, 2), mat)) + blueprint.add(Pair(relativeDirection(cursor, width, 2), mat)) if (buildDirectionSaved.isDiagonal) { addOffset(cursor, height, width, mat, false) } @@ -1094,11 +1094,11 @@ object HighwayTools : Module() { else -> { val evenCursor = relativeDirection(cursor, 1, 2) if (buildDirectionSaved.isDiagonal) { - bluePrint.add(Pair(relativeDirection(evenCursor, width, 2), mat)) + blueprint.add(Pair(relativeDirection(evenCursor, width, 2), mat)) addOffset(cursor, height, width, mat, false) addOffset(evenCursor, height, width, mat, false) } else { - bluePrint.add(Pair(relativeDirection(evenCursor, width, 2), mat)) + blueprint.add(Pair(relativeDirection(evenCursor, width, 2), mat)) } } } @@ -1118,10 +1118,10 @@ object HighwayTools : Module() { Mode.HIGHWAY -> { if (baritoneMode.value) { cursor = relativeDirection(cursor, 1, 0) - bluePrint.add(Pair(cursor, material)) + blueprint.add(Pair(cursor, material)) } cursor = relativeDirection(cursor, 1, 0) - bluePrint.add(Pair(cursor, material)) + blueprint.add(Pair(cursor, material)) var buildIterationsWidth = buildWidth.value / 2 var evenCursor = relativeDirection(cursor, 1, 2) var isOdd = false @@ -1129,7 +1129,7 @@ object HighwayTools : Module() { isOdd = true buildIterationsWidth++ } else { - bluePrint.add(Pair(evenCursor, material)) + blueprint.add(Pair(evenCursor, material)) } for (i in 1 until clearHeight.value + 1) { for (j in 1 until buildIterationsWidth) { @@ -1152,18 +1152,18 @@ object HighwayTools : Module() { cursor = cursor.up() evenCursor = evenCursor.up() if (clearSpace.value && i < clearHeight.value) { - bluePrint.add(Pair(cursor, Blocks.AIR)) - if (!isOdd) bluePrint.add(Pair(evenCursor, Blocks.AIR)) + blueprint.add(Pair(cursor, Blocks.AIR)) + if (!isOdd) blueprint.add(Pair(evenCursor, Blocks.AIR)) } } } Mode.TUNNEL -> { if (baritoneMode.value) { cursor = relativeDirection(cursor, 1, 0) - bluePrint.add(Pair(cursor, fillerMat)) + blueprint.add(Pair(cursor, fillerMat)) } cursor = relativeDirection(cursor, 1, 0) - bluePrint.add(Pair(cursor, fillerMat)) + blueprint.add(Pair(cursor, fillerMat)) var buildIterationsWidth = buildWidth.value / 2 var evenCursor = relativeDirection(cursor, 1, 2) var isOdd = false @@ -1171,33 +1171,33 @@ object HighwayTools : Module() { isOdd = true buildIterationsWidth++ } else { - bluePrint.add(Pair(evenCursor, fillerMat)) + blueprint.add(Pair(evenCursor, fillerMat)) } for (i in 1 until clearHeight.value + 2) { for (j in 1 until buildIterationsWidth) { if (i > 1) { if (cornerBlock.value && i == 2 && j == buildIterationsWidth - 1) continue - bluePrint.add(Pair(relativeDirection(cursor, j, -2), Blocks.AIR)) - if (isOdd) bluePrint.add(Pair(relativeDirection(cursor, j, 2), Blocks.AIR)) - else bluePrint.add(Pair(relativeDirection(evenCursor, j, 2), Blocks.AIR)) + blueprint.add(Pair(relativeDirection(cursor, j, -2), Blocks.AIR)) + if (isOdd) blueprint.add(Pair(relativeDirection(cursor, j, 2), Blocks.AIR)) + else blueprint.add(Pair(relativeDirection(evenCursor, j, 2), Blocks.AIR)) if (buildDirectionSaved.isDiagonal) { - bluePrint.add(Pair(relativeDirection(cursor, j, -3), Blocks.AIR)) - if (isOdd) bluePrint.add(Pair(relativeDirection(cursor, j, 3), Blocks.AIR)) - else bluePrint.add(Pair(relativeDirection(evenCursor, j, 3), Blocks.AIR)) + blueprint.add(Pair(relativeDirection(cursor, j, -3), Blocks.AIR)) + if (isOdd) blueprint.add(Pair(relativeDirection(cursor, j, 3), Blocks.AIR)) + else blueprint.add(Pair(relativeDirection(evenCursor, j, 3), Blocks.AIR)) } } } cursor = cursor.up() evenCursor = evenCursor.up() if (clearSpace.value && i < clearHeight.value + 1) { - bluePrint.add(Pair(cursor, Blocks.AIR)) - if (!isOdd) bluePrint.add(Pair(evenCursor, Blocks.AIR)) + blueprint.add(Pair(cursor, Blocks.AIR)) + if (!isOdd) blueprint.add(Pair(evenCursor, Blocks.AIR)) } } } Mode.FLAT -> { for (bp in getBlockPositionsInArea(cursor.north(buildWidth.value).west(buildWidth.value), cursor.south(buildWidth.value).east(buildWidth.value))) { - bluePrint.add(Pair(bp, material)) + blueprint.add(Pair(bp, material)) } } null -> { From ee5a45b3bd57ba023047e4256a03311adac30994 Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 29 Dec 2020 06:04:13 +0100 Subject: [PATCH 124/390] Disable ToggleAutoObsidian on Tunnel mode --- .../me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 0e5c30e1de..6f49a685b7 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -139,7 +139,7 @@ object HighwayTools : Module() { if(toggleInventoryManager.value && InventoryManager.isDisabled) InventoryManager.enable() /* Turn on Auto Obsidian if the user wants us to control it. */ - if(toggleAutoObsidian.value && AutoObsidian.isDisabled) { + if(toggleAutoObsidian.value && AutoObsidian.isDisabled && mode.value != Mode.TUNNEL) { /* If we have no obsidian, immediately turn on Auto Obsidian */ if(InventoryUtils.countItemAll(49) == 0) { AutoObsidian.enable() From b9214c36d30d40e4dbe114a62a88d98872a6f03d Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 29 Dec 2020 06:23:07 +0100 Subject: [PATCH 125/390] Warning is better visible now. --- .../me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 6f49a685b7..4184e6f1e7 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -912,7 +912,7 @@ object HighwayTools : Module() { append("\n §9> §7Coordinate: §a${startingBlockPos.z}§r") } } - if (startingBlockPos.y in 117..119) append("\n §9> §7You should move to Y 120 to build proper highways") + if (startingBlockPos.y in 117..119) append("\n §9> §cCheck coordinate Y / altitude and make sure to move around Y 120 for the correct height") sendChatMessage(toString()) } } From 539d0cc02ef50e69b2b62ecb9074a3c18e076651 Mon Sep 17 00:00:00 2001 From: natan <2222natan@gmail.com> Date: Tue, 29 Dec 2020 11:54:19 +0200 Subject: [PATCH 126/390] Added Auto Tool so the player can chose it would start activating when the HT starts, i checked and it works great! Oh and i remove a thing from AutoObsidian.kt that haven't being used. --- .../zeroeightsix/kami/module/modules/misc/AutoObsidian.kt | 4 ++-- .../zeroeightsix/kami/module/modules/misc/HighwayTools.kt | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt index c5e1e0fb73..8ee921d787 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt @@ -8,7 +8,6 @@ import me.zeroeightsix.kami.setting.Settings import me.zeroeightsix.kami.util.BaritoneUtils import me.zeroeightsix.kami.util.BlockUtils.getHitVecOffset import me.zeroeightsix.kami.util.BlockUtils.isPlaceableForChest -import me.zeroeightsix.kami.util.EntityUtils import me.zeroeightsix.kami.util.EntityUtils.getDroppedItem import me.zeroeightsix.kami.util.InventoryUtils import me.zeroeightsix.kami.util.combat.SurroundUtils @@ -224,6 +223,7 @@ object AutoObsidian : Module() { targetEnderChest = maxEnderChests } } + state = when { (!canPickUpObsidian() && mode.value != Mode.INFINITE) -> State.DONE /* Never transition to done when in INFINITE mode */ state == State.DONE && autoRefill.value && InventoryUtils.countItemAll(ItemID.OBSIDIAN.id) <= threshold.value -> State.SEARCHING @@ -382,7 +382,7 @@ object AutoObsidian : Module() { return } } - /* Else, we already have enderchests in the hostbar */ + /* Else, we already have ender chests in the hotbar */ InventoryUtils.swapSlotToItem(ItemID.ENDER_CHEST.id) placeBlock(pos) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 4184e6f1e7..512c04c75f 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -75,6 +75,7 @@ object HighwayTools : Module() { private val interacting = register(Settings.enumBuilder(InteractMode::class.java, "InteractMode").withValue(InteractMode.SPOOF).withVisibility { page.value == Page.BEHAVIOR }) private val illegalPlacements = register(Settings.booleanBuilder("IllegalPlacements").withValue(false).withVisibility { page.value == Page.BEHAVIOR }) private val maxReach = register(Settings.floatBuilder("MaxReach").withValue(4.5F).withRange(1.0f, 6.0f).withStep(0.1f).withVisibility { page.value == Page.BEHAVIOR }) + private val toggleAutoTool = register(Settings.booleanBuilder("ToggleAutoTool").withValue(true).withVisibility { page.value == Page.BEHAVIOR }) private val toggleInventoryManager = register(Settings.booleanBuilder("ToggleInvManager").withValue(true).withVisibility { page.value == Page.BEHAVIOR }) private val toggleAutoObsidian = register(Settings.booleanBuilder("ToggleAutoObsidian").withValue(true).withVisibility { page.value == Page.BEHAVIOR }) @@ -135,6 +136,9 @@ object HighwayTools : Module() { return } + /* Turn on Auto Tool if the users wants us to control it */ + if(toggleAutoTool.value && AutoTool.isDisabled) AutoTool.enable() + /* Turn on inventory manager if the users wants us to control it */ if(toggleInventoryManager.value && InventoryManager.isDisabled) InventoryManager.enable() @@ -198,6 +202,9 @@ object HighwayTools : Module() { if (process != null && process.isPresent && process.get() == HighwayToolsProcess) process.get().onLostControl() } + /* Turn off Auto Tool if the users wants us to control it */ + if(toggleAutoTool.value && AutoTool.isEnabled) AutoTool.disable() + /* Turn off inventory manager if the users wants us to control it */ if(toggleInventoryManager.value && InventoryManager.isEnabled) InventoryManager.disable() From 708d628fc7a0775b99fa2a262e1e133bd179d89c Mon Sep 17 00:00:00 2001 From: Natan <66911017+Natan515@users.noreply.github.com> Date: Tue, 29 Dec 2020 15:27:18 +0200 Subject: [PATCH 127/390] Update gradle.properties --- gradle.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gradle.properties b/gradle.properties index 8a8e403e21..8b8013cace 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ org.gradle.jvmargs=-Xmx3G modGroup=me.zeroeightsix -modVersion=1.12.xx-dev-ht-v06 +modVersion=1.12.xx-dev-ht-v07 kotlin_version=1.4.21 -kotlinx_coroutines_version=1.4.1 \ No newline at end of file +kotlinx_coroutines_version=1.4.1 From a636c6b125e3a92f7c73aef518ad60cc0a209a19 Mon Sep 17 00:00:00 2001 From: natan <2222natan@gmail.com> Date: Tue, 29 Dec 2020 18:24:43 +0200 Subject: [PATCH 128/390] Fix tunnel mod issue with the right Y alert --- .../zeroeightsix/kami/module/modules/misc/HighwayTools.kt | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 512c04c75f..3a58763744 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -216,9 +216,7 @@ object HighwayTools : Module() { printDisable() } - fun isDone(): Boolean { - return pendingTasks.size == 0 - } + fun isDone(): Boolean = pendingTasks.size == 0 init { listener { @@ -919,7 +917,7 @@ object HighwayTools : Module() { append("\n §9> §7Coordinate: §a${startingBlockPos.z}§r") } } - if (startingBlockPos.y in 117..119) append("\n §9> §cCheck coordinate Y / altitude and make sure to move around Y 120 for the correct height") + if (startingBlockPos.y in 117..119 && mode.value != Mode.TUNNEL) append("\n §9> §cCheck coordinate Y / altitude and make sure to move around Y 120 for the correct height") sendChatMessage(toString()) } } From 73ce03ff39e9c99478d3ebf85ddbb65f15dbe91f Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 29 Dec 2020 23:07:12 +0100 Subject: [PATCH 129/390] Ideal tool selection for tasks --- .../kami/module/modules/misc/HighwayTools.kt | 54 +++++++++++++++---- 1 file changed, 43 insertions(+), 11 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 4184e6f1e7..068151803e 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -3,6 +3,7 @@ package me.zeroeightsix.kami.module.modules.misc import me.zeroeightsix.kami.event.events.RenderWorldEvent import me.zeroeightsix.kami.event.events.SafeTickEvent import me.zeroeightsix.kami.gui.kami.DisplayGuiScreen +import me.zeroeightsix.kami.mixin.extension.syncCurrentPlayItem import me.zeroeightsix.kami.module.Module import me.zeroeightsix.kami.module.modules.player.AutoEat import me.zeroeightsix.kami.module.modules.player.InventoryManager @@ -27,8 +28,11 @@ import me.zeroeightsix.kami.util.text.MessageSendHelper.sendChatMessage import net.minecraft.block.Block import net.minecraft.block.Block.getIdFromBlock import net.minecraft.block.BlockLiquid +import net.minecraft.block.state.IBlockState import net.minecraft.client.audio.PositionedSoundRecord +import net.minecraft.enchantment.EnchantmentHelper import net.minecraft.init.Blocks +import net.minecraft.init.Enchantments import net.minecraft.init.SoundEvents import net.minecraft.network.play.client.CPacketPlayer import net.minecraft.network.play.client.CPacketPlayerDigging @@ -41,6 +45,7 @@ import org.kamiblue.event.listener.listener import java.util.* import kotlin.collections.ArrayList import kotlin.math.abs +import kotlin.math.pow import kotlin.math.sqrt /** @@ -576,17 +581,18 @@ object HighwayTools : Module() { private fun inventoryProcessor(blockTask: BlockTask): Boolean { when (blockTask.taskState) { TaskState.BREAK, TaskState.EMERGENCY_BREAK -> { - val noHotbar = InventoryUtils.getSlotsNoHotbar(278) - if (InventoryUtils.getSlotsHotbar(278) == null && noHotbar != null) { -// InventoryUtils.moveToHotbar(278, 130) - InventoryUtils.moveToSlot(noHotbar[0], 36) - } else if (InventoryUtils.getSlots(0, 35, 278) == null) { - sendChatMessage("$chatName No Pickaxe was found in inventory") - mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) - disable() - return false - } - InventoryUtils.swapSlotToItem(278) + equipBestTool(mc.world.getBlockState(blockTask.blockPos)) +// val noHotbar = InventoryUtils.getSlotsNoHotbar(278) +// if (InventoryUtils.getSlotsHotbar(278) == null && noHotbar != null) { +//// InventoryUtils.moveToHotbar(278, 130) +// InventoryUtils.moveToSlot(noHotbar[0], 36) +// } else if (InventoryUtils.getSlots(0, 35, 278) == null) { +// sendChatMessage("$chatName No Pickaxe was found in inventory") +// mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) +// disable() +// return false +// } +// InventoryUtils.swapSlotToItem(278) } TaskState.PLACE, TaskState.LIQUID_FLOW, TaskState.LIQUID_SOURCE -> { val blockID = getIdFromBlock(blockTask.block) @@ -617,6 +623,32 @@ object HighwayTools : Module() { return true } + private fun equipBestTool(blockState: IBlockState) { + var bestSlot = -1 + var max = 0.0 + + for (i in 0..8) { + val stack = mc.player.inventory.getStackInSlot(i) + if (stack.isEmpty) continue + var speed = stack.getDestroySpeed(blockState) + var eff: Int + + if (speed > 1) { + speed += (if (EnchantmentHelper.getEnchantmentLevel(Enchantments.EFFICIENCY, stack).also { eff = it } > 0.0) eff.toDouble().pow(2.0) + 1 else 0.0).toFloat() + if (speed > max) { + max = speed.toDouble() + bestSlot = i + } + } + } + if (bestSlot != -1) equip(bestSlot) + } + + private fun equip(slot: Int) { + mc.player.inventory.currentItem = slot + mc.playerController.syncCurrentPlayItem() + } + private fun liquidHandler(blockTask: BlockTask): Boolean { var foundLiquid = false for (side in EnumFacing.values()) { From 73efb9f1502656ac92b8aeb1b7f8b9df05ecc274 Mon Sep 17 00:00:00 2001 From: natan <2222natan@gmail.com> Date: Wed, 30 Dec 2020 08:22:51 +0200 Subject: [PATCH 130/390] fix --- .../zeroeightsix/kami/module/modules/misc/HighwayTools.kt | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 3a58763744..55bb4305f3 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -75,7 +75,6 @@ object HighwayTools : Module() { private val interacting = register(Settings.enumBuilder(InteractMode::class.java, "InteractMode").withValue(InteractMode.SPOOF).withVisibility { page.value == Page.BEHAVIOR }) private val illegalPlacements = register(Settings.booleanBuilder("IllegalPlacements").withValue(false).withVisibility { page.value == Page.BEHAVIOR }) private val maxReach = register(Settings.floatBuilder("MaxReach").withValue(4.5F).withRange(1.0f, 6.0f).withStep(0.1f).withVisibility { page.value == Page.BEHAVIOR }) - private val toggleAutoTool = register(Settings.booleanBuilder("ToggleAutoTool").withValue(true).withVisibility { page.value == Page.BEHAVIOR }) private val toggleInventoryManager = register(Settings.booleanBuilder("ToggleInvManager").withValue(true).withVisibility { page.value == Page.BEHAVIOR }) private val toggleAutoObsidian = register(Settings.booleanBuilder("ToggleAutoObsidian").withValue(true).withVisibility { page.value == Page.BEHAVIOR }) @@ -136,9 +135,6 @@ object HighwayTools : Module() { return } - /* Turn on Auto Tool if the users wants us to control it */ - if(toggleAutoTool.value && AutoTool.isDisabled) AutoTool.enable() - /* Turn on inventory manager if the users wants us to control it */ if(toggleInventoryManager.value && InventoryManager.isDisabled) InventoryManager.enable() @@ -202,8 +198,6 @@ object HighwayTools : Module() { if (process != null && process.isPresent && process.get() == HighwayToolsProcess) process.get().onLostControl() } - /* Turn off Auto Tool if the users wants us to control it */ - if(toggleAutoTool.value && AutoTool.isEnabled) AutoTool.disable() /* Turn off inventory manager if the users wants us to control it */ if(toggleInventoryManager.value && InventoryManager.isEnabled) InventoryManager.disable() From 89030be53ab8f144b1be2194c474e33c2498ef07 Mon Sep 17 00:00:00 2001 From: natan <2222natan@gmail.com> Date: Wed, 30 Dec 2020 17:00:40 +0200 Subject: [PATCH 131/390] Added HT to DiscordRPC.kt But it doesn't look great so if u got suggestions let me know natan515#5842 --- .../me/zeroeightsix/kami/module/modules/misc/DiscordRPC.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/DiscordRPC.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/DiscordRPC.kt index cf44f36345..d26cc3fab8 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/DiscordRPC.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/DiscordRPC.kt @@ -32,7 +32,7 @@ object DiscordRPC : Module() { private val updateDelay = register(Settings.floatBuilder("UpdateDelay").withValue(4f).withRange(1f, 10f)) private enum class LineInfo { - VERSION, WORLD, DIMENSION, USERNAME, HEALTH, HUNGER, SERVER_IP, COORDS, SPEED, HELD_ITEM, FPS, TPS, NONE + VERSION, WORLD, DIMENSION, USERNAME, HEALTH, HUNGER, SERVER_IP, COORDS, SPEED, HELD_ITEM, FPS, TPS, TASK, NONE } private val presence = DiscordRichPresence() @@ -119,6 +119,10 @@ object DiscordRPC : Module() { LineInfo.DIMENSION -> { InfoCalculator.dimension() } + LineInfo.TASK -> { + if (HighwayTools.isEnabled) "Making highways" + else "" + } LineInfo.USERNAME -> { mc.session.username } From d5b94983bad47b9616a47358bdbebbd851c7a967 Mon Sep 17 00:00:00 2001 From: natan515 <2222natan@gmail.com> Date: Thu, 31 Dec 2020 23:06:25 +0200 Subject: [PATCH 132/390] Better RPC --- .../zeroeightsix/kami/module/modules/misc/DiscordRPC.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/DiscordRPC.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/DiscordRPC.kt index d26cc3fab8..ec323bf809 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/DiscordRPC.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/DiscordRPC.kt @@ -32,7 +32,7 @@ object DiscordRPC : Module() { private val updateDelay = register(Settings.floatBuilder("UpdateDelay").withValue(4f).withRange(1f, 10f)) private enum class LineInfo { - VERSION, WORLD, DIMENSION, USERNAME, HEALTH, HUNGER, SERVER_IP, COORDS, SPEED, HELD_ITEM, FPS, TPS, TASK, NONE + VERSION, WORLD, DIMENSION, USERNAME, HEALTH, HUNGER, SERVER_IP, COORDS, SPEED, HELD_ITEM, FPS, TPS, Highway_Work, NONE } private val presence = DiscordRichPresence() @@ -119,9 +119,9 @@ object DiscordRPC : Module() { LineInfo.DIMENSION -> { InfoCalculator.dimension() } - LineInfo.TASK -> { - if (HighwayTools.isEnabled) "Making highways" - else "" + LineInfo.Highway_Work -> { + if (HighwayTools.isEnabled) "Making Highways" + else "Doing Nothing" } LineInfo.USERNAME -> { mc.session.username From 8dd9d5a1e22fef50c7aa2bab0a6523e29715c63d Mon Sep 17 00:00:00 2001 From: Natan <66911017+Natan515@users.noreply.github.com> Date: Thu, 31 Dec 2020 23:18:37 +0200 Subject: [PATCH 133/390] FIX --- .../me/zeroeightsix/kami/module/modules/misc/DiscordRPC.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/DiscordRPC.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/DiscordRPC.kt index ec323bf809..50589f5e7b 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/DiscordRPC.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/DiscordRPC.kt @@ -32,7 +32,7 @@ object DiscordRPC : Module() { private val updateDelay = register(Settings.floatBuilder("UpdateDelay").withValue(4f).withRange(1f, 10f)) private enum class LineInfo { - VERSION, WORLD, DIMENSION, USERNAME, HEALTH, HUNGER, SERVER_IP, COORDS, SPEED, HELD_ITEM, FPS, TPS, Highway_Work, NONE + VERSION, WORLD, DIMENSION, USERNAME, HEALTH, HUNGER, SERVER_IP, COORDS, SPEED, HELD_ITEM, FPS, TPS, HIGHWAY__WORK, NONE } private val presence = DiscordRichPresence() @@ -119,7 +119,7 @@ object DiscordRPC : Module() { LineInfo.DIMENSION -> { InfoCalculator.dimension() } - LineInfo.Highway_Work -> { + LineInfo.HIGHWAY__WORK -> { if (HighwayTools.isEnabled) "Making Highways" else "Doing Nothing" } From b39905f0f3b1a2f8224ee258ce1aec88ec892d18 Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Thu, 31 Dec 2020 20:34:35 -0500 Subject: [PATCH 134/390] Fixed formatting, extracted duplicate code --- .../kami/module/modules/misc/AutoObsidian.kt | 113 ++++++++---------- 1 file changed, 53 insertions(+), 60 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt index 8ee921d787..4e2356e853 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt @@ -36,27 +36,27 @@ import kotlin.math.min @Module.Info( - name = "AutoObsidian", - category = Module.Category.MISC, - description = "Breaks down Ender Chests to restock obsidian" + name = "AutoObsidian", + category = Module.Category.MISC, + description = "Breaks down Ender Chests to restock obsidian" ) object AutoObsidian : Module() { - private val mode = register(Settings.e("Mode", Mode.TARGETSTACKS)) - private val modeExitStrings = mapOf(Mode.FILLINVENTORY to "Inventory filled", Mode.TARGETSTACKS to "Target Stacks Reached") + private val mode = register(Settings.e("Mode", Mode.TARGET_STACKS)) + private val modeExitStrings = mapOf(Mode.FILL_INVENTORY to "Inventory filled", Mode.TARGET_STACKS to "Target Stacks Reached") private val searchShulker = register(Settings.b("SearchShulker", false)) private val autoRefill = register(Settings.booleanBuilder("AutoRefill").withValue(false).withVisibility { mode.value != Mode.INFINITE }) private val threshold = register(Settings.integerBuilder("RefillThreshold").withValue(8).withRange(1, 56).withVisibility { autoRefill.value && mode.value != Mode.INFINITE }) - private val targetStacks = register(Settings.integerBuilder("TargetStacks").withValue(1).withRange(1, 20).withVisibility { mode.value == Mode.TARGETSTACKS }) + private val targetStacks = register(Settings.integerBuilder("TargetStacks").withValue(1).withRange(1, 20).withVisibility { mode.value == Mode.TARGET_STACKS }) private val delayTicks = register(Settings.integerBuilder("DelayTicks").withValue(5).withRange(0, 10)) private val interacting = register(Settings.enumBuilder(InteractMode::class.java).withName("InteractMode").withValue(InteractMode.SPOOF)) private val autoCenter = register(Settings.enumBuilder(AutoCenterMode::class.java).withName("AutoCenter").withValue(AutoCenterMode.MOTION)) private val maxReach = register(Settings.floatBuilder("MaxReach").withValue(4.5F).withRange(1.0f, 6.0f).withStep(0.1f)) private enum class Mode { - TARGETSTACKS, + TARGET_STACKS, INFINITE, - FILLINVENTORY + FILL_INVENTORY } enum class State { @@ -77,6 +77,7 @@ object AutoObsidian : Module() { DONE } + @Suppress("UNUSED") private enum class InteractMode { OFF, SPOOF, @@ -88,6 +89,7 @@ object AutoObsidian : Module() { TP, MOTION } + private enum class ItemID(val id: Int) { AIR(0), OBSIDIAN(49), @@ -213,15 +215,17 @@ object AutoObsidian : Module() { } /* Updates main state */ - var placedEnderChest = enderChestCount - InventoryUtils.countItemAll(ItemID.ENDER_CHEST.id) + val placedEnderChest = enderChestCount - InventoryUtils.countItemAll(ItemID.ENDER_CHEST.id) var targetEnderChest = -1 - when(mode.value) { - Mode.TARGETSTACKS -> { + when (mode.value) { + Mode.TARGET_STACKS -> { targetEnderChest = min((targetStacks.value * 64 - obsidianCount) / 8, maxEnderChests) } - Mode.FILLINVENTORY -> { + Mode.FILL_INVENTORY -> { targetEnderChest = maxEnderChests } + else -> { + } } state = when { @@ -269,10 +273,9 @@ object AutoObsidian : Module() { mc.player?.inventory?.mainInventory?.let { val clonedList = ArrayList(it) for (itemStack in clonedList) { - if(getIdFromItem(itemStack.item) == ItemID.AIR.id) { + if (getIdFromItem(itemStack.item) == ItemID.AIR.id) { maxEnderChests += 8 - } - else if(getIdFromItem(itemStack.item) == ItemID.OBSIDIAN.id) { + } else if (getIdFromItem(itemStack.item) == ItemID.OBSIDIAN.id) { /* Pick floor: It is better to have an unfilled stack then overfill and get stuck trying to pick up extra obsidian */ @@ -298,11 +301,11 @@ object AutoObsidian : Module() { val clonedList = ArrayList(it) for (itemStack in clonedList) { /* If there is an air block slot, we have an open inventory slot */ - if(getIdFromItem(itemStack.item) == ItemID.AIR.id) { + if (getIdFromItem(itemStack.item) == ItemID.AIR.id) { return true } /* If there is a non-full stack of obsidian, we have an open inventory slot */ - if((getIdFromItem(itemStack.item) == ItemID.OBSIDIAN.id) && itemStack.count < 64) { + if ((getIdFromItem(itemStack.item) == ItemID.OBSIDIAN.id) && itemStack.count < 64) { return true } } @@ -390,7 +393,7 @@ object AutoObsidian : Module() { private fun openShulker(pos: BlockPos) { - if(mc.currentScreen is GuiShulkerBox) { + if (mc.currentScreen is GuiShulkerBox) { Thread { /* Extra delay here to wait for the item list to be loaded */ Thread.sleep(delayTicks.value * 50L) @@ -412,12 +415,14 @@ object AutoObsidian : Module() { } }.start() } else { - var rayTrace = mc.world.rayTraceBlocks(mc.player.getPositionEyes(1f), Vec3d(pos).add(0.5, 0.5, 0.5)) ?: return + var rayTrace = mc.world.rayTraceBlocks(mc.player.getPositionEyes(1f), Vec3d(pos).add(0.5, 0.5, 0.5)) + ?: return if (rayTrace.blockPos != pos) { var found = false for (side in EnumFacing.values()) { if (mc.world.getBlockState(pos.offset(side)).block == Blocks.AIR) { - rayTrace = mc.world.rayTraceBlocks(mc.player.getPositionEyes(1f), Vec3d(pos).add(0.5, 0.5, 0.5).add(Vec3d(side.directionVec).scale(0.499)))?: continue + rayTrace = mc.world.rayTraceBlocks(mc.player.getPositionEyes(1f), Vec3d(pos).add(0.5, 0.5, 0.5).add(Vec3d(side.directionVec).scale(0.499))) + ?: continue if (rayTrace.blockPos == pos) { found = true break @@ -428,23 +433,14 @@ object AutoObsidian : Module() { return } } - val hitVecOffset = rayTrace.hitVec - val rotation = getRotationTo(hitVecOffset, true) - when (interacting.value) { - InteractMode.SPOOF -> { - val rotationPacket = CPacketPlayer.PositionRotation(mc.player.posX, mc.player.posY, mc.player.posZ, rotation.x.toFloat(), rotation.y.toFloat(), mc.player.onGround) - mc.connection!!.sendPacket(rotationPacket) - } - InteractMode.VIEWLOCK -> { - mc.player.rotationYaw = rotation.x.toFloat() - mc.player.rotationPitch = rotation.y.toFloat() - } - } + + rotation(rayTrace.hitVec) + val hitVecOffset = rayTrace.hitVec.subtract(Vec3d(rayTrace.blockPos)) /* Added a delay here so it doesn't spam right click and get you kicked */ if (System.currentTimeMillis() >= openTime + 2000L) { openTime = System.currentTimeMillis() - Thread{ + Thread { Thread.sleep(delayTicks.value * 25L) val placePacket = CPacketPlayerTryUseItemOnBlock(rayTrace.blockPos, rayTrace.sideHit, EnumHand.MAIN_HAND, hitVecOffset.x.toFloat(), hitVecOffset.y.toFloat(), hitVecOffset.z.toFloat()) mc.connection!!.sendPacket(placePacket) @@ -462,7 +458,7 @@ object AutoObsidian : Module() { if (mc.world.getBlockState(offPos).material.isReplaceable) continue if (mc.player.getPositionEyes(1f).distanceTo(Vec3d(offPos).add(getHitVecOffset(side))) > maxReach.value) continue val rotationVector = Vec3d(offPos).add(0.5, 0.5, 0.5).add(Vec3d(side.opposite.directionVec).scale(0.499)) - val rt = mc.world.rayTraceBlocks(mc.player.getPositionEyes(1f), rotationVector)?: continue + val rt = mc.world.rayTraceBlocks(mc.player.getPositionEyes(1f), rotationVector) ?: continue if (rt.typeOfHit != RayTraceResult.Type.BLOCK) continue if (rt.blockPos == offPos && offPos.offset(rt.sideHit) == pos) { rayTraces.add(rt) @@ -487,20 +483,10 @@ object AutoObsidian : Module() { return } - val hitVecOffset = rayTrace.hitVec - val rotation = getRotationTo(hitVecOffset, true) - when (interacting.value) { - InteractMode.SPOOF -> { - val rotationPacket = CPacketPlayer.PositionRotation(mc.player.posX, mc.player.posY, mc.player.posZ, rotation.x.toFloat(), rotation.y.toFloat(), mc.player.onGround) - mc.connection!!.sendPacket(rotationPacket) - } - InteractMode.VIEWLOCK -> { - mc.player.rotationYaw = rotation.x.toFloat() - mc.player.rotationPitch = rotation.y.toFloat() - } - } + rotation(rayTrace.hitVec) + val hitVecOffset = rayTrace.hitVec.subtract(Vec3d(rayTrace.blockPos)) - Thread{ + Thread { Thread.sleep(delayTicks.value * 25L) val placePacket = CPacketPlayerTryUseItemOnBlock(rayTrace.blockPos, rayTrace.sideHit, EnumHand.MAIN_HAND, hitVecOffset.x.toFloat(), hitVecOffset.y.toFloat(), hitVecOffset.z.toFloat()) mc.connection!!.sendPacket(placePacket) @@ -522,12 +508,14 @@ object AutoObsidian : Module() { InventoryUtils.swapSlotToItem(ItemID.DIAMOND_PICKAXE.id) } - var rayTrace = mc.world.rayTraceBlocks(mc.player.getPositionEyes(1f), Vec3d(pos).add(0.5, 0.5, 0.5)) ?: return false + var rayTrace = mc.world.rayTraceBlocks(mc.player.getPositionEyes(1f), Vec3d(pos).add(0.5, 0.5, 0.5)) + ?: return false if (rayTrace.blockPos != pos) { var found = false for (side in EnumFacing.values()) { if (mc.world.getBlockState(pos.offset(side)).block == Blocks.AIR) { - rayTrace = mc.world.rayTraceBlocks(mc.player.getPositionEyes(1f), Vec3d(pos).add(0.5, 0.5, 0.5).add(Vec3d(side.directionVec).scale(0.499)))?: continue + rayTrace = mc.world.rayTraceBlocks(mc.player.getPositionEyes(1f), Vec3d(pos).add(0.5, 0.5, 0.5).add(Vec3d(side.directionVec).scale(0.499))) + ?: continue if (rayTrace.blockPos == pos) { found = true break @@ -538,18 +526,9 @@ object AutoObsidian : Module() { return false } } + val facing = rayTrace.sideHit ?: return false - val rotation = getRotationTo(rayTrace.hitVec, true) - when (interacting.value) { - InteractMode.SPOOF -> { - val rotationPacket = CPacketPlayer.PositionRotation(mc.player.posX, mc.player.posY, mc.player.posZ, rotation.x.toFloat(), rotation.y.toFloat(), mc.player.onGround) - mc.connection!!.sendPacket(rotationPacket) - } - InteractMode.VIEWLOCK -> { - mc.player.rotationYaw = rotation.x.toFloat() - mc.player.rotationPitch = rotation.y.toFloat() - } - } + rotation(rayTrace.hitVec) Thread { Thread.sleep(delayTicks.value * 25L) @@ -564,6 +543,20 @@ object AutoObsidian : Module() { return true } + private fun rotation(hitVec: Vec3d) { + val rotation = getRotationTo(hitVec, true) + when (interacting.value) { + InteractMode.SPOOF -> { + val rotationPacket = CPacketPlayer.PositionRotation(mc.player.posX, mc.player.posY, mc.player.posZ, rotation.x.toFloat(), rotation.y.toFloat(), mc.player.onGround) + mc.connection!!.sendPacket(rotationPacket) + } + InteractMode.VIEWLOCK -> { + mc.player.rotationYaw = rotation.x.toFloat() + mc.player.rotationPitch = rotation.y.toFloat() + } + } + } + private fun collectDroppedItem(itemId: Int) { pathing = if (getDroppedItem(itemId, 16.0f) != null) { goal = getDroppedItem(itemId, 16.0f) From 710d3c07c38df94078793bc56c17a69780802689 Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Thu, 31 Dec 2020 23:41:52 -0500 Subject: [PATCH 135/390] Cleaned up states code --- .../kami/module/modules/misc/AutoObsidian.kt | 252 ++++++++---------- 1 file changed, 114 insertions(+), 138 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt index 4e2356e853..b05ba58b9f 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt @@ -8,9 +8,11 @@ import me.zeroeightsix.kami.setting.Settings import me.zeroeightsix.kami.util.BaritoneUtils import me.zeroeightsix.kami.util.BlockUtils.getHitVecOffset import me.zeroeightsix.kami.util.BlockUtils.isPlaceableForChest +import me.zeroeightsix.kami.util.EntityUtils import me.zeroeightsix.kami.util.EntityUtils.getDroppedItem import me.zeroeightsix.kami.util.InventoryUtils import me.zeroeightsix.kami.util.combat.SurroundUtils +import me.zeroeightsix.kami.util.id import me.zeroeightsix.kami.util.math.RotationUtils.getRotationTo import me.zeroeightsix.kami.util.text.MessageSendHelper.sendChatMessage import net.minecraft.block.BlockShulkerBox @@ -32,7 +34,6 @@ import net.minecraftforge.fml.common.gameevent.TickEvent import org.kamiblue.event.listener.listener import kotlin.math.ceil import kotlin.math.floor -import kotlin.math.min @Module.Info( @@ -91,7 +92,6 @@ object AutoObsidian : Module() { } private enum class ItemID(val id: Int) { - AIR(0), OBSIDIAN(49), ENDER_CHEST(130), DIAMOND_PICKAXE(278) @@ -106,9 +106,6 @@ object AutoObsidian : Module() { private var playerPos = BlockPos(0, -1, 0) private var placingPos = BlockPos(0, -1, 0) private var shulkerBoxId = 0 - private var enderChestCount = -1 - private var maxEnderChests = -1 /* The number of ender chests required to completely fill an inventory */ - private var obsidianCount = -1 private var tickCount = 0 private var openTime = 0L @@ -121,67 +118,49 @@ object AutoObsidian : Module() { state = State.SEARCHING } + override fun onDisable() { + reset() + } + init { listener { - if (it.phase != TickEvent.Phase.END) { - if (mc.playerController == null) return@listener - - if (tickCount < delayTicks.value) { - tickCount++ - return@listener - } else tickCount = 0 - - updateState() - when (state) { - - /* Searching states */ - State.SEARCHING -> { - if (searchShulker.value) { - when (searchingState) { - SearchingState.PLACING -> placeShulker(placingPos) - SearchingState.OPENING -> openShulker(placingPos) - SearchingState.PRE_MINING -> mineBlock(placingPos, true) - SearchingState.MINING -> mineBlock(placingPos, false) - SearchingState.COLLECTING -> collectDroppedItem(shulkerBoxId) - SearchingState.DONE -> { - /* Positions need to be updated after moving while collecting dropped shulker box */ - val currentPos = BlockPos(floor(mc.player.posX).toInt(), floor(mc.player.posY).toInt(), floor(mc.player.posZ).toInt()) - playerPos = currentPos - centerPlayer() - setPlacingPos() - } - } - } else searchingState = SearchingState.DONE - } + if (it.phase != TickEvent.Phase.END || mc.playerController == null) return@listener - /* Main states */ - State.PLACING -> placeEnderChest(placingPos) - State.PRE_MINING -> mineBlock(placingPos, true) - State.MINING -> mineBlock(placingPos, false) - State.COLLECTING -> collectDroppedItem(ItemID.OBSIDIAN.id) - State.DONE -> { - if (!autoRefill.value) { - sendChatMessage("$chatName ".plus(modeExitStrings[mode.value]).plus(", disabling.")) - this.disable() - } else { - if (active) sendChatMessage("$chatName ".plus(modeExitStrings[mode.value]).plus(", stopping.")) - reset() - } - } - } - } else { + if (tickCount < delayTicks.value) { + tickCount++ return@listener + } else { + tickCount = 0 } - } - } - override fun onDisable() { - BaritoneUtils.primary?.pathingControlManager?.mostRecentInControl()?.let { - if (it.isPresent && it.get() == AutoObsidianProcess) { - it.get().onLostControl() + updateState() + when (state) { + State.SEARCHING -> { + searchingState() + } + State.PLACING -> { + placeEnderChest(placingPos) + } + State.PRE_MINING -> { + mineBlock(placingPos, true) + } + State.MINING -> { + mineBlock(placingPos, false) + } + State.COLLECTING -> { + collectDroppedItem(ItemID.OBSIDIAN.id) + } + State.DONE -> { + if (!autoRefill.value) { + sendChatMessage("$chatName ".plus(modeExitStrings[mode.value]).plus(", disabling.")) + this.disable() + } else { + if (active) sendChatMessage("$chatName ".plus(modeExitStrings[mode.value]).plus(", stopping.")) + reset() + } + } } } - reset() } private fun updateState() { @@ -207,117 +186,115 @@ object AutoObsidian : Module() { } } - /* Updates ender chest and obsidian counts before placing and mining ender chest */ - if (state == State.SEARCHING) { - enderChestCount = InventoryUtils.countItemAll(ItemID.ENDER_CHEST.id) - maxEnderChests = maxPossibleEnderChests() - obsidianCount = countObsidian() - } + updateMainState() + updateSearchingState() + } + + private fun updateMainState() { + val obbyCount = countObby() - /* Updates main state */ - val placedEnderChest = enderChestCount - InventoryUtils.countItemAll(ItemID.ENDER_CHEST.id) - var targetEnderChest = -1 - when (mode.value) { - Mode.TARGET_STACKS -> { - targetEnderChest = min((targetStacks.value * 64 - obsidianCount) / 8, maxEnderChests) + state = when { + (!canPickUpObsidian() && mode.value != Mode.INFINITE) -> { + State.DONE /* Never transition to done when in INFINITE mode */ } - Mode.FILL_INVENTORY -> { - targetEnderChest = maxEnderChests + state == State.DONE && autoRefill.value && InventoryUtils.countItemAll(ItemID.OBSIDIAN.id) <= threshold.value -> { + State.SEARCHING + } + state == State.COLLECTING && getDroppedItem(ItemID.OBSIDIAN.id, 8.0f) == null -> { + State.DONE + } + state != State.DONE && mc.world.isAirBlock(placingPos) && mode.value != Mode.INFINITE && obbyCount >= targetStacks.value -> { + State.COLLECTING + } + state == State.MINING && mc.world.isAirBlock(placingPos) -> { + State.PLACING + } + state == State.PLACING && !mc.world.isAirBlock(placingPos) -> { + State.PRE_MINING + } + state == State.SEARCHING && searchingState == SearchingState.DONE && (mode.value == Mode.INFINITE || obbyCount < targetStacks.value) -> { + State.PLACING } else -> { + state } } + } - state = when { - (!canPickUpObsidian() && mode.value != Mode.INFINITE) -> State.DONE /* Never transition to done when in INFINITE mode */ - state == State.DONE && autoRefill.value && InventoryUtils.countItemAll(ItemID.OBSIDIAN.id) <= threshold.value -> State.SEARCHING - state == State.COLLECTING && getDroppedItem(ItemID.OBSIDIAN.id, 16.0f) == null -> State.DONE - state != State.DONE && mc.world.isAirBlock(placingPos) && placedEnderChest >= targetEnderChest && mode.value != Mode.INFINITE -> State.COLLECTING - state == State.MINING && mc.world.isAirBlock(placingPos) -> State.PLACING - state == State.PLACING && !mc.world.isAirBlock(placingPos) -> State.PRE_MINING - state == State.SEARCHING && searchingState == SearchingState.DONE && (placedEnderChest < targetEnderChest || mode.value == Mode.INFINITE) -> State.PLACING - else -> state - } + private fun countObby(): Int { + val inventory = InventoryUtils.countItemAll(49) + val dropped = EntityUtils.getDroppedItems(49, 8.0f).sumBy { it.item.count } + return ceil((inventory + dropped) / 8.0f).toInt() / 8 + } + private fun updateSearchingState() { /* Updates searching state */ if (state == State.SEARCHING && searchingState != SearchingState.DONE) { searchingState = when { - searchingState == SearchingState.PLACING && InventoryUtils.countItemAll(ItemID.ENDER_CHEST.id) > 0 -> SearchingState.DONE - searchingState == SearchingState.COLLECTING && getDroppedItem(shulkerBoxId, 16.0f) == null -> SearchingState.DONE + searchingState == SearchingState.PLACING && InventoryUtils.countItemAll(ItemID.ENDER_CHEST.id) > 0 -> { + SearchingState.DONE + } + searchingState == SearchingState.COLLECTING && getDroppedItem(shulkerBoxId, 8.0f) == null -> { + SearchingState.DONE + } searchingState == SearchingState.MINING && mc.world.isAirBlock(placingPos) -> { if (InventoryUtils.countItemAll(ItemID.ENDER_CHEST.id) > 0) { SearchingState.COLLECTING - } else { /* In case if the shulker wasn't placed due to server lag */ + } else { + // In case if the shulker wasn't placed due to server lag SearchingState.PLACING } } - searchingState == SearchingState.OPENING && (InventoryUtils.countItemAll(ItemID.ENDER_CHEST.id) >= 64 || InventoryUtils.getSlots(0, 35, 0) == null) -> SearchingState.PRE_MINING + searchingState == SearchingState.OPENING && (InventoryUtils.countItemAll(ItemID.ENDER_CHEST.id) >= 64 + || InventoryUtils.getSlots(0, 35, 0) == null) -> { + SearchingState.PRE_MINING + } searchingState == SearchingState.PLACING && !mc.world.isAirBlock(placingPos) -> { if (mc.world.getBlockState(placingPos).block is BlockShulkerBox) { SearchingState.OPENING - } else { /* In case if the shulker wasn't placed due to server lag */ + } else { + // In case if the shulker wasn't placed due to server lag SearchingState.PRE_MINING } } - else -> searchingState - } - } else if (state != State.SEARCHING) searchingState = SearchingState.PLACING - - } - - /* - Calculate the maximum possible ender chests we can break given the current space in our inventory - */ - private fun maxPossibleEnderChests(): Int { - var maxEnderChests = 0 - mc.player?.inventory?.mainInventory?.let { - val clonedList = ArrayList(it) - for (itemStack in clonedList) { - if (getIdFromItem(itemStack.item) == ItemID.AIR.id) { - maxEnderChests += 8 - } else if (getIdFromItem(itemStack.item) == ItemID.OBSIDIAN.id) { - /* Pick floor: It is better to have an unfilled stack then overfill and get stuck trying to pick - up extra obsidian - */ - maxEnderChests += floor((64.0 - itemStack.count) / 8.0).toInt() + else -> { + searchingState } } + } else if (state != State.SEARCHING) { + searchingState = SearchingState.PLACING } - /* Here we assume ender chests are stacked the most efficiently possible. For every 64 ender chests - mined, another item slot is freed, which allows us to mine an additional 8 ender chests to fill - that slot with obsidian. - */ - maxEnderChests += floor(maxEnderChests / 64.0).toInt() * 8 - - return maxEnderChests } - /* - Check if we can pick up more obsidian: - There must be at least one slot which is either empty, or contains a stack of obsidian less than 64 - */ + /** + * Check if we can pick up more obsidian: + * There must be at least one slot which is either empty, or contains a stack of obsidian less than 64 + */ private fun canPickUpObsidian(): Boolean { - mc.player?.inventory?.mainInventory?.let { - val clonedList = ArrayList(it) - for (itemStack in clonedList) { - /* If there is an air block slot, we have an open inventory slot */ - if (getIdFromItem(itemStack.item) == ItemID.AIR.id) { - return true - } - /* If there is a non-full stack of obsidian, we have an open inventory slot */ - if ((getIdFromItem(itemStack.item) == ItemID.OBSIDIAN.id) && itemStack.count < 64) { - return true + return mc.player?.inventory?.mainInventory?.any { + it.isEmpty || it.item.id == ItemID.OBSIDIAN.id && it.count < 64 + } ?: false + } + + private fun searchingState() { + if (searchShulker.value) { + when (searchingState) { + SearchingState.PLACING -> placeShulker(placingPos) + SearchingState.OPENING -> openShulker(placingPos) + SearchingState.PRE_MINING -> mineBlock(placingPos, true) + SearchingState.MINING -> mineBlock(placingPos, false) + SearchingState.COLLECTING -> collectDroppedItem(shulkerBoxId) + SearchingState.DONE -> { + /* Positions need to be updated after moving while collecting dropped shulker box */ + val currentPos = BlockPos(floor(mc.player.posX).toInt(), floor(mc.player.posY).toInt(), floor(mc.player.posZ).toInt()) + playerPos = currentPos + centerPlayer() + setPlacingPos() } } + } else { + searchingState = SearchingState.DONE } - - /* No matches to eligible slots, we can not pick up any more items */ - return false - } - - /* Return the obsidian count, rounded up to the nearest 8th */ - private fun countObsidian(): Int { - return ceil(InventoryUtils.countItemAll(ItemID.OBSIDIAN.id).toDouble() / 8.0).toInt() * 8 } private fun setPlacingPos() { @@ -580,5 +557,4 @@ object AutoObsidian : Module() { placingPos = BlockPos(0, -1, 0) tickCount = 0 } - /* End of tasks */ } From 854faf674a4a64d4fbc42e2d4ce27f8ebb179534 Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Thu, 31 Dec 2020 23:44:03 -0500 Subject: [PATCH 136/390] Fixed thread safety --- .../kami/module/modules/misc/AutoObsidian.kt | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt index b05ba58b9f..17f69190a7 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt @@ -5,14 +5,11 @@ import me.zeroeightsix.kami.module.Module import me.zeroeightsix.kami.module.modules.player.NoBreakAnimation import me.zeroeightsix.kami.process.AutoObsidianProcess import me.zeroeightsix.kami.setting.Settings -import me.zeroeightsix.kami.util.BaritoneUtils +import me.zeroeightsix.kami.util.* import me.zeroeightsix.kami.util.BlockUtils.getHitVecOffset import me.zeroeightsix.kami.util.BlockUtils.isPlaceableForChest -import me.zeroeightsix.kami.util.EntityUtils import me.zeroeightsix.kami.util.EntityUtils.getDroppedItem -import me.zeroeightsix.kami.util.InventoryUtils import me.zeroeightsix.kami.util.combat.SurroundUtils -import me.zeroeightsix.kami.util.id import me.zeroeightsix.kami.util.math.RotationUtils.getRotationTo import me.zeroeightsix.kami.util.text.MessageSendHelper.sendChatMessage import net.minecraft.block.BlockShulkerBox @@ -382,13 +379,15 @@ object AutoObsidian : Module() { break } } - if (enderChestSlot != -1) { - mc.playerController.windowClick(currentContainer.windowId, enderChestSlot, 0, ClickType.QUICK_MOVE, mc.player) - mc.player.closeScreen() - } else { - sendChatMessage("$chatName No ender chest was found in shulker, disabling.") - mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) - this.disable() + onMainThreadSafe { + if (enderChestSlot != -1) { + playerController.windowClick(currentContainer.windowId, enderChestSlot, 0, ClickType.QUICK_MOVE, Companion.mc.player) + player.closeScreen() + } else { + sendChatMessage("$chatName No ender chest was found in shulker, disabling.") + mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) + disable() + } } }.start() } else { From 840f46082e394c554ec2a8c63896a9348182d496 Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Thu, 31 Dec 2020 23:49:22 -0500 Subject: [PATCH 137/390] Cleaned up placeBlock() --- .../kami/module/modules/misc/AutoObsidian.kt | 50 ++++++++----------- 1 file changed, 21 insertions(+), 29 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt index 17f69190a7..9cd675bb4f 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt @@ -6,11 +6,11 @@ import me.zeroeightsix.kami.module.modules.player.NoBreakAnimation import me.zeroeightsix.kami.process.AutoObsidianProcess import me.zeroeightsix.kami.setting.Settings import me.zeroeightsix.kami.util.* -import me.zeroeightsix.kami.util.BlockUtils.getHitVecOffset import me.zeroeightsix.kami.util.BlockUtils.isPlaceableForChest import me.zeroeightsix.kami.util.EntityUtils.getDroppedItem import me.zeroeightsix.kami.util.combat.SurroundUtils import me.zeroeightsix.kami.util.math.RotationUtils.getRotationTo +import me.zeroeightsix.kami.util.math.VectorUtils.toVec3d import me.zeroeightsix.kami.util.text.MessageSendHelper.sendChatMessage import net.minecraft.block.BlockShulkerBox import net.minecraft.client.audio.PositionedSoundRecord @@ -419,7 +419,7 @@ object AutoObsidian : Module() { Thread { Thread.sleep(delayTicks.value * 25L) val placePacket = CPacketPlayerTryUseItemOnBlock(rayTrace.blockPos, rayTrace.sideHit, EnumHand.MAIN_HAND, hitVecOffset.x.toFloat(), hitVecOffset.y.toFloat(), hitVecOffset.z.toFloat()) - mc.connection!!.sendPacket(placePacket) + mc.connection?.sendPacket(placePacket) mc.player.swingArm(EnumHand.MAIN_HAND) if (NoBreakAnimation.isEnabled) NoBreakAnimation.resetMining() }.start() @@ -428,36 +428,28 @@ object AutoObsidian : Module() { } private fun placeBlock(pos: BlockPos) { - val rayTraces = mutableListOf() + val results = mutableListOf() + val eyePos = mc.player.getPositionEyes(1f) + for (side in EnumFacing.values()) { val offPos = pos.offset(side) if (mc.world.getBlockState(offPos).material.isReplaceable) continue - if (mc.player.getPositionEyes(1f).distanceTo(Vec3d(offPos).add(getHitVecOffset(side))) > maxReach.value) continue - val rotationVector = Vec3d(offPos).add(0.5, 0.5, 0.5).add(Vec3d(side.opposite.directionVec).scale(0.499)) - val rt = mc.world.rayTraceBlocks(mc.player.getPositionEyes(1f), rotationVector) ?: continue - if (rt.typeOfHit != RayTraceResult.Type.BLOCK) continue - if (rt.blockPos == offPos && offPos.offset(rt.sideHit) == pos) { - rayTraces.add(rt) + + val hitVec = offPos.toVec3d().add(Vec3d(side.opposite.directionVec).scale(0.499)) + if (eyePos.distanceTo(hitVec) > maxReach.value) continue + + val rayTraceResult = mc.world.rayTraceBlocks(eyePos, hitVec) ?: continue + if (rayTraceResult.typeOfHit != RayTraceResult.Type.BLOCK) continue + if (rayTraceResult.blockPos == offPos && offPos.offset(rayTraceResult.sideHit) == pos) { + results.add(rayTraceResult) } } - if (rayTraces.size == 0) { - sendChatMessage("Position: $pos not available") - // placeBlockWall(pos, mat) - return - } - var rayTrace: RayTraceResult? = null - var shortestRT = 99.0 - for (rt in rayTraces) { - if (mc.player.getPositionEyes(1f).distanceTo(Vec3d(rt.blockPos).add(getHitVecOffset(rt.sideHit))) < shortestRT) { - shortestRT = mc.player.getPositionEyes(1f).distanceTo(Vec3d(rt.blockPos).add(getHitVecOffset(rt.sideHit))) - rayTrace = rt + val rayTrace = results.minByOrNull { eyePos.distanceTo(it.hitVec) } + ?: run { + sendChatMessage("Can't find any vector?") + return } - } - if (rayTrace == null) { - sendChatMessage("Can't find any vector?") - return - } rotation(rayTrace.hitVec) val hitVecOffset = rayTrace.hitVec.subtract(Vec3d(rayTrace.blockPos)) @@ -465,7 +457,7 @@ object AutoObsidian : Module() { Thread { Thread.sleep(delayTicks.value * 25L) val placePacket = CPacketPlayerTryUseItemOnBlock(rayTrace.blockPos, rayTrace.sideHit, EnumHand.MAIN_HAND, hitVecOffset.x.toFloat(), hitVecOffset.y.toFloat(), hitVecOffset.z.toFloat()) - mc.connection!!.sendPacket(placePacket) + mc.connection?.sendPacket(placePacket) mc.player.swingArm(EnumHand.MAIN_HAND) if (NoBreakAnimation.isEnabled) NoBreakAnimation.resetMining() }.start() @@ -509,10 +501,10 @@ object AutoObsidian : Module() { Thread { Thread.sleep(delayTicks.value * 25L) if (pre) { - mc.connection!!.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, pos, facing)) + mc.connection?.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, pos, facing)) if (state != State.SEARCHING) state = State.MINING else searchingState = SearchingState.MINING } else { - mc.connection!!.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, pos, facing)) + mc.connection?.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, pos, facing)) } mc.player.swingArm(EnumHand.MAIN_HAND) }.start() @@ -524,7 +516,7 @@ object AutoObsidian : Module() { when (interacting.value) { InteractMode.SPOOF -> { val rotationPacket = CPacketPlayer.PositionRotation(mc.player.posX, mc.player.posY, mc.player.posZ, rotation.x.toFloat(), rotation.y.toFloat(), mc.player.onGround) - mc.connection!!.sendPacket(rotationPacket) + mc.connection?.sendPacket(rotationPacket) } InteractMode.VIEWLOCK -> { mc.player.rotationYaw = rotation.x.toFloat() From 8908fa374eb7f4009d98cf3ee760341f5624a4a9 Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Fri, 1 Jan 2021 00:02:40 -0500 Subject: [PATCH 138/390] Cleaned up raytrace code --- .../kami/module/modules/misc/AutoObsidian.kt | 80 +++---------------- 1 file changed, 12 insertions(+), 68 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt index 9cd675bb4f..479da1787c 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt @@ -15,17 +15,14 @@ import me.zeroeightsix.kami.util.text.MessageSendHelper.sendChatMessage import net.minecraft.block.BlockShulkerBox import net.minecraft.client.audio.PositionedSoundRecord import net.minecraft.client.gui.inventory.GuiShulkerBox -import net.minecraft.init.Blocks import net.minecraft.init.SoundEvents import net.minecraft.inventory.ClickType -import net.minecraft.item.Item.getIdFromItem import net.minecraft.network.play.client.CPacketPlayer import net.minecraft.network.play.client.CPacketPlayerDigging import net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock import net.minecraft.util.EnumFacing import net.minecraft.util.EnumHand import net.minecraft.util.math.BlockPos -import net.minecraft.util.math.RayTraceResult import net.minecraft.util.math.Vec3d import net.minecraftforge.fml.common.gameevent.TickEvent import org.kamiblue.event.listener.listener @@ -374,7 +371,7 @@ object AutoObsidian : Module() { val currentContainer = mc.player.openContainer var enderChestSlot = -1 for (i in 0..26) { - if (getIdFromItem(currentContainer.inventory[i].item) == ItemID.ENDER_CHEST.id) { + if (currentContainer.inventory[i].item.id == ItemID.ENDER_CHEST.id) { enderChestSlot = i break } @@ -391,34 +388,17 @@ object AutoObsidian : Module() { } }.start() } else { - var rayTrace = mc.world.rayTraceBlocks(mc.player.getPositionEyes(1f), Vec3d(pos).add(0.5, 0.5, 0.5)) - ?: return - if (rayTrace.blockPos != pos) { - var found = false - for (side in EnumFacing.values()) { - if (mc.world.getBlockState(pos.offset(side)).block == Blocks.AIR) { - rayTrace = mc.world.rayTraceBlocks(mc.player.getPositionEyes(1f), Vec3d(pos).add(0.5, 0.5, 0.5).add(Vec3d(side.directionVec).scale(0.499))) - ?: continue - if (rayTrace.blockPos == pos) { - found = true - break - } - } - } - if (!found) { - return - } - } + val side = EnumFacing.getDirectionFromEntityLiving(pos, mc.player) + val hitVecOffset = BlockUtils.getHitVecOffset(side) - rotation(rayTrace.hitVec) - val hitVecOffset = rayTrace.hitVec.subtract(Vec3d(rayTrace.blockPos)) + rotation(pos.toVec3d().add(hitVecOffset)) /* Added a delay here so it doesn't spam right click and get you kicked */ if (System.currentTimeMillis() >= openTime + 2000L) { openTime = System.currentTimeMillis() Thread { Thread.sleep(delayTicks.value * 25L) - val placePacket = CPacketPlayerTryUseItemOnBlock(rayTrace.blockPos, rayTrace.sideHit, EnumHand.MAIN_HAND, hitVecOffset.x.toFloat(), hitVecOffset.y.toFloat(), hitVecOffset.z.toFloat()) + val placePacket = CPacketPlayerTryUseItemOnBlock(pos, side, EnumHand.MAIN_HAND, hitVecOffset.x.toFloat(), hitVecOffset.y.toFloat(), hitVecOffset.z.toFloat()) mc.connection?.sendPacket(placePacket) mc.player.swingArm(EnumHand.MAIN_HAND) if (NoBreakAnimation.isEnabled) NoBreakAnimation.resetMining() @@ -428,35 +408,17 @@ object AutoObsidian : Module() { } private fun placeBlock(pos: BlockPos) { - val results = mutableListOf() - val eyePos = mc.player.getPositionEyes(1f) - - for (side in EnumFacing.values()) { - val offPos = pos.offset(side) - if (mc.world.getBlockState(offPos).material.isReplaceable) continue - - val hitVec = offPos.toVec3d().add(Vec3d(side.opposite.directionVec).scale(0.499)) - if (eyePos.distanceTo(hitVec) > maxReach.value) continue - - val rayTraceResult = mc.world.rayTraceBlocks(eyePos, hitVec) ?: continue - if (rayTraceResult.typeOfHit != RayTraceResult.Type.BLOCK) continue - if (rayTraceResult.blockPos == offPos && offPos.offset(rayTraceResult.sideHit) == pos) { - results.add(rayTraceResult) - } - } - - val rayTrace = results.minByOrNull { eyePos.distanceTo(it.hitVec) } + val pair = BlockUtils.getNeighbour(pos, 1) ?: run { - sendChatMessage("Can't find any vector?") + sendChatMessage("Can't find neighbour block") return } - rotation(rayTrace.hitVec) - val hitVecOffset = rayTrace.hitVec.subtract(Vec3d(rayTrace.blockPos)) + val hitVecOffset = BlockUtils.getHitVecOffset(pair.first) Thread { Thread.sleep(delayTicks.value * 25L) - val placePacket = CPacketPlayerTryUseItemOnBlock(rayTrace.blockPos, rayTrace.sideHit, EnumHand.MAIN_HAND, hitVecOffset.x.toFloat(), hitVecOffset.y.toFloat(), hitVecOffset.z.toFloat()) + val placePacket = CPacketPlayerTryUseItemOnBlock(pair.second, pair.first, EnumHand.MAIN_HAND, hitVecOffset.x.toFloat(), hitVecOffset.y.toFloat(), hitVecOffset.z.toFloat()) mc.connection?.sendPacket(placePacket) mc.player.swingArm(EnumHand.MAIN_HAND) if (NoBreakAnimation.isEnabled) NoBreakAnimation.resetMining() @@ -476,36 +438,18 @@ object AutoObsidian : Module() { InventoryUtils.swapSlotToItem(ItemID.DIAMOND_PICKAXE.id) } - var rayTrace = mc.world.rayTraceBlocks(mc.player.getPositionEyes(1f), Vec3d(pos).add(0.5, 0.5, 0.5)) - ?: return false - if (rayTrace.blockPos != pos) { - var found = false - for (side in EnumFacing.values()) { - if (mc.world.getBlockState(pos.offset(side)).block == Blocks.AIR) { - rayTrace = mc.world.rayTraceBlocks(mc.player.getPositionEyes(1f), Vec3d(pos).add(0.5, 0.5, 0.5).add(Vec3d(side.directionVec).scale(0.499))) - ?: continue - if (rayTrace.blockPos == pos) { - found = true - break - } - } - } - if (!found) { - return false - } - } - - val facing = rayTrace.sideHit ?: return false - rotation(rayTrace.hitVec) + val facing = EnumFacing.getDirectionFromEntityLiving(pos, mc.player) Thread { Thread.sleep(delayTicks.value * 25L) + if (pre) { mc.connection?.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, pos, facing)) if (state != State.SEARCHING) state = State.MINING else searchingState = SearchingState.MINING } else { mc.connection?.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, pos, facing)) } + mc.player.swingArm(EnumHand.MAIN_HAND) }.start() return true From 55a5d5c3c836f6e99fd2e1d6379f88ef51bef750 Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Fri, 1 Jan 2021 00:14:47 -0500 Subject: [PATCH 139/390] Rewrote placing position finding --- .../kami/module/modules/misc/AutoObsidian.kt | 46 +++++++++---------- .../me/zeroeightsix/kami/util/BlockUtils.kt | 9 ---- 2 files changed, 23 insertions(+), 32 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt index 479da1787c..b8640308d2 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt @@ -6,10 +6,10 @@ import me.zeroeightsix.kami.module.modules.player.NoBreakAnimation import me.zeroeightsix.kami.process.AutoObsidianProcess import me.zeroeightsix.kami.setting.Settings import me.zeroeightsix.kami.util.* -import me.zeroeightsix.kami.util.BlockUtils.isPlaceableForChest import me.zeroeightsix.kami.util.EntityUtils.getDroppedItem import me.zeroeightsix.kami.util.combat.SurroundUtils import me.zeroeightsix.kami.util.math.RotationUtils.getRotationTo +import me.zeroeightsix.kami.util.math.VectorUtils.toBlockPos import me.zeroeightsix.kami.util.math.VectorUtils.toVec3d import me.zeroeightsix.kami.util.text.MessageSendHelper.sendChatMessage import net.minecraft.block.BlockShulkerBox @@ -292,34 +292,34 @@ object AutoObsidian : Module() { } private fun setPlacingPos() { - if (getPlacingPos().y != -1) { - placingPos = getPlacingPos() + val feetPos = mc.player.positionVector.toBlockPos() + val eyePos = mc.player.getPositionEyes(1f) + var validPos: BlockPos? = null + + for (x in -4..4) { + for (y in -4..4) { + for (z in -4..4) { + val pos = feetPos.add(x, y, z) + if (eyePos.distanceTo(pos.toVec3d()) > maxReach.value) continue + + if (mc.world.getBlockState(pos.down()).material.isReplaceable) continue + if (!BlockUtils.isPlaceable(pos) || !BlockUtils.isPlaceable(pos.up())) continue + + validPos = pos + break + } + } + } + + if (validPos != null) { + placingPos = validPos } else { sendChatMessage("$chatName No valid position for placing shulker box / ender chest nearby, disabling.") mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) this.disable() - return } } - private fun getPlacingPos(): BlockPos { - val pos = playerPos - var facing = EnumFacing.NORTH - for (i in 1..4) { - val posOffset = pos.offset(facing) - val posOffsetDiagonal = posOffset.offset(facing.rotateY()) - when { - isPlaceableForChest(posOffset) -> return posOffset - isPlaceableForChest(posOffset.up()) -> return posOffset.up() - isPlaceableForChest(posOffsetDiagonal) -> return posOffsetDiagonal - isPlaceableForChest(posOffsetDiagonal.up()) -> return posOffsetDiagonal.up() - else -> facing = facing.rotateY() - } - } - return BlockPos(0, -1, 0) - } - - /* Tasks */ private fun placeShulker(pos: BlockPos) { for (i in 219..234) { if (InventoryUtils.getSlotsHotbar(i) == null) { @@ -356,13 +356,13 @@ object AutoObsidian : Module() { return } } + /* Else, we already have ender chests in the hotbar */ InventoryUtils.swapSlotToItem(ItemID.ENDER_CHEST.id) placeBlock(pos) } - private fun openShulker(pos: BlockPos) { if (mc.currentScreen is GuiShulkerBox) { Thread { diff --git a/src/main/java/me/zeroeightsix/kami/util/BlockUtils.kt b/src/main/java/me/zeroeightsix/kami/util/BlockUtils.kt index b9159667e7..1e98a65619 100644 --- a/src/main/java/me/zeroeightsix/kami/util/BlockUtils.kt +++ b/src/main/java/me/zeroeightsix/kami/util/BlockUtils.kt @@ -139,15 +139,6 @@ object BlockUtils { fun isPlaceable(pos: BlockPos, ignoreSelfCollide: Boolean = false) = mc.world.getBlockState(pos).material.isReplaceable && mc.world.checkNoEntityCollision(AxisAlignedBB(pos), if (ignoreSelfCollide) mc.player else null) - /** - * Checks if given [pos] is able to chest (air above) block in it - * - * @return true playing is not colliding with [pos] and there is block below it - */ - fun isPlaceableForChest(pos: BlockPos): Boolean { - return isPlaceable(pos) && !mc.world.getBlockState(pos.down()).material.isReplaceable && mc.world.isAirBlock(pos.up()) - } - fun buildStructure(placeSpeed: Float, getPlaceInfo: (HashSet) -> Pair?) { val emptyHashSet = HashSet() val placed = HashSet() From 68fbdfebeb52e89cab67b37fff5dd46cc20bac43 Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Fri, 1 Jan 2021 00:18:23 -0500 Subject: [PATCH 140/390] Readable enum names --- .../kami/module/modules/misc/AutoObsidian.kt | 55 ++++++++++--------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt index b8640308d2..de17dea3d1 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt @@ -25,6 +25,7 @@ import net.minecraft.util.EnumHand import net.minecraft.util.math.BlockPos import net.minecraft.util.math.Vec3d import net.minecraftforge.fml.common.gameevent.TickEvent +import org.kamiblue.commons.interfaces.DisplayEnum import org.kamiblue.event.listener.listener import kotlin.math.ceil import kotlin.math.floor @@ -48,41 +49,41 @@ object AutoObsidian : Module() { private val autoCenter = register(Settings.enumBuilder(AutoCenterMode::class.java).withName("AutoCenter").withValue(AutoCenterMode.MOTION)) private val maxReach = register(Settings.floatBuilder("MaxReach").withValue(4.5F).withRange(1.0f, 6.0f).withStep(0.1f)) - private enum class Mode { - TARGET_STACKS, - INFINITE, - FILL_INVENTORY + private enum class Mode(override val displayName: String) : DisplayEnum { + TARGET_STACKS("Target stacks"), + INFINITE("Infinite"), + FILL_INVENTORY("Fill inventory") } - enum class State { - SEARCHING, - PLACING, - PRE_MINING, - MINING, - COLLECTING, - DONE + enum class State(override val displayName: String) : DisplayEnum { + SEARCHING("Searching"), + PLACING("Placing"), + PRE_MINING("Pre mining"), + MINING("Mining"), + COLLECTING("Collecting"), + DONE("Done") } - private enum class SearchingState { - PLACING, - OPENING, - PRE_MINING, - MINING, - COLLECTING, - DONE + private enum class SearchingState(override val displayName: String) : DisplayEnum { + PLACING("SearchingState"), + OPENING("Opening"), + PRE_MINING("Pre mining"), + MINING("Mining"), + COLLECTING("Collecting"), + DONE("Done") } @Suppress("UNUSED") - private enum class InteractMode { - OFF, - SPOOF, - VIEWLOCK + private enum class InteractMode(override val displayName: String) : DisplayEnum { + OFF("Off"), + SPOOF("Spoof"), + VIEW_LOCK("View Lock") } - private enum class AutoCenterMode { - OFF, - TP, - MOTION + private enum class AutoCenterMode(override val displayName: String) : DisplayEnum { + OFF("Off"), + TP("Teleport"), + MOTION("Motion") } private enum class ItemID(val id: Int) { @@ -462,7 +463,7 @@ object AutoObsidian : Module() { val rotationPacket = CPacketPlayer.PositionRotation(mc.player.posX, mc.player.posY, mc.player.posZ, rotation.x.toFloat(), rotation.y.toFloat(), mc.player.onGround) mc.connection?.sendPacket(rotationPacket) } - InteractMode.VIEWLOCK -> { + InteractMode.VIEW_LOCK -> { mc.player.rotationYaw = rotation.x.toFloat() mc.player.rotationPitch = rotation.y.toFloat() } From 4453bca4ffa8c49830680e32bb8af43d97285cc5 Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Fri, 1 Jan 2021 00:26:28 -0500 Subject: [PATCH 141/390] Rewrote obby counting --- .../kami/module/modules/misc/AutoObsidian.kt | 54 ++++++++++++++----- 1 file changed, 41 insertions(+), 13 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt index de17dea3d1..b9be25b000 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt @@ -37,22 +37,22 @@ import kotlin.math.floor description = "Breaks down Ender Chests to restock obsidian" ) object AutoObsidian : Module() { - private val mode = register(Settings.e("Mode", Mode.TARGET_STACKS)) - private val modeExitStrings = mapOf(Mode.FILL_INVENTORY to "Inventory filled", Mode.TARGET_STACKS to "Target Stacks Reached") + private val fillMode = register(Settings.e("FillMode", FillMode.TARGET_STACKS)) + private val modeExitStrings = mapOf(FillMode.FILL_INVENTORY to "Inventory filled", FillMode.TARGET_STACKS to "Target Stacks Reached") private val searchShulker = register(Settings.b("SearchShulker", false)) - private val autoRefill = register(Settings.booleanBuilder("AutoRefill").withValue(false).withVisibility { mode.value != Mode.INFINITE }) - private val threshold = register(Settings.integerBuilder("RefillThreshold").withValue(8).withRange(1, 56).withVisibility { autoRefill.value && mode.value != Mode.INFINITE }) - private val targetStacks = register(Settings.integerBuilder("TargetStacks").withValue(1).withRange(1, 20).withVisibility { mode.value == Mode.TARGET_STACKS }) + private val autoRefill = register(Settings.booleanBuilder("AutoRefill").withValue(false).withVisibility { fillMode.value != FillMode.INFINITE }) + private val threshold = register(Settings.integerBuilder("RefillThreshold").withValue(8).withRange(1, 56).withVisibility { autoRefill.value && fillMode.value != FillMode.INFINITE }) + private val targetStacks = register(Settings.integerBuilder("TargetStacks").withValue(1).withRange(1, 20).withVisibility { fillMode.value == FillMode.TARGET_STACKS }) private val delayTicks = register(Settings.integerBuilder("DelayTicks").withValue(5).withRange(0, 10)) private val interacting = register(Settings.enumBuilder(InteractMode::class.java).withName("InteractMode").withValue(InteractMode.SPOOF)) private val autoCenter = register(Settings.enumBuilder(AutoCenterMode::class.java).withName("AutoCenter").withValue(AutoCenterMode.MOTION)) private val maxReach = register(Settings.floatBuilder("MaxReach").withValue(4.5F).withRange(1.0f, 6.0f).withStep(0.1f)) - private enum class Mode(override val displayName: String) : DisplayEnum { + private enum class FillMode(override val displayName: String) : DisplayEnum { TARGET_STACKS("Target stacks"), - INFINITE("Infinite"), - FILL_INVENTORY("Fill inventory") + FILL_INVENTORY("Fill inventory"), + INFINITE("Infinite") } enum class State(override val displayName: String) : DisplayEnum { @@ -147,10 +147,10 @@ object AutoObsidian : Module() { } State.DONE -> { if (!autoRefill.value) { - sendChatMessage("$chatName ".plus(modeExitStrings[mode.value]).plus(", disabling.")) + sendChatMessage("$chatName ".plus(modeExitStrings[fillMode.value]).plus(", disabling.")) this.disable() } else { - if (active) sendChatMessage("$chatName ".plus(modeExitStrings[mode.value]).plus(", stopping.")) + if (active) sendChatMessage("$chatName ".plus(modeExitStrings[fillMode.value]).plus(", stopping.")) reset() } } @@ -187,9 +187,10 @@ object AutoObsidian : Module() { private fun updateMainState() { val obbyCount = countObby() + val slotCount = countEmptySlots() state = when { - (!canPickUpObsidian() && mode.value != Mode.INFINITE) -> { + (!canPickUpObsidian() && fillMode.value != FillMode.INFINITE) -> { State.DONE /* Never transition to done when in INFINITE mode */ } state == State.DONE && autoRefill.value && InventoryUtils.countItemAll(ItemID.OBSIDIAN.id) <= threshold.value -> { @@ -198,7 +199,7 @@ object AutoObsidian : Module() { state == State.COLLECTING && getDroppedItem(ItemID.OBSIDIAN.id, 8.0f) == null -> { State.DONE } - state != State.DONE && mc.world.isAirBlock(placingPos) && mode.value != Mode.INFINITE && obbyCount >= targetStacks.value -> { + state != State.DONE && mc.world.isAirBlock(placingPos) && !checkObbyCount(obbyCount, slotCount) -> { State.COLLECTING } state == State.MINING && mc.world.isAirBlock(placingPos) -> { @@ -207,7 +208,7 @@ object AutoObsidian : Module() { state == State.PLACING && !mc.world.isAirBlock(placingPos) -> { State.PRE_MINING } - state == State.SEARCHING && searchingState == SearchingState.DONE && (mode.value == Mode.INFINITE || obbyCount < targetStacks.value) -> { + state == State.SEARCHING && searchingState == SearchingState.DONE && checkObbyCount(obbyCount, slotCount) -> { State.PLACING } else -> { @@ -216,12 +217,39 @@ object AutoObsidian : Module() { } } + /** + * @return True if can still place more ender chest + */ + private fun checkObbyCount(obbyCount: Int, slotCount: Int): Boolean { + return when (fillMode.value!!) { + FillMode.TARGET_STACKS -> { + obbyCount < targetStacks.value + } + FillMode.FILL_INVENTORY -> { + slotCount > 8 + } + FillMode.INFINITE -> { + true + } + } + } + private fun countObby(): Int { val inventory = InventoryUtils.countItemAll(49) val dropped = EntityUtils.getDroppedItems(49, 8.0f).sumBy { it.item.count } return ceil((inventory + dropped) / 8.0f).toInt() / 8 } + private fun countEmptySlots(): Int { + return mc.player?.inventory?.mainInventory?.sumBy { + when { + it.isEmpty -> 64 + it.item.id == ItemID.OBSIDIAN.id -> 64 - it.count + else -> 0 + } + } ?: 0 + } + private fun updateSearchingState() { /* Updates searching state */ if (state == State.SEARCHING && searchingState != SearchingState.DONE) { From b4b6906589caa1f465bc296a4ce4d30905af2058 Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Fri, 1 Jan 2021 00:29:50 -0500 Subject: [PATCH 142/390] Cleaned up position finding code --- .../kami/module/modules/misc/AutoObsidian.kt | 56 ++++--------------- 1 file changed, 10 insertions(+), 46 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt index b9be25b000..5277e39c53 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt @@ -7,7 +7,6 @@ import me.zeroeightsix.kami.process.AutoObsidianProcess import me.zeroeightsix.kami.setting.Settings import me.zeroeightsix.kami.util.* import me.zeroeightsix.kami.util.EntityUtils.getDroppedItem -import me.zeroeightsix.kami.util.combat.SurroundUtils import me.zeroeightsix.kami.util.math.RotationUtils.getRotationTo import me.zeroeightsix.kami.util.math.VectorUtils.toBlockPos import me.zeroeightsix.kami.util.math.VectorUtils.toVec3d @@ -28,7 +27,6 @@ import net.minecraftforge.fml.common.gameevent.TickEvent import org.kamiblue.commons.interfaces.DisplayEnum import org.kamiblue.event.listener.listener import kotlin.math.ceil -import kotlin.math.floor @Module.Info( @@ -46,7 +44,6 @@ object AutoObsidian : Module() { private val targetStacks = register(Settings.integerBuilder("TargetStacks").withValue(1).withRange(1, 20).withVisibility { fillMode.value == FillMode.TARGET_STACKS }) private val delayTicks = register(Settings.integerBuilder("DelayTicks").withValue(5).withRange(0, 10)) private val interacting = register(Settings.enumBuilder(InteractMode::class.java).withName("InteractMode").withValue(InteractMode.SPOOF)) - private val autoCenter = register(Settings.enumBuilder(AutoCenterMode::class.java).withName("AutoCenter").withValue(AutoCenterMode.MOTION)) private val maxReach = register(Settings.floatBuilder("MaxReach").withValue(4.5F).withRange(1.0f, 6.0f).withStep(0.1f)) private enum class FillMode(override val displayName: String) : DisplayEnum { @@ -80,12 +77,6 @@ object AutoObsidian : Module() { VIEW_LOCK("View Lock") } - private enum class AutoCenterMode(override val displayName: String) : DisplayEnum { - OFF("Off"), - TP("Teleport"), - MOTION("Motion") - } - private enum class ItemID(val id: Int) { OBSIDIAN(49), ENDER_CHEST(130), @@ -98,7 +89,6 @@ object AutoObsidian : Module() { private var active = false private var searchingState = SearchingState.PLACING - private var playerPos = BlockPos(0, -1, 0) private var placingPos = BlockPos(0, -1, 0) private var shulkerBoxId = 0 private var tickCount = 0 @@ -159,9 +149,7 @@ object AutoObsidian : Module() { } private fun updateState() { - val currentPos = BlockPos(floor(mc.player.posX).toInt(), floor(mc.player.posY).toInt(), floor(mc.player.posZ).toInt()) if (state != State.DONE && placingPos.y == -1) { - playerPos = currentPos setPlacingPos() } @@ -170,17 +158,6 @@ object AutoObsidian : Module() { BaritoneUtils.primary?.pathingControlManager?.registerProcess(AutoObsidianProcess) } - /* Tell baritone to get you back to position */ - if (state != State.DONE && state != State.COLLECTING && searchingState != SearchingState.COLLECTING) { - if (currentPos.x != playerPos.x || currentPos.z != playerPos.z) { - pathing = true - goal = playerPos - return - } else { - pathing = false - } - } - updateMainState() updateSearchingState() } @@ -217,6 +194,16 @@ object AutoObsidian : Module() { } } + /** + * Check if we can pick up more obsidian: + * There must be at least one slot which is either empty, or contains a stack of obsidian less than 64 + */ + private fun canPickUpObsidian(): Boolean { + return mc.player?.inventory?.mainInventory?.any { + it.isEmpty || it.item.id == ItemID.OBSIDIAN.id && it.count < 64 + } ?: false + } + /** * @return True if can still place more ender chest */ @@ -289,16 +276,6 @@ object AutoObsidian : Module() { } } - /** - * Check if we can pick up more obsidian: - * There must be at least one slot which is either empty, or contains a stack of obsidian less than 64 - */ - private fun canPickUpObsidian(): Boolean { - return mc.player?.inventory?.mainInventory?.any { - it.isEmpty || it.item.id == ItemID.OBSIDIAN.id && it.count < 64 - } ?: false - } - private fun searchingState() { if (searchShulker.value) { when (searchingState) { @@ -308,10 +285,6 @@ object AutoObsidian : Module() { SearchingState.MINING -> mineBlock(placingPos, false) SearchingState.COLLECTING -> collectDroppedItem(shulkerBoxId) SearchingState.DONE -> { - /* Positions need to be updated after moving while collecting dropped shulker box */ - val currentPos = BlockPos(floor(mc.player.posX).toInt(), floor(mc.player.posY).toInt(), floor(mc.player.posZ).toInt()) - playerPos = currentPos - centerPlayer() setPlacingPos() } } @@ -505,19 +478,10 @@ object AutoObsidian : Module() { } else false } - private fun centerPlayer(): Boolean { - return if (autoCenter.value == AutoCenterMode.OFF) { - true - } else { - SurroundUtils.centerPlayer(autoCenter.value == AutoCenterMode.TP) - } - } - private fun reset() { active = false pathing = false searchingState = SearchingState.PLACING - playerPos = BlockPos(0, -1, 0) placingPos = BlockPos(0, -1, 0) tickCount = 0 } From b231edb50136155790b70af700eb182c29e98399 Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Fri, 1 Jan 2021 00:50:15 -0500 Subject: [PATCH 143/390] Make AutoObsidianProcess uses readable name --- .../kami/module/modules/misc/AutoObsidian.kt | 1 - .../zeroeightsix/kami/process/AutoObsidianProcess.kt | 12 +++++------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt index 5277e39c53..af1c3c569b 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt @@ -99,7 +99,6 @@ object AutoObsidian : Module() { } override fun onEnable() { - if (mc.player == null) return state = State.SEARCHING } diff --git a/src/main/java/me/zeroeightsix/kami/process/AutoObsidianProcess.kt b/src/main/java/me/zeroeightsix/kami/process/AutoObsidianProcess.kt index 6fa64f9696..3e1fc161ee 100644 --- a/src/main/java/me/zeroeightsix/kami/process/AutoObsidianProcess.kt +++ b/src/main/java/me/zeroeightsix/kami/process/AutoObsidianProcess.kt @@ -6,10 +6,6 @@ import baritone.api.process.PathingCommand import baritone.api.process.PathingCommandType import me.zeroeightsix.kami.module.modules.misc.AutoObsidian -/** - * Created by Xiaro on 13/07/20. - * Updated by Xiaro on 11/09/20 - */ object AutoObsidianProcess : IBaritoneProcess { override fun isTemporary(): Boolean { @@ -23,16 +19,18 @@ object AutoObsidianProcess : IBaritoneProcess { override fun onLostControl() {} override fun displayName0(): String { - return "AutoObsidian: " + AutoObsidian.state.toString().toLowerCase() + return "AutoObsidian: " + AutoObsidian.state.displayName } override fun isActive(): Boolean { return AutoObsidian.isActive() } - override fun onTick(p0: Boolean, p1: Boolean): PathingCommand? { + override fun onTick(p0: Boolean, p1: Boolean): PathingCommand { return if (AutoObsidian.pathing && AutoObsidian.goal != null) { PathingCommand(GoalNear(AutoObsidian.goal, 0), PathingCommandType.SET_GOAL_AND_PATH) - } else PathingCommand(null, PathingCommandType.REQUEST_PAUSE) + } else { + PathingCommand(null, PathingCommandType.REQUEST_PAUSE) + } } } \ No newline at end of file From 77c7b34d8d70dd4aee4332004b94f665a833e135 Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Fri, 1 Jan 2021 01:27:39 -0500 Subject: [PATCH 144/390] Updates placingPos dynamically --- .../kami/module/modules/misc/AutoObsidian.kt | 84 +++++++++++-------- 1 file changed, 48 insertions(+), 36 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt index af1c3c569b..7dbe90f774 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt @@ -1,5 +1,6 @@ package me.zeroeightsix.kami.module.modules.misc +import me.zeroeightsix.kami.event.events.RenderWorldEvent import me.zeroeightsix.kami.event.events.SafeTickEvent import me.zeroeightsix.kami.module.Module import me.zeroeightsix.kami.module.modules.player.NoBreakAnimation @@ -7,13 +8,17 @@ import me.zeroeightsix.kami.process.AutoObsidianProcess import me.zeroeightsix.kami.setting.Settings import me.zeroeightsix.kami.util.* import me.zeroeightsix.kami.util.EntityUtils.getDroppedItem +import me.zeroeightsix.kami.util.color.ColorHolder +import me.zeroeightsix.kami.util.graphics.ESPRenderer import me.zeroeightsix.kami.util.math.RotationUtils.getRotationTo -import me.zeroeightsix.kami.util.math.VectorUtils.toBlockPos +import me.zeroeightsix.kami.util.math.VectorUtils import me.zeroeightsix.kami.util.math.VectorUtils.toVec3d import me.zeroeightsix.kami.util.text.MessageSendHelper.sendChatMessage import net.minecraft.block.BlockShulkerBox +import net.minecraft.block.state.IBlockState import net.minecraft.client.audio.PositionedSoundRecord import net.minecraft.client.gui.inventory.GuiShulkerBox +import net.minecraft.init.Blocks import net.minecraft.init.SoundEvents import net.minecraft.inventory.ClickType import net.minecraft.network.play.client.CPacketPlayer @@ -22,12 +27,12 @@ import net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock import net.minecraft.util.EnumFacing import net.minecraft.util.EnumHand import net.minecraft.util.math.BlockPos +import net.minecraft.util.math.RayTraceResult import net.minecraft.util.math.Vec3d import net.minecraftforge.fml.common.gameevent.TickEvent +import org.kamiblue.commons.extension.ceilToInt import org.kamiblue.commons.interfaces.DisplayEnum import org.kamiblue.event.listener.listener -import kotlin.math.ceil - @Module.Info( name = "AutoObsidian", @@ -94,6 +99,8 @@ object AutoObsidian : Module() { private var tickCount = 0 private var openTime = 0L + private val renderer = ESPRenderer().apply { aFilled = 33; aOutline = 233 } + override fun isActive(): Boolean { return isEnabled && active } @@ -145,11 +152,15 @@ object AutoObsidian : Module() { } } } + + listener { + if (state != State.DONE) renderer.render(clear = false, cull = true) + } } private fun updateState() { - if (state != State.DONE && placingPos.y == -1) { - setPlacingPos() + if (state != State.DONE) { + updatePlacingPos() } if (!active && state != State.DONE) { @@ -161,6 +172,36 @@ object AutoObsidian : Module() { updateSearchingState() } + private fun updatePlacingPos() { + val eyePos = mc.player.getPositionEyes(1f) + if (isPositionValid(placingPos, mc.world.getBlockState(placingPos), eyePos)) return + + val posList = VectorUtils.getBlockPosInSphere(eyePos, maxReach.value) + .sortedBy { it.distanceSqToCenter(eyePos.x, eyePos.y, eyePos.z) } + .map { it to mc.world.getBlockState(it) } + .toList() + + val pair = posList.find { it.second.block == Blocks.ENDER_CHEST || it.second.block is BlockShulkerBox } + ?: posList.find { isPositionValid(it.first, it.second, eyePos) } + + if (pair != null) { + placingPos = pair.first + renderer.clear() + renderer.add(pair.first, ColorHolder(64, 255, 64)) + } else { + sendChatMessage("$chatName No valid position for placing shulker box / ender chest nearby, disabling.") + mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) + this.disable() + } + } + + private fun isPositionValid(pos: BlockPos, blockState: IBlockState, eyePos: Vec3d) = + !mc.world.getBlockState(pos.down()).material.isReplaceable + && (blockState.block.let { it == Blocks.ENDER_CHEST || it is BlockShulkerBox } + || BlockUtils.isPlaceable(pos)) + && mc.world.isAirBlock(pos.up()) + && mc.world.rayTraceBlocks(eyePos, pos.toVec3d())?.let { it.typeOfHit == RayTraceResult.Type.MISS } ?: true + private fun updateMainState() { val obbyCount = countObby() val slotCount = countEmptySlots() @@ -284,7 +325,7 @@ object AutoObsidian : Module() { SearchingState.MINING -> mineBlock(placingPos, false) SearchingState.COLLECTING -> collectDroppedItem(shulkerBoxId) SearchingState.DONE -> { - setPlacingPos() + updatePlacingPos() } } } else { @@ -292,35 +333,6 @@ object AutoObsidian : Module() { } } - private fun setPlacingPos() { - val feetPos = mc.player.positionVector.toBlockPos() - val eyePos = mc.player.getPositionEyes(1f) - var validPos: BlockPos? = null - - for (x in -4..4) { - for (y in -4..4) { - for (z in -4..4) { - val pos = feetPos.add(x, y, z) - if (eyePos.distanceTo(pos.toVec3d()) > maxReach.value) continue - - if (mc.world.getBlockState(pos.down()).material.isReplaceable) continue - if (!BlockUtils.isPlaceable(pos) || !BlockUtils.isPlaceable(pos.up())) continue - - validPos = pos - break - } - } - } - - if (validPos != null) { - placingPos = validPos - } else { - sendChatMessage("$chatName No valid position for placing shulker box / ender chest nearby, disabling.") - mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) - this.disable() - } - } - private fun placeShulker(pos: BlockPos) { for (i in 219..234) { if (InventoryUtils.getSlotsHotbar(i) == null) { @@ -409,7 +421,7 @@ object AutoObsidian : Module() { } private fun placeBlock(pos: BlockPos) { - val pair = BlockUtils.getNeighbour(pos, 1) + val pair = BlockUtils.getNeighbour(pos, 1, 6.5f) ?: run { sendChatMessage("Can't find neighbour block") return From 01839890096af184f3fda5995eb9456799224dc8 Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Fri, 1 Jan 2021 01:35:19 -0500 Subject: [PATCH 145/390] Fixed obby counting --- src/main/commons | 2 +- .../kami/module/modules/misc/AutoObsidian.kt | 33 ++++++++----------- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/main/commons b/src/main/commons index 3c425397af..7e2929904f 160000 --- a/src/main/commons +++ b/src/main/commons @@ -1 +1 @@ -Subproject commit 3c425397afdb54fab53cf90724cb8f854602fbb7 +Subproject commit 7e2929904f0a126457a64d817f4a654473ae89be diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt index 7dbe90f774..a81961c5b3 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt @@ -203,20 +203,16 @@ object AutoObsidian : Module() { && mc.world.rayTraceBlocks(eyePos, pos.toVec3d())?.let { it.typeOfHit == RayTraceResult.Type.MISS } ?: true private fun updateMainState() { - val obbyCount = countObby() - val slotCount = countEmptySlots() + val passCountCheck = checkObbyCount() state = when { - (!canPickUpObsidian() && fillMode.value != FillMode.INFINITE) -> { - State.DONE /* Never transition to done when in INFINITE mode */ - } state == State.DONE && autoRefill.value && InventoryUtils.countItemAll(ItemID.OBSIDIAN.id) <= threshold.value -> { State.SEARCHING } - state == State.COLLECTING && getDroppedItem(ItemID.OBSIDIAN.id, 8.0f) == null -> { + state == State.COLLECTING && (!canPickUpObby() || getDroppedItem(ItemID.OBSIDIAN.id, 16.0f) == null) -> { State.DONE } - state != State.DONE && mc.world.isAirBlock(placingPos) && !checkObbyCount(obbyCount, slotCount) -> { + state != State.DONE && mc.world.isAirBlock(placingPos) && !passCountCheck -> { State.COLLECTING } state == State.MINING && mc.world.isAirBlock(placingPos) -> { @@ -225,7 +221,7 @@ object AutoObsidian : Module() { state == State.PLACING && !mc.world.isAirBlock(placingPos) -> { State.PRE_MINING } - state == State.SEARCHING && searchingState == SearchingState.DONE && checkObbyCount(obbyCount, slotCount) -> { + state == State.SEARCHING && searchingState == SearchingState.DONE && passCountCheck -> { State.PLACING } else -> { @@ -238,8 +234,8 @@ object AutoObsidian : Module() { * Check if we can pick up more obsidian: * There must be at least one slot which is either empty, or contains a stack of obsidian less than 64 */ - private fun canPickUpObsidian(): Boolean { - return mc.player?.inventory?.mainInventory?.any { + private fun canPickUpObby(): Boolean { + return fillMode.value == FillMode.INFINITE || mc.player?.inventory?.mainInventory?.any { it.isEmpty || it.item.id == ItemID.OBSIDIAN.id && it.count < 64 } ?: false } @@ -247,13 +243,16 @@ object AutoObsidian : Module() { /** * @return True if can still place more ender chest */ - private fun checkObbyCount(obbyCount: Int, slotCount: Int): Boolean { + private fun checkObbyCount(): Boolean { + val inventory = InventoryUtils.countItemAll(ItemID.OBSIDIAN.id) + val dropped = EntityUtils.getDroppedItems(ItemID.OBSIDIAN.id, 16.0f).sumBy { it.item.count } + return when (fillMode.value!!) { FillMode.TARGET_STACKS -> { - obbyCount < targetStacks.value + ((inventory + dropped) / 8.0f).ceilToInt() / 8 < targetStacks.value } FillMode.FILL_INVENTORY -> { - slotCount > 8 + countEmptySlots() - dropped >= 8 } FillMode.INFINITE -> { true @@ -261,12 +260,6 @@ object AutoObsidian : Module() { } } - private fun countObby(): Int { - val inventory = InventoryUtils.countItemAll(49) - val dropped = EntityUtils.getDroppedItems(49, 8.0f).sumBy { it.item.count } - return ceil((inventory + dropped) / 8.0f).toInt() / 8 - } - private fun countEmptySlots(): Int { return mc.player?.inventory?.mainInventory?.sumBy { when { @@ -284,7 +277,7 @@ object AutoObsidian : Module() { searchingState == SearchingState.PLACING && InventoryUtils.countItemAll(ItemID.ENDER_CHEST.id) > 0 -> { SearchingState.DONE } - searchingState == SearchingState.COLLECTING && getDroppedItem(shulkerBoxId, 8.0f) == null -> { + searchingState == SearchingState.COLLECTING && getDroppedItem(shulkerBoxId, 16.0f) == null -> { SearchingState.DONE } searchingState == SearchingState.MINING && mc.world.isAirBlock(placingPos) -> { From 480daca318d3992bd7db69487fec5a550fb24d9f Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Fri, 1 Jan 2021 01:39:08 -0500 Subject: [PATCH 146/390] Removed useless map --- .../kami/module/modules/misc/AutoObsidian.kt | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt index a81961c5b3..565daa639a 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt @@ -41,8 +41,6 @@ import org.kamiblue.event.listener.listener ) object AutoObsidian : Module() { private val fillMode = register(Settings.e("FillMode", FillMode.TARGET_STACKS)) - private val modeExitStrings = mapOf(FillMode.FILL_INVENTORY to "Inventory filled", FillMode.TARGET_STACKS to "Target Stacks Reached") - private val searchShulker = register(Settings.b("SearchShulker", false)) private val autoRefill = register(Settings.booleanBuilder("AutoRefill").withValue(false).withVisibility { fillMode.value != FillMode.INFINITE }) private val threshold = register(Settings.integerBuilder("RefillThreshold").withValue(8).withRange(1, 56).withVisibility { autoRefill.value && fillMode.value != FillMode.INFINITE }) @@ -51,10 +49,10 @@ object AutoObsidian : Module() { private val interacting = register(Settings.enumBuilder(InteractMode::class.java).withName("InteractMode").withValue(InteractMode.SPOOF)) private val maxReach = register(Settings.floatBuilder("MaxReach").withValue(4.5F).withRange(1.0f, 6.0f).withStep(0.1f)) - private enum class FillMode(override val displayName: String) : DisplayEnum { - TARGET_STACKS("Target stacks"), - FILL_INVENTORY("Fill inventory"), - INFINITE("Infinite") + private enum class FillMode(override val displayName: String, val message: String) : DisplayEnum { + TARGET_STACKS("Target stacks", "Target Stacks Reached"), + FILL_INVENTORY("Fill inventory", "Inventory filled"), + INFINITE("Infinite", "") } enum class State(override val displayName: String) : DisplayEnum { @@ -143,10 +141,10 @@ object AutoObsidian : Module() { } State.DONE -> { if (!autoRefill.value) { - sendChatMessage("$chatName ".plus(modeExitStrings[fillMode.value]).plus(", disabling.")) + sendChatMessage("$chatName ${fillMode.value.message}, disabling.") this.disable() } else { - if (active) sendChatMessage("$chatName ".plus(modeExitStrings[fillMode.value]).plus(", stopping.")) + if (active) sendChatMessage("$chatName ${fillMode.value.message}, stopping.") reset() } } From 6da9e37c930749d3dd39898475298ea652d73bb7 Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Fri, 1 Jan 2021 01:40:56 -0500 Subject: [PATCH 147/390] Cleaned up if else branches in updateSearchingState() --- .../kami/module/modules/misc/AutoObsidian.kt | 59 ++++++++++--------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt index 565daa639a..25e142dbab 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt @@ -269,40 +269,41 @@ object AutoObsidian : Module() { } private fun updateSearchingState() { - /* Updates searching state */ - if (state == State.SEARCHING && searchingState != SearchingState.DONE) { - searchingState = when { - searchingState == SearchingState.PLACING && InventoryUtils.countItemAll(ItemID.ENDER_CHEST.id) > 0 -> { - SearchingState.DONE - } - searchingState == SearchingState.COLLECTING && getDroppedItem(shulkerBoxId, 16.0f) == null -> { - SearchingState.DONE - } - searchingState == SearchingState.MINING && mc.world.isAirBlock(placingPos) -> { - if (InventoryUtils.countItemAll(ItemID.ENDER_CHEST.id) > 0) { - SearchingState.COLLECTING - } else { - // In case if the shulker wasn't placed due to server lag - SearchingState.PLACING + if (state == State.SEARCHING) { + if (searchingState != SearchingState.DONE) { + searchingState = when { + searchingState == SearchingState.PLACING && InventoryUtils.countItemAll(ItemID.ENDER_CHEST.id) > 0 -> { + SearchingState.DONE } - } - searchingState == SearchingState.OPENING && (InventoryUtils.countItemAll(ItemID.ENDER_CHEST.id) >= 64 - || InventoryUtils.getSlots(0, 35, 0) == null) -> { - SearchingState.PRE_MINING - } - searchingState == SearchingState.PLACING && !mc.world.isAirBlock(placingPos) -> { - if (mc.world.getBlockState(placingPos).block is BlockShulkerBox) { - SearchingState.OPENING - } else { - // In case if the shulker wasn't placed due to server lag + searchingState == SearchingState.COLLECTING && getDroppedItem(shulkerBoxId, 16.0f) == null -> { + SearchingState.DONE + } + searchingState == SearchingState.MINING && mc.world.isAirBlock(placingPos) -> { + if (InventoryUtils.countItemAll(ItemID.ENDER_CHEST.id) > 0) { + SearchingState.COLLECTING + } else { + // In case if the shulker wasn't placed due to server lag + SearchingState.PLACING + } + } + searchingState == SearchingState.OPENING && (InventoryUtils.countItemAll(ItemID.ENDER_CHEST.id) >= 64 + || InventoryUtils.getSlots(0, 35, 0) == null) -> { SearchingState.PRE_MINING } - } - else -> { - searchingState + searchingState == SearchingState.PLACING && !mc.world.isAirBlock(placingPos) -> { + if (mc.world.getBlockState(placingPos).block is BlockShulkerBox) { + SearchingState.OPENING + } else { + // In case if the shulker wasn't placed due to server lag + SearchingState.PRE_MINING + } + } + else -> { + searchingState + } } } - } else if (state != State.SEARCHING) { + } else { searchingState = SearchingState.PLACING } } From a2d7eee74cb1d0a6a110bfedd0b66266142193f3 Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Fri, 1 Jan 2021 02:26:29 -0500 Subject: [PATCH 148/390] Spoof rotations properly --- .../kami/module/modules/misc/AutoObsidian.kt | 55 ++++++++++++------- 1 file changed, 36 insertions(+), 19 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt index 25e142dbab..18896baf4e 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt @@ -1,7 +1,10 @@ package me.zeroeightsix.kami.module.modules.misc +import me.zeroeightsix.kami.event.KamiEvent +import me.zeroeightsix.kami.event.events.OnUpdateWalkingPlayerEvent import me.zeroeightsix.kami.event.events.RenderWorldEvent import me.zeroeightsix.kami.event.events.SafeTickEvent +import me.zeroeightsix.kami.manager.managers.PlayerPacketManager import me.zeroeightsix.kami.module.Module import me.zeroeightsix.kami.module.modules.player.NoBreakAnimation import me.zeroeightsix.kami.process.AutoObsidianProcess @@ -11,6 +14,7 @@ import me.zeroeightsix.kami.util.EntityUtils.getDroppedItem import me.zeroeightsix.kami.util.color.ColorHolder import me.zeroeightsix.kami.util.graphics.ESPRenderer import me.zeroeightsix.kami.util.math.RotationUtils.getRotationTo +import me.zeroeightsix.kami.util.math.Vec2f import me.zeroeightsix.kami.util.math.VectorUtils import me.zeroeightsix.kami.util.math.VectorUtils.toVec3d import me.zeroeightsix.kami.util.text.MessageSendHelper.sendChatMessage @@ -21,7 +25,6 @@ import net.minecraft.client.gui.inventory.GuiShulkerBox import net.minecraft.init.Blocks import net.minecraft.init.SoundEvents import net.minecraft.inventory.ClickType -import net.minecraft.network.play.client.CPacketPlayer import net.minecraft.network.play.client.CPacketPlayerDigging import net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock import net.minecraft.util.EnumFacing @@ -96,7 +99,9 @@ object AutoObsidian : Module() { private var shulkerBoxId = 0 private var tickCount = 0 private var openTime = 0L + private var lastHitVec: Vec3d? = null + private val rotateTimer = TimerUtils.TickTimer(TimerUtils.TimeUnit.TICKS) private val renderer = ESPRenderer().apply { aFilled = 33; aOutline = 233 } override fun isActive(): Boolean { @@ -154,6 +159,26 @@ object AutoObsidian : Module() { listener { if (state != State.DONE) renderer.render(clear = false, cull = true) } + + listener { + if (it.era != KamiEvent.Era.PRE || rotateTimer.tick(20L, false)) return@listener + doRotation() + } + } + + private fun doRotation() { + val rotation = lastHitVec?.let { Vec2f(getRotationTo(it, true)) } ?: return + + when (interacting.value) { + InteractMode.SPOOF -> { + val packet = PlayerPacketManager.PlayerPacket(rotating = true, rotation = rotation ) + PlayerPacketManager.addPacket(this, packet) + } + InteractMode.VIEW_LOCK -> { + mc.player.rotationYaw = rotation.x + mc.player.rotationPitch = rotation.y + } + } } private fun updateState() { @@ -396,7 +421,8 @@ object AutoObsidian : Module() { val side = EnumFacing.getDirectionFromEntityLiving(pos, mc.player) val hitVecOffset = BlockUtils.getHitVecOffset(side) - rotation(pos.toVec3d().add(hitVecOffset)) + lastHitVec = BlockUtils.getHitVec(pos, side) + rotateTimer.reset() /* Added a delay here so it doesn't spam right click and get you kicked */ if (System.currentTimeMillis() >= openTime + 2000L) { @@ -420,6 +446,8 @@ object AutoObsidian : Module() { } val hitVecOffset = BlockUtils.getHitVecOffset(pair.first) + lastHitVec = BlockUtils.getHitVec(pair.second, pair.first) + rotateTimer.reset() Thread { Thread.sleep(delayTicks.value * 25L) @@ -443,16 +471,18 @@ object AutoObsidian : Module() { InventoryUtils.swapSlotToItem(ItemID.DIAMOND_PICKAXE.id) } - val facing = EnumFacing.getDirectionFromEntityLiving(pos, mc.player) + val side = EnumFacing.getDirectionFromEntityLiving(pos, mc.player) + lastHitVec = BlockUtils.getHitVec(pos, side) + rotateTimer.reset() Thread { Thread.sleep(delayTicks.value * 25L) if (pre) { - mc.connection?.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, pos, facing)) + mc.connection?.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, pos, side)) if (state != State.SEARCHING) state = State.MINING else searchingState = SearchingState.MINING } else { - mc.connection?.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, pos, facing)) + mc.connection?.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, pos, side)) } mc.player.swingArm(EnumHand.MAIN_HAND) @@ -460,20 +490,6 @@ object AutoObsidian : Module() { return true } - private fun rotation(hitVec: Vec3d) { - val rotation = getRotationTo(hitVec, true) - when (interacting.value) { - InteractMode.SPOOF -> { - val rotationPacket = CPacketPlayer.PositionRotation(mc.player.posX, mc.player.posY, mc.player.posZ, rotation.x.toFloat(), rotation.y.toFloat(), mc.player.onGround) - mc.connection?.sendPacket(rotationPacket) - } - InteractMode.VIEW_LOCK -> { - mc.player.rotationYaw = rotation.x.toFloat() - mc.player.rotationPitch = rotation.y.toFloat() - } - } - } - private fun collectDroppedItem(itemId: Int) { pathing = if (getDroppedItem(itemId, 16.0f) != null) { goal = getDroppedItem(itemId, 16.0f) @@ -487,5 +503,6 @@ object AutoObsidian : Module() { searchingState = SearchingState.PLACING placingPos = BlockPos(0, -1, 0) tickCount = 0 + lastHitVec = null } } From bb55a003ccd2c9d211b849cfa579279b6043b5b4 Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Fri, 1 Jan 2021 02:43:28 -0500 Subject: [PATCH 149/390] Use coroutines instead of threads --- .../kami/module/modules/misc/AutoObsidian.kt | 99 ++++++++++--------- 1 file changed, 51 insertions(+), 48 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt index 18896baf4e..bd906a9442 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt @@ -1,5 +1,7 @@ package me.zeroeightsix.kami.module.modules.misc +import kotlinx.coroutines.delay +import kotlinx.coroutines.launch import me.zeroeightsix.kami.event.KamiEvent import me.zeroeightsix.kami.event.events.OnUpdateWalkingPlayerEvent import me.zeroeightsix.kami.event.events.RenderWorldEvent @@ -10,6 +12,7 @@ import me.zeroeightsix.kami.module.modules.player.NoBreakAnimation import me.zeroeightsix.kami.process.AutoObsidianProcess import me.zeroeightsix.kami.setting.Settings import me.zeroeightsix.kami.util.* +import me.zeroeightsix.kami.util.BlockUtils.placeBlock import me.zeroeightsix.kami.util.EntityUtils.getDroppedItem import me.zeroeightsix.kami.util.color.ColorHolder import me.zeroeightsix.kami.util.graphics.ESPRenderer @@ -25,6 +28,7 @@ import net.minecraft.client.gui.inventory.GuiShulkerBox import net.minecraft.init.Blocks import net.minecraft.init.SoundEvents import net.minecraft.inventory.ClickType +import net.minecraft.network.play.client.CPacketEntityAction import net.minecraft.network.play.client.CPacketPlayerDigging import net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock import net.minecraft.util.EnumFacing @@ -395,28 +399,17 @@ object AutoObsidian : Module() { private fun openShulker(pos: BlockPos) { if (mc.currentScreen is GuiShulkerBox) { - Thread { - /* Extra delay here to wait for the item list to be loaded */ - Thread.sleep(delayTicks.value * 50L) - val currentContainer = mc.player.openContainer - var enderChestSlot = -1 - for (i in 0..26) { - if (currentContainer.inventory[i].item.id == ItemID.ENDER_CHEST.id) { - enderChestSlot = i - break - } - } - onMainThreadSafe { - if (enderChestSlot != -1) { - playerController.windowClick(currentContainer.windowId, enderChestSlot, 0, ClickType.QUICK_MOVE, Companion.mc.player) - player.closeScreen() - } else { - sendChatMessage("$chatName No ender chest was found in shulker, disabling.") - mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) - disable() - } - } - }.start() + val container = mc.player.openContainer + val slot = container.inventory.subList(0, 27).indexOfFirst { it.item.id == ItemID.OBSIDIAN.id } + + if (slot != -1) { + InventoryUtils.inventoryClick(container.windowId, slot, 0, ClickType.QUICK_MOVE) + mc.player.closeScreen() + } else { + sendChatMessage("$chatName No ender chest was found in shulker, disabling.") + mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) + disable() + } } else { val side = EnumFacing.getDirectionFromEntityLiving(pos, mc.player) val hitVecOffset = BlockUtils.getHitVecOffset(side) @@ -427,13 +420,15 @@ object AutoObsidian : Module() { /* Added a delay here so it doesn't spam right click and get you kicked */ if (System.currentTimeMillis() >= openTime + 2000L) { openTime = System.currentTimeMillis() - Thread { - Thread.sleep(delayTicks.value * 25L) - val placePacket = CPacketPlayerTryUseItemOnBlock(pos, side, EnumHand.MAIN_HAND, hitVecOffset.x.toFloat(), hitVecOffset.y.toFloat(), hitVecOffset.z.toFloat()) - mc.connection?.sendPacket(placePacket) - mc.player.swingArm(EnumHand.MAIN_HAND) - if (NoBreakAnimation.isEnabled) NoBreakAnimation.resetMining() - }.start() + + // TODO: Replace with defaultScope later + moduleScope.launch { + delay(10L) + onMainThreadSafe { + connection.sendPacket(CPacketPlayerTryUseItemOnBlock(pos, side, EnumHand.MAIN_HAND, hitVecOffset.x.toFloat(), hitVecOffset.y.toFloat(), hitVecOffset.z.toFloat())) + player.swingArm(EnumHand.MAIN_HAND) + } + } } } } @@ -445,17 +440,24 @@ object AutoObsidian : Module() { return } - val hitVecOffset = BlockUtils.getHitVecOffset(pair.first) lastHitVec = BlockUtils.getHitVec(pair.second, pair.first) rotateTimer.reset() - Thread { - Thread.sleep(delayTicks.value * 25L) - val placePacket = CPacketPlayerTryUseItemOnBlock(pair.second, pair.first, EnumHand.MAIN_HAND, hitVecOffset.x.toFloat(), hitVecOffset.y.toFloat(), hitVecOffset.z.toFloat()) - mc.connection?.sendPacket(placePacket) - mc.player.swingArm(EnumHand.MAIN_HAND) - if (NoBreakAnimation.isEnabled) NoBreakAnimation.resetMining() - }.start() + mc.connection?.sendPacket(CPacketEntityAction(mc.player, CPacketEntityAction.Action.START_SNEAKING)) + + // TODO: Replace with defaultScope later + moduleScope.launch { + delay(10L) + onMainThreadSafe { + placeBlock(pair.second, pair.first) + if (NoBreakAnimation.isEnabled) NoBreakAnimation.resetMining() + } + + delay(10L) + onMainThreadSafe { + connection.sendPacket(CPacketEntityAction(Companion.mc.player, CPacketEntityAction.Action.STOP_SNEAKING)) + } + } } private fun mineBlock(pos: BlockPos, pre: Boolean): Boolean { @@ -475,18 +477,19 @@ object AutoObsidian : Module() { lastHitVec = BlockUtils.getHitVec(pos, side) rotateTimer.reset() - Thread { - Thread.sleep(delayTicks.value * 25L) - - if (pre) { - mc.connection?.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, pos, side)) - if (state != State.SEARCHING) state = State.MINING else searchingState = SearchingState.MINING - } else { - mc.connection?.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, pos, side)) + // TODO: Replace with defaultScope later + moduleScope.launch { + delay(5L) + onMainThreadSafe { + if (pre) { + connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, pos, side)) + if (state != State.SEARCHING) state = State.MINING else searchingState = SearchingState.MINING + } else { + connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, pos, side)) + } + player.swingArm(EnumHand.MAIN_HAND) } - - mc.player.swingArm(EnumHand.MAIN_HAND) - }.start() + } return true } From 2ac3bbae41ba57e559dd4a1525a493a002c7444b Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Fri, 1 Jan 2021 02:48:59 -0500 Subject: [PATCH 150/390] Wait for shulker item to be loaded for maximum of 5 seconds --- .../kami/module/modules/misc/AutoObsidian.kt | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt index bd906a9442..f3b1c89891 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt @@ -102,10 +102,10 @@ object AutoObsidian : Module() { private var placingPos = BlockPos(0, -1, 0) private var shulkerBoxId = 0 private var tickCount = 0 - private var openTime = 0L private var lastHitVec: Vec3d? = null private val rotateTimer = TimerUtils.TickTimer(TimerUtils.TimeUnit.TICKS) + private val shulkerOpenTimer = TimerUtils.TickTimer(TimerUtils.TimeUnit.TICKS) private val renderer = ESPRenderer().apply { aFilled = 33; aOutline = 233 } override fun isActive(): Boolean { @@ -400,12 +400,12 @@ object AutoObsidian : Module() { private fun openShulker(pos: BlockPos) { if (mc.currentScreen is GuiShulkerBox) { val container = mc.player.openContainer - val slot = container.inventory.subList(0, 27).indexOfFirst { it.item.id == ItemID.OBSIDIAN.id } + val slot = container.inventory.subList(0, 27).indexOfFirst { it.item.id == ItemID.ENDER_CHEST.id } if (slot != -1) { InventoryUtils.inventoryClick(container.windowId, slot, 0, ClickType.QUICK_MOVE) mc.player.closeScreen() - } else { + } else if (shulkerOpenTimer.tick(100, false)) { // Wait for maximum of 5 seconds sendChatMessage("$chatName No ender chest was found in shulker, disabling.") mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) disable() @@ -417,10 +417,7 @@ object AutoObsidian : Module() { lastHitVec = BlockUtils.getHitVec(pos, side) rotateTimer.reset() - /* Added a delay here so it doesn't spam right click and get you kicked */ - if (System.currentTimeMillis() >= openTime + 2000L) { - openTime = System.currentTimeMillis() - + if (shulkerOpenTimer.tick(50)) { // TODO: Replace with defaultScope later moduleScope.launch { delay(10L) From 944be871f2ab21da16ad77649b0e204a15df2367 Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Fri, 1 Jan 2021 02:52:46 -0500 Subject: [PATCH 151/390] Use timer for tick delay --- .../kami/module/modules/misc/AutoObsidian.kt | 41 +++++++------------ 1 file changed, 15 insertions(+), 26 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt index f3b1c89891..2b2b3b8d56 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt @@ -101,9 +101,9 @@ object AutoObsidian : Module() { private var searchingState = SearchingState.PLACING private var placingPos = BlockPos(0, -1, 0) private var shulkerBoxId = 0 - private var tickCount = 0 private var lastHitVec: Vec3d? = null + private val tickTimer = TimerUtils.TickTimer(TimerUtils.TimeUnit.TICKS) private val rotateTimer = TimerUtils.TickTimer(TimerUtils.TimeUnit.TICKS) private val shulkerOpenTimer = TimerUtils.TickTimer(TimerUtils.TimeUnit.TICKS) private val renderer = ESPRenderer().apply { aFilled = 33; aOutline = 233 } @@ -122,14 +122,8 @@ object AutoObsidian : Module() { init { listener { - if (it.phase != TickEvent.Phase.END || mc.playerController == null) return@listener - - if (tickCount < delayTicks.value) { - tickCount++ - return@listener - } else { - tickCount = 0 - } + if (it.phase != TickEvent.Phase.END || mc.playerController == null + || !tickTimer.tick(delayTicks.value.toLong())) return@listener updateState() when (state) { @@ -164,23 +158,19 @@ object AutoObsidian : Module() { if (state != State.DONE) renderer.render(clear = false, cull = true) } - listener { - if (it.era != KamiEvent.Era.PRE || rotateTimer.tick(20L, false)) return@listener - doRotation() - } - } + listener { event -> + if (event.era != KamiEvent.Era.PRE || rotateTimer.tick(20L, false)) return@listener + val rotation = lastHitVec?.let { Vec2f(getRotationTo(it, true)) } ?: return@listener - private fun doRotation() { - val rotation = lastHitVec?.let { Vec2f(getRotationTo(it, true)) } ?: return - - when (interacting.value) { - InteractMode.SPOOF -> { - val packet = PlayerPacketManager.PlayerPacket(rotating = true, rotation = rotation ) - PlayerPacketManager.addPacket(this, packet) - } - InteractMode.VIEW_LOCK -> { - mc.player.rotationYaw = rotation.x - mc.player.rotationPitch = rotation.y + when (interacting.value) { + InteractMode.SPOOF -> { + val packet = PlayerPacketManager.PlayerPacket(rotating = true, rotation = rotation) + PlayerPacketManager.addPacket(this, packet) + } + InteractMode.VIEW_LOCK -> { + mc.player.rotationYaw = rotation.x + mc.player.rotationPitch = rotation.y + } } } } @@ -502,7 +492,6 @@ object AutoObsidian : Module() { pathing = false searchingState = SearchingState.PLACING placingPos = BlockPos(0, -1, 0) - tickCount = 0 lastHitVec = null } } From 4d08bae94434bebfa6dd1b38ad9f1afac4474570 Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Fri, 1 Jan 2021 03:19:48 -0500 Subject: [PATCH 152/390] Improved pathing --- .../kami/module/modules/misc/AutoObsidian.kt | 38 ++++++++++++------- .../kami/process/AutoObsidianProcess.kt | 9 ++--- 2 files changed, 27 insertions(+), 20 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt index 2b2b3b8d56..0cb6301316 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt @@ -1,5 +1,7 @@ package me.zeroeightsix.kami.module.modules.misc +import baritone.api.pathing.goals.Goal +import baritone.api.pathing.goals.GoalNear import kotlinx.coroutines.delay import kotlinx.coroutines.launch import me.zeroeightsix.kami.event.KamiEvent @@ -54,7 +56,7 @@ object AutoObsidian : Module() { private val targetStacks = register(Settings.integerBuilder("TargetStacks").withValue(1).withRange(1, 20).withVisibility { fillMode.value == FillMode.TARGET_STACKS }) private val delayTicks = register(Settings.integerBuilder("DelayTicks").withValue(5).withRange(0, 10)) private val interacting = register(Settings.enumBuilder(InteractMode::class.java).withName("InteractMode").withValue(InteractMode.SPOOF)) - private val maxReach = register(Settings.floatBuilder("MaxReach").withValue(4.5F).withRange(1.0f, 6.0f).withStep(0.1f)) + private val maxReach = register(Settings.floatBuilder("MaxReach").withValue(4.5F).withRange(2.0f, 6.0f).withStep(0.1f)) private enum class FillMode(override val displayName: String, val message: String) : DisplayEnum { TARGET_STACKS("Target stacks", "Target Stacks Reached"), @@ -93,12 +95,11 @@ object AutoObsidian : Module() { DIAMOND_PICKAXE(278) } - var pathing = false - var goal: BlockPos? = null - var state = State.SEARCHING + var goal: Goal? = null; private set + var state = State.SEARCHING; private set + private var searchingState = SearchingState.PLACING private var active = false - private var searchingState = SearchingState.PLACING private var placingPos = BlockPos(0, -1, 0) private var shulkerBoxId = 0 private var lastHitVec: Vec3d? = null @@ -178,11 +179,19 @@ object AutoObsidian : Module() { private fun updateState() { if (state != State.DONE) { updatePlacingPos() - } - if (!active && state != State.DONE) { - active = true - BaritoneUtils.primary?.pathingControlManager?.registerProcess(AutoObsidianProcess) + if (!active) { + active = true + BaritoneUtils.primary?.pathingControlManager?.registerProcess(AutoObsidianProcess) + } + + if (state != State.COLLECTING && searchingState != SearchingState.COLLECTING) { + goal = if (mc.player.getDistanceSqToCenter(placingPos) > 2.0) { + GoalNear(placingPos, 2) + } else { + null + } + } } updateMainState() @@ -481,15 +490,16 @@ object AutoObsidian : Module() { } private fun collectDroppedItem(itemId: Int) { - pathing = if (getDroppedItem(itemId, 16.0f) != null) { - goal = getDroppedItem(itemId, 16.0f) - true - } else false + goal = if (getDroppedItem(itemId, 16.0f) != null) { + GoalNear(getDroppedItem(itemId, 16.0f), 0) + } else { + null + } } private fun reset() { active = false - pathing = false + goal = null searchingState = SearchingState.PLACING placingPos = BlockPos(0, -1, 0) lastHitVec = null diff --git a/src/main/java/me/zeroeightsix/kami/process/AutoObsidianProcess.kt b/src/main/java/me/zeroeightsix/kami/process/AutoObsidianProcess.kt index 3e1fc161ee..b854e1dd85 100644 --- a/src/main/java/me/zeroeightsix/kami/process/AutoObsidianProcess.kt +++ b/src/main/java/me/zeroeightsix/kami/process/AutoObsidianProcess.kt @@ -1,6 +1,5 @@ package me.zeroeightsix.kami.process -import baritone.api.pathing.goals.GoalNear import baritone.api.process.IBaritoneProcess import baritone.api.process.PathingCommand import baritone.api.process.PathingCommandType @@ -27,10 +26,8 @@ object AutoObsidianProcess : IBaritoneProcess { } override fun onTick(p0: Boolean, p1: Boolean): PathingCommand { - return if (AutoObsidian.pathing && AutoObsidian.goal != null) { - PathingCommand(GoalNear(AutoObsidian.goal, 0), PathingCommandType.SET_GOAL_AND_PATH) - } else { - PathingCommand(null, PathingCommandType.REQUEST_PAUSE) - } + return AutoObsidian.goal?.let { + PathingCommand(it, PathingCommandType.SET_GOAL_AND_PATH) + } ?: PathingCommand(null, PathingCommandType.REQUEST_PAUSE) } } \ No newline at end of file From e1ac12413027811cb775902081def6d7810d3dfa Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Fri, 1 Jan 2021 03:27:11 -0500 Subject: [PATCH 153/390] Move the shulker into hotbar if it is in inventory --- .../kami/module/modules/misc/AutoObsidian.kt | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt index 0cb6301316..1649a80e04 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt @@ -28,6 +28,7 @@ import net.minecraft.block.state.IBlockState import net.minecraft.client.audio.PositionedSoundRecord import net.minecraft.client.gui.inventory.GuiShulkerBox import net.minecraft.init.Blocks +import net.minecraft.init.Items import net.minecraft.init.SoundEvents import net.minecraft.inventory.ClickType import net.minecraft.network.play.client.CPacketEntityAction @@ -354,18 +355,22 @@ object AutoObsidian : Module() { } private fun placeShulker(pos: BlockPos) { - for (i in 219..234) { - if (InventoryUtils.getSlotsHotbar(i) == null) { - if (i != 234) continue else { - sendChatMessage("$chatName No shulker box was found in hotbar, disabling.") - mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) - this.disable() - return + if (InventoryUtils.getSlotsHotbar(shulkerBoxId) == null && InventoryUtils.getSlotsNoHotbar(shulkerBoxId) != null) { + InventoryUtils.moveToHotbar(shulkerBoxId, Items.DIAMOND_PICKAXE.id) + } else { + for (i in 219..234) { + if (InventoryUtils.getSlotsHotbar(i) == null) { + if (i == 234) { + sendChatMessage("$chatName No shulker box was found in hotbar, disabling.") + mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) + this.disable() + } + continue } + shulkerBoxId = i + InventoryUtils.swapSlotToItem(i) + break } - shulkerBoxId = i - InventoryUtils.swapSlotToItem(i) - break } if (mc.world.getBlockState(pos).block !is BlockShulkerBox) { From b1c5d1867b3db556cd96ee12b2d6abece2d5c558 Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Fri, 1 Jan 2021 03:28:00 -0500 Subject: [PATCH 154/390] Removed unneeded this. --- .../zeroeightsix/kami/module/modules/misc/AutoObsidian.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt index 1649a80e04..ba55a32a77 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt @@ -147,7 +147,7 @@ object AutoObsidian : Module() { State.DONE -> { if (!autoRefill.value) { sendChatMessage("$chatName ${fillMode.value.message}, disabling.") - this.disable() + disable() } else { if (active) sendChatMessage("$chatName ${fillMode.value.message}, stopping.") reset() @@ -218,7 +218,7 @@ object AutoObsidian : Module() { } else { sendChatMessage("$chatName No valid position for placing shulker box / ender chest nearby, disabling.") mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) - this.disable() + disable() } } @@ -363,7 +363,7 @@ object AutoObsidian : Module() { if (i == 234) { sendChatMessage("$chatName No shulker box was found in hotbar, disabling.") mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) - this.disable() + disable() } continue } @@ -390,7 +390,7 @@ object AutoObsidian : Module() { } else { sendChatMessage("$chatName No ender chest was found in inventory, disabling.") mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) - this.disable() + disable() return } } From cd16a07c828e088d503f7c24b408e9261841236a Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Fri, 1 Jan 2021 03:29:20 -0500 Subject: [PATCH 155/390] Removed unneeded boolean returning --- .../me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt index ba55a32a77..29b7703a0e 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt @@ -461,15 +461,13 @@ object AutoObsidian : Module() { } } - private fun mineBlock(pos: BlockPos, pre: Boolean): Boolean { + private fun mineBlock(pos: BlockPos, pre: Boolean) { if (pre) { if (InventoryUtils.getSlotsHotbar(ItemID.DIAMOND_PICKAXE.id) == null && InventoryUtils.getSlotsNoHotbar(ItemID.DIAMOND_PICKAXE.id) != null) { InventoryUtils.moveToHotbar(ItemID.DIAMOND_PICKAXE.id, ItemID.ENDER_CHEST.id) - return false } else if (InventoryUtils.getSlots(0, 35, ItemID.DIAMOND_PICKAXE.id) == null) { sendChatMessage("No pickaxe was found in inventory.") mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) - return false } InventoryUtils.swapSlotToItem(ItemID.DIAMOND_PICKAXE.id) } @@ -491,7 +489,6 @@ object AutoObsidian : Module() { player.swingArm(EnumHand.MAIN_HAND) } } - return true } private fun collectDroppedItem(itemId: Int) { From 3e5e3e5e31c31ccf910c7de189c6e1d7334948f0 Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Fri, 1 Jan 2021 03:51:00 -0500 Subject: [PATCH 156/390] Fixed formatting --- .../kami/module/modules/misc/AutoObsidian.kt | 32 ++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt index 29b7703a0e..a8ad37178b 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt @@ -56,7 +56,7 @@ object AutoObsidian : Module() { private val threshold = register(Settings.integerBuilder("RefillThreshold").withValue(8).withRange(1, 56).withVisibility { autoRefill.value && fillMode.value != FillMode.INFINITE }) private val targetStacks = register(Settings.integerBuilder("TargetStacks").withValue(1).withRange(1, 20).withVisibility { fillMode.value == FillMode.TARGET_STACKS }) private val delayTicks = register(Settings.integerBuilder("DelayTicks").withValue(5).withRange(0, 10)) - private val interacting = register(Settings.enumBuilder(InteractMode::class.java).withName("InteractMode").withValue(InteractMode.SPOOF)) + private val interacting = register(Settings.e("InteractMode", InteractMode.SPOOF)) private val maxReach = register(Settings.floatBuilder("MaxReach").withValue(4.5F).withRange(2.0f, 6.0f).withStep(0.1f)) private enum class FillMode(override val displayName: String, val message: String) : DisplayEnum { @@ -164,7 +164,7 @@ object AutoObsidian : Module() { if (event.era != KamiEvent.Era.PRE || rotateTimer.tick(20L, false)) return@listener val rotation = lastHitVec?.let { Vec2f(getRotationTo(it, true)) } ?: return@listener - when (interacting.value) { + when (interacting.value!!) { InteractMode.SPOOF -> { val packet = PlayerPacketManager.PlayerPacket(rotating = true, rotation = rotation) PlayerPacketManager.addPacket(this, packet) @@ -340,11 +340,21 @@ object AutoObsidian : Module() { private fun searchingState() { if (searchShulker.value) { when (searchingState) { - SearchingState.PLACING -> placeShulker(placingPos) - SearchingState.OPENING -> openShulker(placingPos) - SearchingState.PRE_MINING -> mineBlock(placingPos, true) - SearchingState.MINING -> mineBlock(placingPos, false) - SearchingState.COLLECTING -> collectDroppedItem(shulkerBoxId) + SearchingState.PLACING -> { + placeShulker(placingPos) + } + SearchingState.OPENING -> { + openShulker(placingPos) + } + SearchingState.PRE_MINING -> { + mineBlock(placingPos, true) + } + SearchingState.MINING -> { + mineBlock(placingPos, false) + } + SearchingState.COLLECTING -> { + collectDroppedItem(shulkerBoxId) + } SearchingState.DONE -> { updatePlacingPos() } @@ -493,10 +503,10 @@ object AutoObsidian : Module() { private fun collectDroppedItem(itemId: Int) { goal = if (getDroppedItem(itemId, 16.0f) != null) { - GoalNear(getDroppedItem(itemId, 16.0f), 0) - } else { - null - } + GoalNear(getDroppedItem(itemId, 16.0f), 0) + } else { + null + } } private fun reset() { From 85340610b60cb6d6ddff6a3daa187565b89dc4f7 Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Fri, 1 Jan 2021 03:52:50 -0500 Subject: [PATCH 157/390] Fixed warning --- .../me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt index a8ad37178b..bd9039f683 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt @@ -164,7 +164,7 @@ object AutoObsidian : Module() { if (event.era != KamiEvent.Era.PRE || rotateTimer.tick(20L, false)) return@listener val rotation = lastHitVec?.let { Vec2f(getRotationTo(it, true)) } ?: return@listener - when (interacting.value!!) { + when (interacting.value) { InteractMode.SPOOF -> { val packet = PlayerPacketManager.PlayerPacket(rotating = true, rotation = rotation) PlayerPacketManager.addPacket(this, packet) @@ -173,6 +173,9 @@ object AutoObsidian : Module() { mc.player.rotationYaw = rotation.x mc.player.rotationPitch = rotation.y } + else -> { + + } } } } From 45d7f72c65b4b1aeae0228bc836da48c70035061 Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Fri, 1 Jan 2021 18:26:14 -0500 Subject: [PATCH 158/390] Fixed dead codes --- .../kami/module/modules/misc/HighwayTools.kt | 60 +++++++++---------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 1756b895c5..edc7b617dc 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -11,19 +11,18 @@ import me.zeroeightsix.kami.module.modules.player.NoBreakAnimation import me.zeroeightsix.kami.process.HighwayToolsProcess import me.zeroeightsix.kami.setting.Settings import me.zeroeightsix.kami.util.BaritoneUtils -import me.zeroeightsix.kami.util.BlockUtils import me.zeroeightsix.kami.util.InventoryUtils +import me.zeroeightsix.kami.util.WorldUtils import me.zeroeightsix.kami.util.color.ColorHolder import me.zeroeightsix.kami.util.graphics.ESPRenderer import me.zeroeightsix.kami.util.math.CoordinateConverter.asString import me.zeroeightsix.kami.util.math.Direction import me.zeroeightsix.kami.util.math.RotationUtils -import me.zeroeightsix.kami.util.math.Vec2d +import me.zeroeightsix.kami.util.math.Vec2f +import me.zeroeightsix.kami.util.math.VectorUtils.distanceTo import me.zeroeightsix.kami.util.math.VectorUtils.getBlockPositionsInArea -import me.zeroeightsix.kami.util.math.VectorUtils.getDistance import me.zeroeightsix.kami.util.math.VectorUtils.multiply import me.zeroeightsix.kami.util.math.VectorUtils.toBlockPos -import me.zeroeightsix.kami.util.math.VectorUtils.toVec3d import me.zeroeightsix.kami.util.text.MessageSendHelper.sendChatMessage import net.minecraft.block.Block import net.minecraft.block.Block.getIdFromBlock @@ -39,7 +38,10 @@ import net.minecraft.network.play.client.CPacketPlayerDigging import net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock import net.minecraft.util.EnumFacing import net.minecraft.util.EnumHand -import net.minecraft.util.math.* +import net.minecraft.util.math.AxisAlignedBB +import net.minecraft.util.math.BlockPos +import net.minecraft.util.math.RayTraceResult +import net.minecraft.util.math.Vec3d import net.minecraftforge.fml.common.gameevent.TickEvent import org.kamiblue.event.listener.listener import java.util.* @@ -52,7 +54,6 @@ import kotlin.math.sqrt * @author Avanatiker * @since 20/08/2020 */ - @Module.Info( name = "HighwayTools", description = "Be the grief a step a head.", @@ -231,11 +232,10 @@ object HighwayTools : Module() { if (baritoneMode.value) { pathing = BaritoneUtils.isPathing - var taskDistance = BlockPos(0, -1, 0) - (pendingTasks.firstOrNull() ?: doneTasks.firstOrNull())?.let { element -> - taskDistance = element.blockPos - } - if (getDistance(mc.player.positionVector, taskDistance.toVec3d()) < maxReach.value ) { + val taskPos = (pendingTasks.firstOrNull() ?: doneTasks.firstOrNull())?.blockPos + ?: BlockPos(0, -1, 0) + + if (mc.player.positionVector.distanceTo(taskPos) < maxReach.value ) { if (!isDone()) { if(canDoTask()) { if (!pathing) adjustPlayerPosition(false) @@ -475,7 +475,7 @@ object HighwayTools : Module() { block == material && block == blockTask.block -> updateTask(blockTask, TaskState.PLACED) block == fillerMat && block == blockTask.block -> updateTask(blockTask, TaskState.PLACED) else -> { - if (!BlockUtils.isPlaceable(blockTask.blockPos)) { + if (!WorldUtils.isPlaceable(blockTask.blockPos)) { // if (debugMessages.value != DebugMessages.OFF) sendChatMessage("Error: " + blockTask.blockPos + " is not a valid position to place a block, removing task.") // blockQueue.remove(blockTask) if (debugMessages.value != DebugMessages.OFF) sendChatMessage("Invalid place position: " + blockTask.blockPos) @@ -746,7 +746,7 @@ object HighwayTools : Module() { if (rayTrace == null) return val facing = rayTrace.sideHit - val rotation = RotationUtils.getRotationTo(rayTrace.hitVec, true) + val rotation = RotationUtils.getRotationTo(rayTrace.hitVec) setRotation(rotation) @@ -787,7 +787,7 @@ object HighwayTools : Module() { val neighbour = blockTask.blockPos.offset(side) val hitVec = Vec3d(neighbour).add(0.5, 0.5, 0.5).add(Vec3d(side.opposite.directionVec).scale(0.5)) - val rotation = RotationUtils.getRotationTo(hitVec, true) + val rotation = RotationUtils.getRotationTo(hitVec) setRotation(rotation) Thread { @@ -806,7 +806,7 @@ object HighwayTools : Module() { for (side in EnumFacing.values()) { val offPos = blockTask.blockPos.offset(side) if (mc.world.getBlockState(offPos).material.isReplaceable) continue - if (mc.player.getPositionEyes(1f).distanceTo(Vec3d(offPos).add(BlockUtils.getHitVecOffset(side))) > maxReach.value) continue + if (mc.player.getPositionEyes(1f).distanceTo(Vec3d(offPos).add(WorldUtils.getHitVecOffset(side))) > maxReach.value) continue val rotationVector = Vec3d(offPos).add(0.5, 0.5, 0.5).add(Vec3d(side.opposite.directionVec).scale(0.499)) val rt = mc.world.rayTraceBlocks(mc.player.getPositionEyes(1f), rotationVector, false)?: continue if (rt.typeOfHit != RayTraceResult.Type.BLOCK) continue @@ -821,8 +821,8 @@ object HighwayTools : Module() { var rayTrace = emergencyHits[0] var shortestRT = 99.0 for (rt in emergencyHits) { - if (mc.player.getPositionEyes(1f).distanceTo(Vec3d(rt.blockPos).add(BlockUtils.getHitVecOffset(rt.sideHit))) < shortestRT) { - shortestRT = mc.player.getPositionEyes(1f).distanceTo(Vec3d(rt.blockPos).add(BlockUtils.getHitVecOffset(rt.sideHit))) + if (mc.player.getPositionEyes(1f).distanceTo(Vec3d(rt.blockPos).add(WorldUtils.getHitVecOffset(rt.sideHit))) < shortestRT) { + shortestRT = mc.player.getPositionEyes(1f).distanceTo(Vec3d(rt.blockPos).add(WorldUtils.getHitVecOffset(rt.sideHit))) rayTrace = rt } } @@ -840,8 +840,8 @@ object HighwayTools : Module() { var rayTrace: RayTraceResult? = null var shortestRT = 99.0 for (rt in directHits) { - if (mc.player.getPositionEyes(1f).distanceTo(Vec3d(rt.blockPos).add(BlockUtils.getHitVecOffset(rt.sideHit))) < shortestRT) { - shortestRT = mc.player.getPositionEyes(1f).distanceTo(Vec3d(rt.blockPos).add(BlockUtils.getHitVecOffset(rt.sideHit))) + if (mc.player.getPositionEyes(1f).distanceTo(Vec3d(rt.blockPos).add(WorldUtils.getHitVecOffset(rt.sideHit))) < shortestRT) { + shortestRT = mc.player.getPositionEyes(1f).distanceTo(Vec3d(rt.blockPos).add(WorldUtils.getHitVecOffset(rt.sideHit))) rayTrace = rt } } @@ -851,7 +851,7 @@ object HighwayTools : Module() { } val hitVecOffset = rayTrace.hitVec - val rotation = RotationUtils.getRotationTo(hitVecOffset, true) + val rotation = RotationUtils.getRotationTo(hitVecOffset) setRotation(rotation) Thread { @@ -864,15 +864,15 @@ object HighwayTools : Module() { return true } - private fun setRotation(rotation: Vec2d) { + private fun setRotation(rotation: Vec2f) { when (interacting.value) { InteractMode.SPOOF -> { - val rotationPacket = CPacketPlayer.PositionRotation(mc.player.posX, mc.player.posY, mc.player.posZ, rotation.x.toFloat(), rotation.y.toFloat(), mc.player.onGround) + val rotationPacket = CPacketPlayer.PositionRotation(mc.player.posX, mc.player.posY, mc.player.posZ, rotation.x, rotation.y, mc.player.onGround) mc.connection!!.sendPacket(rotationPacket) } InteractMode.VIEWLOCK -> { - mc.player.rotationYaw = rotation.x.toFloat() - mc.player.rotationPitch = rotation.y.toFloat() + mc.player.rotationYaw = rotation.x + mc.player.rotationPitch = rotation.y } else -> {} } @@ -902,8 +902,8 @@ object HighwayTools : Module() { bridge && !buildDirectionSaved.isDiagonal -> vec = vec.add(Vec3d(buildDirectionSaved.directionVec).scale(0.51)) bridge && buildDirectionSaved.isDiagonal -> vec = vec.add(Vec3d(buildDirectionSaved.directionVec).scale(0.525)) } - mc.player.motionX = MathHelper.clamp(vec.x / 2.0, -0.2, 0.2) - mc.player.motionZ = MathHelper.clamp(vec.z / 2.0, -0.2, 0.2) + mc.player.motionX = (vec.x / 2.0).coerceIn(-0.2, 0.2) + mc.player.motionZ = (vec.z / 2.0).coerceIn(-0.2, 0.2) } private fun getQueue(): List { @@ -958,7 +958,7 @@ object HighwayTools : Module() { "\n §9> §7Destroyed blocks: §a$totalBlocksDestroyed§r" ) - if (baritoneMode.value) append("\n §9> §7Distance: §a${getDistance(startingBlockPos.toVec3d(), currentBlockPos.toVec3d()).toInt()}§r") + if (baritoneMode.value) append("\n §9> §7Distance: §a${startingBlockPos.distanceTo(currentBlockPos).toInt()}§r") sendChatMessage(toString()) } @@ -999,7 +999,7 @@ object HighwayTools : Module() { val minutes = ((runtimeSec % 3600) / 60).toInt().toString().padStart(2,'0') val hours = (runtimeSec / 3600).toInt().toString().padStart(2,'0') - val distanceDone = getDistance(startingBlockPos.toVec3d(), currentBlockPos.toVec3d()).toInt() + val distanceDone = startingBlockPos.distanceTo(currentBlockPos).toInt() val secLeft = runtimeSec / (distanceDone * pavingLeftAll + 0.0001) val secondsLeft = (secLeft % 60).toInt().toString().padStart(2,'0') @@ -1011,7 +1011,7 @@ object HighwayTools : Module() { " §7Runtime: §9$hours:$minutes:$seconds", " §7Placements per second: §9%.2f".format(totalBlocksPlaced / runtimeSec), " §7Breaks per second: §9%.2f".format(totalBlocksDestroyed / runtimeSec), - " §7Distance per hour: §9%.2f".format((getDistance(startingBlockPos.toVec3d(), currentBlockPos.toVec3d()).toInt() / runtimeSec) * 60 * 60), + " §7Distance per hour: §9%.2f".format((startingBlockPos.distanceTo(currentBlockPos).toInt() / runtimeSec) * 60 * 60), " §7One food loss per §9${totalBlocksDestroyed / foodLoss}§7 blocks mined", "§rEnvironment", " §7Starting coordinates: §9(${startingBlockPos.asString()})", @@ -1325,7 +1325,7 @@ object HighwayTools : Module() { override fun compare(a: BlockTask, b: BlockTask): Int = when { a.taskState.ordinal != b.taskState.ordinal -> a.taskState.ordinal - b.taskState.ordinal a.taskState.ordinal == b.taskState.ordinal && stuckManager.stuckLevel != StuckLevel.NONE -> a.taskState.ordinal - b.taskState.ordinal - else -> getDistance(mc.player.positionVector, a.blockPos.toVec3d()).toInt() - getDistance(mc.player.positionVector, b.blockPos.toVec3d()).toInt() + else -> (mc.player.distanceTo(a.blockPos) - mc.player.distanceTo(b.blockPos)).toInt() } } } From 910f07f6ad8967125cc5a5396ee120838138b087 Mon Sep 17 00:00:00 2001 From: Christian Date: Sat, 2 Jan 2021 01:40:30 +0100 Subject: [PATCH 159/390] Help to understand packet behavior with PacketLogger more packets coming soon --- .../kami/module/modules/player/PacketLogger.kt | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/player/PacketLogger.kt b/src/main/java/me/zeroeightsix/kami/module/modules/player/PacketLogger.kt index 39c3ad46a8..2892ddf101 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/player/PacketLogger.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/player/PacketLogger.kt @@ -8,6 +8,9 @@ import me.zeroeightsix.kami.setting.Setting import me.zeroeightsix.kami.setting.Settings import org.kamiblue.event.listener.listener import me.zeroeightsix.kami.util.text.MessageSendHelper +import net.minecraft.network.play.client.CPacketPlayer +import net.minecraft.network.play.client.CPacketPlayerDigging +import net.minecraft.util.math.Vec3d import java.io.* import java.nio.charset.StandardCharsets import java.text.SimpleDateFormat @@ -41,7 +44,17 @@ object PacketLogger : Module() { return@listener } - lines.add("${sdf.format(Date())}\n${it.packet.javaClass.simpleName}\n${it.packet.javaClass}\n${it.packet}\n\n") + lines.add("${sdf.format(Date())}\n${it.packet.javaClass.simpleName}\n${it.packet.javaClass}\n${it.packet}") + when (it.packet) { + is CPacketPlayerDigging -> { + lines.add("\nMining - ${it.packet.position}@${it.packet.facing} - ${it.packet.action}") + } + is CPacketPlayer.Rotation -> { + val vec = Vec3d(it.packet.getX(0.0), it.packet.getY(0.0), it.packet.getZ(0.0)) + lines.add("\nRotation - Pitch: ${it.packet.getPitch(0.0F)} Yaw: ${it.packet.getYaw(0.0F)}") + } + } + lines.add("\n\n") } listener { From 53a71f1fda0bebd90036cbd6c02034cda8381091 Mon Sep 17 00:00:00 2001 From: Christian Date: Sat, 2 Jan 2021 02:08:16 +0100 Subject: [PATCH 160/390] First try of coroutine packets and fixed version --- gradle.properties | 2 +- .../kami/module/modules/misc/HighwayTools.kt | 118 ++++++++++-------- 2 files changed, 65 insertions(+), 55 deletions(-) diff --git a/gradle.properties b/gradle.properties index 6492aaa779..3bb6c71504 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ org.gradle.jvmargs=-Xmx3G modGroup=me.zeroeightsix -modVersion=2.01.xx-dev-ht-v08 +modVersion=2.01.xx-dev-ht-v07 kotlin_version=1.4.21 kotlinx_coroutines_version=1.4.1 \ No newline at end of file diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index edc7b617dc..cd00c1d7c7 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -1,8 +1,13 @@ package me.zeroeightsix.kami.module.modules.misc +import kotlinx.coroutines.delay +import kotlinx.coroutines.launch +import me.zeroeightsix.kami.event.Phase +import me.zeroeightsix.kami.event.events.OnUpdateWalkingPlayerEvent import me.zeroeightsix.kami.event.events.RenderWorldEvent import me.zeroeightsix.kami.event.events.SafeTickEvent import me.zeroeightsix.kami.gui.kami.DisplayGuiScreen +import me.zeroeightsix.kami.manager.managers.PlayerPacketManager import me.zeroeightsix.kami.mixin.extension.syncCurrentPlayItem import me.zeroeightsix.kami.module.Module import me.zeroeightsix.kami.module.modules.player.AutoEat @@ -10,20 +15,20 @@ import me.zeroeightsix.kami.module.modules.player.InventoryManager import me.zeroeightsix.kami.module.modules.player.NoBreakAnimation import me.zeroeightsix.kami.process.HighwayToolsProcess import me.zeroeightsix.kami.setting.Settings -import me.zeroeightsix.kami.util.BaritoneUtils -import me.zeroeightsix.kami.util.InventoryUtils -import me.zeroeightsix.kami.util.WorldUtils +import me.zeroeightsix.kami.util.* +import me.zeroeightsix.kami.util.WorldUtils.placeBlock import me.zeroeightsix.kami.util.color.ColorHolder import me.zeroeightsix.kami.util.graphics.ESPRenderer import me.zeroeightsix.kami.util.math.CoordinateConverter.asString import me.zeroeightsix.kami.util.math.Direction import me.zeroeightsix.kami.util.math.RotationUtils -import me.zeroeightsix.kami.util.math.Vec2f import me.zeroeightsix.kami.util.math.VectorUtils.distanceTo import me.zeroeightsix.kami.util.math.VectorUtils.getBlockPositionsInArea import me.zeroeightsix.kami.util.math.VectorUtils.multiply import me.zeroeightsix.kami.util.math.VectorUtils.toBlockPos import me.zeroeightsix.kami.util.text.MessageSendHelper.sendChatMessage +import me.zeroeightsix.kami.util.threads.defaultScope +import me.zeroeightsix.kami.util.threads.onMainThreadSafe import net.minecraft.block.Block import net.minecraft.block.Block.getIdFromBlock import net.minecraft.block.BlockLiquid @@ -33,9 +38,7 @@ import net.minecraft.enchantment.EnchantmentHelper import net.minecraft.init.Blocks import net.minecraft.init.Enchantments import net.minecraft.init.SoundEvents -import net.minecraft.network.play.client.CPacketPlayer import net.minecraft.network.play.client.CPacketPlayerDigging -import net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock import net.minecraft.util.EnumFacing import net.minecraft.util.EnumHand import net.minecraft.util.math.AxisAlignedBB @@ -125,6 +128,8 @@ object HighwayTools : Module() { private val stuckManager = StuckManagement(StuckLevel.NONE, 0) private val renderer = ESPRenderer() private var active = false + private var lastHitVec: Vec3d? = null + private val rotateTimer = TickTimer(TimeUnit.TICKS) // stats private var totalBlocksPlaced = 0 @@ -276,6 +281,25 @@ object HighwayTools : Module() { if (mc.player == null) return@listener renderer.render(false) } + + listener { event -> + if (event.phase != Phase.PRE || rotateTimer.tick(20L, false)) return@listener + val rotation = lastHitVec?.let { RotationUtils.getRotationTo(it) } ?: return@listener + + when (interacting.value) { + InteractMode.SPOOF -> { + val packet = PlayerPacketManager.PlayerPacket(rotating = true, rotation = rotation) + PlayerPacketManager.addPacket(this, packet) + } + InteractMode.VIEW_LOCK -> { + mc.player.rotationYaw = rotation.x + mc.player.rotationPitch = rotation.y + } + else -> { + + } + } + } } private fun updateRenderer() { @@ -746,21 +770,20 @@ object HighwayTools : Module() { if (rayTrace == null) return val facing = rayTrace.sideHit - val rotation = RotationUtils.getRotationTo(rayTrace.hitVec) - - setRotation(rotation) + lastHitVec = rayTrace.hitVec + rotateTimer.reset() when (mc.world.getBlockState(blockTask.blockPos).block) { Blocks.NETHERRACK -> { updateTask(blockTask, TaskState.BROKEN) waitTicks = tickDelayBreak.value - Thread { - Thread.sleep(16L) - mc.connection!!.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, blockTask.blockPos, facing)) - Thread.sleep(16L) - mc.connection!!.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, blockTask.blockPos, facing)) - mc.player.swingArm(EnumHand.MAIN_HAND) - }.start() + defaultScope.launch { + delay(5L) + onMainThreadSafe { + connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, blockTask.blockPos, facing)) + player.swingArm(EnumHand.MAIN_HAND) + } + } } else -> dispatchGenericMineThread(blockTask, facing) } @@ -774,11 +797,13 @@ object HighwayTools : Module() { else -> CPacketPlayerDigging() } if (blockTask.taskState == TaskState.BREAK || blockTask.taskState == TaskState.EMERGENCY_BREAK) updateTask(blockTask, TaskState.BREAKING) - Thread { - Thread.sleep(25L) - mc.connection!!.sendPacket(digPacket) - mc.player.swingArm(EnumHand.MAIN_HAND) - }.start() + defaultScope.launch { + delay(5L) + onMainThreadSafe { + connection.sendPacket(digPacket) + player.swingArm(EnumHand.MAIN_HAND) + } + } } // Only temporary till we found solution to avoid untraceable blocks @@ -787,16 +812,16 @@ object HighwayTools : Module() { val neighbour = blockTask.blockPos.offset(side) val hitVec = Vec3d(neighbour).add(0.5, 0.5, 0.5).add(Vec3d(side.opposite.directionVec).scale(0.5)) - val rotation = RotationUtils.getRotationTo(hitVec) - setRotation(rotation) + lastHitVec = hitVec + rotateTimer.reset() - Thread { - Thread.sleep(25L) - val placePacket = CPacketPlayerTryUseItemOnBlock(neighbour, side.opposite, EnumHand.MAIN_HAND, hitVec.x.toFloat(), hitVec.y.toFloat(), hitVec.z.toFloat()) - mc.connection!!.sendPacket(placePacket) - mc.player.swingArm(EnumHand.MAIN_HAND) - if (NoBreakAnimation.isEnabled) NoBreakAnimation.resetMining() - }.start() + defaultScope.launch { + delay(10L) + onMainThreadSafe { + placeBlock(neighbour, side.opposite) + if (NoBreakAnimation.isEnabled) NoBreakAnimation.resetMining() + } + } return true } @@ -850,32 +875,17 @@ object HighwayTools : Module() { return false } - val hitVecOffset = rayTrace.hitVec - val rotation = RotationUtils.getRotationTo(hitVecOffset) - setRotation(rotation) + lastHitVec = rayTrace.hitVec + rotateTimer.reset() - Thread { - Thread.sleep(25L) - val placePacket = CPacketPlayerTryUseItemOnBlock(rayTrace.blockPos, rayTrace.sideHit, EnumHand.MAIN_HAND, hitVecOffset.x.toFloat(), hitVecOffset.y.toFloat(), hitVecOffset.z.toFloat()) - mc.connection!!.sendPacket(placePacket) - mc.player.swingArm(EnumHand.MAIN_HAND) - if (NoBreakAnimation.isEnabled) NoBreakAnimation.resetMining() - }.start() - return true - } - - private fun setRotation(rotation: Vec2f) { - when (interacting.value) { - InteractMode.SPOOF -> { - val rotationPacket = CPacketPlayer.PositionRotation(mc.player.posX, mc.player.posY, mc.player.posZ, rotation.x, rotation.y, mc.player.onGround) - mc.connection!!.sendPacket(rotationPacket) + defaultScope.launch { + delay(10L) + onMainThreadSafe { + placeBlock(rayTrace.blockPos, rayTrace.sideHit) + if (NoBreakAnimation.isEnabled) NoBreakAnimation.resetMining() } - InteractMode.VIEWLOCK -> { - mc.player.rotationYaw = rotation.x - mc.player.rotationPitch = rotation.y - } - else -> {} } + return true } private fun getPlaceableSide(pos: BlockPos): EnumFacing? { @@ -1352,7 +1362,7 @@ object HighwayTools : Module() { private enum class InteractMode { OFF, SPOOF, - VIEWLOCK + VIEW_LOCK } enum class StuckLevel { From 673283323f4eb371091a75077c48db2ddbb33c6a Mon Sep 17 00:00:00 2001 From: Christian Date: Sat, 2 Jan 2021 04:12:52 +0100 Subject: [PATCH 161/390] Try to use different event system --- .../kami/module/modules/misc/HighwayTools.kt | 98 +++++++++---------- 1 file changed, 45 insertions(+), 53 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index cd00c1d7c7..0a238d4375 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -5,7 +5,6 @@ import kotlinx.coroutines.launch import me.zeroeightsix.kami.event.Phase import me.zeroeightsix.kami.event.events.OnUpdateWalkingPlayerEvent import me.zeroeightsix.kami.event.events.RenderWorldEvent -import me.zeroeightsix.kami.event.events.SafeTickEvent import me.zeroeightsix.kami.gui.kami.DisplayGuiScreen import me.zeroeightsix.kami.manager.managers.PlayerPacketManager import me.zeroeightsix.kami.mixin.extension.syncCurrentPlayItem @@ -29,6 +28,7 @@ import me.zeroeightsix.kami.util.math.VectorUtils.toBlockPos import me.zeroeightsix.kami.util.text.MessageSendHelper.sendChatMessage import me.zeroeightsix.kami.util.threads.defaultScope import me.zeroeightsix.kami.util.threads.onMainThreadSafe +import me.zeroeightsix.kami.util.threads.safeListener import net.minecraft.block.Block import net.minecraft.block.Block.getIdFromBlock import net.minecraft.block.BlockLiquid @@ -45,7 +45,6 @@ import net.minecraft.util.math.AxisAlignedBB import net.minecraft.util.math.BlockPos import net.minecraft.util.math.RayTraceResult import net.minecraft.util.math.Vec3d -import net.minecraftforge.fml.common.gameevent.TickEvent import org.kamiblue.event.listener.listener import java.util.* import kotlin.collections.ArrayList @@ -224,72 +223,65 @@ object HighwayTools : Module() { fun isDone(): Boolean = pendingTasks.size == 0 init { - listener { - if (it.phase != TickEvent.Phase.END) { - if (mc.playerController == null) return@listener + listener { + if (mc.player == null) return@listener + renderer.render(false) + } - updateRenderer() + safeListener { event -> + if (event.phase != Phase.PRE || rotateTimer.tick(20L, false)) return@safeListener - if (!active) { - active = true - BaritoneUtils.primary?.pathingControlManager?.registerProcess(HighwayToolsProcess) - } + updateRenderer() - if (baritoneMode.value) { - pathing = BaritoneUtils.isPathing - val taskPos = (pendingTasks.firstOrNull() ?: doneTasks.firstOrNull())?.blockPos - ?: BlockPos(0, -1, 0) - - if (mc.player.positionVector.distanceTo(taskPos) < maxReach.value ) { - if (!isDone()) { - if(canDoTask()) { - if (!pathing) adjustPlayerPosition(false) - val currentFood = mc.player.foodStats.foodLevel - if (currentFood != prevFood) { - if (currentFood < prevFood) foodLoss++ - prevFood = currentFood - } - doTask() - } - } else { - if (checkTasks() && !pathing) { - currentBlockPos = getNextBlock(getNextBlock()) - doneTasks.clear() - updateTasks(currentBlockPos) - } else { - refreshData() + if (!active) { + active = true + BaritoneUtils.primary?.pathingControlManager?.registerProcess(HighwayToolsProcess) + } + + if (baritoneMode.value) { + pathing = BaritoneUtils.isPathing + val taskPos = (pendingTasks.firstOrNull() ?: doneTasks.firstOrNull())?.blockPos + ?: BlockPos(0, -1, 0) + + if (mc.player.positionVector.distanceTo(taskPos) < maxReach.value ) { + if (!isDone()) { + if(canDoTask()) { + if (!pathing) adjustPlayerPosition(false) + val currentFood = mc.player.foodStats.foodLevel + if (currentFood != prevFood) { + if (currentFood < prevFood) foodLoss++ + prevFood = currentFood } + doTask() } } else { - refreshData() + if (checkTasks() && !pathing) { + currentBlockPos = getNextBlock(getNextBlock()) + doneTasks.clear() + updateTasks(currentBlockPos) + } else { + refreshData() + } } } else { - if (currentBlockPos == mc.player.positionVector.toBlockPos()) { - doTask() - } else { - currentBlockPos = mc.player.positionVector.toBlockPos() - if (abs((buildDirectionSaved.ordinal - Direction.fromEntity(mc.player).ordinal) % 8) == 4) buildDirectionSaved = Direction.fromEntity(mc.player) - refreshData() - } + refreshData() } } else { - return@listener + if (currentBlockPos == mc.player.positionVector.toBlockPos()) { + doTask() + } else { + currentBlockPos = mc.player.positionVector.toBlockPos() + if (abs((buildDirectionSaved.ordinal - Direction.fromEntity(mc.player).ordinal) % 8) == 4) buildDirectionSaved = Direction.fromEntity(mc.player) + refreshData() + } } - } - - listener { - if (mc.player == null) return@listener - renderer.render(false) - } - listener { event -> - if (event.phase != Phase.PRE || rotateTimer.tick(20L, false)) return@listener - val rotation = lastHitVec?.let { RotationUtils.getRotationTo(it) } ?: return@listener + val rotation = lastHitVec?.let { RotationUtils.getRotationTo(it) } ?: return@safeListener when (interacting.value) { InteractMode.SPOOF -> { val packet = PlayerPacketManager.PlayerPacket(rotating = true, rotation = rotation) - PlayerPacketManager.addPacket(this, packet) + PlayerPacketManager.addPacket(this@HighwayTools, packet) } InteractMode.VIEW_LOCK -> { mc.player.rotationYaw = rotation.x @@ -909,7 +901,7 @@ object HighwayTools : Module() { private fun adjustPlayerPosition(bridge: Boolean) { var vec = Vec3d(getNextWalkableBlock()).add(0.5, 0.5, 0.5).subtract(mc.player.positionVector) when { - bridge && !buildDirectionSaved.isDiagonal -> vec = vec.add(Vec3d(buildDirectionSaved.directionVec).scale(0.51)) + bridge && !buildDirectionSaved.isDiagonal -> vec = vec.add(Vec3d(buildDirectionSaved.directionVec).scale(0.525)) bridge && buildDirectionSaved.isDiagonal -> vec = vec.add(Vec3d(buildDirectionSaved.directionVec).scale(0.525)) } mc.player.motionX = (vec.x / 2.0).coerceIn(-0.2, 0.2) From 231352ab27e19cfde19c10ec94851a1147a13bea Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Fri, 1 Jan 2021 22:18:31 -0500 Subject: [PATCH 162/390] Fixed return in OnUpdateWalkingPlayer --- .../me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 0a238d4375..29f1017d48 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -229,7 +229,7 @@ object HighwayTools : Module() { } safeListener { event -> - if (event.phase != Phase.PRE || rotateTimer.tick(20L, false)) return@safeListener + if (event.phase != Phase.PRE) return@safeListener updateRenderer() @@ -276,6 +276,7 @@ object HighwayTools : Module() { } } + if (rotateTimer.tick(20L, false)) return@safeListener val rotation = lastHitVec?.let { RotationUtils.getRotationTo(it) } ?: return@safeListener when (interacting.value) { From 77c0585d6e8562d72d93a653588da58f9b761441 Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Fri, 1 Jan 2021 22:30:20 -0500 Subject: [PATCH 163/390] Auto formatted HighwayTools --- .../kami/module/modules/misc/HighwayTools.kt | 100 +++++++++--------- 1 file changed, 50 insertions(+), 50 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 29f1017d48..a41a888b18 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -57,10 +57,10 @@ import kotlin.math.sqrt * @since 20/08/2020 */ @Module.Info( - name = "HighwayTools", - description = "Be the grief a step a head.", - category = Module.Category.MISC, - modulePriority = 10 + name = "HighwayTools", + description = "Be the grief a step a head.", + category = Module.Category.MISC, + modulePriority = 10 ) object HighwayTools : Module() { @@ -98,14 +98,14 @@ object HighwayTools : Module() { // internal settings val ignoreBlocks = hashSetOf( - Blocks.STANDING_SIGN, - Blocks.WALL_SIGN, - Blocks.STANDING_BANNER, - Blocks.WALL_BANNER, - Blocks.BEDROCK, - Blocks.END_PORTAL, - Blocks.END_PORTAL_FRAME, - Blocks.PORTAL + Blocks.STANDING_SIGN, + Blocks.WALL_SIGN, + Blocks.STANDING_BANNER, + Blocks.WALL_BANNER, + Blocks.BEDROCK, + Blocks.END_PORTAL, + Blocks.END_PORTAL_FRAME, + Blocks.PORTAL ) var material: Block = Blocks.OBSIDIAN var fillerMat: Block = Blocks.NETHERRACK @@ -146,15 +146,14 @@ object HighwayTools : Module() { } /* Turn on inventory manager if the users wants us to control it */ - if(toggleInventoryManager.value && InventoryManager.isDisabled) InventoryManager.enable() + if (toggleInventoryManager.value && InventoryManager.isDisabled) InventoryManager.enable() /* Turn on Auto Obsidian if the user wants us to control it. */ - if(toggleAutoObsidian.value && AutoObsidian.isDisabled && mode.value != Mode.TUNNEL) { + if (toggleAutoObsidian.value && AutoObsidian.isDisabled && mode.value != Mode.TUNNEL) { /* If we have no obsidian, immediately turn on Auto Obsidian */ - if(InventoryUtils.countItemAll(49) == 0) { + if (InventoryUtils.countItemAll(49) == 0) { AutoObsidian.enable() - } - else { + } else { Thread { /* Wait 1 second because turning both on simultaneously is buggy */ Thread.sleep(1000L) @@ -210,10 +209,10 @@ object HighwayTools : Module() { /* Turn off inventory manager if the users wants us to control it */ - if(toggleInventoryManager.value && InventoryManager.isEnabled) InventoryManager.disable() + if (toggleInventoryManager.value && InventoryManager.isEnabled) InventoryManager.disable() /* Turn off auto obsidian if the user wants us to control it */ - if(toggleAutoObsidian.value && AutoObsidian.isEnabled) { + if (toggleAutoObsidian.value && AutoObsidian.isEnabled) { AutoObsidian.disable() } @@ -243,9 +242,9 @@ object HighwayTools : Module() { val taskPos = (pendingTasks.firstOrNull() ?: doneTasks.firstOrNull())?.blockPos ?: BlockPos(0, -1, 0) - if (mc.player.positionVector.distanceTo(taskPos) < maxReach.value ) { + if (mc.player.positionVector.distanceTo(taskPos) < maxReach.value) { if (!isDone()) { - if(canDoTask()) { + if (canDoTask()) { if (!pathing) adjustPlayerPosition(false) val currentFood = mc.player.foodStats.foodLevel if (currentFood != prevFood) { @@ -347,21 +346,21 @@ object HighwayTools : Module() { when (blockTask.taskState) { TaskState.DONE -> doDone(blockTask) - TaskState.BREAKING -> if(!doBreaking(blockTask)) { + TaskState.BREAKING -> if (!doBreaking(blockTask)) { stuckManager.increase(blockTask) return } TaskState.BROKEN -> doBroken(blockTask) TaskState.PLACED -> doPlaced(blockTask) - TaskState.EMERGENCY_BREAK -> if(!doBreak(blockTask)) { + TaskState.EMERGENCY_BREAK -> if (!doBreak(blockTask)) { stuckManager.increase(blockTask) return } - TaskState.BREAK -> if(!doBreak(blockTask)) { + TaskState.BREAK -> if (!doBreak(blockTask)) { stuckManager.increase(blockTask) return } - TaskState.PLACE, TaskState.LIQUID_SOURCE, TaskState.LIQUID_FLOW -> if(!doPlace(blockTask)) { + TaskState.PLACE, TaskState.LIQUID_SOURCE, TaskState.LIQUID_FLOW -> if (!doPlace(blockTask)) { stuckManager.increase(blockTask) return } @@ -618,7 +617,7 @@ object HighwayTools : Module() { // for (x in InventoryUtils.getSlots(0, 35, blockID)!!) InventoryUtils.throwAllInSlot(x) // } if (InventoryUtils.getSlotsHotbar(blockID) == null && - noHotbar != null) { + noHotbar != null) { when (blockTask.block) { fillerMat -> InventoryUtils.moveToSlot(noHotbar[0], 37) material -> InventoryUtils.moveToSlot(noHotbar[0], 38) @@ -826,7 +825,7 @@ object HighwayTools : Module() { if (mc.world.getBlockState(offPos).material.isReplaceable) continue if (mc.player.getPositionEyes(1f).distanceTo(Vec3d(offPos).add(WorldUtils.getHitVecOffset(side))) > maxReach.value) continue val rotationVector = Vec3d(offPos).add(0.5, 0.5, 0.5).add(Vec3d(side.opposite.directionVec).scale(0.499)) - val rt = mc.world.rayTraceBlocks(mc.player.getPositionEyes(1f), rotationVector, false)?: continue + val rt = mc.world.rayTraceBlocks(mc.player.getPositionEyes(1f), rotationVector, false) ?: continue if (rt.typeOfHit != RayTraceResult.Type.BLOCK) continue if (rt.blockPos == offPos && offPos.offset(rt.sideHit) == blockTask.blockPos) { directHits.add(rt) @@ -848,7 +847,7 @@ object HighwayTools : Module() { return false } return if (illegalPlacements.value) { - if(debugMessages.value == DebugMessages.ALL) sendChatMessage("Trying to place through wall ${blockTask.blockPos}") + if (debugMessages.value == DebugMessages.ALL) sendChatMessage("Trying to place through wall ${blockTask.blockPos}") placeBlockWall(blockTask) } else { false @@ -957,8 +956,8 @@ object HighwayTools : Module() { StringBuilder(2).run { append( "$chatName Module stopped." + - "\n §9> §7Placed blocks: §a$totalBlocksPlaced§r" + - "\n §9> §7Destroyed blocks: §a$totalBlocksDestroyed§r" + "\n §9> §7Placed blocks: §a$totalBlocksPlaced§r" + + "\n §9> §7Destroyed blocks: §a$totalBlocksDestroyed§r" ) if (baritoneMode.value) append("\n §9> §7Distance: §a${startingBlockPos.distanceTo(currentBlockPos).toInt()}§r") @@ -998,16 +997,16 @@ object HighwayTools : Module() { val pavingLeftAll = (materialLeft + indirectMaterialLeft) / (blueprintStats.first + 1) val runtimeSec = ((System.currentTimeMillis() - startTime) / 1000) + 0.0001 - val seconds = (runtimeSec % 60).toInt().toString().padStart(2,'0') - val minutes = ((runtimeSec % 3600) / 60).toInt().toString().padStart(2,'0') - val hours = (runtimeSec / 3600).toInt().toString().padStart(2,'0') + val seconds = (runtimeSec % 60).toInt().toString().padStart(2, '0') + val minutes = ((runtimeSec % 3600) / 60).toInt().toString().padStart(2, '0') + val hours = (runtimeSec / 3600).toInt().toString().padStart(2, '0') val distanceDone = startingBlockPos.distanceTo(currentBlockPos).toInt() val secLeft = runtimeSec / (distanceDone * pavingLeftAll + 0.0001) - val secondsLeft = (secLeft % 60).toInt().toString().padStart(2,'0') - val minutesLeft = ((secLeft % 3600) / 60).toInt().toString().padStart(2,'0') - val hoursLeft = (secLeft / 3600).toInt().toString().padStart(2,'0') + val secondsLeft = (secLeft % 60).toInt().toString().padStart(2, '0') + val minutesLeft = ((secLeft % 3600) / 60).toInt().toString().padStart(2, '0') + val hoursLeft = (secLeft / 3600).toInt().toString().padStart(2, '0') val statistics = mutableListOf( "§rPerformance", @@ -1019,8 +1018,8 @@ object HighwayTools : Module() { "§rEnvironment", " §7Starting coordinates: §9(${startingBlockPos.asString()})", " §7Direction: §9${buildDirectionSaved.displayName}", - " §7Blocks destroyed: §9$totalBlocksDestroyed".padStart(6,'0'), - " §7Blocks placed: §9$totalBlocksPlaced".padStart(6,'0'), + " §7Blocks destroyed: §9$totalBlocksDestroyed".padStart(6, '0'), + " §7Blocks placed: §9$totalBlocksPlaced".padStart(6, '0'), " §7Material: §9${material.localizedName}", " §7Filler: §9${fillerMat.localizedName}", "§rTask", @@ -1054,8 +1053,8 @@ object HighwayTools : Module() { for (step in 1..3) { val pos = relativeDirection(currentBlockPos, step, 0) if (mc.world.getBlockState(pos.down()).block == material && - mc.world.getBlockState(pos).block == Blocks.AIR && - mc.world.getBlockState(pos.up()).block == Blocks.AIR) lastWalkable = pos + mc.world.getBlockState(pos).block == Blocks.AIR && + mc.world.getBlockState(pos.up()).block == Blocks.AIR) lastWalkable = pos else break } } @@ -1063,12 +1062,13 @@ object HighwayTools : Module() { for (step in 1..3) { val pos = relativeDirection(currentBlockPos, step, 0) if (mc.world.getBlockState(pos.down()).block == fillerMat && - mc.world.getBlockState(pos).block == Blocks.AIR && - mc.world.getBlockState(pos.up()).block == Blocks.AIR) lastWalkable = pos + mc.world.getBlockState(pos).block == Blocks.AIR && + mc.world.getBlockState(pos.up()).block == Blocks.AIR) lastWalkable = pos else break } } - else -> {} + else -> { + } } return lastWalkable @@ -1242,9 +1242,9 @@ object HighwayTools : Module() { } data class StuckManagement( - var stuckLevel: StuckLevel, - var stuckValue: Int - ) { + var stuckLevel: StuckLevel, + var stuckValue: Int + ) { fun increase(blockTask: BlockTask) { when (blockTask.taskState) { @@ -1261,7 +1261,7 @@ object HighwayTools : Module() { if (debugMessages.value == DebugMessages.ALL) sendChatMessage("$chatName Shuffled tasks $stuckValue") } } - stuckValue in 100..200 -> { + stuckValue in 100..200 -> { stuckLevel = StuckLevel.MINOR if (!pathing && blockTask.taskState == TaskState.PLACE && !buildDirectionSaved.isDiagonal) adjustPlayerPosition(true) if (blockTask.taskState != TaskState.BREAKING) { @@ -1302,9 +1302,9 @@ object HighwayTools : Module() { } data class BlockTask( - val blockPos: BlockPos, - var taskState: TaskState, - var block: Block + val blockPos: BlockPos, + var taskState: TaskState, + var block: Block ) { override fun toString(): String { return "Block: " + block.localizedName + " @ Position: (" + blockPos.asString() + ") Priority: " + taskState.ordinal + " State: " + taskState.toString() From 4cc1bf8275897628544522d326b9acd6bc0a7cf6 Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Fri, 1 Jan 2021 22:44:14 -0500 Subject: [PATCH 164/390] Cleaned up duplicated code --- .../kami/module/modules/misc/AutoTool.kt | 10 +- .../kami/module/modules/misc/HighwayTools.kt | 129 ++++++------------ 2 files changed, 45 insertions(+), 94 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoTool.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoTool.kt index e3e7c6bb07..bd5391458d 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoTool.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoTool.kt @@ -5,6 +5,7 @@ import me.zeroeightsix.kami.mixin.extension.syncCurrentPlayItem import me.zeroeightsix.kami.module.Module import me.zeroeightsix.kami.setting.Setting import me.zeroeightsix.kami.setting.Settings +import me.zeroeightsix.kami.util.InventoryUtils import me.zeroeightsix.kami.util.combat.CombatUtils import net.minecraft.block.state.IBlockState import net.minecraft.enchantment.EnchantmentHelper @@ -57,7 +58,7 @@ object AutoTool : Module() { } } - private fun equipBestTool(blockState: IBlockState) { + fun equipBestTool(blockState: IBlockState) { var bestSlot = -1 var max = 0.0 @@ -75,12 +76,7 @@ object AutoTool : Module() { } } } - if (bestSlot != -1) equip(bestSlot) - } - - private fun equip(slot: Int) { - mc.player.inventory.currentItem = slot - mc.playerController.syncCurrentPlayItem() + if (bestSlot != -1) InventoryUtils.swapSlot(bestSlot) } init { diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index a41a888b18..0b07a07975 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -7,7 +7,6 @@ import me.zeroeightsix.kami.event.events.OnUpdateWalkingPlayerEvent import me.zeroeightsix.kami.event.events.RenderWorldEvent import me.zeroeightsix.kami.gui.kami.DisplayGuiScreen import me.zeroeightsix.kami.manager.managers.PlayerPacketManager -import me.zeroeightsix.kami.mixin.extension.syncCurrentPlayItem import me.zeroeightsix.kami.module.Module import me.zeroeightsix.kami.module.modules.player.AutoEat import me.zeroeightsix.kami.module.modules.player.InventoryManager @@ -32,11 +31,8 @@ import me.zeroeightsix.kami.util.threads.safeListener import net.minecraft.block.Block import net.minecraft.block.Block.getIdFromBlock import net.minecraft.block.BlockLiquid -import net.minecraft.block.state.IBlockState import net.minecraft.client.audio.PositionedSoundRecord -import net.minecraft.enchantment.EnchantmentHelper import net.minecraft.init.Blocks -import net.minecraft.init.Enchantments import net.minecraft.init.SoundEvents import net.minecraft.network.play.client.CPacketPlayerDigging import net.minecraft.util.EnumFacing @@ -49,7 +45,6 @@ import org.kamiblue.event.listener.listener import java.util.* import kotlin.collections.ArrayList import kotlin.math.abs -import kotlin.math.pow import kotlin.math.sqrt /** @@ -97,7 +92,7 @@ object HighwayTools : Module() { private val aOutline = register(Settings.integerBuilder("OutlineAlpha").withValue(91).withRange(0, 255).withStep(1).withVisibility { outline.value && page.value == Page.CONFIG }) // internal settings - val ignoreBlocks = hashSetOf( + val ignoreBlocks = setOf( Blocks.STANDING_SIGN, Blocks.WALL_SIGN, Blocks.STANDING_BANNER, @@ -596,7 +591,7 @@ object HighwayTools : Module() { private fun inventoryProcessor(blockTask: BlockTask): Boolean { when (blockTask.taskState) { TaskState.BREAK, TaskState.EMERGENCY_BREAK -> { - equipBestTool(mc.world.getBlockState(blockTask.blockPos)) + AutoTool.equipBestTool(mc.world.getBlockState(blockTask.blockPos)) // val noHotbar = InventoryUtils.getSlotsNoHotbar(278) // if (InventoryUtils.getSlotsHotbar(278) == null && noHotbar != null) { //// InventoryUtils.moveToHotbar(278, 130) @@ -638,32 +633,6 @@ object HighwayTools : Module() { return true } - private fun equipBestTool(blockState: IBlockState) { - var bestSlot = -1 - var max = 0.0 - - for (i in 0..8) { - val stack = mc.player.inventory.getStackInSlot(i) - if (stack.isEmpty) continue - var speed = stack.getDestroySpeed(blockState) - var eff: Int - - if (speed > 1) { - speed += (if (EnchantmentHelper.getEnchantmentLevel(Enchantments.EFFICIENCY, stack).also { eff = it } > 0.0) eff.toDouble().pow(2.0) + 1 else 0.0).toFloat() - if (speed > max) { - max = speed.toDouble() - bestSlot = i - } - } - } - if (bestSlot != -1) equip(bestSlot) - } - - private fun equip(slot: Int) { - mc.player.inventory.currentItem = slot - mc.playerController.syncCurrentPlayItem() - } - private fun liquidHandler(blockTask: BlockTask): Boolean { var foundLiquid = false for (side in EnumFacing.values()) { @@ -1149,7 +1118,7 @@ object HighwayTools : Module() { var cursor = blockPos.down() when (mode.value) { - Mode.HIGHWAY -> { + Mode.HIGHWAY, Mode.TUNNEL -> { if (baritoneMode.value) { cursor = relativeDirection(cursor, 1, 0) blueprint.add(Pair(cursor, material)) @@ -1165,67 +1134,53 @@ object HighwayTools : Module() { } else { blueprint.add(Pair(evenCursor, material)) } - for (i in 1 until clearHeight.value + 1) { - for (j in 1 until buildIterationsWidth) { - if (i == 1) { - if (j == buildIterationsWidth - 1 && !cornerBlock.value) { - genOffset(cursor, i, j, fillerMat, isOdd) - } else { - genOffset(cursor, i, j, material, isOdd) - } - } else { - if (i <= railingHeight.value + 1 && j == buildIterationsWidth - 1) { - genOffset(cursor, i, j, material, isOdd) + if (mode.value == Mode.HIGHWAY) { + for (i in 1 until clearHeight.value + 1) { + for (j in 1 until buildIterationsWidth) { + if (i == 1) { + if (j == buildIterationsWidth - 1 && !cornerBlock.value) { + genOffset(cursor, i, j, fillerMat, isOdd) + } else { + genOffset(cursor, i, j, material, isOdd) + } } else { - if (clearSpace.value) { - genOffset(cursor, i, j, Blocks.AIR, isOdd) + if (i <= railingHeight.value + 1 && j == buildIterationsWidth - 1) { + genOffset(cursor, i, j, material, isOdd) + } else { + if (clearSpace.value) { + genOffset(cursor, i, j, Blocks.AIR, isOdd) + } } } } + cursor = cursor.up() + evenCursor = evenCursor.up() + if (clearSpace.value && i < clearHeight.value) { + blueprint.add(Pair(cursor, Blocks.AIR)) + if (!isOdd) blueprint.add(Pair(evenCursor, Blocks.AIR)) + } } - cursor = cursor.up() - evenCursor = evenCursor.up() - if (clearSpace.value && i < clearHeight.value) { - blueprint.add(Pair(cursor, Blocks.AIR)) - if (!isOdd) blueprint.add(Pair(evenCursor, Blocks.AIR)) - } - } - } - Mode.TUNNEL -> { - if (baritoneMode.value) { - cursor = relativeDirection(cursor, 1, 0) - blueprint.add(Pair(cursor, fillerMat)) - } - cursor = relativeDirection(cursor, 1, 0) - blueprint.add(Pair(cursor, fillerMat)) - var buildIterationsWidth = buildWidth.value / 2 - var evenCursor = relativeDirection(cursor, 1, 2) - var isOdd = false - if (buildWidth.value % 2 == 1) { - isOdd = true - buildIterationsWidth++ } else { - blueprint.add(Pair(evenCursor, fillerMat)) - } - for (i in 1 until clearHeight.value + 2) { - for (j in 1 until buildIterationsWidth) { - if (i > 1) { - if (cornerBlock.value && i == 2 && j == buildIterationsWidth - 1) continue - blueprint.add(Pair(relativeDirection(cursor, j, -2), Blocks.AIR)) - if (isOdd) blueprint.add(Pair(relativeDirection(cursor, j, 2), Blocks.AIR)) - else blueprint.add(Pair(relativeDirection(evenCursor, j, 2), Blocks.AIR)) - if (buildDirectionSaved.isDiagonal) { - blueprint.add(Pair(relativeDirection(cursor, j, -3), Blocks.AIR)) - if (isOdd) blueprint.add(Pair(relativeDirection(cursor, j, 3), Blocks.AIR)) - else blueprint.add(Pair(relativeDirection(evenCursor, j, 3), Blocks.AIR)) + for (i in 1 until clearHeight.value + 2) { + for (j in 1 until buildIterationsWidth) { + if (i > 1) { + if (cornerBlock.value && i == 2 && j == buildIterationsWidth - 1) continue + blueprint.add(Pair(relativeDirection(cursor, j, -2), Blocks.AIR)) + if (isOdd) blueprint.add(Pair(relativeDirection(cursor, j, 2), Blocks.AIR)) + else blueprint.add(Pair(relativeDirection(evenCursor, j, 2), Blocks.AIR)) + if (buildDirectionSaved.isDiagonal) { + blueprint.add(Pair(relativeDirection(cursor, j, -3), Blocks.AIR)) + if (isOdd) blueprint.add(Pair(relativeDirection(cursor, j, 3), Blocks.AIR)) + else blueprint.add(Pair(relativeDirection(evenCursor, j, 3), Blocks.AIR)) + } } } - } - cursor = cursor.up() - evenCursor = evenCursor.up() - if (clearSpace.value && i < clearHeight.value + 1) { - blueprint.add(Pair(cursor, Blocks.AIR)) - if (!isOdd) blueprint.add(Pair(evenCursor, Blocks.AIR)) + cursor = cursor.up() + evenCursor = evenCursor.up() + if (clearSpace.value && i < clearHeight.value + 1) { + blueprint.add(Pair(cursor, Blocks.AIR)) + if (!isOdd) blueprint.add(Pair(evenCursor, Blocks.AIR)) + } } } } From 23c76f45f3a84b086e553ce82475ecb71c458bc6 Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Fri, 1 Jan 2021 22:48:12 -0500 Subject: [PATCH 165/390] Replaced getPlaceableSide with WorldUtils.getNeighbour --- .../kami/module/modules/misc/HighwayTools.kt | 22 +++++-------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 0b07a07975..00b47ea336 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -564,8 +564,8 @@ object HighwayTools : Module() { if (buildDirectionSaved.isDiagonal) { val blockUp = mc.world.getBlockState(blockPos.up()).block when { - getPlaceableSide(blockPos.up()) == null && blockUp != material -> addTask(blockPos, TaskState.PLACE, fillerMat) - getPlaceableSide(blockPos.up()) != null -> addTask(blockPos, fillerMat) + WorldUtils.getNeighbour(blockPos.up(), 1) == null && blockUp != material -> addTask(blockPos, TaskState.PLACE, fillerMat) + WorldUtils.getNeighbour(blockPos.up(), 1) != null -> addTask(blockPos, fillerMat) } } } else { @@ -769,9 +769,8 @@ object HighwayTools : Module() { // Only temporary till we found solution to avoid untraceable blocks private fun placeBlockWall(blockTask: BlockTask): Boolean { - val side = getPlaceableSide(blockTask.blockPos) ?: return false - val neighbour = blockTask.blockPos.offset(side) - val hitVec = Vec3d(neighbour).add(0.5, 0.5, 0.5).add(Vec3d(side.opposite.directionVec).scale(0.5)) + val pair = WorldUtils.getNeighbour(blockTask.blockPos, 1) ?: return false + val hitVec = WorldUtils.getHitVec(pair.second, pair.first) lastHitVec = hitVec rotateTimer.reset() @@ -779,7 +778,7 @@ object HighwayTools : Module() { defaultScope.launch { delay(10L) onMainThreadSafe { - placeBlock(neighbour, side.opposite) + placeBlock(pair.second, pair.first) if (NoBreakAnimation.isEnabled) NoBreakAnimation.resetMining() } } @@ -843,22 +842,11 @@ object HighwayTools : Module() { delay(10L) onMainThreadSafe { placeBlock(rayTrace.blockPos, rayTrace.sideHit) - if (NoBreakAnimation.isEnabled) NoBreakAnimation.resetMining() } } return true } - private fun getPlaceableSide(pos: BlockPos): EnumFacing? { - for (side in EnumFacing.values()) { - val neighbour = pos.offset(side) - if (!mc.world.getBlockState(neighbour).block.canCollideCheck(mc.world.getBlockState(neighbour), false)) continue - val blockState = mc.world.getBlockState(neighbour) - if (!blockState.material.isReplaceable) return side - } - return null - } - private fun isInsideSelection(blockPos: BlockPos): Boolean { return pendingTasks.any { it.blockPos == blockPos } } From 2f0bfda57de1a282711fb656ab4ebf4d925fa34e Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Fri, 1 Jan 2021 23:03:47 -0500 Subject: [PATCH 166/390] Grouped up some functions by calls --- .../kami/module/modules/misc/HighwayTools.kt | 244 +++++++++--------- 1 file changed, 124 insertions(+), 120 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 00b47ea336..1373e679d5 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -24,6 +24,7 @@ import me.zeroeightsix.kami.util.math.VectorUtils.distanceTo import me.zeroeightsix.kami.util.math.VectorUtils.getBlockPositionsInArea import me.zeroeightsix.kami.util.math.VectorUtils.multiply import me.zeroeightsix.kami.util.math.VectorUtils.toBlockPos +import me.zeroeightsix.kami.util.math.VectorUtils.toVec3d import me.zeroeightsix.kami.util.text.MessageSendHelper.sendChatMessage import me.zeroeightsix.kami.util.threads.defaultScope import me.zeroeightsix.kami.util.threads.onMainThreadSafe @@ -582,10 +583,86 @@ object HighwayTools : Module() { } } - private fun shuffleTasks() { - val shuffled = pendingTasks.shuffled() - pendingTasks.clear() - pendingTasks.addAll(shuffled) + private fun updateBlockArray(blockPos: BlockPos) { + var cursor = blockPos.down() + + when (mode.value) { + Mode.HIGHWAY, Mode.TUNNEL -> { + if (baritoneMode.value) { + cursor = relativeDirection(cursor, 1, 0) + blueprint.add(Pair(cursor, material)) + } + cursor = relativeDirection(cursor, 1, 0) + blueprint.add(Pair(cursor, material)) + var buildIterationsWidth = buildWidth.value / 2 + var evenCursor = relativeDirection(cursor, 1, 2) + var isOdd = false + if (buildWidth.value % 2 == 1) { + isOdd = true + buildIterationsWidth++ + } else { + blueprint.add(Pair(evenCursor, material)) + } + if (mode.value == Mode.HIGHWAY) { + for (i in 1 until clearHeight.value + 1) { + for (j in 1 until buildIterationsWidth) { + if (i == 1) { + if (j == buildIterationsWidth - 1 && !cornerBlock.value) { + genOffset(cursor, i, j, fillerMat, isOdd) + } else { + genOffset(cursor, i, j, material, isOdd) + } + } else { + if (i <= railingHeight.value + 1 && j == buildIterationsWidth - 1) { + genOffset(cursor, i, j, material, isOdd) + } else { + if (clearSpace.value) { + genOffset(cursor, i, j, Blocks.AIR, isOdd) + } + } + } + } + cursor = cursor.up() + evenCursor = evenCursor.up() + if (clearSpace.value && i < clearHeight.value) { + blueprint.add(Pair(cursor, Blocks.AIR)) + if (!isOdd) blueprint.add(Pair(evenCursor, Blocks.AIR)) + } + } + } else { + for (i in 1 until clearHeight.value + 2) { + for (j in 1 until buildIterationsWidth) { + if (i > 1) { + if (cornerBlock.value && i == 2 && j == buildIterationsWidth - 1) continue + blueprint.add(Pair(relativeDirection(cursor, j, -2), Blocks.AIR)) + if (isOdd) blueprint.add(Pair(relativeDirection(cursor, j, 2), Blocks.AIR)) + else blueprint.add(Pair(relativeDirection(evenCursor, j, 2), Blocks.AIR)) + if (buildDirectionSaved.isDiagonal) { + blueprint.add(Pair(relativeDirection(cursor, j, -3), Blocks.AIR)) + if (isOdd) blueprint.add(Pair(relativeDirection(cursor, j, 3), Blocks.AIR)) + else blueprint.add(Pair(relativeDirection(evenCursor, j, 3), Blocks.AIR)) + } + } + } + cursor = cursor.up() + evenCursor = evenCursor.up() + if (clearSpace.value && i < clearHeight.value + 1) { + blueprint.add(Pair(cursor, Blocks.AIR)) + if (!isOdd) blueprint.add(Pair(evenCursor, Blocks.AIR)) + } + } + } + } + Mode.FLAT -> { + for (bp in getBlockPositionsInArea(cursor.north(buildWidth.value).west(buildWidth.value), cursor.south(buildWidth.value).east(buildWidth.value))) { + blueprint.add(Pair(bp, material)) + } + } + null -> { + sendChatMessage("Module logic is a lie.") + disable() + } + } } private fun inventoryProcessor(blockTask: BlockTask): Boolean { @@ -750,6 +827,17 @@ object HighwayTools : Module() { } } + private fun getAABBSide(bb: AxisAlignedBB, side: EnumFacing): Double { + return when (side) { + EnumFacing.UP -> bb.maxY - bb.center.y + EnumFacing.NORTH -> bb.center.z - bb.minZ + EnumFacing.EAST -> bb.maxX - bb.center.x + EnumFacing.SOUTH -> bb.maxZ - bb.center.z + EnumFacing.WEST -> bb.center.x - bb.minX + EnumFacing.DOWN -> bb.center.y - bb.minY + } + } + /* Dispatches a thread to mine any non-netherrack blocks generically */ private fun dispatchGenericMineThread(blockTask: BlockTask, facing: EnumFacing) { val digPacket: CPacketPlayerDigging = when (blockTask.taskState) { @@ -788,12 +876,14 @@ object HighwayTools : Module() { private fun placeBlock(blockTask: BlockTask): Boolean { val directHits = mutableListOf() val emergencyHits = mutableListOf() + val eyePos = mc.player.getPositionEyes(1f) + for (side in EnumFacing.values()) { val offPos = blockTask.blockPos.offset(side) if (mc.world.getBlockState(offPos).material.isReplaceable) continue - if (mc.player.getPositionEyes(1f).distanceTo(Vec3d(offPos).add(WorldUtils.getHitVecOffset(side))) > maxReach.value) continue - val rotationVector = Vec3d(offPos).add(0.5, 0.5, 0.5).add(Vec3d(side.opposite.directionVec).scale(0.499)) - val rt = mc.world.rayTraceBlocks(mc.player.getPositionEyes(1f), rotationVector, false) ?: continue + if (eyePos.distanceTo(Vec3d(offPos).add(WorldUtils.getHitVecOffset(side))) > maxReach.value) continue + val rotationVector = offPos.toVec3d().add(Vec3d(side.opposite.directionVec).scale(0.499)) + val rt = mc.world.rayTraceBlocks(eyePos, rotationVector, false) ?: continue if (rt.typeOfHit != RayTraceResult.Type.BLOCK) continue if (rt.blockPos == offPos && offPos.offset(rt.sideHit) == blockTask.blockPos) { directHits.add(rt) @@ -806,8 +896,9 @@ object HighwayTools : Module() { var rayTrace = emergencyHits[0] var shortestRT = 99.0 for (rt in emergencyHits) { - if (mc.player.getPositionEyes(1f).distanceTo(Vec3d(rt.blockPos).add(WorldUtils.getHitVecOffset(rt.sideHit))) < shortestRT) { - shortestRT = mc.player.getPositionEyes(1f).distanceTo(Vec3d(rt.blockPos).add(WorldUtils.getHitVecOffset(rt.sideHit))) + val dist = eyePos.distanceTo(WorldUtils.getHitVec(rt.blockPos, rt.sideHit)) + if (dist < shortestRT) { + shortestRT = dist rayTrace = rt } } @@ -825,8 +916,9 @@ object HighwayTools : Module() { var rayTrace: RayTraceResult? = null var shortestRT = 99.0 for (rt in directHits) { - if (mc.player.getPositionEyes(1f).distanceTo(Vec3d(rt.blockPos).add(WorldUtils.getHitVecOffset(rt.sideHit))) < shortestRT) { - shortestRT = mc.player.getPositionEyes(1f).distanceTo(Vec3d(rt.blockPos).add(WorldUtils.getHitVecOffset(rt.sideHit))) + val dist = eyePos.distanceTo(WorldUtils.getHitVec(rt.blockPos, rt.sideHit)) + if (dist < shortestRT) { + shortestRT = dist rayTrace = rt } } @@ -856,7 +948,7 @@ object HighwayTools : Module() { } private fun adjustPlayerPosition(bridge: Boolean) { - var vec = Vec3d(getNextWalkableBlock()).add(0.5, 0.5, 0.5).subtract(mc.player.positionVector) + var vec = getNextWalkableBlock().toVec3d().subtract(mc.player.positionVector) when { bridge && !buildDirectionSaved.isDiagonal -> vec = vec.add(Vec3d(buildDirectionSaved.directionVec).scale(0.525)) bridge && buildDirectionSaved.isDiagonal -> vec = vec.add(Vec3d(buildDirectionSaved.directionVec).scale(0.525)) @@ -865,15 +957,6 @@ object HighwayTools : Module() { mc.player.motionZ = (vec.z / 2.0).coerceIn(-0.2, 0.2) } - private fun getQueue(): List { - val message: MutableList = mutableListOf() - message.add("QUEUE:") - for (blockTask in pendingTasks) message.add(" " + blockTask.block.localizedName + "@(" + blockTask.blockPos.asString() + ") Priority: " + blockTask.taskState.ordinal + " State: " + blockTask.taskState.toString()) - message.add("DONE:") - for (blockTask in doneTasks) message.add(" " + blockTask.block.localizedName + "@(" + blockTask.blockPos.asString() + ") Priority: " + blockTask.taskState.ordinal + " State: " + blockTask.taskState.toString()) - return message - } - fun printSettings() { StringBuilder(ignoreBlocks.size + 1).run { append("$chatName Settings" + @@ -995,13 +1078,25 @@ object HighwayTools : Module() { ) if (printDebug.value) { - // for (x in getQueue()) sendChatMessage(x) statistics.addAll(getQueue()) } return statistics } + private fun getQueue(): List { + val message = ArrayList() + message.add("QUEUE:") + addTaskToMessageList(message, pendingTasks) + message.add("DONE:") + addTaskToMessageList(message, doneTasks) + return message + } + + private fun addTaskToMessageList(list: ArrayList, tasks: Collection) { + for (blockTask in tasks) list.add(" " + blockTask.block.localizedName + "@(" + blockTask.blockPos.asString() + ") Priority: " + blockTask.taskState.ordinal + " State: " + blockTask.taskState.toString()) + } + fun getNextWalkableBlock(): BlockPos { var lastWalkable = getNextBlock() @@ -1031,11 +1126,7 @@ object HighwayTools : Module() { return lastWalkable } - private fun getNextBlock(): BlockPos { - return getNextBlock(currentBlockPos) - } - - private fun getNextBlock(blockPos: BlockPos): BlockPos { + private fun getNextBlock(blockPos: BlockPos = currentBlockPos): BlockPos { return relativeDirection(blockPos, 1, 0) } @@ -1045,17 +1136,6 @@ object HighwayTools : Module() { return current.add(direction.directionVec.multiply(steps)) } - private fun getAABBSide(bb: AxisAlignedBB, side: EnumFacing): Double { - return when (side) { - EnumFacing.UP -> bb.maxY - bb.center.y - EnumFacing.NORTH -> bb.center.z - bb.minZ - EnumFacing.EAST -> bb.maxX - bb.center.x - EnumFacing.SOUTH -> bb.maxZ - bb.center.z - EnumFacing.WEST -> bb.center.x - bb.minX - EnumFacing.DOWN -> bb.center.y - bb.minY - } - } - private fun addOffset(cursor: BlockPos, height: Int, width: Int, mat: Block, turn: Boolean) { var turnValue = 1 if (turn) turnValue = -1 @@ -1102,88 +1182,6 @@ object HighwayTools : Module() { shuffleTasks() } - private fun updateBlockArray(blockPos: BlockPos) { - var cursor = blockPos.down() - - when (mode.value) { - Mode.HIGHWAY, Mode.TUNNEL -> { - if (baritoneMode.value) { - cursor = relativeDirection(cursor, 1, 0) - blueprint.add(Pair(cursor, material)) - } - cursor = relativeDirection(cursor, 1, 0) - blueprint.add(Pair(cursor, material)) - var buildIterationsWidth = buildWidth.value / 2 - var evenCursor = relativeDirection(cursor, 1, 2) - var isOdd = false - if (buildWidth.value % 2 == 1) { - isOdd = true - buildIterationsWidth++ - } else { - blueprint.add(Pair(evenCursor, material)) - } - if (mode.value == Mode.HIGHWAY) { - for (i in 1 until clearHeight.value + 1) { - for (j in 1 until buildIterationsWidth) { - if (i == 1) { - if (j == buildIterationsWidth - 1 && !cornerBlock.value) { - genOffset(cursor, i, j, fillerMat, isOdd) - } else { - genOffset(cursor, i, j, material, isOdd) - } - } else { - if (i <= railingHeight.value + 1 && j == buildIterationsWidth - 1) { - genOffset(cursor, i, j, material, isOdd) - } else { - if (clearSpace.value) { - genOffset(cursor, i, j, Blocks.AIR, isOdd) - } - } - } - } - cursor = cursor.up() - evenCursor = evenCursor.up() - if (clearSpace.value && i < clearHeight.value) { - blueprint.add(Pair(cursor, Blocks.AIR)) - if (!isOdd) blueprint.add(Pair(evenCursor, Blocks.AIR)) - } - } - } else { - for (i in 1 until clearHeight.value + 2) { - for (j in 1 until buildIterationsWidth) { - if (i > 1) { - if (cornerBlock.value && i == 2 && j == buildIterationsWidth - 1) continue - blueprint.add(Pair(relativeDirection(cursor, j, -2), Blocks.AIR)) - if (isOdd) blueprint.add(Pair(relativeDirection(cursor, j, 2), Blocks.AIR)) - else blueprint.add(Pair(relativeDirection(evenCursor, j, 2), Blocks.AIR)) - if (buildDirectionSaved.isDiagonal) { - blueprint.add(Pair(relativeDirection(cursor, j, -3), Blocks.AIR)) - if (isOdd) blueprint.add(Pair(relativeDirection(cursor, j, 3), Blocks.AIR)) - else blueprint.add(Pair(relativeDirection(evenCursor, j, 3), Blocks.AIR)) - } - } - } - cursor = cursor.up() - evenCursor = evenCursor.up() - if (clearSpace.value && i < clearHeight.value + 1) { - blueprint.add(Pair(cursor, Blocks.AIR)) - if (!isOdd) blueprint.add(Pair(evenCursor, Blocks.AIR)) - } - } - } - } - Mode.FLAT -> { - for (bp in getBlockPositionsInArea(cursor.north(buildWidth.value).west(buildWidth.value), cursor.south(buildWidth.value).east(buildWidth.value))) { - blueprint.add(Pair(bp, material)) - } - } - null -> { - sendChatMessage("Module logic is a lie.") - disable() - } - } - } - data class StuckManagement( var stuckLevel: StuckLevel, var stuckValue: Int @@ -1244,6 +1242,12 @@ object HighwayTools : Module() { } } + private fun shuffleTasks() { + val shuffled = pendingTasks.shuffled() + pendingTasks.clear() + pendingTasks.addAll(shuffled) + } + data class BlockTask( val blockPos: BlockPos, var taskState: TaskState, From 7fe8f2ecfeb2476cebb2a4dd847b81c01e843c8f Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Fri, 1 Jan 2021 23:11:47 -0500 Subject: [PATCH 167/390] Cleaned up comparator --- .../kami/module/modules/misc/HighwayTools.kt | 60 +++++++++---------- 1 file changed, 28 insertions(+), 32 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 1373e679d5..0e1cf7bea6 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -112,7 +112,7 @@ object HighwayTools : Module() { private var baritoneSettingRenderGoal = false // runtime vars - val pendingTasks = PriorityQueue(BlockTaskComparator) + val pendingTasks = PriorityQueue() private val doneTasks = ArrayList() private val blueprint = ArrayList>() private var waitTicks = 0 @@ -306,11 +306,11 @@ object HighwayTools : Module() { } } - private fun addTask(blockPos: BlockPos, taskState: TaskState, material: Block) { + private fun addTaskToPending(blockPos: BlockPos, taskState: TaskState, material: Block) { pendingTasks.add(BlockTask(blockPos, taskState, material)) } - private fun addTask(blockPos: BlockPos, material: Block) { + private fun addTaskToDone(blockPos: BlockPos, material: Block) { doneTasks.add(BlockTask(blockPos, TaskState.DONE, material)) } @@ -539,25 +539,25 @@ object HighwayTools : Module() { var filler = fillerMat if (isInsideBuild(blockPos) || fillerMatLeft == 0) filler = material when (mc.world.getBlockState(blockPos).getValue(BlockLiquid.LEVEL) != 0) { - true -> addTask(blockPos, TaskState.LIQUID_FLOW, filler) - false -> addTask(blockPos, TaskState.LIQUID_SOURCE, filler) + true -> addTaskToPending(blockPos, TaskState.LIQUID_FLOW, filler) + false -> addTaskToPending(blockPos, TaskState.LIQUID_SOURCE, filler) } } else -> { when (blockType) { Blocks.AIR -> { when { - block in ignoreBlocks -> addTask(blockPos, Blocks.AIR) - block == Blocks.AIR -> addTask(blockPos, Blocks.AIR) - block == Blocks.FIRE -> addTask(blockPos, TaskState.BREAK, Blocks.FIRE) - block != Blocks.AIR -> addTask(blockPos, TaskState.BREAK, Blocks.AIR) + block in ignoreBlocks -> addTaskToDone(blockPos, Blocks.AIR) + block == Blocks.AIR -> addTaskToDone(blockPos, Blocks.AIR) + block == Blocks.FIRE -> addTaskToPending(blockPos, TaskState.BREAK, Blocks.FIRE) + block != Blocks.AIR -> addTaskToPending(blockPos, TaskState.BREAK, Blocks.AIR) } } material -> { when { - block == material -> addTask(blockPos, material) - !isReplaceable && block != material -> addTask(blockPos, TaskState.BREAK, material) - isReplaceable -> addTask(blockPos, TaskState.PLACE, material) + block == material -> addTaskToDone(blockPos, material) + !isReplaceable && block != material -> addTaskToPending(blockPos, TaskState.BREAK, material) + isReplaceable -> addTaskToPending(blockPos, TaskState.PLACE, material) } } fillerMat -> { @@ -565,15 +565,15 @@ object HighwayTools : Module() { if (buildDirectionSaved.isDiagonal) { val blockUp = mc.world.getBlockState(blockPos.up()).block when { - WorldUtils.getNeighbour(blockPos.up(), 1) == null && blockUp != material -> addTask(blockPos, TaskState.PLACE, fillerMat) - WorldUtils.getNeighbour(blockPos.up(), 1) != null -> addTask(blockPos, fillerMat) + WorldUtils.getNeighbour(blockPos.up(), 1) == null && blockUp != material -> addTaskToPending(blockPos, TaskState.PLACE, fillerMat) + WorldUtils.getNeighbour(blockPos.up(), 1) != null -> addTaskToDone(blockPos, fillerMat) } } } else { when { - block == fillerMat -> addTask(blockPos, fillerMat) - !isReplaceable && block != fillerMat -> addTask(blockPos, TaskState.BREAK, fillerMat) - isReplaceable -> addTask(blockPos, TaskState.PLACE, fillerMat) + block == fillerMat -> addTaskToDone(blockPos, fillerMat) + !isReplaceable && block != fillerMat -> addTaskToPending(blockPos, TaskState.BREAK, fillerMat) + isReplaceable -> addTaskToPending(blockPos, TaskState.PLACE, fillerMat) } } } @@ -736,8 +736,8 @@ object HighwayTools : Module() { } if (found.isEmpty()) { when (flowing) { - false -> addTask(neighbour, TaskState.LIQUID_SOURCE, filler) - true -> addTask(neighbour, TaskState.LIQUID_FLOW, filler) + false -> addTaskToPending(neighbour, TaskState.LIQUID_SOURCE, filler) + true -> addTaskToPending(neighbour, TaskState.LIQUID_FLOW, filler) } } else { for (x in found) { @@ -902,7 +902,7 @@ object HighwayTools : Module() { rayTrace = rt } } - addTask(rayTrace.blockPos, TaskState.EMERGENCY_BREAK, Blocks.AIR) + addTaskToPending(rayTrace.blockPos, TaskState.EMERGENCY_BREAK, Blocks.AIR) return false } return if (illegalPlacements.value) { @@ -1248,11 +1248,17 @@ object HighwayTools : Module() { pendingTasks.addAll(shuffled) } - data class BlockTask( + class BlockTask( val blockPos: BlockPos, var taskState: TaskState, var block: Block - ) { + ) : Comparable { + override fun compareTo(other: BlockTask) = when { + taskState.ordinal != other.taskState.ordinal -> taskState.ordinal - other.taskState.ordinal + taskState.ordinal == other.taskState.ordinal && stuckManager.stuckLevel != StuckLevel.NONE -> 0 + else -> (mc.player.distanceTo(blockPos) - mc.player.distanceTo(other.blockPos)).toInt() + } + override fun toString(): String { return "Block: " + block.localizedName + " @ Position: (" + blockPos.asString() + ") Priority: " + taskState.ordinal + " State: " + taskState.toString() } @@ -1270,16 +1276,6 @@ object HighwayTools : Module() { PLACED(ColorHolder(53, 222, 66)) } - class BlockTaskComparator { - companion object : Comparator { - override fun compare(a: BlockTask, b: BlockTask): Int = when { - a.taskState.ordinal != b.taskState.ordinal -> a.taskState.ordinal - b.taskState.ordinal - a.taskState.ordinal == b.taskState.ordinal && stuckManager.stuckLevel != StuckLevel.NONE -> a.taskState.ordinal - b.taskState.ordinal - else -> (mc.player.distanceTo(a.blockPos) - mc.player.distanceTo(b.blockPos)).toInt() - } - } - } - private enum class DebugMessages { OFF, IMPORTANT, From 38b3bb001c3dd1fc6264c896441a2700f2290c80 Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Fri, 1 Jan 2021 23:17:01 -0500 Subject: [PATCH 168/390] Cleaned up StuckManager class --- .../kami/module/modules/misc/HighwayTools.kt | 29 +++++++++---------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 0e1cf7bea6..bc7ac564b6 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -120,7 +120,6 @@ object HighwayTools : Module() { var pathing = false private var currentBlockPos = BlockPos(0, -1, 0) private var startingBlockPos = BlockPos(0, -1, 0) - private val stuckManager = StuckManagement(StuckLevel.NONE, 0) private val renderer = ESPRenderer() private var active = false private var lastHitVec: Vec3d? = null @@ -343,26 +342,26 @@ object HighwayTools : Module() { when (blockTask.taskState) { TaskState.DONE -> doDone(blockTask) TaskState.BREAKING -> if (!doBreaking(blockTask)) { - stuckManager.increase(blockTask) + StuckManager.increase(blockTask) return } TaskState.BROKEN -> doBroken(blockTask) TaskState.PLACED -> doPlaced(blockTask) TaskState.EMERGENCY_BREAK -> if (!doBreak(blockTask)) { - stuckManager.increase(blockTask) + StuckManager.increase(blockTask) return } TaskState.BREAK -> if (!doBreak(blockTask)) { - stuckManager.increase(blockTask) + StuckManager.increase(blockTask) return } TaskState.PLACE, TaskState.LIQUID_SOURCE, TaskState.LIQUID_FLOW -> if (!doPlace(blockTask)) { - stuckManager.increase(blockTask) + StuckManager.increase(blockTask) return } } - if (blockTask.taskState != TaskState.BREAKING) stuckManager.reset() + if (blockTask.taskState != TaskState.BREAKING) StuckManager.reset() } else { waitTicks-- } @@ -789,9 +788,9 @@ object HighwayTools : Module() { } if (directHits.size == 0) { - stuckManager.increase(blockTask) + StuckManager.increase(blockTask) refreshData() - if (stuckManager.stuckLevel == StuckLevel.NONE) doTask() + if (StuckManager.stuckLevel == StuckLevel.NONE) doTask() return } @@ -892,7 +891,7 @@ object HighwayTools : Module() { } } if (directHits.size == 0) { - if (emergencyHits.size > 0 && stuckManager.stuckLevel.ordinal > 0 && (blockTask.taskState == TaskState.LIQUID_SOURCE || blockTask.taskState == TaskState.LIQUID_FLOW)) { + if (emergencyHits.size > 0 && StuckManager.stuckLevel.ordinal > 0 && (blockTask.taskState == TaskState.LIQUID_SOURCE || blockTask.taskState == TaskState.LIQUID_FLOW)) { var rayTrace = emergencyHits[0] var shortestRT = 99.0 for (rt in emergencyHits) { @@ -1067,7 +1066,7 @@ object HighwayTools : Module() { " §7Target state: §9${currentTask?.block?.localizedName}", " §7Position: §9(${currentTask?.blockPos?.asString()})", "§rDebug", - " §7Stuck manager: §9${stuckManager}", + " §7Stuck manager: §9${StuckManager}", " §7Pathing: §9$pathing", "§rEstimations", " §7${material.localizedName} (main material): §9$materialLeft + ($indirectMaterialLeft)", @@ -1182,10 +1181,10 @@ object HighwayTools : Module() { shuffleTasks() } - data class StuckManagement( - var stuckLevel: StuckLevel, - var stuckValue: Int - ) { + object StuckManager { + var stuckLevel = StuckLevel.NONE + var stuckValue = 0 + fun increase(blockTask: BlockTask) { when (blockTask.taskState) { @@ -1255,7 +1254,7 @@ object HighwayTools : Module() { ) : Comparable { override fun compareTo(other: BlockTask) = when { taskState.ordinal != other.taskState.ordinal -> taskState.ordinal - other.taskState.ordinal - taskState.ordinal == other.taskState.ordinal && stuckManager.stuckLevel != StuckLevel.NONE -> 0 + taskState.ordinal == other.taskState.ordinal && StuckManager.stuckLevel != StuckLevel.NONE -> 0 else -> (mc.player.distanceTo(blockPos) - mc.player.distanceTo(other.blockPos)).toInt() } From 9d44208b37fca1fca67ef86bfc0c4f36e1e083d0 Mon Sep 17 00:00:00 2001 From: Christian Date: Sat, 2 Jan 2021 05:20:48 +0100 Subject: [PATCH 169/390] PacketLogger fix and instant mine fix --- .../zeroeightsix/kami/module/modules/misc/HighwayTools.kt | 5 +++++ .../kami/module/modules/player/PacketLogger.kt | 7 ++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index a41a888b18..fa64bcd571 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -775,6 +775,11 @@ object HighwayTools : Module() { connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, blockTask.blockPos, facing)) player.swingArm(EnumHand.MAIN_HAND) } + delay(45L) + onMainThreadSafe { + connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, blockTask.blockPos, facing)) + player.swingArm(EnumHand.MAIN_HAND) + } } } else -> dispatchGenericMineThread(blockTask, facing) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/player/PacketLogger.kt b/src/main/java/me/zeroeightsix/kami/module/modules/player/PacketLogger.kt index 2892ddf101..d5b027eba2 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/player/PacketLogger.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/player/PacketLogger.kt @@ -3,6 +3,8 @@ package me.zeroeightsix.kami.module.modules.player import me.zeroeightsix.kami.KamiMod import me.zeroeightsix.kami.event.events.PacketEvent import me.zeroeightsix.kami.event.events.SafeTickEvent +import me.zeroeightsix.kami.mixin.extension.pitch +import me.zeroeightsix.kami.mixin.extension.yaw import me.zeroeightsix.kami.module.Module import me.zeroeightsix.kami.setting.Setting import me.zeroeightsix.kami.setting.Settings @@ -49,9 +51,8 @@ object PacketLogger : Module() { is CPacketPlayerDigging -> { lines.add("\nMining - ${it.packet.position}@${it.packet.facing} - ${it.packet.action}") } - is CPacketPlayer.Rotation -> { - val vec = Vec3d(it.packet.getX(0.0), it.packet.getY(0.0), it.packet.getZ(0.0)) - lines.add("\nRotation - Pitch: ${it.packet.getPitch(0.0F)} Yaw: ${it.packet.getYaw(0.0F)}") + is CPacketPlayer -> { + lines.add("\nRotation - Pitch: ${it.packet.pitch} Yaw: ${it.packet.yaw}") } } lines.add("\n\n") From 538e11ec22316ffa1b77df31bbedc6ce88b8323a Mon Sep 17 00:00:00 2001 From: natan515 <2222natan@gmail.com> Date: Sat, 2 Jan 2021 09:14:37 +0200 Subject: [PATCH 170/390] They fixed gui in singelplayer so there is no reason for the change i did a week ago --- .../me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index fa64bcd571..8a9b6c163c 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -1279,7 +1279,7 @@ object HighwayTools : Module() { stuckLevel = StuckLevel.MODERATE if (!pathing && blockTask.taskState == TaskState.PLACE && !buildDirectionSaved.isDiagonal) adjustPlayerPosition(true) refreshData() - if (debugMessages.value != DebugMessages.OFF && (mc.currentScreen !is DisplayGuiScreen || mc.currentServerData != null)) sendChatMessage("$chatName Refreshing data") + if (debugMessages.value != DebugMessages.OFF ) sendChatMessage("$chatName Refreshing data") } stuckValue > 500 -> { stuckLevel = StuckLevel.MAYOR From 75ef90fa0913b170e1f24971272ec1a231d11a39 Mon Sep 17 00:00:00 2001 From: theredstoner Date: Sat, 2 Jan 2021 01:20:22 -0700 Subject: [PATCH 171/390] [AutoObsidian] Don't use silk touch pickaxes Also re-adds a missing disable() --- .../kami/module/modules/misc/AutoObsidian.kt | 38 +++++++++++++++++-- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt index 0fd048c7a7..5430fb28e7 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt @@ -28,7 +28,9 @@ import net.minecraft.block.BlockShulkerBox import net.minecraft.block.state.IBlockState import net.minecraft.client.audio.PositionedSoundRecord import net.minecraft.client.gui.inventory.GuiShulkerBox +import net.minecraft.enchantment.EnchantmentHelper import net.minecraft.init.Blocks +import net.minecraft.init.Enchantments import net.minecraft.init.Items import net.minecraft.init.SoundEvents import net.minecraft.inventory.ClickType @@ -473,13 +475,41 @@ object AutoObsidian : Module() { } } + /** + * @return True if there is a non-sliktouch pick in the hotbar, else returns false + */ + private fun hotbarHasNonSilkTouchPick(): Boolean { + if (InventoryUtils.getSlotsHotbar(ItemID.DIAMOND_PICKAXE.id) == null) return false + for (pos in InventoryUtils.getSlotsHotbar(ItemID.DIAMOND_PICKAXE.id)!!) { + if (EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, mc.player.inventory.getStackInSlot(pos)) == 0) { + return true + } + } + return false + } + + /** + * Gets the first non-hotbar slot of a diamond pickaxe that does not have the silk touch enchantment. + * @return The position of the pickaxe. -1 if there is no match. + */ + private fun getNonSilkTouchPickPos(): Int { + if (InventoryUtils.getSlotsNoHotbar(ItemID.DIAMOND_PICKAXE.id) == null) return -1 + for (pos in InventoryUtils.getSlotsNoHotbar(ItemID.DIAMOND_PICKAXE.id)!!) { + if (EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, mc.player.inventory.getStackInSlot(pos)) == 0) { + return pos + } + } + return -1 + } + private fun mineBlock(pos: BlockPos, pre: Boolean) { if (pre) { - if (InventoryUtils.getSlotsHotbar(ItemID.DIAMOND_PICKAXE.id) == null && InventoryUtils.getSlotsNoHotbar(ItemID.DIAMOND_PICKAXE.id) != null) { - InventoryUtils.moveToHotbar(ItemID.DIAMOND_PICKAXE.id, ItemID.ENDER_CHEST.id) - } else if (InventoryUtils.getSlots(0, 35, ItemID.DIAMOND_PICKAXE.id) == null) { - sendChatMessage("No pickaxe was found in inventory.") + if (!hotbarHasNonSilkTouchPick() && getNonSilkTouchPickPos() != -1) { + InventoryUtils.moveToSlot(0, getNonSilkTouchPickPos(), 36) + } else if (!hotbarHasNonSilkTouchPick()) { + sendChatMessage("No valid pickaxe was found in inventory.") mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) + disable() } InventoryUtils.swapSlotToItem(ItemID.DIAMOND_PICKAXE.id) } From 8b88fa47653202344fbbc7ce72a2cc38f0ea7681 Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Sat, 2 Jan 2021 13:31:48 -0500 Subject: [PATCH 172/390] Replaced toVec3d() with toVec3dCenter() --- .../me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt | 4 ++-- .../me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt index 0fd048c7a7..3b70ec6227 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt @@ -20,7 +20,7 @@ import me.zeroeightsix.kami.util.color.ColorHolder import me.zeroeightsix.kami.util.graphics.ESPRenderer import me.zeroeightsix.kami.util.math.RotationUtils.getRotationTo import me.zeroeightsix.kami.util.math.VectorUtils -import me.zeroeightsix.kami.util.math.VectorUtils.toVec3d +import me.zeroeightsix.kami.util.math.VectorUtils.toVec3dCenter import me.zeroeightsix.kami.util.text.MessageSendHelper.sendChatMessage import me.zeroeightsix.kami.util.threads.defaultScope import me.zeroeightsix.kami.util.threads.onMainThreadSafe @@ -231,7 +231,7 @@ object AutoObsidian : Module() { && (blockState.block.let { it == Blocks.ENDER_CHEST || it is BlockShulkerBox } || WorldUtils.isPlaceable(pos)) && mc.world.isAirBlock(pos.up()) - && mc.world.rayTraceBlocks(eyePos, pos.toVec3d())?.let { it.typeOfHit == RayTraceResult.Type.MISS } ?: true + && mc.world.rayTraceBlocks(eyePos, pos.toVec3dCenter())?.let { it.typeOfHit == RayTraceResult.Type.MISS } ?: true private fun updateMainState() { val passCountCheck = checkObbyCount() diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index bc7ac564b6..d3da7ff5e7 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -25,6 +25,7 @@ import me.zeroeightsix.kami.util.math.VectorUtils.getBlockPositionsInArea import me.zeroeightsix.kami.util.math.VectorUtils.multiply import me.zeroeightsix.kami.util.math.VectorUtils.toBlockPos import me.zeroeightsix.kami.util.math.VectorUtils.toVec3d +import me.zeroeightsix.kami.util.math.VectorUtils.toVec3dCenter import me.zeroeightsix.kami.util.text.MessageSendHelper.sendChatMessage import me.zeroeightsix.kami.util.threads.defaultScope import me.zeroeightsix.kami.util.threads.onMainThreadSafe @@ -881,7 +882,7 @@ object HighwayTools : Module() { val offPos = blockTask.blockPos.offset(side) if (mc.world.getBlockState(offPos).material.isReplaceable) continue if (eyePos.distanceTo(Vec3d(offPos).add(WorldUtils.getHitVecOffset(side))) > maxReach.value) continue - val rotationVector = offPos.toVec3d().add(Vec3d(side.opposite.directionVec).scale(0.499)) + val rotationVector = offPos.toVec3dCenter().add(side.opposite.directionVec.toVec3d().scale(0.499)) val rt = mc.world.rayTraceBlocks(eyePos, rotationVector, false) ?: continue if (rt.typeOfHit != RayTraceResult.Type.BLOCK) continue if (rt.blockPos == offPos && offPos.offset(rt.sideHit) == blockTask.blockPos) { @@ -947,7 +948,7 @@ object HighwayTools : Module() { } private fun adjustPlayerPosition(bridge: Boolean) { - var vec = getNextWalkableBlock().toVec3d().subtract(mc.player.positionVector) + var vec = getNextWalkableBlock().toVec3dCenter().subtract(mc.player.positionVector) when { bridge && !buildDirectionSaved.isDiagonal -> vec = vec.add(Vec3d(buildDirectionSaved.directionVec).scale(0.525)) bridge && buildDirectionSaved.isDiagonal -> vec = vec.add(Vec3d(buildDirectionSaved.directionVec).scale(0.525)) From 42ebe2fbc55efc21ca941df9e9f33942406d50ba Mon Sep 17 00:00:00 2001 From: theredstoner Date: Sat, 2 Jan 2021 11:37:39 -0700 Subject: [PATCH 173/390] Use up all e-chests before searching shulker Before, we would re-open the shulker if we picked up a stack less than 64. Now, use up all the e-chests in our inventory before opening a shulker. This fixes a case where AutoObsidian disables due to a shulker being empty, yet there are still e-chests in our inventory. --- .../me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt index 0fd048c7a7..8c506dc9aa 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt @@ -319,7 +319,7 @@ object AutoObsidian : Module() { SearchingState.PLACING } } - searchingState == SearchingState.OPENING && (InventoryUtils.countItemAll(ItemID.ENDER_CHEST.id) >= 64 + searchingState == SearchingState.OPENING && (InventoryUtils.countItemAll(ItemID.ENDER_CHEST.id) > 0 || InventoryUtils.getSlots(0, 35, 0) == null) -> { SearchingState.PRE_MINING } From 7f75709d46fbc3098f71d8ab634bde7afa095502 Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Sat, 2 Jan 2021 13:44:53 -0500 Subject: [PATCH 174/390] Cleaned up placing ray trace code --- .../kami/module/modules/misc/AutoObsidian.kt | 2 - .../kami/module/modules/misc/HighwayTools.kt | 99 ++++++------------- 2 files changed, 32 insertions(+), 69 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt index 3b70ec6227..51c23ee43d 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt @@ -10,7 +10,6 @@ import me.zeroeightsix.kami.event.events.RenderWorldEvent import me.zeroeightsix.kami.event.events.SafeTickEvent import me.zeroeightsix.kami.manager.managers.PlayerPacketManager import me.zeroeightsix.kami.module.Module -import me.zeroeightsix.kami.module.modules.player.NoBreakAnimation import me.zeroeightsix.kami.process.AutoObsidianProcess import me.zeroeightsix.kami.setting.Settings import me.zeroeightsix.kami.util.* @@ -463,7 +462,6 @@ object AutoObsidian : Module() { delay(10L) onMainThreadSafe { placeBlock(pair.second, pair.first) - if (NoBreakAnimation.isEnabled) NoBreakAnimation.resetMining() } delay(10L) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index d3da7ff5e7..2043f7c2be 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -10,7 +10,6 @@ import me.zeroeightsix.kami.manager.managers.PlayerPacketManager import me.zeroeightsix.kami.module.Module import me.zeroeightsix.kami.module.modules.player.AutoEat import me.zeroeightsix.kami.module.modules.player.InventoryManager -import me.zeroeightsix.kami.module.modules.player.NoBreakAnimation import me.zeroeightsix.kami.process.HighwayToolsProcess import me.zeroeightsix.kami.setting.Settings import me.zeroeightsix.kami.util.* @@ -24,7 +23,6 @@ import me.zeroeightsix.kami.util.math.VectorUtils.distanceTo import me.zeroeightsix.kami.util.math.VectorUtils.getBlockPositionsInArea import me.zeroeightsix.kami.util.math.VectorUtils.multiply import me.zeroeightsix.kami.util.math.VectorUtils.toBlockPos -import me.zeroeightsix.kami.util.math.VectorUtils.toVec3d import me.zeroeightsix.kami.util.math.VectorUtils.toVec3dCenter import me.zeroeightsix.kami.util.text.MessageSendHelper.sendChatMessage import me.zeroeightsix.kami.util.threads.defaultScope @@ -36,6 +34,7 @@ import net.minecraft.block.BlockLiquid import net.minecraft.client.audio.PositionedSoundRecord import net.minecraft.init.Blocks import net.minecraft.init.SoundEvents +import net.minecraft.network.play.client.CPacketEntityAction import net.minecraft.network.play.client.CPacketPlayerDigging import net.minecraft.util.EnumFacing import net.minecraft.util.EnumHand @@ -855,88 +854,54 @@ object HighwayTools : Module() { } } - // Only temporary till we found solution to avoid untraceable blocks - private fun placeBlockWall(blockTask: BlockTask): Boolean { - val pair = WorldUtils.getNeighbour(blockTask.blockPos, 1) ?: return false - val hitVec = WorldUtils.getHitVec(pair.second, pair.first) + private fun placeBlock(blockTask: BlockTask): Boolean { + if (!isVisible(blockTask.blockPos)) { + if (illegalPlacements.value) { + if (debugMessages.value == DebugMessages.ALL) { + sendChatMessage("Trying to place through wall ${blockTask.blockPos}") + } + } else { + return false + } + } - lastHitVec = hitVec + val pair = WorldUtils.getNeighbour(blockTask.blockPos, 1, 6.5f) + ?: run { + sendChatMessage("Can't find neighbour block") + return false + } + + lastHitVec = WorldUtils.getHitVec(pair.second, pair.first) rotateTimer.reset() + mc.connection?.sendPacket(CPacketEntityAction(mc.player, CPacketEntityAction.Action.START_SNEAKING)) + defaultScope.launch { delay(10L) onMainThreadSafe { placeBlock(pair.second, pair.first) - if (NoBreakAnimation.isEnabled) NoBreakAnimation.resetMining() + } + + delay(10L) + onMainThreadSafe { + connection.sendPacket(CPacketEntityAction(Companion.mc.player, CPacketEntityAction.Action.STOP_SNEAKING)) } } return true } - private fun placeBlock(blockTask: BlockTask): Boolean { - val directHits = mutableListOf() - val emergencyHits = mutableListOf() + private fun isVisible(pos: BlockPos): Boolean { val eyePos = mc.player.getPositionEyes(1f) for (side in EnumFacing.values()) { - val offPos = blockTask.blockPos.offset(side) - if (mc.world.getBlockState(offPos).material.isReplaceable) continue - if (eyePos.distanceTo(Vec3d(offPos).add(WorldUtils.getHitVecOffset(side))) > maxReach.value) continue - val rotationVector = offPos.toVec3dCenter().add(side.opposite.directionVec.toVec3d().scale(0.499)) - val rt = mc.world.rayTraceBlocks(eyePos, rotationVector, false) ?: continue - if (rt.typeOfHit != RayTraceResult.Type.BLOCK) continue - if (rt.blockPos == offPos && offPos.offset(rt.sideHit) == blockTask.blockPos) { - directHits.add(rt) - } else { - emergencyHits.add(rt) - } - } - if (directHits.size == 0) { - if (emergencyHits.size > 0 && StuckManager.stuckLevel.ordinal > 0 && (blockTask.taskState == TaskState.LIQUID_SOURCE || blockTask.taskState == TaskState.LIQUID_FLOW)) { - var rayTrace = emergencyHits[0] - var shortestRT = 99.0 - for (rt in emergencyHits) { - val dist = eyePos.distanceTo(WorldUtils.getHitVec(rt.blockPos, rt.sideHit)) - if (dist < shortestRT) { - shortestRT = dist - rayTrace = rt - } - } - addTaskToPending(rayTrace.blockPos, TaskState.EMERGENCY_BREAK, Blocks.AIR) - return false - } - return if (illegalPlacements.value) { - if (debugMessages.value == DebugMessages.ALL) sendChatMessage("Trying to place through wall ${blockTask.blockPos}") - placeBlockWall(blockTask) - } else { - false - } + val blockState = mc.world.getBlockState(pos.offset(side)) + if (blockState.isFullBlock) continue + val rayTraceResult = mc.world.rayTraceBlocks(eyePos, WorldUtils.getHitVec(pos, side), false, true, false) ?: continue + if (rayTraceResult.typeOfHit == RayTraceResult.Type.BLOCK && rayTraceResult.hitVec.distanceTo(pos) > 1.0) continue + return true } - var rayTrace: RayTraceResult? = null - var shortestRT = 99.0 - for (rt in directHits) { - val dist = eyePos.distanceTo(WorldUtils.getHitVec(rt.blockPos, rt.sideHit)) - if (dist < shortestRT) { - shortestRT = dist - rayTrace = rt - } - } - if (rayTrace == null) { - sendChatMessage("Can't find any vector?") - return false - } - - lastHitVec = rayTrace.hitVec - rotateTimer.reset() - - defaultScope.launch { - delay(10L) - onMainThreadSafe { - placeBlock(rayTrace.blockPos, rayTrace.sideHit) - } - } - return true + return false } private fun isInsideSelection(blockPos: BlockPos): Boolean { From 09cb5e41c65925e7e155bb35d4dbf4807f3a781a Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Sat, 2 Jan 2021 13:47:17 -0500 Subject: [PATCH 175/390] Use flooredPosition instead --- .../kami/module/modules/misc/HighwayTools.kt | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 2043f7c2be..af498e53e5 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -13,6 +13,7 @@ import me.zeroeightsix.kami.module.modules.player.InventoryManager import me.zeroeightsix.kami.process.HighwayToolsProcess import me.zeroeightsix.kami.setting.Settings import me.zeroeightsix.kami.util.* +import me.zeroeightsix.kami.util.EntityUtils.flooredPosition import me.zeroeightsix.kami.util.WorldUtils.placeBlock import me.zeroeightsix.kami.util.color.ColorHolder import me.zeroeightsix.kami.util.graphics.ESPRenderer @@ -22,7 +23,6 @@ import me.zeroeightsix.kami.util.math.RotationUtils import me.zeroeightsix.kami.util.math.VectorUtils.distanceTo import me.zeroeightsix.kami.util.math.VectorUtils.getBlockPositionsInArea import me.zeroeightsix.kami.util.math.VectorUtils.multiply -import me.zeroeightsix.kami.util.math.VectorUtils.toBlockPos import me.zeroeightsix.kami.util.math.VectorUtils.toVec3dCenter import me.zeroeightsix.kami.util.text.MessageSendHelper.sendChatMessage import me.zeroeightsix.kami.util.threads.defaultScope @@ -157,7 +157,7 @@ object HighwayTools : Module() { } } - startingBlockPos = mc.player.positionVector.toBlockPos() + startingBlockPos = mc.player.flooredPosition currentBlockPos = startingBlockPos playerHotbarSlot = mc.player.inventory.currentItem lastHotbarSlot = -1 @@ -261,10 +261,10 @@ object HighwayTools : Module() { refreshData() } } else { - if (currentBlockPos == mc.player.positionVector.toBlockPos()) { + if (currentBlockPos == mc.player.flooredPosition) { doTask() } else { - currentBlockPos = mc.player.positionVector.toBlockPos() + currentBlockPos = mc.player.flooredPosition if (abs((buildDirectionSaved.ordinal - Direction.fromEntity(mc.player).ordinal) % 8) == 4) buildDirectionSaved = Direction.fromEntity(mc.player) refreshData() } @@ -532,7 +532,7 @@ object HighwayTools : Module() { updateBlockArray(getNextBlock(originPos)) for ((blockPos, blockType) in blueprint) { val isReplaceable = mc.world.getBlockState(blockPos).material.isReplaceable - if (blockPos == mc.player.positionVector.toBlockPos().down()) continue + if (blockPos == mc.player.flooredPosition.down()) continue when (val block = mc.world.getBlockState(blockPos).block) { is BlockLiquid -> { var filler = fillerMat @@ -750,7 +750,7 @@ object HighwayTools : Module() { } private fun mineBlock(blockTask: BlockTask) { - if (blockTask.blockPos == mc.player.positionVector.toBlockPos().down()) { + if (blockTask.blockPos == mc.player.flooredPosition.down()) { updateTask(blockTask, TaskState.DONE) return } @@ -896,7 +896,8 @@ object HighwayTools : Module() { for (side in EnumFacing.values()) { val blockState = mc.world.getBlockState(pos.offset(side)) if (blockState.isFullBlock) continue - val rayTraceResult = mc.world.rayTraceBlocks(eyePos, WorldUtils.getHitVec(pos, side), false, true, false) ?: continue + val rayTraceResult = mc.world.rayTraceBlocks(eyePos, WorldUtils.getHitVec(pos, side), false, true, false) + ?: continue if (rayTraceResult.typeOfHit == RayTraceResult.Type.BLOCK && rayTraceResult.hitVec.distanceTo(pos) > 1.0) continue return true } @@ -1150,7 +1151,7 @@ object HighwayTools : Module() { object StuckManager { var stuckLevel = StuckLevel.NONE var stuckValue = 0 - + fun increase(blockTask: BlockTask) { when (blockTask.taskState) { From 819d101593de018dde86f119d16e25e8bc2265ee Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Sat, 2 Jan 2021 14:18:49 -0500 Subject: [PATCH 176/390] CLeaned up ray trace code in breaking --- .../kami/module/modules/misc/HighwayTools.kt | 59 ++----------------- 1 file changed, 6 insertions(+), 53 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index af498e53e5..918751273f 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -38,7 +38,6 @@ import net.minecraft.network.play.client.CPacketEntityAction import net.minecraft.network.play.client.CPacketPlayerDigging 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.RayTraceResult import net.minecraft.util.math.Vec3d @@ -512,7 +511,6 @@ object HighwayTools : Module() { return true } - private fun checkTasks(): Boolean { for (blockTask in doneTasks) { val block = mc.world.getBlockState(blockTask.blockPos).block @@ -758,56 +756,22 @@ object HighwayTools : Module() { /* For fire, we just need to mine the top of the block below the fire */ /* TODO: This will not work if the top of the block which the fire is on is not visible */ if (blockTask.block == Blocks.FIRE) { - val blockBelowFire = BlockPos(blockTask.blockPos.x, blockTask.blockPos.y - 1, blockTask.blockPos.z) + val blockBelowFire = blockTask.blockPos.down() mc.playerController.clickBlock(blockBelowFire, EnumFacing.UP) mc.player.swingArm(EnumHand.MAIN_HAND) updateTask(blockTask, TaskState.BREAKING) return } - val directHits = mutableListOf() - val bb = mc.world.getBlockState(blockTask.blockPos).getSelectedBoundingBox(mc.world, blockTask.blockPos) - val playerEyeVec = mc.player.getPositionEyes(1f) - - for (side in EnumFacing.values()) { - loop@ for (direction in EnumFacing.values()) { - when (side) { - EnumFacing.UP -> if (direction == EnumFacing.DOWN || direction == EnumFacing.UP) continue@loop - EnumFacing.DOWN -> if (direction == EnumFacing.UP || direction == EnumFacing.DOWN) continue@loop - EnumFacing.NORTH -> if (direction == EnumFacing.SOUTH || direction == EnumFacing.NORTH) continue@loop - EnumFacing.EAST -> if (direction == EnumFacing.WEST || direction == EnumFacing.EAST) continue@loop - EnumFacing.SOUTH -> if (direction == EnumFacing.NORTH || direction == EnumFacing.SOUTH) continue@loop - EnumFacing.WEST -> if (direction == EnumFacing.EAST || direction == EnumFacing.WEST) continue@loop - } - val sideVec = bb.center.add(Vec3d(side.directionVec).scale(getAABBSide(bb, side) * 0.9).add(Vec3d(direction.directionVec)).scale(getAABBSide(bb, direction) - 0.001)) - if (playerEyeVec.distanceTo(sideVec) > maxReach.value) continue - if (mc.world.getBlockState(blockTask.blockPos.offset(side)).block != Blocks.AIR) continue - val rt = mc.world.rayTraceBlocks(playerEyeVec, sideVec, false) ?: continue - if (rt.blockPos == blockTask.blockPos && rt.sideHit == side) directHits.add(rt) - } - } - - if (directHits.size == 0) { + if (!isVisible(blockTask.blockPos)) { StuckManager.increase(blockTask) refreshData() if (StuckManager.stuckLevel == StuckLevel.NONE) doTask() return } - var rayTrace: RayTraceResult? = null - var shortestRT = 999.0 - for (rt in directHits) { - val distance = playerEyeVec.distanceTo(rt.hitVec) - if (distance < shortestRT) { - shortestRT = distance - rayTrace = rt - } - } - - if (rayTrace == null) return - - val facing = rayTrace.sideHit - lastHitVec = rayTrace.hitVec + val side = EnumFacing.getDirectionFromEntityLiving(blockTask.blockPos, mc.player) + lastHitVec = WorldUtils.getHitVec(blockTask.blockPos, side) rotateTimer.reset() when (mc.world.getBlockState(blockTask.blockPos).block) { @@ -817,23 +781,12 @@ object HighwayTools : Module() { defaultScope.launch { delay(5L) onMainThreadSafe { - connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, blockTask.blockPos, facing)) + connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, blockTask.blockPos, side)) player.swingArm(EnumHand.MAIN_HAND) } } } - else -> dispatchGenericMineThread(blockTask, facing) - } - } - - private fun getAABBSide(bb: AxisAlignedBB, side: EnumFacing): Double { - return when (side) { - EnumFacing.UP -> bb.maxY - bb.center.y - EnumFacing.NORTH -> bb.center.z - bb.minZ - EnumFacing.EAST -> bb.maxX - bb.center.x - EnumFacing.SOUTH -> bb.maxZ - bb.center.z - EnumFacing.WEST -> bb.center.x - bb.minX - EnumFacing.DOWN -> bb.center.y - bb.minY + else -> dispatchGenericMineThread(blockTask, side) } } From d506da58799dafc0efb9b397a209cb50b1f837ef Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Sat, 2 Jan 2021 14:29:45 -0500 Subject: [PATCH 177/390] Cleaned up liquid handling code --- .../kami/module/modules/misc/HighwayTools.kt | 77 +++++++++++-------- 1 file changed, 47 insertions(+), 30 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 918751273f..55eb52f742 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -45,7 +45,6 @@ import org.kamiblue.event.listener.listener import java.util.* import kotlin.collections.ArrayList import kotlin.math.abs -import kotlin.math.sqrt /** * @author Avanatiker @@ -339,24 +338,36 @@ object HighwayTools : Module() { val blockTask = pendingTasks.peek() when (blockTask.taskState) { - TaskState.DONE -> doDone(blockTask) - TaskState.BREAKING -> if (!doBreaking(blockTask)) { - StuckManager.increase(blockTask) - return + TaskState.DONE -> { + doDone(blockTask) } - TaskState.BROKEN -> doBroken(blockTask) - TaskState.PLACED -> doPlaced(blockTask) - TaskState.EMERGENCY_BREAK -> if (!doBreak(blockTask)) { - StuckManager.increase(blockTask) - return + TaskState.BREAKING -> { + if (!doBreaking(blockTask)) { + StuckManager.increase(blockTask) + return + } + } + TaskState.BROKEN -> { + doBroken(blockTask) + } + TaskState.PLACED -> { + doPlaced(blockTask) + } + TaskState.EMERGENCY_BREAK -> { + if (!doBreak(blockTask)) { + StuckManager.increase(blockTask) + return + } } TaskState.BREAK -> if (!doBreak(blockTask)) { StuckManager.increase(blockTask) return } - TaskState.PLACE, TaskState.LIQUID_SOURCE, TaskState.LIQUID_FLOW -> if (!doPlace(blockTask)) { - StuckManager.increase(blockTask) - return + TaskState.PLACE, TaskState.LIQUID_SOURCE, TaskState.LIQUID_FLOW -> { + if (!doPlace(blockTask)) { + StuckManager.increase(blockTask) + return + } } } @@ -466,7 +477,7 @@ object HighwayTools : Module() { else -> { // liquid search around the breaking block if (blockTask.taskState != TaskState.EMERGENCY_BREAK) { - if (liquidHandler(blockTask)) { + if (handleLiquid(blockTask)) { updateTask(blockTask, TaskState.EMERGENCY_BREAK) return true } @@ -482,8 +493,12 @@ object HighwayTools : Module() { val block = mc.world.getBlockState(blockTask.blockPos).block when { - block == material && block == blockTask.block -> updateTask(blockTask, TaskState.PLACED) - block == fillerMat && block == blockTask.block -> updateTask(blockTask, TaskState.PLACED) + block == material && block == blockTask.block -> { + updateTask(blockTask, TaskState.PLACED) + } + block == fillerMat && block == blockTask.block -> { + updateTask(blockTask, TaskState.PLACED) + } else -> { if (!WorldUtils.isPlaceable(blockTask.blockPos)) { // if (debugMessages.value != DebugMessages.OFF) sendChatMessage("Error: " + blockTask.blockPos + " is not a valid position to place a block, removing task.") @@ -707,39 +722,41 @@ object HighwayTools : Module() { return true } - private fun liquidHandler(blockTask: BlockTask): Boolean { + private fun handleLiquid(blockTask: BlockTask): Boolean { var foundLiquid = false for (side in EnumFacing.values()) { val neighbour = blockTask.blockPos.offset(side) val neighbourBlock = mc.world.getBlockState(neighbour).block + if (neighbourBlock is BlockLiquid) { - var flowing = false - try { - flowing = mc.world.getBlockState(blockTask.blockPos).getValue(BlockLiquid.LEVEL) != 0 - } catch (e: Exception) { + val isFlowing = mc.world.getBlockState(blockTask.blockPos).let { + it.block is BlockLiquid && it.getValue(BlockLiquid.LEVEL) != 0 } - if (sqrt(mc.player.getDistanceSqToCenter(neighbour)) > maxReach.value) continue + + if (mc.player.distanceTo(neighbour) > maxReach.value) continue + foundLiquid = true - val found = mutableListOf>() - var filler = fillerMat - if (isInsideBuild(neighbour)) filler = material + val found = ArrayList>() + val filler = if (isInsideBuild(neighbour)) material else fillerMat + for (bt in pendingTasks) { if (bt.blockPos == neighbour) { - when (flowing) { + when (isFlowing) { false -> found.add(Triple(bt, TaskState.LIQUID_SOURCE, filler)) true -> found.add(Triple(bt, TaskState.LIQUID_FLOW, filler)) } } } + if (found.isEmpty()) { - when (flowing) { + when (isFlowing) { false -> addTaskToPending(neighbour, TaskState.LIQUID_SOURCE, filler) true -> addTaskToPending(neighbour, TaskState.LIQUID_FLOW, filler) } } else { - for (x in found) { - updateTask(x.first, x.second) - updateTask(x.first, x.third) + for (triple in found) { + updateTask(triple.first, triple.second) + updateTask(triple.first, triple.third) } } } From 97ce605b638371a0c790170f07a1278036f7d6aa Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Sat, 2 Jan 2021 14:40:08 -0500 Subject: [PATCH 178/390] Fixed build error --- .../me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 55eb52f742..f7db54ff1e 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -91,7 +91,7 @@ object HighwayTools : Module() { private val aOutline = register(Settings.integerBuilder("OutlineAlpha").withValue(91).withRange(0, 255).withStep(1).withVisibility { outline.value && page.value == Page.CONFIG }) // internal settings - val ignoreBlocks = setOf( + val ignoreBlocks = hashSetOf( Blocks.STANDING_SIGN, Blocks.WALL_SIGN, Blocks.STANDING_BANNER, From 0746941acbd9393fb762ed9a8e53fc67ead8eb77 Mon Sep 17 00:00:00 2001 From: theredstoner Date: Sat, 2 Jan 2021 13:16:34 -0700 Subject: [PATCH 179/390] Add leaveEmptyShulker mode to AutoObsidian This mode will cause us not to baritone towards empty shulker boxes. This allows us to search multiple shulkers when searchShulker is on as the old shulkers will not be picked up intentionally (and if they are picked up they will be re-dropped) --- .../kami/module/modules/misc/AutoObsidian.kt | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt index 8c506dc9aa..1c0e015c63 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt @@ -53,6 +53,7 @@ import org.kamiblue.event.listener.listener object AutoObsidian : Module() { private val fillMode = register(Settings.e("FillMode", FillMode.TARGET_STACKS)) private val searchShulker = register(Settings.b("SearchShulker", false)) + private val leaveEmptyShulkers = register(Settings.booleanBuilder("LeaveEmptyShulkers").withValue(true).withVisibility { searchShulker.value == true }) private val autoRefill = register(Settings.booleanBuilder("AutoRefill").withValue(false).withVisibility { fillMode.value != FillMode.INFINITE }) private val threshold = register(Settings.integerBuilder("RefillThreshold").withValue(8).withRange(1, 56).withVisibility { autoRefill.value && fillMode.value != FillMode.INFINITE }) private val targetStacks = register(Settings.integerBuilder("TargetStacks").withValue(1).withRange(1, 20).withVisibility { fillMode.value == FillMode.TARGET_STACKS }) @@ -94,7 +95,8 @@ object AutoObsidian : Module() { private enum class ItemID(val id: Int) { OBSIDIAN(49), ENDER_CHEST(130), - DIAMOND_PICKAXE(278) + DIAMOND_PICKAXE(278), + AIR(0) } var goal: Goal? = null; private set @@ -424,9 +426,15 @@ object AutoObsidian : Module() { InventoryUtils.inventoryClick(container.windowId, slot, 0, ClickType.QUICK_MOVE) mc.player.closeScreen() } else if (shulkerOpenTimer.tick(100, false)) { // Wait for maximum of 5 seconds - sendChatMessage("$chatName No ender chest was found in shulker, disabling.") - mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) - disable() + if(leaveEmptyShulkers.value && container.inventory.subList(0, 27).indexOfFirst { it.item.id != ItemID.AIR.id } == -1) { + searchingState = SearchingState.PRE_MINING + mc.player.closeScreen() + } + else { + sendChatMessage("$chatName No ender chest was found in shulker, disabling.") + mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) + disable() + } } } else { val side = EnumFacing.getDirectionFromEntityLiving(pos, mc.player) From cbe3461c680e12b7806a64d47762d0f50e30ec37 Mon Sep 17 00:00:00 2001 From: theredstoner Date: Sat, 2 Jan 2021 13:26:10 -0700 Subject: [PATCH 180/390] Cleanup --- .../kami/module/modules/misc/AutoObsidian.kt | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt index 5430fb28e7..04fb890c9c 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt @@ -479,9 +479,9 @@ object AutoObsidian : Module() { * @return True if there is a non-sliktouch pick in the hotbar, else returns false */ private fun hotbarHasNonSilkTouchPick(): Boolean { - if (InventoryUtils.getSlotsHotbar(ItemID.DIAMOND_PICKAXE.id) == null) return false - for (pos in InventoryUtils.getSlotsHotbar(ItemID.DIAMOND_PICKAXE.id)!!) { - if (EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, mc.player.inventory.getStackInSlot(pos)) == 0) { + val slotsWithPickaxes = InventoryUtils.getSlotsHotbar(ItemID.DIAMOND_PICKAXE.id) ?: return false + for (slot in slotsWithPickaxes) { + if (EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, mc.player.inventory.getStackInSlot(slot)) == 0) { return true } } @@ -493,10 +493,10 @@ object AutoObsidian : Module() { * @return The position of the pickaxe. -1 if there is no match. */ private fun getNonSilkTouchPickPos(): Int { - if (InventoryUtils.getSlotsNoHotbar(ItemID.DIAMOND_PICKAXE.id) == null) return -1 - for (pos in InventoryUtils.getSlotsNoHotbar(ItemID.DIAMOND_PICKAXE.id)!!) { - if (EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, mc.player.inventory.getStackInSlot(pos)) == 0) { - return pos + val slotsWithPickaxes = InventoryUtils.getSlotsNoHotbar(ItemID.DIAMOND_PICKAXE.id) ?: return -1 + for (slot in slotsWithPickaxes) { + if (EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, mc.player.inventory.getStackInSlot(slot)) == 0) { + return slot } } return -1 From 8158c16a5cc4e9b2595c78b04e4cdc4d15a34e3f Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Sat, 2 Jan 2021 19:58:08 -0500 Subject: [PATCH 181/390] Run everything in SafeClientEvent --- src/main/commons | 2 +- .../kami/module/modules/misc/HighwayTools.kt | 158 +++++++++--------- 2 files changed, 84 insertions(+), 76 deletions(-) diff --git a/src/main/commons b/src/main/commons index 7e2929904f..fea63e2afc 160000 --- a/src/main/commons +++ b/src/main/commons @@ -1 +1 @@ -Subproject commit 7e2929904f0a126457a64d817f4a654473ae89be +Subproject commit fea63e2afccef89e229944d19051381a5150d782 diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index f7db54ff1e..1f82e569fe 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -3,11 +3,13 @@ package me.zeroeightsix.kami.module.modules.misc import kotlinx.coroutines.delay import kotlinx.coroutines.launch import me.zeroeightsix.kami.event.Phase +import me.zeroeightsix.kami.event.SafeClientEvent import me.zeroeightsix.kami.event.events.OnUpdateWalkingPlayerEvent import me.zeroeightsix.kami.event.events.RenderWorldEvent import me.zeroeightsix.kami.gui.kami.DisplayGuiScreen import me.zeroeightsix.kami.manager.managers.PlayerPacketManager import me.zeroeightsix.kami.module.Module +import me.zeroeightsix.kami.module.modules.misc.HighwayTools.StuckManager.increase import me.zeroeightsix.kami.module.modules.player.AutoEat import me.zeroeightsix.kami.module.modules.player.InventoryManager import me.zeroeightsix.kami.process.HighwayToolsProcess @@ -27,6 +29,7 @@ import me.zeroeightsix.kami.util.math.VectorUtils.toVec3dCenter import me.zeroeightsix.kami.util.text.MessageSendHelper.sendChatMessage import me.zeroeightsix.kami.util.threads.defaultScope import me.zeroeightsix.kami.util.threads.onMainThreadSafe +import me.zeroeightsix.kami.util.threads.runSafe import me.zeroeightsix.kami.util.threads.safeListener import net.minecraft.block.Block import net.minecraft.block.Block.getIdFromBlock @@ -41,7 +44,6 @@ import net.minecraft.util.EnumHand import net.minecraft.util.math.BlockPos import net.minecraft.util.math.RayTraceResult import net.minecraft.util.math.Vec3d -import org.kamiblue.event.listener.listener import java.util.* import kotlin.collections.ArrayList import kotlin.math.abs @@ -176,8 +178,10 @@ object HighwayTools : Module() { playerHotbarSlot = mc.player.inventory.currentItem - refreshData() - printEnable() + runSafe { + refreshData() + printEnable() + } } override fun onDisable() { @@ -215,8 +219,7 @@ object HighwayTools : Module() { fun isDone(): Boolean = pendingTasks.size == 0 init { - listener { - if (mc.player == null) return@listener + safeListener { renderer.render(false) } @@ -235,11 +238,11 @@ object HighwayTools : Module() { val taskPos = (pendingTasks.firstOrNull() ?: doneTasks.firstOrNull())?.blockPos ?: BlockPos(0, -1, 0) - if (mc.player.positionVector.distanceTo(taskPos) < maxReach.value) { + if (player.positionVector.distanceTo(taskPos) < maxReach.value) { if (!isDone()) { if (canDoTask()) { if (!pathing) adjustPlayerPosition(false) - val currentFood = mc.player.foodStats.foodLevel + val currentFood = player.foodStats.foodLevel if (currentFood != prevFood) { if (currentFood < prevFood) foodLoss++ prevFood = currentFood @@ -259,11 +262,11 @@ object HighwayTools : Module() { refreshData() } } else { - if (currentBlockPos == mc.player.flooredPosition) { + if (currentBlockPos == player.flooredPosition) { doTask() } else { - currentBlockPos = mc.player.flooredPosition - if (abs((buildDirectionSaved.ordinal - Direction.fromEntity(mc.player).ordinal) % 8) == 4) buildDirectionSaved = Direction.fromEntity(mc.player) + currentBlockPos = player.flooredPosition + if (abs((buildDirectionSaved.ordinal - Direction.fromEntity(player).ordinal) % 8) == 4) buildDirectionSaved = Direction.fromEntity(player) refreshData() } } @@ -277,8 +280,8 @@ object HighwayTools : Module() { PlayerPacketManager.addPacket(this@HighwayTools, packet) } InteractMode.VIEW_LOCK -> { - mc.player.rotationYaw = rotation.x - mc.player.rotationPitch = rotation.y + player.rotationYaw = rotation.x + player.rotationPitch = rotation.y } else -> { @@ -287,7 +290,7 @@ object HighwayTools : Module() { } } - private fun updateRenderer() { + private fun SafeClientEvent.updateRenderer() { renderer.clear() renderer.aFilled = if (filled.value) aFilled.value else 0 renderer.aOutline = if (outline.value) aOutline.value else 0 @@ -295,11 +298,11 @@ object HighwayTools : Module() { // renderer.add(getNextWalkableBlock(), ColorHolder(0, 0, 0)) for (blockTask in pendingTasks) { if (blockTask.taskState == TaskState.DONE) continue - renderer.add(mc.world.getBlockState(blockTask.blockPos).getSelectedBoundingBox(mc.world, blockTask.blockPos), blockTask.taskState.color) + renderer.add(world.getBlockState(blockTask.blockPos).getSelectedBoundingBox(world, blockTask.blockPos), blockTask.taskState.color) } for (blockTask in doneTasks) { if (blockTask.block == Blocks.AIR) continue - renderer.add(mc.world.getBlockState(blockTask.blockPos).getSelectedBoundingBox(mc.world, blockTask.blockPos), blockTask.taskState.color) + renderer.add(world.getBlockState(blockTask.blockPos).getSelectedBoundingBox(world, blockTask.blockPos), blockTask.taskState.color) } } @@ -332,7 +335,7 @@ object HighwayTools : Module() { return !BaritoneUtils.paused && !AutoObsidian.isActive() && !AutoEat.eating } - private fun doTask() { + private fun SafeClientEvent.doTask() { if (!isDone() && canDoTask()) { if (waitTicks == 0) { val blockTask = pendingTasks.peek() @@ -343,7 +346,7 @@ object HighwayTools : Module() { } TaskState.BREAKING -> { if (!doBreaking(blockTask)) { - StuckManager.increase(blockTask) + increase(blockTask) return } } @@ -355,17 +358,17 @@ object HighwayTools : Module() { } TaskState.EMERGENCY_BREAK -> { if (!doBreak(blockTask)) { - StuckManager.increase(blockTask) + increase(blockTask) return } } TaskState.BREAK -> if (!doBreak(blockTask)) { - StuckManager.increase(blockTask) + increase(blockTask) return } TaskState.PLACE, TaskState.LIQUID_SOURCE, TaskState.LIQUID_FLOW -> { if (!doPlace(blockTask)) { - StuckManager.increase(blockTask) + increase(blockTask) return } } @@ -378,14 +381,14 @@ object HighwayTools : Module() { } } - private fun doDone(blockTask: BlockTask) { + private fun SafeClientEvent.doDone(blockTask: BlockTask) { pendingTasks.poll() doneTasks.add(blockTask) doTask() } - private fun doBreaking(blockTask: BlockTask): Boolean { - when (mc.world.getBlockState(blockTask.blockPos).block) { + private fun SafeClientEvent.doBreaking(blockTask: BlockTask): Boolean { + when (world.getBlockState(blockTask.blockPos).block) { Blocks.AIR -> { totalBlocksDestroyed++ waitTicks = tickDelayBreak.value @@ -399,7 +402,7 @@ object HighwayTools : Module() { is BlockLiquid -> { var filler = fillerMat if (isInsideBuild(blockTask.blockPos) || fillerMatLeft == 0) filler = material - if (mc.world.getBlockState(blockTask.blockPos).getValue(BlockLiquid.LEVEL) != 0) { + if (world.getBlockState(blockTask.blockPos).getValue(BlockLiquid.LEVEL) != 0) { updateTask(blockTask, TaskState.LIQUID_FLOW) updateTask(blockTask, filler) } else { @@ -414,8 +417,8 @@ object HighwayTools : Module() { return true } - private fun doBroken(blockTask: BlockTask) { - when (mc.world.getBlockState(blockTask.blockPos).block) { + private fun SafeClientEvent.doBroken(blockTask: BlockTask) { + when (world.getBlockState(blockTask.blockPos).block) { Blocks.AIR -> { totalBlocksDestroyed++ if (blockTask.block == material || blockTask.block == fillerMat) { @@ -431,8 +434,8 @@ object HighwayTools : Module() { doTask() } - private fun doPlaced(blockTask: BlockTask) { - val block = mc.world.getBlockState(blockTask.blockPos).block + private fun SafeClientEvent.doPlaced(blockTask: BlockTask) { + val block = world.getBlockState(blockTask.blockPos).block when { blockTask.block == block && block != Blocks.AIR -> updateTask(blockTask, TaskState.DONE) @@ -443,7 +446,7 @@ object HighwayTools : Module() { doTask() } - private fun doBreak(blockTask: BlockTask): Boolean { + private fun SafeClientEvent.doBreak(blockTask: BlockTask): Boolean { // ignore blocks if (blockTask.taskState != TaskState.EMERGENCY_BREAK) { @@ -454,7 +457,7 @@ object HighwayTools : Module() { } // last check before breaking - when (mc.world.getBlockState(blockTask.blockPos).block) { + when (world.getBlockState(blockTask.blockPos).block) { Blocks.AIR -> { if (blockTask.block == Blocks.AIR) { updateTask(blockTask, TaskState.DONE) @@ -466,7 +469,7 @@ object HighwayTools : Module() { is BlockLiquid -> { var filler = fillerMat if (isInsideBuild(blockTask.blockPos) || fillerMatLeft == 0) filler = material - if (mc.world.getBlockState(blockTask.blockPos).getValue(BlockLiquid.LEVEL) != 0) { + if (world.getBlockState(blockTask.blockPos).getValue(BlockLiquid.LEVEL) != 0) { updateTask(blockTask, TaskState.LIQUID_FLOW) updateTask(blockTask, filler) } else { @@ -489,8 +492,8 @@ object HighwayTools : Module() { return true } - private fun doPlace(blockTask: BlockTask): Boolean { - val block = mc.world.getBlockState(blockTask.blockPos).block + private fun SafeClientEvent.doPlace(blockTask: BlockTask): Boolean { + val block = world.getBlockState(blockTask.blockPos).block when { block == material && block == blockTask.block -> { @@ -526,9 +529,9 @@ object HighwayTools : Module() { return true } - private fun checkTasks(): Boolean { + private fun SafeClientEvent.checkTasks(): Boolean { for (blockTask in doneTasks) { - val block = mc.world.getBlockState(blockTask.blockPos).block + val block = world.getBlockState(blockTask.blockPos).block if (ignoreBlocks.contains(block)) continue when { blockTask.block == material && block != material -> return false @@ -539,18 +542,18 @@ object HighwayTools : Module() { return true } - private fun updateTasks(originPos: BlockPos) { + private fun SafeClientEvent.updateTasks(originPos: BlockPos) { blueprint.clear() updateBlockArray(originPos) updateBlockArray(getNextBlock(originPos)) for ((blockPos, blockType) in blueprint) { - val isReplaceable = mc.world.getBlockState(blockPos).material.isReplaceable - if (blockPos == mc.player.flooredPosition.down()) continue - when (val block = mc.world.getBlockState(blockPos).block) { + val isReplaceable = world.getBlockState(blockPos).material.isReplaceable + if (blockPos == player.flooredPosition.down()) continue + when (val block = world.getBlockState(blockPos).block) { is BlockLiquid -> { var filler = fillerMat if (isInsideBuild(blockPos) || fillerMatLeft == 0) filler = material - when (mc.world.getBlockState(blockPos).getValue(BlockLiquid.LEVEL) != 0) { + when (world.getBlockState(blockPos).getValue(BlockLiquid.LEVEL) != 0) { true -> addTaskToPending(blockPos, TaskState.LIQUID_FLOW, filler) false -> addTaskToPending(blockPos, TaskState.LIQUID_SOURCE, filler) } @@ -575,7 +578,7 @@ object HighwayTools : Module() { fillerMat -> { if (mode.value == Mode.HIGHWAY) { if (buildDirectionSaved.isDiagonal) { - val blockUp = mc.world.getBlockState(blockPos.up()).block + val blockUp = world.getBlockState(blockPos.up()).block when { WorldUtils.getNeighbour(blockPos.up(), 1) == null && blockUp != material -> addTaskToPending(blockPos, TaskState.PLACE, fillerMat) WorldUtils.getNeighbour(blockPos.up(), 1) != null -> addTaskToDone(blockPos, fillerMat) @@ -677,10 +680,10 @@ object HighwayTools : Module() { } } - private fun inventoryProcessor(blockTask: BlockTask): Boolean { + private fun SafeClientEvent.inventoryProcessor(blockTask: BlockTask): Boolean { when (blockTask.taskState) { TaskState.BREAK, TaskState.EMERGENCY_BREAK -> { - AutoTool.equipBestTool(mc.world.getBlockState(blockTask.blockPos)) + AutoTool.equipBestTool(world.getBlockState(blockTask.blockPos)) // val noHotbar = InventoryUtils.getSlotsNoHotbar(278) // if (InventoryUtils.getSlotsHotbar(278) == null && noHotbar != null) { //// InventoryUtils.moveToHotbar(278, 130) @@ -722,18 +725,18 @@ object HighwayTools : Module() { return true } - private fun handleLiquid(blockTask: BlockTask): Boolean { + private fun SafeClientEvent.handleLiquid(blockTask: BlockTask): Boolean { var foundLiquid = false for (side in EnumFacing.values()) { val neighbour = blockTask.blockPos.offset(side) - val neighbourBlock = mc.world.getBlockState(neighbour).block + val neighbourBlock = world.getBlockState(neighbour).block if (neighbourBlock is BlockLiquid) { - val isFlowing = mc.world.getBlockState(blockTask.blockPos).let { + val isFlowing = world.getBlockState(blockTask.blockPos).let { it.block is BlockLiquid && it.getValue(BlockLiquid.LEVEL) != 0 } - if (mc.player.distanceTo(neighbour) > maxReach.value) continue + if (player.distanceTo(neighbour) > maxReach.value) continue foundLiquid = true val found = ArrayList>() @@ -764,8 +767,8 @@ object HighwayTools : Module() { return foundLiquid } - private fun mineBlock(blockTask: BlockTask) { - if (blockTask.blockPos == mc.player.flooredPosition.down()) { + private fun SafeClientEvent.mineBlock(blockTask: BlockTask) { + if (blockTask.blockPos == player.flooredPosition.down()) { updateTask(blockTask, TaskState.DONE) return } @@ -774,24 +777,24 @@ object HighwayTools : Module() { /* TODO: This will not work if the top of the block which the fire is on is not visible */ if (blockTask.block == Blocks.FIRE) { val blockBelowFire = blockTask.blockPos.down() - mc.playerController.clickBlock(blockBelowFire, EnumFacing.UP) - mc.player.swingArm(EnumHand.MAIN_HAND) + playerController.clickBlock(blockBelowFire, EnumFacing.UP) + player.swingArm(EnumHand.MAIN_HAND) updateTask(blockTask, TaskState.BREAKING) return } if (!isVisible(blockTask.blockPos)) { - StuckManager.increase(blockTask) + increase(blockTask) refreshData() if (StuckManager.stuckLevel == StuckLevel.NONE) doTask() return } - val side = EnumFacing.getDirectionFromEntityLiving(blockTask.blockPos, mc.player) + val side = EnumFacing.getDirectionFromEntityLiving(blockTask.blockPos, player) lastHitVec = WorldUtils.getHitVec(blockTask.blockPos, side) rotateTimer.reset() - when (mc.world.getBlockState(blockTask.blockPos).block) { + when (world.getBlockState(blockTask.blockPos).block) { Blocks.NETHERRACK -> { updateTask(blockTask, TaskState.BROKEN) waitTicks = tickDelayBreak.value @@ -801,6 +804,11 @@ object HighwayTools : Module() { connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, blockTask.blockPos, side)) player.swingArm(EnumHand.MAIN_HAND) } + delay(20L) + onMainThreadSafe { + connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, blockTask.blockPos, side)) + player.swingArm(EnumHand.MAIN_HAND) + } } } else -> dispatchGenericMineThread(blockTask, side) @@ -809,7 +817,7 @@ object HighwayTools : Module() { /* Dispatches a thread to mine any non-netherrack blocks generically */ private fun dispatchGenericMineThread(blockTask: BlockTask, facing: EnumFacing) { - val digPacket: CPacketPlayerDigging = when (blockTask.taskState) { + val digPacket = when (blockTask.taskState) { TaskState.BREAK, TaskState.EMERGENCY_BREAK -> CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, blockTask.blockPos, facing) TaskState.BREAKING -> CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, blockTask.blockPos, facing) else -> CPacketPlayerDigging() @@ -824,7 +832,7 @@ object HighwayTools : Module() { } } - private fun placeBlock(blockTask: BlockTask): Boolean { + private fun SafeClientEvent.placeBlock(blockTask: BlockTask): Boolean { if (!isVisible(blockTask.blockPos)) { if (illegalPlacements.value) { if (debugMessages.value == DebugMessages.ALL) { @@ -844,7 +852,7 @@ object HighwayTools : Module() { lastHitVec = WorldUtils.getHitVec(pair.second, pair.first) rotateTimer.reset() - mc.connection?.sendPacket(CPacketEntityAction(mc.player, CPacketEntityAction.Action.START_SNEAKING)) + connection.sendPacket(CPacketEntityAction(player, CPacketEntityAction.Action.START_SNEAKING)) defaultScope.launch { delay(10L) @@ -854,19 +862,19 @@ object HighwayTools : Module() { delay(10L) onMainThreadSafe { - connection.sendPacket(CPacketEntityAction(Companion.mc.player, CPacketEntityAction.Action.STOP_SNEAKING)) + connection.sendPacket(CPacketEntityAction(player, CPacketEntityAction.Action.STOP_SNEAKING)) } } return true } - private fun isVisible(pos: BlockPos): Boolean { - val eyePos = mc.player.getPositionEyes(1f) + private fun SafeClientEvent.isVisible(pos: BlockPos): Boolean { + val eyePos = player.getPositionEyes(1f) for (side in EnumFacing.values()) { - val blockState = mc.world.getBlockState(pos.offset(side)) + val blockState = world.getBlockState(pos.offset(side)) if (blockState.isFullBlock) continue - val rayTraceResult = mc.world.rayTraceBlocks(eyePos, WorldUtils.getHitVec(pos, side), false, true, false) + val rayTraceResult = world.rayTraceBlocks(eyePos, WorldUtils.getHitVec(pos, side), false, true, false) ?: continue if (rayTraceResult.typeOfHit == RayTraceResult.Type.BLOCK && rayTraceResult.hitVec.distanceTo(pos) > 1.0) continue return true @@ -883,14 +891,14 @@ object HighwayTools : Module() { return pendingTasks.any { it.blockPos == blockPos && it.block == material } } - private fun adjustPlayerPosition(bridge: Boolean) { - var vec = getNextWalkableBlock().toVec3dCenter().subtract(mc.player.positionVector) + private fun SafeClientEvent.adjustPlayerPosition(bridge: Boolean) { + var vec = getNextWalkableBlock().toVec3dCenter().subtract(player.positionVector) when { bridge && !buildDirectionSaved.isDiagonal -> vec = vec.add(Vec3d(buildDirectionSaved.directionVec).scale(0.525)) bridge && buildDirectionSaved.isDiagonal -> vec = vec.add(Vec3d(buildDirectionSaved.directionVec).scale(0.525)) } - mc.player.motionX = (vec.x / 2.0).coerceIn(-0.2, 0.2) - mc.player.motionZ = (vec.z / 2.0).coerceIn(-0.2, 0.2) + player.motionX = (vec.x / 2.0).coerceIn(-0.2, 0.2) + player.motionZ = (vec.z / 2.0).coerceIn(-0.2, 0.2) } fun printSettings() { @@ -1033,25 +1041,25 @@ object HighwayTools : Module() { for (blockTask in tasks) list.add(" " + blockTask.block.localizedName + "@(" + blockTask.blockPos.asString() + ") Priority: " + blockTask.taskState.ordinal + " State: " + blockTask.taskState.toString()) } - fun getNextWalkableBlock(): BlockPos { + fun SafeClientEvent.getNextWalkableBlock(): BlockPos { var lastWalkable = getNextBlock() when (mode.value) { Mode.HIGHWAY -> { for (step in 1..3) { val pos = relativeDirection(currentBlockPos, step, 0) - if (mc.world.getBlockState(pos.down()).block == material && - mc.world.getBlockState(pos).block == Blocks.AIR && - mc.world.getBlockState(pos.up()).block == Blocks.AIR) lastWalkable = pos + if (world.getBlockState(pos.down()).block == material && + world.getBlockState(pos).block == Blocks.AIR && + world.getBlockState(pos.up()).block == Blocks.AIR) lastWalkable = pos else break } } Mode.TUNNEL -> { for (step in 1..3) { val pos = relativeDirection(currentBlockPos, step, 0) - if (mc.world.getBlockState(pos.down()).block == fillerMat && - mc.world.getBlockState(pos).block == Blocks.AIR && - mc.world.getBlockState(pos.up()).block == Blocks.AIR) lastWalkable = pos + if (world.getBlockState(pos.down()).block == fillerMat && + world.getBlockState(pos).block == Blocks.AIR && + world.getBlockState(pos.up()).block == Blocks.AIR) lastWalkable = pos else break } } @@ -1111,7 +1119,7 @@ object HighwayTools : Module() { } } - private fun refreshData() { + private fun SafeClientEvent.refreshData() { doneTasks.clear() pendingTasks.clear() updateTasks(currentBlockPos) @@ -1122,7 +1130,7 @@ object HighwayTools : Module() { var stuckLevel = StuckLevel.NONE var stuckValue = 0 - fun increase(blockTask: BlockTask) { + fun SafeClientEvent.increase(blockTask: BlockTask) { when (blockTask.taskState) { TaskState.BREAK -> stuckValue += 30 From 2081a64540aef5635e04d5fd3025f9734ec6e477 Mon Sep 17 00:00:00 2001 From: Christian Date: Sun, 3 Jan 2021 05:12:12 +0100 Subject: [PATCH 182/390] Dynamic blueprint generator --- .../kami/module/modules/misc/HighwayTools.kt | 75 ++++++------------- 1 file changed, 23 insertions(+), 52 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 8a9b6c163c..eb197d1b38 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -1119,25 +1119,27 @@ object HighwayTools : Module() { } private fun genOffset(cursor: BlockPos, height: Int, width: Int, mat: Block, isOdd: Boolean) { - blueprint.add(Pair(relativeDirection(cursor, width, -2), mat)) + var matUse = mat + if (mode.value == Mode.TUNNEL) matUse = Blocks.AIR + blueprint.add(Pair(relativeDirection(cursor, width, -2), matUse)) if (buildDirectionSaved.isDiagonal) { - addOffset(cursor, height, width, mat, true) + addOffset(cursor, height, width, matUse, true) } when { isOdd -> { - blueprint.add(Pair(relativeDirection(cursor, width, 2), mat)) + blueprint.add(Pair(relativeDirection(cursor, width, 2), matUse)) if (buildDirectionSaved.isDiagonal) { - addOffset(cursor, height, width, mat, false) + addOffset(cursor, height, width, matUse, false) } } else -> { val evenCursor = relativeDirection(cursor, 1, 2) if (buildDirectionSaved.isDiagonal) { - blueprint.add(Pair(relativeDirection(evenCursor, width, 2), mat)) - addOffset(cursor, height, width, mat, false) - addOffset(evenCursor, height, width, mat, false) + blueprint.add(Pair(relativeDirection(evenCursor, width, 2), matUse)) + addOffset(cursor, height, width, matUse, false) + addOffset(evenCursor, height, width, matUse, false) } else { - blueprint.add(Pair(relativeDirection(evenCursor, width, 2), mat)) + blueprint.add(Pair(relativeDirection(evenCursor, width, 2), matUse)) } } } @@ -1154,13 +1156,15 @@ object HighwayTools : Module() { var cursor = blockPos.down() when (mode.value) { - Mode.HIGHWAY -> { + Mode.HIGHWAY, Mode.TUNNEL -> { + var mat = material + if (mode.value == Mode.TUNNEL) mat = fillerMat if (baritoneMode.value) { cursor = relativeDirection(cursor, 1, 0) - blueprint.add(Pair(cursor, material)) + blueprint.add(Pair(cursor, mat)) } cursor = relativeDirection(cursor, 1, 0) - blueprint.add(Pair(cursor, material)) + blueprint.add(Pair(cursor, mat)) var buildIterationsWidth = buildWidth.value / 2 var evenCursor = relativeDirection(cursor, 1, 2) var isOdd = false @@ -1168,19 +1172,20 @@ object HighwayTools : Module() { isOdd = true buildIterationsWidth++ } else { - blueprint.add(Pair(evenCursor, material)) + blueprint.add(Pair(evenCursor, mat)) } + if (mode.value == Mode.TUNNEL) cursor = cursor.up() for (i in 1 until clearHeight.value + 1) { for (j in 1 until buildIterationsWidth) { if (i == 1) { if (j == buildIterationsWidth - 1 && !cornerBlock.value) { genOffset(cursor, i, j, fillerMat, isOdd) } else { - genOffset(cursor, i, j, material, isOdd) + genOffset(cursor, i, j, mat, isOdd) } } else { if (i <= railingHeight.value + 1 && j == buildIterationsWidth - 1) { - genOffset(cursor, i, j, material, isOdd) + genOffset(cursor, i, j, mat, isOdd) } else { if (clearSpace.value) { genOffset(cursor, i, j, Blocks.AIR, isOdd) @@ -1188,47 +1193,13 @@ object HighwayTools : Module() { } } } - cursor = cursor.up() - evenCursor = evenCursor.up() - if (clearSpace.value && i < clearHeight.value) { - blueprint.add(Pair(cursor, Blocks.AIR)) - if (!isOdd) blueprint.add(Pair(evenCursor, Blocks.AIR)) - } - } - } - Mode.TUNNEL -> { - if (baritoneMode.value) { - cursor = relativeDirection(cursor, 1, 0) - blueprint.add(Pair(cursor, fillerMat)) - } - cursor = relativeDirection(cursor, 1, 0) - blueprint.add(Pair(cursor, fillerMat)) - var buildIterationsWidth = buildWidth.value / 2 - var evenCursor = relativeDirection(cursor, 1, 2) - var isOdd = false - if (buildWidth.value % 2 == 1) { - isOdd = true - buildIterationsWidth++ - } else { - blueprint.add(Pair(evenCursor, fillerMat)) - } - for (i in 1 until clearHeight.value + 2) { - for (j in 1 until buildIterationsWidth) { - if (i > 1) { - if (cornerBlock.value && i == 2 && j == buildIterationsWidth - 1) continue - blueprint.add(Pair(relativeDirection(cursor, j, -2), Blocks.AIR)) - if (isOdd) blueprint.add(Pair(relativeDirection(cursor, j, 2), Blocks.AIR)) - else blueprint.add(Pair(relativeDirection(evenCursor, j, 2), Blocks.AIR)) - if (buildDirectionSaved.isDiagonal) { - blueprint.add(Pair(relativeDirection(cursor, j, -3), Blocks.AIR)) - if (isOdd) blueprint.add(Pair(relativeDirection(cursor, j, 3), Blocks.AIR)) - else blueprint.add(Pair(relativeDirection(evenCursor, j, 3), Blocks.AIR)) - } - } + if (mode.value == Mode.TUNNEL) { + if (i == 1) blueprint.add(Pair(cursor, Blocks.AIR)) + if (i == clearHeight.value) blueprint.add(Pair(evenCursor.up(), Blocks.AIR)) } cursor = cursor.up() evenCursor = evenCursor.up() - if (clearSpace.value && i < clearHeight.value + 1) { + if (clearSpace.value && i < clearHeight.value) { blueprint.add(Pair(cursor, Blocks.AIR)) if (!isOdd) blueprint.add(Pair(evenCursor, Blocks.AIR)) } From 55a7c787aa0d4186a367f3a260e8a04463eb5457 Mon Sep 17 00:00:00 2001 From: Christian Date: Sun, 3 Jan 2021 05:24:55 +0100 Subject: [PATCH 183/390] Bump to v08 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 3bb6c71504..6492aaa779 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ org.gradle.jvmargs=-Xmx3G modGroup=me.zeroeightsix -modVersion=2.01.xx-dev-ht-v07 +modVersion=2.01.xx-dev-ht-v08 kotlin_version=1.4.21 kotlinx_coroutines_version=1.4.1 \ No newline at end of file From d91eab330fcf41fc833cdb75affff0d86ab70ebe Mon Sep 17 00:00:00 2001 From: Christian Date: Sun, 3 Jan 2021 05:26:48 +0100 Subject: [PATCH 184/390] Fix deprecated code in AutoObsidian --- .../zeroeightsix/kami/module/modules/misc/AutoObsidian.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt index 04aead9d7d..2537d2208d 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt @@ -7,7 +7,6 @@ import kotlinx.coroutines.launch import me.zeroeightsix.kami.event.Phase import me.zeroeightsix.kami.event.events.OnUpdateWalkingPlayerEvent import me.zeroeightsix.kami.event.events.RenderWorldEvent -import me.zeroeightsix.kami.event.events.SafeTickEvent import me.zeroeightsix.kami.manager.managers.PlayerPacketManager import me.zeroeightsix.kami.module.Module import me.zeroeightsix.kami.module.modules.player.NoBreakAnimation @@ -24,6 +23,7 @@ import me.zeroeightsix.kami.util.math.VectorUtils.toVec3d import me.zeroeightsix.kami.util.text.MessageSendHelper.sendChatMessage import me.zeroeightsix.kami.util.threads.defaultScope import me.zeroeightsix.kami.util.threads.onMainThreadSafe +import me.zeroeightsix.kami.util.threads.safeListener import net.minecraft.block.BlockShulkerBox import net.minecraft.block.state.IBlockState import net.minecraft.client.audio.PositionedSoundRecord @@ -128,9 +128,9 @@ object AutoObsidian : Module() { } init { - listener { + safeListener { if (it.phase != TickEvent.Phase.END || mc.playerController == null - || !tickTimer.tick(delayTicks.value.toLong())) return@listener + || !tickTimer.tick(delayTicks.value.toLong())) return@safeListener updateState() when (state) { From d981e92ae0503c62b219bfe92737db3b10020352 Mon Sep 17 00:00:00 2001 From: Christian Date: Sun, 3 Jan 2021 05:34:08 +0100 Subject: [PATCH 185/390] Formatting --- .../me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt | 5 ++--- .../me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt index 2537d2208d..55f803df2e 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt @@ -428,11 +428,10 @@ object AutoObsidian : Module() { InventoryUtils.inventoryClick(container.windowId, slot, 0, ClickType.QUICK_MOVE) mc.player.closeScreen() } else if (shulkerOpenTimer.tick(100, false)) { // Wait for maximum of 5 seconds - if(leaveEmptyShulkers.value && container.inventory.subList(0, 27).indexOfFirst { it.item.id != ItemID.AIR.id } == -1) { + if (leaveEmptyShulkers.value && container.inventory.subList(0, 27).indexOfFirst { it.item.id != ItemID.AIR.id } == -1) { searchingState = SearchingState.PRE_MINING mc.player.closeScreen() - } - else { + } else { sendChatMessage("$chatName No ender chest was found in shulker, disabling.") mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) disable() diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index eb197d1b38..714b4e67e4 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -1250,7 +1250,7 @@ object HighwayTools : Module() { stuckLevel = StuckLevel.MODERATE if (!pathing && blockTask.taskState == TaskState.PLACE && !buildDirectionSaved.isDiagonal) adjustPlayerPosition(true) refreshData() - if (debugMessages.value != DebugMessages.OFF ) sendChatMessage("$chatName Refreshing data") + if (debugMessages.value != DebugMessages.OFF) sendChatMessage("$chatName Refreshing data") } stuckValue > 500 -> { stuckLevel = StuckLevel.MAYOR From b8f1b33fcd9e89bfe65310b69d649b3a2a81b22f Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Sun, 3 Jan 2021 00:06:11 -0500 Subject: [PATCH 186/390] Fixed visible check, added rayTraceHitVec --- .../kami/module/modules/misc/HighwayTools.kt | 57 +++++++++++-------- .../me/zeroeightsix/kami/util/WorldUtils.kt | 35 +++++++----- .../kami/util/math/BoundingBoxUtils.kt | 38 +++++++++++++ .../kami/util/math/VectorUtils.kt | 10 +++- 4 files changed, 101 insertions(+), 39 deletions(-) create mode 100644 src/main/java/me/zeroeightsix/kami/util/math/BoundingBoxUtils.kt diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 1f82e569fe..534e05df07 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -17,6 +17,7 @@ import me.zeroeightsix.kami.setting.Settings import me.zeroeightsix.kami.util.* import me.zeroeightsix.kami.util.EntityUtils.flooredPosition import me.zeroeightsix.kami.util.WorldUtils.placeBlock +import me.zeroeightsix.kami.util.WorldUtils.rayTraceHitVec import me.zeroeightsix.kami.util.color.ColorHolder import me.zeroeightsix.kami.util.graphics.ESPRenderer import me.zeroeightsix.kami.util.math.CoordinateConverter.asString @@ -511,9 +512,16 @@ object HighwayTools : Module() { return false } - if (!inventoryProcessor(blockTask)) return false - if (!placeBlock(blockTask)) return false - if (blockTask.taskState != TaskState.PLACE && isInsideSelection(blockTask.blockPos)) updateTask(blockTask, Blocks.AIR) + if (!inventoryProcessor(blockTask)) { + return false + } + if (!placeBlock(blockTask)) { + return false + } + if (blockTask.taskState != TaskState.PLACE && isInsideSelection(blockTask.blockPos)) { + updateTask(blockTask, Blocks.AIR) + } + updateTask(blockTask, TaskState.PLACED) if (blocksPerTick.value > blocksPlaced + 1) { blocksPlaced++ @@ -783,15 +791,17 @@ object HighwayTools : Module() { return } - if (!isVisible(blockTask.blockPos)) { + val rayTraceResult = rayTraceHitVec(blockTask.blockPos) + + if (rayTraceResult == null) { increase(blockTask) refreshData() if (StuckManager.stuckLevel == StuckLevel.NONE) doTask() return } - val side = EnumFacing.getDirectionFromEntityLiving(blockTask.blockPos, player) - lastHitVec = WorldUtils.getHitVec(blockTask.blockPos, side) + val side = rayTraceResult.sideHit + lastHitVec = rayTraceResult.hitVec rotateTimer.reset() when (world.getBlockState(blockTask.blockPos).block) { @@ -804,7 +814,7 @@ object HighwayTools : Module() { connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, blockTask.blockPos, side)) player.swingArm(EnumHand.MAIN_HAND) } - delay(20L) + delay(10L) onMainThreadSafe { connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, blockTask.blockPos, side)) player.swingArm(EnumHand.MAIN_HAND) @@ -833,6 +843,12 @@ object HighwayTools : Module() { } private fun SafeClientEvent.placeBlock(blockTask: BlockTask): Boolean { + val pair = WorldUtils.getNeighbour(blockTask.blockPos, 1, 6.5f) + ?: run { + sendChatMessage("Can't find neighbour block") + return false + } + if (!isVisible(blockTask.blockPos)) { if (illegalPlacements.value) { if (debugMessages.value == DebugMessages.ALL) { @@ -843,19 +859,13 @@ object HighwayTools : Module() { } } - val pair = WorldUtils.getNeighbour(blockTask.blockPos, 1, 6.5f) - ?: run { - sendChatMessage("Can't find neighbour block") - return false - } - lastHitVec = WorldUtils.getHitVec(pair.second, pair.first) rotateTimer.reset() connection.sendPacket(CPacketEntityAction(player, CPacketEntityAction.Action.START_SNEAKING)) defaultScope.launch { - delay(10L) + delay(5L) onMainThreadSafe { placeBlock(pair.second, pair.first) } @@ -874,8 +884,8 @@ object HighwayTools : Module() { for (side in EnumFacing.values()) { val blockState = world.getBlockState(pos.offset(side)) if (blockState.isFullBlock) continue - val rayTraceResult = world.rayTraceBlocks(eyePos, WorldUtils.getHitVec(pos, side), false, true, false) - ?: continue + val rayTraceResult = world.rayTraceBlocks(eyePos, WorldUtils.getHitVec(pos, side), false, false, true) + ?: return true if (rayTraceResult.typeOfHit == RayTraceResult.Type.BLOCK && rayTraceResult.hitVec.distanceTo(pos) > 1.0) continue return true } @@ -1041,25 +1051,25 @@ object HighwayTools : Module() { for (blockTask in tasks) list.add(" " + blockTask.block.localizedName + "@(" + blockTask.blockPos.asString() + ") Priority: " + blockTask.taskState.ordinal + " State: " + blockTask.taskState.toString()) } - fun SafeClientEvent.getNextWalkableBlock(): BlockPos { + fun getNextWalkableBlock(): BlockPos { var lastWalkable = getNextBlock() when (mode.value) { Mode.HIGHWAY -> { for (step in 1..3) { val pos = relativeDirection(currentBlockPos, step, 0) - if (world.getBlockState(pos.down()).block == material && - world.getBlockState(pos).block == Blocks.AIR && - world.getBlockState(pos.up()).block == Blocks.AIR) lastWalkable = pos + if (mc.world.getBlockState(pos.down()).block == material && + mc.world.getBlockState(pos).block == Blocks.AIR && + mc.world.getBlockState(pos.up()).block == Blocks.AIR) lastWalkable = pos else break } } Mode.TUNNEL -> { for (step in 1..3) { val pos = relativeDirection(currentBlockPos, step, 0) - if (world.getBlockState(pos.down()).block == fillerMat && - world.getBlockState(pos).block == Blocks.AIR && - world.getBlockState(pos.up()).block == Blocks.AIR) lastWalkable = pos + if (mc.world.getBlockState(pos.down()).block == fillerMat && + mc.world.getBlockState(pos).block == Blocks.AIR && + mc.world.getBlockState(pos.up()).block == Blocks.AIR) lastWalkable = pos else break } } @@ -1131,7 +1141,6 @@ object HighwayTools : Module() { var stuckValue = 0 fun SafeClientEvent.increase(blockTask: BlockTask) { - when (blockTask.taskState) { TaskState.BREAK -> stuckValue += 30 TaskState.EMERGENCY_BREAK -> stuckValue += 30 diff --git a/src/main/java/me/zeroeightsix/kami/util/WorldUtils.kt b/src/main/java/me/zeroeightsix/kami/util/WorldUtils.kt index 722964e3f9..a12190880f 100644 --- a/src/main/java/me/zeroeightsix/kami/util/WorldUtils.kt +++ b/src/main/java/me/zeroeightsix/kami/util/WorldUtils.kt @@ -4,6 +4,7 @@ import kotlinx.coroutines.delay import me.zeroeightsix.kami.event.SafeClientEvent import me.zeroeightsix.kami.manager.managers.PlayerPacketManager import me.zeroeightsix.kami.util.math.RotationUtils +import me.zeroeightsix.kami.util.math.corners import me.zeroeightsix.kami.util.threads.runSafeSuspend import net.minecraft.client.Minecraft import net.minecraft.entity.Entity @@ -105,6 +106,14 @@ object WorldUtils { return mc.world.getBlockState(pos).block == Blocks.WATER } + /** + * Checks if given [pos] is able to place block in it + * + * @return true playing is not colliding with [pos] and there is block below it + */ + fun isPlaceable(pos: BlockPos, ignoreSelfCollide: Boolean = false) = mc.world.getBlockState(pos).material.isReplaceable + && mc.world.checkNoEntityCollision(AxisAlignedBB(pos), if (ignoreSelfCollide) mc.player else null) + fun rayTraceTo(blockPos: BlockPos): RayTraceResult? { return mc.world.rayTraceBlocks(mc.player.getPositionEyes(1f), Vec3d(blockPos).add(0.5, 0.5, 0.5)) } @@ -123,23 +132,21 @@ object WorldUtils { return Vec3d(vec.x * 0.5 + 0.5, vec.y * 0.5 + 0.5, vec.z * 0.5 + 0.5) } - /** - * Checks if given [pos] is able to place block in it - * - * @return true playing is not colliding with [pos] and there is block below it - */ - fun isPlaceable(pos: BlockPos, ignoreSelfCollide: Boolean = false) = mc.world.getBlockState(pos).material.isReplaceable - && mc.world.checkNoEntityCollision(AxisAlignedBB(pos), if (ignoreSelfCollide) mc.player else null) + fun SafeClientEvent.rayTraceHitVec(pos: BlockPos) : RayTraceResult? { + val eyePos = player.getPositionEyes(1f) + val bb = world.getBlockState(pos).getSelectedBoundingBox(world, pos) - /** - * Checks if given [pos] is able to chest (air above) block in it - * - * @return true playing is not colliding with [pos] and there is block below it - */ - fun isPlaceableForChest(pos: BlockPos): Boolean { - return isPlaceable(pos) && !mc.world.getBlockState(pos.down()).material.isReplaceable && mc.world.isAirBlock(pos.up()) + return world.rayTraceBlocks(eyePos, bb.center, false, false, true)?.takeIf { + it.isEqualTo(pos) + } ?: bb.corners(0.95).mapNotNull { corner -> + world.rayTraceBlocks(eyePos, corner, false, false, true)?.takeIf { it.isEqualTo(pos) } + }.minByOrNull { + it.hitVec?.distanceTo(eyePos) ?: 69420.0 + } } + private fun RayTraceResult.isEqualTo(pos: BlockPos) = typeOfHit == RayTraceResult.Type.BLOCK && blockPos == pos + suspend fun buildStructure( placeSpeed: Float, getPlaceInfo: (HashSet) -> Pair? diff --git a/src/main/java/me/zeroeightsix/kami/util/math/BoundingBoxUtils.kt b/src/main/java/me/zeroeightsix/kami/util/math/BoundingBoxUtils.kt new file mode 100644 index 0000000000..1dec35c5d0 --- /dev/null +++ b/src/main/java/me/zeroeightsix/kami/util/math/BoundingBoxUtils.kt @@ -0,0 +1,38 @@ +package me.zeroeightsix.kami.util.math + +import me.zeroeightsix.kami.util.math.VectorUtils.plus +import me.zeroeightsix.kami.util.math.VectorUtils.times +import me.zeroeightsix.kami.util.math.VectorUtils.toVec3d +import net.minecraft.util.EnumFacing +import net.minecraft.util.math.AxisAlignedBB +import net.minecraft.util.math.Vec3d + +val AxisAlignedBB.xLength get() = maxX - minX + +val AxisAlignedBB.yLength get() = maxY - minY + +val AxisAlignedBB.zLength get() = maxY - minY + +val AxisAlignedBB.lengths get() = Vec3d(xLength, yLength, zLength) + +fun AxisAlignedBB.corners(scale: Double) : Array { + val growSizes = lengths * (scale - 1.0) + return grow(growSizes.x, growSizes.y, growSizes.z).corners() +} + +fun AxisAlignedBB.corners() = arrayOf( + Vec3d(minX, minY, minZ), + Vec3d(minX, minY, maxZ), + Vec3d(minX, maxY, minZ), + Vec3d(minX, maxY, maxZ), + Vec3d(maxX, minY, minZ), + Vec3d(maxX, minY, maxZ), + Vec3d(maxX, maxY, minZ), + Vec3d(maxX, maxY, maxZ), +) + +fun AxisAlignedBB.side(side: EnumFacing, scale: Double = 0.5) : Vec3d { + val lengths = lengths + val sideDirectionVec = side.directionVec.toVec3d() + return lengths * sideDirectionVec * scale + center +} \ No newline at end of file diff --git a/src/main/java/me/zeroeightsix/kami/util/math/VectorUtils.kt b/src/main/java/me/zeroeightsix/kami/util/math/VectorUtils.kt index 5a1de215b5..32f3613361 100644 --- a/src/main/java/me/zeroeightsix/kami/util/math/VectorUtils.kt +++ b/src/main/java/me/zeroeightsix/kami/util/math/VectorUtils.kt @@ -72,7 +72,7 @@ object VectorUtils { } fun Vec3i.toVec3d(offSet: Vec3d): Vec3d { - return Vec3d(x+ offSet.x, y + offSet.y, z + offSet.z) + return Vec3d(x + offSet.x, y + offSet.y, z + offSet.z) } fun Vec3i.toVec3d(xOffset: Double, yOffset: Double, zOffset: Double): Vec3d { @@ -126,4 +126,12 @@ object VectorUtils { fun Vec3i.multiply(multiplier: Int): Vec3i { return Vec3i(x * multiplier, y * multiplier, z * multiplier) } + + infix operator fun Vec3d.times(vec3d: Vec3d): Vec3d = Vec3d(x * vec3d.x, y * vec3d.y, z * vec3d.z) + + infix operator fun Vec3d.times(multiplier: Double): Vec3d = Vec3d(x * multiplier, y * multiplier, z * multiplier) + + infix operator fun Vec3d.plus(vec3d: Vec3d): Vec3d = add(vec3d) + + infix operator fun Vec3d.minus(vec3d: Vec3d): Vec3d = subtract(vec3d) } From 3740075e4bbaba74d98ab4aa02e835ddbda192e8 Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Sun, 3 Jan 2021 14:06:26 -0500 Subject: [PATCH 187/390] Rewrote task priority comparing --- .../kami/module/modules/misc/HighwayTools.kt | 23 +++++++++++++------ .../kami/util/threads/ThreadSafety.kt | 2 +- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index ab42bf21cf..b2b8f68663 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -1191,10 +1191,19 @@ object HighwayTools : Module() { var taskState: TaskState, var block: Block ) : Comparable { - override fun compareTo(other: BlockTask) = when { - taskState.ordinal != other.taskState.ordinal -> taskState.ordinal - other.taskState.ordinal - taskState.ordinal == other.taskState.ordinal && StuckManager.stuckLevel != StuckLevel.NONE -> 0 - else -> (mc.player.distanceTo(blockPos) - mc.player.distanceTo(other.blockPos)).toInt() + override fun compareTo(other: BlockTask) : Int { + return runSafeR { + if (!isVisible(other.blockPos)) return@runSafeR 69 + + val statePriority = taskState.ordinal - other.taskState.ordinal + if (statePriority != 0) return@runSafeR statePriority + + val eyePos = player.getPositionEyes(1f) ?: Vec3d.ZERO + val dist = (eyePos.distanceTo(other.blockPos) - eyePos.distanceTo(blockPos)).toInt() + if (dist != 0) return@runSafeR dist + + -0x22 + } ?: -420 } override fun toString(): String { @@ -1204,13 +1213,13 @@ object HighwayTools : Module() { enum class TaskState(val color: ColorHolder) { DONE(ColorHolder(50, 50, 50)), - BREAKING(ColorHolder(240, 222, 60)), - EMERGENCY_BREAK(ColorHolder(220, 41, 140)), LIQUID_SOURCE(ColorHolder(120, 41, 240)), LIQUID_FLOW(ColorHolder(120, 41, 240)), + BREAKING(ColorHolder(240, 222, 60)), + EMERGENCY_BREAK(ColorHolder(220, 41, 140)), BREAK(ColorHolder(222, 0, 0)), - BROKEN(ColorHolder(111, 0, 0)), PLACE(ColorHolder(35, 188, 254)), + BROKEN(ColorHolder(111, 0, 0)), PLACED(ColorHolder(53, 222, 66)) } diff --git a/src/main/java/me/zeroeightsix/kami/util/threads/ThreadSafety.kt b/src/main/java/me/zeroeightsix/kami/util/threads/ThreadSafety.kt index 9685ce7c2b..05bda951e1 100644 --- a/src/main/java/me/zeroeightsix/kami/util/threads/ThreadSafety.kt +++ b/src/main/java/me/zeroeightsix/kami/util/threads/ThreadSafety.kt @@ -31,7 +31,7 @@ fun runSafe(block: SafeClientEvent.() -> Unit) { ClientEvent().toSafe()?.let { block(it) } } -fun runSafe(block: SafeClientEvent.() -> R): R? { +fun runSafeR(block: SafeClientEvent.() -> R): R? { return ClientEvent().toSafe()?.let { block(it) } } From 11e6d9f8c1886cde7322ed22be2bc4df2bebc532 Mon Sep 17 00:00:00 2001 From: theredstoner Date: Sun, 3 Jan 2021 13:37:55 -0700 Subject: [PATCH 188/390] Fix silk touch check in AutoObsidian Check the case where both a silk-touch and non-silk-touch pickaxe are in the hotbar, but the silk-touch pickaxe has a lower slot number than the non-silk-touch pickaxe. --- .../kami/module/modules/misc/AutoObsidian.kt | 43 ++++++++++++------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt index 55f803df2e..a0669d23ad 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt @@ -483,23 +483,24 @@ object AutoObsidian : Module() { } /** - * @return True if there is a non-sliktouch pick in the hotbar, else returns false + * Gets the first hotbar slot of a diamond pickaxe that does not have the silk touch enchantment. + * @return The position of the pickaxe. -1 if there is no match. */ - private fun hotbarHasNonSilkTouchPick(): Boolean { - val slotsWithPickaxes = InventoryUtils.getSlotsHotbar(ItemID.DIAMOND_PICKAXE.id) ?: return false + private fun getHotbarNonSilkTouchPick(): Int { + val slotsWithPickaxes = InventoryUtils.getSlotsHotbar(ItemID.DIAMOND_PICKAXE.id) ?: return -1 for (slot in slotsWithPickaxes) { if (EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, mc.player.inventory.getStackInSlot(slot)) == 0) { - return true + return slot } } - return false + return -1 } /** * Gets the first non-hotbar slot of a diamond pickaxe that does not have the silk touch enchantment. * @return The position of the pickaxe. -1 if there is no match. */ - private fun getNonSilkTouchPickPos(): Int { + private fun getInventoryNonSilkTouchPick(): Int { val slotsWithPickaxes = InventoryUtils.getSlotsNoHotbar(ItemID.DIAMOND_PICKAXE.id) ?: return -1 for (slot in slotsWithPickaxes) { if (EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, mc.player.inventory.getStackInSlot(slot)) == 0) { @@ -509,17 +510,27 @@ object AutoObsidian : Module() { return -1 } - private fun mineBlock(pos: BlockPos, pre: Boolean) { - if (pre) { - if (!hotbarHasNonSilkTouchPick() && getNonSilkTouchPickPos() != -1) { - InventoryUtils.moveToSlot(0, getNonSilkTouchPickPos(), 36) - } else if (!hotbarHasNonSilkTouchPick()) { - sendChatMessage("No valid pickaxe was found in inventory.") - mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) - disable() - } - InventoryUtils.swapSlotToItem(ItemID.DIAMOND_PICKAXE.id) + /** + * Swaps the active hotbar slot to one which has a valid pickaxe (i.e. non-silk touch). If there is no valid pickaxe, + * disable the module. + */ + private fun swapToValidPickaxe() { + var hotbarPickaxeSlot = getHotbarNonSilkTouchPick() + val inventoryPickaxeSlot = getInventoryNonSilkTouchPick() + if ((hotbarPickaxeSlot == -1) && (inventoryPickaxeSlot != -1)) { + /* Note that slot 36 in windowId 0 is the same as slot 0 in the hotbar */ + InventoryUtils.moveToSlot(0, inventoryPickaxeSlot, 36) + hotbarPickaxeSlot = 0 + } else if (hotbarPickaxeSlot == -1) { + sendChatMessage("No valid pickaxe was found in inventory.") + mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) + disable() } + InventoryUtils.swapSlot(hotbarPickaxeSlot) + } + + private fun mineBlock(pos: BlockPos, pre: Boolean) { + if (pre) swapToValidPickaxe() val side = EnumFacing.getDirectionFromEntityLiving(pos, mc.player) lastHitVec = WorldUtils.getHitVec(pos, side) From 188de783d47cca2b125557f72cac603680933ff3 Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Sun, 3 Jan 2021 15:38:57 -0500 Subject: [PATCH 189/390] Fixed task sorting --- .../kami/module/modules/misc/HighwayTools.kt | 207 +++++------------- 1 file changed, 57 insertions(+), 150 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index b2b8f68663..403e0fcb08 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -6,10 +6,8 @@ import me.zeroeightsix.kami.event.Phase import me.zeroeightsix.kami.event.SafeClientEvent import me.zeroeightsix.kami.event.events.OnUpdateWalkingPlayerEvent import me.zeroeightsix.kami.event.events.RenderWorldEvent -import me.zeroeightsix.kami.gui.kami.DisplayGuiScreen import me.zeroeightsix.kami.manager.managers.PlayerPacketManager import me.zeroeightsix.kami.module.Module -import me.zeroeightsix.kami.module.modules.misc.HighwayTools.StuckManager.increase import me.zeroeightsix.kami.module.modules.player.AutoEat import me.zeroeightsix.kami.module.modules.player.InventoryManager import me.zeroeightsix.kami.process.HighwayToolsProcess @@ -28,10 +26,7 @@ import me.zeroeightsix.kami.util.math.VectorUtils.getBlockPositionsInArea import me.zeroeightsix.kami.util.math.VectorUtils.multiply import me.zeroeightsix.kami.util.math.VectorUtils.toVec3dCenter import me.zeroeightsix.kami.util.text.MessageSendHelper.sendChatMessage -import me.zeroeightsix.kami.util.threads.defaultScope -import me.zeroeightsix.kami.util.threads.onMainThreadSafe -import me.zeroeightsix.kami.util.threads.runSafe -import me.zeroeightsix.kami.util.threads.safeListener +import me.zeroeightsix.kami.util.threads.* import net.minecraft.block.Block import net.minecraft.block.Block.getIdFromBlock import net.minecraft.block.BlockLiquid @@ -113,7 +108,7 @@ object HighwayTools : Module() { private var baritoneSettingRenderGoal = false // runtime vars - val pendingTasks = PriorityQueue() + val pendingTasks = LinkedList() private val doneTasks = ArrayList() private val blueprint = ArrayList>() private var waitTicks = 0 @@ -228,6 +223,9 @@ object HighwayTools : Module() { if (event.phase != Phase.PRE) return@safeListener updateRenderer() + pendingTasks.sortWith(compareBy { + it.taskState.ordinal + it.stuckTicks + player.getPositionEyes(1f).distanceTo(it.blockPos) + }) if (!active) { active = true @@ -329,6 +327,7 @@ object HighwayTools : Module() { pendingTasks.poll() blockTask.block = material doneTasks.add(blockTask) + blockTask.onUpdate() } /* Returns true if we can do a task, else returns false */ @@ -346,10 +345,7 @@ object HighwayTools : Module() { doDone(blockTask) } TaskState.BREAKING -> { - if (!doBreaking(blockTask)) { - increase(blockTask) - return - } + doBreaking(blockTask) } TaskState.BROKEN -> { doBroken(blockTask) @@ -358,24 +354,15 @@ object HighwayTools : Module() { doPlaced(blockTask) } TaskState.EMERGENCY_BREAK -> { - if (!doBreak(blockTask)) { - increase(blockTask) - return - } + doBreak(blockTask) } - TaskState.BREAK -> if (!doBreak(blockTask)) { - increase(blockTask) - return + TaskState.BREAK -> { + doBreak(blockTask) } TaskState.PLACE, TaskState.LIQUID_SOURCE, TaskState.LIQUID_FLOW -> { - if (!doPlace(blockTask)) { - increase(blockTask) - return - } + doPlace(blockTask) } } - - if (blockTask.taskState != TaskState.BREAKING) StuckManager.reset() } else { waitTicks-- } @@ -388,7 +375,7 @@ object HighwayTools : Module() { doTask() } - private fun SafeClientEvent.doBreaking(blockTask: BlockTask): Boolean { + private fun SafeClientEvent.doBreaking(blockTask: BlockTask) { when (world.getBlockState(blockTask.blockPos).block) { Blocks.AIR -> { totalBlocksDestroyed++ @@ -415,7 +402,6 @@ object HighwayTools : Module() { mineBlock(blockTask) } } - return true } private fun SafeClientEvent.doBroken(blockTask: BlockTask) { @@ -486,14 +472,16 @@ object HighwayTools : Module() { return true } } - if (!inventoryProcessor(blockTask)) return false + + inventoryProcessor(blockTask) + mineBlock(blockTask) } } return true } - private fun SafeClientEvent.doPlace(blockTask: BlockTask): Boolean { + private fun SafeClientEvent.doPlace(blockTask: BlockTask) { val block = world.getBlockState(blockTask.blockPos).block when { @@ -505,19 +493,15 @@ object HighwayTools : Module() { } else -> { if (!WorldUtils.isPlaceable(blockTask.blockPos)) { -// if (debugMessages.value != DebugMessages.OFF) sendChatMessage("Error: " + blockTask.blockPos + " is not a valid position to place a block, removing task.") -// blockQueue.remove(blockTask) if (debugMessages.value != DebugMessages.OFF) sendChatMessage("Invalid place position: " + blockTask.blockPos) refreshData() - return false + return } - if (!inventoryProcessor(blockTask)) { - return false - } - if (!placeBlock(blockTask)) { - return false - } + inventoryProcessor(blockTask) + + placeBlock(blockTask) + if (blockTask.taskState != TaskState.PLACE && isInsideSelection(blockTask.blockPos)) { updateTask(blockTask, Blocks.AIR) } @@ -534,7 +518,6 @@ object HighwayTools : Module() { totalBlocksPlaced++ } } - return true } private fun SafeClientEvent.checkTasks(): Boolean { @@ -671,49 +654,33 @@ object HighwayTools : Module() { } } - private fun SafeClientEvent.inventoryProcessor(blockTask: BlockTask): Boolean { + private fun SafeClientEvent.inventoryProcessor(blockTask: BlockTask) { when (blockTask.taskState) { TaskState.BREAK, TaskState.EMERGENCY_BREAK -> { AutoTool.equipBestTool(world.getBlockState(blockTask.blockPos)) -// val noHotbar = InventoryUtils.getSlotsNoHotbar(278) -// if (InventoryUtils.getSlotsHotbar(278) == null && noHotbar != null) { -//// InventoryUtils.moveToHotbar(278, 130) -// InventoryUtils.moveToSlot(noHotbar[0], 36) -// } else if (InventoryUtils.getSlots(0, 35, 278) == null) { -// sendChatMessage("$chatName No Pickaxe was found in inventory") -// mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) -// disable() -// return false -// } -// InventoryUtils.swapSlotToItem(278) } TaskState.PLACE, TaskState.LIQUID_FLOW, TaskState.LIQUID_SOURCE -> { val blockID = getIdFromBlock(blockTask.block) val noHotbar = InventoryUtils.getSlotsNoHotbar(blockID) -// fillerMatLeft = InventoryUtils.countItemAll(getIdFromBlock(fillerMat)) -// if (fillerMatLeft > overburden.value) { -// for (x in InventoryUtils.getSlots(0, 35, blockID)!!) InventoryUtils.throwAllInSlot(x) -// } - if (InventoryUtils.getSlotsHotbar(blockID) == null && - noHotbar != null) { + + if (InventoryUtils.getSlotsHotbar(blockID) == null && noHotbar != null) { when (blockTask.block) { fillerMat -> InventoryUtils.moveToSlot(noHotbar[0], 37) material -> InventoryUtils.moveToSlot(noHotbar[0], 38) } -// for (x in InventoryUtils.getSlotsNoHotbar(blockID)!!) { -// InventoryUtils.quickMoveSlot(x) -// } } else if (InventoryUtils.getSlots(0, 35, blockID) == null) { sendChatMessage("$chatName No ${blockTask.block.localizedName} was found in inventory") mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) disable() - return false + blockTask.onFailed() } + InventoryUtils.swapSlotToItem(blockID) } - else -> return false + else -> { + blockTask.onFailed() + } } - return true } private fun SafeClientEvent.handleLiquid(blockTask: BlockTask): Boolean { @@ -777,9 +744,7 @@ object HighwayTools : Module() { val rayTraceResult = rayTraceHitVec(blockTask.blockPos) if (rayTraceResult == null) { - increase(blockTask) - refreshData() - if (StuckManager.stuckLevel == StuckLevel.NONE) doTask() + blockTask.onFailed() return } @@ -792,14 +757,14 @@ object HighwayTools : Module() { updateTask(blockTask, TaskState.BROKEN) waitTicks = tickDelayBreak.value defaultScope.launch { - delay(5L) + delay(10L) onMainThreadSafe { connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, blockTask.blockPos, side)) player.swingArm(EnumHand.MAIN_HAND) } - delay(45L) + delay(40L) onMainThreadSafe { - connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, blockTask.blockPos, facing)) + connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, blockTask.blockPos, side)) player.swingArm(EnumHand.MAIN_HAND) } } @@ -817,7 +782,7 @@ object HighwayTools : Module() { } if (blockTask.taskState == TaskState.BREAK || blockTask.taskState == TaskState.EMERGENCY_BREAK) updateTask(blockTask, TaskState.BREAKING) defaultScope.launch { - delay(5L) + delay(10L) onMainThreadSafe { connection.sendPacket(digPacket) player.swingArm(EnumHand.MAIN_HAND) @@ -825,11 +790,12 @@ object HighwayTools : Module() { } } - private fun SafeClientEvent.placeBlock(blockTask: BlockTask): Boolean { + private fun SafeClientEvent.placeBlock(blockTask: BlockTask) { val pair = WorldUtils.getNeighbour(blockTask.blockPos, 1, 6.5f) ?: run { sendChatMessage("Can't find neighbour block") - return false + blockTask.onFailed() + return } if (!isVisible(blockTask.blockPos)) { @@ -838,7 +804,7 @@ object HighwayTools : Module() { sendChatMessage("Trying to place through wall ${blockTask.blockPos}") } } else { - return false + blockTask.onFailed() } } @@ -848,7 +814,7 @@ object HighwayTools : Module() { connection.sendPacket(CPacketEntityAction(player, CPacketEntityAction.Action.START_SNEAKING)) defaultScope.launch { - delay(5L) + delay(10L) onMainThreadSafe { placeBlock(pair.second, pair.first) } @@ -858,7 +824,6 @@ object HighwayTools : Module() { connection.sendPacket(CPacketEntityAction(player, CPacketEntityAction.Action.STOP_SNEAKING)) } } - return true } private fun SafeClientEvent.isVisible(pos: BlockPos): Boolean { @@ -957,7 +922,7 @@ object HighwayTools : Module() { return Pair(materialUsed / 2, fillerMatUsed / 2) } - fun gatherStatistics(): MutableList { + fun gatherStatistics(): List { val currentTask: BlockTask? = if (isDone()) { null } else { @@ -1114,6 +1079,12 @@ object HighwayTools : Module() { } } + object StuckManager { + override fun toString(): String { + return " " + } + } + private fun SafeClientEvent.refreshData() { doneTasks.clear() pendingTasks.clear() @@ -1121,65 +1092,6 @@ object HighwayTools : Module() { shuffleTasks() } - object StuckManager { - var stuckLevel = StuckLevel.NONE - var stuckValue = 0 - - fun SafeClientEvent.increase(blockTask: BlockTask) { - when (blockTask.taskState) { - TaskState.BREAK -> stuckValue += 30 - TaskState.EMERGENCY_BREAK -> stuckValue += 30 - TaskState.PLACE, TaskState.LIQUID_SOURCE, TaskState.LIQUID_FLOW -> stuckValue += 10 - else -> stuckValue++ - } - when { - stuckValue < 100 -> { -// if (!pathing && blockTask.taskState == TaskState.PLACE && !buildDirectionSaved.isDiagonal) adjustPlayerPosition(true) - if (blockTask.taskState != TaskState.BREAKING) { - shuffleTasks() - if (debugMessages.value == DebugMessages.ALL) sendChatMessage("$chatName Shuffled tasks $stuckValue") - } - } - stuckValue in 100..200 -> { - stuckLevel = StuckLevel.MINOR - if (!pathing && blockTask.taskState == TaskState.PLACE && !buildDirectionSaved.isDiagonal) adjustPlayerPosition(true) - if (blockTask.taskState != TaskState.BREAKING) { - shuffleTasks() - if (debugMessages.value == DebugMessages.ALL) sendChatMessage("$chatName Shuffled tasks $stuckValue") - } - // Jump etc? - } - stuckValue in 200..500 -> { - stuckLevel = StuckLevel.MODERATE - if (!pathing && blockTask.taskState == TaskState.PLACE && !buildDirectionSaved.isDiagonal) adjustPlayerPosition(true) - refreshData() - if (debugMessages.value != DebugMessages.OFF) sendChatMessage("$chatName Refreshing data") - } - stuckValue > 500 -> { - stuckLevel = StuckLevel.MAYOR - if (!pathing && blockTask.taskState == TaskState.PLACE && !buildDirectionSaved.isDiagonal) adjustPlayerPosition(true) - refreshData() - if (debugMessages.value != DebugMessages.OFF && (mc.currentScreen !is DisplayGuiScreen || mc.currentServerData != null)) sendChatMessage("$chatName Refreshing data") -// reset() -// disable() -// enable() - - // Scaffold - } - } - } - - fun reset() { - stuckLevel = StuckLevel.NONE - stuckValue = 0 - active = false - } - - override fun toString(): String { - return "Level: $stuckLevel Value: $stuckValue" - } - } - private fun shuffleTasks() { val shuffled = pendingTasks.shuffled() pendingTasks.clear() @@ -1190,37 +1102,32 @@ object HighwayTools : Module() { val blockPos: BlockPos, var taskState: TaskState, var block: Block - ) : Comparable { - override fun compareTo(other: BlockTask) : Int { - return runSafeR { - if (!isVisible(other.blockPos)) return@runSafeR 69 - - val statePriority = taskState.ordinal - other.taskState.ordinal - if (statePriority != 0) return@runSafeR statePriority + ) { + var stuckTicks = 0; private set - val eyePos = player.getPositionEyes(1f) ?: Vec3d.ZERO - val dist = (eyePos.distanceTo(other.blockPos) - eyePos.distanceTo(blockPos)).toInt() - if (dist != 0) return@runSafeR dist + fun onFailed() { + stuckTicks++ + } - -0x22 - } ?: -420 + fun onUpdate() { + stuckTicks = 0 } override fun toString(): String { - return "Block: " + block.localizedName + " @ Position: (" + blockPos.asString() + ") Priority: " + taskState.ordinal + " State: " + taskState.toString() + return "Block: ${block.localizedName} @ Position: (${blockPos.asString()}) State: ${taskState.name}" } } enum class TaskState(val color: ColorHolder) { - DONE(ColorHolder(50, 50, 50)), LIQUID_SOURCE(ColorHolder(120, 41, 240)), LIQUID_FLOW(ColorHolder(120, 41, 240)), + BROKEN(ColorHolder(111, 0, 0)), BREAKING(ColorHolder(240, 222, 60)), EMERGENCY_BREAK(ColorHolder(220, 41, 140)), BREAK(ColorHolder(222, 0, 0)), + PLACED(ColorHolder(53, 222, 66)), PLACE(ColorHolder(35, 188, 254)), - BROKEN(ColorHolder(111, 0, 0)), - PLACED(ColorHolder(53, 222, 66)) + DONE(ColorHolder(50, 50, 50)) } private enum class DebugMessages { From ba5248d4fc9dc106c968be13d92681dc51697875 Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Sun, 3 Jan 2021 15:43:35 -0500 Subject: [PATCH 190/390] Cleaned up variables --- .../kami/module/modules/misc/HighwayTools.kt | 33 ++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 403e0fcb08..6fab7c09a3 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -107,21 +107,24 @@ object HighwayTools : Module() { private var baritoneSettingAllowPlace = false private var baritoneSettingRenderGoal = false - // runtime vars - val pendingTasks = LinkedList() - private val doneTasks = ArrayList() - private val blueprint = ArrayList>() + // State + private var active = false + var pathing = false; private set private var waitTicks = 0 private var blocksPlaced = 0 - var pathing = false private var currentBlockPos = BlockPos(0, -1, 0) private var startingBlockPos = BlockPos(0, -1, 0) - private val renderer = ESPRenderer() - private var active = false + + // Rotation private var lastHitVec: Vec3d? = null private val rotateTimer = TickTimer(TimeUnit.TICKS) - // stats + // Tasks + val pendingTasks = LinkedList() + private val doneTasks = ArrayList() + private val blueprint = ArrayList>() + + // Stats private var totalBlocksPlaced = 0 private var totalBlocksDestroyed = 0 private var startTime = 0L @@ -130,6 +133,12 @@ object HighwayTools : Module() { private var materialLeft = 0 private var fillerMatLeft = 0 + private val renderer = ESPRenderer() + + override fun isActive(): Boolean { + return isEnabled && active + } + override fun onEnable() { if (mc.player == null) { disable() @@ -757,12 +766,12 @@ object HighwayTools : Module() { updateTask(blockTask, TaskState.BROKEN) waitTicks = tickDelayBreak.value defaultScope.launch { - delay(10L) + delay(20L) onMainThreadSafe { connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, blockTask.blockPos, side)) player.swingArm(EnumHand.MAIN_HAND) } - delay(40L) + delay(20L) onMainThreadSafe { connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, blockTask.blockPos, side)) player.swingArm(EnumHand.MAIN_HAND) @@ -782,7 +791,7 @@ object HighwayTools : Module() { } if (blockTask.taskState == TaskState.BREAK || blockTask.taskState == TaskState.EMERGENCY_BREAK) updateTask(blockTask, TaskState.BREAKING) defaultScope.launch { - delay(10L) + delay(20L) onMainThreadSafe { connection.sendPacket(digPacket) player.swingArm(EnumHand.MAIN_HAND) @@ -814,7 +823,7 @@ object HighwayTools : Module() { connection.sendPacket(CPacketEntityAction(player, CPacketEntityAction.Action.START_SNEAKING)) defaultScope.launch { - delay(10L) + delay(20L) onMainThreadSafe { placeBlock(pair.second, pair.first) } From 727551d2197dc40f248ef1e81579c068e664f815 Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Sun, 3 Jan 2021 16:14:43 -0500 Subject: [PATCH 191/390] Cleaned up HighwayToolsProcess --- .../kami/process/HighwayToolsProcess.kt | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/process/HighwayToolsProcess.kt b/src/main/java/me/zeroeightsix/kami/process/HighwayToolsProcess.kt index f4eea8b915..e40a1612a2 100644 --- a/src/main/java/me/zeroeightsix/kami/process/HighwayToolsProcess.kt +++ b/src/main/java/me/zeroeightsix/kami/process/HighwayToolsProcess.kt @@ -24,11 +24,10 @@ object HighwayToolsProcess : IBaritoneProcess { override fun onLostControl() {} override fun displayName0(): String { - val ht = HighwayTools - val processName = if (ht.pendingTasks.size > 0 && !ht.pathing) { - ht.pendingTasks.peek().toString() - } else if (ht.pathing) { - "Moving to Position: (${ht.getNextWalkableBlock().asString()})" + val processName = if (HighwayTools.pendingTasks.size > 0 && !HighwayTools.pathing) { + HighwayTools.pendingTasks.peek().toString() + } else if (HighwayTools.pathing) { + "Moving to Position: (${HighwayTools.getNextWalkableBlock().asString()})" } else { "Manual mode" } @@ -40,9 +39,8 @@ object HighwayToolsProcess : IBaritoneProcess { } override fun onTick(p0: Boolean, p1: Boolean): PathingCommand? { - val ht = HighwayTools - return if (ht.baritoneMode.value) { - PathingCommand(GoalNear(ht.getNextWalkableBlock(), 0), PathingCommandType.SET_GOAL_AND_PATH) + return if (HighwayTools.baritoneMode.value) { + PathingCommand(GoalNear(HighwayTools.getNextWalkableBlock(), 0), PathingCommandType.SET_GOAL_AND_PATH) } else PathingCommand(null, PathingCommandType.REQUEST_PAUSE) } } \ No newline at end of file From b1ae9779738093644d640f4fb416e5851ab8c28f Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Sun, 3 Jan 2021 17:00:34 -0500 Subject: [PATCH 192/390] Rewrote task executing --- .../kami/module/modules/misc/HighwayTools.kt | 285 +++++++++--------- 1 file changed, 146 insertions(+), 139 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 6fab7c09a3..f01f839984 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -24,7 +24,6 @@ import me.zeroeightsix.kami.util.math.RotationUtils import me.zeroeightsix.kami.util.math.VectorUtils.distanceTo import me.zeroeightsix.kami.util.math.VectorUtils.getBlockPositionsInArea import me.zeroeightsix.kami.util.math.VectorUtils.multiply -import me.zeroeightsix.kami.util.math.VectorUtils.toVec3dCenter import me.zeroeightsix.kami.util.text.MessageSendHelper.sendChatMessage import me.zeroeightsix.kami.util.threads.* import net.minecraft.block.Block @@ -69,7 +68,6 @@ object HighwayTools : Module() { // behavior settings val baritoneMode = register(Settings.booleanBuilder("AutoMode").withValue(true).withVisibility { page.value == Page.BEHAVIOR }) - private val blocksPerTick = register(Settings.integerBuilder("BlocksPerTick").withValue(1).withRange(1, 10).withStep(1).withVisibility { page.value == Page.BEHAVIOR }) private val tickDelayPlace = register(Settings.integerBuilder("TickDelayPlace").withValue(3).withRange(0, 16).withStep(1).withVisibility { page.value == Page.BEHAVIOR }) private val tickDelayBreak = register(Settings.integerBuilder("TickDelayBreak").withValue(1).withRange(0, 16).withStep(1).withVisibility { page.value == Page.BEHAVIOR }) private val interacting = register(Settings.enumBuilder(InteractMode::class.java, "InteractMode").withValue(InteractMode.SPOOF).withVisibility { page.value == Page.BEHAVIOR }) @@ -111,7 +109,6 @@ object HighwayTools : Module() { private var active = false var pathing = false; private set private var waitTicks = 0 - private var blocksPlaced = 0 private var currentBlockPos = BlockPos(0, -1, 0) private var startingBlockPos = BlockPos(0, -1, 0) @@ -123,6 +120,7 @@ object HighwayTools : Module() { val pendingTasks = LinkedList() private val doneTasks = ArrayList() private val blueprint = ArrayList>() + private var lastTask: BlockTask? = null // Stats private var totalBlocksPlaced = 0 @@ -218,6 +216,8 @@ object HighwayTools : Module() { AutoObsidian.disable() } + lastTask = null + printDisable() } @@ -233,7 +233,10 @@ object HighwayTools : Module() { updateRenderer() pendingTasks.sortWith(compareBy { - it.taskState.ordinal + it.stuckTicks + player.getPositionEyes(1f).distanceTo(it.blockPos) + it.taskState.ordinal * 10 + + player.getPositionEyes(1f).distanceTo(it.blockPos) * 5 + + it.stuckTicks * 2 + + it.ranTicks }) if (!active) { @@ -249,13 +252,7 @@ object HighwayTools : Module() { if (player.positionVector.distanceTo(taskPos) < maxReach.value) { if (!isDone()) { if (canDoTask()) { - if (!pathing) adjustPlayerPosition(false) - val currentFood = player.foodStats.foodLevel - if (currentFood != prevFood) { - if (currentFood < prevFood) foodLoss++ - prevFood = currentFood - } - doTask() + doNextTask() } } else { if (checkTasks() && !pathing) { @@ -271,7 +268,7 @@ object HighwayTools : Module() { } } else { if (currentBlockPos == player.flooredPosition) { - doTask() + doNextTask() } else { currentBlockPos = player.flooredPosition if (abs((buildDirectionSaved.ordinal - Direction.fromEntity(player).ordinal) % 8) == 4) buildDirectionSaved = Direction.fromEntity(player) @@ -279,21 +276,34 @@ object HighwayTools : Module() { } } - if (rotateTimer.tick(20L, false)) return@safeListener - val rotation = lastHitVec?.let { RotationUtils.getRotationTo(it) } ?: return@safeListener + updateFood() + doRotation() + } + } - when (interacting.value) { - InteractMode.SPOOF -> { - val packet = PlayerPacketManager.PlayerPacket(rotating = true, rotation = rotation) - PlayerPacketManager.addPacket(this@HighwayTools, packet) - } - InteractMode.VIEW_LOCK -> { - player.rotationYaw = rotation.x - player.rotationPitch = rotation.y - } - else -> { + private fun SafeClientEvent.updateFood() { + val currentFood = player.foodStats.foodLevel + if (currentFood != prevFood) { + if (currentFood < prevFood) foodLoss++ + prevFood = currentFood + } + } + + private fun SafeClientEvent.doRotation() { + if (rotateTimer.tick(20L, false)) return + val rotation = lastHitVec?.let { RotationUtils.getRotationTo(it) } ?: return + + when (interacting.value) { + InteractMode.SPOOF -> { + val packet = PlayerPacketManager.PlayerPacket(rotating = true, rotation = rotation) + PlayerPacketManager.addPacket(this@HighwayTools, packet) + } + InteractMode.VIEW_LOCK -> { + player.rotationYaw = rotation.x + player.rotationPitch = rotation.y + } + else -> { - } } } } @@ -322,66 +332,63 @@ object HighwayTools : Module() { doneTasks.add(BlockTask(blockPos, TaskState.DONE, material)) } - private fun updateTask(blockTask: BlockTask, taskState: TaskState) { - pendingTasks.poll() - blockTask.taskState = taskState - if (taskState == TaskState.DONE) { - doneTasks.add(blockTask) - } else { - pendingTasks.add(blockTask) - } - } - - private fun updateTask(blockTask: BlockTask, material: Block) { - pendingTasks.poll() - blockTask.block = material - doneTasks.add(blockTask) - blockTask.onUpdate() - } - /* Returns true if we can do a task, else returns false */ private fun canDoTask(): Boolean { return !BaritoneUtils.paused && !AutoObsidian.isActive() && !AutoEat.eating } - private fun SafeClientEvent.doTask() { - if (!isDone() && canDoTask()) { - if (waitTicks == 0) { - val blockTask = pendingTasks.peek() + private fun SafeClientEvent.doNextTask() { + if (isDone() || !canDoTask()) return + if (waitTicks > 0) { + waitTicks-- + return + } - when (blockTask.taskState) { - TaskState.DONE -> { - doDone(blockTask) - } - TaskState.BREAKING -> { - doBreaking(blockTask) - } - TaskState.BROKEN -> { - doBroken(blockTask) - } - TaskState.PLACED -> { - doPlaced(blockTask) - } - TaskState.EMERGENCY_BREAK -> { - doBreak(blockTask) - } - TaskState.BREAK -> { - doBreak(blockTask) - } - TaskState.PLACE, TaskState.LIQUID_SOURCE, TaskState.LIQUID_FLOW -> { - doPlace(blockTask) - } - } - } else { - waitTicks-- + lastTask?.let { + it.onTick() + doTask(it) + if (it.taskState != TaskState.DONE) return + } + + var currentTask: BlockTask? = pendingTasks.peek() + + while (currentTask != null) { + currentTask.onTick() + doTask(currentTask) + lastTask = currentTask + + if (currentTask.taskState != TaskState.DONE) break + + currentTask = pendingTasks.peek() + } + } + + private fun SafeClientEvent.doTask(blockTask: BlockTask) { + when (blockTask.taskState) { + TaskState.DONE -> { + doDone(blockTask) + } + TaskState.BREAKING -> { + doBreaking(blockTask) + } + TaskState.BROKEN -> { + doBroken(blockTask) + } + TaskState.PLACED -> { + doPlaced(blockTask) + } + TaskState.EMERGENCY_BREAK, TaskState.BREAK -> { + doBreak(blockTask) + } + TaskState.PLACE, TaskState.LIQUID_SOURCE, TaskState.LIQUID_FLOW -> { + doPlace(blockTask) } } } - private fun SafeClientEvent.doDone(blockTask: BlockTask) { + private fun doDone(blockTask: BlockTask) { pendingTasks.poll() doneTasks.add(blockTask) - doTask() } private fun SafeClientEvent.doBreaking(blockTask: BlockTask) { @@ -390,21 +397,20 @@ object HighwayTools : Module() { totalBlocksDestroyed++ waitTicks = tickDelayBreak.value if (blockTask.block == material || blockTask.block == fillerMat) { - updateTask(blockTask, TaskState.PLACE) + blockTask.updateState(TaskState.PLACE) } else { - updateTask(blockTask, TaskState.DONE) - doTask() + blockTask.updateState(TaskState.DONE) } } is BlockLiquid -> { var filler = fillerMat if (isInsideBuild(blockTask.blockPos) || fillerMatLeft == 0) filler = material if (world.getBlockState(blockTask.blockPos).getValue(BlockLiquid.LEVEL) != 0) { - updateTask(blockTask, TaskState.LIQUID_FLOW) - updateTask(blockTask, filler) + blockTask.updateState(TaskState.LIQUID_FLOW) + blockTask.updateMaterial(filler) } else { - updateTask(blockTask, TaskState.LIQUID_SOURCE) - updateTask(blockTask, filler) + blockTask.updateState(TaskState.LIQUID_SOURCE) + blockTask.updateMaterial(filler) } } else -> { @@ -418,67 +424,63 @@ object HighwayTools : Module() { Blocks.AIR -> { totalBlocksDestroyed++ if (blockTask.block == material || blockTask.block == fillerMat) { - updateTask(blockTask, TaskState.PLACE) + blockTask.updateState(TaskState.PLACE) } else { - updateTask(blockTask, TaskState.DONE) + blockTask.updateState(TaskState.DONE) } } else -> { - updateTask(blockTask, TaskState.BREAK) + blockTask.updateState(TaskState.BREAK) } } - doTask() } private fun SafeClientEvent.doPlaced(blockTask: BlockTask) { val block = world.getBlockState(blockTask.blockPos).block when { - blockTask.block == block && block != Blocks.AIR -> updateTask(blockTask, TaskState.DONE) - blockTask.block == Blocks.AIR && block != Blocks.AIR -> updateTask(blockTask, TaskState.BREAK) - blockTask.block == block && block == Blocks.AIR -> updateTask(blockTask, TaskState.BREAK) - else -> updateTask(blockTask, TaskState.PLACE) + blockTask.block == block && block != Blocks.AIR -> blockTask.updateState(TaskState.DONE) + blockTask.block == Blocks.AIR && block != Blocks.AIR -> blockTask.updateState(TaskState.BREAK) + blockTask.block == block && block == Blocks.AIR -> blockTask.updateState(TaskState.BREAK) + else -> blockTask.updateState(TaskState.PLACE) } - doTask() } - private fun SafeClientEvent.doBreak(blockTask: BlockTask): Boolean { + private fun SafeClientEvent.doBreak(blockTask: BlockTask) { // ignore blocks - if (blockTask.taskState != TaskState.EMERGENCY_BREAK) { - if (blockTask.block != Blocks.AIR && ignoreBlocks.contains(blockTask.block)) { - updateTask(blockTask, TaskState.DONE) - doTask() - } + if (blockTask.taskState != TaskState.EMERGENCY_BREAK + && blockTask.block != Blocks.AIR + && ignoreBlocks.contains(blockTask.block)) { + blockTask.updateState(TaskState.DONE) } // last check before breaking when (world.getBlockState(blockTask.blockPos).block) { Blocks.AIR -> { if (blockTask.block == Blocks.AIR) { - updateTask(blockTask, TaskState.DONE) + blockTask.updateState(TaskState.DONE) } else { - updateTask(blockTask, TaskState.PLACE) + blockTask.updateState(TaskState.PLACE) } - doTask() } is BlockLiquid -> { var filler = fillerMat if (isInsideBuild(blockTask.blockPos) || fillerMatLeft == 0) filler = material if (world.getBlockState(blockTask.blockPos).getValue(BlockLiquid.LEVEL) != 0) { - updateTask(blockTask, TaskState.LIQUID_FLOW) - updateTask(blockTask, filler) + blockTask.updateState(TaskState.LIQUID_FLOW) + blockTask.updateMaterial(filler) } else { - updateTask(blockTask, TaskState.LIQUID_SOURCE) - updateTask(blockTask, filler) + blockTask.updateState(TaskState.LIQUID_SOURCE) + blockTask.updateMaterial(filler) } } else -> { // liquid search around the breaking block if (blockTask.taskState != TaskState.EMERGENCY_BREAK) { if (handleLiquid(blockTask)) { - updateTask(blockTask, TaskState.EMERGENCY_BREAK) - return true + blockTask.updateState(TaskState.EMERGENCY_BREAK) + return } } @@ -487,7 +489,6 @@ object HighwayTools : Module() { mineBlock(blockTask) } } - return true } private fun SafeClientEvent.doPlace(blockTask: BlockTask) { @@ -495,10 +496,10 @@ object HighwayTools : Module() { when { block == material && block == blockTask.block -> { - updateTask(blockTask, TaskState.PLACED) + blockTask.updateState(TaskState.PLACED) } block == fillerMat && block == blockTask.block -> { - updateTask(blockTask, TaskState.PLACED) + blockTask.updateState(TaskState.PLACED) } else -> { if (!WorldUtils.isPlaceable(blockTask.blockPos)) { @@ -512,16 +513,10 @@ object HighwayTools : Module() { placeBlock(blockTask) if (blockTask.taskState != TaskState.PLACE && isInsideSelection(blockTask.blockPos)) { - updateTask(blockTask, Blocks.AIR) + blockTask.updateMaterial(Blocks.AIR) } - updateTask(blockTask, TaskState.PLACED) - if (blocksPerTick.value > blocksPlaced + 1) { - blocksPlaced++ - doTask() - } else { - blocksPlaced = 0 - } + blockTask.updateState(TaskState.PLACED) waitTicks = tickDelayPlace.value totalBlocksPlaced++ @@ -725,8 +720,8 @@ object HighwayTools : Module() { } } else { for (triple in found) { - updateTask(triple.first, triple.second) - updateTask(triple.first, triple.third) + blockTask.updateState(triple.second) + blockTask.updateMaterial(triple.third) } } } @@ -736,7 +731,7 @@ object HighwayTools : Module() { private fun SafeClientEvent.mineBlock(blockTask: BlockTask) { if (blockTask.blockPos == player.flooredPosition.down()) { - updateTask(blockTask, TaskState.DONE) + blockTask.updateState(TaskState.DONE) return } @@ -746,7 +741,7 @@ object HighwayTools : Module() { val blockBelowFire = blockTask.blockPos.down() playerController.clickBlock(blockBelowFire, EnumFacing.UP) player.swingArm(EnumHand.MAIN_HAND) - updateTask(blockTask, TaskState.BREAKING) + blockTask.updateState(TaskState.BREAKING) return } @@ -763,7 +758,6 @@ object HighwayTools : Module() { when (world.getBlockState(blockTask.blockPos).block) { Blocks.NETHERRACK -> { - updateTask(blockTask, TaskState.BROKEN) waitTicks = tickDelayBreak.value defaultScope.launch { delay(20L) @@ -775,6 +769,7 @@ object HighwayTools : Module() { onMainThreadSafe { connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, blockTask.blockPos, side)) player.swingArm(EnumHand.MAIN_HAND) + blockTask.updateState(TaskState.BROKEN) } } } @@ -784,16 +779,20 @@ object HighwayTools : Module() { /* Dispatches a thread to mine any non-netherrack blocks generically */ private fun dispatchGenericMineThread(blockTask: BlockTask, facing: EnumFacing) { - val digPacket = when (blockTask.taskState) { - TaskState.BREAK, TaskState.EMERGENCY_BREAK -> CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, blockTask.blockPos, facing) - TaskState.BREAKING -> CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, blockTask.blockPos, facing) - else -> CPacketPlayerDigging() + val action = if (blockTask.taskState == TaskState.BREAKING) { + CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK + } else { + CPacketPlayerDigging.Action.START_DESTROY_BLOCK + } + + if (blockTask.taskState == TaskState.BREAK || blockTask.taskState == TaskState.EMERGENCY_BREAK) { + blockTask.updateState(TaskState.BREAKING) } - if (blockTask.taskState == TaskState.BREAK || blockTask.taskState == TaskState.EMERGENCY_BREAK) updateTask(blockTask, TaskState.BREAKING) + defaultScope.launch { delay(20L) onMainThreadSafe { - connection.sendPacket(digPacket) + connection.sendPacket(CPacketPlayerDigging(action, blockTask.blockPos, facing)) player.swingArm(EnumHand.MAIN_HAND) } } @@ -858,16 +857,6 @@ object HighwayTools : Module() { return pendingTasks.any { it.blockPos == blockPos && it.block == material } } - private fun SafeClientEvent.adjustPlayerPosition(bridge: Boolean) { - var vec = getNextWalkableBlock().toVec3dCenter().subtract(player.positionVector) - when { - bridge && !buildDirectionSaved.isDiagonal -> vec = vec.add(Vec3d(buildDirectionSaved.directionVec).scale(0.525)) - bridge && buildDirectionSaved.isDiagonal -> vec = vec.add(Vec3d(buildDirectionSaved.directionVec).scale(0.525)) - } - player.motionX = (vec.x / 2.0).coerceIn(-0.2, 0.2) - player.motionZ = (vec.z / 2.0).coerceIn(-0.2, 0.2) - } - fun printSettings() { StringBuilder(ignoreBlocks.size + 1).run { append("$chatName Settings" + @@ -1112,14 +1101,32 @@ object HighwayTools : Module() { var taskState: TaskState, var block: Block ) { + var ranTicks = 0; private set var stuckTicks = 0; private set + fun updateState(state: TaskState) { + taskState = state + onUpdate() + } + + fun updateMaterial(material: Block) { + block = material + onUpdate() + } + + fun onTick() { + ranTicks++ + } + fun onFailed() { stuckTicks++ } fun onUpdate() { - stuckTicks = 0 + if (taskState == TaskState.DONE) { + stuckTicks = 0 + ranTicks = 0 + } } override fun toString(): String { @@ -1128,6 +1135,7 @@ object HighwayTools : Module() { } enum class TaskState(val color: ColorHolder) { + DONE(ColorHolder(50, 50, 50)), LIQUID_SOURCE(ColorHolder(120, 41, 240)), LIQUID_FLOW(ColorHolder(120, 41, 240)), BROKEN(ColorHolder(111, 0, 0)), @@ -1135,8 +1143,7 @@ object HighwayTools : Module() { EMERGENCY_BREAK(ColorHolder(220, 41, 140)), BREAK(ColorHolder(222, 0, 0)), PLACED(ColorHolder(53, 222, 66)), - PLACE(ColorHolder(35, 188, 254)), - DONE(ColorHolder(50, 50, 50)) + PLACE(ColorHolder(35, 188, 254)) } private enum class DebugMessages { From 00e1a659d001cabbbdf112259091281373eb4a47 Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Sun, 3 Jan 2021 19:12:26 -0500 Subject: [PATCH 193/390] Rewrote blue print generating --- .../kami/module/modules/misc/HighwayTools.kt | 423 ++++++++---------- .../kami/process/HighwayToolsProcess.kt | 7 +- .../zeroeightsix/kami/util/math/Direction.kt | 4 + 3 files changed, 199 insertions(+), 235 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index f01f839984..0fc1e7dc21 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -22,7 +22,6 @@ import me.zeroeightsix.kami.util.math.CoordinateConverter.asString import me.zeroeightsix.kami.util.math.Direction import me.zeroeightsix.kami.util.math.RotationUtils import me.zeroeightsix.kami.util.math.VectorUtils.distanceTo -import me.zeroeightsix.kami.util.math.VectorUtils.getBlockPositionsInArea import me.zeroeightsix.kami.util.math.VectorUtils.multiply import me.zeroeightsix.kami.util.text.MessageSendHelper.sendChatMessage import me.zeroeightsix.kami.util.threads.* @@ -41,6 +40,7 @@ import net.minecraft.util.math.RayTraceResult import net.minecraft.util.math.Vec3d import java.util.* import kotlin.collections.ArrayList +import kotlin.collections.LinkedHashMap import kotlin.math.abs /** @@ -63,7 +63,7 @@ object HighwayTools : Module() { private val clearHeight = register(Settings.integerBuilder("Height").withValue(4).withRange(1, 6).withStep(1).withVisibility { page.value == Page.BUILD && clearSpace.value }) private val buildWidth = register(Settings.integerBuilder("Width").withValue(5).withRange(1, 9).withStep(1).withVisibility { page.value == Page.BUILD }) private val railing = register(Settings.booleanBuilder("Railing").withValue(true).withVisibility { page.value == Page.BUILD && mode.value == Mode.HIGHWAY }) - private val railingHeight = register(Settings.integerBuilder("RailingHeight").withValue(1).withRange(0, 4).withStep(1).withMaximum(clearHeight.value).withVisibility { railing.value && page.value == Page.BUILD && mode.value == Mode.HIGHWAY }) + private val railingHeight = register(Settings.integerBuilder("RailingHeight").withValue(1).withRange(1, 4).withStep(1).withVisibility { railing.value && page.value == Page.BUILD && mode.value == Mode.HIGHWAY }) private val cornerBlock = register(Settings.booleanBuilder("CornerBlock").withValue(false).withVisibility { page.value == Page.BUILD && (mode.value == Mode.HIGHWAY || mode.value == Mode.TUNNEL) }) // behavior settings @@ -101,26 +101,29 @@ object HighwayTools : Module() { var fillerMat: Block = Blocks.NETHERRACK private var playerHotbarSlot = -1 private var lastHotbarSlot = -1 - private var buildDirectionSaved = Direction.NORTH private var baritoneSettingAllowPlace = false private var baritoneSettingRenderGoal = false + // Blue print + private var startingDirection = Direction.NORTH + private var currentBlockPos = BlockPos(0, -1, 0) + private var startingBlockPos = BlockPos(0, -1, 0) + private val blueprint = ArrayList>() + private val blueprintNew = LinkedHashMap() + // State private var active = false var pathing = false; private set private var waitTicks = 0 - private var currentBlockPos = BlockPos(0, -1, 0) - private var startingBlockPos = BlockPos(0, -1, 0) // Rotation private var lastHitVec: Vec3d? = null private val rotateTimer = TickTimer(TimeUnit.TICKS) // Tasks - val pendingTasks = LinkedList() + private val pendingTasks = LinkedList() private val doneTasks = ArrayList() - private val blueprint = ArrayList>() - private var lastTask: BlockTask? = null + var lastTask: BlockTask? = null; private set // Stats private var totalBlocksPlaced = 0 @@ -164,7 +167,7 @@ object HighwayTools : Module() { currentBlockPos = startingBlockPos playerHotbarSlot = mc.player.inventory.currentItem lastHotbarSlot = -1 - buildDirectionSaved = Direction.fromEntity(mc.player) + startingDirection = Direction.fromEntity(mc.player) startTime = System.currentTimeMillis() totalBlocksPlaced = 0 totalBlocksDestroyed = 0 @@ -234,7 +237,7 @@ object HighwayTools : Module() { updateRenderer() pendingTasks.sortWith(compareBy { it.taskState.ordinal * 10 + - player.getPositionEyes(1f).distanceTo(it.blockPos) * 5 + + player.getPositionEyes(1f).distanceTo(it.blockPos) * 8 + it.stuckTicks * 2 + it.ranTicks }) @@ -271,7 +274,7 @@ object HighwayTools : Module() { doNextTask() } else { currentBlockPos = player.flooredPosition - if (abs((buildDirectionSaved.ordinal - Direction.fromEntity(player).ordinal) % 8) == 4) buildDirectionSaved = Direction.fromEntity(player) + if (abs((startingDirection.ordinal - Direction.fromEntity(player).ordinal) % 8) == 4) startingDirection = Direction.fromEntity(player) refreshData() } } @@ -312,8 +315,8 @@ object HighwayTools : Module() { renderer.clear() renderer.aFilled = if (filled.value) aFilled.value else 0 renderer.aOutline = if (outline.value) aOutline.value else 0 -// renderer.add(currentBlockPos, ColorHolder(255, 255, 255)) -// renderer.add(getNextWalkableBlock(), ColorHolder(0, 0, 0)) + renderer.through = false + for (blockTask in pendingTasks) { if (blockTask.taskState == TaskState.DONE) continue renderer.add(world.getBlockState(blockTask.blockPos).getSelectedBoundingBox(world, blockTask.blockPos), blockTask.taskState.color) @@ -324,6 +327,169 @@ object HighwayTools : Module() { } } + private fun SafeClientEvent.refreshData() { + doneTasks.clear() + pendingTasks.clear() + lastTask = null + updateTasks(currentBlockPos) + } + + private fun SafeClientEvent.updateTasks(originPos: BlockPos) { + blueprintNew.clear() + generateBluePrint(originPos) + + for ((pos, block) in blueprintNew) { + if (block == Blocks.AIR) { + addTaskClear(pos) + } else { + addTaskBuild(pos, block) + } + } + } + + private fun SafeClientEvent.addTaskBuild(pos: BlockPos, block: Block) { + val blockState = world.getBlockState(pos) + + when { + blockState.block == block -> { + addTaskToDone(pos, block) + } + blockState.material.isReplaceable -> { + addTaskToPending(pos, TaskState.PLACE, block) + } + else -> { + addTaskToPending(pos, TaskState.BREAK, block) + } + } + } + + private fun SafeClientEvent.addTaskClear(pos: BlockPos) { + if (world.isAirBlock(pos)) { + addTaskToDone(pos, Blocks.AIR) + } else { + addTaskToPending(pos, TaskState.BREAK, Blocks.AIR) + } + } + + private fun generateBluePrint(feetPos: BlockPos) { + val basePos = feetPos.down() + + if (mode.value != Mode.FLAT) { + val zDirection = startingDirection + val xDirection = zDirection.clockwise(2) + val nextPos = basePos.add(zDirection.directionVec) + + generateClear(basePos, xDirection) + generateClear(nextPos, xDirection) + + generateBase(basePos, xDirection) + generateBase(nextPos, xDirection) + } else { + generateFlat(basePos) + } + } + + private fun generateClear(basePos: BlockPos, xDirection: Direction) { + if (!clearSpace.value) return + + for (w in 0 until buildWidth.value) { + for (h in 0 until clearHeight.value) { + val x = w - buildWidth.value / 2 + val pos = basePos.add(xDirection.directionVec.multiply(x)).up(h) + + if (mode.value == Mode.HIGHWAY && h == 0 && isRail(w)) { + continue + } + + blueprintNew[pos] = Blocks.AIR + } + } + } + + private fun generateBase(basePos: BlockPos, xDirection: Direction) { + val baseMaterial = if (mode.value == Mode.TUNNEL) fillerMat else material + + for (w in 0 until buildWidth.value) { + val x = w - buildWidth.value / 2 + val pos = basePos.add(xDirection.directionVec.multiply(x)) + + if (mode.value == Mode.HIGHWAY) { + if (isRail(w)) { + for (y in 1..railingHeight.value) { + blueprintNew[pos.up(y)] = baseMaterial + } + } else { + blueprintNew[pos] = baseMaterial + } + } else { + blueprintNew[pos.down()] = baseMaterial + } + } + } + + private fun isRail(w: Int) = railing.value && w !in 1 until buildWidth.value - 1 + + private fun generateFlat(basePos: BlockPos) { + // Base + for (x in -buildWidth.value..buildWidth.value) { + for (z in -buildWidth.value..buildWidth.value) { + val pos = basePos.add(x, 0, z) + + blueprintNew[pos] = material + } + } + + // Clear + if (!clearSpace.value) return + for (x in -buildWidth.value..buildWidth.value) { + for (z in -buildWidth.value..buildWidth.value) { + for (y in 1 until clearHeight.value) { + val pos = basePos.add(x, y, z) + blueprintNew[pos] = Blocks.AIR + } + } + } + } + + fun getNextWalkableBlock(): BlockPos { + var lastWalkable = getNextBlock() + + when (mode.value) { + Mode.HIGHWAY -> { + for (step in 1..3) { + val pos = relativeDirection(currentBlockPos, step, 0) + if (mc.world.getBlockState(pos.down()).block == material && + mc.world.getBlockState(pos).block == Blocks.AIR && + mc.world.getBlockState(pos.up()).block == Blocks.AIR) lastWalkable = pos + else break + } + } + Mode.TUNNEL -> { + for (step in 1..3) { + val pos = relativeDirection(currentBlockPos, step, 0) + if (mc.world.getBlockState(pos.down()).block == fillerMat && + mc.world.getBlockState(pos).block == Blocks.AIR && + mc.world.getBlockState(pos.up()).block == Blocks.AIR) lastWalkable = pos + else break + } + } + else -> { + } + } + + return lastWalkable + } + + private fun getNextBlock(blockPos: BlockPos = currentBlockPos): BlockPos { + return relativeDirection(blockPos, 1, 0) + } + + private fun relativeDirection(current: BlockPos, steps: Int, turn: Int): BlockPos { + val index = startingDirection.ordinal + turn + val direction = Direction.values()[Math.floorMod(index, 8)] + return current.add(direction.directionVec.multiply(steps)) + } + private fun addTaskToPending(blockPos: BlockPos, taskState: TaskState, material: Block) { pendingTasks.add(BlockTask(blockPos, taskState, material)) } @@ -347,7 +513,11 @@ object HighwayTools : Module() { lastTask?.let { it.onTick() doTask(it) - if (it.taskState != TaskState.DONE) return + + if (it.taskState != TaskState.DONE) { + if (it.stuckTicks > 20) refreshData() + return + } } var currentTask: BlockTask? = pendingTasks.peek() @@ -528,134 +698,15 @@ object HighwayTools : Module() { for (blockTask in doneTasks) { val block = world.getBlockState(blockTask.blockPos).block if (ignoreBlocks.contains(block)) continue + when { blockTask.block == material && block != material -> return false mode.value == Mode.TUNNEL && blockTask.block == fillerMat && block != fillerMat -> return false blockTask.block == Blocks.AIR && block != Blocks.AIR -> return false } - } - return true - } - - private fun SafeClientEvent.updateTasks(originPos: BlockPos) { - blueprint.clear() - updateBlockArray(originPos) - updateBlockArray(getNextBlock(originPos)) - for ((blockPos, blockType) in blueprint) { - val isReplaceable = world.getBlockState(blockPos).material.isReplaceable - if (blockPos == player.flooredPosition.down()) continue - when (val block = world.getBlockState(blockPos).block) { - is BlockLiquid -> { - var filler = fillerMat - if (isInsideBuild(blockPos) || fillerMatLeft == 0) filler = material - when (world.getBlockState(blockPos).getValue(BlockLiquid.LEVEL) != 0) { - true -> addTaskToPending(blockPos, TaskState.LIQUID_FLOW, filler) - false -> addTaskToPending(blockPos, TaskState.LIQUID_SOURCE, filler) - } - } - else -> { - when (blockType) { - Blocks.AIR -> { - when { - block in ignoreBlocks -> addTaskToDone(blockPos, Blocks.AIR) - block == Blocks.AIR -> addTaskToDone(blockPos, Blocks.AIR) - block == Blocks.FIRE -> addTaskToPending(blockPos, TaskState.BREAK, Blocks.FIRE) - block != Blocks.AIR -> addTaskToPending(blockPos, TaskState.BREAK, Blocks.AIR) - } - } - material -> { - when { - block == material -> addTaskToDone(blockPos, material) - !isReplaceable && block != material -> addTaskToPending(blockPos, TaskState.BREAK, material) - isReplaceable -> addTaskToPending(blockPos, TaskState.PLACE, material) - } - } - fillerMat -> { - if (mode.value == Mode.HIGHWAY) { - if (buildDirectionSaved.isDiagonal) { - val blockUp = world.getBlockState(blockPos.up()).block - when { - WorldUtils.getNeighbour(blockPos.up(), 1) == null && blockUp != material -> addTaskToPending(blockPos, TaskState.PLACE, fillerMat) - WorldUtils.getNeighbour(blockPos.up(), 1) != null -> addTaskToDone(blockPos, fillerMat) - } - } - } else { - when { - block == fillerMat -> addTaskToDone(blockPos, fillerMat) - !isReplaceable && block != fillerMat -> addTaskToPending(blockPos, TaskState.BREAK, fillerMat) - isReplaceable -> addTaskToPending(blockPos, TaskState.PLACE, fillerMat) - } - } - } - } - } - } - } - } - private fun updateBlockArray(blockPos: BlockPos) { - var cursor = blockPos.down() - - when (mode.value) { - Mode.HIGHWAY, Mode.TUNNEL -> { - var mat = material - if (mode.value == Mode.TUNNEL) mat = fillerMat - if (baritoneMode.value) { - cursor = relativeDirection(cursor, 1, 0) - blueprint.add(Pair(cursor, mat)) - } - cursor = relativeDirection(cursor, 1, 0) - blueprint.add(Pair(cursor, mat)) - var buildIterationsWidth = buildWidth.value / 2 - var evenCursor = relativeDirection(cursor, 1, 2) - var isOdd = false - if (buildWidth.value % 2 == 1) { - isOdd = true - buildIterationsWidth++ - } else { - blueprint.add(Pair(evenCursor, mat)) - } - if (mode.value == Mode.TUNNEL) cursor = cursor.up() - for (i in 1 until clearHeight.value + 1) { - for (j in 1 until buildIterationsWidth) { - if (i == 1) { - if (j == buildIterationsWidth - 1 && !cornerBlock.value) { - genOffset(cursor, i, j, fillerMat, isOdd) - } else { - genOffset(cursor, i, j, mat, isOdd) - } - } else { - if (i <= railingHeight.value + 1 && j == buildIterationsWidth - 1) { - genOffset(cursor, i, j, mat, isOdd) - } else { - if (clearSpace.value) { - genOffset(cursor, i, j, Blocks.AIR, isOdd) - } - } - } - } - if (mode.value == Mode.TUNNEL) { - if (i == 1) blueprint.add(Pair(cursor, Blocks.AIR)) - if (i == clearHeight.value) blueprint.add(Pair(evenCursor.up(), Blocks.AIR)) - } - cursor = cursor.up() - evenCursor = evenCursor.up() - if (clearSpace.value && i < clearHeight.value) { - blueprint.add(Pair(cursor, Blocks.AIR)) - if (!isOdd) blueprint.add(Pair(evenCursor, Blocks.AIR)) - } - } - } - Mode.FLAT -> { - for (bp in getBlockPositionsInArea(cursor.north(buildWidth.value).west(buildWidth.value), cursor.south(buildWidth.value).east(buildWidth.value))) { - blueprint.add(Pair(bp, material)) - } - } - null -> { - sendChatMessage("Module logic is a lie.") - disable() - } } + return true } private fun SafeClientEvent.inventoryProcessor(blockTask: BlockTask) { @@ -874,12 +925,12 @@ object HighwayTools : Module() { if (info.value) { StringBuilder(2).run { append("$chatName Module started." + - "\n §9> §7Direction: §a${buildDirectionSaved.displayName}§r") + "\n §9> §7Direction: §a${startingDirection.displayName}§r") - if (buildDirectionSaved.isDiagonal) { + if (startingDirection.isDiagonal) { append("\n §9> §7Coordinates: §a${startingBlockPos.x} ${startingBlockPos.z}§r") } else { - if (buildDirectionSaved == Direction.NORTH || buildDirectionSaved == Direction.SOUTH) { + if (startingDirection == Direction.NORTH || startingDirection == Direction.SOUTH) { append("\n §9> §7Coordinate: §a${startingBlockPos.x}§r") } else { append("\n §9> §7Coordinate: §a${startingBlockPos.z}§r") @@ -957,7 +1008,7 @@ object HighwayTools : Module() { " §7One food loss per §9${totalBlocksDestroyed / foodLoss}§7 blocks mined", "§rEnvironment", " §7Starting coordinates: §9(${startingBlockPos.asString()})", - " §7Direction: §9${buildDirectionSaved.displayName}", + " §7Direction: §9${startingDirection.displayName}", " §7Blocks destroyed: §9$totalBlocksDestroyed".padStart(6, '0'), " §7Blocks placed: §9$totalBlocksPlaced".padStart(6, '0'), " §7Material: §9${material.localizedName}", @@ -996,106 +1047,12 @@ object HighwayTools : Module() { private fun addTaskToMessageList(list: ArrayList, tasks: Collection) { for (blockTask in tasks) list.add(" " + blockTask.block.localizedName + "@(" + blockTask.blockPos.asString() + ") Priority: " + blockTask.taskState.ordinal + " State: " + blockTask.taskState.toString()) } - - fun getNextWalkableBlock(): BlockPos { - var lastWalkable = getNextBlock() - - when (mode.value) { - Mode.HIGHWAY -> { - for (step in 1..3) { - val pos = relativeDirection(currentBlockPos, step, 0) - if (mc.world.getBlockState(pos.down()).block == material && - mc.world.getBlockState(pos).block == Blocks.AIR && - mc.world.getBlockState(pos.up()).block == Blocks.AIR) lastWalkable = pos - else break - } - } - Mode.TUNNEL -> { - for (step in 1..3) { - val pos = relativeDirection(currentBlockPos, step, 0) - if (mc.world.getBlockState(pos.down()).block == fillerMat && - mc.world.getBlockState(pos).block == Blocks.AIR && - mc.world.getBlockState(pos.up()).block == Blocks.AIR) lastWalkable = pos - else break - } - } - else -> { - } - } - - return lastWalkable - } - - private fun getNextBlock(blockPos: BlockPos = currentBlockPos): BlockPos { - return relativeDirection(blockPos, 1, 0) - } - - private fun relativeDirection(current: BlockPos, steps: Int, turn: Int): BlockPos { - val index = buildDirectionSaved.ordinal + turn - val direction = Direction.values()[Math.floorMod(index, 8)] - return current.add(direction.directionVec.multiply(steps)) - } - - private fun addOffset(cursor: BlockPos, height: Int, width: Int, mat: Block, turn: Boolean) { - var turnValue = 1 - if (turn) turnValue = -1 - if (mat != fillerMat) { - if (height > 1) { - blueprint.add(Pair(relativeDirection(relativeDirection(cursor, 1, 3 * turnValue), width - 1, 2 * turnValue), Blocks.AIR)) - } else { - blueprint.add(Pair(relativeDirection(relativeDirection(cursor, 1, 3 * turnValue), width - 1, 2 * turnValue), mat)) - } - } else { - blueprint.add(Pair(relativeDirection(relativeDirection(cursor, 1, 3 * turnValue), width - 1, 2 * turnValue), material)) - } - } - - private fun genOffset(cursor: BlockPos, height: Int, width: Int, mat: Block, isOdd: Boolean) { - var matUse = mat - if (mode.value == Mode.TUNNEL) matUse = Blocks.AIR - blueprint.add(Pair(relativeDirection(cursor, width, -2), matUse)) - if (buildDirectionSaved.isDiagonal) { - addOffset(cursor, height, width, matUse, true) - } - when { - isOdd -> { - blueprint.add(Pair(relativeDirection(cursor, width, 2), matUse)) - if (buildDirectionSaved.isDiagonal) { - addOffset(cursor, height, width, matUse, false) - } - } - else -> { - val evenCursor = relativeDirection(cursor, 1, 2) - if (buildDirectionSaved.isDiagonal) { - blueprint.add(Pair(relativeDirection(evenCursor, width, 2), matUse)) - addOffset(cursor, height, width, matUse, false) - addOffset(evenCursor, height, width, matUse, false) - } else { - blueprint.add(Pair(relativeDirection(evenCursor, width, 2), matUse)) - } - } - } - } - object StuckManager { override fun toString(): String { return " " } } - private fun SafeClientEvent.refreshData() { - doneTasks.clear() - pendingTasks.clear() - updateTasks(currentBlockPos) - shuffleTasks() - } - - private fun shuffleTasks() { - val shuffled = pendingTasks.shuffled() - pendingTasks.clear() - pendingTasks.addAll(shuffled) - } - class BlockTask( val blockPos: BlockPos, var taskState: TaskState, diff --git a/src/main/java/me/zeroeightsix/kami/process/HighwayToolsProcess.kt b/src/main/java/me/zeroeightsix/kami/process/HighwayToolsProcess.kt index e40a1612a2..71d1b643ed 100644 --- a/src/main/java/me/zeroeightsix/kami/process/HighwayToolsProcess.kt +++ b/src/main/java/me/zeroeightsix/kami/process/HighwayToolsProcess.kt @@ -24,13 +24,16 @@ object HighwayToolsProcess : IBaritoneProcess { override fun onLostControl() {} override fun displayName0(): String { - val processName = if (HighwayTools.pendingTasks.size > 0 && !HighwayTools.pathing) { - HighwayTools.pendingTasks.peek().toString() + val lastTask = HighwayTools.lastTask + + val processName = if (lastTask != null && !HighwayTools.pathing) { + lastTask.toString() } else if (HighwayTools.pathing) { "Moving to Position: (${HighwayTools.getNextWalkableBlock().asString()})" } else { "Manual mode" } + return "HighwayTools: $processName" } diff --git a/src/main/java/me/zeroeightsix/kami/util/math/Direction.kt b/src/main/java/me/zeroeightsix/kami/util/math/Direction.kt index 3dfeb55128..a9b0bc557f 100644 --- a/src/main/java/me/zeroeightsix/kami/util/math/Direction.kt +++ b/src/main/java/me/zeroeightsix/kami/util/math/Direction.kt @@ -19,6 +19,10 @@ enum class Direction(val displayName: String, val displayNameXY: String, val dir WEST("West", "-X", Vec3i(-1, 0, 0), false), NORTH_WEST("North West", "-X -Z", Vec3i(-1, 0, -1), true); + fun clockwise(n: Int = 1) = values()[Math.floorMod((ordinal + n), 8)] + + fun counterClockwise(n: Int = 1) = values()[Math.floorMod((ordinal - n), 8)] + companion object { @JvmStatic From e3fe96cda6704086a37ad233a837fa8d50f9824b Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Sun, 3 Jan 2021 21:09:04 -0500 Subject: [PATCH 194/390] Rewrote pathing --- .../kami/module/modules/misc/HighwayTools.kt | 235 +++++++----------- .../kami/process/HighwayToolsProcess.kt | 19 +- 2 files changed, 99 insertions(+), 155 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 0fc1e7dc21..7151e53958 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -1,5 +1,6 @@ package me.zeroeightsix.kami.module.modules.misc +import baritone.api.pathing.goals.GoalNear import kotlinx.coroutines.delay import kotlinx.coroutines.launch import me.zeroeightsix.kami.event.Phase @@ -41,7 +42,6 @@ import net.minecraft.util.math.Vec3d import java.util.* import kotlin.collections.ArrayList import kotlin.collections.LinkedHashMap -import kotlin.math.abs /** * @author Avanatiker @@ -67,7 +67,6 @@ object HighwayTools : Module() { private val cornerBlock = register(Settings.booleanBuilder("CornerBlock").withValue(false).withVisibility { page.value == Page.BUILD && (mode.value == Mode.HIGHWAY || mode.value == Mode.TUNNEL) }) // behavior settings - val baritoneMode = register(Settings.booleanBuilder("AutoMode").withValue(true).withVisibility { page.value == Page.BEHAVIOR }) private val tickDelayPlace = register(Settings.integerBuilder("TickDelayPlace").withValue(3).withRange(0, 16).withStep(1).withVisibility { page.value == Page.BEHAVIOR }) private val tickDelayBreak = register(Settings.integerBuilder("TickDelayBreak").withValue(1).withRange(0, 16).withStep(1).withVisibility { page.value == Page.BEHAVIOR }) private val interacting = register(Settings.enumBuilder(InteractMode::class.java, "InteractMode").withValue(InteractMode.SPOOF).withVisibility { page.value == Page.BEHAVIOR }) @@ -99,8 +98,6 @@ object HighwayTools : Module() { ) var material: Block = Blocks.OBSIDIAN var fillerMat: Block = Blocks.NETHERRACK - private var playerHotbarSlot = -1 - private var lastHotbarSlot = -1 private var baritoneSettingAllowPlace = false private var baritoneSettingRenderGoal = false @@ -113,13 +110,15 @@ object HighwayTools : Module() { // State private var active = false - var pathing = false; private set private var waitTicks = 0 // Rotation private var lastHitVec: Vec3d? = null private val rotateTimer = TickTimer(TimeUnit.TICKS) + // Pathing + var goal: GoalNear? = null; private set + // Tasks private val pendingTasks = LinkedList() private val doneTasks = ArrayList() @@ -165,25 +164,20 @@ object HighwayTools : Module() { startingBlockPos = mc.player.flooredPosition currentBlockPos = startingBlockPos - playerHotbarSlot = mc.player.inventory.currentItem - lastHotbarSlot = -1 startingDirection = Direction.fromEntity(mc.player) + startTime = System.currentTimeMillis() totalBlocksPlaced = 0 totalBlocksDestroyed = 0 - if (baritoneMode.value) { - baritoneSettingAllowPlace = BaritoneUtils.settings?.allowPlace?.value ?: true - BaritoneUtils.settings?.allowPlace?.value = false + baritoneSettingAllowPlace = BaritoneUtils.settings?.allowPlace?.value ?: true + BaritoneUtils.settings?.allowPlace?.value = false - if (!goalRender.value) { - baritoneSettingRenderGoal = BaritoneUtils.settings?.renderGoal?.value ?: true - BaritoneUtils.settings?.renderGoal?.value = false - } + if (!goalRender.value) { + baritoneSettingRenderGoal = BaritoneUtils.settings?.renderGoal?.value ?: true + BaritoneUtils.settings?.renderGoal?.value = false } - playerHotbarSlot = mc.player.inventory.currentItem - runSafe { refreshData() printEnable() @@ -195,21 +189,8 @@ object HighwayTools : Module() { active = false - // load initial player hand - if (lastHotbarSlot != playerHotbarSlot && playerHotbarSlot != -1) { - mc.player.inventory.currentItem = playerHotbarSlot - } - playerHotbarSlot = -1 - lastHotbarSlot = -1 - - if (baritoneMode.value) { - BaritoneUtils.settings?.allowPlace?.value = baritoneSettingAllowPlace - if (!goalRender.value) BaritoneUtils.settings?.renderGoal?.value = baritoneSettingRenderGoal - val process = BaritoneUtils.primary?.pathingControlManager?.mostRecentInControl() - - if (process != null && process.isPresent && process.get() == HighwayToolsProcess) process.get().onLostControl() - } - + BaritoneUtils.settings?.allowPlace?.value = baritoneSettingAllowPlace + if (!goalRender.value) BaritoneUtils.settings?.renderGoal?.value = baritoneSettingRenderGoal /* Turn off inventory manager if the users wants us to control it */ if (toggleInventoryManager.value && InventoryManager.isEnabled) InventoryManager.disable() @@ -224,8 +205,6 @@ object HighwayTools : Module() { printDisable() } - fun isDone(): Boolean = pendingTasks.size == 0 - init { safeListener { renderer.render(false) @@ -234,56 +213,37 @@ object HighwayTools : Module() { safeListener { event -> if (event.phase != Phase.PRE) return@safeListener - updateRenderer() - pendingTasks.sortWith(compareBy { - it.taskState.ordinal * 10 + - player.getPositionEyes(1f).distanceTo(it.blockPos) * 8 + - it.stuckTicks * 2 + - it.ranTicks - }) - if (!active) { active = true BaritoneUtils.primary?.pathingControlManager?.registerProcess(HighwayToolsProcess) } - if (baritoneMode.value) { - pathing = BaritoneUtils.isPathing - val taskPos = (pendingTasks.firstOrNull() ?: doneTasks.firstOrNull())?.blockPos - ?: BlockPos(0, -1, 0) + updateRenderer() + updateFood() - if (player.positionVector.distanceTo(taskPos) < maxReach.value) { - if (!isDone()) { - if (canDoTask()) { - doNextTask() - } - } else { - if (checkTasks() && !pathing) { - currentBlockPos = getNextBlock(getNextBlock()) - doneTasks.clear() - updateTasks(currentBlockPos) - } else { - refreshData() - } - } - } else { - refreshData() - } - } else { - if (currentBlockPos == player.flooredPosition) { - doNextTask() - } else { - currentBlockPos = player.flooredPosition - if (abs((startingDirection.ordinal - Direction.fromEntity(player).ordinal) % 8) == 4) startingDirection = Direction.fromEntity(player) - refreshData() - } - } + if (BaritoneUtils.paused || AutoObsidian.isActive() || AutoEat.eating) return@safeListener + + doPathing() + runTasks() - updateFood() doRotation() } } + private fun SafeClientEvent.updateRenderer() { + renderer.clear() + renderer.aFilled = if (filled.value) aFilled.value else 0 + renderer.aOutline = if (outline.value) aOutline.value else 0 + for (blockTask in pendingTasks) { + if (blockTask.taskState == TaskState.DONE) continue + renderer.add(world.getBlockState(blockTask.blockPos).getSelectedBoundingBox(world, blockTask.blockPos), blockTask.taskState.color) + } + for (blockTask in doneTasks) { + if (blockTask.block == Blocks.AIR) continue + renderer.add(world.getBlockState(blockTask.blockPos).getSelectedBoundingBox(world, blockTask.blockPos), blockTask.taskState.color) + } + } + private fun SafeClientEvent.updateFood() { val currentFood = player.foodStats.foodLevel if (currentFood != prevFood) { @@ -311,22 +271,6 @@ object HighwayTools : Module() { } } - private fun SafeClientEvent.updateRenderer() { - renderer.clear() - renderer.aFilled = if (filled.value) aFilled.value else 0 - renderer.aOutline = if (outline.value) aOutline.value else 0 - renderer.through = false - - for (blockTask in pendingTasks) { - if (blockTask.taskState == TaskState.DONE) continue - renderer.add(world.getBlockState(blockTask.blockPos).getSelectedBoundingBox(world, blockTask.blockPos), blockTask.taskState.color) - } - for (blockTask in doneTasks) { - if (blockTask.block == Blocks.AIR) continue - renderer.add(world.getBlockState(blockTask.blockPos).getSelectedBoundingBox(world, blockTask.blockPos), blockTask.taskState.color) - } - } - private fun SafeClientEvent.refreshData() { doneTasks.clear() pendingTasks.clear() @@ -451,67 +395,76 @@ object HighwayTools : Module() { } } - fun getNextWalkableBlock(): BlockPos { - var lastWalkable = getNextBlock() - - when (mode.value) { - Mode.HIGHWAY -> { - for (step in 1..3) { - val pos = relativeDirection(currentBlockPos, step, 0) - if (mc.world.getBlockState(pos.down()).block == material && - mc.world.getBlockState(pos).block == Blocks.AIR && - mc.world.getBlockState(pos.up()).block == Blocks.AIR) lastWalkable = pos - else break - } - } - Mode.TUNNEL -> { - for (step in 1..3) { - val pos = relativeDirection(currentBlockPos, step, 0) - if (mc.world.getBlockState(pos.down()).block == fillerMat && - mc.world.getBlockState(pos).block == Blocks.AIR && - mc.world.getBlockState(pos.up()).block == Blocks.AIR) lastWalkable = pos - else break - } - } - else -> { - } - } - - return lastWalkable + private fun addTaskToPending(blockPos: BlockPos, taskState: TaskState, material: Block) { + pendingTasks.add(BlockTask(blockPos, taskState, material)) } - private fun getNextBlock(blockPos: BlockPos = currentBlockPos): BlockPos { - return relativeDirection(blockPos, 1, 0) + private fun addTaskToDone(blockPos: BlockPos, material: Block) { + doneTasks.add(BlockTask(blockPos, TaskState.DONE, material)) } - private fun relativeDirection(current: BlockPos, steps: Int, turn: Int): BlockPos { - val index = startingDirection.ordinal + turn - val direction = Direction.values()[Math.floorMod(index, 8)] - return current.add(direction.directionVec.multiply(steps)) - } + private fun SafeClientEvent.doPathing() { + val nextPos = getNextPos() - private fun addTaskToPending(blockPos: BlockPos, taskState: TaskState, material: Block) { - pendingTasks.add(BlockTask(blockPos, taskState, material)) + if (nextPos == mc.player.flooredPosition) { + currentBlockPos = nextPos + goal = null + } else { + goal = GoalNear(nextPos, 0) + } } - private fun addTaskToDone(blockPos: BlockPos, material: Block) { - doneTasks.add(BlockTask(blockPos, TaskState.DONE, material)) + private fun SafeClientEvent.getNextPos() : BlockPos { + val baseMaterial = if (mode.value == Mode.TUNNEL) fillerMat else material + var lastPos = currentBlockPos + + for (step in 1..2) { + val pos = currentBlockPos.add(startingDirection.directionVec.multiply(step)) + val block = world.getBlockState(pos.down()).block + if (block != baseMaterial) break + + lastPos = pos + } + + return lastPos } - /* Returns true if we can do a task, else returns false */ - private fun canDoTask(): Boolean { - return !BaritoneUtils.paused && !AutoObsidian.isActive() && !AutoEat.eating + private fun SafeClientEvent.runTasks() { + if (pendingTasks.isNotEmpty()) { + pendingTasks.sortWith(compareBy { + it.taskState.ordinal * 10 + + player.getPositionEyes(1f).distanceTo(it.blockPos) * 8 + + it.stuckTicks * 2 + + it.ranTicks + }) + + (lastTask?: pendingTasks.peek())?.let { + val dist = player.getPositionEyes(1f).distanceTo(it.blockPos) - 0.7 + if (dist > maxReach.value) { + refreshData() + } else { + doNextTask() + } + } + } else { + if (checkDoneTasks()) { + doneTasks.clear() + updateTasks(currentBlockPos.add(startingDirection.directionVec)) + } else { + refreshData() + } + } } private fun SafeClientEvent.doNextTask() { - if (isDone() || !canDoTask()) return + if (goal != null) return + if (waitTicks > 0) { waitTicks-- return } lastTask?.let { - it.onTick() doTask(it) if (it.taskState != TaskState.DONE) { @@ -523,7 +476,6 @@ object HighwayTools : Module() { var currentTask: BlockTask? = pendingTasks.peek() while (currentTask != null) { - currentTask.onTick() doTask(currentTask) lastTask = currentTask @@ -534,6 +486,8 @@ object HighwayTools : Module() { } private fun SafeClientEvent.doTask(blockTask: BlockTask) { + blockTask.onTick() + when (blockTask.taskState) { TaskState.DONE -> { doDone(blockTask) @@ -694,7 +648,7 @@ object HighwayTools : Module() { } } - private fun SafeClientEvent.checkTasks(): Boolean { + private fun SafeClientEvent.checkDoneTasks(): Boolean { for (blockTask in doneTasks) { val block = world.getBlockState(blockTask.blockPos).block if (ignoreBlocks.contains(block)) continue @@ -913,8 +867,8 @@ object HighwayTools : Module() { append("$chatName Settings" + "\n §9> §rMain material: §7${material.localizedName}" + "\n §9> §rFiller material: §7${fillerMat.localizedName}" + - "\n §9> §rBaritone: §7${baritoneMode.value}" + "\n §9> §rIgnored Blocks:") + for (b in ignoreBlocks) append("\n §9> §7${b!!.registryName}") sendChatMessage(toString()) @@ -950,8 +904,7 @@ object HighwayTools : Module() { "\n §9> §7Placed blocks: §a$totalBlocksPlaced§r" + "\n §9> §7Destroyed blocks: §a$totalBlocksDestroyed§r" ) - - if (baritoneMode.value) append("\n §9> §7Distance: §a${startingBlockPos.distanceTo(currentBlockPos).toInt()}§r") + append("\n §9> §7Distance: §a${startingBlockPos.distanceTo(currentBlockPos).toInt()}§r") sendChatMessage(toString()) } @@ -972,11 +925,7 @@ object HighwayTools : Module() { } fun gatherStatistics(): List { - val currentTask: BlockTask? = if (isDone()) { - null - } else { - pendingTasks.peek() - } + val currentTask: BlockTask? = pendingTasks.peek() materialLeft = InventoryUtils.countItemAll(getIdFromBlock(material)) fillerMatLeft = InventoryUtils.countItemAll(getIdFromBlock(fillerMat)) @@ -1019,12 +968,12 @@ object HighwayTools : Module() { " §7Position: §9(${currentTask?.blockPos?.asString()})", "§rDebug", " §7Stuck manager: §9${StuckManager}", - " §7Pathing: §9$pathing", + //" §7Pathing: §9$pathing", "§rEstimations", " §7${material.localizedName} (main material): §9$materialLeft + ($indirectMaterialLeft)", " §7${fillerMat.localizedName} (filler material): §9$fillerMatLeft", " §7Paving distance left: §9$pavingLeftAll", - " §7Estimated destination: §9(${relativeDirection(currentBlockPos, pavingLeft, 0).asString()})", + //" §7Estimated destination: §9(${relativeDirection(currentBlockPos, pavingLeft, 0).asString()})", " §7ETA: §9$hoursLeft:$minutesLeft:$secondsLeft" ) diff --git a/src/main/java/me/zeroeightsix/kami/process/HighwayToolsProcess.kt b/src/main/java/me/zeroeightsix/kami/process/HighwayToolsProcess.kt index 71d1b643ed..792ea732e3 100644 --- a/src/main/java/me/zeroeightsix/kami/process/HighwayToolsProcess.kt +++ b/src/main/java/me/zeroeightsix/kami/process/HighwayToolsProcess.kt @@ -1,6 +1,5 @@ package me.zeroeightsix.kami.process -import baritone.api.pathing.goals.GoalNear import baritone.api.process.IBaritoneProcess import baritone.api.process.PathingCommand import baritone.api.process.PathingCommandType @@ -26,13 +25,9 @@ object HighwayToolsProcess : IBaritoneProcess { override fun displayName0(): String { val lastTask = HighwayTools.lastTask - val processName = if (lastTask != null && !HighwayTools.pathing) { - lastTask.toString() - } else if (HighwayTools.pathing) { - "Moving to Position: (${HighwayTools.getNextWalkableBlock().asString()})" - } else { - "Manual mode" - } + val processName = HighwayTools.goal?.goalPos?.asString() + ?: lastTask?.toString() + ?: "Thinking" return "HighwayTools: $processName" } @@ -41,9 +36,9 @@ object HighwayToolsProcess : IBaritoneProcess { return HighwayTools.isEnabled } - override fun onTick(p0: Boolean, p1: Boolean): PathingCommand? { - return if (HighwayTools.baritoneMode.value) { - PathingCommand(GoalNear(HighwayTools.getNextWalkableBlock(), 0), PathingCommandType.SET_GOAL_AND_PATH) - } else PathingCommand(null, PathingCommandType.REQUEST_PAUSE) + override fun onTick(p0: Boolean, p1: Boolean): PathingCommand { + return HighwayTools.goal?.let { + PathingCommand(it, PathingCommandType.SET_GOAL_AND_PATH) + } ?: PathingCommand(null, PathingCommandType.REQUEST_PAUSE) } } \ No newline at end of file From 4b3d1b57dcb22d9375b29b062ffe66499b12ffe3 Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Sun, 3 Jan 2021 22:04:36 -0500 Subject: [PATCH 195/390] Fixed task sorting --- .../kami/module/modules/misc/HighwayTools.kt | 49 +++++++++++-------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 7151e53958..1a71e2ed0c 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -28,6 +28,7 @@ import me.zeroeightsix.kami.util.text.MessageSendHelper.sendChatMessage import me.zeroeightsix.kami.util.threads.* import net.minecraft.block.Block import net.minecraft.block.Block.getIdFromBlock +import net.minecraft.block.BlockAir import net.minecraft.block.BlockLiquid import net.minecraft.client.audio.PositionedSoundRecord import net.minecraft.init.Blocks @@ -41,6 +42,7 @@ import net.minecraft.util.math.RayTraceResult import net.minecraft.util.math.Vec3d import java.util.* import kotlin.collections.ArrayList +import kotlin.collections.HashSet import kotlin.collections.LinkedHashMap /** @@ -120,7 +122,7 @@ object HighwayTools : Module() { var goal: GoalNear? = null; private set // Tasks - private val pendingTasks = LinkedList() + private val pendingTasks = HashSet() private val doneTasks = ArrayList() var lastTask: BlockTask? = null; private set @@ -420,8 +422,14 @@ object HighwayTools : Module() { for (step in 1..2) { val pos = currentBlockPos.add(startingDirection.directionVec.multiply(step)) - val block = world.getBlockState(pos.down()).block - if (block != baseMaterial) break + + if (!blueprintNew.containsKey(pos.down())) break + + val block = world.getBlockState(pos).block + val blockBelow = world.getBlockState(pos.down()).block + + if (block is BlockLiquid || blockBelow is BlockLiquid) break + if (block !is BlockAir || blockBelow != baseMaterial) break lastPos = pos } @@ -431,19 +439,19 @@ object HighwayTools : Module() { private fun SafeClientEvent.runTasks() { if (pendingTasks.isNotEmpty()) { - pendingTasks.sortWith(compareBy { + val sortedTasks = pendingTasks.sortedBy { it.taskState.ordinal * 10 + - player.getPositionEyes(1f).distanceTo(it.blockPos) * 8 + + player.getPositionEyes(1f).distanceTo(it.blockPos) * 2 + it.stuckTicks * 2 + it.ranTicks - }) + } - (lastTask?: pendingTasks.peek())?.let { + (lastTask?: sortedTasks.firstOrNull())?.let { val dist = player.getPositionEyes(1f).distanceTo(it.blockPos) - 0.7 if (dist > maxReach.value) { refreshData() } else { - doNextTask() + doNextTask(sortedTasks) } } } else { @@ -456,7 +464,7 @@ object HighwayTools : Module() { } } - private fun SafeClientEvent.doNextTask() { + private fun SafeClientEvent.doNextTask(sortedTasks: List) { if (goal != null) return if (waitTicks > 0) { @@ -473,15 +481,10 @@ object HighwayTools : Module() { } } - var currentTask: BlockTask? = pendingTasks.peek() - - while (currentTask != null) { - doTask(currentTask) - lastTask = currentTask - - if (currentTask.taskState != TaskState.DONE) break - - currentTask = pendingTasks.peek() + for (task in sortedTasks) { + doTask(task) + if (task.taskState != TaskState.DONE) break + lastTask = task } } @@ -511,7 +514,7 @@ object HighwayTools : Module() { } private fun doDone(blockTask: BlockTask) { - pendingTasks.poll() + pendingTasks.remove(blockTask) doneTasks.add(blockTask) } @@ -925,7 +928,7 @@ object HighwayTools : Module() { } fun gatherStatistics(): List { - val currentTask: BlockTask? = pendingTasks.peek() + val currentTask = lastTask materialLeft = InventoryUtils.countItemAll(getIdFromBlock(material)) fillerMatLeft = InventoryUtils.countItemAll(getIdFromBlock(fillerMat)) @@ -1038,6 +1041,12 @@ object HighwayTools : Module() { override fun toString(): String { return "Block: ${block.localizedName} @ Position: (${blockPos.asString()}) State: ${taskState.name}" } + + override fun equals(other: Any?) = this === other + || (other is BlockTask + && blockPos == other.blockPos) + + override fun hashCode() = blockPos.hashCode() } enum class TaskState(val color: ColorHolder) { From a44da054e791e1da24d5ad5a4e377cd80c026434 Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Sun, 3 Jan 2021 22:26:40 -0500 Subject: [PATCH 196/390] Fixed tunnel mode blue print --- .../kami/module/modules/misc/HighwayTools.kt | 44 +++++++++---------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 1a71e2ed0c..fa2a0646a4 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -28,7 +28,6 @@ import me.zeroeightsix.kami.util.text.MessageSendHelper.sendChatMessage import me.zeroeightsix.kami.util.threads.* import net.minecraft.block.Block import net.minecraft.block.Block.getIdFromBlock -import net.minecraft.block.BlockAir import net.minecraft.block.BlockLiquid import net.minecraft.client.audio.PositionedSoundRecord import net.minecraft.init.Blocks @@ -347,7 +346,11 @@ object HighwayTools : Module() { continue } - blueprintNew[pos] = Blocks.AIR + if (mode.value == Mode.HIGHWAY) { + blueprintNew[pos] = Blocks.AIR + } else { + blueprintNew[pos.up()] = Blocks.AIR + } } } } @@ -359,16 +362,12 @@ object HighwayTools : Module() { val x = w - buildWidth.value / 2 val pos = basePos.add(xDirection.directionVec.multiply(x)) - if (mode.value == Mode.HIGHWAY) { - if (isRail(w)) { - for (y in 1..railingHeight.value) { - blueprintNew[pos.up(y)] = baseMaterial - } - } else { - blueprintNew[pos] = baseMaterial + if (mode.value == Mode.HIGHWAY && isRail(w)) { + for (y in 1..railingHeight.value) { + blueprintNew[pos.up(y)] = baseMaterial } } else { - blueprintNew[pos.down()] = baseMaterial + blueprintNew[pos] = baseMaterial } } } @@ -416,7 +415,7 @@ object HighwayTools : Module() { } } - private fun SafeClientEvent.getNextPos() : BlockPos { + private fun SafeClientEvent.getNextPos(): BlockPos { val baseMaterial = if (mode.value == Mode.TUNNEL) fillerMat else material var lastPos = currentBlockPos @@ -429,7 +428,7 @@ object HighwayTools : Module() { val blockBelow = world.getBlockState(pos.down()).block if (block is BlockLiquid || blockBelow is BlockLiquid) break - if (block !is BlockAir || blockBelow != baseMaterial) break + if (block != Blocks.AIR || blockBelow != baseMaterial) break lastPos = pos } @@ -446,7 +445,7 @@ object HighwayTools : Module() { it.ranTicks } - (lastTask?: sortedTasks.firstOrNull())?.let { + (lastTask ?: sortedTasks.firstOrNull())?.let { val dist = player.getPositionEyes(1f).distanceTo(it.blockPos) - 0.7 if (dist > maxReach.value) { refreshData() @@ -465,8 +464,6 @@ object HighwayTools : Module() { } private fun SafeClientEvent.doNextTask(sortedTasks: List) { - if (goal != null) return - if (waitTicks > 0) { waitTicks-- return @@ -483,8 +480,8 @@ object HighwayTools : Module() { for (task in sortedTasks) { doTask(task) - if (task.taskState != TaskState.DONE) break lastTask = task + if (task.taskState != TaskState.DONE) break } } @@ -550,7 +547,7 @@ object HighwayTools : Module() { when (world.getBlockState(blockTask.blockPos).block) { Blocks.AIR -> { totalBlocksDestroyed++ - if (blockTask.block == material || blockTask.block == fillerMat) { + if (blockTask.block != Blocks.AIR) { blockTask.updateState(TaskState.PLACE) } else { blockTask.updateState(TaskState.DONE) @@ -579,7 +576,7 @@ object HighwayTools : Module() { if (blockTask.taskState != TaskState.EMERGENCY_BREAK && blockTask.block != Blocks.AIR && ignoreBlocks.contains(blockTask.block)) { - blockTask.updateState(TaskState.DONE) + blockTask.updateState(TaskState.DONE) } // last check before breaking @@ -768,12 +765,12 @@ object HighwayTools : Module() { Blocks.NETHERRACK -> { waitTicks = tickDelayBreak.value defaultScope.launch { - delay(20L) + delay(10L) onMainThreadSafe { connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, blockTask.blockPos, side)) player.swingArm(EnumHand.MAIN_HAND) } - delay(20L) + delay(40L) onMainThreadSafe { connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, blockTask.blockPos, side)) player.swingArm(EnumHand.MAIN_HAND) @@ -798,7 +795,7 @@ object HighwayTools : Module() { } defaultScope.launch { - delay(20L) + delay(10L) onMainThreadSafe { connection.sendPacket(CPacketPlayerDigging(action, blockTask.blockPos, facing)) player.swingArm(EnumHand.MAIN_HAND) @@ -830,7 +827,7 @@ object HighwayTools : Module() { connection.sendPacket(CPacketEntityAction(player, CPacketEntityAction.Action.START_SNEAKING)) defaultScope.launch { - delay(20L) + delay(10L) onMainThreadSafe { placeBlock(pair.second, pair.first) } @@ -999,6 +996,7 @@ object HighwayTools : Module() { private fun addTaskToMessageList(list: ArrayList, tasks: Collection) { for (blockTask in tasks) list.add(" " + blockTask.block.localizedName + "@(" + blockTask.blockPos.asString() + ") Priority: " + blockTask.taskState.ordinal + " State: " + blockTask.taskState.toString()) } + object StuckManager { override fun toString(): String { return " " @@ -1046,7 +1044,7 @@ object HighwayTools : Module() { || (other is BlockTask && blockPos == other.blockPos) - override fun hashCode() = blockPos.hashCode() + override fun hashCode() = blockPos.hashCode() } enum class TaskState(val color: ColorHolder) { From ac40f17e8630d6a9c7eb1bf9d43cba071a4a5b81 Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Sun, 3 Jan 2021 22:28:27 -0500 Subject: [PATCH 197/390] Removed stuck manager --- .../kami/module/modules/misc/HighwayTools.kt | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index fa2a0646a4..c3a735fe04 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -967,7 +967,7 @@ object HighwayTools : Module() { " §7Target state: §9${currentTask?.block?.localizedName}", " §7Position: §9(${currentTask?.blockPos?.asString()})", "§rDebug", - " §7Stuck manager: §9${StuckManager}", + " §7Stuck ticks: §9${lastTask?.stuckTicks?.toString()?: "N/A"}", //" §7Pathing: §9$pathing", "§rEstimations", " §7${material.localizedName} (main material): §9$materialLeft + ($indirectMaterialLeft)", @@ -997,12 +997,6 @@ object HighwayTools : Module() { for (blockTask in tasks) list.add(" " + blockTask.block.localizedName + "@(" + blockTask.blockPos.asString() + ") Priority: " + blockTask.taskState.ordinal + " State: " + blockTask.taskState.toString()) } - object StuckManager { - override fun toString(): String { - return " " - } - } - class BlockTask( val blockPos: BlockPos, var taskState: TaskState, @@ -1084,11 +1078,5 @@ object HighwayTools : Module() { VIEW_LOCK } - enum class StuckLevel { - NONE, - MINOR, - MODERATE, - MAYOR - } } From ec9682f58c2d5a8b7efe49c21616b14376e17a9a Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Sun, 3 Jan 2021 23:16:43 -0500 Subject: [PATCH 198/390] Attempt to fixed place/break counter --- .../kami/module/modules/misc/HighwayTools.kt | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index c3a735fe04..ad8344a253 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -546,12 +546,12 @@ object HighwayTools : Module() { private fun SafeClientEvent.doBroken(blockTask: BlockTask) { when (world.getBlockState(blockTask.blockPos).block) { Blocks.AIR -> { - totalBlocksDestroyed++ if (blockTask.block != Blocks.AIR) { blockTask.updateState(TaskState.PLACE) } else { blockTask.updateState(TaskState.DONE) } + totalBlocksDestroyed++ } else -> { blockTask.updateState(TaskState.BREAK) @@ -563,10 +563,19 @@ object HighwayTools : Module() { val block = world.getBlockState(blockTask.blockPos).block when { - blockTask.block == block && block != Blocks.AIR -> blockTask.updateState(TaskState.DONE) - blockTask.block == Blocks.AIR && block != Blocks.AIR -> blockTask.updateState(TaskState.BREAK) - blockTask.block == block && block == Blocks.AIR -> blockTask.updateState(TaskState.BREAK) - else -> blockTask.updateState(TaskState.PLACE) + blockTask.block == block && block != Blocks.AIR -> { + blockTask.updateState(TaskState.DONE) + totalBlocksPlaced++ + } + blockTask.block == Blocks.AIR && block != Blocks.AIR -> { + blockTask.updateState(TaskState.BREAK) + } + blockTask.block == block && block == Blocks.AIR -> { + blockTask.updateState(TaskState.BREAK) + } + else -> { + blockTask.updateState(TaskState.PLACE) + } } } @@ -643,7 +652,6 @@ object HighwayTools : Module() { blockTask.updateState(TaskState.PLACED) waitTicks = tickDelayPlace.value - totalBlocksPlaced++ } } } From 553e450bdc481c9862d7e421b1e4572460351ba1 Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Mon, 4 Jan 2021 09:50:41 -0500 Subject: [PATCH 199/390] Fixed pathing pos check --- .../zeroeightsix/kami/module/modules/misc/HighwayTools.kt | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index ad8344a253..0a093c0519 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -423,12 +423,10 @@ object HighwayTools : Module() { val pos = currentBlockPos.add(startingDirection.directionVec.multiply(step)) if (!blueprintNew.containsKey(pos.down())) break + if (!world.isAirBlock(pos) || !world.isAirBlock(pos.up())) break - val block = world.getBlockState(pos).block val blockBelow = world.getBlockState(pos.down()).block - - if (block is BlockLiquid || blockBelow is BlockLiquid) break - if (block != Blocks.AIR || blockBelow != baseMaterial) break + if (blockBelow != baseMaterial) break lastPos = pos } From 0ad26c4af7d22001a3492d348018486edeb3649e Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Mon, 4 Jan 2021 10:59:23 -0500 Subject: [PATCH 200/390] Rewrote stuck counting --- .../kami/module/modules/misc/HighwayTools.kt | 71 ++++++++++--------- 1 file changed, 38 insertions(+), 33 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 0a093c0519..e1f252415f 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -272,14 +272,11 @@ object HighwayTools : Module() { } } - private fun SafeClientEvent.refreshData() { + private fun SafeClientEvent.refreshData(originPos: BlockPos = currentBlockPos) { doneTasks.clear() pendingTasks.clear() lastTask = null - updateTasks(currentBlockPos) - } - private fun SafeClientEvent.updateTasks(originPos: BlockPos) { blueprintNew.clear() generateBluePrint(originPos) @@ -437,10 +434,9 @@ object HighwayTools : Module() { private fun SafeClientEvent.runTasks() { if (pendingTasks.isNotEmpty()) { val sortedTasks = pendingTasks.sortedBy { - it.taskState.ordinal * 10 + + it.taskState.priority + player.getPositionEyes(1f).distanceTo(it.blockPos) * 2 + - it.stuckTicks * 2 + - it.ranTicks + it.stuckTicks * 10 / it.taskState.stuckTimeout } (lastTask ?: sortedTasks.firstOrNull())?.let { @@ -471,7 +467,13 @@ object HighwayTools : Module() { doTask(it) if (it.taskState != TaskState.DONE) { - if (it.stuckTicks > 20) refreshData() + val timeout = it.taskState.stuckTimeout + if (it.stuckTicks > timeout) { + if (debugMessages.value == DebugMessages.IMPORTANT) { + sendChatMessage("Stuck for more than $timeout ticks, refreshing data.") + } + refreshData() + } return } } @@ -687,13 +689,13 @@ object HighwayTools : Module() { sendChatMessage("$chatName No ${blockTask.block.localizedName} was found in inventory") mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) disable() - blockTask.onFailed() + blockTask.onStuck() } InventoryUtils.swapSlotToItem(blockID) } else -> { - blockTask.onFailed() + blockTask.onStuck() } } } @@ -759,7 +761,7 @@ object HighwayTools : Module() { val rayTraceResult = rayTraceHitVec(blockTask.blockPos) if (rayTraceResult == null) { - blockTask.onFailed() + blockTask.onStuck() return } @@ -813,7 +815,7 @@ object HighwayTools : Module() { val pair = WorldUtils.getNeighbour(blockTask.blockPos, 1, 6.5f) ?: run { sendChatMessage("Can't find neighbour block") - blockTask.onFailed() + blockTask.onStuck() return } @@ -823,7 +825,7 @@ object HighwayTools : Module() { sendChatMessage("Trying to place through wall ${blockTask.blockPos}") } } else { - blockTask.onFailed() + blockTask.onStuck() } } @@ -860,12 +862,12 @@ object HighwayTools : Module() { return false } - private fun isInsideSelection(blockPos: BlockPos): Boolean { - return pendingTasks.any { it.blockPos == blockPos } + private fun isInsideSelection(pos: BlockPos): Boolean { + return blueprintNew.containsKey(pos) } - private fun isInsideBuild(blockPos: BlockPos): Boolean { - return pendingTasks.any { it.blockPos == blockPos && it.block == material } + private fun isInsideBuild(pos: BlockPos): Boolean { + return blueprintNew[pos]?.let { it != Blocks.AIR } ?: false } fun printSettings() { @@ -973,7 +975,7 @@ object HighwayTools : Module() { " §7Target state: §9${currentTask?.block?.localizedName}", " §7Position: §9(${currentTask?.blockPos?.asString()})", "§rDebug", - " §7Stuck ticks: §9${lastTask?.stuckTicks?.toString()?: "N/A"}", + " §7Stuck ticks: §9${lastTask?.stuckTicks?.toString() ?: "N/A"}", //" §7Pathing: §9$pathing", "§rEstimations", " §7${material.localizedName} (main material): §9$materialLeft + ($indirectMaterialLeft)", @@ -1012,28 +1014,31 @@ object HighwayTools : Module() { var stuckTicks = 0; private set fun updateState(state: TaskState) { + if (state == taskState) return taskState = state onUpdate() } fun updateMaterial(material: Block) { + if (material == block) return block = material onUpdate() } fun onTick() { ranTicks++ + if (ranTicks > taskState.stuckThreshold) { + stuckTicks++ + } } - fun onFailed() { + fun onStuck() { stuckTicks++ } fun onUpdate() { - if (taskState == TaskState.DONE) { - stuckTicks = 0 - ranTicks = 0 - } + stuckTicks = 0 + ranTicks = 0 } override fun toString(): String { @@ -1047,16 +1052,16 @@ object HighwayTools : Module() { override fun hashCode() = blockPos.hashCode() } - enum class TaskState(val color: ColorHolder) { - DONE(ColorHolder(50, 50, 50)), - LIQUID_SOURCE(ColorHolder(120, 41, 240)), - LIQUID_FLOW(ColorHolder(120, 41, 240)), - BROKEN(ColorHolder(111, 0, 0)), - BREAKING(ColorHolder(240, 222, 60)), - EMERGENCY_BREAK(ColorHolder(220, 41, 140)), - BREAK(ColorHolder(222, 0, 0)), - PLACED(ColorHolder(53, 222, 66)), - PLACE(ColorHolder(35, 188, 254)) + enum class TaskState(val priority: Int, val stuckThreshold: Int, val stuckTimeout: Int, val color: ColorHolder) { + DONE(0, 69420, 0x22, ColorHolder(50, 50, 50)), + LIQUID_SOURCE(1, 100, 100, ColorHolder(120, 41, 240)), + LIQUID_FLOW(20, 80, 80, ColorHolder(120, 41, 240)), + BROKEN(120, 20, 10, ColorHolder(111, 0, 0)), + BREAKING(140, 100, 100, ColorHolder(240, 222, 60)), + EMERGENCY_BREAK(160, 20, 20, ColorHolder(220, 41, 140)), + BREAK(180, 20, 20, ColorHolder(222, 0, 0)), + PLACED(280, 20, 5, ColorHolder(53, 222, 66)), + PLACE(300, 20, 10, ColorHolder(35, 188, 254)) } private enum class DebugMessages { From 5bf66068cfe2eb58c977efd34940325e2a9405cf Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Mon, 4 Jan 2021 11:13:32 -0500 Subject: [PATCH 201/390] Fixed diagonal blue print generating --- .../kami/module/modules/misc/HighwayTools.kt | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index e1f252415f..4703eea0cf 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -318,7 +318,7 @@ object HighwayTools : Module() { if (mode.value != Mode.FLAT) { val zDirection = startingDirection - val xDirection = zDirection.clockwise(2) + val xDirection = zDirection.clockwise(if (zDirection.isDiagonal) 1 else 2) val nextPos = basePos.add(zDirection.directionVec) generateClear(basePos, xDirection) @@ -373,8 +373,10 @@ object HighwayTools : Module() { private fun generateFlat(basePos: BlockPos) { // Base - for (x in -buildWidth.value..buildWidth.value) { - for (z in -buildWidth.value..buildWidth.value) { + for (w1 in 0 until buildWidth.value) { + for (w2 in 0 until buildWidth.value) { + val x = w1 - buildWidth.value / 2 + val z = w2 - buildWidth.value / 2 val pos = basePos.add(x, 0, z) blueprintNew[pos] = material @@ -383,10 +385,13 @@ object HighwayTools : Module() { // Clear if (!clearSpace.value) return - for (x in -buildWidth.value..buildWidth.value) { - for (z in -buildWidth.value..buildWidth.value) { + for (w1 in -buildWidth.value..buildWidth.value) { + for (w2 in -buildWidth.value..buildWidth.value) { for (y in 1 until clearHeight.value) { + val x = w1 - buildWidth.value / 2 + val z = w2 - buildWidth.value / 2 val pos = basePos.add(x, y, z) + blueprintNew[pos] = Blocks.AIR } } @@ -450,7 +455,7 @@ object HighwayTools : Module() { } else { if (checkDoneTasks()) { doneTasks.clear() - updateTasks(currentBlockPos.add(startingDirection.directionVec)) + refreshData(currentBlockPos.add(startingDirection.directionVec)) } else { refreshData() } From 2933a56242ab8899fb9624dd55891831f355fbab Mon Sep 17 00:00:00 2001 From: Christian Date: Mon, 4 Jan 2021 22:31:26 +0100 Subject: [PATCH 202/390] Dynamic blueprint depth based on player range --- .../kami/module/modules/misc/HighwayTools.kt | 37 +++++++++++++++---- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 4703eea0cf..07ff51157f 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -24,6 +24,7 @@ import me.zeroeightsix.kami.util.math.Direction import me.zeroeightsix.kami.util.math.RotationUtils import me.zeroeightsix.kami.util.math.VectorUtils.distanceTo import me.zeroeightsix.kami.util.math.VectorUtils.multiply +import me.zeroeightsix.kami.util.math.VectorUtils.toVec3d import me.zeroeightsix.kami.util.text.MessageSendHelper.sendChatMessage import me.zeroeightsix.kami.util.threads.* import net.minecraft.block.Block @@ -313,24 +314,39 @@ object HighwayTools : Module() { } } - private fun generateBluePrint(feetPos: BlockPos) { + private fun SafeClientEvent.generateBluePrint(feetPos: BlockPos) { val basePos = feetPos.down() if (mode.value != Mode.FLAT) { val zDirection = startingDirection val xDirection = zDirection.clockwise(if (zDirection.isDiagonal) 1 else 2) - val nextPos = basePos.add(zDirection.directionVec) - generateClear(basePos, xDirection) - generateClear(nextPos, xDirection) + for (x in -12 until 12) { + val thisPos = basePos.add(zDirection.directionVec.multiply(x)) + generateClear(thisPos, xDirection) + generateBase(thisPos, xDirection) + } + + pickTasksInRange() - generateBase(basePos, xDirection) - generateBase(nextPos, xDirection) } else { generateFlat(basePos) } } + private fun SafeClientEvent.pickTasksInRange() { + val removeCandidates = LinkedList() + for (task in blueprintNew) { + if (player.getPositionEyes(1f).distanceTo(task.key) > maxReach.value) { + removeCandidates.add(task.key) + } + } + + for (task in removeCandidates) { + blueprintNew.remove(task) + } + } + private fun generateClear(basePos: BlockPos, xDirection: Direction) { if (!clearSpace.value) return @@ -430,12 +446,19 @@ object HighwayTools : Module() { val blockBelow = world.getBlockState(pos.down()).block if (blockBelow != baseMaterial) break - lastPos = pos + if (checkFOMO(pos)) lastPos = pos } return lastPos } + private fun checkFOMO(pos: BlockPos): Boolean { + for (task in blueprint) { + if (pos.toVec3d().distanceTo(task.first.toVec3d()) > maxReach.value) return false + } + return true + } + private fun SafeClientEvent.runTasks() { if (pendingTasks.isNotEmpty()) { val sortedTasks = pendingTasks.sortedBy { From f1d1b40db1a264dbf1206f765267b9035341ce25 Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Mon, 4 Jan 2021 17:28:47 -0500 Subject: [PATCH 203/390] Fixed AutoObsidian settings --- .../kami/module/modules/misc/AutoObsidian.kt | 46 +++++++++---------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt index efbb67d8ba..9b2e0ee520 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt @@ -10,7 +10,7 @@ import me.zeroeightsix.kami.event.events.RenderWorldEvent import me.zeroeightsix.kami.manager.managers.PlayerPacketManager import me.zeroeightsix.kami.module.Module import me.zeroeightsix.kami.process.AutoObsidianProcess -import me.zeroeightsix.kami.setting.Settings +import me.zeroeightsix.kami.setting.ModuleConfig.setting import me.zeroeightsix.kami.util.* import me.zeroeightsix.kami.util.EntityUtils.getDroppedItem import me.zeroeightsix.kami.util.WorldUtils.placeBlock @@ -52,15 +52,15 @@ import org.kamiblue.event.listener.listener description = "Breaks down Ender Chests to restock obsidian" ) object AutoObsidian : Module() { - private val fillMode = register(Settings.e("FillMode", FillMode.TARGET_STACKS)) - private val searchShulker = register(Settings.b("SearchShulker", false)) - private val leaveEmptyShulkers = register(Settings.booleanBuilder("LeaveEmptyShulkers").withValue(true).withVisibility { searchShulker.value == true }) - private val autoRefill = register(Settings.booleanBuilder("AutoRefill").withValue(false).withVisibility { fillMode.value != FillMode.INFINITE }) - private val threshold = register(Settings.integerBuilder("RefillThreshold").withValue(8).withRange(1, 56).withVisibility { autoRefill.value && fillMode.value != FillMode.INFINITE }) - private val targetStacks = register(Settings.integerBuilder("TargetStacks").withValue(1).withRange(1, 20).withVisibility { fillMode.value == FillMode.TARGET_STACKS }) - private val delayTicks = register(Settings.integerBuilder("DelayTicks").withValue(5).withRange(0, 10)) - private val interacting = register(Settings.e("InteractMode", InteractMode.SPOOF)) - private val maxReach = register(Settings.floatBuilder("MaxReach").withValue(4.5F).withRange(2.0f, 6.0f).withStep(0.1f)) + private val fillMode by setting("FillMode", FillMode.TARGET_STACKS) + private val searchShulker by setting("SearchShulker", false) + private val leaveEmptyShulkers by setting("LeaveEmptyShulkers", true, { searchShulker }) + private val autoRefill by setting("AutoRefill", false,{ fillMode != FillMode.INFINITE }) + private val threshold by setting("RefillThreshold", 8, 1..56, 1, { autoRefill && fillMode != FillMode.INFINITE }) + private val targetStacks by setting("TargetStacks", 1, 1..20, 1, { fillMode == FillMode.TARGET_STACKS }) + private val delayTicks by setting("DelayTicks", 5, 0..10, 1) + private val interacting by setting("InteractMode", InteractMode.SPOOF) + private val maxReach by setting("MaxReach", 4.5f, 2.0f..6.0f, 0.1f) private enum class FillMode(override val displayName: String, val message: String) : DisplayEnum { TARGET_STACKS("Target stacks", "Target Stacks Reached"), @@ -129,7 +129,7 @@ object AutoObsidian : Module() { init { safeListener { if (it.phase != TickEvent.Phase.END || mc.playerController == null - || !tickTimer.tick(delayTicks.value.toLong())) return@safeListener + || !tickTimer.tick(delayTicks.toLong())) return@safeListener updateState() when (state) { @@ -149,11 +149,11 @@ object AutoObsidian : Module() { collectDroppedItem(ItemID.OBSIDIAN.id) } State.DONE -> { - if (!autoRefill.value) { - sendChatMessage("$chatName ${fillMode.value.message}, disabling.") + if (!autoRefill) { + sendChatMessage("$chatName ${fillMode.message}, disabling.") disable() } else { - if (active) sendChatMessage("$chatName ${fillMode.value.message}, stopping.") + if (active) sendChatMessage("$chatName ${fillMode.message}, stopping.") reset() } } @@ -168,7 +168,7 @@ object AutoObsidian : Module() { if (event.phase != Phase.PRE || rotateTimer.tick(20L, false)) return@listener val rotation = lastHitVec?.let { getRotationTo(it) } ?: return@listener - when (interacting.value) { + when (interacting) { InteractMode.SPOOF -> { val packet = PlayerPacketManager.PlayerPacket(rotating = true, rotation = rotation) PlayerPacketManager.addPacket(this, packet) @@ -210,7 +210,7 @@ object AutoObsidian : Module() { val eyePos = mc.player.getPositionEyes(1f) if (isPositionValid(placingPos, mc.world.getBlockState(placingPos), eyePos)) return - val posList = VectorUtils.getBlockPosInSphere(eyePos, maxReach.value) + val posList = VectorUtils.getBlockPosInSphere(eyePos, maxReach) .sortedBy { it.distanceSqToCenter(eyePos.x, eyePos.y, eyePos.z) } .map { it to mc.world.getBlockState(it) } .toList() @@ -240,7 +240,7 @@ object AutoObsidian : Module() { val passCountCheck = checkObbyCount() state = when { - state == State.DONE && autoRefill.value && InventoryUtils.countItemAll(ItemID.OBSIDIAN.id) <= threshold.value -> { + state == State.DONE && autoRefill && InventoryUtils.countItemAll(ItemID.OBSIDIAN.id) <= threshold -> { State.SEARCHING } state == State.COLLECTING && (!canPickUpObby() || getDroppedItem(ItemID.OBSIDIAN.id, 16.0f) == null) -> { @@ -269,7 +269,7 @@ object AutoObsidian : Module() { * There must be at least one slot which is either empty, or contains a stack of obsidian less than 64 */ private fun canPickUpObby(): Boolean { - return fillMode.value == FillMode.INFINITE || mc.player?.inventory?.mainInventory?.any { + return fillMode == FillMode.INFINITE || mc.player?.inventory?.mainInventory?.any { it.isEmpty || it.item.id == ItemID.OBSIDIAN.id && it.count < 64 } ?: false } @@ -281,9 +281,9 @@ object AutoObsidian : Module() { val inventory = InventoryUtils.countItemAll(ItemID.OBSIDIAN.id) val dropped = EntityUtils.getDroppedItems(ItemID.OBSIDIAN.id, 16.0f).sumBy { it.item.count } - return when (fillMode.value!!) { + return when (fillMode) { FillMode.TARGET_STACKS -> { - ((inventory + dropped) / 8.0f).ceilToInt() / 8 < targetStacks.value + ((inventory + dropped) / 8.0f).ceilToInt() / 8 < targetStacks } FillMode.FILL_INVENTORY -> { countEmptySlots() - dropped >= 8 @@ -345,7 +345,7 @@ object AutoObsidian : Module() { } private fun searchingState() { - if (searchShulker.value) { + if (searchShulker) { when (searchingState) { SearchingState.PLACING -> { placeShulker(placingPos) @@ -402,7 +402,7 @@ object AutoObsidian : Module() { return } else if (InventoryUtils.getSlots(0, 35, ItemID.ENDER_CHEST.id) == null) { /* Case where we are out of ender chests */ - if (searchShulker.value) { + if (searchShulker) { state = State.SEARCHING } else { sendChatMessage("$chatName No ender chest was found in inventory, disabling.") @@ -427,7 +427,7 @@ object AutoObsidian : Module() { InventoryUtils.inventoryClick(container.windowId, slot, 0, ClickType.QUICK_MOVE) mc.player.closeScreen() } else if (shulkerOpenTimer.tick(100, false)) { // Wait for maximum of 5 seconds - if (leaveEmptyShulkers.value && container.inventory.subList(0, 27).indexOfFirst { it.item.id != ItemID.AIR.id } == -1) { + if (leaveEmptyShulkers && container.inventory.subList(0, 27).indexOfFirst { it.item.id != ItemID.AIR.id } == -1) { searchingState = SearchingState.PRE_MINING mc.player.closeScreen() } else { From f3646e49e8b5b49fb4f3a519da3bfc702321e584 Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Mon, 4 Jan 2021 17:36:34 -0500 Subject: [PATCH 204/390] Fixed HighwayTools setting --- .../kami/module/modules/misc/HighwayTools.kt | 142 +++++++++--------- 1 file changed, 71 insertions(+), 71 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 4703eea0cf..7a0196062a 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -12,7 +12,7 @@ import me.zeroeightsix.kami.module.Module import me.zeroeightsix.kami.module.modules.player.AutoEat import me.zeroeightsix.kami.module.modules.player.InventoryManager import me.zeroeightsix.kami.process.HighwayToolsProcess -import me.zeroeightsix.kami.setting.Settings +import me.zeroeightsix.kami.setting.ModuleConfig.setting import me.zeroeightsix.kami.util.* import me.zeroeightsix.kami.util.EntityUtils.flooredPosition import me.zeroeightsix.kami.util.WorldUtils.placeBlock @@ -56,35 +56,35 @@ import kotlin.collections.LinkedHashMap ) object HighwayTools : Module() { - private val mode = register(Settings.e("Mode", Mode.HIGHWAY)) - private val page = register(Settings.e("Page", Page.BUILD)) + private val mode by setting("Mode", Mode.HIGHWAY) + private val page by setting("Page", Page.BUILD) // build settings - private val clearSpace = register(Settings.booleanBuilder("ClearSpace").withValue(true).withVisibility { page.value == Page.BUILD && mode.value == Mode.HIGHWAY }) - private val clearHeight = register(Settings.integerBuilder("Height").withValue(4).withRange(1, 6).withStep(1).withVisibility { page.value == Page.BUILD && clearSpace.value }) - private val buildWidth = register(Settings.integerBuilder("Width").withValue(5).withRange(1, 9).withStep(1).withVisibility { page.value == Page.BUILD }) - private val railing = register(Settings.booleanBuilder("Railing").withValue(true).withVisibility { page.value == Page.BUILD && mode.value == Mode.HIGHWAY }) - private val railingHeight = register(Settings.integerBuilder("RailingHeight").withValue(1).withRange(1, 4).withStep(1).withVisibility { railing.value && page.value == Page.BUILD && mode.value == Mode.HIGHWAY }) - private val cornerBlock = register(Settings.booleanBuilder("CornerBlock").withValue(false).withVisibility { page.value == Page.BUILD && (mode.value == Mode.HIGHWAY || mode.value == Mode.TUNNEL) }) + private val clearSpace by setting("ClearSpace", true, { page == Page.BUILD && mode == Mode.HIGHWAY }) + private val clearHeight by setting("Height", 4, 1..6, 1, { page == Page.BUILD && clearSpace }) + private val buildWidth by setting("Width", 5, 1..9, 1, { page == Page.BUILD }) + private val railing by setting("Railing", true, { page == Page.BUILD && mode == Mode.HIGHWAY }) + private val railingHeight by setting("RailingHeight", 1, 1..4, 1, { railing && page == Page.BUILD && mode == Mode.HIGHWAY }) + private val cornerBlock by setting("CornerBlock", false, { page == Page.BUILD && (mode == Mode.HIGHWAY || mode == Mode.TUNNEL) }) // behavior settings - private val tickDelayPlace = register(Settings.integerBuilder("TickDelayPlace").withValue(3).withRange(0, 16).withStep(1).withVisibility { page.value == Page.BEHAVIOR }) - private val tickDelayBreak = register(Settings.integerBuilder("TickDelayBreak").withValue(1).withRange(0, 16).withStep(1).withVisibility { page.value == Page.BEHAVIOR }) - private val interacting = register(Settings.enumBuilder(InteractMode::class.java, "InteractMode").withValue(InteractMode.SPOOF).withVisibility { page.value == Page.BEHAVIOR }) - private val illegalPlacements = register(Settings.booleanBuilder("IllegalPlacements").withValue(false).withVisibility { page.value == Page.BEHAVIOR }) - private val maxReach = register(Settings.floatBuilder("MaxReach").withValue(4.5F).withRange(1.0f, 6.0f).withStep(0.1f).withVisibility { page.value == Page.BEHAVIOR }) - private val toggleInventoryManager = register(Settings.booleanBuilder("ToggleInvManager").withValue(true).withVisibility { page.value == Page.BEHAVIOR }) - private val toggleAutoObsidian = register(Settings.booleanBuilder("ToggleAutoObsidian").withValue(true).withVisibility { page.value == Page.BEHAVIOR }) + private val tickDelayPlace by setting("TickDelayPlace", 3, 0..16, 1, { page == Page.BEHAVIOR }) + private val tickDelayBreak by setting("TickDelayBreak", 1, 0..16, 1, { page == Page.BEHAVIOR }) + private val interacting by setting("InteractMode", InteractMode.SPOOF, { page == Page.BEHAVIOR }) + private val illegalPlacements by setting("IllegalPlacements", false, { page == Page.BEHAVIOR }) + private val maxReach by setting("MaxReach", 4.5f, 1.0f..6.0f, 0.1f, { page == Page.BEHAVIOR }) + private val toggleInventoryManager by setting("ToggleInvManager", true, { page == Page.BEHAVIOR }) + private val toggleAutoObsidian by setting("ToggleAutoObsidian", true, { page == Page.BEHAVIOR }) // config - private val info = register(Settings.booleanBuilder("ShowInfo").withValue(true).withVisibility { page.value == Page.CONFIG }) - private val printDebug = register(Settings.booleanBuilder("ShowQueue").withValue(false).withVisibility { page.value == Page.CONFIG }) - private val debugMessages = register(Settings.enumBuilder(DebugMessages::class.java, "Debug").withValue(DebugMessages.IMPORTANT).withVisibility { page.value == Page.CONFIG }) - private val goalRender = register(Settings.booleanBuilder("GoalRender").withValue(false).withVisibility { page.value == Page.CONFIG }) - private val filled = register(Settings.booleanBuilder("Filled").withValue(true).withVisibility { page.value == Page.CONFIG }) - private val outline = register(Settings.booleanBuilder("Outline").withValue(true).withVisibility { page.value == Page.CONFIG }) - private val aFilled = register(Settings.integerBuilder("FilledAlpha").withValue(26).withRange(0, 255).withStep(1).withVisibility { filled.value && page.value == Page.CONFIG }) - private val aOutline = register(Settings.integerBuilder("OutlineAlpha").withValue(91).withRange(0, 255).withStep(1).withVisibility { outline.value && page.value == Page.CONFIG }) + private val info by setting("ShowInfo", true, { page == Page.CONFIG }) + private val printDebug by setting("ShowQueue", false, { page == Page.CONFIG }) + private val debugMessages by setting("Debug", DebugMessages.IMPORTANT, { page == Page.CONFIG }) + private val goalRender by setting("GoalRender", false, { page == Page.CONFIG }) + private val filled by setting("Filled", true, { page == Page.CONFIG }) + private val outline by setting("Outline", true, { page == Page.CONFIG }) + private val aFilled by setting("FilledAlpha", 26, 0..255, 1, { filled && page == Page.CONFIG }) + private val aOutline by setting("OutlineAlpha", 91, 0..255, 1, { outline && page == Page.CONFIG }) // internal settings val ignoreBlocks = hashSetOf( @@ -147,10 +147,10 @@ object HighwayTools : Module() { } /* Turn on inventory manager if the users wants us to control it */ - if (toggleInventoryManager.value && InventoryManager.isDisabled) InventoryManager.enable() + if (toggleInventoryManager && InventoryManager.isDisabled) InventoryManager.enable() /* Turn on Auto Obsidian if the user wants us to control it. */ - if (toggleAutoObsidian.value && AutoObsidian.isDisabled && mode.value != Mode.TUNNEL) { + if (toggleAutoObsidian && AutoObsidian.isDisabled && mode != Mode.TUNNEL) { /* If we have no obsidian, immediately turn on Auto Obsidian */ if (InventoryUtils.countItemAll(49) == 0) { AutoObsidian.enable() @@ -174,7 +174,7 @@ object HighwayTools : Module() { baritoneSettingAllowPlace = BaritoneUtils.settings?.allowPlace?.value ?: true BaritoneUtils.settings?.allowPlace?.value = false - if (!goalRender.value) { + if (!goalRender) { baritoneSettingRenderGoal = BaritoneUtils.settings?.renderGoal?.value ?: true BaritoneUtils.settings?.renderGoal?.value = false } @@ -191,13 +191,13 @@ object HighwayTools : Module() { active = false BaritoneUtils.settings?.allowPlace?.value = baritoneSettingAllowPlace - if (!goalRender.value) BaritoneUtils.settings?.renderGoal?.value = baritoneSettingRenderGoal + if (!goalRender) BaritoneUtils.settings?.renderGoal?.value = baritoneSettingRenderGoal /* Turn off inventory manager if the users wants us to control it */ - if (toggleInventoryManager.value && InventoryManager.isEnabled) InventoryManager.disable() + if (toggleInventoryManager && InventoryManager.isEnabled) InventoryManager.disable() /* Turn off auto obsidian if the user wants us to control it */ - if (toggleAutoObsidian.value && AutoObsidian.isEnabled) { + if (toggleAutoObsidian && AutoObsidian.isEnabled) { AutoObsidian.disable() } @@ -233,8 +233,8 @@ object HighwayTools : Module() { private fun SafeClientEvent.updateRenderer() { renderer.clear() - renderer.aFilled = if (filled.value) aFilled.value else 0 - renderer.aOutline = if (outline.value) aOutline.value else 0 + renderer.aFilled = if (filled) aFilled else 0 + renderer.aOutline = if (outline) aOutline else 0 for (blockTask in pendingTasks) { if (blockTask.taskState == TaskState.DONE) continue renderer.add(world.getBlockState(blockTask.blockPos).getSelectedBoundingBox(world, blockTask.blockPos), blockTask.taskState.color) @@ -257,7 +257,7 @@ object HighwayTools : Module() { if (rotateTimer.tick(20L, false)) return val rotation = lastHitVec?.let { RotationUtils.getRotationTo(it) } ?: return - when (interacting.value) { + when (interacting) { InteractMode.SPOOF -> { val packet = PlayerPacketManager.PlayerPacket(rotating = true, rotation = rotation) PlayerPacketManager.addPacket(this@HighwayTools, packet) @@ -316,7 +316,7 @@ object HighwayTools : Module() { private fun generateBluePrint(feetPos: BlockPos) { val basePos = feetPos.down() - if (mode.value != Mode.FLAT) { + if (mode != Mode.FLAT) { val zDirection = startingDirection val xDirection = zDirection.clockwise(if (zDirection.isDiagonal) 1 else 2) val nextPos = basePos.add(zDirection.directionVec) @@ -332,18 +332,18 @@ object HighwayTools : Module() { } private fun generateClear(basePos: BlockPos, xDirection: Direction) { - if (!clearSpace.value) return + if (!clearSpace) return - for (w in 0 until buildWidth.value) { - for (h in 0 until clearHeight.value) { - val x = w - buildWidth.value / 2 + for (w in 0 until buildWidth) { + for (h in 0 until clearHeight) { + val x = w - buildWidth / 2 val pos = basePos.add(xDirection.directionVec.multiply(x)).up(h) - if (mode.value == Mode.HIGHWAY && h == 0 && isRail(w)) { + if (mode == Mode.HIGHWAY && h == 0 && isRail(w)) { continue } - if (mode.value == Mode.HIGHWAY) { + if (mode == Mode.HIGHWAY) { blueprintNew[pos] = Blocks.AIR } else { blueprintNew[pos.up()] = Blocks.AIR @@ -353,14 +353,14 @@ object HighwayTools : Module() { } private fun generateBase(basePos: BlockPos, xDirection: Direction) { - val baseMaterial = if (mode.value == Mode.TUNNEL) fillerMat else material + val baseMaterial = if (mode == Mode.TUNNEL) fillerMat else material - for (w in 0 until buildWidth.value) { - val x = w - buildWidth.value / 2 + for (w in 0 until buildWidth) { + val x = w - buildWidth / 2 val pos = basePos.add(xDirection.directionVec.multiply(x)) - if (mode.value == Mode.HIGHWAY && isRail(w)) { - for (y in 1..railingHeight.value) { + if (mode == Mode.HIGHWAY && isRail(w)) { + for (y in 1..railingHeight) { blueprintNew[pos.up(y)] = baseMaterial } } else { @@ -369,14 +369,14 @@ object HighwayTools : Module() { } } - private fun isRail(w: Int) = railing.value && w !in 1 until buildWidth.value - 1 + private fun isRail(w: Int) = railing && w !in 1 until buildWidth - 1 private fun generateFlat(basePos: BlockPos) { // Base - for (w1 in 0 until buildWidth.value) { - for (w2 in 0 until buildWidth.value) { - val x = w1 - buildWidth.value / 2 - val z = w2 - buildWidth.value / 2 + for (w1 in 0 until buildWidth) { + for (w2 in 0 until buildWidth) { + val x = w1 - buildWidth / 2 + val z = w2 - buildWidth / 2 val pos = basePos.add(x, 0, z) blueprintNew[pos] = material @@ -384,12 +384,12 @@ object HighwayTools : Module() { } // Clear - if (!clearSpace.value) return - for (w1 in -buildWidth.value..buildWidth.value) { - for (w2 in -buildWidth.value..buildWidth.value) { - for (y in 1 until clearHeight.value) { - val x = w1 - buildWidth.value / 2 - val z = w2 - buildWidth.value / 2 + if (!clearSpace) return + for (w1 in -buildWidth..buildWidth) { + for (w2 in -buildWidth..buildWidth) { + for (y in 1 until clearHeight) { + val x = w1 - buildWidth / 2 + val z = w2 - buildWidth / 2 val pos = basePos.add(x, y, z) blueprintNew[pos] = Blocks.AIR @@ -418,7 +418,7 @@ object HighwayTools : Module() { } private fun SafeClientEvent.getNextPos(): BlockPos { - val baseMaterial = if (mode.value == Mode.TUNNEL) fillerMat else material + val baseMaterial = if (mode == Mode.TUNNEL) fillerMat else material var lastPos = currentBlockPos for (step in 1..2) { @@ -446,7 +446,7 @@ object HighwayTools : Module() { (lastTask ?: sortedTasks.firstOrNull())?.let { val dist = player.getPositionEyes(1f).distanceTo(it.blockPos) - 0.7 - if (dist > maxReach.value) { + if (dist > maxReach) { refreshData() } else { doNextTask(sortedTasks) @@ -474,7 +474,7 @@ object HighwayTools : Module() { if (it.taskState != TaskState.DONE) { val timeout = it.taskState.stuckTimeout if (it.stuckTicks > timeout) { - if (debugMessages.value == DebugMessages.IMPORTANT) { + if (debugMessages == DebugMessages.IMPORTANT) { sendChatMessage("Stuck for more than $timeout ticks, refreshing data.") } refreshData() @@ -524,7 +524,7 @@ object HighwayTools : Module() { when (world.getBlockState(blockTask.blockPos).block) { Blocks.AIR -> { totalBlocksDestroyed++ - waitTicks = tickDelayBreak.value + waitTicks = tickDelayBreak if (blockTask.block == material || blockTask.block == fillerMat) { blockTask.updateState(TaskState.PLACE) } else { @@ -641,7 +641,7 @@ object HighwayTools : Module() { } else -> { if (!WorldUtils.isPlaceable(blockTask.blockPos)) { - if (debugMessages.value != DebugMessages.OFF) sendChatMessage("Invalid place position: " + blockTask.blockPos) + if (debugMessages != DebugMessages.OFF) sendChatMessage("Invalid place position: " + blockTask.blockPos) refreshData() return } @@ -656,7 +656,7 @@ object HighwayTools : Module() { blockTask.updateState(TaskState.PLACED) - waitTicks = tickDelayPlace.value + waitTicks = tickDelayPlace } } } @@ -668,7 +668,7 @@ object HighwayTools : Module() { when { blockTask.block == material && block != material -> return false - mode.value == Mode.TUNNEL && blockTask.block == fillerMat && block != fillerMat -> return false + mode == Mode.TUNNEL && blockTask.block == fillerMat && block != fillerMat -> return false blockTask.block == Blocks.AIR && block != Blocks.AIR -> return false } @@ -716,7 +716,7 @@ object HighwayTools : Module() { it.block is BlockLiquid && it.getValue(BlockLiquid.LEVEL) != 0 } - if (player.distanceTo(neighbour) > maxReach.value) continue + if (player.distanceTo(neighbour) > maxReach) continue foundLiquid = true val found = ArrayList>() @@ -776,7 +776,7 @@ object HighwayTools : Module() { when (world.getBlockState(blockTask.blockPos).block) { Blocks.NETHERRACK -> { - waitTicks = tickDelayBreak.value + waitTicks = tickDelayBreak defaultScope.launch { delay(10L) onMainThreadSafe { @@ -825,8 +825,8 @@ object HighwayTools : Module() { } if (!isVisible(blockTask.blockPos)) { - if (illegalPlacements.value) { - if (debugMessages.value == DebugMessages.ALL) { + if (illegalPlacements) { + if (debugMessages == DebugMessages.ALL) { sendChatMessage("Trying to place through wall ${blockTask.blockPos}") } } else { @@ -889,7 +889,7 @@ object HighwayTools : Module() { } private fun printEnable() { - if (info.value) { + if (info) { StringBuilder(2).run { append("$chatName Module started." + "\n §9> §7Direction: §a${startingDirection.displayName}§r") @@ -903,14 +903,14 @@ object HighwayTools : Module() { append("\n §9> §7Coordinate: §a${startingBlockPos.z}§r") } } - if (startingBlockPos.y in 117..119 && mode.value != Mode.TUNNEL) append("\n §9> §cCheck coordinate Y / altitude and make sure to move around Y 120 for the correct height") + if (startingBlockPos.y in 117..119 && mode != Mode.TUNNEL) append("\n §9> §cCheck coordinate Y / altitude and make sure to move around Y 120 for the correct height") sendChatMessage(toString()) } } } private fun printDisable() { - if (info.value) { + if (info) { StringBuilder(2).run { append( "$chatName Module stopped." + @@ -990,7 +990,7 @@ object HighwayTools : Module() { " §7ETA: §9$hoursLeft:$minutesLeft:$secondsLeft" ) - if (printDebug.value) { + if (printDebug) { statistics.addAll(getQueue()) } From 1cacbc21fe0ebc574fd25f54904fa2539d83e129 Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 5 Jan 2021 00:51:31 +0100 Subject: [PATCH 205/390] First iteration of virtual packet sounds Not sure if they are the correct sounds all the time. --- .../kami/module/modules/misc/HighwayTools.kt | 60 ++++++++++++++----- .../me/zeroeightsix/kami/util/WorldUtils.kt | 7 --- 2 files changed, 44 insertions(+), 23 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 07ff51157f..091634797a 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -6,6 +6,7 @@ import kotlinx.coroutines.launch import me.zeroeightsix.kami.event.Phase import me.zeroeightsix.kami.event.SafeClientEvent import me.zeroeightsix.kami.event.events.OnUpdateWalkingPlayerEvent +import me.zeroeightsix.kami.event.events.PacketEvent import me.zeroeightsix.kami.event.events.RenderWorldEvent import me.zeroeightsix.kami.manager.managers.PlayerPacketManager import me.zeroeightsix.kami.module.Module @@ -35,8 +36,10 @@ import net.minecraft.init.Blocks import net.minecraft.init.SoundEvents import net.minecraft.network.play.client.CPacketEntityAction import net.minecraft.network.play.client.CPacketPlayerDigging +import net.minecraft.network.play.server.SPacketBlockChange import net.minecraft.util.EnumFacing import net.minecraft.util.EnumHand +import net.minecraft.util.SoundCategory import net.minecraft.util.math.BlockPos import net.minecraft.util.math.RayTraceResult import net.minecraft.util.math.Vec3d @@ -78,6 +81,7 @@ object HighwayTools : Module() { private val toggleAutoObsidian = register(Settings.booleanBuilder("ToggleAutoObsidian").withValue(true).withVisibility { page.value == Page.BEHAVIOR }) // config + private val fakeSounds = register(Settings.booleanBuilder("Sounds").withValue(true).withVisibility { page.value == Page.CONFIG }) private val info = register(Settings.booleanBuilder("ShowInfo").withValue(true).withVisibility { page.value == Page.CONFIG }) private val printDebug = register(Settings.booleanBuilder("ShowQueue").withValue(false).withVisibility { page.value == Page.CONFIG }) private val debugMessages = register(Settings.enumBuilder(DebugMessages::class.java, "Debug").withValue(DebugMessages.IMPORTANT).withVisibility { page.value == Page.CONFIG }) @@ -230,6 +234,28 @@ object HighwayTools : Module() { doRotation() } + + safeListener { event -> + if (event.packet is SPacketBlockChange) { + val pos = event.packet.blockPosition + if (isInsideSelection(pos)) { + val blockStateNow = world.getBlockState(pos) + val blockStateAfter = event.packet.blockState + if (blockStateNow.block != blockStateAfter.block && fakeSounds.value) { + when { + blockStateAfter.block == Blocks.AIR -> { + val soundType = blockStateNow.block.getSoundType(blockStateNow, world, pos, player) + world.playSound(player, pos, soundType.breakSound, SoundCategory.BLOCKS, (soundType.getVolume() + 1.0f) / 2.0f, soundType.getPitch() * 0.8f) + } + blockStateNow.block == Blocks.AIR -> { + val soundType = blockStateAfter.block.getSoundType(blockStateAfter, world, pos, player) + world.playSound(player, pos, soundType.placeSound, SoundCategory.BLOCKS, (soundType.getVolume() + 1.0f) / 2.0f, soundType.getPitch() * 0.8f) + } + } + } + } + } + } } private fun SafeClientEvent.updateRenderer() { @@ -798,26 +824,28 @@ object HighwayTools : Module() { rotateTimer.reset() when (world.getBlockState(blockTask.blockPos).block) { - Blocks.NETHERRACK -> { - waitTicks = tickDelayBreak.value - defaultScope.launch { - delay(10L) - onMainThreadSafe { - connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, blockTask.blockPos, side)) - player.swingArm(EnumHand.MAIN_HAND) - } - delay(40L) - onMainThreadSafe { - connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, blockTask.blockPos, side)) - player.swingArm(EnumHand.MAIN_HAND) - blockTask.updateState(TaskState.BROKEN) - } - } - } + Blocks.NETHERRACK -> dispatchInstantBreakThread(blockTask, side) else -> dispatchGenericMineThread(blockTask, side) } } + private fun dispatchInstantBreakThread(blockTask: BlockTask, facing: EnumFacing) { + waitTicks = tickDelayBreak.value + defaultScope.launch { + delay(10L) + onMainThreadSafe { + connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, blockTask.blockPos, facing)) + player.swingArm(EnumHand.MAIN_HAND) + } + delay(40L) + onMainThreadSafe { + connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, blockTask.blockPos, facing)) + player.swingArm(EnumHand.MAIN_HAND) + blockTask.updateState(TaskState.BROKEN) + } + } + } + /* Dispatches a thread to mine any non-netherrack blocks generically */ private fun dispatchGenericMineThread(blockTask: BlockTask, facing: EnumFacing) { val action = if (blockTask.taskState == TaskState.BREAKING) { diff --git a/src/main/java/me/zeroeightsix/kami/util/WorldUtils.kt b/src/main/java/me/zeroeightsix/kami/util/WorldUtils.kt index a12190880f..32d492202b 100644 --- a/src/main/java/me/zeroeightsix/kami/util/WorldUtils.kt +++ b/src/main/java/me/zeroeightsix/kami/util/WorldUtils.kt @@ -253,13 +253,6 @@ object WorldUtils { val placePacket = CPacketPlayerTryUseItemOnBlock(pos, side, EnumHand.MAIN_HAND, hitVecOffset.x.toFloat(), hitVecOffset.y.toFloat(), hitVecOffset.z.toFloat()) connection.sendPacket(placePacket) player.swingArm(EnumHand.MAIN_HAND) - - val itemStack = PlayerPacketManager.getHoldingItemStack() - val block = (itemStack.item as? ItemBlock?)?.block ?: return - val metaData = itemStack.metadata - val blockState = block.getStateForPlacement(world, pos, side, hitVecOffset.x.toFloat(), hitVecOffset.y.toFloat(), hitVecOffset.z.toFloat(), metaData, player, EnumHand.MAIN_HAND) - val soundType = blockState.block.getSoundType(blockState, world, pos, player) - world.playSound(player, pos, soundType.placeSound, SoundCategory.BLOCKS, (soundType.getVolume() + 1.0f) / 2.0f, soundType.getPitch() * 0.8f) } } \ No newline at end of file From 1396421ed121bb469975e52ab9d1342abfeb4421 Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Mon, 4 Jan 2021 19:27:08 -0500 Subject: [PATCH 206/390] Re added HighwayTools hud --- .../gui/hudgui/elements/misc/HighwayToolsHud.kt | 17 +++++++++++++++++ .../me/zeroeightsix/kami/util/math/Direction.kt | 16 ++++++++-------- 2 files changed, 25 insertions(+), 8 deletions(-) create mode 100644 src/main/java/me/zeroeightsix/kami/gui/hudgui/elements/misc/HighwayToolsHud.kt diff --git a/src/main/java/me/zeroeightsix/kami/gui/hudgui/elements/misc/HighwayToolsHud.kt b/src/main/java/me/zeroeightsix/kami/gui/hudgui/elements/misc/HighwayToolsHud.kt new file mode 100644 index 0000000000..6115aa6156 --- /dev/null +++ b/src/main/java/me/zeroeightsix/kami/gui/hudgui/elements/misc/HighwayToolsHud.kt @@ -0,0 +1,17 @@ +package me.zeroeightsix.kami.gui.hudgui.elements.misc + +import me.zeroeightsix.kami.gui.hudgui.LabelHud +import me.zeroeightsix.kami.module.modules.misc.HighwayTools + +object HighwayToolsHud : LabelHud( + name = "HighwayTools", + category = Category.MISC, + description = "Hud for HighwayTools module" +) { + override fun updateText() { + val list = HighwayTools.gatherStatistics() + for (line in list) { + displayText.addLine(line) + } + } +} \ No newline at end of file diff --git a/src/main/java/me/zeroeightsix/kami/util/math/Direction.kt b/src/main/java/me/zeroeightsix/kami/util/math/Direction.kt index c62b10a873..1b478f161e 100644 --- a/src/main/java/me/zeroeightsix/kami/util/math/Direction.kt +++ b/src/main/java/me/zeroeightsix/kami/util/math/Direction.kt @@ -16,14 +16,14 @@ enum class Direction( val directionVec: Vec3i, val isDiagonal: Boolean ) : DisplayEnum { - NORTH("North", "-Z", Vec3i(0, 0, -1)), - NORTH_EAST("North East", "+X -Z", Vec3i(1, 0, -1)), - EAST("East", "+X", Vec3i(1, 0, 0)), - SOUTH_EAST("South East", "+X +Z", Vec3i(1, 0, 1)), - SOUTH("South", "+Z", Vec3i(0, 0, 1)), - SOUTH_WEST("South West", "-X +Z", Vec3i(-1, 0, 1)), - WEST("West", "-X", Vec3i(-1, 0, 0)), - NORTH_WEST("North West", "-X -Z", Vec3i(-1, 0, -1)); + NORTH("North", "-Z", Vec3i(0, 0, -1), false), + NORTH_EAST("North East", "+X -Z", Vec3i(1, 0, -1), true), + EAST("East", "+X", Vec3i(1, 0, 0), false), + SOUTH_EAST("South East", "+X +Z", Vec3i(1, 0, 1), true), + SOUTH("South", "+Z", Vec3i(0, 0, 1), false), + SOUTH_WEST("South West", "-X +Z", Vec3i(-1, 0, 1), true), + WEST("West", "-X", Vec3i(-1, 0, 0), false), + NORTH_WEST("North West", "-X -Z", Vec3i(-1, 0, -1), true); fun clockwise(n: Int = 1) = values()[Math.floorMod((ordinal + n), 8)] From 0dfacbb80a8ec3db3d85a34814d0b64eb16a0bd8 Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Mon, 4 Jan 2021 19:37:29 -0500 Subject: [PATCH 207/390] Cleaned up break sound code --- .../kami/module/modules/misc/HighwayTools.kt | 83 +++++++++---------- 1 file changed, 38 insertions(+), 45 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 5df7007c8f..3499f2f72b 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -64,32 +64,32 @@ object HighwayTools : Module() { private val page by setting("Page", Page.BUILD) // build settings - private val clearSpace by setting("ClearSpace", true, { page == Page.BUILD && mode == Mode.HIGHWAY }) - private val clearHeight by setting("Height", 4, 1..6, 1, { page == Page.BUILD && clearSpace }) - private val buildWidth by setting("Width", 5, 1..9, 1, { page == Page.BUILD }) - private val railing by setting("Railing", true, { page == Page.BUILD && mode == Mode.HIGHWAY }) - private val railingHeight by setting("RailingHeight", 1, 1..4, 1, { railing && page == Page.BUILD && mode == Mode.HIGHWAY }) - private val cornerBlock by setting("CornerBlock", false, { page == Page.BUILD && (mode == Mode.HIGHWAY || mode == Mode.TUNNEL) }) + private val clearSpace by setting("ClearSpace", true, { page == Page.BUILD && mode == Mode.HIGHWAY }) + private val clearHeight by setting("Height", 4, 1..6, 1, { page == Page.BUILD && clearSpace }) + private val buildWidth by setting("Width", 5, 1..9, 1, { page == Page.BUILD }) + private val railing by setting("Railing", true, { page == Page.BUILD && mode == Mode.HIGHWAY }) + private val railingHeight by setting("RailingHeight", 1, 1..4, 1, { railing && page == Page.BUILD && mode == Mode.HIGHWAY }) + private val cornerBlock by setting("CornerBlock", false, { page == Page.BUILD && (mode == Mode.HIGHWAY || mode == Mode.TUNNEL) }) // behavior settings - private val tickDelayPlace by setting("TickDelayPlace", 3, 0..16, 1, { page == Page.BEHAVIOR }) - private val tickDelayBreak by setting("TickDelayBreak", 1, 0..16, 1, { page == Page.BEHAVIOR }) - private val interacting by setting("InteractMode", InteractMode.SPOOF, { page == Page.BEHAVIOR }) - private val illegalPlacements by setting("IllegalPlacements", false, { page == Page.BEHAVIOR }) - private val maxReach by setting("MaxReach", 4.5f, 1.0f..6.0f, 0.1f, { page == Page.BEHAVIOR }) - private val toggleInventoryManager by setting("ToggleInvManager", true, { page == Page.BEHAVIOR }) - private val toggleAutoObsidian by setting("ToggleAutoObsidian", true, { page == Page.BEHAVIOR }) + private val tickDelayPlace by setting("TickDelayPlace", 3, 0..16, 1, { page == Page.BEHAVIOR }) + private val tickDelayBreak by setting("TickDelayBreak", 1, 0..16, 1, { page == Page.BEHAVIOR }) + private val interacting by setting("InteractMode", InteractMode.SPOOF, { page == Page.BEHAVIOR }) + private val illegalPlacements by setting("IllegalPlacements", false, { page == Page.BEHAVIOR }) + private val maxReach by setting("MaxReach", 4.5f, 1.0f..6.0f, 0.1f, { page == Page.BEHAVIOR }) + private val toggleInventoryManager by setting("ToggleInvManager", true, { page == Page.BEHAVIOR }) + private val toggleAutoObsidian by setting("ToggleAutoObsidian", true, { page == Page.BEHAVIOR }) // config private val fakeSounds by setting("Sounds", true, { page == Page.CONFIG }) - private val info by setting("ShowInfo", true, { page == Page.CONFIG }) - private val printDebug by setting("ShowQueue", false, { page == Page.CONFIG }) - private val debugMessages by setting("Debug", DebugMessages.IMPORTANT, { page == Page.CONFIG }) - private val goalRender by setting("GoalRender", false, { page == Page.CONFIG }) - private val filled by setting("Filled", true, { page == Page.CONFIG }) - private val outline by setting("Outline", true, { page == Page.CONFIG }) - private val aFilled by setting("FilledAlpha", 26, 0..255, 1, { filled && page == Page.CONFIG }) - private val aOutline by setting("OutlineAlpha", 91, 0..255, 1, { outline && page == Page.CONFIG }) + private val info by setting("ShowInfo", true, { page == Page.CONFIG }) + private val printDebug by setting("ShowQueue", false, { page == Page.CONFIG }) + private val debugMessages by setting("Debug", DebugMessages.IMPORTANT, { page == Page.CONFIG }) + private val goalRender by setting("GoalRender", false, { page == Page.CONFIG }) + private val filled by setting("Filled", true, { page == Page.CONFIG }) + private val outline by setting("Outline", true, { page == Page.CONFIG }) + private val aFilled by setting("FilledAlpha", 26, 0..255, 1, { filled && page == Page.CONFIG }) + private val aOutline by setting("OutlineAlpha", 91, 0..255, 1, { outline && page == Page.CONFIG }) // internal settings val ignoreBlocks = hashSetOf( @@ -212,6 +212,21 @@ object HighwayTools : Module() { } init { + safeListener { + if (it.packet !is SPacketBlockChange || !fakeSounds) return@safeListener + + val pos = it.packet.blockPosition + if (!isInsideSelection(pos)) return@safeListener + + val prev = world.getBlockState(pos) + val new = it.packet.getBlockState() + + if (prev.block != new.block && new.block == Blocks.AIR) { + val soundType = new.block.getSoundType(new, world, pos, player) + world.playSound(player, pos, soundType.breakSound, SoundCategory.BLOCKS, (soundType.getVolume() + 1.0f) / 2.0f, soundType.getPitch() * 0.8f) + } + } + safeListener { renderer.render(false) } @@ -234,28 +249,6 @@ object HighwayTools : Module() { doRotation() } - - safeListener { event -> - if (event.packet is SPacketBlockChange) { - val pos = event.packet.blockPosition - if (isInsideSelection(pos)) { - val blockStateNow = world.getBlockState(pos) - val blockStateAfter = event.packet.blockState - if (blockStateNow.block != blockStateAfter.block && fakeSounds.value) { - when { - blockStateAfter.block == Blocks.AIR -> { - val soundType = blockStateNow.block.getSoundType(blockStateNow, world, pos, player) - world.playSound(player, pos, soundType.breakSound, SoundCategory.BLOCKS, (soundType.getVolume() + 1.0f) / 2.0f, soundType.getPitch() * 0.8f) - } - blockStateNow.block == Blocks.AIR -> { - val soundType = blockStateAfter.block.getSoundType(blockStateAfter, world, pos, player) - world.playSound(player, pos, soundType.placeSound, SoundCategory.BLOCKS, (soundType.getVolume() + 1.0f) / 2.0f, soundType.getPitch() * 0.8f) - } - } - } - } - } - } } private fun SafeClientEvent.updateRenderer() { @@ -363,7 +356,7 @@ object HighwayTools : Module() { private fun SafeClientEvent.pickTasksInRange() { val removeCandidates = LinkedList() for (task in blueprintNew) { - if (player.getPositionEyes(1f).distanceTo(task.key) > maxReach.value) { + if (player.getPositionEyes(1f).distanceTo(task.key) > maxReach) { removeCandidates.add(task.key) } } @@ -480,7 +473,7 @@ object HighwayTools : Module() { private fun checkFOMO(pos: BlockPos): Boolean { for (task in blueprint) { - if (pos.toVec3d().distanceTo(task.first.toVec3d()) > maxReach.value) return false + if (pos.toVec3d().distanceTo(task.first.toVec3d()) > maxReach) return false } return true } From 9954534cb6f3c881633f9cfe2e406abeaca72051 Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Mon, 4 Jan 2021 20:29:37 -0500 Subject: [PATCH 208/390] Reverted cringe change --- src/main/java/me/zeroeightsix/kami/util/WorldUtils.kt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/me/zeroeightsix/kami/util/WorldUtils.kt b/src/main/java/me/zeroeightsix/kami/util/WorldUtils.kt index 32d492202b..a12190880f 100644 --- a/src/main/java/me/zeroeightsix/kami/util/WorldUtils.kt +++ b/src/main/java/me/zeroeightsix/kami/util/WorldUtils.kt @@ -253,6 +253,13 @@ object WorldUtils { val placePacket = CPacketPlayerTryUseItemOnBlock(pos, side, EnumHand.MAIN_HAND, hitVecOffset.x.toFloat(), hitVecOffset.y.toFloat(), hitVecOffset.z.toFloat()) connection.sendPacket(placePacket) player.swingArm(EnumHand.MAIN_HAND) + + val itemStack = PlayerPacketManager.getHoldingItemStack() + val block = (itemStack.item as? ItemBlock?)?.block ?: return + val metaData = itemStack.metadata + val blockState = block.getStateForPlacement(world, pos, side, hitVecOffset.x.toFloat(), hitVecOffset.y.toFloat(), hitVecOffset.z.toFloat(), metaData, player, EnumHand.MAIN_HAND) + val soundType = blockState.block.getSoundType(blockState, world, pos, player) + world.playSound(player, pos, soundType.placeSound, SoundCategory.BLOCKS, (soundType.getVolume() + 1.0f) / 2.0f, soundType.getPitch() * 0.8f) } } \ No newline at end of file From f3fb00f750db688c0e37257ed0e30e2001341bb3 Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Mon, 4 Jan 2021 20:47:09 -0500 Subject: [PATCH 209/390] Fixed crash and compatiblity between ht and autoobsidian --- .../kami/module/modules/misc/HighwayTools.kt | 17 +++++------------ .../kami/process/AutoObsidianProcess.kt | 2 +- .../kami/process/TemporaryPauseProcess.kt | 2 +- 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 3499f2f72b..66731fae06 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -156,16 +156,7 @@ object HighwayTools : Module() { /* Turn on Auto Obsidian if the user wants us to control it. */ if (toggleAutoObsidian && AutoObsidian.isDisabled && mode != Mode.TUNNEL) { - /* If we have no obsidian, immediately turn on Auto Obsidian */ - if (InventoryUtils.countItemAll(49) == 0) { - AutoObsidian.enable() - } else { - Thread { - /* Wait 1 second because turning both on simultaneously is buggy */ - Thread.sleep(1000L) - AutoObsidian.enable() - }.start() - } + AutoObsidian.enable() } startingBlockPos = mc.player.flooredPosition @@ -222,8 +213,10 @@ object HighwayTools : Module() { val new = it.packet.getBlockState() if (prev.block != new.block && new.block == Blocks.AIR) { - val soundType = new.block.getSoundType(new, world, pos, player) - world.playSound(player, pos, soundType.breakSound, SoundCategory.BLOCKS, (soundType.getVolume() + 1.0f) / 2.0f, soundType.getPitch() * 0.8f) + onMainThreadSafe { + val soundType = new.block.getSoundType(new, world, pos, player) + world.playSound(player, pos, soundType.breakSound, SoundCategory.BLOCKS, (soundType.getVolume() + 1.0f) / 2.0f, soundType.getPitch() * 0.8f) + } } } diff --git a/src/main/java/me/zeroeightsix/kami/process/AutoObsidianProcess.kt b/src/main/java/me/zeroeightsix/kami/process/AutoObsidianProcess.kt index b854e1dd85..10a2e8bd2b 100644 --- a/src/main/java/me/zeroeightsix/kami/process/AutoObsidianProcess.kt +++ b/src/main/java/me/zeroeightsix/kami/process/AutoObsidianProcess.kt @@ -12,7 +12,7 @@ object AutoObsidianProcess : IBaritoneProcess { } override fun priority(): Double { - return 2.0 + return 3.0 } override fun onLostControl() {} diff --git a/src/main/java/me/zeroeightsix/kami/process/TemporaryPauseProcess.kt b/src/main/java/me/zeroeightsix/kami/process/TemporaryPauseProcess.kt index 23b4dc3bb5..db0b1c6652 100644 --- a/src/main/java/me/zeroeightsix/kami/process/TemporaryPauseProcess.kt +++ b/src/main/java/me/zeroeightsix/kami/process/TemporaryPauseProcess.kt @@ -12,7 +12,7 @@ object TemporaryPauseProcess : IBaritoneProcess { } override fun priority(): Double { - return 3.0 + return 5.0 } override fun isActive(): Boolean { From 28f405c0d0cdec475106aa8d9f3e53cb41d4b14f Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 5 Jan 2021 04:46:34 +0100 Subject: [PATCH 210/390] More accurate stat counter --- .../kami/module/modules/misc/HighwayTools.kt | 37 ++++++++++++------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 66731fae06..dd6e5ec89d 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -43,6 +43,8 @@ import net.minecraft.util.SoundCategory import net.minecraft.util.math.BlockPos import net.minecraft.util.math.RayTraceResult import net.minecraft.util.math.Vec3d +import org.kamiblue.commons.extension.ceilToInt +import org.kamiblue.commons.extension.floorToInt import java.util.* import kotlin.collections.ArrayList import kotlin.collections.HashSet @@ -204,7 +206,7 @@ object HighwayTools : Module() { init { safeListener { - if (it.packet !is SPacketBlockChange || !fakeSounds) return@safeListener + if (it.packet !is SPacketBlockChange) return@safeListener val pos = it.packet.blockPosition if (!isInsideSelection(pos)) return@safeListener @@ -212,10 +214,19 @@ object HighwayTools : Module() { val prev = world.getBlockState(pos) val new = it.packet.getBlockState() - if (prev.block != new.block && new.block == Blocks.AIR) { - onMainThreadSafe { - val soundType = new.block.getSoundType(new, world, pos, player) - world.playSound(player, pos, soundType.breakSound, SoundCategory.BLOCKS, (soundType.getVolume() + 1.0f) / 2.0f, soundType.getPitch() * 0.8f) + if (prev.block != new.block) { + when { + new.block == Blocks.AIR -> { + totalBlocksDestroyed++ + if (fakeSounds) { + val soundType = new.block.getSoundType(new, world, pos, player) + world.playSound(player, pos, soundType.breakSound, SoundCategory.BLOCKS, (soundType.getVolume() + 1.0f) / 2.0f, soundType.getPitch() * 0.8f) + } + } + prev.block == Blocks.AIR -> { + totalBlocksPlaced++ + // Wait for it :P + } } } } @@ -224,8 +235,8 @@ object HighwayTools : Module() { renderer.render(false) } - safeListener { event -> - if (event.phase != Phase.PRE) return@safeListener + safeListener { + if (it.phase != Phase.PRE) return@safeListener if (!active) { active = true @@ -333,7 +344,7 @@ object HighwayTools : Module() { val zDirection = startingDirection val xDirection = zDirection.clockwise(if (zDirection.isDiagonal) 1 else 2) - for (x in -12 until 12) { + for (x in -maxReach.floorToInt()..maxReach.ceilToInt()) { val thisPos = basePos.add(zDirection.directionVec.multiply(x)) generateClear(thisPos, xDirection) generateBase(thisPos, xDirection) @@ -461,12 +472,13 @@ object HighwayTools : Module() { if (checkFOMO(pos)) lastPos = pos } + if (currentBlockPos != lastPos) refreshData() return lastPos } - private fun checkFOMO(pos: BlockPos): Boolean { - for (task in blueprint) { - if (pos.toVec3d().distanceTo(task.first.toVec3d()) > maxReach) return false + private fun checkFOMO(origin: BlockPos): Boolean { + for ((pos, _) in blueprint) { + if (origin.toVec3d().distanceTo(pos.toVec3d()) > maxReach) return false } return true } @@ -558,7 +570,6 @@ object HighwayTools : Module() { private fun SafeClientEvent.doBreaking(blockTask: BlockTask) { when (world.getBlockState(blockTask.blockPos).block) { Blocks.AIR -> { - totalBlocksDestroyed++ waitTicks = tickDelayBreak if (blockTask.block == material || blockTask.block == fillerMat) { blockTask.updateState(TaskState.PLACE) @@ -591,7 +602,6 @@ object HighwayTools : Module() { } else { blockTask.updateState(TaskState.DONE) } - totalBlocksDestroyed++ } else -> { blockTask.updateState(TaskState.BREAK) @@ -605,7 +615,6 @@ object HighwayTools : Module() { when { blockTask.block == block && block != Blocks.AIR -> { blockTask.updateState(TaskState.DONE) - totalBlocksPlaced++ } blockTask.block == Blocks.AIR && block != Blocks.AIR -> { blockTask.updateState(TaskState.BREAK) From 628fe8a24572fe967099091ab0ec5e13fb248af0 Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 5 Jan 2021 05:49:27 +0100 Subject: [PATCH 211/390] Sound fix and tunnel mode rework --- .../kami/module/modules/misc/HighwayTools.kt | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index dd6e5ec89d..e038275236 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -220,7 +220,9 @@ object HighwayTools : Module() { totalBlocksDestroyed++ if (fakeSounds) { val soundType = new.block.getSoundType(new, world, pos, player) - world.playSound(player, pos, soundType.breakSound, SoundCategory.BLOCKS, (soundType.getVolume() + 1.0f) / 2.0f, soundType.getPitch() * 0.8f) + onMainThread { + world.playSound(player, pos, soundType.breakSound, SoundCategory.BLOCKS, (soundType.getVolume() + 1.0f) / 2.0f, soundType.getPitch() * 0.8f) + } } } prev.block == Blocks.AIR -> { @@ -347,7 +349,11 @@ object HighwayTools : Module() { for (x in -maxReach.floorToInt()..maxReach.ceilToInt()) { val thisPos = basePos.add(zDirection.directionVec.multiply(x)) generateClear(thisPos, xDirection) - generateBase(thisPos, xDirection) + if (mode != Mode.TUNNEL) generateBase(thisPos, xDirection) + } + if (mode == Mode.TUNNEL) { + blueprintNew[basePos.add(startingDirection.directionVec.multiply(1))] = fillerMat + blueprintNew[basePos.add(startingDirection.directionVec.multiply(2))] = fillerMat } pickTasksInRange() @@ -392,18 +398,16 @@ object HighwayTools : Module() { } private fun generateBase(basePos: BlockPos, xDirection: Direction) { - val baseMaterial = if (mode == Mode.TUNNEL) fillerMat else material - for (w in 0 until buildWidth) { val x = w - buildWidth / 2 val pos = basePos.add(xDirection.directionVec.multiply(x)) if (mode == Mode.HIGHWAY && isRail(w)) { for (y in 1..railingHeight) { - blueprintNew[pos.up(y)] = baseMaterial + blueprintNew[pos.up(y)] = material } } else { - blueprintNew[pos] = baseMaterial + blueprintNew[pos] = material } } } @@ -463,11 +467,11 @@ object HighwayTools : Module() { for (step in 1..2) { val pos = currentBlockPos.add(startingDirection.directionVec.multiply(step)) - if (!blueprintNew.containsKey(pos.down())) break + if (!blueprintNew.containsKey(pos.down()) && mode != Mode.TUNNEL) break if (!world.isAirBlock(pos) || !world.isAirBlock(pos.up())) break val blockBelow = world.getBlockState(pos.down()).block - if (blockBelow != baseMaterial) break + if (blockBelow != baseMaterial && mode != Mode.TUNNEL) break if (checkFOMO(pos)) lastPos = pos } From ec400be2b89239a1650c2025c616846b7b1e198c Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 5 Jan 2021 06:34:38 +0100 Subject: [PATCH 212/390] FOMO fix --- .../me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index e038275236..d1d65f7a21 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -481,8 +481,8 @@ object HighwayTools : Module() { } private fun checkFOMO(origin: BlockPos): Boolean { - for ((pos, _) in blueprint) { - if (origin.toVec3d().distanceTo(pos.toVec3d()) > maxReach) return false + for (task in pendingTasks) { + if (task.taskState != TaskState.DONE && origin.distanceTo(task.blockPos) > maxReach) return false } return true } From e844bd4857d3ce8f4b81fe62eb815c4f5dc0179c Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Tue, 5 Jan 2021 00:47:11 -0500 Subject: [PATCH 213/390] Optimized range filtering --- .../kami/module/modules/misc/HighwayTools.kt | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index d1d65f7a21..5f4527f41b 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -357,22 +357,15 @@ object HighwayTools : Module() { } pickTasksInRange() - } else { generateFlat(basePos) } } private fun SafeClientEvent.pickTasksInRange() { - val removeCandidates = LinkedList() - for (task in blueprintNew) { - if (player.getPositionEyes(1f).distanceTo(task.key) > maxReach) { - removeCandidates.add(task.key) - } - } - - for (task in removeCandidates) { - blueprintNew.remove(task) + val eyePos = player.getPositionEyes(1f) + blueprintNew.keys.removeIf { + eyePos.distanceTo(it) - 0.7 > maxReach } } From bab97db127e3eec873a0b9ed36b621220d641844 Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 5 Jan 2021 07:19:52 +0100 Subject: [PATCH 214/390] Corner block option --- .../kami/module/modules/misc/HighwayTools.kt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 5f4527f41b..366ff5f31a 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -352,8 +352,8 @@ object HighwayTools : Module() { if (mode != Mode.TUNNEL) generateBase(thisPos, xDirection) } if (mode == Mode.TUNNEL) { - blueprintNew[basePos.add(startingDirection.directionVec.multiply(1))] = fillerMat - blueprintNew[basePos.add(startingDirection.directionVec.multiply(2))] = fillerMat + blueprintNew[basePos.add(zDirection.directionVec.multiply(1))] = fillerMat + blueprintNew[basePos.add(zDirection.directionVec.multiply(2))] = fillerMat } pickTasksInRange() @@ -384,7 +384,7 @@ object HighwayTools : Module() { if (mode == Mode.HIGHWAY) { blueprintNew[pos] = Blocks.AIR } else { - blueprintNew[pos.up()] = Blocks.AIR + if (!(isRail(w) && h == 0 && !cornerBlock)) blueprintNew[pos.up()] = Blocks.AIR } } } @@ -396,7 +396,8 @@ object HighwayTools : Module() { val pos = basePos.add(xDirection.directionVec.multiply(x)) if (mode == Mode.HIGHWAY && isRail(w)) { - for (y in 1..railingHeight) { + val startHeight = if (cornerBlock) 0 else 1 + for (y in startHeight..railingHeight) { blueprintNew[pos.up(y)] = material } } else { From b335f0ec5d2f39bea3ec9d756e165def8f4a8e16 Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 5 Jan 2021 09:42:30 +0100 Subject: [PATCH 215/390] Tried to fix isVisible but iam too tired. Hope this helps --- .../kami/module/modules/misc/HighwayTools.kt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 366ff5f31a..c7f983a8cf 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -875,6 +875,7 @@ object HighwayTools : Module() { } } else { blockTask.onStuck() + return } } @@ -900,12 +901,12 @@ object HighwayTools : Module() { val eyePos = player.getPositionEyes(1f) for (side in EnumFacing.values()) { - val blockState = world.getBlockState(pos.offset(side)) + val offPos = pos.offset(side) + val blockState = world.getBlockState(offPos) if (blockState.isFullBlock) continue val rayTraceResult = world.rayTraceBlocks(eyePos, WorldUtils.getHitVec(pos, side), false, false, true) - ?: return true - if (rayTraceResult.typeOfHit == RayTraceResult.Type.BLOCK && rayTraceResult.hitVec.distanceTo(pos) > 1.0) continue - return true + ?: continue + if (rayTraceResult.typeOfHit == RayTraceResult.Type.BLOCK && rayTraceResult.blockPos == offPos && offPos.offset(rayTraceResult.sideHit) == pos) return true } return false From 5aef571f919adef5bb97afb712ea81b128007a0b Mon Sep 17 00:00:00 2001 From: Christian Date: Wed, 6 Jan 2021 04:25:53 +0100 Subject: [PATCH 216/390] PlaceBlock rework --- .../kami/module/modules/misc/HighwayTools.kt | 53 ++++++++----------- .../me/zeroeightsix/kami/util/WorldUtils.kt | 26 ++++++++- 2 files changed, 45 insertions(+), 34 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index c7f983a8cf..14d4494319 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -17,7 +17,8 @@ import me.zeroeightsix.kami.setting.ModuleConfig.setting import me.zeroeightsix.kami.util.* import me.zeroeightsix.kami.util.EntityUtils.flooredPosition import me.zeroeightsix.kami.util.WorldUtils.placeBlock -import me.zeroeightsix.kami.util.WorldUtils.rayTraceHitVec +import me.zeroeightsix.kami.util.WorldUtils.rayTraceBreakVec +import me.zeroeightsix.kami.util.WorldUtils.rayTracePlaceVec import me.zeroeightsix.kami.util.color.ColorHolder import me.zeroeightsix.kami.util.graphics.ESPRenderer import me.zeroeightsix.kami.util.math.CoordinateConverter.asString @@ -25,7 +26,6 @@ import me.zeroeightsix.kami.util.math.Direction import me.zeroeightsix.kami.util.math.RotationUtils import me.zeroeightsix.kami.util.math.VectorUtils.distanceTo import me.zeroeightsix.kami.util.math.VectorUtils.multiply -import me.zeroeightsix.kami.util.math.VectorUtils.toVec3d import me.zeroeightsix.kami.util.text.MessageSendHelper.sendChatMessage import me.zeroeightsix.kami.util.threads.* import net.minecraft.block.Block @@ -36,6 +36,7 @@ import net.minecraft.init.Blocks import net.minecraft.init.SoundEvents import net.minecraft.network.play.client.CPacketEntityAction import net.minecraft.network.play.client.CPacketPlayerDigging +import net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock import net.minecraft.network.play.server.SPacketBlockChange import net.minecraft.util.EnumFacing import net.minecraft.util.EnumHand @@ -227,7 +228,12 @@ object HighwayTools : Module() { } prev.block == Blocks.AIR -> { totalBlocksPlaced++ - // Wait for it :P + if (fakeSounds) { + val soundType = prev.block.getSoundType(prev, world, pos, player) + onMainThread { + world.playSound(player, pos, soundType.placeSound, SoundCategory.BLOCKS, (soundType.getVolume() + 1.0f) / 2.0f, soundType.getPitch() * 0.8f) + } + } } } } @@ -805,7 +811,7 @@ object HighwayTools : Module() { return } - val rayTraceResult = rayTraceHitVec(blockTask.blockPos) + val rayTraceResult = rayTraceBreakVec(blockTask.blockPos) if (rayTraceResult == null) { blockTask.onStuck() @@ -861,25 +867,20 @@ object HighwayTools : Module() { } private fun SafeClientEvent.placeBlock(blockTask: BlockTask) { - val pair = WorldUtils.getNeighbour(blockTask.blockPos, 1, 6.5f) - ?: run { - sendChatMessage("Can't find neighbour block") - blockTask.onStuck() - return - } + val rayTraceResult = rayTracePlaceVec(blockTask.blockPos) - if (!isVisible(blockTask.blockPos)) { + if (rayTraceResult == null) { if (illegalPlacements) { if (debugMessages == DebugMessages.ALL) { sendChatMessage("Trying to place through wall ${blockTask.blockPos}") } } else { blockTask.onStuck() - return } + return } - lastHitVec = WorldUtils.getHitVec(pair.second, pair.first) + lastHitVec = rayTraceResult.hitVec rotateTimer.reset() connection.sendPacket(CPacketEntityAction(player, CPacketEntityAction.Action.START_SNEAKING)) @@ -887,7 +888,10 @@ object HighwayTools : Module() { defaultScope.launch { delay(10L) onMainThreadSafe { - placeBlock(pair.second, pair.first) + val offsetHitVec = lastHitVec ?: return@onMainThreadSafe + val placePacket = CPacketPlayerTryUseItemOnBlock(rayTraceResult.blockPos, rayTraceResult.sideHit, EnumHand.MAIN_HAND, offsetHitVec.x.toFloat(), offsetHitVec.y.toFloat(), offsetHitVec.z.toFloat()) + connection.sendPacket(placePacket) + player.swingArm(EnumHand.MAIN_HAND) } delay(10L) @@ -897,21 +901,6 @@ object HighwayTools : Module() { } } - private fun SafeClientEvent.isVisible(pos: BlockPos): Boolean { - val eyePos = player.getPositionEyes(1f) - - for (side in EnumFacing.values()) { - val offPos = pos.offset(side) - val blockState = world.getBlockState(offPos) - if (blockState.isFullBlock) continue - val rayTraceResult = world.rayTraceBlocks(eyePos, WorldUtils.getHitVec(pos, side), false, false, true) - ?: continue - if (rayTraceResult.typeOfHit == RayTraceResult.Type.BLOCK && rayTraceResult.blockPos == offPos && offPos.offset(rayTraceResult.sideHit) == pos) return true - } - - return false - } - private fun isInsideSelection(pos: BlockPos): Boolean { return blueprintNew.containsKey(pos) } @@ -969,7 +958,7 @@ object HighwayTools : Module() { } } - fun getBlueprintStats(): Pair { + private fun getBlueprintStats(): Pair { var materialUsed = 0 var fillerMatUsed = 0 for ((_, b) in blueprint) { @@ -1060,7 +1049,7 @@ object HighwayTools : Module() { var taskState: TaskState, var block: Block ) { - var ranTicks = 0; private set + private var ranTicks = 0 var stuckTicks = 0; private set fun updateState(state: TaskState) { @@ -1086,7 +1075,7 @@ object HighwayTools : Module() { stuckTicks++ } - fun onUpdate() { + private fun onUpdate() { stuckTicks = 0 ranTicks = 0 } diff --git a/src/main/java/me/zeroeightsix/kami/util/WorldUtils.kt b/src/main/java/me/zeroeightsix/kami/util/WorldUtils.kt index a12190880f..7f68d4c341 100644 --- a/src/main/java/me/zeroeightsix/kami/util/WorldUtils.kt +++ b/src/main/java/me/zeroeightsix/kami/util/WorldUtils.kt @@ -4,6 +4,7 @@ import kotlinx.coroutines.delay import me.zeroeightsix.kami.event.SafeClientEvent import me.zeroeightsix.kami.manager.managers.PlayerPacketManager import me.zeroeightsix.kami.util.math.RotationUtils +import me.zeroeightsix.kami.util.math.VectorUtils.toVec3d import me.zeroeightsix.kami.util.math.corners import me.zeroeightsix.kami.util.threads.runSafeSuspend import net.minecraft.client.Minecraft @@ -132,19 +133,40 @@ object WorldUtils { return Vec3d(vec.x * 0.5 + 0.5, vec.y * 0.5 + 0.5, vec.z * 0.5 + 0.5) } - fun SafeClientEvent.rayTraceHitVec(pos: BlockPos) : RayTraceResult? { + fun SafeClientEvent.rayTraceBreakVec(pos: BlockPos) : RayTraceResult? { val eyePos = player.getPositionEyes(1f) val bb = world.getBlockState(pos).getSelectedBoundingBox(world, pos) return world.rayTraceBlocks(eyePos, bb.center, false, false, true)?.takeIf { it.isEqualTo(pos) } ?: bb.corners(0.95).mapNotNull { corner -> - world.rayTraceBlocks(eyePos, corner, false, false, true)?.takeIf { it.isEqualTo(pos) } + world.rayTraceBlocks(eyePos, corner, false, false, true)?.takeIf { + it.isEqualTo(pos) + } }.minByOrNull { it.hitVec?.distanceTo(eyePos) ?: 69420.0 } } + fun SafeClientEvent.rayTracePlaceVec(pos: BlockPos) : RayTraceResult? { + val eyePos = player.getPositionEyes(1f) + + for (side in EnumFacing.values()) { + val offPos = pos.offset(side) + val blockState = world.getBlockState(offPos) + if (!blockState.isFullBlock) continue + val bb = blockState.getSelectedBoundingBox(world, offPos) + return bb.corners(0.95).mapNotNull { corner -> + world.rayTraceBlocks(eyePos, corner, false, false, true)?.takeIf { + it.isEqualTo(offPos) + } + }.minByOrNull { + it.hitVec?.distanceTo(eyePos) ?: 69420.0 + } + } + return null + } + private fun RayTraceResult.isEqualTo(pos: BlockPos) = typeOfHit == RayTraceResult.Type.BLOCK && blockPos == pos suspend fun buildStructure( From a66a241f0c1df024ca588e7769b2f68ddb918708 Mon Sep 17 00:00:00 2001 From: Christian Date: Wed, 6 Jan 2021 05:12:33 +0100 Subject: [PATCH 217/390] Placement debug only temorary --- .../kami/module/modules/misc/HighwayTools.kt | 26 +++++++++++++++++-- .../me/zeroeightsix/kami/util/WorldUtils.kt | 1 + 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 14d4494319..fe6c59b72f 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -7,6 +7,7 @@ import me.zeroeightsix.kami.event.Phase import me.zeroeightsix.kami.event.SafeClientEvent import me.zeroeightsix.kami.event.events.OnUpdateWalkingPlayerEvent import me.zeroeightsix.kami.event.events.PacketEvent +import me.zeroeightsix.kami.event.events.RenderOverlayEvent import me.zeroeightsix.kami.event.events.RenderWorldEvent import me.zeroeightsix.kami.manager.managers.PlayerPacketManager import me.zeroeightsix.kami.module.Module @@ -16,16 +17,18 @@ import me.zeroeightsix.kami.process.HighwayToolsProcess import me.zeroeightsix.kami.setting.ModuleConfig.setting import me.zeroeightsix.kami.util.* import me.zeroeightsix.kami.util.EntityUtils.flooredPosition -import me.zeroeightsix.kami.util.WorldUtils.placeBlock import me.zeroeightsix.kami.util.WorldUtils.rayTraceBreakVec import me.zeroeightsix.kami.util.WorldUtils.rayTracePlaceVec import me.zeroeightsix.kami.util.color.ColorHolder -import me.zeroeightsix.kami.util.graphics.ESPRenderer +import me.zeroeightsix.kami.util.graphics.* import me.zeroeightsix.kami.util.math.CoordinateConverter.asString import me.zeroeightsix.kami.util.math.Direction import me.zeroeightsix.kami.util.math.RotationUtils +import me.zeroeightsix.kami.util.math.Vec2d import me.zeroeightsix.kami.util.math.VectorUtils.distanceTo import me.zeroeightsix.kami.util.math.VectorUtils.multiply +import me.zeroeightsix.kami.util.math.VectorUtils.toVec3d +import me.zeroeightsix.kami.util.math.corners import me.zeroeightsix.kami.util.text.MessageSendHelper.sendChatMessage import me.zeroeightsix.kami.util.threads.* import net.minecraft.block.Block @@ -46,6 +49,8 @@ import net.minecraft.util.math.RayTraceResult import net.minecraft.util.math.Vec3d import org.kamiblue.commons.extension.ceilToInt import org.kamiblue.commons.extension.floorToInt +import org.kamiblue.event.listener.listener +import org.lwjgl.opengl.GL11 import java.util.* import kotlin.collections.ArrayList import kotlin.collections.HashSet @@ -261,6 +266,23 @@ object HighwayTools : Module() { doRotation() } + + safeListener { + val taskPos = lastTask?.blockPos ?: currentBlockPos + val bb = world.getBlockState(taskPos).getSelectedBoundingBox(world, taskPos) + val vertices = mutableListOf() + for (vec in bb.corners(0.90)) { + vertices.add(Vec2d(ProjectionUtils.toScaledScreenPos(vec))) + } + val vertexHelper = VertexHelper(GlStateUtils.useVbo()) + GL11.glDisable(GL11.GL_TEXTURE_2D) + for (vec in vertices) { + RenderUtils2D.drawLine(vertexHelper, Vec2d(ProjectionUtils.toScaledScreenPos(player.getPositionEyes(1f))), vec, 2F, ColorHolder(55, 255, 55)) + } + val hitVec = lastHitVec ?: return@safeListener + RenderUtils2D.drawLine(vertexHelper, Vec2d(ProjectionUtils.toScaledScreenPos(player.getPositionEyes(1f))), Vec2d(ProjectionUtils.toScaledScreenPos(hitVec)),3F, ColorHolder(255, 55, 55)) + GL11.glEnable(GL11.GL_TEXTURE_2D) + } } private fun SafeClientEvent.updateRenderer() { diff --git a/src/main/java/me/zeroeightsix/kami/util/WorldUtils.kt b/src/main/java/me/zeroeightsix/kami/util/WorldUtils.kt index 7f68d4c341..c35ff61e19 100644 --- a/src/main/java/me/zeroeightsix/kami/util/WorldUtils.kt +++ b/src/main/java/me/zeroeightsix/kami/util/WorldUtils.kt @@ -156,6 +156,7 @@ object WorldUtils { val blockState = world.getBlockState(offPos) if (!blockState.isFullBlock) continue val bb = blockState.getSelectedBoundingBox(world, offPos) + return bb.corners(0.95).mapNotNull { corner -> world.rayTraceBlocks(eyePos, corner, false, false, true)?.takeIf { it.isEqualTo(offPos) From 87c1eb85337b4737ec555ffaa245025e31ca0cdc Mon Sep 17 00:00:00 2001 From: Christian Date: Wed, 6 Jan 2021 05:34:25 +0100 Subject: [PATCH 218/390] Start is without tasks behind the player --- .../me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index fe6c59b72f..2d6056ac39 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -392,8 +392,9 @@ object HighwayTools : Module() { private fun SafeClientEvent.pickTasksInRange() { val eyePos = player.getPositionEyes(1f) + val startBlocker = startingBlockPos.add(startingDirection.clockwise(4).directionVec.multiply(maxReach.toInt() - 1)) blueprintNew.keys.removeIf { - eyePos.distanceTo(it) - 0.7 > maxReach + eyePos.distanceTo(it) - 0.7 > maxReach || startBlocker.distanceTo(it) < maxReach } } From 06edeb11c413bcc4cb0961a27d4223d3847e7c9f Mon Sep 17 00:00:00 2001 From: Christian Date: Thu, 7 Jan 2021 03:29:10 +0100 Subject: [PATCH 219/390] Hud merge fix --- .../kami/gui/hudgui/elements/misc/HighwayToolsHud.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/me/zeroeightsix/kami/gui/hudgui/elements/misc/HighwayToolsHud.kt b/src/main/java/me/zeroeightsix/kami/gui/hudgui/elements/misc/HighwayToolsHud.kt index 6115aa6156..342c99f2cc 100644 --- a/src/main/java/me/zeroeightsix/kami/gui/hudgui/elements/misc/HighwayToolsHud.kt +++ b/src/main/java/me/zeroeightsix/kami/gui/hudgui/elements/misc/HighwayToolsHud.kt @@ -1,5 +1,6 @@ package me.zeroeightsix.kami.gui.hudgui.elements.misc +import me.zeroeightsix.kami.event.SafeClientEvent import me.zeroeightsix.kami.gui.hudgui.LabelHud import me.zeroeightsix.kami.module.modules.misc.HighwayTools @@ -8,7 +9,7 @@ object HighwayToolsHud : LabelHud( category = Category.MISC, description = "Hud for HighwayTools module" ) { - override fun updateText() { + override fun SafeClientEvent.updateText() { val list = HighwayTools.gatherStatistics() for (line in list) { displayText.addLine(line) From e5eb3f5e0d1ad3d171b5a724a701f12d84272652 Mon Sep 17 00:00:00 2001 From: Christian Date: Thu, 7 Jan 2021 09:58:18 +0100 Subject: [PATCH 220/390] Fix wrong placeBlock and RusherHack incompatibility --- .../kami/module/modules/misc/AutoObsidian.kt | 4 +- .../kami/module/modules/misc/HighwayTools.kt | 42 +++++------------- .../me/zeroeightsix/kami/util/WorldUtils.kt | 13 +++--- .../kami/util/math/BoundingBoxUtils.kt | 44 +++++++++++++++++++ 4 files changed, 65 insertions(+), 38 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt index 9a1fc50dc0..27c34c1ff5 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt @@ -157,8 +157,8 @@ object AutoObsidian : Module() { if (state != State.DONE) renderer.render(clear = false, cull = true) } - safeListener { event -> - if (event.phase != Phase.PRE || rotateTimer.tick(20L, false)) return@safeListener + safeListener { event -> + if (event.phase != TickEvent.Phase.START || rotateTimer.tick(20L, false)) return@safeListener val rotation = lastHitVec?.let { getRotationTo(it) } ?: return@safeListener when (rotationMode) { diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 2d6056ac39..ad757ce19c 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -21,14 +21,11 @@ import me.zeroeightsix.kami.util.WorldUtils.rayTraceBreakVec import me.zeroeightsix.kami.util.WorldUtils.rayTracePlaceVec import me.zeroeightsix.kami.util.color.ColorHolder import me.zeroeightsix.kami.util.graphics.* +import me.zeroeightsix.kami.util.math.* import me.zeroeightsix.kami.util.math.CoordinateConverter.asString -import me.zeroeightsix.kami.util.math.Direction -import me.zeroeightsix.kami.util.math.RotationUtils -import me.zeroeightsix.kami.util.math.Vec2d import me.zeroeightsix.kami.util.math.VectorUtils.distanceTo import me.zeroeightsix.kami.util.math.VectorUtils.multiply import me.zeroeightsix.kami.util.math.VectorUtils.toVec3d -import me.zeroeightsix.kami.util.math.corners import me.zeroeightsix.kami.util.text.MessageSendHelper.sendChatMessage import me.zeroeightsix.kami.util.threads.* import net.minecraft.block.Block @@ -47,6 +44,7 @@ import net.minecraft.util.SoundCategory import net.minecraft.util.math.BlockPos import net.minecraft.util.math.RayTraceResult import net.minecraft.util.math.Vec3d +import net.minecraftforge.fml.common.gameevent.TickEvent import org.kamiblue.commons.extension.ceilToInt import org.kamiblue.commons.extension.floorToInt import org.kamiblue.event.listener.listener @@ -248,8 +246,8 @@ object HighwayTools : Module() { renderer.render(false) } - safeListener { - if (it.phase != Phase.PRE) return@safeListener + safeListener { event -> + if (event.phase != TickEvent.Phase.START) return@safeListener if (!active) { active = true @@ -266,23 +264,6 @@ object HighwayTools : Module() { doRotation() } - - safeListener { - val taskPos = lastTask?.blockPos ?: currentBlockPos - val bb = world.getBlockState(taskPos).getSelectedBoundingBox(world, taskPos) - val vertices = mutableListOf() - for (vec in bb.corners(0.90)) { - vertices.add(Vec2d(ProjectionUtils.toScaledScreenPos(vec))) - } - val vertexHelper = VertexHelper(GlStateUtils.useVbo()) - GL11.glDisable(GL11.GL_TEXTURE_2D) - for (vec in vertices) { - RenderUtils2D.drawLine(vertexHelper, Vec2d(ProjectionUtils.toScaledScreenPos(player.getPositionEyes(1f))), vec, 2F, ColorHolder(55, 255, 55)) - } - val hitVec = lastHitVec ?: return@safeListener - RenderUtils2D.drawLine(vertexHelper, Vec2d(ProjectionUtils.toScaledScreenPos(player.getPositionEyes(1f))), Vec2d(ProjectionUtils.toScaledScreenPos(hitVec)),3F, ColorHolder(255, 55, 55)) - GL11.glEnable(GL11.GL_TEXTURE_2D) - } } private fun SafeClientEvent.updateRenderer() { @@ -394,7 +375,7 @@ object HighwayTools : Module() { val eyePos = player.getPositionEyes(1f) val startBlocker = startingBlockPos.add(startingDirection.clockwise(4).directionVec.multiply(maxReach.toInt() - 1)) blueprintNew.keys.removeIf { - eyePos.distanceTo(it) - 0.7 > maxReach || startBlocker.distanceTo(it) < maxReach + eyePos.distanceTo(it) > maxReach - 0.7 || startBlocker.distanceTo(it) < maxReach } } @@ -519,12 +500,13 @@ object HighwayTools : Module() { } (lastTask ?: sortedTasks.firstOrNull())?.let { - val dist = player.getPositionEyes(1f).distanceTo(it.blockPos) - 0.7 - if (dist > maxReach) { - refreshData() - } else { - doNextTask(sortedTasks) - } +// val dist = player.getPositionEyes(1f).distanceTo(it.blockPos) - 0.7 +// if (dist > maxReach) { +// refreshData() +// } else { +// doNextTask(sortedTasks) +// } + doNextTask(sortedTasks) } } else { if (checkDoneTasks()) { diff --git a/src/main/java/me/zeroeightsix/kami/util/WorldUtils.kt b/src/main/java/me/zeroeightsix/kami/util/WorldUtils.kt index c35ff61e19..f7277269fe 100644 --- a/src/main/java/me/zeroeightsix/kami/util/WorldUtils.kt +++ b/src/main/java/me/zeroeightsix/kami/util/WorldUtils.kt @@ -4,8 +4,8 @@ import kotlinx.coroutines.delay import me.zeroeightsix.kami.event.SafeClientEvent import me.zeroeightsix.kami.manager.managers.PlayerPacketManager import me.zeroeightsix.kami.util.math.RotationUtils -import me.zeroeightsix.kami.util.math.VectorUtils.toVec3d import me.zeroeightsix.kami.util.math.corners +import me.zeroeightsix.kami.util.math.faceCorners import me.zeroeightsix.kami.util.threads.runSafeSuspend import net.minecraft.client.Minecraft import net.minecraft.entity.Entity @@ -150,22 +150,23 @@ object WorldUtils { fun SafeClientEvent.rayTracePlaceVec(pos: BlockPos) : RayTraceResult? { val eyePos = player.getPositionEyes(1f) + val possibleTraces = mutableListOf() for (side in EnumFacing.values()) { val offPos = pos.offset(side) val blockState = world.getBlockState(offPos) if (!blockState.isFullBlock) continue val bb = blockState.getSelectedBoundingBox(world, offPos) - - return bb.corners(0.95).mapNotNull { corner -> - world.rayTraceBlocks(eyePos, corner, false, false, true)?.takeIf { - it.isEqualTo(offPos) + val rt = bb.faceCorners(side.opposite, 0.85).mapNotNull { corner -> + world.rayTraceBlocks(eyePos, corner, false, false, false)?.takeIf { + it.isEqualTo(offPos) && it.sideHit == side.opposite } }.minByOrNull { it.hitVec?.distanceTo(eyePos) ?: 69420.0 } + possibleTraces.add(rt) } - return null + return possibleTraces.minByOrNull { it.hitVec?.distanceTo(eyePos) ?: 69420.0 } } private fun RayTraceResult.isEqualTo(pos: BlockPos) = typeOfHit == RayTraceResult.Type.BLOCK && blockPos == pos diff --git a/src/main/java/me/zeroeightsix/kami/util/math/BoundingBoxUtils.kt b/src/main/java/me/zeroeightsix/kami/util/math/BoundingBoxUtils.kt index 1dec35c5d0..d3a7ad53fd 100644 --- a/src/main/java/me/zeroeightsix/kami/util/math/BoundingBoxUtils.kt +++ b/src/main/java/me/zeroeightsix/kami/util/math/BoundingBoxUtils.kt @@ -35,4 +35,48 @@ fun AxisAlignedBB.side(side: EnumFacing, scale: Double = 0.5) : Vec3d { val lengths = lengths val sideDirectionVec = side.directionVec.toVec3d() return lengths * sideDirectionVec * scale + center +} + +fun AxisAlignedBB.faceCorners(facing: EnumFacing, scale: Double) : Array { + + val selectedCorners = mutableListOf() + when (facing) { + EnumFacing.UP -> { + selectedCorners.add(Vec3d(minX + scale * xLength, maxY - 0.01, minZ + scale * zLength)) + selectedCorners.add(Vec3d(maxX - scale * xLength, maxY - 0.01, minZ + scale * zLength)) + selectedCorners.add(Vec3d(minX + scale * xLength, maxY - 0.01, maxZ - scale * zLength)) + selectedCorners.add(Vec3d(maxX - scale * xLength, maxY - 0.01, maxZ - scale * zLength)) + } + EnumFacing.DOWN -> { + selectedCorners.add(Vec3d(minX + scale * xLength, minY + 0.01, minZ + scale * zLength)) + selectedCorners.add(Vec3d(maxX - scale * xLength, minY + 0.01, minZ + scale * zLength)) + selectedCorners.add(Vec3d(minX + scale * xLength, minY + 0.01, maxZ - scale * zLength)) + selectedCorners.add(Vec3d(maxX - scale * xLength, minY + 0.01, maxZ - scale * zLength)) + } + EnumFacing.NORTH -> { + selectedCorners.add(Vec3d(minX + scale * xLength, minY + scale * yLength, minZ + 0.01)) + selectedCorners.add(Vec3d(maxX - scale * xLength, minY + scale * yLength, minZ + 0.01)) + selectedCorners.add(Vec3d(minX + scale * xLength, maxY - scale * yLength, minZ + 0.01)) + selectedCorners.add(Vec3d(maxX - scale * xLength, maxY - scale * yLength, minZ + 0.01)) + } + EnumFacing.EAST -> { + selectedCorners.add(Vec3d(maxX - 0.01, minY + scale * yLength, minZ + scale * zLength)) + selectedCorners.add(Vec3d(maxX - 0.01, minY + scale * yLength, minZ + scale * zLength)) + selectedCorners.add(Vec3d(maxX - 0.01, maxY - scale * yLength, maxZ - scale * zLength)) + selectedCorners.add(Vec3d(maxX - 0.01, maxY - scale * yLength, maxZ - scale * zLength)) + } + EnumFacing.SOUTH -> { + selectedCorners.add(Vec3d(minX + scale * xLength, minY + scale * yLength, maxZ - 0.01)) + selectedCorners.add(Vec3d(maxX - scale * xLength, minY + scale * yLength, maxZ - 0.01)) + selectedCorners.add(Vec3d(minX + scale * xLength, maxY - scale * yLength, maxZ - 0.01)) + selectedCorners.add(Vec3d(maxX - scale * xLength, maxY - scale * yLength, maxZ - 0.01)) + } + EnumFacing.WEST -> { + selectedCorners.add(Vec3d(minX + 0.01, minY + scale * yLength, minZ + scale * zLength)) + selectedCorners.add(Vec3d(minX + 0.01, minY + scale * yLength, minZ + scale * zLength)) + selectedCorners.add(Vec3d(minX + 0.01, maxY - scale * yLength, maxZ - scale * zLength)) + selectedCorners.add(Vec3d(minX + 0.01, maxY - scale * yLength, maxZ - scale * zLength)) + } + } + return selectedCorners.toTypedArray() } \ No newline at end of file From 1228039ab91c23998da3d04a89e78fece63d5cbd Mon Sep 17 00:00:00 2001 From: Christian Date: Fri, 8 Jan 2021 20:26:11 +0100 Subject: [PATCH 221/390] Merge fixes --- .../kami/module/modules/misc/HighwayTools.kt | 92 +++++++++---------- 1 file changed, 45 insertions(+), 47 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index ad757ce19c..f76d45f3d8 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -58,14 +58,12 @@ import kotlin.collections.LinkedHashMap * @author Avanatiker * @since 20/08/2020 */ -@Module.Info( +object HighwayTools : Module( name = "HighwayTools", description = "Be the grief a step a head.", - category = Module.Category.MISC, + category = Category.MISC, modulePriority = 10 -) -object HighwayTools : Module() { - +) { private val mode by setting("Mode", Mode.HIGHWAY) private val page by setting("Page", Page.BUILD) @@ -151,64 +149,64 @@ object HighwayTools : Module() { return isEnabled && active } - override fun onEnable() { - if (mc.player == null) { - disable() - return - } + init { + onEnable { + if (mc.player == null) { + disable() + return@onEnable + } - /* Turn on inventory manager if the users wants us to control it */ - if (toggleInventoryManager && InventoryManager.isDisabled) InventoryManager.enable() + /* Turn on inventory manager if the users wants us to control it */ + if (toggleInventoryManager && InventoryManager.isDisabled) InventoryManager.enable() - /* Turn on Auto Obsidian if the user wants us to control it. */ - if (toggleAutoObsidian && AutoObsidian.isDisabled && mode != Mode.TUNNEL) { - AutoObsidian.enable() - } + /* Turn on Auto Obsidian if the user wants us to control it. */ + if (toggleAutoObsidian && AutoObsidian.isDisabled && mode != Mode.TUNNEL) { + AutoObsidian.enable() + } - startingBlockPos = mc.player.flooredPosition - currentBlockPos = startingBlockPos - startingDirection = Direction.fromEntity(mc.player) + startingBlockPos = mc.player.flooredPosition + currentBlockPos = startingBlockPos + startingDirection = Direction.fromEntity(mc.player) - startTime = System.currentTimeMillis() - totalBlocksPlaced = 0 - totalBlocksDestroyed = 0 + startTime = System.currentTimeMillis() + totalBlocksPlaced = 0 + totalBlocksDestroyed = 0 - baritoneSettingAllowPlace = BaritoneUtils.settings?.allowPlace?.value ?: true - BaritoneUtils.settings?.allowPlace?.value = false + baritoneSettingAllowPlace = BaritoneUtils.settings?.allowPlace?.value ?: true + BaritoneUtils.settings?.allowPlace?.value = false - if (!goalRender) { - baritoneSettingRenderGoal = BaritoneUtils.settings?.renderGoal?.value ?: true - BaritoneUtils.settings?.renderGoal?.value = false - } + if (!goalRender) { + baritoneSettingRenderGoal = BaritoneUtils.settings?.renderGoal?.value ?: true + BaritoneUtils.settings?.renderGoal?.value = false + } - runSafe { - refreshData() - printEnable() + runSafe { + refreshData() + printEnable() + } } - } - override fun onDisable() { - if (mc.player == null) return + onDisable { + if (mc.player == null) return@onDisable - active = false + active = false - BaritoneUtils.settings?.allowPlace?.value = baritoneSettingAllowPlace - if (!goalRender) BaritoneUtils.settings?.renderGoal?.value = baritoneSettingRenderGoal + BaritoneUtils.settings?.allowPlace?.value = baritoneSettingAllowPlace + if (!goalRender) BaritoneUtils.settings?.renderGoal?.value = baritoneSettingRenderGoal - /* Turn off inventory manager if the users wants us to control it */ - if (toggleInventoryManager && InventoryManager.isEnabled) InventoryManager.disable() + /* Turn off inventory manager if the users wants us to control it */ + if (toggleInventoryManager && InventoryManager.isEnabled) InventoryManager.disable() - /* Turn off auto obsidian if the user wants us to control it */ - if (toggleAutoObsidian && AutoObsidian.isEnabled) { - AutoObsidian.disable() - } + /* Turn off auto obsidian if the user wants us to control it */ + if (toggleAutoObsidian && AutoObsidian.isEnabled) { + AutoObsidian.disable() + } - lastTask = null + lastTask = null - printDisable() - } + printDisable() + } - init { safeListener { if (it.packet !is SPacketBlockChange) return@safeListener From 198ef4d47b6c4c0e9cd9862dcb3020e746de2540 Mon Sep 17 00:00:00 2001 From: Christian Date: Thu, 21 Jan 2021 07:33:34 +0100 Subject: [PATCH 222/390] Fix basic workflow --- .../kami/module/modules/misc/HighwayTools.kt | 32 +- .../module/modules/player/PacketLogger.kt | 320 ++++++++++++++---- 2 files changed, 278 insertions(+), 74 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index fa6a3172e3..1e7cbe06ce 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -458,27 +458,27 @@ internal object HighwayTools : Module( private fun SafeClientEvent.getNextPos(): BlockPos { val baseMaterial = if (mode == Mode.TUNNEL) fillerMat else material - var lastPos = currentBlockPos + var nextPos = currentBlockPos - for (step in 1..2) { - val pos = currentBlockPos.add(startingDirection.directionVec.multiply(step)) + for (step in 1..3) { + val possiblePos = currentBlockPos.add(startingDirection.directionVec.multiply(step)) - if (!blueprintNew.containsKey(pos.down()) && mode != Mode.TUNNEL) break - if (!world.isAirBlock(pos) || !world.isAirBlock(pos.up())) break +// if (!blueprintNew.containsKey(possiblePos.down()) && mode != Mode.TUNNEL) break + if (!world.isAirBlock(possiblePos) || !world.isAirBlock(possiblePos.up())) break - val blockBelow = world.getBlockState(pos.down()).block + val blockBelow = world.getBlockState(possiblePos.down()).block if (blockBelow != baseMaterial && mode != Mode.TUNNEL) break - if (checkFOMO(pos)) lastPos = pos + if (checkFOMO(possiblePos)) nextPos = possiblePos } - if (currentBlockPos != lastPos) refreshData() - return lastPos + if (currentBlockPos != nextPos) refreshData() + return nextPos } private fun checkFOMO(origin: BlockPos): Boolean { for (task in pendingTasks) { - if (task.taskState != TaskState.DONE && origin.distanceTo(task.blockPos) > maxReach) return false + if (task.taskState != TaskState.DONE && origin.distanceTo(task.blockPos) > maxReach - 1.0) return false } return true } @@ -957,7 +957,7 @@ internal object HighwayTools : Module( fillerMat -> fillerMatUsed++ } } - // TODO: Make it dynamic for several depth layers + // TODO: Update to new dynamic blueprint return Pair(materialUsed / 2, fillerMatUsed / 2) } @@ -1005,13 +1005,13 @@ internal object HighwayTools : Module( " §7Position: §9(${currentTask?.blockPos?.asString()})", "§rDebug", " §7Stuck ticks: §9${lastTask?.stuckTicks?.toString() ?: "N/A"}", - //" §7Pathing: §9$pathing", +// " §7Pathing: §9$pathing", "§rEstimations", " §7${material.localizedName} (main material): §9$materialLeft + ($indirectMaterialLeft)", " §7${fillerMat.localizedName} (filler material): §9$fillerMatLeft", - " §7Paving distance left: §9$pavingLeftAll", - //" §7Estimated destination: §9(${relativeDirection(currentBlockPos, pavingLeft, 0).asString()})", - " §7ETA: §9$hoursLeft:$minutesLeft:$secondsLeft" +// " §7Paving distance left: §9$pavingLeftAll", +// " §7Estimated destination: §9(${currentBlockPos.add(startingDirection.directionVec.multiply(pavingLeft))})", +// " §7ETA: §9$hoursLeft:$minutesLeft:$secondsLeft" ) if (printDebug) { @@ -1045,7 +1045,7 @@ internal object HighwayTools : Module( fun updateState(state: TaskState) { if (state == taskState) return taskState = state - onUpdate() + if (taskState == TaskState.PLACE && state == TaskState.PLACED) onUpdate() } fun updateMaterial(material: Block) { diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/player/PacketLogger.kt b/src/main/java/me/zeroeightsix/kami/module/modules/player/PacketLogger.kt index 6890e24ef8..3932b1fbae 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/player/PacketLogger.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/player/PacketLogger.kt @@ -1,100 +1,304 @@ package me.zeroeightsix.kami.module.modules.player -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.launch import me.zeroeightsix.kami.KamiMod +import me.zeroeightsix.kami.event.events.ConnectionEvent import me.zeroeightsix.kami.event.events.PacketEvent -import me.zeroeightsix.kami.mixin.extension.pitch -import me.zeroeightsix.kami.mixin.extension.yaw +import me.zeroeightsix.kami.mixin.extension.* import me.zeroeightsix.kami.module.Category import me.zeroeightsix.kami.module.Module -import me.zeroeightsix.kami.util.text.MessageSendHelper -import me.zeroeightsix.kami.util.threads.defaultScope +import me.zeroeightsix.kami.util.text.MessageSendHelper.sendChatMessage +import me.zeroeightsix.kami.util.threads.onMainThread import me.zeroeightsix.kami.util.threads.safeListener -import net.minecraft.network.play.client.CPacketPlayer -import net.minecraft.network.play.client.CPacketPlayerDigging +import net.minecraft.network.play.client.* +import net.minecraft.network.play.server.* import net.minecraftforge.fml.common.gameevent.TickEvent -import java.io.File +import java.io.* import java.text.SimpleDateFormat import java.util.* +import kotlin.ConcurrentModificationException internal object PacketLogger : Module( name = "PacketLogger", description = "Logs sent packets to a file", category = Category.PLAYER ) { - private val append by setting("Append", false) - private val clear = setting("Clear", false) + private val showClientTicks by setting("ShowClientTicks", true) + private val logInChat by setting("LogInChat", false) + private val packetsFrom by setting("LogPacketsFrom", Type.BOTH) + private val ignoreKeepAlive by setting("IgnoreKeepAlive", true) + private val ignoreChunkLoading by setting("IgnoreChunkLoading", true) + private val ignoreUnknown by setting("IgnoreUnknownPackets", false) + private val ignoreChat by setting("IgnoreChat", true) - private val file = File("${KamiMod.DIRECTORY}packet_logger.txt") - private val lines = Collections.synchronizedList(ArrayList()) - private val sdf = SimpleDateFormat("HH:mm:ss.SSS") + val sdf = SimpleDateFormat("HH-mm-ss_SSS") + val sdflog = SimpleDateFormat("HH:mm:ss.SSS") + private var filename = "" + private val lines = ArrayList() + + private var start = 0L + private var last = 0L + + enum class Type { + CLIENT, SERVER, BOTH + } init { onEnable { - if (append) read() + if (mc.player == null) { + disable() + return@onEnable + } + onMainThread { + start = System.currentTimeMillis() + } + + filename = "KAMIBluePackets_${sdf.format(Date())}.csv" + lines.add("From,Packet Name,Time Since Start (ms),Time Since Last (ms),Data\n") + sendChatMessage("$chatName started.") } onDisable { - write() + if (mc.player != null) write() + sendChatMessage("$chatName stopped.") } - safeListener { - lines.add("${sdf.format(Date())}\n${it.packet.javaClass.simpleName}\n${it.packet.javaClass}\n${it.packet}") - when (it.packet) { - is CPacketPlayerDigging -> { - lines.add("\nMining - ${it.packet.position}@${it.packet.facing} - ${it.packet.action}") - } - is CPacketPlayer -> { - lines.add("\nRotation - Pitch: ${it.packet.pitch} Yaw: ${it.packet.yaw}") + safeListener { + if (packetsFrom == Type.SERVER || packetsFrom == Type.BOTH) { + when (it.packet) { + is SPacketEntityTeleport -> { + add(Type.SERVER, it.packet.javaClass.simpleName, + "x: ${it.packet.x} " + + "y: ${it.packet.y} " + + "z: ${it.packet.z} " + + "pitch: ${it.packet.pitch} " + + "yaw: ${it.packet.yaw} " + + "entityId: ${it.packet.entityId}") + } + is SPacketEntityMetadata -> { + var data = "dataEntries: " + for (entry in it.packet.dataManagerEntries) { + data += "> isDirty: ${entry.isDirty} " + + "key: ${entry.key} " + + "value: ${entry.value} " + } + add(Type.SERVER, it.packet.javaClass.simpleName, data) + } + is SPacketUnloadChunk -> { + if (!ignoreChunkLoading) { + add(Type.SERVER, it.packet.javaClass.simpleName, + "x: ${it.packet.x} " + + "z: ${it.packet.z}") + } + } + is SPacketDestroyEntities -> { + var entries = "entityIDs: " + for (entry in it.packet.entityIDs) { + entries += "> $entry " + } + add(Type.SERVER, it.packet.javaClass.simpleName, entries) + } + is SPacketPlayerPosLook -> { + var flags = "flags: " + for (entry in it.packet.flags) { + flags += "> ${entry.name} " + } + add(Type.SERVER, it.packet.javaClass.simpleName, + "x: ${it.packet.x} " + + "y: ${it.packet.y} " + + "z: ${it.packet.z} " + + "pitch: ${it.packet.pitch} " + + "yaw: ${it.packet.yaw} " + + "teleportId: ${it.packet.teleportId}") + + } + is SPacketBlockChange -> { + add(Type.SERVER, it.packet.javaClass.simpleName, + "x: ${it.packet.blockPosition.x} " + + "y: ${it.packet.blockPosition.y} " + + "z: ${it.packet.blockPosition.z}") + } + is SPacketMultiBlockChange -> { + var changedBlocks = "changedBlocks: " + for (changedBlock in it.packet.changedBlocks) { + changedBlocks += "> x: ${changedBlock.pos.x} y: ${changedBlock.pos.y} z: ${changedBlock.pos.z} " + } + add(Type.SERVER, it.packet.javaClass.simpleName, changedBlocks) + } + is SPacketTimeUpdate -> { + add(Type.SERVER, it.packet.javaClass.simpleName, + "totalWorldTime: ${it.packet.totalWorldTime} " + + "worldTime: ${it.packet.worldTime}") + } + is SPacketChat -> { + if (!ignoreChat) { + add(Type.SERVER, it.packet.javaClass.simpleName, + "unformattedText: ${it.packet.chatComponent.unformattedText} " + + "type: ${it.packet.type} " + + "isSystem: ${it.packet.isSystem}") + } + } + is SPacketTeams -> { + add(Type.SERVER, it.packet.javaClass.simpleName, + "action: ${it.packet.action} " + + "displayName: ${it.packet.displayName} " + + "color: ${it.packet.color}") + } + is SPacketChunkData -> { + add(Type.SERVER, it.packet.javaClass.simpleName, + "chunkX: ${it.packet.chunkX} " + + "chunkZ: ${it.packet.chunkZ} " + + "extractedSize: ${it.packet.extractedSize}") + } + is SPacketEntityProperties -> { + add(Type.SERVER, it.packet.javaClass.simpleName, + "entityId: ${it.packet.entityId}") + } + is SPacketUpdateTileEntity -> { + add(Type.SERVER, it.packet.javaClass.simpleName, + "posX: ${it.packet.pos.x} " + + "posY: ${it.packet.pos.y} " + + "posZ: ${it.packet.pos.z}") + } + is SPacketSpawnObject -> { + add(Type.SERVER, it.packet.javaClass.simpleName, + "entityID: ${it.packet.entityID} " + + "data: ${it.packet.data}") + } + is SPacketKeepAlive -> { + if (!ignoreKeepAlive) { + add(Type.SERVER, it.packet.javaClass.simpleName, + "id: ${it.packet.id}") + } + } + else -> { + if (!ignoreUnknown) { + add(Type.SERVER, it.packet.javaClass.simpleName, "Not Registered in PacketLogger.kt") + } + } } + if (logInChat) sendChatMessage(lines.joinToString()) } - lines.add("\n\n") } - safeListener { - if (player.ticksExisted % 200 == 0) write() + /* Listen to PostSend and not Send since packets can get cancelled before we actually send them */ + safeListener { + if (packetsFrom == Type.CLIENT || packetsFrom == Type.BOTH ) { + when (it.packet) { + is CPacketAnimation -> { + add(Type.CLIENT, it.packet.javaClass.simpleName, + "hand: ${it.packet.hand}") + } + is CPacketPlayer.Rotation -> { + add(Type.CLIENT, it.packet.javaClass.simpleName, + "pitch: ${it.packet.pitch} "+ + "yaw: ${it.packet.yaw} " + + "onGround: ${it.packet.isOnGround}") + } + is CPacketPlayer.Position -> { + add(Type.CLIENT, it.packet.javaClass.simpleName, + "x: ${it.packet.x} " + + "y: ${it.packet.y} " + + "z: ${it.packet.z} " + + "onGround: ${it.packet.isOnGround}") + } + is CPacketPlayer.PositionRotation -> { + add(Type.CLIENT, it.packet.javaClass.simpleName, + "x: ${it.packet.x} " + + "y: ${it.packet.y} " + + "z: ${it.packet.z} " + + "pitch: ${it.packet.pitch} " + + "yaw: ${it.packet.yaw} " + + "onGround: ${it.packet.isOnGround}") + } + is CPacketPlayerDigging -> { + add(Type.CLIENT, it.packet.javaClass.simpleName, + "positionX: ${it.packet.position.x} " + + "positionY: ${it.packet.position.y} " + + "positionZ: ${it.packet.position.z} " + + "facing: ${it.packet.facing} " + + "action: ${it.packet.action} ") + } + is CPacketEntityAction -> { + add(Type.CLIENT, it.packet.javaClass.simpleName, + "action: ${it.packet.action} " + + "auxData: ${it.packet.auxData}") + } + is CPacketUseEntity -> { + add(Type.CLIENT, it.packet.javaClass.simpleName, + "action: ${it.packet.action} " + + "hand: ${it.packet.hand} " + + "hitVecX: ${it.packet.hitVec.x} " + + "hitVecY: ${it.packet.hitVec.y} " + + "hitVecZ: ${it.packet.hitVec.z}") + } + is CPacketPlayerTryUseItem -> { + add(Type.CLIENT, it.packet.javaClass.simpleName, + "hand: ${it.packet.hand}") + } + is CPacketConfirmTeleport -> { + add(Type.CLIENT, it.packet.javaClass.simpleName, + "teleportId: ${it.packet.teleportId}") + } + is CPacketChatMessage -> { + if (!ignoreChat) { + add(Type.SERVER, it.packet.javaClass.simpleName, + "message: ${it.packet.message}") + } + } + is CPacketKeepAlive -> { + if (!ignoreKeepAlive) { + add(Type.CLIENT, it.packet.javaClass.simpleName, + "key: ${it.packet.key}") + } + } + else -> { + if (!ignoreUnknown) { + add(Type.CLIENT, it.packet.javaClass.simpleName, "Not Registered in PacketLogger.kt") + } + } + } + if (logInChat) sendChatMessage(lines.joinToString()) + } } - } - private fun write() { - defaultScope.launch(Dispatchers.IO) { - try { - file.bufferedWriter().use { - lines.forEach(it::write) - } - } catch (e: Exception) { - KamiMod.LOG.error("$chatName Error saving!", e) + safeListener { + if (showClientTicks) { + if (it.phase == TickEvent.Phase.START) lines.add("Tick Pulse - Realtime: ${sdflog.format(Date())} - Runtime: ${System.currentTimeMillis() - start}ms\n") + if (player.ticksExisted % 200 == 0) write() } + } - lines.clear() + safeListener { + disable() } } - private fun read() { - defaultScope.launch(Dispatchers.IO) { - lines.clear() - - try { - file.bufferedReader().forEachLine { - lines.add(it) + private fun write() { + try { + FileWriter(filename).also { + for (line in lines) it.write(line) + it.close() + } + } catch (e: Exception) { + when (e) { + is IOException, + is ConcurrentModificationException -> { + KamiMod.LOG.error("$chatName Error saving!") + e.printStackTrace() } - } catch (e: Exception) { - KamiMod.LOG.error("$chatName Error loading!", e) + else -> throw e } } + lines.clear() } - init { - clear.consumers.add { _, input -> - if (input) { - lines.clear() - write() - MessageSendHelper.sendChatMessage("$chatName Packet log cleared!") - false - } else { - input - } - } + /** + * Writes a line to the csv following the format: + * from (client or server), packet name, time since start, time since last packet, packet data + */ + private fun add(from: Type, packetName: String, data: String) { + lines.add("${from.name},$packetName,${System.currentTimeMillis() - start},${System.currentTimeMillis() - last},$data") + lines.add("\n") + last = System.currentTimeMillis() } -} \ No newline at end of file +} From 61804a051827d26efaf294348028eb1020a99038 Mon Sep 17 00:00:00 2001 From: Christian Date: Mon, 25 Jan 2021 08:54:57 +0100 Subject: [PATCH 223/390] Work in progress. Cleanup pending --- .../kami/module/modules/misc/HighwayTools.kt | 113 +++++++++--------- 1 file changed, 55 insertions(+), 58 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 1e7cbe06ce..e39cd53177 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -75,6 +75,7 @@ internal object HighwayTools : Module( private val interacting by setting("InteractMode", InteractMode.SPOOF, { page == Page.BEHAVIOR }) private val illegalPlacements by setting("IllegalPlacements", false, { page == Page.BEHAVIOR }) private val maxReach by setting("MaxReach", 4.5f, 1.0f..6.0f, 0.1f, { page == Page.BEHAVIOR }) + private val tickDelayCheck by setting("TickDelayCheck", 2, 1..128, 1, { page == Page.BEHAVIOR }) private val toggleInventoryManager by setting("ToggleInvManager", true, { page == Page.BEHAVIOR }) private val toggleAutoObsidian by setting("ToggleAutoObsidian", true, { page == Page.BEHAVIOR }) @@ -117,7 +118,7 @@ internal object HighwayTools : Module( private var waitTicks = 0 // Rotation - private var lastHitVec: Vec3d? = null + private var lastHitVec = Vec3d.ZERO private val rotateTimer = TickTimer(TimeUnit.TICKS) // Pathing @@ -485,21 +486,24 @@ internal object HighwayTools : Module( private fun SafeClientEvent.runTasks() { if (pendingTasks.isNotEmpty()) { - val sortedTasks = pendingTasks.sortedBy { - it.taskState.priority + - player.getPositionEyes(1f).distanceTo(it.blockPos) * 2 + - it.stuckTicks * 10 / it.taskState.stuckTimeout - } +// (startingBlockPos.distanceTo(player.position) / startingBlockPos.distanceTo(it.blockPos)) * player.distanceTo(it.blockPos) * (lastHitVec.distanceTo(it.blockPos) * 2) + + val sortedTasks = pendingTasks.sortedWith( + compareBy { + it.taskState.ordinal + }.thenBy { + it.stuckTicks + }.thenBy { + startingBlockPos.distanceTo(it.blockPos) + }.thenBy { + player.distanceTo(it.blockPos) + }.thenBy { + lastHitVec?.distanceTo(it.blockPos) + } + ) + doTask(sortedTasks[0]) - (lastTask ?: sortedTasks.firstOrNull())?.let { -// val dist = player.getPositionEyes(1f).distanceTo(it.blockPos) - 0.7 -// if (dist > maxReach) { -// refreshData() -// } else { -// doNextTask(sortedTasks) -// } - doNextTask(sortedTasks) - } + if (sortedTasks[0].taskState.ordinal < 2) runTasks() } else { if (checkDoneTasks()) { doneTasks.clear() @@ -510,34 +514,6 @@ internal object HighwayTools : Module( } } - private fun SafeClientEvent.doNextTask(sortedTasks: List) { - if (waitTicks > 0) { - waitTicks-- - return - } - - lastTask?.let { - doTask(it) - - if (it.taskState != TaskState.DONE) { - val timeout = it.taskState.stuckTimeout - if (it.stuckTicks > timeout) { - if (debugMessages == DebugMessages.IMPORTANT) { - sendChatMessage("Stuck for more than $timeout ticks, refreshing data.") - } - refreshData() - } - return - } - } - - for (task in sortedTasks) { - doTask(task) - lastTask = task - if (task.taskState != TaskState.DONE) break - } - } - private fun SafeClientEvent.doTask(blockTask: BlockTask) { blockTask.onTick() @@ -560,6 +536,9 @@ internal object HighwayTools : Module( TaskState.PLACE, TaskState.LIQUID_SOURCE, TaskState.LIQUID_FLOW -> { doPlace(blockTask) } + TaskState.PENDING -> { + sendChatMessage("PENDING.") + } } } @@ -822,6 +801,7 @@ internal object HighwayTools : Module( waitTicks = tickDelayBreak defaultScope.launch { delay(10L) + blockTask.updateState(TaskState.PENDING) onMainThreadSafe { connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, blockTask.blockPos, facing)) player.swingArm(EnumHand.MAIN_HAND) @@ -830,8 +810,9 @@ internal object HighwayTools : Module( onMainThreadSafe { connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, blockTask.blockPos, facing)) player.swingArm(EnumHand.MAIN_HAND) - blockTask.updateState(TaskState.BROKEN) } + delay(50L * tickDelayCheck) + blockTask.updateState(TaskState.BROKEN) } } @@ -876,6 +857,7 @@ internal object HighwayTools : Module( connection.sendPacket(CPacketEntityAction(player, CPacketEntityAction.Action.START_SNEAKING)) defaultScope.launch { + blockTask.updateState(TaskState.PENDING) delay(10L) onMainThreadSafe { val offsetHitVec = lastHitVec ?: return@onMainThreadSafe @@ -883,11 +865,12 @@ internal object HighwayTools : Module( connection.sendPacket(placePacket) player.swingArm(EnumHand.MAIN_HAND) } - delay(10L) onMainThreadSafe { connection.sendPacket(CPacketEntityAction(player, CPacketEntityAction.Action.STOP_SNEAKING)) } + delay(50L * tickDelayCheck) + blockTask.updateState(TaskState.PLACED) } } @@ -1021,7 +1004,7 @@ internal object HighwayTools : Module( return statistics } - private fun getQueue(): List { + private fun SafeClientEvent.getQueue(): List { val message = ArrayList() message.add("QUEUE:") addTaskToMessageList(message, pendingTasks) @@ -1030,8 +1013,21 @@ internal object HighwayTools : Module( return message } - private fun addTaskToMessageList(list: ArrayList, tasks: Collection) { - for (blockTask in tasks) list.add(" " + blockTask.block.localizedName + "@(" + blockTask.blockPos.asString() + ") Priority: " + blockTask.taskState.ordinal + " State: " + blockTask.taskState.toString()) + private fun SafeClientEvent.addTaskToMessageList(list: ArrayList, tasks: Collection) { + val sortedTasks = tasks.sortedWith( + compareBy { + it.taskState.ordinal + }.thenBy { + it.stuckTicks + }.thenBy { + startingBlockPos.distanceTo(it.blockPos) + }.thenBy { + player.distanceTo(it.blockPos) + }.thenBy { + lastHitVec?.distanceTo(it.blockPos) + } + ) + for (blockTask in sortedTasks) list.add(" " + blockTask.block.localizedName + "@(" + blockTask.blockPos.asString() + ") Priority: " + blockTask.taskState.ordinal + " State: " + blockTask.taskState.toString()) } class BlockTask( @@ -1081,16 +1077,17 @@ internal object HighwayTools : Module( override fun hashCode() = blockPos.hashCode() } - enum class TaskState(val priority: Int, val stuckThreshold: Int, val stuckTimeout: Int, val color: ColorHolder) { - DONE(0, 69420, 0x22, ColorHolder(50, 50, 50)), - LIQUID_SOURCE(1, 100, 100, ColorHolder(120, 41, 240)), - LIQUID_FLOW(20, 80, 80, ColorHolder(120, 41, 240)), - BROKEN(120, 20, 10, ColorHolder(111, 0, 0)), - BREAKING(140, 100, 100, ColorHolder(240, 222, 60)), - EMERGENCY_BREAK(160, 20, 20, ColorHolder(220, 41, 140)), - BREAK(180, 20, 20, ColorHolder(222, 0, 0)), - PLACED(280, 20, 5, ColorHolder(53, 222, 66)), - PLACE(300, 20, 10, ColorHolder(35, 188, 254)) + enum class TaskState(val stuckThreshold: Int, val stuckTimeout: Int, val color: ColorHolder) { + DONE(69420, 0x22, ColorHolder(50, 50, 50)), + BROKEN(20, 10, ColorHolder(111, 0, 0)), + PLACED(20, 5, ColorHolder(53, 222, 66)), + LIQUID_SOURCE(100, 100, ColorHolder(120, 41, 240)), + LIQUID_FLOW(80, 80, ColorHolder(120, 41, 240)), + BREAKING(100, 100, ColorHolder(240, 222, 60)), + EMERGENCY_BREAK(20, 20, ColorHolder(220, 41, 140)), + BREAK(20, 20, ColorHolder(222, 0, 0)), + PLACE(20, 10, ColorHolder(35, 188, 254)), + PENDING(100000, 100000, ColorHolder(0, 0, 0)) } private enum class DebugMessages { From 9ff5c4302239c820e7bca2795fb103ea727eacad Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 26 Jan 2021 01:34:37 +0100 Subject: [PATCH 224/390] Ideal task checking --- .../kami/module/modules/misc/HighwayTools.kt | 64 +++++++++++-------- 1 file changed, 39 insertions(+), 25 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index e39cd53177..612fb39e7e 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -75,7 +75,6 @@ internal object HighwayTools : Module( private val interacting by setting("InteractMode", InteractMode.SPOOF, { page == Page.BEHAVIOR }) private val illegalPlacements by setting("IllegalPlacements", false, { page == Page.BEHAVIOR }) private val maxReach by setting("MaxReach", 4.5f, 1.0f..6.0f, 0.1f, { page == Page.BEHAVIOR }) - private val tickDelayCheck by setting("TickDelayCheck", 2, 1..128, 1, { page == Page.BEHAVIOR }) private val toggleInventoryManager by setting("ToggleInvManager", true, { page == Page.BEHAVIOR }) private val toggleAutoObsidian by setting("ToggleAutoObsidian", true, { page == Page.BEHAVIOR }) @@ -211,23 +210,28 @@ internal object HighwayTools : Module( val prev = world.getBlockState(pos) val new = it.packet.getBlockState() - if (prev.block != new.block) { - when { - new.block == Blocks.AIR -> { - totalBlocksDestroyed++ - if (fakeSounds) { - val soundType = new.block.getSoundType(new, world, pos, player) - onMainThread { - world.playSound(player, pos, soundType.breakSound, SoundCategory.BLOCKS, (soundType.getVolume() + 1.0f) / 2.0f, soundType.getPitch() * 0.8f) + if (isInsideBuild(pos) && prev.block != new.block) { + val task = getTaskFromPos(pos) + if (task.taskState == TaskState.PENDING) { + when { + prev.block != Blocks.AIR && new.block == Blocks.AIR -> { + totalBlocksDestroyed++ + task.updateState(TaskState.BROKEN) + if (fakeSounds) { + val soundType = prev.block.getSoundType(prev, world, pos, player) + onMainThread { + world.playSound(player, pos, soundType.breakSound, SoundCategory.BLOCKS, (soundType.getVolume() + 1.0f) / 2.0f, soundType.getPitch() * 0.8f) + } } } - } - prev.block == Blocks.AIR -> { - totalBlocksPlaced++ - if (fakeSounds) { - val soundType = prev.block.getSoundType(prev, world, pos, player) - onMainThread { - world.playSound(player, pos, soundType.placeSound, SoundCategory.BLOCKS, (soundType.getVolume() + 1.0f) / 2.0f, soundType.getPitch() * 0.8f) + (task.block == material || task.block == fillerMat) && task.block == new.block -> { + totalBlocksPlaced++ + task.updateState(TaskState.PLACED) + if (fakeSounds) { + val soundType = new.block.getSoundType(new, world, pos, player) + onMainThread { + world.playSound(player, pos, soundType.placeSound, SoundCategory.BLOCKS, (soundType.getVolume() + 1.0f) / 2.0f, soundType.getPitch() * 0.8f) + } } } } @@ -341,6 +345,13 @@ internal object HighwayTools : Module( } } + private fun getTaskFromPos(pos: BlockPos): BlockTask { + for (task in pendingTasks) { + if (task.blockPos == pos) return task + } + return BlockTask(BlockPos(0, -1, 0), TaskState.DONE, Blocks.AIR) + } + private fun SafeClientEvent.generateBluePrint(feetPos: BlockPos) { val basePos = feetPos.down() @@ -559,7 +570,7 @@ internal object HighwayTools : Module( } is BlockLiquid -> { var filler = fillerMat - if (isInsideBuild(blockTask.blockPos) || fillerMatLeft == 0) filler = material + if (isInsideBlueprint(blockTask.blockPos) || fillerMatLeft == 0) filler = material if (world.getBlockState(blockTask.blockPos).getValue(BlockLiquid.LEVEL) != 0) { blockTask.updateState(TaskState.LIQUID_FLOW) blockTask.updateMaterial(filler) @@ -628,7 +639,7 @@ internal object HighwayTools : Module( } is BlockLiquid -> { var filler = fillerMat - if (isInsideBuild(blockTask.blockPos) || fillerMatLeft == 0) filler = material + if (isInsideBlueprint(blockTask.blockPos) || fillerMatLeft == 0) filler = material if (world.getBlockState(blockTask.blockPos).getValue(BlockLiquid.LEVEL) != 0) { blockTask.updateState(TaskState.LIQUID_FLOW) blockTask.updateMaterial(filler) @@ -737,7 +748,7 @@ internal object HighwayTools : Module( foundLiquid = true val found = ArrayList>() - val filler = if (isInsideBuild(neighbour)) material else fillerMat + val filler = if (isInsideBlueprint(neighbour)) material else fillerMat for (bt in pendingTasks) { if (bt.blockPos == neighbour) { @@ -800,8 +811,8 @@ internal object HighwayTools : Module( private fun dispatchInstantBreakThread(blockTask: BlockTask, facing: EnumFacing) { waitTicks = tickDelayBreak defaultScope.launch { - delay(10L) blockTask.updateState(TaskState.PENDING) + delay(10L) onMainThreadSafe { connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, blockTask.blockPos, facing)) player.swingArm(EnumHand.MAIN_HAND) @@ -811,8 +822,6 @@ internal object HighwayTools : Module( connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, blockTask.blockPos, facing)) player.swingArm(EnumHand.MAIN_HAND) } - delay(50L * tickDelayCheck) - blockTask.updateState(TaskState.BROKEN) } } @@ -869,8 +878,6 @@ internal object HighwayTools : Module( onMainThreadSafe { connection.sendPacket(CPacketEntityAction(player, CPacketEntityAction.Action.STOP_SNEAKING)) } - delay(50L * tickDelayCheck) - blockTask.updateState(TaskState.PLACED) } } @@ -878,10 +885,17 @@ internal object HighwayTools : Module( return blueprintNew.containsKey(pos) } - private fun isInsideBuild(pos: BlockPos): Boolean { + private fun isInsideBlueprint(pos: BlockPos): Boolean { return blueprintNew[pos]?.let { it != Blocks.AIR } ?: false } + private fun isInsideBuild(pos: BlockPos): Boolean { + for (task in pendingTasks) { + if (task.blockPos == pos) return true + } + return false + } + fun printSettings() { StringBuilder(ignoreBlocks.size + 1).run { append("$chatName Settings" + From ec26e9912b09da0c6730380ad19b371419944ae8 Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 26 Jan 2021 03:36:23 +0100 Subject: [PATCH 225/390] Smooth pending --- .../kami/module/modules/misc/HighwayTools.kt | 111 +++++++++++------- 1 file changed, 66 insertions(+), 45 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 612fb39e7e..df3dc8acb6 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -111,6 +111,7 @@ internal object HighwayTools : Module( private var startingBlockPos = BlockPos(0, -1, 0) private val blueprint = ArrayList>() private val blueprintNew = LinkedHashMap() + private var sortedTasks: List = emptyList() // State private var active = false @@ -212,26 +213,28 @@ internal object HighwayTools : Module( if (isInsideBuild(pos) && prev.block != new.block) { val task = getTaskFromPos(pos) - if (task.taskState == TaskState.PENDING) { - when { - prev.block != Blocks.AIR && new.block == Blocks.AIR -> { - totalBlocksDestroyed++ - task.updateState(TaskState.BROKEN) - if (fakeSounds) { - val soundType = prev.block.getSoundType(prev, world, pos, player) - onMainThread { - world.playSound(player, pos, soundType.breakSound, SoundCategory.BLOCKS, (soundType.getVolume() + 1.0f) / 2.0f, soundType.getPitch() * 0.8f) - } + when { + task.taskState == TaskState.PENDING_BROKEN && + prev.block != Blocks.AIR && + new.block == Blocks.AIR -> { + totalBlocksDestroyed++ + task.updateState(TaskState.BROKEN) + if (fakeSounds) { + val soundType = prev.block.getSoundType(prev, world, pos, player) + onMainThread { + world.playSound(player, pos, soundType.breakSound, SoundCategory.BLOCKS, (soundType.getVolume() + 1.0f) / 2.0f, soundType.getPitch() * 0.8f) } } - (task.block == material || task.block == fillerMat) && task.block == new.block -> { - totalBlocksPlaced++ - task.updateState(TaskState.PLACED) - if (fakeSounds) { - val soundType = new.block.getSoundType(new, world, pos, player) - onMainThread { - world.playSound(player, pos, soundType.placeSound, SoundCategory.BLOCKS, (soundType.getVolume() + 1.0f) / 2.0f, soundType.getPitch() * 0.8f) - } + } + task.taskState == TaskState.PENDING_PLACED && + (task.block == material || task.block == fillerMat) + && task.block == new.block -> { + totalBlocksPlaced++ + task.updateState(TaskState.PLACED) + if (fakeSounds) { + val soundType = new.block.getSoundType(new, world, pos, player) + onMainThread { + world.playSound(player, pos, soundType.placeSound, SoundCategory.BLOCKS, (soundType.getVolume() + 1.0f) / 2.0f, soundType.getPitch() * 0.8f) } } } @@ -497,9 +500,14 @@ internal object HighwayTools : Module( private fun SafeClientEvent.runTasks() { if (pendingTasks.isNotEmpty()) { + if (waitTicks > 0) { + waitTicks-- + return + } + // (startingBlockPos.distanceTo(player.position) / startingBlockPos.distanceTo(it.blockPos)) * player.distanceTo(it.blockPos) * (lastHitVec.distanceTo(it.blockPos) * 2) - val sortedTasks = pendingTasks.sortedWith( + sortedTasks = pendingTasks.sortedWith( compareBy { it.taskState.ordinal }.thenBy { @@ -512,12 +520,35 @@ internal object HighwayTools : Module( lastHitVec?.distanceTo(it.blockPos) } ) - doTask(sortedTasks[0]) - if (sortedTasks[0].taskState.ordinal < 2) runTasks() + val firstTask = sortedTasks[0] + + val timeout = firstTask.taskState.stuckTimeout + if (firstTask.stuckTicks > timeout) { + when (firstTask.taskState) { + TaskState.PENDING_BROKEN -> firstTask.updateState(TaskState.BREAK) + TaskState.PENDING_PLACED -> firstTask.updateState(TaskState.PLACE) + else -> { + if (debugMessages != DebugMessages.OFF) { + sendChatMessage("Stuck for more then $timeout ticks, refreshing data.") + } + refreshData() + } + } + } + + doTask(firstTask) + + when (firstTask.taskState) { + TaskState.DONE, + TaskState.BROKEN, + TaskState.PLACED -> runTasks() + else -> {} + } } else { if (checkDoneTasks()) { doneTasks.clear() + // ToDo: This maybe is causing desync of current pos and goal? refreshData(currentBlockPos.add(startingDirection.directionVec)) } else { refreshData() @@ -547,8 +578,9 @@ internal object HighwayTools : Module( TaskState.PLACE, TaskState.LIQUID_SOURCE, TaskState.LIQUID_FLOW -> { doPlace(blockTask) } - TaskState.PENDING -> { - sendChatMessage("PENDING.") + TaskState.PENDING_BROKEN, TaskState.PENDING_PLACED -> { + if (debugMessages == DebugMessages.ALL) sendChatMessage("$chatName Currently waiting for blockState updates...") + blockTask.onStuck() } } } @@ -811,7 +843,7 @@ internal object HighwayTools : Module( private fun dispatchInstantBreakThread(blockTask: BlockTask, facing: EnumFacing) { waitTicks = tickDelayBreak defaultScope.launch { - blockTask.updateState(TaskState.PENDING) + blockTask.updateState(TaskState.PENDING_BROKEN) delay(10L) onMainThreadSafe { connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, blockTask.blockPos, facing)) @@ -853,6 +885,7 @@ internal object HighwayTools : Module( if (illegalPlacements) { if (debugMessages == DebugMessages.ALL) { sendChatMessage("Trying to place through wall ${blockTask.blockPos}") + // ToDo: Actually place through wall } } else { blockTask.onStuck() @@ -866,7 +899,7 @@ internal object HighwayTools : Module( connection.sendPacket(CPacketEntityAction(player, CPacketEntityAction.Action.START_SNEAKING)) defaultScope.launch { - blockTask.updateState(TaskState.PENDING) + blockTask.updateState(TaskState.PENDING_PLACED) delay(10L) onMainThreadSafe { val offsetHitVec = lastHitVec ?: return@onMainThreadSafe @@ -1018,30 +1051,17 @@ internal object HighwayTools : Module( return statistics } - private fun SafeClientEvent.getQueue(): List { + private fun getQueue(): List { val message = ArrayList() - message.add("QUEUE:") - addTaskToMessageList(message, pendingTasks) - message.add("DONE:") + message.add("Pending Tasks:") + addTaskToMessageList(message, sortedTasks) + message.add("Done Tasks:") addTaskToMessageList(message, doneTasks) return message } - private fun SafeClientEvent.addTaskToMessageList(list: ArrayList, tasks: Collection) { - val sortedTasks = tasks.sortedWith( - compareBy { - it.taskState.ordinal - }.thenBy { - it.stuckTicks - }.thenBy { - startingBlockPos.distanceTo(it.blockPos) - }.thenBy { - player.distanceTo(it.blockPos) - }.thenBy { - lastHitVec?.distanceTo(it.blockPos) - } - ) - for (blockTask in sortedTasks) list.add(" " + blockTask.block.localizedName + "@(" + blockTask.blockPos.asString() + ") Priority: " + blockTask.taskState.ordinal + " State: " + blockTask.taskState.toString()) + private fun addTaskToMessageList(list: ArrayList, tasks: Collection) { + for (blockTask in tasks) list.add(" ${blockTask.block.localizedName}@(${blockTask.blockPos.asString()}) State: ${blockTask.taskState} Timings: (Threshold: ${blockTask.taskState.stuckThreshold}, Timeout: ${blockTask.taskState.stuckTimeout}) Priority: ${blockTask.taskState.ordinal} Stuck: ${blockTask.stuckTicks}") } class BlockTask( @@ -1101,7 +1121,8 @@ internal object HighwayTools : Module( EMERGENCY_BREAK(20, 20, ColorHolder(220, 41, 140)), BREAK(20, 20, ColorHolder(222, 0, 0)), PLACE(20, 10, ColorHolder(35, 188, 254)), - PENDING(100000, 100000, ColorHolder(0, 0, 0)) + PENDING_BROKEN(0, 4, ColorHolder(0, 0, 0)), + PENDING_PLACED(0, 4, ColorHolder(0, 0, 0)) } private enum class DebugMessages { From 872f382df2084822307edcacfb5f65ce5cb61976 Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 26 Jan 2021 04:47:16 +0100 Subject: [PATCH 226/390] Correct stuck handling --- .../kami/module/modules/misc/HighwayTools.kt | 31 ++++++++++++++----- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index df3dc8acb6..4af2e6e08c 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -530,7 +530,7 @@ internal object HighwayTools : Module( TaskState.PENDING_PLACED -> firstTask.updateState(TaskState.PLACE) else -> { if (debugMessages != DebugMessages.OFF) { - sendChatMessage("Stuck for more then $timeout ticks, refreshing data.") + sendChatMessage("Stuck while ${firstTask.taskState}@(${firstTask.blockPos.asString()}) for more then $timeout ticks (${firstTask.stuckTicks}), refreshing data.") } refreshData() } @@ -556,8 +556,19 @@ internal object HighwayTools : Module( } } + private fun agePendingTasks() { + for (task in pendingTasks) { + when (task.taskState) { + TaskState.PENDING_PLACED, + TaskState.PENDING_BROKEN -> task.onStuck() + else -> {} + } + } + } + private fun SafeClientEvent.doTask(blockTask: BlockTask) { blockTask.onTick() + agePendingTasks() when (blockTask.taskState) { TaskState.DONE -> { @@ -978,6 +989,7 @@ internal object HighwayTools : Module( } } + // ToDo: Update to new dynamic blueprint private fun getBlueprintStats(): Pair { var materialUsed = 0 var fillerMatUsed = 0 @@ -987,12 +999,15 @@ internal object HighwayTools : Module( fillerMat -> fillerMatUsed++ } } - // TODO: Update to new dynamic blueprint return Pair(materialUsed / 2, fillerMatUsed / 2) } fun SafeClientEvent.gatherStatistics(): List { - val currentTask = lastTask + val currentTask = if (sortedTasks.isNotEmpty()) { + sortedTasks[0] + } else { + null + } materialLeft = player.allSlots.countBlock(material) fillerMatLeft = player.allSlots.countBlock(fillerMat) @@ -1034,7 +1049,7 @@ internal object HighwayTools : Module( " §7Target state: §9${currentTask?.block?.localizedName}", " §7Position: §9(${currentTask?.blockPos?.asString()})", "§rDebug", - " §7Stuck ticks: §9${lastTask?.stuckTicks?.toString() ?: "N/A"}", + " §7Stuck ticks: §9${currentTask?.stuckTicks.toString()}", // " §7Pathing: §9$pathing", "§rEstimations", " §7${material.localizedName} (main material): §9$materialLeft + ($indirectMaterialLeft)", @@ -1113,16 +1128,16 @@ internal object HighwayTools : Module( enum class TaskState(val stuckThreshold: Int, val stuckTimeout: Int, val color: ColorHolder) { DONE(69420, 0x22, ColorHolder(50, 50, 50)), - BROKEN(20, 10, ColorHolder(111, 0, 0)), - PLACED(20, 5, ColorHolder(53, 222, 66)), + BROKEN(1000, 1000, ColorHolder(111, 0, 0)), + PLACED(1000, 1000, ColorHolder(53, 222, 66)), LIQUID_SOURCE(100, 100, ColorHolder(120, 41, 240)), LIQUID_FLOW(80, 80, ColorHolder(120, 41, 240)), BREAKING(100, 100, ColorHolder(240, 222, 60)), EMERGENCY_BREAK(20, 20, ColorHolder(220, 41, 140)), BREAK(20, 20, ColorHolder(222, 0, 0)), PLACE(20, 10, ColorHolder(35, 188, 254)), - PENDING_BROKEN(0, 4, ColorHolder(0, 0, 0)), - PENDING_PLACED(0, 4, ColorHolder(0, 0, 0)) + PENDING_BROKEN(0, 10, ColorHolder(0, 0, 0)), + PENDING_PLACED(0, 10, ColorHolder(0, 0, 0)) } private enum class DebugMessages { From a7c3a6084897b7d77049fd7e567110418b64dc60 Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 26 Jan 2021 06:01:06 +0100 Subject: [PATCH 227/390] Get tool from inv --- .../kami/module/modules/misc/AutoTool.kt | 18 +++++++++++------- .../kami/module/modules/misc/HighwayTools.kt | 12 ++++-------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoTool.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoTool.kt index 0cc557ba34..004787ac86 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoTool.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoTool.kt @@ -7,12 +7,13 @@ import me.zeroeightsix.kami.module.Category import me.zeroeightsix.kami.module.Module import me.zeroeightsix.kami.util.combat.CombatUtils import me.zeroeightsix.kami.util.combat.CombatUtils.equipBestWeapon -import me.zeroeightsix.kami.util.items.swapToSlot +import me.zeroeightsix.kami.util.items.* import me.zeroeightsix.kami.util.threads.safeListener import net.minecraft.block.state.IBlockState import net.minecraft.enchantment.EnchantmentHelper import net.minecraft.entity.EntityLivingBase import net.minecraft.init.Enchantments +import net.minecraft.inventory.Slot import net.minecraftforge.event.entity.player.PlayerInteractEvent.LeftClickBlock import net.minecraftforge.fml.common.gameevent.TickEvent import org.lwjgl.input.Mouse @@ -59,11 +60,11 @@ internal object AutoTool : Module( } fun SafeClientEvent.equipBestTool(blockState: IBlockState) { - var bestSlot = -1 + var slotFrom: Slot? = null var max = 0.0 - for (i in 0..8) { - val stack = player.inventory.getStackInSlot(i) + for (i in player.inventorySlots) { + val stack = i.stack if (stack.isEmpty) continue var speed = stack.getDestroySpeed(blockState) var eff: Int @@ -75,13 +76,16 @@ internal object AutoTool : Module( ).toFloat() if (speed > max) { max = speed.toDouble() - bestSlot = i + slotFrom = i } } - } - if (bestSlot != -1) swapToSlot(bestSlot) + if (slotFrom != null) { + val slotTo = player.hotbarSlots.firstEmpty()?.hotbarSlot ?: 0 + + moveToHotbar(slotFrom.slotNumber, slotTo) + } } init { diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 4af2e6e08c..23278ef741 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -472,18 +472,13 @@ internal object HighwayTools : Module( } private fun SafeClientEvent.getNextPos(): BlockPos { - val baseMaterial = if (mode == Mode.TUNNEL) fillerMat else material var nextPos = currentBlockPos for (step in 1..3) { val possiblePos = currentBlockPos.add(startingDirection.directionVec.multiply(step)) - -// if (!blueprintNew.containsKey(possiblePos.down()) && mode != Mode.TUNNEL) break - if (!world.isAirBlock(possiblePos) || !world.isAirBlock(possiblePos.up())) break - - val blockBelow = world.getBlockState(possiblePos.down()).block - if (blockBelow != baseMaterial && mode != Mode.TUNNEL) break - + if (getTaskFromPos(possiblePos).taskState != TaskState.DONE || + getTaskFromPos(possiblePos.up()).taskState != TaskState.DONE || + getTaskFromPos(possiblePos.down()).taskState != TaskState.DONE) break if (checkFOMO(possiblePos)) nextPos = possiblePos } @@ -758,6 +753,7 @@ internal object HighwayTools : Module( when (blockTask.taskState) { TaskState.BREAK, TaskState.EMERGENCY_BREAK -> { equipBestTool(world.getBlockState(blockTask.blockPos)) +// swapToValidPickaxe() } TaskState.PLACE, TaskState.LIQUID_FLOW, TaskState.LIQUID_SOURCE -> { if (!swapToBlock(blockTask.block)) { From 1e55997bd1dfc8f1bad2ba035b09178ef7c04d3d Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 26 Jan 2021 13:44:12 +0100 Subject: [PATCH 228/390] Fix random backtracing --- .../zeroeightsix/kami/module/modules/misc/AutoObsidian.kt | 2 +- .../zeroeightsix/kami/module/modules/misc/HighwayTools.kt | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt index 1a96849ba9..862d4eb6ef 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt @@ -222,7 +222,7 @@ internal object AutoObsidian : Module( if (pair != null) { placingPos = pair.first renderer.clear() - renderer.add(pair.first, ColorHolder(64, 255, 64)) + renderer.add(world.getBlockState(pair.first).getSelectedBoundingBox(world, pair.first), ColorHolder(64, 255, 64)) } else { MessageSendHelper.sendChatMessage("$chatName No valid position for placing shulker box / ender chest nearby, disabling.") mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 23278ef741..6285259015 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -278,6 +278,7 @@ internal object HighwayTools : Module( if (blockTask.block == Blocks.AIR) continue renderer.add(world.getBlockState(blockTask.blockPos).getSelectedBoundingBox(world, blockTask.blockPos), blockTask.taskState.color) } +// renderer.add(world.getBlockState(currentBlockPos).getSelectedBoundingBox(world, currentBlockPos), ColorHolder(0, 0, 255)) } private fun SafeClientEvent.updateFood() { @@ -479,7 +480,7 @@ internal object HighwayTools : Module( if (getTaskFromPos(possiblePos).taskState != TaskState.DONE || getTaskFromPos(possiblePos.up()).taskState != TaskState.DONE || getTaskFromPos(possiblePos.down()).taskState != TaskState.DONE) break - if (checkFOMO(possiblePos)) nextPos = possiblePos + if (checkFOMO(possiblePos.up())) nextPos = possiblePos } if (currentBlockPos != nextPos) refreshData() @@ -543,7 +544,6 @@ internal object HighwayTools : Module( } else { if (checkDoneTasks()) { doneTasks.clear() - // ToDo: This maybe is causing desync of current pos and goal? refreshData(currentBlockPos.add(startingDirection.directionVec)) } else { refreshData() @@ -821,7 +821,7 @@ internal object HighwayTools : Module( } /* For fire, we just need to mine the top of the block below the fire */ - /* TODO: This will not work if the top of the block which the fire is on is not visible */ + /* ToDo: This will not work if the top of the block which the fire is on is not visible */ if (blockTask.block == Blocks.FIRE) { val blockBelowFire = blockTask.blockPos.down() playerController.clickBlock(blockBelowFire, EnumFacing.UP) From 257a08df859f0a2fbbd9752bfc50768fbed9f432 Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 26 Jan 2021 22:48:45 +0100 Subject: [PATCH 229/390] Better pending timeout --- .../kami/module/modules/misc/HighwayTools.kt | 24 +++++++------------ 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 6285259015..3e94157e59 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -72,6 +72,7 @@ internal object HighwayTools : Module( // behavior settings private val tickDelayPlace by setting("TickDelayPlace", 3, 0..16, 1, { page == Page.BEHAVIOR }) private val tickDelayBreak by setting("TickDelayBreak", 1, 0..16, 1, { page == Page.BEHAVIOR }) + private val taskTimeoutTicks by setting("TaskTimeoutTicks", 3, 0..16, 1, { page == Page.BEHAVIOR }) private val interacting by setting("InteractMode", InteractMode.SPOOF, { page == Page.BEHAVIOR }) private val illegalPlacements by setting("IllegalPlacements", false, { page == Page.BEHAVIOR }) private val maxReach by setting("MaxReach", 4.5f, 1.0f..6.0f, 0.1f, { page == Page.BEHAVIOR }) @@ -257,7 +258,7 @@ internal object HighwayTools : Module( updateRenderer() updateFood() - if (BaritoneUtils.isPathing || AutoObsidian.isActive() || AutoEat.eating) return@safeListener + if (player.flooredPosition.distanceTo(currentBlockPos) > 2 || AutoObsidian.isActive() || AutoEat.eating) return@safeListener doPathing() runTasks() @@ -475,7 +476,7 @@ internal object HighwayTools : Module( private fun SafeClientEvent.getNextPos(): BlockPos { var nextPos = currentBlockPos - for (step in 1..3) { + for (step in 1..2) { val possiblePos = currentBlockPos.add(startingDirection.directionVec.multiply(step)) if (getTaskFromPos(possiblePos).taskState != TaskState.DONE || getTaskFromPos(possiblePos.up()).taskState != TaskState.DONE || @@ -551,19 +552,8 @@ internal object HighwayTools : Module( } } - private fun agePendingTasks() { - for (task in pendingTasks) { - when (task.taskState) { - TaskState.PENDING_PLACED, - TaskState.PENDING_BROKEN -> task.onStuck() - else -> {} - } - } - } - private fun SafeClientEvent.doTask(blockTask: BlockTask) { blockTask.onTick() - agePendingTasks() when (blockTask.taskState) { TaskState.DONE -> { @@ -861,6 +851,8 @@ internal object HighwayTools : Module( connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, blockTask.blockPos, facing)) player.swingArm(EnumHand.MAIN_HAND) } + delay(50L * taskTimeoutTicks) + if (blockTask.taskState == TaskState.PENDING_BROKEN) blockTask.updateState(TaskState.BREAK) } } @@ -918,6 +910,8 @@ internal object HighwayTools : Module( onMainThreadSafe { connection.sendPacket(CPacketEntityAction(player, CPacketEntityAction.Action.STOP_SNEAKING)) } + delay(50L * taskTimeoutTicks) + if (blockTask.taskState == TaskState.PENDING_PLACED) blockTask.updateState(TaskState.PLACE) } } @@ -1132,8 +1126,8 @@ internal object HighwayTools : Module( EMERGENCY_BREAK(20, 20, ColorHolder(220, 41, 140)), BREAK(20, 20, ColorHolder(222, 0, 0)), PLACE(20, 10, ColorHolder(35, 188, 254)), - PENDING_BROKEN(0, 10, ColorHolder(0, 0, 0)), - PENDING_PLACED(0, 10, ColorHolder(0, 0, 0)) + PENDING_BROKEN(100, 100, ColorHolder(0, 0, 0)), + PENDING_PLACED(100, 100, ColorHolder(0, 0, 0)) } private enum class DebugMessages { From 6384325cdd0c106b8aeb553ead6120cf376eeee9 Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Tue, 26 Jan 2021 16:56:53 -0500 Subject: [PATCH 230/390] Removed weird cross usage --- src/main/commons | 2 +- .../kami/module/modules/misc/AutoTool.kt | 47 +++++++++---------- .../kami/module/modules/misc/HighwayTools.kt | 40 ++++++++++++++-- .../me/zeroeightsix/kami/util/items/Slot.kt | 4 ++ 4 files changed, 61 insertions(+), 32 deletions(-) diff --git a/src/main/commons b/src/main/commons index d42521450d..59cb11580f 160000 --- a/src/main/commons +++ b/src/main/commons @@ -1 +1 @@ -Subproject commit d42521450df8b3dae82a1865680464fd0d02026d +Subproject commit 59cb11580fffffb8ce7cb389850c1c8ef28bb249 diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoTool.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoTool.kt index 004787ac86..246935c42e 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoTool.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoTool.kt @@ -7,13 +7,13 @@ import me.zeroeightsix.kami.module.Category import me.zeroeightsix.kami.module.Module import me.zeroeightsix.kami.util.combat.CombatUtils import me.zeroeightsix.kami.util.combat.CombatUtils.equipBestWeapon -import me.zeroeightsix.kami.util.items.* +import me.zeroeightsix.kami.util.items.hotbarSlots +import me.zeroeightsix.kami.util.items.swapToSlot import me.zeroeightsix.kami.util.threads.safeListener import net.minecraft.block.state.IBlockState import net.minecraft.enchantment.EnchantmentHelper import net.minecraft.entity.EntityLivingBase import net.minecraft.init.Enchantments -import net.minecraft.inventory.Slot import net.minecraftforge.event.entity.player.PlayerInteractEvent.LeftClickBlock import net.minecraftforge.fml.common.gameevent.TickEvent import org.lwjgl.input.Mouse @@ -59,36 +59,31 @@ internal object AutoTool : Module( } } - fun SafeClientEvent.equipBestTool(blockState: IBlockState) { - var slotFrom: Slot? = null - var max = 0.0 + private fun SafeClientEvent.equipBestTool(blockState: IBlockState) { + player.hotbarSlots.maxByOrNull { + val stack = it.stack + if (stack.isEmpty) { + 0.0f + } else { + var speed = stack.getDestroySpeed(blockState) - for (i in player.inventorySlots) { - val stack = i.stack - if (stack.isEmpty) continue - var speed = stack.getDestroySpeed(blockState) - var eff: Int - - if (speed > 1) { - speed += ( - if (EnchantmentHelper.getEnchantmentLevel(Enchantments.EFFICIENCY, stack).also { eff = it } > 0.0) eff.toDouble().pow(2.0) + 1 - else 0.0 - ).toFloat() - if (speed > max) { - max = speed.toDouble() - slotFrom = i + if (speed > 1.0f) { + val efficiency = EnchantmentHelper.getEnchantmentLevel(Enchantments.EFFICIENCY, stack) + if (efficiency > 0) { + speed += efficiency * efficiency + 1.0f + } } - } - } - if (slotFrom != null) { - val slotTo = player.hotbarSlots.firstEmpty()?.hotbarSlot ?: 0 - - moveToHotbar(slotFrom.slotNumber, slotTo) + speed + } + }?.let { + swapToSlot(it) } } init { - switchBack.listeners.add { if (!switchBack.value) shouldMoveBack = false } + switchBack.valueListeners.add { _, it -> + if (!it) shouldMoveBack = false + } } } \ No newline at end of file diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 3e94157e59..8126ddffee 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -9,7 +9,6 @@ import me.zeroeightsix.kami.event.events.RenderWorldEvent import me.zeroeightsix.kami.manager.managers.PlayerPacketManager import me.zeroeightsix.kami.module.Category import me.zeroeightsix.kami.module.Module -import me.zeroeightsix.kami.module.modules.misc.AutoTool.equipBestTool import me.zeroeightsix.kami.module.modules.player.AutoEat import me.zeroeightsix.kami.module.modules.player.InventoryManager import me.zeroeightsix.kami.process.HighwayToolsProcess @@ -29,7 +28,9 @@ import me.zeroeightsix.kami.util.threads.* import net.minecraft.block.Block import net.minecraft.block.BlockLiquid import net.minecraft.client.audio.PositionedSoundRecord +import net.minecraft.enchantment.EnchantmentHelper import net.minecraft.init.Blocks +import net.minecraft.init.Enchantments import net.minecraft.init.SoundEvents import net.minecraft.network.play.client.CPacketEntityAction import net.minecraft.network.play.client.CPacketPlayerDigging @@ -505,7 +506,7 @@ internal object HighwayTools : Module( // (startingBlockPos.distanceTo(player.position) / startingBlockPos.distanceTo(it.blockPos)) * player.distanceTo(it.blockPos) * (lastHitVec.distanceTo(it.blockPos) * 2) sortedTasks = pendingTasks.sortedWith( - compareBy { + compareBy { it.taskState.ordinal }.thenBy { it.stuckTicks @@ -540,7 +541,8 @@ internal object HighwayTools : Module( TaskState.DONE, TaskState.BROKEN, TaskState.PLACED -> runTasks() - else -> {} + else -> { + } } } else { if (checkDoneTasks()) { @@ -742,8 +744,7 @@ internal object HighwayTools : Module( private fun SafeClientEvent.inventoryProcessor(blockTask: BlockTask) { when (blockTask.taskState) { TaskState.BREAK, TaskState.EMERGENCY_BREAK -> { - equipBestTool(world.getBlockState(blockTask.blockPos)) -// swapToValidPickaxe() + swapOrMoveBestTool(blockTask) } TaskState.PLACE, TaskState.LIQUID_FLOW, TaskState.LIQUID_SOURCE -> { if (!swapToBlock(blockTask.block)) { @@ -762,6 +763,35 @@ internal object HighwayTools : Module( } } + private fun SafeClientEvent.swapOrMoveBestTool(blockTask: BlockTask) { + val slotFrom = player.inventorySlots.maxByOrNull { + val stack = it.stack + if (stack.isEmpty) { + 0.0f + } else { + var speed = stack.getDestroySpeed(world.getBlockState(blockTask.blockPos)) + + if (speed > 1.0f) { + val efficiency = EnchantmentHelper.getEnchantmentLevel(Enchantments.EFFICIENCY, stack) + if (efficiency > 0) { + speed += efficiency * efficiency + 1.0f + } + } + + speed + } + } + + if (slotFrom != null) { + slotFrom.toHotbarSlotOrNull()?.let { + swapToSlot(it) + } ?: run { + val slotTo = player.hotbarSlots.firstEmpty()?.hotbarSlot ?: 0 + moveToHotbar(slotFrom.slotNumber, slotTo) + } + } + } + private fun SafeClientEvent.handleLiquid(blockTask: BlockTask): Boolean { var foundLiquid = false for (side in EnumFacing.values()) { diff --git a/src/main/java/me/zeroeightsix/kami/util/items/Slot.kt b/src/main/java/me/zeroeightsix/kami/util/items/Slot.kt index df32c54888..a9f63e1281 100644 --- a/src/main/java/me/zeroeightsix/kami/util/items/Slot.kt +++ b/src/main/java/me/zeroeightsix/kami/util/items/Slot.kt @@ -1,5 +1,6 @@ package me.zeroeightsix.kami.util.items +import me.zeroeightsix.kami.util.Wrapper import net.minecraft.block.Block import net.minecraft.entity.player.EntityPlayer import net.minecraft.inventory.Container @@ -126,6 +127,9 @@ fun Iterable.filterByID(itemID: Int, predicate: (ItemStack) -> Boo fun Iterable.filterByStack(predicate: (ItemStack) -> Boolean = { true }) = filter { predicate(it.stack) } +fun Slot.toHotbarSlotOrNull() = + if (this.slotNumber in 36..44 && this.inventory == Wrapper.player?.inventory) HotbarSlot(this) + else null class HotbarSlot(slot: Slot) : Slot(slot.inventory, slot.slotIndex, slot.xPos, slot.yPos) { init { From 1529072e0ef3f03551eba971dfcd5edc3e1f55aa Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Tue, 26 Jan 2021 18:08:16 -0500 Subject: [PATCH 231/390] Fixed broken method calls --- .../zeroeightsix/kami/module/modules/misc/HighwayTools.kt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 8126ddffee..0853f0bc99 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -14,6 +14,7 @@ import me.zeroeightsix.kami.module.modules.player.InventoryManager import me.zeroeightsix.kami.process.HighwayToolsProcess import me.zeroeightsix.kami.util.* import me.zeroeightsix.kami.util.EntityUtils.flooredPosition +import me.zeroeightsix.kami.util.WorldUtils.isPlaceable import me.zeroeightsix.kami.util.WorldUtils.rayTraceHitVec import me.zeroeightsix.kami.util.WorldUtils.rayTracePlaceVec import me.zeroeightsix.kami.util.color.ColorHolder @@ -21,6 +22,7 @@ import me.zeroeightsix.kami.util.graphics.* import me.zeroeightsix.kami.util.items.* import me.zeroeightsix.kami.util.math.* import me.zeroeightsix.kami.util.math.CoordinateConverter.asString +import me.zeroeightsix.kami.util.math.RotationUtils.getRotationTo import me.zeroeightsix.kami.util.math.VectorUtils.distanceTo import me.zeroeightsix.kami.util.math.VectorUtils.multiply import me.zeroeightsix.kami.util.text.MessageSendHelper.sendChatMessage @@ -293,7 +295,7 @@ internal object HighwayTools : Module( private fun SafeClientEvent.doRotation() { if (rotateTimer.tick(20L, false)) return - val rotation = lastHitVec?.let { RotationUtils.getRotationTo(it) } ?: return + val rotation = lastHitVec?.let { getRotationTo(it) } ?: return when (interacting) { InteractMode.SPOOF -> { @@ -705,7 +707,7 @@ internal object HighwayTools : Module( blockTask.updateState(TaskState.PLACED) } else -> { - if (!WorldUtils.isPlaceable(blockTask.blockPos)) { + if (!isPlaceable(blockTask.blockPos)) { if (debugMessages != DebugMessages.OFF) sendChatMessage("Invalid place position: " + blockTask.blockPos) refreshData() return From 09fe52538e4b407f2f7659ebc0930e36c723b669 Mon Sep 17 00:00:00 2001 From: Christian Date: Wed, 27 Jan 2021 00:17:13 +0100 Subject: [PATCH 232/390] Fix slowdown while walking --- .../kami/module/modules/misc/HighwayTools.kt | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 0853f0bc99..a108ab1c6b 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -357,6 +357,9 @@ internal object HighwayTools : Module( for (task in pendingTasks) { if (task.blockPos == pos) return task } + for (task in doneTasks) { + if (task.blockPos == pos) return task + } return BlockTask(BlockPos(0, -1, 0), TaskState.DONE, Blocks.AIR) } @@ -468,9 +471,9 @@ internal object HighwayTools : Module( private fun SafeClientEvent.doPathing() { val nextPos = getNextPos() - if (nextPos == mc.player.flooredPosition) { + if (player.flooredPosition.distanceTo(nextPos) < 2) { currentBlockPos = nextPos - goal = null + goal = GoalNear(nextPos, 0) } else { goal = GoalNear(nextPos, 0) } @@ -479,13 +482,11 @@ internal object HighwayTools : Module( private fun SafeClientEvent.getNextPos(): BlockPos { var nextPos = currentBlockPos - for (step in 1..2) { - val possiblePos = currentBlockPos.add(startingDirection.directionVec.multiply(step)) - if (getTaskFromPos(possiblePos).taskState != TaskState.DONE || - getTaskFromPos(possiblePos.up()).taskState != TaskState.DONE || - getTaskFromPos(possiblePos.down()).taskState != TaskState.DONE) break - if (checkFOMO(possiblePos.up())) nextPos = possiblePos - } + val possiblePos = currentBlockPos.add(startingDirection.directionVec) + if (getTaskFromPos(possiblePos).taskState != TaskState.DONE || + getTaskFromPos(possiblePos.up()).taskState != TaskState.DONE || + getTaskFromPos(possiblePos.down()).taskState != TaskState.DONE) return nextPos + if (checkFOMO(possiblePos.up())) nextPos = possiblePos if (currentBlockPos != nextPos) refreshData() return nextPos @@ -580,7 +581,7 @@ internal object HighwayTools : Module( } TaskState.PENDING_BROKEN, TaskState.PENDING_PLACED -> { if (debugMessages == DebugMessages.ALL) sendChatMessage("$chatName Currently waiting for blockState updates...") - blockTask.onStuck() +// blockTask.onStuck() } } } From 7dbf99c22bec855de42602e5e43d4069ee3aba8a Mon Sep 17 00:00:00 2001 From: Christian Date: Wed, 27 Jan 2021 00:17:29 +0100 Subject: [PATCH 233/390] Updated submodule src/main/commons --- src/main/commons | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/commons b/src/main/commons index 59cb11580f..d42521450d 160000 --- a/src/main/commons +++ b/src/main/commons @@ -1 +1 @@ -Subproject commit 59cb11580fffffb8ce7cb389850c1c8ef28bb249 +Subproject commit d42521450df8b3dae82a1865680464fd0d02026d From f185ece7bd23b9476db7c5b4e1908f5429d8effc Mon Sep 17 00:00:00 2001 From: Christian Date: Wed, 27 Jan 2021 02:24:56 +0100 Subject: [PATCH 234/390] Better feedback --- .../kami/module/modules/misc/HighwayTools.kt | 74 +++++++++++-------- 1 file changed, 44 insertions(+), 30 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index a108ab1c6b..369d0599f9 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -221,26 +221,14 @@ internal object HighwayTools : Module( task.taskState == TaskState.PENDING_BROKEN && prev.block != Blocks.AIR && new.block == Blocks.AIR -> { - totalBlocksDestroyed++ task.updateState(TaskState.BROKEN) - if (fakeSounds) { - val soundType = prev.block.getSoundType(prev, world, pos, player) - onMainThread { - world.playSound(player, pos, soundType.breakSound, SoundCategory.BLOCKS, (soundType.getVolume() + 1.0f) / 2.0f, soundType.getPitch() * 0.8f) - } - } + sortTasks() } task.taskState == TaskState.PENDING_PLACED && (task.block == material || task.block == fillerMat) && task.block == new.block -> { - totalBlocksPlaced++ task.updateState(TaskState.PLACED) - if (fakeSounds) { - val soundType = new.block.getSoundType(new, world, pos, player) - onMainThread { - world.playSound(player, pos, soundType.placeSound, SoundCategory.BLOCKS, (soundType.getVolume() + 1.0f) / 2.0f, soundType.getPitch() * 0.8f) - } - } + sortTasks() } } } @@ -499,6 +487,22 @@ internal object HighwayTools : Module( return true } + private fun SafeClientEvent.sortTasks() { + sortedTasks = pendingTasks.sortedWith( + compareBy { + it.taskState.ordinal + }.thenBy { + it.stuckTicks + }.thenBy { + startingBlockPos.distanceTo(it.blockPos) + }.thenBy { + player.distanceTo(it.blockPos) + }.thenBy { + lastHitVec?.distanceTo(it.blockPos) + } + ) + } + private fun SafeClientEvent.runTasks() { if (pendingTasks.isNotEmpty()) { if (waitTicks > 0) { @@ -508,19 +512,7 @@ internal object HighwayTools : Module( // (startingBlockPos.distanceTo(player.position) / startingBlockPos.distanceTo(it.blockPos)) * player.distanceTo(it.blockPos) * (lastHitVec.distanceTo(it.blockPos) * 2) - sortedTasks = pendingTasks.sortedWith( - compareBy { - it.taskState.ordinal - }.thenBy { - it.stuckTicks - }.thenBy { - startingBlockPos.distanceTo(it.blockPos) - }.thenBy { - player.distanceTo(it.blockPos) - }.thenBy { - lastHitVec?.distanceTo(it.blockPos) - } - ) + sortTasks() val firstTask = sortedTasks[0] @@ -625,6 +617,13 @@ internal object HighwayTools : Module( blockTask.updateState(TaskState.PLACE) } else { blockTask.updateState(TaskState.DONE) + if (fakeSounds) { + val soundType = blockTask.block.getSoundType(world.getBlockState(blockTask.blockPos), world, blockTask.blockPos, player) + onMainThread { + world.playSound(player, blockTask.blockPos, soundType.breakSound, SoundCategory.BLOCKS, (soundType.getVolume() + 1.0f) / 2.0f, soundType.getPitch() * 0.8f) + } + } + totalBlocksDestroyed++ } } else -> { @@ -639,6 +638,13 @@ internal object HighwayTools : Module( when { blockTask.block == block && block != Blocks.AIR -> { blockTask.updateState(TaskState.DONE) + if (fakeSounds) { + val soundType = block.getSoundType(world.getBlockState(blockTask.blockPos), world, blockTask.blockPos, player) + onMainThread { + world.playSound(player, blockTask.blockPos, soundType.placeSound, SoundCategory.BLOCKS, (soundType.getVolume() + 1.0f) / 2.0f, soundType.getPitch() * 0.8f) + } + } + totalBlocksPlaced++ } blockTask.block == Blocks.AIR && block != Blocks.AIR -> { blockTask.updateState(TaskState.BREAK) @@ -870,10 +876,11 @@ internal object HighwayTools : Module( } } - private fun dispatchInstantBreakThread(blockTask: BlockTask, facing: EnumFacing) { + private fun SafeClientEvent.dispatchInstantBreakThread(blockTask: BlockTask, facing: EnumFacing) { waitTicks = tickDelayBreak defaultScope.launch { blockTask.updateState(TaskState.PENDING_BROKEN) + sortTasks() delay(10L) onMainThreadSafe { connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, blockTask.blockPos, facing)) @@ -885,7 +892,10 @@ internal object HighwayTools : Module( player.swingArm(EnumHand.MAIN_HAND) } delay(50L * taskTimeoutTicks) - if (blockTask.taskState == TaskState.PENDING_BROKEN) blockTask.updateState(TaskState.BREAK) + if (blockTask.taskState == TaskState.PENDING_BROKEN) { + blockTask.updateState(TaskState.BREAK) + sortTasks() + } } } @@ -932,6 +942,7 @@ internal object HighwayTools : Module( defaultScope.launch { blockTask.updateState(TaskState.PENDING_PLACED) + sortTasks() delay(10L) onMainThreadSafe { val offsetHitVec = lastHitVec ?: return@onMainThreadSafe @@ -944,7 +955,10 @@ internal object HighwayTools : Module( connection.sendPacket(CPacketEntityAction(player, CPacketEntityAction.Action.STOP_SNEAKING)) } delay(50L * taskTimeoutTicks) - if (blockTask.taskState == TaskState.PENDING_PLACED) blockTask.updateState(TaskState.PLACE) + if (blockTask.taskState == TaskState.PENDING_PLACED) { + blockTask.updateState(TaskState.PLACE) + sortTasks() + } } } From 96aed114193b5e73b4000b9f491ba61247f4db18 Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Tue, 26 Jan 2021 23:57:40 -0500 Subject: [PATCH 235/390] Replaced raytrace checks with hause visible side check --- .../kami/module/modules/misc/HighwayTools.kt | 48 ++++++------ .../me/zeroeightsix/kami/util/WorldUtils.kt | 76 +++++++++++-------- 2 files changed, 68 insertions(+), 56 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 369d0599f9..dc15bb267b 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -14,9 +14,8 @@ import me.zeroeightsix.kami.module.modules.player.InventoryManager import me.zeroeightsix.kami.process.HighwayToolsProcess import me.zeroeightsix.kami.util.* import me.zeroeightsix.kami.util.EntityUtils.flooredPosition +import me.zeroeightsix.kami.util.WorldUtils.getNeighbour import me.zeroeightsix.kami.util.WorldUtils.isPlaceable -import me.zeroeightsix.kami.util.WorldUtils.rayTraceHitVec -import me.zeroeightsix.kami.util.WorldUtils.rayTracePlaceVec import me.zeroeightsix.kami.util.color.ColorHolder import me.zeroeightsix.kami.util.graphics.* import me.zeroeightsix.kami.util.items.* @@ -25,6 +24,7 @@ import me.zeroeightsix.kami.util.math.CoordinateConverter.asString import me.zeroeightsix.kami.util.math.RotationUtils.getRotationTo import me.zeroeightsix.kami.util.math.VectorUtils.distanceTo import me.zeroeightsix.kami.util.math.VectorUtils.multiply +import me.zeroeightsix.kami.util.math.VectorUtils.toVec3dCenter import me.zeroeightsix.kami.util.text.MessageSendHelper.sendChatMessage import me.zeroeightsix.kami.util.threads.* import net.minecraft.block.Block @@ -41,6 +41,7 @@ import net.minecraft.network.play.server.SPacketBlockChange import net.minecraft.util.EnumFacing import net.minecraft.util.EnumHand import net.minecraft.util.SoundCategory +import net.minecraft.util.math.AxisAlignedBB import net.minecraft.util.math.BlockPos import net.minecraft.util.math.Vec3d import net.minecraftforge.fml.common.gameevent.TickEvent @@ -222,13 +223,11 @@ internal object HighwayTools : Module( prev.block != Blocks.AIR && new.block == Blocks.AIR -> { task.updateState(TaskState.BROKEN) - sortTasks() } task.taskState == TaskState.PENDING_PLACED && (task.block == material || task.block == fillerMat) && task.block == new.block -> { task.updateState(TaskState.PLACED) - sortTasks() } } } @@ -859,7 +858,7 @@ internal object HighwayTools : Module( return } - val rayTraceResult = rayTraceHitVec(blockTask.blockPos) + val rayTraceResult = AxisAlignedBB(blockTask.blockPos).calculateIntercept(player.getPositionEyes(1.0f), blockTask.blockPos.toVec3dCenter()) if (rayTraceResult == null) { blockTask.onStuck() @@ -876,25 +875,26 @@ internal object HighwayTools : Module( } } - private fun SafeClientEvent.dispatchInstantBreakThread(blockTask: BlockTask, facing: EnumFacing) { + private fun dispatchInstantBreakThread(blockTask: BlockTask, facing: EnumFacing) { waitTicks = tickDelayBreak defaultScope.launch { blockTask.updateState(TaskState.PENDING_BROKEN) - sortTasks() + delay(10L) onMainThreadSafe { connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, blockTask.blockPos, facing)) player.swingArm(EnumHand.MAIN_HAND) } + delay(40L) onMainThreadSafe { connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, blockTask.blockPos, facing)) player.swingArm(EnumHand.MAIN_HAND) } + delay(50L * taskTimeoutTicks) if (blockTask.taskState == TaskState.PENDING_BROKEN) { blockTask.updateState(TaskState.BREAK) - sortTasks() } } } @@ -921,43 +921,43 @@ internal object HighwayTools : Module( } private fun SafeClientEvent.placeBlock(blockTask: BlockTask) { - val rayTraceResult = rayTracePlaceVec(blockTask.blockPos) - - if (rayTraceResult == null) { - if (illegalPlacements) { - if (debugMessages == DebugMessages.ALL) { - sendChatMessage("Trying to place through wall ${blockTask.blockPos}") - // ToDo: Actually place through wall + val pair = getNeighbour(blockTask.blockPos, 1, maxReach, true) + ?: run { + if (illegalPlacements) { + if (debugMessages == DebugMessages.ALL) { + sendChatMessage("Trying to place through wall ${blockTask.blockPos}") + getNeighbour(blockTask.blockPos, 1, maxReach) ?: return + } + } else { + blockTask.onStuck() } - } else { - blockTask.onStuck() + return } - return - } - lastHitVec = rayTraceResult.hitVec + val hitVecOffset = WorldUtils.getHitVecOffset(pair.first) + lastHitVec = WorldUtils.getHitVec(pair.second, pair.first) rotateTimer.reset() connection.sendPacket(CPacketEntityAction(player, CPacketEntityAction.Action.START_SNEAKING)) defaultScope.launch { blockTask.updateState(TaskState.PENDING_PLACED) - sortTasks() + delay(10L) onMainThreadSafe { - val offsetHitVec = lastHitVec ?: return@onMainThreadSafe - val placePacket = CPacketPlayerTryUseItemOnBlock(rayTraceResult.blockPos, rayTraceResult.sideHit, EnumHand.MAIN_HAND, offsetHitVec.x.toFloat(), offsetHitVec.y.toFloat(), offsetHitVec.z.toFloat()) + val placePacket = CPacketPlayerTryUseItemOnBlock(pair.second, pair.first, EnumHand.MAIN_HAND, hitVecOffset.x.toFloat(), hitVecOffset.y.toFloat(), hitVecOffset.z.toFloat()) connection.sendPacket(placePacket) player.swingArm(EnumHand.MAIN_HAND) } + delay(10L) onMainThreadSafe { connection.sendPacket(CPacketEntityAction(player, CPacketEntityAction.Action.STOP_SNEAKING)) } + delay(50L * taskTimeoutTicks) if (blockTask.taskState == TaskState.PENDING_PLACED) { blockTask.updateState(TaskState.PLACE) - sortTasks() } } } diff --git a/src/main/java/me/zeroeightsix/kami/util/WorldUtils.kt b/src/main/java/me/zeroeightsix/kami/util/WorldUtils.kt index ef9c13f11a..4858229127 100644 --- a/src/main/java/me/zeroeightsix/kami/util/WorldUtils.kt +++ b/src/main/java/me/zeroeightsix/kami/util/WorldUtils.kt @@ -4,9 +4,10 @@ import kotlinx.coroutines.delay import me.zeroeightsix.kami.event.SafeClientEvent import me.zeroeightsix.kami.manager.managers.PlayerPacketManager import me.zeroeightsix.kami.util.math.RotationUtils.getRotationTo -import me.zeroeightsix.kami.util.math.corners +import me.zeroeightsix.kami.util.math.VectorUtils.toVec3dCenter import me.zeroeightsix.kami.util.math.faceCorners import me.zeroeightsix.kami.util.threads.runSafeSuspend +import net.minecraft.block.state.IBlockState import net.minecraft.entity.Entity import net.minecraft.init.Blocks import net.minecraft.item.ItemBlock @@ -20,6 +21,9 @@ import net.minecraft.util.math.BlockPos import net.minecraft.util.math.RayTraceResult import net.minecraft.util.math.Vec3d import org.kamiblue.commons.extension.add +import java.util.* +import kotlin.collections.ArrayList +import kotlin.collections.HashSet import kotlin.math.floor object WorldUtils { @@ -130,41 +134,41 @@ object WorldUtils { return Vec3d(vec.x * 0.5 + 0.5, vec.y * 0.5 + 0.5, vec.z * 0.5 + 0.5) } - fun SafeClientEvent.rayTraceHitVec(pos: BlockPos): RayTraceResult? { - val eyePos = player.getPositionEyes(1f) - val bb = world.getBlockState(pos).getSelectedBoundingBox(world, pos) + /** + * Get the "visible" sides related to player's eye position + * + * Reverse engineered from HauseMaster's anti cheat plugin + */ + fun SafeClientEvent.getVisibleSides(pos: BlockPos): Set { + val visibleSides = EnumSet.noneOf(EnumFacing::class.java) - return world.rayTraceBlocks(eyePos, bb.center, false, false, true)?.takeIf { - it.isEqualTo(pos) - } ?: bb.corners(0.95).mapNotNull { corner -> - world.rayTraceBlocks(eyePos, corner, false, false, true)?.takeIf { it.isEqualTo(pos) } - }.minByOrNull { - it.hitVec?.distanceTo(eyePos) ?: 69420.0 - } + val blockState = world.getBlockState(pos) + val eyePos = player.getPositionEyes(1.0f) + val blockCenter = pos.toVec3dCenter() + + return visibleSides + .checkAxis(blockState, eyePos.x - blockCenter.x, EnumFacing.WEST, EnumFacing.EAST) + .checkAxis(blockState, eyePos.y - blockCenter.y, EnumFacing.DOWN, EnumFacing.UP) + .checkAxis(blockState, eyePos.z - blockCenter.z, EnumFacing.NORTH, EnumFacing.SOUTH) } - fun SafeClientEvent.rayTracePlaceVec(pos: BlockPos) : RayTraceResult? { - val eyePos = player.getPositionEyes(1f) - val possibleTraces = mutableListOf() - - for (side in EnumFacing.values()) { - val offPos = pos.offset(side) - val blockState = world.getBlockState(offPos) - if (!blockState.isFullBlock) continue - val bb = blockState.getSelectedBoundingBox(world, offPos) - val rt = bb.faceCorners(side.opposite, 0.85).mapNotNull { corner -> - world.rayTraceBlocks(eyePos, corner, false, false, false)?.takeIf { - it.isEqualTo(offPos) && it.sideHit == side.opposite + private fun EnumSet.checkAxis(blockState: IBlockState, diff: Double, negativeSide: EnumFacing, positiveSide: EnumFacing) = + this.apply { + when { + diff < -0.5 -> { + add(negativeSide) + } + diff > 0.5 -> { + add(positiveSide) + } + else -> { + if (!blockState.isFullBlock) { + add(negativeSide) + add(positiveSide) + } } - }.minByOrNull { - it.hitVec?.distanceTo(eyePos) ?: 69420.0 } - possibleTraces.add(rt) } - return possibleTraces.minByOrNull { it.hitVec?.distanceTo(eyePos) ?: 69420.0 } - } - - private fun RayTraceResult.isEqualTo(pos: BlockPos) = typeOfHit == RayTraceResult.Type.BLOCK && blockPos == pos suspend fun SafeClientEvent.buildStructure( placeSpeed: Float, @@ -217,24 +221,32 @@ object WorldUtils { blockPos: BlockPos, attempts: Int = 3, range: Float = 4.25f, + visibleSideCheck: Boolean = false, sides: Array = EnumFacing.values(), toIgnore: HashSet = HashSet() ): Pair? { + val eyePos = player.getPositionEyes(1.0f) + for (side in sides) { val pos = blockPos.offset(side) + if (!toIgnore.add(pos)) continue if (world.getBlockState(pos).material.isReplaceable) continue - if (player.getPositionEyes(1f).distanceTo(Vec3d(pos).add(getHitVecOffset(side))) > range) continue + if (eyePos.distanceTo(Vec3d(pos).add(getHitVecOffset(side))) > range) continue + if (visibleSideCheck && !getVisibleSides(pos).contains(side.opposite)) continue + return Pair(side.opposite, pos) } + if (attempts > 1) { toIgnore.add(blockPos) for (side in sides) { val pos = blockPos.offset(side) if (!isPlaceable(pos)) continue - return getNeighbour(pos, attempts - 1, range, sides, toIgnore) ?: continue + return getNeighbour(pos, attempts - 1, range, visibleSideCheck, sides, toIgnore) ?: continue } } + return null } From 0e0003faffa712def738c6f77c4e7bcef1d80d8e Mon Sep 17 00:00:00 2001 From: Christian Date: Wed, 27 Jan 2021 06:46:16 +0100 Subject: [PATCH 236/390] Fix sneaking when placing --- .../kami/module/modules/misc/HighwayTools.kt | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index dc15bb267b..51450fdab2 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -14,6 +14,7 @@ import me.zeroeightsix.kami.module.modules.player.InventoryManager import me.zeroeightsix.kami.process.HighwayToolsProcess import me.zeroeightsix.kami.util.* import me.zeroeightsix.kami.util.EntityUtils.flooredPosition +import me.zeroeightsix.kami.util.WorldUtils.blackList import me.zeroeightsix.kami.util.WorldUtils.getNeighbour import me.zeroeightsix.kami.util.WorldUtils.isPlaceable import me.zeroeightsix.kami.util.color.ColorHolder @@ -934,25 +935,36 @@ internal object HighwayTools : Module( return } - val hitVecOffset = WorldUtils.getHitVecOffset(pair.first) lastHitVec = WorldUtils.getHitVec(pair.second, pair.first) rotateTimer.reset() - connection.sendPacket(CPacketEntityAction(player, CPacketEntityAction.Action.START_SNEAKING)) + dispatchGenericPlaceThread(blockTask, pair) + } + + private fun SafeClientEvent.dispatchGenericPlaceThread(blockTask: BlockTask, pair: Pair) { + val hitVecOffset = WorldUtils.getHitVecOffset(pair.first) defaultScope.launch { blockTask.updateState(TaskState.PENDING_PLACED) - delay(10L) + if (world.getBlockState(pair.second).block in blackList) { + delay(10L) + onMainThreadSafe { + connection.sendPacket(CPacketEntityAction(player, CPacketEntityAction.Action.START_SNEAKING)) + } + } + onMainThreadSafe { val placePacket = CPacketPlayerTryUseItemOnBlock(pair.second, pair.first, EnumHand.MAIN_HAND, hitVecOffset.x.toFloat(), hitVecOffset.y.toFloat(), hitVecOffset.z.toFloat()) connection.sendPacket(placePacket) player.swingArm(EnumHand.MAIN_HAND) } - delay(10L) - onMainThreadSafe { - connection.sendPacket(CPacketEntityAction(player, CPacketEntityAction.Action.STOP_SNEAKING)) + if (world.getBlockState(pair.second).block in blackList) { + delay(10L) + onMainThreadSafe { + connection.sendPacket(CPacketEntityAction(player, CPacketEntityAction.Action.STOP_SNEAKING)) + } } delay(50L * taskTimeoutTicks) From c6b892d0e7fd181299e268d456bef6ad72254520 Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Wed, 27 Jan 2021 01:46:42 -0500 Subject: [PATCH 237/390] Fixed mining visible check --- .../kami/module/modules/misc/HighwayTools.kt | 23 ++++++++----------- .../me/zeroeightsix/kami/util/WorldUtils.kt | 20 +++++++++++----- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 51450fdab2..fad358d721 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -15,6 +15,7 @@ import me.zeroeightsix.kami.process.HighwayToolsProcess import me.zeroeightsix.kami.util.* import me.zeroeightsix.kami.util.EntityUtils.flooredPosition import me.zeroeightsix.kami.util.WorldUtils.blackList +import me.zeroeightsix.kami.util.WorldUtils.getMiningSide import me.zeroeightsix.kami.util.WorldUtils.getNeighbour import me.zeroeightsix.kami.util.WorldUtils.isPlaceable import me.zeroeightsix.kami.util.color.ColorHolder @@ -25,7 +26,6 @@ import me.zeroeightsix.kami.util.math.CoordinateConverter.asString import me.zeroeightsix.kami.util.math.RotationUtils.getRotationTo import me.zeroeightsix.kami.util.math.VectorUtils.distanceTo import me.zeroeightsix.kami.util.math.VectorUtils.multiply -import me.zeroeightsix.kami.util.math.VectorUtils.toVec3dCenter import me.zeroeightsix.kami.util.text.MessageSendHelper.sendChatMessage import me.zeroeightsix.kami.util.threads.* import net.minecraft.block.Block @@ -42,7 +42,6 @@ import net.minecraft.network.play.server.SPacketBlockChange import net.minecraft.util.EnumFacing import net.minecraft.util.EnumHand import net.minecraft.util.SoundCategory -import net.minecraft.util.math.AxisAlignedBB import net.minecraft.util.math.BlockPos import net.minecraft.util.math.Vec3d import net.minecraftforge.fml.common.gameevent.TickEvent @@ -859,37 +858,35 @@ internal object HighwayTools : Module( return } - val rayTraceResult = AxisAlignedBB(blockTask.blockPos).calculateIntercept(player.getPositionEyes(1.0f), blockTask.blockPos.toVec3dCenter()) - - if (rayTraceResult == null) { + val side = getMiningSide(blockTask.blockPos) ?: run { blockTask.onStuck() return } - val side = rayTraceResult.sideHit - lastHitVec = rayTraceResult.hitVec + lastHitVec = WorldUtils.getHitVec(blockTask.blockPos, side) rotateTimer.reset() when (world.getBlockState(blockTask.blockPos).block) { - Blocks.NETHERRACK -> dispatchInstantBreakThread(blockTask, side) - else -> dispatchGenericMineThread(blockTask, side) + Blocks.NETHERRACK -> mineBlockInstant(blockTask, side) + else -> mineBlockNormal(blockTask, side) } } - private fun dispatchInstantBreakThread(blockTask: BlockTask, facing: EnumFacing) { + private fun mineBlockInstant(blockTask: BlockTask, side: EnumFacing) { waitTicks = tickDelayBreak + defaultScope.launch { blockTask.updateState(TaskState.PENDING_BROKEN) delay(10L) onMainThreadSafe { - connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, blockTask.blockPos, facing)) + connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, blockTask.blockPos, side)) player.swingArm(EnumHand.MAIN_HAND) } delay(40L) onMainThreadSafe { - connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, blockTask.blockPos, facing)) + connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, blockTask.blockPos, side)) player.swingArm(EnumHand.MAIN_HAND) } @@ -901,7 +898,7 @@ internal object HighwayTools : Module( } /* Dispatches a thread to mine any non-netherrack blocks generically */ - private fun dispatchGenericMineThread(blockTask: BlockTask, facing: EnumFacing) { + private fun mineBlockNormal(blockTask: BlockTask, facing: EnumFacing) { val action = if (blockTask.taskState == TaskState.BREAKING) { CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK } else { diff --git a/src/main/java/me/zeroeightsix/kami/util/WorldUtils.kt b/src/main/java/me/zeroeightsix/kami/util/WorldUtils.kt index 4858229127..c2d265f799 100644 --- a/src/main/java/me/zeroeightsix/kami/util/WorldUtils.kt +++ b/src/main/java/me/zeroeightsix/kami/util/WorldUtils.kt @@ -134,6 +134,14 @@ object WorldUtils { return Vec3d(vec.x * 0.5 + 0.5, vec.y * 0.5 + 0.5, vec.z * 0.5 + 0.5) } + fun SafeClientEvent.getMiningSide(pos: BlockPos) : EnumFacing? { + val eyePos = player.getPositionEyes(1.0f) + + return getVisibleSides(pos) + .filter { !world.getBlockState(pos.offset(it)).isFullCube } + .minByOrNull { eyePos.distanceTo(getHitVec(pos, it)) } + } + /** * Get the "visible" sides related to player's eye position * @@ -142,17 +150,17 @@ object WorldUtils { fun SafeClientEvent.getVisibleSides(pos: BlockPos): Set { val visibleSides = EnumSet.noneOf(EnumFacing::class.java) - val blockState = world.getBlockState(pos) + val isFullCube = world.getBlockState(pos).isFullCube val eyePos = player.getPositionEyes(1.0f) val blockCenter = pos.toVec3dCenter() return visibleSides - .checkAxis(blockState, eyePos.x - blockCenter.x, EnumFacing.WEST, EnumFacing.EAST) - .checkAxis(blockState, eyePos.y - blockCenter.y, EnumFacing.DOWN, EnumFacing.UP) - .checkAxis(blockState, eyePos.z - blockCenter.z, EnumFacing.NORTH, EnumFacing.SOUTH) + .checkAxis(eyePos.x - blockCenter.x, EnumFacing.WEST, EnumFacing.EAST, isFullCube) + .checkAxis(eyePos.y - blockCenter.y, EnumFacing.DOWN, EnumFacing.UP, true) + .checkAxis(eyePos.z - blockCenter.z, EnumFacing.NORTH, EnumFacing.SOUTH, isFullCube) } - private fun EnumSet.checkAxis(blockState: IBlockState, diff: Double, negativeSide: EnumFacing, positiveSide: EnumFacing) = + private fun EnumSet.checkAxis(diff: Double, negativeSide: EnumFacing, positiveSide: EnumFacing, bothIfInRange: Boolean) = this.apply { when { diff < -0.5 -> { @@ -162,7 +170,7 @@ object WorldUtils { add(positiveSide) } else -> { - if (!blockState.isFullBlock) { + if (bothIfInRange) { add(negativeSide) add(positiveSide) } From f1313337e366e5b1d3c59ba994e29ab17e19a27a Mon Sep 17 00:00:00 2001 From: Christian Date: Wed, 27 Jan 2021 07:56:03 +0100 Subject: [PATCH 238/390] Fix liquid handling --- .../kami/module/modules/misc/HighwayTools.kt | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index fad358d721..0c74b5b7cf 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -564,7 +564,7 @@ internal object HighwayTools : Module( TaskState.PLACED -> { doPlaced(blockTask) } - TaskState.EMERGENCY_BREAK, TaskState.BREAK -> { + TaskState.BREAK -> { doBreak(blockTask) } TaskState.PLACE, TaskState.LIQUID_SOURCE, TaskState.LIQUID_FLOW -> { @@ -660,8 +660,7 @@ internal object HighwayTools : Module( private fun SafeClientEvent.doBreak(blockTask: BlockTask) { // ignore blocks - if (blockTask.taskState != TaskState.EMERGENCY_BREAK - && blockTask.block != Blocks.AIR + if (blockTask.block != Blocks.AIR && ignoreBlocks.contains(blockTask.block)) { blockTask.updateState(TaskState.DONE) } @@ -687,13 +686,7 @@ internal object HighwayTools : Module( } } else -> { - // liquid search around the breaking block - if (blockTask.taskState != TaskState.EMERGENCY_BREAK) { - if (handleLiquid(blockTask)) { - blockTask.updateState(TaskState.EMERGENCY_BREAK) - return - } - } + if (handleLiquid(blockTask)) return inventoryProcessor(blockTask) @@ -751,7 +744,7 @@ internal object HighwayTools : Module( private fun SafeClientEvent.inventoryProcessor(blockTask: BlockTask) { when (blockTask.taskState) { - TaskState.BREAK, TaskState.EMERGENCY_BREAK -> { + TaskState.BREAK -> { swapOrMoveBestTool(blockTask) } TaskState.PLACE, TaskState.LIQUID_FLOW, TaskState.LIQUID_SOURCE -> { @@ -905,7 +898,7 @@ internal object HighwayTools : Module( CPacketPlayerDigging.Action.START_DESTROY_BLOCK } - if (blockTask.taskState == TaskState.BREAK || blockTask.taskState == TaskState.EMERGENCY_BREAK) { + if (blockTask.taskState == TaskState.BREAK) { blockTask.updateState(TaskState.BREAKING) } @@ -1179,7 +1172,6 @@ internal object HighwayTools : Module( LIQUID_SOURCE(100, 100, ColorHolder(120, 41, 240)), LIQUID_FLOW(80, 80, ColorHolder(120, 41, 240)), BREAKING(100, 100, ColorHolder(240, 222, 60)), - EMERGENCY_BREAK(20, 20, ColorHolder(220, 41, 140)), BREAK(20, 20, ColorHolder(222, 0, 0)), PLACE(20, 10, ColorHolder(35, 188, 254)), PENDING_BROKEN(100, 100, ColorHolder(0, 0, 0)), From 0cf614700a8af15cef6563f83678176df1657cc8 Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Wed, 27 Jan 2021 01:58:42 -0500 Subject: [PATCH 239/390] Find tool in hotbar first --- .../me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 0c74b5b7cf..4476c6f204 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -765,7 +765,7 @@ internal object HighwayTools : Module( } private fun SafeClientEvent.swapOrMoveBestTool(blockTask: BlockTask) { - val slotFrom = player.inventorySlots.maxByOrNull { + val slotFrom = player.inventorySlots.asReversed().maxByOrNull { val stack = it.stack if (stack.isEmpty) { 0.0f From 3268d959400117e9ab3efd1ee746929e1506493e Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Wed, 27 Jan 2021 02:39:58 -0500 Subject: [PATCH 240/390] Use iteration instead of recursive --- .../kami/module/modules/misc/HighwayTools.kt | 65 +++++++++++-------- 1 file changed, 37 insertions(+), 28 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 4476c6f204..6cf15958d3 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -74,8 +74,8 @@ internal object HighwayTools : Module( private val cornerBlock by setting("CornerBlock", false, { page == Page.BUILD && (mode == Mode.HIGHWAY || mode == Mode.TUNNEL) }) // behavior settings - private val tickDelayPlace by setting("TickDelayPlace", 3, 0..16, 1, { page == Page.BEHAVIOR }) - private val tickDelayBreak by setting("TickDelayBreak", 1, 0..16, 1, { page == Page.BEHAVIOR }) + private val tickDelayPlace by setting("TickDelayPlace", 1, 1..20, 1, { page == Page.BEHAVIOR }) + private val tickDelayBreak by setting("TickDelayBreak", 1, 1..20, 1, { page == Page.BEHAVIOR }) private val taskTimeoutTicks by setting("TaskTimeoutTicks", 3, 0..16, 1, { page == Page.BEHAVIOR }) private val interacting by setting("InteractMode", InteractMode.SPOOF, { page == Page.BEHAVIOR }) private val illegalPlacements by setting("IllegalPlacements", false, { page == Page.BEHAVIOR }) @@ -376,6 +376,7 @@ internal object HighwayTools : Module( private fun SafeClientEvent.pickTasksInRange() { val eyePos = player.getPositionEyes(1f) val startBlocker = startingBlockPos.add(startingDirection.clockwise(4).directionVec.multiply(maxReach.toInt() - 1)) + blueprintNew.keys.removeIf { eyePos.distanceTo(it) > maxReach - 0.7 || startBlocker.distanceTo(it) < maxReach } @@ -504,40 +505,25 @@ internal object HighwayTools : Module( private fun SafeClientEvent.runTasks() { if (pendingTasks.isNotEmpty()) { - if (waitTicks > 0) { - waitTicks-- - return - } - -// (startingBlockPos.distanceTo(player.position) / startingBlockPos.distanceTo(it.blockPos)) * player.distanceTo(it.blockPos) * (lastHitVec.distanceTo(it.blockPos) * 2) + waitTicks-- sortTasks() - val firstTask = sortedTasks[0] + for (task in sortedTasks) { + if (!checkStuckTimeout(task)) return + if (task.taskState != TaskState.DONE && waitTicks > 0) return - val timeout = firstTask.taskState.stuckTimeout - if (firstTask.stuckTicks > timeout) { - when (firstTask.taskState) { - TaskState.PENDING_BROKEN -> firstTask.updateState(TaskState.BREAK) - TaskState.PENDING_PLACED -> firstTask.updateState(TaskState.PLACE) + doTask(task) + + when (task.taskState) { + TaskState.DONE, TaskState.BROKEN, TaskState.PLACED -> { + continue + } else -> { - if (debugMessages != DebugMessages.OFF) { - sendChatMessage("Stuck while ${firstTask.taskState}@(${firstTask.blockPos.asString()}) for more then $timeout ticks (${firstTask.stuckTicks}), refreshing data.") - } - refreshData() + break } } } - - doTask(firstTask) - - when (firstTask.taskState) { - TaskState.DONE, - TaskState.BROKEN, - TaskState.PLACED -> runTasks() - else -> { - } - } } else { if (checkDoneTasks()) { doneTasks.clear() @@ -548,6 +534,29 @@ internal object HighwayTools : Module( } } + private fun SafeClientEvent.checkStuckTimeout(blockTask: BlockTask): Boolean { + val timeout = blockTask.taskState.stuckTimeout + if (blockTask.stuckTicks > timeout) { + when (blockTask.taskState) { + TaskState.PENDING_BROKEN -> { + blockTask.updateState(TaskState.BREAK) + } + TaskState.PENDING_PLACED -> { + blockTask.updateState(TaskState.PLACE) + } + else -> { + if (debugMessages != DebugMessages.OFF) { + sendChatMessage("Stuck while ${blockTask.taskState}@(${blockTask.blockPos.asString()}) for more then $timeout ticks (${blockTask.stuckTicks}), refreshing data.") + } + refreshData() + return false + } + } + } + + return true + } + private fun SafeClientEvent.doTask(blockTask: BlockTask) { blockTask.onTick() From 44f6b7a033b1f583895df5bb808e79a2243b1ea4 Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Wed, 27 Jan 2021 03:20:15 -0500 Subject: [PATCH 241/390] Reverted unneeded changes --- .../module/modules/player/NoBreakAnimation.kt | 2 +- .../module/modules/player/PacketLogger.kt | 2 - .../kami/util/math/BoundingBoxUtils.kt | 44 ------------------- 3 files changed, 1 insertion(+), 47 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/player/NoBreakAnimation.kt b/src/main/java/me/zeroeightsix/kami/module/modules/player/NoBreakAnimation.kt index 5a440026b2..3ea8767244 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/player/NoBreakAnimation.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/player/NoBreakAnimation.kt @@ -58,7 +58,7 @@ internal object NoBreakAnimation : Module( } } - fun resetMining() { + private fun resetMining() { isMining = false lastPos = null lastFacing = null diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/player/PacketLogger.kt b/src/main/java/me/zeroeightsix/kami/module/modules/player/PacketLogger.kt index 1c96514db3..a46937caa2 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/player/PacketLogger.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/player/PacketLogger.kt @@ -75,7 +75,6 @@ internal object PacketLogger : Module( synchronized(this) { lines.add("Tick Pulse - Realtime: ${logTimeFormatter.format(LocalTime.now())} - Runtime: ${System.currentTimeMillis() - start}ms\n") } - } /* Don't let lines get too big, write periodically to the file */ @@ -88,7 +87,6 @@ internal object PacketLogger : Module( disable() } - safeListener(Int.MIN_VALUE) { if (ignoreCancelled && it.cancelled) return@safeListener diff --git a/src/main/java/me/zeroeightsix/kami/util/math/BoundingBoxUtils.kt b/src/main/java/me/zeroeightsix/kami/util/math/BoundingBoxUtils.kt index 24335742e4..4ab09996d7 100644 --- a/src/main/java/me/zeroeightsix/kami/util/math/BoundingBoxUtils.kt +++ b/src/main/java/me/zeroeightsix/kami/util/math/BoundingBoxUtils.kt @@ -35,48 +35,4 @@ fun AxisAlignedBB.side(side: EnumFacing, scale: Double = 0.5): Vec3d { val lengths = lengths val sideDirectionVec = side.directionVec.toVec3d() return lengths * sideDirectionVec * scale + center -} - -fun AxisAlignedBB.faceCorners(facing: EnumFacing, scale: Double) : Array { - - val selectedCorners = mutableListOf() - when (facing) { - EnumFacing.UP -> { - selectedCorners.add(Vec3d(minX + scale * xLength, maxY - 0.01, minZ + scale * zLength)) - selectedCorners.add(Vec3d(maxX - scale * xLength, maxY - 0.01, minZ + scale * zLength)) - selectedCorners.add(Vec3d(minX + scale * xLength, maxY - 0.01, maxZ - scale * zLength)) - selectedCorners.add(Vec3d(maxX - scale * xLength, maxY - 0.01, maxZ - scale * zLength)) - } - EnumFacing.DOWN -> { - selectedCorners.add(Vec3d(minX + scale * xLength, minY + 0.01, minZ + scale * zLength)) - selectedCorners.add(Vec3d(maxX - scale * xLength, minY + 0.01, minZ + scale * zLength)) - selectedCorners.add(Vec3d(minX + scale * xLength, minY + 0.01, maxZ - scale * zLength)) - selectedCorners.add(Vec3d(maxX - scale * xLength, minY + 0.01, maxZ - scale * zLength)) - } - EnumFacing.NORTH -> { - selectedCorners.add(Vec3d(minX + scale * xLength, minY + scale * yLength, minZ + 0.01)) - selectedCorners.add(Vec3d(maxX - scale * xLength, minY + scale * yLength, minZ + 0.01)) - selectedCorners.add(Vec3d(minX + scale * xLength, maxY - scale * yLength, minZ + 0.01)) - selectedCorners.add(Vec3d(maxX - scale * xLength, maxY - scale * yLength, minZ + 0.01)) - } - EnumFacing.EAST -> { - selectedCorners.add(Vec3d(maxX - 0.01, minY + scale * yLength, minZ + scale * zLength)) - selectedCorners.add(Vec3d(maxX - 0.01, minY + scale * yLength, minZ + scale * zLength)) - selectedCorners.add(Vec3d(maxX - 0.01, maxY - scale * yLength, maxZ - scale * zLength)) - selectedCorners.add(Vec3d(maxX - 0.01, maxY - scale * yLength, maxZ - scale * zLength)) - } - EnumFacing.SOUTH -> { - selectedCorners.add(Vec3d(minX + scale * xLength, minY + scale * yLength, maxZ - 0.01)) - selectedCorners.add(Vec3d(maxX - scale * xLength, minY + scale * yLength, maxZ - 0.01)) - selectedCorners.add(Vec3d(minX + scale * xLength, maxY - scale * yLength, maxZ - 0.01)) - selectedCorners.add(Vec3d(maxX - scale * xLength, maxY - scale * yLength, maxZ - 0.01)) - } - EnumFacing.WEST -> { - selectedCorners.add(Vec3d(minX + 0.01, minY + scale * yLength, minZ + scale * zLength)) - selectedCorners.add(Vec3d(minX + 0.01, minY + scale * yLength, minZ + scale * zLength)) - selectedCorners.add(Vec3d(minX + 0.01, maxY - scale * yLength, maxZ - scale * zLength)) - selectedCorners.add(Vec3d(minX + 0.01, maxY - scale * yLength, maxZ - scale * zLength)) - } - } - return selectedCorners.toTypedArray() } \ No newline at end of file From 4caf7803d2f1f109841e91ea4ebe0decd10f9273 Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Wed, 27 Jan 2021 03:29:07 -0500 Subject: [PATCH 242/390] Cleaned up item swapping --- .../kami/module/modules/misc/HighwayTools.kt | 42 +++++++++---------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 6cf15958d3..2beb8a0931 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -667,7 +667,6 @@ internal object HighwayTools : Module( } private fun SafeClientEvent.doBreak(blockTask: BlockTask) { - // ignore blocks if (blockTask.block != Blocks.AIR && ignoreBlocks.contains(blockTask.block)) { @@ -697,7 +696,7 @@ internal object HighwayTools : Module( else -> { if (handleLiquid(blockTask)) return - inventoryProcessor(blockTask) + swapOrMoveBestTool(blockTask) mineBlock(blockTask) } @@ -721,7 +720,10 @@ internal object HighwayTools : Module( return } - inventoryProcessor(blockTask) + if (!swapOrMoveBlock(blockTask)) { + blockTask.onStuck() + return + } placeBlock(blockTask) @@ -751,29 +753,20 @@ internal object HighwayTools : Module( return true } - private fun SafeClientEvent.inventoryProcessor(blockTask: BlockTask) { - when (blockTask.taskState) { - TaskState.BREAK -> { - swapOrMoveBestTool(blockTask) - } - TaskState.PLACE, TaskState.LIQUID_FLOW, TaskState.LIQUID_SOURCE -> { - if (!swapToBlock(blockTask.block)) { - if (!swapToBlockOrMove(Blocks.ENDER_CHEST)) { - sendChatMessage("$chatName No ${blockTask.block.localizedName} was found in inventory") - mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) - disable() - blockTask.onStuck() - } - return - } - } - else -> { - blockTask.onStuck() + private fun SafeClientEvent.swapOrMoveBlock(blockTask: BlockTask): Boolean { + return if (!swapToBlock(blockTask.block)) { + if (!swapToBlockOrMove(blockTask.block)) { + sendChatMessage("$chatName No ${blockTask.block.localizedName} was found in inventory") + mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) + disable() } + false + } else { + true } } - private fun SafeClientEvent.swapOrMoveBestTool(blockTask: BlockTask) { + private fun SafeClientEvent.swapOrMoveBestTool(blockTask: BlockTask) : Boolean { val slotFrom = player.inventorySlots.asReversed().maxByOrNull { val stack = it.stack if (stack.isEmpty) { @@ -792,13 +785,16 @@ internal object HighwayTools : Module( } } - if (slotFrom != null) { + return if (slotFrom != null) { slotFrom.toHotbarSlotOrNull()?.let { swapToSlot(it) } ?: run { val slotTo = player.hotbarSlots.firstEmpty()?.hotbarSlot ?: 0 moveToHotbar(slotFrom.slotNumber, slotTo) } + true + } else { + false } } From 06d013289cc20bfed242fde2271a12643a08ae68 Mon Sep 17 00:00:00 2001 From: Christian Date: Wed, 27 Jan 2021 09:42:54 +0100 Subject: [PATCH 243/390] Fix imports --- src/main/java/me/zeroeightsix/kami/util/WorldUtils.kt | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/util/WorldUtils.kt b/src/main/java/me/zeroeightsix/kami/util/WorldUtils.kt index c2d265f799..f3730d4d71 100644 --- a/src/main/java/me/zeroeightsix/kami/util/WorldUtils.kt +++ b/src/main/java/me/zeroeightsix/kami/util/WorldUtils.kt @@ -5,9 +5,7 @@ import me.zeroeightsix.kami.event.SafeClientEvent import me.zeroeightsix.kami.manager.managers.PlayerPacketManager import me.zeroeightsix.kami.util.math.RotationUtils.getRotationTo import me.zeroeightsix.kami.util.math.VectorUtils.toVec3dCenter -import me.zeroeightsix.kami.util.math.faceCorners import me.zeroeightsix.kami.util.threads.runSafeSuspend -import net.minecraft.block.state.IBlockState import net.minecraft.entity.Entity import net.minecraft.init.Blocks import net.minecraft.item.ItemBlock From b67b7bfeef5896fc7072ba56083f5ab98861307b Mon Sep 17 00:00:00 2001 From: Christian Date: Wed, 27 Jan 2021 10:05:43 +0100 Subject: [PATCH 244/390] Better standart setting --- .../me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 2beb8a0931..fedb1465e5 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -74,9 +74,9 @@ internal object HighwayTools : Module( private val cornerBlock by setting("CornerBlock", false, { page == Page.BUILD && (mode == Mode.HIGHWAY || mode == Mode.TUNNEL) }) // behavior settings - private val tickDelayPlace by setting("TickDelayPlace", 1, 1..20, 1, { page == Page.BEHAVIOR }) + private val tickDelayPlace by setting("TickDelayPlace", 2, 1..20, 1, { page == Page.BEHAVIOR }) private val tickDelayBreak by setting("TickDelayBreak", 1, 1..20, 1, { page == Page.BEHAVIOR }) - private val taskTimeoutTicks by setting("TaskTimeoutTicks", 3, 0..16, 1, { page == Page.BEHAVIOR }) + private val taskTimeoutTicks by setting("TaskTimeoutTicks", 5, 0..16, 1, { page == Page.BEHAVIOR }) private val interacting by setting("InteractMode", InteractMode.SPOOF, { page == Page.BEHAVIOR }) private val illegalPlacements by setting("IllegalPlacements", false, { page == Page.BEHAVIOR }) private val maxReach by setting("MaxReach", 4.5f, 1.0f..6.0f, 0.1f, { page == Page.BEHAVIOR }) From 7290a5dc1ad25e2e904fedde61ad47867a8f5d9e Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Wed, 27 Jan 2021 03:45:44 -0500 Subject: [PATCH 245/390] Cleaned up toggle messages --- .../kami/module/modules/misc/HighwayTools.kt | 186 +++++++++--------- 1 file changed, 90 insertions(+), 96 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index fedb1465e5..1292f46468 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -26,7 +26,7 @@ import me.zeroeightsix.kami.util.math.CoordinateConverter.asString import me.zeroeightsix.kami.util.math.RotationUtils.getRotationTo import me.zeroeightsix.kami.util.math.VectorUtils.distanceTo import me.zeroeightsix.kami.util.math.VectorUtils.multiply -import me.zeroeightsix.kami.util.text.MessageSendHelper.sendChatMessage +import me.zeroeightsix.kami.util.text.MessageSendHelper import me.zeroeightsix.kami.util.threads.* import net.minecraft.block.Block import net.minecraft.block.BlockLiquid @@ -114,8 +114,7 @@ internal object HighwayTools : Module( private var startingDirection = Direction.NORTH private var currentBlockPos = BlockPos(0, -1, 0) private var startingBlockPos = BlockPos(0, -1, 0) - private val blueprint = ArrayList>() - private val blueprintNew = LinkedHashMap() + private val blueprint = LinkedHashMap() private var sortedTasks: List = emptyList() // State @@ -151,62 +150,90 @@ internal object HighwayTools : Module( init { onEnable { - if (mc.player == null) { - disable() - return@onEnable - } - - /* Turn on inventory manager if the users wants us to control it */ - if (toggleInventoryManager && InventoryManager.isDisabled) InventoryManager.enable() + runSafeR { + /* Turn on inventory manager if the users wants us to control it */ + if (toggleInventoryManager && InventoryManager.isDisabled) { + InventoryManager.enable() + } - /* Turn on Auto Obsidian if the user wants us to control it. */ - if (toggleAutoObsidian && AutoObsidian.isDisabled && mode != Mode.TUNNEL) { - AutoObsidian.enable() - } + /* Turn on Auto Obsidian if the user wants us to control it. */ + if (toggleAutoObsidian && AutoObsidian.isDisabled && mode != Mode.TUNNEL) { + AutoObsidian.enable() + } - startingBlockPos = mc.player.flooredPosition - currentBlockPos = startingBlockPos - startingDirection = Direction.fromEntity(mc.player) + startingBlockPos = Companion.mc.player.flooredPosition + currentBlockPos = startingBlockPos + startingDirection = Direction.fromEntity(Companion.mc.player) - startTime = System.currentTimeMillis() - totalBlocksPlaced = 0 - totalBlocksDestroyed = 0 + startTime = System.currentTimeMillis() + totalBlocksPlaced = 0 + totalBlocksDestroyed = 0 - baritoneSettingAllowPlace = BaritoneUtils.settings?.allowPlace?.value ?: true - BaritoneUtils.settings?.allowPlace?.value = false + baritoneSettingAllowPlace = BaritoneUtils.settings?.allowPlace?.value ?: true + BaritoneUtils.settings?.allowPlace?.value = false - if (!goalRender) { - baritoneSettingRenderGoal = BaritoneUtils.settings?.renderGoal?.value ?: true - BaritoneUtils.settings?.renderGoal?.value = false - } + if (!goalRender) { + baritoneSettingRenderGoal = BaritoneUtils.settings?.renderGoal?.value ?: true + BaritoneUtils.settings?.renderGoal?.value = false + } - runSafe { refreshData() printEnable() - } + } ?: disable() } onDisable { - if (mc.player == null) return@onDisable + runSafe { + /* Turn off inventory manager if the users wants us to control it */ + if (toggleInventoryManager && InventoryManager.isEnabled) { + InventoryManager.disable() + } - active = false + /* Turn off auto obsidian if the user wants us to control it */ + if (toggleAutoObsidian && AutoObsidian.isEnabled) { + AutoObsidian.disable() + } - BaritoneUtils.settings?.allowPlace?.value = baritoneSettingAllowPlace - if (!goalRender) BaritoneUtils.settings?.renderGoal?.value = baritoneSettingRenderGoal + BaritoneUtils.settings?.allowPlace?.value = baritoneSettingAllowPlace + if (!goalRender) BaritoneUtils.settings?.renderGoal?.value = baritoneSettingRenderGoal - /* Turn off inventory manager if the users wants us to control it */ - if (toggleInventoryManager && InventoryManager.isEnabled) InventoryManager.disable() + active = false + lastTask = null - /* Turn off auto obsidian if the user wants us to control it */ - if (toggleAutoObsidian && AutoObsidian.isEnabled) { - AutoObsidian.disable() + printDisable() + } + } + } + + private fun printEnable() { + if (info) { + MessageSendHelper.sendRawChatMessage(" §9> §7Direction: §a${startingDirection.displayName}§r") + + if (startingDirection.isDiagonal) { + MessageSendHelper.sendRawChatMessage(" §9> §7Coordinates: §a${startingBlockPos.x} ${startingBlockPos.z}§r") + } else { + if (startingDirection == Direction.NORTH || startingDirection == Direction.SOUTH) { + MessageSendHelper.sendRawChatMessage(" §9> §7Coordinate: §a${startingBlockPos.x}§r") + } else { + MessageSendHelper.sendRawChatMessage(" §9> §7Coordinate: §a${startingBlockPos.z}§r") + } } - lastTask = null + if (startingBlockPos.y in 117..119 && mode != Mode.TUNNEL) { + MessageSendHelper.sendRawChatMessage(" §9> §cCheck coordinate Y / altitude and make sure to move around Y 120 for the correct height") + } + } + } - printDisable() + private fun printDisable() { + if (info) { + MessageSendHelper.sendRawChatMessage(" §9> §7Placed blocks: §a$totalBlocksPlaced§r") + MessageSendHelper.sendRawChatMessage(" §9> §7Destroyed blocks: §a$totalBlocksDestroyed§r") + MessageSendHelper.sendRawChatMessage(" §9> §7Distance: §a${startingBlockPos.distanceTo(currentBlockPos).toInt()}§r") } + } + init { safeListener { if (it.packet !is SPacketBlockChange) return@safeListener @@ -261,15 +288,16 @@ internal object HighwayTools : Module( renderer.clear() renderer.aFilled = if (filled) aFilled else 0 renderer.aOutline = if (outline) aOutline else 0 + for (blockTask in pendingTasks) { if (blockTask.taskState == TaskState.DONE) continue renderer.add(world.getBlockState(blockTask.blockPos).getSelectedBoundingBox(world, blockTask.blockPos), blockTask.taskState.color) } + for (blockTask in doneTasks) { if (blockTask.block == Blocks.AIR) continue renderer.add(world.getBlockState(blockTask.blockPos).getSelectedBoundingBox(world, blockTask.blockPos), blockTask.taskState.color) } -// renderer.add(world.getBlockState(currentBlockPos).getSelectedBoundingBox(world, currentBlockPos), ColorHolder(0, 0, 255)) } private fun SafeClientEvent.updateFood() { @@ -304,10 +332,10 @@ internal object HighwayTools : Module( pendingTasks.clear() lastTask = null - blueprintNew.clear() + blueprint.clear() generateBluePrint(originPos) - for ((pos, block) in blueprintNew) { + for ((pos, block) in blueprint) { if (block == Blocks.AIR) { addTaskClear(pos) } else { @@ -363,8 +391,8 @@ internal object HighwayTools : Module( if (mode != Mode.TUNNEL) generateBase(thisPos, xDirection) } if (mode == Mode.TUNNEL) { - blueprintNew[basePos.add(zDirection.directionVec.multiply(1))] = fillerMat - blueprintNew[basePos.add(zDirection.directionVec.multiply(2))] = fillerMat + blueprint[basePos.add(zDirection.directionVec.multiply(1))] = fillerMat + blueprint[basePos.add(zDirection.directionVec.multiply(2))] = fillerMat } pickTasksInRange() @@ -377,7 +405,7 @@ internal object HighwayTools : Module( val eyePos = player.getPositionEyes(1f) val startBlocker = startingBlockPos.add(startingDirection.clockwise(4).directionVec.multiply(maxReach.toInt() - 1)) - blueprintNew.keys.removeIf { + blueprint.keys.removeIf { eyePos.distanceTo(it) > maxReach - 0.7 || startBlocker.distanceTo(it) < maxReach } } @@ -395,9 +423,9 @@ internal object HighwayTools : Module( } if (mode == Mode.HIGHWAY) { - blueprintNew[pos] = Blocks.AIR + blueprint[pos] = Blocks.AIR } else { - if (!(isRail(w) && h == 0 && !cornerBlock)) blueprintNew[pos.up()] = Blocks.AIR + if (!(isRail(w) && h == 0 && !cornerBlock)) blueprint[pos.up()] = Blocks.AIR } } } @@ -411,10 +439,10 @@ internal object HighwayTools : Module( if (mode == Mode.HIGHWAY && isRail(w)) { val startHeight = if (cornerBlock) 0 else 1 for (y in startHeight..railingHeight) { - blueprintNew[pos.up(y)] = material + blueprint[pos.up(y)] = material } } else { - blueprintNew[pos] = material + blueprint[pos] = material } } } @@ -429,7 +457,7 @@ internal object HighwayTools : Module( val z = w2 - buildWidth / 2 val pos = basePos.add(x, 0, z) - blueprintNew[pos] = material + blueprint[pos] = material } } @@ -442,7 +470,7 @@ internal object HighwayTools : Module( val z = w2 - buildWidth / 2 val pos = basePos.add(x, y, z) - blueprintNew[pos] = Blocks.AIR + blueprint[pos] = Blocks.AIR } } } @@ -546,7 +574,7 @@ internal object HighwayTools : Module( } else -> { if (debugMessages != DebugMessages.OFF) { - sendChatMessage("Stuck while ${blockTask.taskState}@(${blockTask.blockPos.asString()}) for more then $timeout ticks (${blockTask.stuckTicks}), refreshing data.") + MessageSendHelper.sendChatMessage("Stuck while ${blockTask.taskState}@(${blockTask.blockPos.asString()}) for more then $timeout ticks (${blockTask.stuckTicks}), refreshing data.") } refreshData() return false @@ -580,7 +608,7 @@ internal object HighwayTools : Module( doPlace(blockTask) } TaskState.PENDING_BROKEN, TaskState.PENDING_PLACED -> { - if (debugMessages == DebugMessages.ALL) sendChatMessage("$chatName Currently waiting for blockState updates...") + if (debugMessages == DebugMessages.ALL) MessageSendHelper.sendChatMessage("$chatName Currently waiting for blockState updates...") // blockTask.onStuck() } } @@ -715,7 +743,7 @@ internal object HighwayTools : Module( } else -> { if (!isPlaceable(blockTask.blockPos)) { - if (debugMessages != DebugMessages.OFF) sendChatMessage("Invalid place position: " + blockTask.blockPos) + if (debugMessages != DebugMessages.OFF) MessageSendHelper.sendChatMessage("Invalid place position: " + blockTask.blockPos) refreshData() return } @@ -756,7 +784,7 @@ internal object HighwayTools : Module( private fun SafeClientEvent.swapOrMoveBlock(blockTask: BlockTask): Boolean { return if (!swapToBlock(blockTask.block)) { if (!swapToBlockOrMove(blockTask.block)) { - sendChatMessage("$chatName No ${blockTask.block.localizedName} was found in inventory") + MessageSendHelper.sendChatMessage("$chatName No ${blockTask.block.localizedName} was found in inventory") mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) disable() } @@ -766,7 +794,7 @@ internal object HighwayTools : Module( } } - private fun SafeClientEvent.swapOrMoveBestTool(blockTask: BlockTask) : Boolean { + private fun SafeClientEvent.swapOrMoveBestTool(blockTask: BlockTask): Boolean { val slotFrom = player.inventorySlots.asReversed().maxByOrNull { val stack = it.stack if (stack.isEmpty) { @@ -921,7 +949,7 @@ internal object HighwayTools : Module( ?: run { if (illegalPlacements) { if (debugMessages == DebugMessages.ALL) { - sendChatMessage("Trying to place through wall ${blockTask.blockPos}") + MessageSendHelper.sendChatMessage("Trying to place through wall ${blockTask.blockPos}") getNeighbour(blockTask.blockPos, 1, maxReach) ?: return } } else { @@ -970,11 +998,11 @@ internal object HighwayTools : Module( } private fun isInsideSelection(pos: BlockPos): Boolean { - return blueprintNew.containsKey(pos) + return blueprint.containsKey(pos) } private fun isInsideBlueprint(pos: BlockPos): Boolean { - return blueprintNew[pos]?.let { it != Blocks.AIR } ?: false + return blueprint[pos]?.let { it != Blocks.AIR } ?: false } private fun isInsideBuild(pos: BlockPos): Boolean { @@ -993,43 +1021,7 @@ internal object HighwayTools : Module( for (b in ignoreBlocks) append("\n §9> §7${b!!.registryName}") - sendChatMessage(toString()) - } - } - - private fun printEnable() { - if (info) { - StringBuilder(2).run { - append("$chatName Module started." + - "\n §9> §7Direction: §a${startingDirection.displayName}§r") - - if (startingDirection.isDiagonal) { - append("\n §9> §7Coordinates: §a${startingBlockPos.x} ${startingBlockPos.z}§r") - } else { - if (startingDirection == Direction.NORTH || startingDirection == Direction.SOUTH) { - append("\n §9> §7Coordinate: §a${startingBlockPos.x}§r") - } else { - append("\n §9> §7Coordinate: §a${startingBlockPos.z}§r") - } - } - if (startingBlockPos.y in 117..119 && mode != Mode.TUNNEL) append("\n §9> §cCheck coordinate Y / altitude and make sure to move around Y 120 for the correct height") - sendChatMessage(toString()) - } - } - } - - private fun printDisable() { - if (info) { - StringBuilder(2).run { - append( - "$chatName Module stopped." + - "\n §9> §7Placed blocks: §a$totalBlocksPlaced§r" + - "\n §9> §7Destroyed blocks: §a$totalBlocksDestroyed§r" - ) - append("\n §9> §7Distance: §a${startingBlockPos.distanceTo(currentBlockPos).toInt()}§r") - - sendChatMessage(toString()) - } + MessageSendHelper.sendChatMessage(toString()) } } @@ -1037,12 +1029,14 @@ internal object HighwayTools : Module( private fun getBlueprintStats(): Pair { var materialUsed = 0 var fillerMatUsed = 0 + for ((_, b) in blueprint) { when (b) { material -> materialUsed++ fillerMat -> fillerMatUsed++ } } + return Pair(materialUsed / 2, fillerMatUsed / 2) } From 6fcb61a0e33626ddede9cdfcc5a8f21925858435 Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Wed, 27 Jan 2021 04:20:21 -0500 Subject: [PATCH 246/390] Cleaned up task position code --- .../kami/module/modules/misc/HighwayTools.kt | 103 ++++++++---------- 1 file changed, 46 insertions(+), 57 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 1292f46468..4440ca6860 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -49,7 +49,6 @@ import org.kamiblue.commons.extension.ceilToInt import org.kamiblue.commons.extension.floorToInt import java.util.* import kotlin.collections.ArrayList -import kotlin.collections.HashSet import kotlin.collections.LinkedHashMap /** @@ -115,7 +114,6 @@ internal object HighwayTools : Module( private var currentBlockPos = BlockPos(0, -1, 0) private var startingBlockPos = BlockPos(0, -1, 0) private val blueprint = LinkedHashMap() - private var sortedTasks: List = emptyList() // State private var active = false @@ -129,8 +127,9 @@ internal object HighwayTools : Module( var goal: GoalNear? = null; private set // Tasks - private val pendingTasks = HashSet() - private val doneTasks = ArrayList() + private val pendingTasks = LinkedHashMap() + private val doneTasks = LinkedHashMap() + private var sortedTasks: List = emptyList() var lastTask: BlockTask? = null; private set // Stats @@ -198,6 +197,7 @@ internal object HighwayTools : Module( if (!goalRender) BaritoneUtils.settings?.renderGoal?.value = baritoneSettingRenderGoal active = false + goal = null lastTask = null printDisable() @@ -238,13 +238,14 @@ internal object HighwayTools : Module( if (it.packet !is SPacketBlockChange) return@safeListener val pos = it.packet.blockPosition - if (!isInsideSelection(pos)) return@safeListener + if (!isInsideBlueprint(pos)) return@safeListener val prev = world.getBlockState(pos) val new = it.packet.getBlockState() - if (isInsideBuild(pos) && prev.block != new.block) { - val task = getTaskFromPos(pos) + if (prev.block != new.block) { + val task = pendingTasks[pos] ?: return@safeListener + when { task.taskState == TaskState.PENDING_BROKEN && prev.block != Blocks.AIR && @@ -289,12 +290,12 @@ internal object HighwayTools : Module( renderer.aFilled = if (filled) aFilled else 0 renderer.aOutline = if (outline) aOutline else 0 - for (blockTask in pendingTasks) { + for (blockTask in pendingTasks.values) { if (blockTask.taskState == TaskState.DONE) continue renderer.add(world.getBlockState(blockTask.blockPos).getSelectedBoundingBox(world, blockTask.blockPos), blockTask.taskState.color) } - for (blockTask in doneTasks) { + for (blockTask in doneTasks.values) { if (blockTask.block == Blocks.AIR) continue renderer.add(world.getBlockState(blockTask.blockPos).getSelectedBoundingBox(world, blockTask.blockPos), blockTask.taskState.color) } @@ -368,16 +369,6 @@ internal object HighwayTools : Module( } } - private fun getTaskFromPos(pos: BlockPos): BlockTask { - for (task in pendingTasks) { - if (task.blockPos == pos) return task - } - for (task in doneTasks) { - if (task.blockPos == pos) return task - } - return BlockTask(BlockPos(0, -1, 0), TaskState.DONE, Blocks.AIR) - } - private fun SafeClientEvent.generateBluePrint(feetPos: BlockPos) { val basePos = feetPos.down() @@ -403,10 +394,9 @@ internal object HighwayTools : Module( private fun SafeClientEvent.pickTasksInRange() { val eyePos = player.getPositionEyes(1f) - val startBlocker = startingBlockPos.add(startingDirection.clockwise(4).directionVec.multiply(maxReach.toInt() - 1)) blueprint.keys.removeIf { - eyePos.distanceTo(it) > maxReach - 0.7 || startBlocker.distanceTo(it) < maxReach + eyePos.distanceTo(it) > maxReach - 0.7 } } @@ -477,46 +467,52 @@ internal object HighwayTools : Module( } private fun addTaskToPending(blockPos: BlockPos, taskState: TaskState, material: Block) { - pendingTasks.add(BlockTask(blockPos, taskState, material)) + pendingTasks[blockPos] = (BlockTask(blockPos, taskState, material)) } private fun addTaskToDone(blockPos: BlockPos, material: Block) { - doneTasks.add(BlockTask(blockPos, TaskState.DONE, material)) + doneTasks[blockPos] = (BlockTask(blockPos, TaskState.DONE, material)) } private fun SafeClientEvent.doPathing() { val nextPos = getNextPos() - if (player.flooredPosition.distanceTo(nextPos) < 2) { + if (player.flooredPosition.distanceTo(nextPos) < 2.0) { currentBlockPos = nextPos - goal = GoalNear(nextPos, 0) - } else { - goal = GoalNear(nextPos, 0) } + + goal = GoalNear(nextPos, 0) } private fun SafeClientEvent.getNextPos(): BlockPos { var nextPos = currentBlockPos val possiblePos = currentBlockPos.add(startingDirection.directionVec) - if (getTaskFromPos(possiblePos).taskState != TaskState.DONE || - getTaskFromPos(possiblePos.up()).taskState != TaskState.DONE || - getTaskFromPos(possiblePos.down()).taskState != TaskState.DONE) return nextPos - if (checkFOMO(possiblePos.up())) nextPos = possiblePos + + if (!isTaskDoneOrNull(possiblePos) || + !isTaskDoneOrNull(possiblePos.up()) || + !isTaskDoneOrNull(possiblePos.down())) return nextPos + + if (checkTasks(possiblePos.up())) nextPos = possiblePos if (currentBlockPos != nextPos) refreshData() + return nextPos } - private fun checkFOMO(origin: BlockPos): Boolean { - for (task in pendingTasks) { - if (task.taskState != TaskState.DONE && origin.distanceTo(task.blockPos) > maxReach - 1.0) return false + private fun isTaskDoneOrNull(pos: BlockPos) = + (pendingTasks[pos] ?: doneTasks[pos])?.let { + it.taskState == TaskState.DONE + } ?: true + + private fun checkTasks(pos: BlockPos): Boolean { + return pendingTasks.values.all { + it.taskState == TaskState.DONE || pos.distanceTo(it.blockPos) < maxReach - 2.0 } - return true } private fun SafeClientEvent.sortTasks() { - sortedTasks = pendingTasks.sortedWith( + sortedTasks = pendingTasks.values.sortedWith( compareBy { it.taskState.ordinal }.thenBy { @@ -615,8 +611,8 @@ internal object HighwayTools : Module( } private fun doDone(blockTask: BlockTask) { - pendingTasks.remove(blockTask) - doneTasks.add(blockTask) + pendingTasks[blockTask.blockPos] + doneTasks[blockTask.blockPos] = blockTask } private fun SafeClientEvent.doBreaking(blockTask: BlockTask) { @@ -631,7 +627,7 @@ internal object HighwayTools : Module( } is BlockLiquid -> { var filler = fillerMat - if (isInsideBlueprint(blockTask.blockPos) || fillerMatLeft == 0) filler = material + if (isInsideBlueprintBuild(blockTask.blockPos) || fillerMatLeft == 0) filler = material if (world.getBlockState(blockTask.blockPos).getValue(BlockLiquid.LEVEL) != 0) { blockTask.updateState(TaskState.LIQUID_FLOW) blockTask.updateMaterial(filler) @@ -712,7 +708,7 @@ internal object HighwayTools : Module( } is BlockLiquid -> { var filler = fillerMat - if (isInsideBlueprint(blockTask.blockPos) || fillerMatLeft == 0) filler = material + if (isInsideBlueprintBuild(blockTask.blockPos) || fillerMatLeft == 0) filler = material if (world.getBlockState(blockTask.blockPos).getValue(BlockLiquid.LEVEL) != 0) { blockTask.updateState(TaskState.LIQUID_FLOW) blockTask.updateMaterial(filler) @@ -755,7 +751,7 @@ internal object HighwayTools : Module( placeBlock(blockTask) - if (blockTask.taskState != TaskState.PLACE && isInsideSelection(blockTask.blockPos)) { + if (blockTask.taskState != TaskState.PLACE && isInsideBlueprint(blockTask.blockPos)) { blockTask.updateMaterial(Blocks.AIR) } @@ -767,7 +763,7 @@ internal object HighwayTools : Module( } private fun SafeClientEvent.checkDoneTasks(): Boolean { - for (blockTask in doneTasks) { + for (blockTask in doneTasks.values) { val block = world.getBlockState(blockTask.blockPos).block if (ignoreBlocks.contains(block)) continue @@ -841,13 +837,13 @@ internal object HighwayTools : Module( foundLiquid = true val found = ArrayList>() - val filler = if (isInsideBlueprint(neighbour)) material else fillerMat + val filler = if (isInsideBlueprintBuild(neighbour)) material else fillerMat - for (bt in pendingTasks) { - if (bt.blockPos == neighbour) { + for (task in pendingTasks.values) { + if (task.blockPos == neighbour) { when (isFlowing) { - false -> found.add(Triple(bt, TaskState.LIQUID_SOURCE, filler)) - true -> found.add(Triple(bt, TaskState.LIQUID_FLOW, filler)) + false -> found.add(Triple(task, TaskState.LIQUID_SOURCE, filler)) + true -> found.add(Triple(task, TaskState.LIQUID_FLOW, filler)) } } } @@ -997,21 +993,14 @@ internal object HighwayTools : Module( } } - private fun isInsideSelection(pos: BlockPos): Boolean { + private fun isInsideBlueprint(pos: BlockPos): Boolean { return blueprint.containsKey(pos) } - private fun isInsideBlueprint(pos: BlockPos): Boolean { + private fun isInsideBlueprintBuild(pos: BlockPos): Boolean { return blueprint[pos]?.let { it != Blocks.AIR } ?: false } - private fun isInsideBuild(pos: BlockPos): Boolean { - for (task in pendingTasks) { - if (task.blockPos == pos) return true - } - return false - } - fun printSettings() { StringBuilder(ignoreBlocks.size + 1).run { append("$chatName Settings" + @@ -1109,7 +1098,7 @@ internal object HighwayTools : Module( message.add("Pending Tasks:") addTaskToMessageList(message, sortedTasks) message.add("Done Tasks:") - addTaskToMessageList(message, doneTasks) + addTaskToMessageList(message, doneTasks.values) return message } From de9ef5536b8cb6dc929f127a396b171829f283a8 Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Wed, 27 Jan 2021 04:21:46 -0500 Subject: [PATCH 247/390] Renamed InteractMode to RotationMode --- .../kami/module/modules/misc/HighwayTools.kt | 50 ++++++++----------- 1 file changed, 21 insertions(+), 29 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 4440ca6860..01964f9243 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -76,7 +76,7 @@ internal object HighwayTools : Module( private val tickDelayPlace by setting("TickDelayPlace", 2, 1..20, 1, { page == Page.BEHAVIOR }) private val tickDelayBreak by setting("TickDelayBreak", 1, 1..20, 1, { page == Page.BEHAVIOR }) private val taskTimeoutTicks by setting("TaskTimeoutTicks", 5, 0..16, 1, { page == Page.BEHAVIOR }) - private val interacting by setting("InteractMode", InteractMode.SPOOF, { page == Page.BEHAVIOR }) + private val interacting by setting("RotationMode", RotationMode.SPOOF, { page == Page.BEHAVIOR }) private val illegalPlacements by setting("IllegalPlacements", false, { page == Page.BEHAVIOR }) private val maxReach by setting("MaxReach", 4.5f, 1.0f..6.0f, 0.1f, { page == Page.BEHAVIOR }) private val toggleInventoryManager by setting("ToggleInvManager", true, { page == Page.BEHAVIOR }) @@ -93,6 +93,23 @@ internal object HighwayTools : Module( private val aFilled by setting("FilledAlpha", 26, 0..255, 1, { filled && page == Page.CONFIG }) private val aOutline by setting("OutlineAlpha", 91, 0..255, 1, { outline && page == Page.CONFIG }) + private enum class Mode { + HIGHWAY, FLAT, TUNNEL + } + + private enum class Page { + BUILD, BEHAVIOR, CONFIG + } + + @Suppress("UNUSED") + private enum class RotationMode { + OFF, SPOOF, VIEW_LOCK + } + + private enum class DebugMessages { + OFF, IMPORTANT, ALL + } + // internal settings val ignoreBlocks = hashSetOf( Blocks.STANDING_SIGN, @@ -314,16 +331,16 @@ internal object HighwayTools : Module( val rotation = lastHitVec?.let { getRotationTo(it) } ?: return when (interacting) { - InteractMode.SPOOF -> { + RotationMode.SPOOF -> { val packet = PlayerPacketManager.PlayerPacket(rotating = true, rotation = rotation) PlayerPacketManager.addPacket(this@HighwayTools, packet) } - InteractMode.VIEW_LOCK -> { + RotationMode.VIEW_LOCK -> { player.rotationYaw = rotation.x player.rotationPitch = rotation.y } else -> { - + // RotationMode.OFF } } } @@ -1166,30 +1183,5 @@ internal object HighwayTools : Module( PENDING_PLACED(100, 100, ColorHolder(0, 0, 0)) } - private enum class DebugMessages { - OFF, - IMPORTANT, - ALL - } - - private enum class Mode { - HIGHWAY, - FLAT, - TUNNEL - } - - private enum class Page { - BUILD, - BEHAVIOR, - CONFIG - } - - @Suppress("UNUSED") - private enum class InteractMode { - OFF, - SPOOF, - VIEW_LOCK - } - } From d053ed710a93c42254bd5e864a584f44fcc2cdcf Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Wed, 27 Jan 2021 04:44:54 -0500 Subject: [PATCH 248/390] Fixed place packet delay --- .../kami/module/modules/misc/HighwayTools.kt | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 01964f9243..45acb42665 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -773,8 +773,6 @@ internal object HighwayTools : Module( } blockTask.updateState(TaskState.PLACED) - - waitTicks = tickDelayPlace } } } @@ -913,9 +911,9 @@ internal object HighwayTools : Module( private fun mineBlockInstant(blockTask: BlockTask, side: EnumFacing) { waitTicks = tickDelayBreak + blockTask.updateState(TaskState.PENDING_BROKEN) defaultScope.launch { - blockTask.updateState(TaskState.PENDING_BROKEN) delay(10L) onMainThreadSafe { @@ -974,29 +972,29 @@ internal object HighwayTools : Module( lastHitVec = WorldUtils.getHitVec(pair.second, pair.first) rotateTimer.reset() - dispatchGenericPlaceThread(blockTask, pair) + placeBlockNormal(blockTask, pair) } - private fun SafeClientEvent.dispatchGenericPlaceThread(blockTask: BlockTask, pair: Pair) { + private fun SafeClientEvent.placeBlockNormal(blockTask: BlockTask, pair: Pair) { val hitVecOffset = WorldUtils.getHitVecOffset(pair.first) + val currentBlock = world.getBlockState(pair.second).block - defaultScope.launch { - blockTask.updateState(TaskState.PENDING_PLACED) + waitTicks = tickDelayPlace + blockTask.updateState(TaskState.PENDING_PLACED) - if (world.getBlockState(pair.second).block in blackList) { - delay(10L) - onMainThreadSafe { - connection.sendPacket(CPacketEntityAction(player, CPacketEntityAction.Action.START_SNEAKING)) - } - } + if (currentBlock in blackList) { + connection.sendPacket(CPacketEntityAction(player, CPacketEntityAction.Action.START_SNEAKING)) + } + defaultScope.launch { + delay(10L) onMainThreadSafe { val placePacket = CPacketPlayerTryUseItemOnBlock(pair.second, pair.first, EnumHand.MAIN_HAND, hitVecOffset.x.toFloat(), hitVecOffset.y.toFloat(), hitVecOffset.z.toFloat()) connection.sendPacket(placePacket) player.swingArm(EnumHand.MAIN_HAND) } - if (world.getBlockState(pair.second).block in blackList) { + if (currentBlock in blackList) { delay(10L) onMainThreadSafe { connection.sendPacket(CPacketEntityAction(player, CPacketEntityAction.Action.STOP_SNEAKING)) From ad1ccd57b7af9e4d16fbe4650c7731900b1c0d3f Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Wed, 27 Jan 2021 04:50:27 -0500 Subject: [PATCH 249/390] Fixed pathing stop too early --- .../me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 45acb42665..d86647d0fc 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -524,7 +524,7 @@ internal object HighwayTools : Module( private fun checkTasks(pos: BlockPos): Boolean { return pendingTasks.values.all { - it.taskState == TaskState.DONE || pos.distanceTo(it.blockPos) < maxReach - 2.0 + it.taskState == TaskState.DONE || pos.distanceTo(it.blockPos) < maxReach - 1.0 } } From e19c845d1d62c27e61202de329ec7cde6d1153a7 Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Wed, 27 Jan 2021 05:03:45 -0500 Subject: [PATCH 250/390] Fixed placing error --- .../kami/module/modules/misc/HighwayTools.kt | 21 ++++++------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index d86647d0fc..78f4d444d0 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -682,23 +682,21 @@ internal object HighwayTools : Module( } private fun SafeClientEvent.doPlaced(blockTask: BlockTask) { - val block = world.getBlockState(blockTask.blockPos).block + val currentBlock = world.getBlockState(blockTask.blockPos).block when { - blockTask.block == block && block != Blocks.AIR -> { + blockTask.block == currentBlock && currentBlock != Blocks.AIR -> { blockTask.updateState(TaskState.DONE) if (fakeSounds) { - val soundType = block.getSoundType(world.getBlockState(blockTask.blockPos), world, blockTask.blockPos, player) - onMainThread { - world.playSound(player, blockTask.blockPos, soundType.placeSound, SoundCategory.BLOCKS, (soundType.getVolume() + 1.0f) / 2.0f, soundType.getPitch() * 0.8f) - } + val soundType = currentBlock.getSoundType(world.getBlockState(blockTask.blockPos), world, blockTask.blockPos, player) + world.playSound(player, blockTask.blockPos, soundType.placeSound, SoundCategory.BLOCKS, (soundType.getVolume() + 1.0f) / 2.0f, soundType.getPitch() * 0.8f) } totalBlocksPlaced++ } - blockTask.block == Blocks.AIR && block != Blocks.AIR -> { + blockTask.block == currentBlock && currentBlock == Blocks.AIR -> { blockTask.updateState(TaskState.BREAK) } - blockTask.block == block && block == Blocks.AIR -> { + blockTask.block == Blocks.AIR && currentBlock != Blocks.AIR -> { blockTask.updateState(TaskState.BREAK) } else -> { @@ -767,12 +765,6 @@ internal object HighwayTools : Module( } placeBlock(blockTask) - - if (blockTask.taskState != TaskState.PLACE && isInsideBlueprint(blockTask.blockPos)) { - blockTask.updateMaterial(Blocks.AIR) - } - - blockTask.updateState(TaskState.PLACED) } } } @@ -914,7 +906,6 @@ internal object HighwayTools : Module( blockTask.updateState(TaskState.PENDING_BROKEN) defaultScope.launch { - delay(10L) onMainThreadSafe { connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, blockTask.blockPos, side)) From 806b0b926794d9cb2462f9870b747a4f9b9bee0d Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Wed, 27 Jan 2021 10:10:15 -0500 Subject: [PATCH 251/390] Fixed illegal placements setting --- .../me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 78f4d444d0..c8df0b690f 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -952,12 +952,12 @@ internal object HighwayTools : Module( if (illegalPlacements) { if (debugMessages == DebugMessages.ALL) { MessageSendHelper.sendChatMessage("Trying to place through wall ${blockTask.blockPos}") - getNeighbour(blockTask.blockPos, 1, maxReach) ?: return } + getNeighbour(blockTask.blockPos, 1, maxReach) ?: return } else { blockTask.onStuck() + return } - return } lastHitVec = WorldUtils.getHitVec(pair.second, pair.first) From 74df840ae22b3f5ec4bc557e859c7b2eae23c945 Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Wed, 27 Jan 2021 10:46:30 -0500 Subject: [PATCH 252/390] Make the delay before mining/placing longer --- .../kami/module/modules/misc/HighwayTools.kt | 55 ++++++++++--------- 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index c8df0b690f..b53b1b7fce 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -75,7 +75,7 @@ internal object HighwayTools : Module( // behavior settings private val tickDelayPlace by setting("TickDelayPlace", 2, 1..20, 1, { page == Page.BEHAVIOR }) private val tickDelayBreak by setting("TickDelayBreak", 1, 1..20, 1, { page == Page.BEHAVIOR }) - private val taskTimeoutTicks by setting("TaskTimeoutTicks", 5, 0..16, 1, { page == Page.BEHAVIOR }) + private val taskTimeoutTicks by setting("TaskTimeoutTicks", 5, 0..20, 1, { page == Page.BEHAVIOR }) private val interacting by setting("RotationMode", RotationMode.SPOOF, { page == Page.BEHAVIOR }) private val illegalPlacements by setting("IllegalPlacements", false, { page == Page.BEHAVIOR }) private val maxReach by setting("MaxReach", 4.5f, 1.0f..6.0f, 0.1f, { page == Page.BEHAVIOR }) @@ -528,22 +528,6 @@ internal object HighwayTools : Module( } } - private fun SafeClientEvent.sortTasks() { - sortedTasks = pendingTasks.values.sortedWith( - compareBy { - it.taskState.ordinal - }.thenBy { - it.stuckTicks - }.thenBy { - startingBlockPos.distanceTo(it.blockPos) - }.thenBy { - player.distanceTo(it.blockPos) - }.thenBy { - lastHitVec?.distanceTo(it.blockPos) - } - ) - } - private fun SafeClientEvent.runTasks() { if (pendingTasks.isNotEmpty()) { @@ -575,8 +559,25 @@ internal object HighwayTools : Module( } } + private fun SafeClientEvent.sortTasks() { + val eyePos = mc.player.getPositionEyes(1.0f) + + sortedTasks = pendingTasks.values.sortedWith( + compareBy { + it.taskState.ordinal + }.thenBy { + it.stuckTicks / 20 + }.thenBy { + eyePos.distanceTo(it.blockPos) + }.thenBy { + lastHitVec?.distanceTo(it.blockPos) + } + ) + } + private fun SafeClientEvent.checkStuckTimeout(blockTask: BlockTask): Boolean { val timeout = blockTask.taskState.stuckTimeout + if (blockTask.stuckTicks > timeout) { when (blockTask.taskState) { TaskState.PENDING_BROKEN -> { @@ -621,8 +622,10 @@ internal object HighwayTools : Module( doPlace(blockTask) } TaskState.PENDING_BROKEN, TaskState.PENDING_PLACED -> { - if (debugMessages == DebugMessages.ALL) MessageSendHelper.sendChatMessage("$chatName Currently waiting for blockState updates...") -// blockTask.onStuck() + if (debugMessages == DebugMessages.ALL) { + MessageSendHelper.sendChatMessage("$chatName Currently waiting for blockState updates...") + } + blockTask.onStuck() } } } @@ -906,13 +909,13 @@ internal object HighwayTools : Module( blockTask.updateState(TaskState.PENDING_BROKEN) defaultScope.launch { - delay(10L) + delay(20L) onMainThreadSafe { connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, blockTask.blockPos, side)) player.swingArm(EnumHand.MAIN_HAND) } - delay(40L) + delay(30L) onMainThreadSafe { connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, blockTask.blockPos, side)) player.swingArm(EnumHand.MAIN_HAND) @@ -938,7 +941,7 @@ internal object HighwayTools : Module( } defaultScope.launch { - delay(10L) + delay(20L) onMainThreadSafe { connection.sendPacket(CPacketPlayerDigging(action, blockTask.blockPos, facing)) player.swingArm(EnumHand.MAIN_HAND) @@ -978,7 +981,7 @@ internal object HighwayTools : Module( } defaultScope.launch { - delay(10L) + delay(20L) onMainThreadSafe { val placePacket = CPacketPlayerTryUseItemOnBlock(pair.second, pair.first, EnumHand.MAIN_HAND, hitVecOffset.x.toFloat(), hitVecOffset.y.toFloat(), hitVecOffset.z.toFloat()) connection.sendPacket(placePacket) @@ -986,7 +989,7 @@ internal object HighwayTools : Module( } if (currentBlock in blackList) { - delay(10L) + delay(20L) onMainThreadSafe { connection.sendPacket(CPacketEntityAction(player, CPacketEntityAction.Action.STOP_SNEAKING)) } @@ -1123,7 +1126,9 @@ internal object HighwayTools : Module( fun updateState(state: TaskState) { if (state == taskState) return taskState = state - if (taskState == TaskState.PLACE && state == TaskState.PLACED) onUpdate() + if (state == TaskState.DONE || state == TaskState.PLACED || state == TaskState.BROKEN) { + onUpdate() + } } fun updateMaterial(material: Block) { From e900fe4a8113084036687b2f74272a08758a8321 Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Wed, 27 Jan 2021 11:08:42 -0500 Subject: [PATCH 253/390] Iterate through all task and update their states first --- .../kami/module/modules/misc/HighwayTools.kt | 104 +++++++++--------- 1 file changed, 55 insertions(+), 49 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index b53b1b7fce..bcf087f3b4 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -529,16 +529,25 @@ internal object HighwayTools : Module( } private fun SafeClientEvent.runTasks() { - if (pendingTasks.isNotEmpty()) { - + if (pendingTasks.isEmpty()) { + if (checkDoneTasks()) { + doneTasks.clear() + refreshData(currentBlockPos.add(startingDirection.directionVec)) + } else { + refreshData() + } + } else { waitTicks-- + for (task in pendingTasks.values) { + doTask(task, true) + } sortTasks() for (task in sortedTasks) { if (!checkStuckTimeout(task)) return if (task.taskState != TaskState.DONE && waitTicks > 0) return - doTask(task) + doTask(task, false) when (task.taskState) { TaskState.DONE, TaskState.BROKEN, TaskState.PLACED -> { @@ -549,14 +558,22 @@ internal object HighwayTools : Module( } } } - } else { - if (checkDoneTasks()) { - doneTasks.clear() - refreshData(currentBlockPos.add(startingDirection.directionVec)) - } else { - refreshData() + } + } + + private fun SafeClientEvent.checkDoneTasks(): Boolean { + for (blockTask in doneTasks.values) { + val block = world.getBlockState(blockTask.blockPos).block + if (ignoreBlocks.contains(block)) continue + + when { + blockTask.block == material && block != material -> return false + mode == Mode.TUNNEL && blockTask.block == fillerMat && block != fillerMat -> return false + blockTask.block == Blocks.AIR && block != Blocks.AIR -> return false } + } + return true } private fun SafeClientEvent.sortTasks() { @@ -599,15 +616,15 @@ internal object HighwayTools : Module( return true } - private fun SafeClientEvent.doTask(blockTask: BlockTask) { - blockTask.onTick() + private fun SafeClientEvent.doTask(blockTask: BlockTask, updateOnly: Boolean) { + if (!updateOnly) blockTask.onTick() when (blockTask.taskState) { TaskState.DONE -> { doDone(blockTask) } TaskState.BREAKING -> { - doBreaking(blockTask) + doBreaking(blockTask, updateOnly) } TaskState.BROKEN -> { doBroken(blockTask) @@ -616,13 +633,13 @@ internal object HighwayTools : Module( doPlaced(blockTask) } TaskState.BREAK -> { - doBreak(blockTask) + doBreak(blockTask, updateOnly) } TaskState.PLACE, TaskState.LIQUID_SOURCE, TaskState.LIQUID_FLOW -> { - doPlace(blockTask) + doPlace(blockTask, updateOnly) } TaskState.PENDING_BROKEN, TaskState.PENDING_PLACED -> { - if (debugMessages == DebugMessages.ALL) { + if (!updateOnly && debugMessages == DebugMessages.ALL) { MessageSendHelper.sendChatMessage("$chatName Currently waiting for blockState updates...") } blockTask.onStuck() @@ -635,7 +652,7 @@ internal object HighwayTools : Module( doneTasks[blockTask.blockPos] = blockTask } - private fun SafeClientEvent.doBreaking(blockTask: BlockTask) { + private fun SafeClientEvent.doBreaking(blockTask: BlockTask, updateOnly: Boolean) { when (world.getBlockState(blockTask.blockPos).block) { Blocks.AIR -> { waitTicks = tickDelayBreak @@ -657,7 +674,9 @@ internal object HighwayTools : Module( } } else -> { - mineBlock(blockTask) + if (!updateOnly) { + mineBlock(blockTask) + } } } } @@ -708,7 +727,7 @@ internal object HighwayTools : Module( } } - private fun SafeClientEvent.doBreak(blockTask: BlockTask) { + private fun SafeClientEvent.doBreak(blockTask: BlockTask, updateOnly: Boolean) { // ignore blocks if (blockTask.block != Blocks.AIR && ignoreBlocks.contains(blockTask.block)) { @@ -736,16 +755,16 @@ internal object HighwayTools : Module( } } else -> { - if (handleLiquid(blockTask)) return - - swapOrMoveBestTool(blockTask) - - mineBlock(blockTask) + if (!updateOnly) { + if (handleLiquid(blockTask)) return + swapOrMoveBestTool(blockTask) + mineBlock(blockTask) + } } } } - private fun SafeClientEvent.doPlace(blockTask: BlockTask) { + private fun SafeClientEvent.doPlace(blockTask: BlockTask, updateOnly: Boolean) { val block = world.getBlockState(blockTask.blockPos).block when { @@ -756,35 +775,22 @@ internal object HighwayTools : Module( blockTask.updateState(TaskState.PLACED) } else -> { - if (!isPlaceable(blockTask.blockPos)) { - if (debugMessages != DebugMessages.OFF) MessageSendHelper.sendChatMessage("Invalid place position: " + blockTask.blockPos) - refreshData() - return - } - - if (!swapOrMoveBlock(blockTask)) { - blockTask.onStuck() - return - } - - placeBlock(blockTask) - } - } - } + if (!updateOnly) { + if (!isPlaceable(blockTask.blockPos)) { + if (debugMessages != DebugMessages.OFF) MessageSendHelper.sendChatMessage("Invalid place position: " + blockTask.blockPos) + refreshData() + return + } - private fun SafeClientEvent.checkDoneTasks(): Boolean { - for (blockTask in doneTasks.values) { - val block = world.getBlockState(blockTask.blockPos).block - if (ignoreBlocks.contains(block)) continue + if (!swapOrMoveBlock(blockTask)) { + blockTask.onStuck() + return + } - when { - blockTask.block == material && block != material -> return false - mode == Mode.TUNNEL && blockTask.block == fillerMat && block != fillerMat -> return false - blockTask.block == Blocks.AIR && block != Blocks.AIR -> return false + placeBlock(blockTask) + } } - } - return true } private fun SafeClientEvent.swapOrMoveBlock(blockTask: BlockTask): Boolean { From 2694f3e0b3730f29987ae20462e2cc5eef2c8b64 Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Wed, 27 Jan 2021 11:23:31 -0500 Subject: [PATCH 254/390] Don't do the check before running task --- .../kami/module/modules/misc/HighwayTools.kt | 233 +++++++++--------- 1 file changed, 117 insertions(+), 116 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index bcf087f3b4..e5b5df73df 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -616,30 +616,30 @@ internal object HighwayTools : Module( return true } - private fun SafeClientEvent.doTask(blockTask: BlockTask, updateOnly: Boolean) { - if (!updateOnly) blockTask.onTick() + private fun SafeClientEvent.doTask(blockTask: BlockTask, update: Boolean) { + if (!update) blockTask.onTick() when (blockTask.taskState) { TaskState.DONE -> { - doDone(blockTask) + doDone(blockTask, update) } TaskState.BREAKING -> { - doBreaking(blockTask, updateOnly) + doBreaking(blockTask, update) } TaskState.BROKEN -> { - doBroken(blockTask) + doBroken(blockTask, update) } TaskState.PLACED -> { - doPlaced(blockTask) + doPlaced(blockTask, update) } TaskState.BREAK -> { - doBreak(blockTask, updateOnly) + doBreak(blockTask, update) } TaskState.PLACE, TaskState.LIQUID_SOURCE, TaskState.LIQUID_FLOW -> { - doPlace(blockTask, updateOnly) + doPlace(blockTask, update) } TaskState.PENDING_BROKEN, TaskState.PENDING_PLACED -> { - if (!updateOnly && debugMessages == DebugMessages.ALL) { + if (!update && debugMessages == DebugMessages.ALL) { MessageSendHelper.sendChatMessage("$chatName Currently waiting for blockState updates...") } blockTask.onStuck() @@ -647,149 +647,150 @@ internal object HighwayTools : Module( } } - private fun doDone(blockTask: BlockTask) { - pendingTasks[blockTask.blockPos] - doneTasks[blockTask.blockPos] = blockTask + private fun doDone(blockTask: BlockTask, update: Boolean) { + if (update) { + pendingTasks[blockTask.blockPos] + doneTasks[blockTask.blockPos] = blockTask + } } - private fun SafeClientEvent.doBreaking(blockTask: BlockTask, updateOnly: Boolean) { - when (world.getBlockState(blockTask.blockPos).block) { - Blocks.AIR -> { - waitTicks = tickDelayBreak - if (blockTask.block == material || blockTask.block == fillerMat) { - blockTask.updateState(TaskState.PLACE) - } else { - blockTask.updateState(TaskState.DONE) - } - } - is BlockLiquid -> { - var filler = fillerMat - if (isInsideBlueprintBuild(blockTask.blockPos) || fillerMatLeft == 0) filler = material - if (world.getBlockState(blockTask.blockPos).getValue(BlockLiquid.LEVEL) != 0) { - blockTask.updateState(TaskState.LIQUID_FLOW) - blockTask.updateMaterial(filler) - } else { - blockTask.updateState(TaskState.LIQUID_SOURCE) - blockTask.updateMaterial(filler) + private fun SafeClientEvent.doBreaking(blockTask: BlockTask, update: Boolean) { + if (update) { + when (world.getBlockState(blockTask.blockPos).block) { + Blocks.AIR -> { + waitTicks = tickDelayBreak + if (blockTask.block == material || blockTask.block == fillerMat) { + blockTask.updateState(TaskState.PLACE) + } else { + blockTask.updateState(TaskState.DONE) + } } - } - else -> { - if (!updateOnly) { - mineBlock(blockTask) + is BlockLiquid -> { + var filler = fillerMat + if (isInsideBlueprintBuild(blockTask.blockPos) || fillerMatLeft == 0) filler = material + if (world.getBlockState(blockTask.blockPos).getValue(BlockLiquid.LEVEL) != 0) { + blockTask.updateState(TaskState.LIQUID_FLOW) + blockTask.updateMaterial(filler) + } else { + blockTask.updateState(TaskState.LIQUID_SOURCE) + blockTask.updateMaterial(filler) + } } } + } else { + mineBlock(blockTask) } } - private fun SafeClientEvent.doBroken(blockTask: BlockTask) { - when (world.getBlockState(blockTask.blockPos).block) { - Blocks.AIR -> { - if (blockTask.block != Blocks.AIR) { - blockTask.updateState(TaskState.PLACE) - } else { - blockTask.updateState(TaskState.DONE) - if (fakeSounds) { - val soundType = blockTask.block.getSoundType(world.getBlockState(blockTask.blockPos), world, blockTask.blockPos, player) - onMainThread { - world.playSound(player, blockTask.blockPos, soundType.breakSound, SoundCategory.BLOCKS, (soundType.getVolume() + 1.0f) / 2.0f, soundType.getPitch() * 0.8f) + private fun SafeClientEvent.doBroken(blockTask: BlockTask, update: Boolean) { + if (update) { + when (world.getBlockState(blockTask.blockPos).block) { + Blocks.AIR -> { + if (blockTask.block != Blocks.AIR) { + blockTask.updateState(TaskState.PLACE) + } else { + blockTask.updateState(TaskState.DONE) + if (fakeSounds) { + val soundType = blockTask.block.getSoundType(world.getBlockState(blockTask.blockPos), world, blockTask.blockPos, player) + onMainThread { + world.playSound(player, blockTask.blockPos, soundType.breakSound, SoundCategory.BLOCKS, (soundType.getVolume() + 1.0f) / 2.0f, soundType.getPitch() * 0.8f) + } } + totalBlocksDestroyed++ } - totalBlocksDestroyed++ } - } - else -> { - blockTask.updateState(TaskState.BREAK) + else -> { + blockTask.updateState(TaskState.BREAK) + } } } } - private fun SafeClientEvent.doPlaced(blockTask: BlockTask) { - val currentBlock = world.getBlockState(blockTask.blockPos).block + private fun SafeClientEvent.doPlaced(blockTask: BlockTask, update: Boolean) { + if (update) { + val currentBlock = world.getBlockState(blockTask.blockPos).block - when { - blockTask.block == currentBlock && currentBlock != Blocks.AIR -> { - blockTask.updateState(TaskState.DONE) - if (fakeSounds) { - val soundType = currentBlock.getSoundType(world.getBlockState(blockTask.blockPos), world, blockTask.blockPos, player) - world.playSound(player, blockTask.blockPos, soundType.placeSound, SoundCategory.BLOCKS, (soundType.getVolume() + 1.0f) / 2.0f, soundType.getPitch() * 0.8f) + when { + blockTask.block == currentBlock && currentBlock != Blocks.AIR -> { + blockTask.updateState(TaskState.DONE) + if (fakeSounds) { + val soundType = currentBlock.getSoundType(world.getBlockState(blockTask.blockPos), world, blockTask.blockPos, player) + world.playSound(player, blockTask.blockPos, soundType.placeSound, SoundCategory.BLOCKS, (soundType.getVolume() + 1.0f) / 2.0f, soundType.getPitch() * 0.8f) + } + totalBlocksPlaced++ + } + blockTask.block == currentBlock && currentBlock == Blocks.AIR -> { + blockTask.updateState(TaskState.BREAK) + } + blockTask.block == Blocks.AIR && currentBlock != Blocks.AIR -> { + blockTask.updateState(TaskState.BREAK) + } + else -> { + blockTask.updateState(TaskState.PLACE) } - totalBlocksPlaced++ - } - blockTask.block == currentBlock && currentBlock == Blocks.AIR -> { - blockTask.updateState(TaskState.BREAK) - } - blockTask.block == Blocks.AIR && currentBlock != Blocks.AIR -> { - blockTask.updateState(TaskState.BREAK) - } - else -> { - blockTask.updateState(TaskState.PLACE) } } } - private fun SafeClientEvent.doBreak(blockTask: BlockTask, updateOnly: Boolean) { + private fun SafeClientEvent.doBreak(blockTask: BlockTask, update: Boolean) { // ignore blocks - if (blockTask.block != Blocks.AIR - && ignoreBlocks.contains(blockTask.block)) { + if (blockTask.block != Blocks.AIR && ignoreBlocks.contains(blockTask.block)) { blockTask.updateState(TaskState.DONE) } - // last check before breaking - when (world.getBlockState(blockTask.blockPos).block) { - Blocks.AIR -> { - if (blockTask.block == Blocks.AIR) { - blockTask.updateState(TaskState.DONE) - } else { - blockTask.updateState(TaskState.PLACE) - } - } - is BlockLiquid -> { - var filler = fillerMat - if (isInsideBlueprintBuild(blockTask.blockPos) || fillerMatLeft == 0) filler = material - if (world.getBlockState(blockTask.blockPos).getValue(BlockLiquid.LEVEL) != 0) { - blockTask.updateState(TaskState.LIQUID_FLOW) - blockTask.updateMaterial(filler) - } else { - blockTask.updateState(TaskState.LIQUID_SOURCE) - blockTask.updateMaterial(filler) + if (update) { + when (world.getBlockState(blockTask.blockPos).block) { + Blocks.AIR -> { + if (blockTask.block == Blocks.AIR) { + blockTask.updateState(TaskState.DONE) + } else { + blockTask.updateState(TaskState.PLACE) + } } - } - else -> { - if (!updateOnly) { - if (handleLiquid(blockTask)) return - swapOrMoveBestTool(blockTask) - mineBlock(blockTask) + is BlockLiquid -> { + var filler = fillerMat + if (isInsideBlueprintBuild(blockTask.blockPos) || fillerMatLeft == 0) filler = material + if (world.getBlockState(blockTask.blockPos).getValue(BlockLiquid.LEVEL) != 0) { + blockTask.updateState(TaskState.LIQUID_FLOW) + blockTask.updateMaterial(filler) + } else { + blockTask.updateState(TaskState.LIQUID_SOURCE) + blockTask.updateMaterial(filler) + } } } + } else { + if (handleLiquid(blockTask)) return + swapOrMoveBestTool(blockTask) + mineBlock(blockTask) } } - private fun SafeClientEvent.doPlace(blockTask: BlockTask, updateOnly: Boolean) { - val block = world.getBlockState(blockTask.blockPos).block + private fun SafeClientEvent.doPlace(blockTask: BlockTask, update: Boolean) { + if (update) { + val block = world.getBlockState(blockTask.blockPos).block - when { - block == material && block == blockTask.block -> { - blockTask.updateState(TaskState.PLACED) + when { + block == material && block == blockTask.block -> { + blockTask.updateState(TaskState.PLACED) + } + block == fillerMat && block == blockTask.block -> { + blockTask.updateState(TaskState.PLACED) + } } - block == fillerMat && block == blockTask.block -> { - blockTask.updateState(TaskState.PLACED) + } else { + if (!isPlaceable(blockTask.blockPos)) { + if (debugMessages != DebugMessages.OFF) MessageSendHelper.sendChatMessage("Invalid place position: " + blockTask.blockPos) + refreshData() + return } - else -> { - if (!updateOnly) { - if (!isPlaceable(blockTask.blockPos)) { - if (debugMessages != DebugMessages.OFF) MessageSendHelper.sendChatMessage("Invalid place position: " + blockTask.blockPos) - refreshData() - return - } - - if (!swapOrMoveBlock(blockTask)) { - blockTask.onStuck() - return - } - placeBlock(blockTask) - } + if (!swapOrMoveBlock(blockTask)) { + blockTask.onStuck() + return } + + placeBlock(blockTask) } } From 99b5e964cd61fde4e2faa06e1a90ba39e74b7db4 Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Wed, 27 Jan 2021 11:35:44 -0500 Subject: [PATCH 255/390] Pause if rubber band --- .../kami/module/modules/misc/HighwayTools.kt | 74 +++++++++++-------- .../kami/process/HighwayToolsProcess.kt | 2 +- 2 files changed, 45 insertions(+), 31 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index e5b5df73df..ae4e70e26a 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -39,6 +39,7 @@ import net.minecraft.network.play.client.CPacketEntityAction import net.minecraft.network.play.client.CPacketPlayerDigging import net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock import net.minecraft.network.play.server.SPacketBlockChange +import net.minecraft.network.play.server.SPacketPlayerPosLook import net.minecraft.util.EnumFacing import net.minecraft.util.EnumHand import net.minecraft.util.SoundCategory @@ -73,14 +74,15 @@ internal object HighwayTools : Module( private val cornerBlock by setting("CornerBlock", false, { page == Page.BUILD && (mode == Mode.HIGHWAY || mode == Mode.TUNNEL) }) // behavior settings - private val tickDelayPlace by setting("TickDelayPlace", 2, 1..20, 1, { page == Page.BEHAVIOR }) - private val tickDelayBreak by setting("TickDelayBreak", 1, 1..20, 1, { page == Page.BEHAVIOR }) - private val taskTimeoutTicks by setting("TaskTimeoutTicks", 5, 0..20, 1, { page == Page.BEHAVIOR }) private val interacting by setting("RotationMode", RotationMode.SPOOF, { page == Page.BEHAVIOR }) private val illegalPlacements by setting("IllegalPlacements", false, { page == Page.BEHAVIOR }) - private val maxReach by setting("MaxReach", 4.5f, 1.0f..6.0f, 0.1f, { page == Page.BEHAVIOR }) private val toggleInventoryManager by setting("ToggleInvManager", true, { page == Page.BEHAVIOR }) private val toggleAutoObsidian by setting("ToggleAutoObsidian", true, { page == Page.BEHAVIOR }) + private val tickDelayPlace by setting("TickDelayPlace", 2, 1..20, 1, { page == Page.BEHAVIOR }) + private val tickDelayBreak by setting("TickDelayBreak", 1, 1..20, 1, { page == Page.BEHAVIOR }) + private val taskTimeoutTicks by setting("TaskTimeoutTicks", 5, 0..20, 1, { page == Page.BEHAVIOR }) + private val rubberBandTimeout by setting("RubberBandTimeout", 5, 1..20, 1, { page == Page.BEHAVIOR }) + private val maxReach by setting("MaxReach", 4.5f, 1.0f..6.0f, 0.1f, { page == Page.BEHAVIOR }) // config private val fakeSounds by setting("Sounds", true, { page == Page.CONFIG }) @@ -133,6 +135,7 @@ internal object HighwayTools : Module( private val blueprint = LinkedHashMap() // State + private val rubberBandTimer = TickTimer(TimeUnit.TICKS) private var active = false private var waitTicks = 0 @@ -252,29 +255,34 @@ internal object HighwayTools : Module( init { safeListener { - if (it.packet !is SPacketBlockChange) return@safeListener - - val pos = it.packet.blockPosition - if (!isInsideBlueprint(pos)) return@safeListener - - val prev = world.getBlockState(pos) - val new = it.packet.getBlockState() - - if (prev.block != new.block) { - val task = pendingTasks[pos] ?: return@safeListener - - when { - task.taskState == TaskState.PENDING_BROKEN && - prev.block != Blocks.AIR && - new.block == Blocks.AIR -> { - task.updateState(TaskState.BROKEN) - } - task.taskState == TaskState.PENDING_PLACED && - (task.block == material || task.block == fillerMat) - && task.block == new.block -> { - task.updateState(TaskState.PLACED) + when (it.packet) { + is SPacketBlockChange -> { + val pos = it.packet.blockPosition + if (!isInsideBlueprint(pos)) return@safeListener + + val prev = world.getBlockState(pos) + val new = it.packet.getBlockState() + + if (prev.block != new.block) { + val task = pendingTasks[pos] ?: return@safeListener + + when { + task.taskState == TaskState.PENDING_BROKEN && + prev.block != Blocks.AIR && + new.block == Blocks.AIR -> { + task.updateState(TaskState.BROKEN) + } + task.taskState == TaskState.PENDING_PLACED && + (task.block == material || task.block == fillerMat) + && task.block == new.block -> { + task.updateState(TaskState.PLACED) + } + } } } + is SPacketPlayerPosLook -> { + rubberBandTimer.reset() + } } } @@ -285,16 +293,22 @@ internal object HighwayTools : Module( safeListener { event -> if (event.phase != TickEvent.Phase.START) return@safeListener + updateRenderer() + updateFood() + + if (!rubberBandTimer.tick(rubberBandTimeout.toLong(), false)) { + return@safeListener + } + + if (player.flooredPosition.distanceTo(currentBlockPos) > 2 || AutoObsidian.isActive() || AutoEat.eating) { + return@safeListener + } + if (!active) { active = true BaritoneUtils.primary?.pathingControlManager?.registerProcess(HighwayToolsProcess) } - updateRenderer() - updateFood() - - if (player.flooredPosition.distanceTo(currentBlockPos) > 2 || AutoObsidian.isActive() || AutoEat.eating) return@safeListener - doPathing() runTasks() diff --git a/src/main/java/me/zeroeightsix/kami/process/HighwayToolsProcess.kt b/src/main/java/me/zeroeightsix/kami/process/HighwayToolsProcess.kt index 792ea732e3..bde0293491 100644 --- a/src/main/java/me/zeroeightsix/kami/process/HighwayToolsProcess.kt +++ b/src/main/java/me/zeroeightsix/kami/process/HighwayToolsProcess.kt @@ -33,7 +33,7 @@ object HighwayToolsProcess : IBaritoneProcess { } override fun isActive(): Boolean { - return HighwayTools.isEnabled + return HighwayTools.isActive() } override fun onTick(p0: Boolean, p1: Boolean): PathingCommand { From 699b7e4243bea3f7351d83aadfa4f02866eca85a Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Wed, 27 Jan 2021 11:36:32 -0500 Subject: [PATCH 256/390] Higher weight for stuck tick --- .../me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index ae4e70e26a..ae9706ce77 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -597,7 +597,7 @@ internal object HighwayTools : Module( compareBy { it.taskState.ordinal }.thenBy { - it.stuckTicks / 20 + it.stuckTicks / 2 }.thenBy { eyePos.distanceTo(it.blockPos) }.thenBy { From 4b0fda5b05895b5f540dd630fb83b7c3197ba23b Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Wed, 27 Jan 2021 11:56:57 -0500 Subject: [PATCH 257/390] Fixed getVisibleSides full cube check --- .../kami/module/modules/misc/HighwayTools.kt | 106 +++++++++--------- .../me/zeroeightsix/kami/util/WorldUtils.kt | 16 +-- 2 files changed, 61 insertions(+), 61 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index ae9706ce77..728172d649 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -821,6 +821,59 @@ internal object HighwayTools : Module( } } + private fun SafeClientEvent.placeBlock(blockTask: BlockTask) { + val pair = getNeighbour(blockTask.blockPos, 1, maxReach, true) + ?: run { + if (illegalPlacements) { + if (debugMessages == DebugMessages.ALL) { + MessageSendHelper.sendChatMessage("Trying to place through wall ${blockTask.blockPos}") + } + getNeighbour(blockTask.blockPos, 1, maxReach) ?: return + } else { + blockTask.onStuck() + return + } + } + + lastHitVec = WorldUtils.getHitVec(pair.second, pair.first) + rotateTimer.reset() + + placeBlockNormal(blockTask, pair) + } + + private fun SafeClientEvent.placeBlockNormal(blockTask: BlockTask, pair: Pair) { + val hitVecOffset = WorldUtils.getHitVecOffset(pair.first) + val currentBlock = world.getBlockState(pair.second).block + + waitTicks = tickDelayPlace + blockTask.updateState(TaskState.PENDING_PLACED) + + if (currentBlock in blackList) { + connection.sendPacket(CPacketEntityAction(player, CPacketEntityAction.Action.START_SNEAKING)) + } + + defaultScope.launch { + delay(20L) + onMainThreadSafe { + val placePacket = CPacketPlayerTryUseItemOnBlock(pair.second, pair.first, EnumHand.MAIN_HAND, hitVecOffset.x.toFloat(), hitVecOffset.y.toFloat(), hitVecOffset.z.toFloat()) + connection.sendPacket(placePacket) + player.swingArm(EnumHand.MAIN_HAND) + } + + if (currentBlock in blackList) { + delay(20L) + onMainThreadSafe { + connection.sendPacket(CPacketEntityAction(player, CPacketEntityAction.Action.STOP_SNEAKING)) + } + } + + delay(50L * taskTimeoutTicks) + if (blockTask.taskState == TaskState.PENDING_PLACED) { + blockTask.updateState(TaskState.PLACE) + } + } + } + private fun SafeClientEvent.swapOrMoveBestTool(blockTask: BlockTask): Boolean { val slotFrom = player.inventorySlots.asReversed().maxByOrNull { val stack = it.stack @@ -970,59 +1023,6 @@ internal object HighwayTools : Module( } } - private fun SafeClientEvent.placeBlock(blockTask: BlockTask) { - val pair = getNeighbour(blockTask.blockPos, 1, maxReach, true) - ?: run { - if (illegalPlacements) { - if (debugMessages == DebugMessages.ALL) { - MessageSendHelper.sendChatMessage("Trying to place through wall ${blockTask.blockPos}") - } - getNeighbour(blockTask.blockPos, 1, maxReach) ?: return - } else { - blockTask.onStuck() - return - } - } - - lastHitVec = WorldUtils.getHitVec(pair.second, pair.first) - rotateTimer.reset() - - placeBlockNormal(blockTask, pair) - } - - private fun SafeClientEvent.placeBlockNormal(blockTask: BlockTask, pair: Pair) { - val hitVecOffset = WorldUtils.getHitVecOffset(pair.first) - val currentBlock = world.getBlockState(pair.second).block - - waitTicks = tickDelayPlace - blockTask.updateState(TaskState.PENDING_PLACED) - - if (currentBlock in blackList) { - connection.sendPacket(CPacketEntityAction(player, CPacketEntityAction.Action.START_SNEAKING)) - } - - defaultScope.launch { - delay(20L) - onMainThreadSafe { - val placePacket = CPacketPlayerTryUseItemOnBlock(pair.second, pair.first, EnumHand.MAIN_HAND, hitVecOffset.x.toFloat(), hitVecOffset.y.toFloat(), hitVecOffset.z.toFloat()) - connection.sendPacket(placePacket) - player.swingArm(EnumHand.MAIN_HAND) - } - - if (currentBlock in blackList) { - delay(20L) - onMainThreadSafe { - connection.sendPacket(CPacketEntityAction(player, CPacketEntityAction.Action.STOP_SNEAKING)) - } - } - - delay(50L * taskTimeoutTicks) - if (blockTask.taskState == TaskState.PENDING_PLACED) { - blockTask.updateState(TaskState.PLACE) - } - } - } - private fun isInsideBlueprint(pos: BlockPos): Boolean { return blueprint.containsKey(pos) } diff --git a/src/main/java/me/zeroeightsix/kami/util/WorldUtils.kt b/src/main/java/me/zeroeightsix/kami/util/WorldUtils.kt index f3730d4d71..aa2e7a5848 100644 --- a/src/main/java/me/zeroeightsix/kami/util/WorldUtils.kt +++ b/src/main/java/me/zeroeightsix/kami/util/WorldUtils.kt @@ -153,9 +153,9 @@ object WorldUtils { val blockCenter = pos.toVec3dCenter() return visibleSides - .checkAxis(eyePos.x - blockCenter.x, EnumFacing.WEST, EnumFacing.EAST, isFullCube) + .checkAxis(eyePos.x - blockCenter.x, EnumFacing.WEST, EnumFacing.EAST, !isFullCube) .checkAxis(eyePos.y - blockCenter.y, EnumFacing.DOWN, EnumFacing.UP, true) - .checkAxis(eyePos.z - blockCenter.z, EnumFacing.NORTH, EnumFacing.SOUTH, isFullCube) + .checkAxis(eyePos.z - blockCenter.z, EnumFacing.NORTH, EnumFacing.SOUTH, !isFullCube) } private fun EnumSet.checkAxis(diff: Double, negativeSide: EnumFacing, positiveSide: EnumFacing, bothIfInRange: Boolean) = @@ -234,14 +234,14 @@ object WorldUtils { val eyePos = player.getPositionEyes(1.0f) for (side in sides) { - val pos = blockPos.offset(side) + val offsetPos = blockPos.offset(side) - if (!toIgnore.add(pos)) continue - if (world.getBlockState(pos).material.isReplaceable) continue - if (eyePos.distanceTo(Vec3d(pos).add(getHitVecOffset(side))) > range) continue - if (visibleSideCheck && !getVisibleSides(pos).contains(side.opposite)) continue + if (!toIgnore.add(offsetPos)) continue + if (world.getBlockState(offsetPos).material.isReplaceable) continue + if (eyePos.distanceTo(getHitVec(blockPos, side)) > range) continue + if (visibleSideCheck && !getVisibleSides(offsetPos).contains(side.opposite)) continue - return Pair(side.opposite, pos) + return Pair(side.opposite, offsetPos) } if (attempts > 1) { From d7bc77a9e140816e4c736e0fe08bc30be985bf21 Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Wed, 27 Jan 2021 12:15:36 -0500 Subject: [PATCH 258/390] Move block to slot that has block first before moving to first slot --- .../kami/module/modules/misc/HighwayTools.kt | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 728172d649..1483ec3502 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -35,6 +35,7 @@ import net.minecraft.enchantment.EnchantmentHelper import net.minecraft.init.Blocks import net.minecraft.init.Enchantments import net.minecraft.init.SoundEvents +import net.minecraft.item.ItemBlock import net.minecraft.network.play.client.CPacketEntityAction import net.minecraft.network.play.client.CPacketPlayerDigging import net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock @@ -809,12 +810,14 @@ internal object HighwayTools : Module( } private fun SafeClientEvent.swapOrMoveBlock(blockTask: BlockTask): Boolean { - return if (!swapToBlock(blockTask.block)) { - if (!swapToBlockOrMove(blockTask.block)) { - MessageSendHelper.sendChatMessage("$chatName No ${blockTask.block.localizedName} was found in inventory") - mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) - disable() - } + val success = swapToBlockOrMove(blockTask.block, predicateSlot = { + it.item is ItemBlock + }) + + return if (!success) { + MessageSendHelper.sendChatMessage("$chatName No ${blockTask.block.localizedName} was found in inventory") + mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) + disable() false } else { true From 9bd62b87a16825dc7f2ef32873a0c4005aff45b2 Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Wed, 27 Jan 2021 13:52:35 -0500 Subject: [PATCH 259/390] Cleaned up setting namings --- .../kami/module/modules/misc/HighwayTools.kt | 82 +++++++++---------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 1483ec3502..bac31d99f1 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -67,30 +67,30 @@ internal object HighwayTools : Module( private val page by setting("Page", Page.BUILD) // build settings - private val clearSpace by setting("ClearSpace", true, { page == Page.BUILD && mode == Mode.HIGHWAY }) - private val clearHeight by setting("Height", 4, 1..6, 1, { page == Page.BUILD && clearSpace }) - private val buildWidth by setting("Width", 5, 1..9, 1, { page == Page.BUILD }) + private val clearSpace by setting("Clear Space", true, { page == Page.BUILD && mode == Mode.HIGHWAY }) + private val height by setting("Height", 4, 1..6, 1, { page == Page.BUILD && clearSpace }) + private val width by setting("Width", 5, 1..9, 1, { page == Page.BUILD }) private val railing by setting("Railing", true, { page == Page.BUILD && mode == Mode.HIGHWAY }) - private val railingHeight by setting("RailingHeight", 1, 1..4, 1, { railing && page == Page.BUILD && mode == Mode.HIGHWAY }) - private val cornerBlock by setting("CornerBlock", false, { page == Page.BUILD && (mode == Mode.HIGHWAY || mode == Mode.TUNNEL) }) + private val railingHeight by setting("Railing Height", 1, 1..4, 1, { railing && page == Page.BUILD && mode == Mode.HIGHWAY }) + private val cornerBlock by setting("Corner Block", false, { page == Page.BUILD && (mode == Mode.HIGHWAY || mode == Mode.TUNNEL) }) // behavior settings - private val interacting by setting("RotationMode", RotationMode.SPOOF, { page == Page.BEHAVIOR }) - private val illegalPlacements by setting("IllegalPlacements", false, { page == Page.BEHAVIOR }) - private val toggleInventoryManager by setting("ToggleInvManager", true, { page == Page.BEHAVIOR }) - private val toggleAutoObsidian by setting("ToggleAutoObsidian", true, { page == Page.BEHAVIOR }) - private val tickDelayPlace by setting("TickDelayPlace", 2, 1..20, 1, { page == Page.BEHAVIOR }) - private val tickDelayBreak by setting("TickDelayBreak", 1, 1..20, 1, { page == Page.BEHAVIOR }) - private val taskTimeoutTicks by setting("TaskTimeoutTicks", 5, 0..20, 1, { page == Page.BEHAVIOR }) - private val rubberBandTimeout by setting("RubberBandTimeout", 5, 1..20, 1, { page == Page.BEHAVIOR }) + private val interacting by setting("Rotation Mode", RotationMode.SPOOF, { page == Page.BEHAVIOR }) + private val illegalPlacements by setting("Illegal Placements", false, { page == Page.BEHAVIOR }) + private val toggleInventoryManager by setting("Toggle InvManager", true, { page == Page.BEHAVIOR }) + private val toggleAutoObsidian by setting("Toggle AutoObsidian", true, { page == Page.BEHAVIOR }) + private val placeDelay by setting("Place Delay", 2, 1..20, 1, { page == Page.BEHAVIOR }) + private val breakDelay by setting("Break Delay", 1, 1..20, 1, { page == Page.BEHAVIOR }) + private val taskTimeout by setting("Task Timeout", 5, 0..20, 1, { page == Page.BEHAVIOR }) + private val rubberbandTimeout by setting("Rubberband Timeout", 5, 1..20, 1, { page == Page.BEHAVIOR }) private val maxReach by setting("MaxReach", 4.5f, 1.0f..6.0f, 0.1f, { page == Page.BEHAVIOR }) // config - private val fakeSounds by setting("Sounds", true, { page == Page.CONFIG }) - private val info by setting("ShowInfo", true, { page == Page.CONFIG }) - private val printDebug by setting("ShowQueue", false, { page == Page.CONFIG }) - private val debugMessages by setting("Debug", DebugMessages.IMPORTANT, { page == Page.CONFIG }) - private val goalRender by setting("GoalRender", false, { page == Page.CONFIG }) + private val fakeSounds by setting("Fake Sounds", true, { page == Page.CONFIG }) + private val info by setting("Show Info", true, { page == Page.CONFIG }) + private val printDebug by setting("Show Queue", false, { page == Page.CONFIG }) + private val debugMessages by setting("Debug Messages", DebugMessages.IMPORTANT, { page == Page.CONFIG }) + private val goalRender by setting("Goal Render", false, { page == Page.CONFIG }) private val filled by setting("Filled", true, { page == Page.CONFIG }) private val outline by setting("Outline", true, { page == Page.CONFIG }) private val aFilled by setting("FilledAlpha", 26, 0..255, 1, { filled && page == Page.CONFIG }) @@ -136,7 +136,7 @@ internal object HighwayTools : Module( private val blueprint = LinkedHashMap() // State - private val rubberBandTimer = TickTimer(TimeUnit.TICKS) + private val rubberbandTimer = TickTimer(TimeUnit.TICKS) private var active = false private var waitTicks = 0 @@ -282,7 +282,7 @@ internal object HighwayTools : Module( } } is SPacketPlayerPosLook -> { - rubberBandTimer.reset() + rubberbandTimer.reset() } } } @@ -297,7 +297,7 @@ internal object HighwayTools : Module( updateRenderer() updateFood() - if (!rubberBandTimer.tick(rubberBandTimeout.toLong(), false)) { + if (!rubberbandTimer.tick(rubberbandTimeout.toLong(), false)) { return@safeListener } @@ -435,9 +435,9 @@ internal object HighwayTools : Module( private fun generateClear(basePos: BlockPos, xDirection: Direction) { if (!clearSpace) return - for (w in 0 until buildWidth) { - for (h in 0 until clearHeight) { - val x = w - buildWidth / 2 + for (w in 0 until width) { + for (h in 0 until height) { + val x = w - width / 2 val pos = basePos.add(xDirection.directionVec.multiply(x)).up(h) if (mode == Mode.HIGHWAY && h == 0 && isRail(w)) { @@ -454,8 +454,8 @@ internal object HighwayTools : Module( } private fun generateBase(basePos: BlockPos, xDirection: Direction) { - for (w in 0 until buildWidth) { - val x = w - buildWidth / 2 + for (w in 0 until width) { + val x = w - width / 2 val pos = basePos.add(xDirection.directionVec.multiply(x)) if (mode == Mode.HIGHWAY && isRail(w)) { @@ -469,14 +469,14 @@ internal object HighwayTools : Module( } } - private fun isRail(w: Int) = railing && w !in 1 until buildWidth - 1 + private fun isRail(w: Int) = railing && w !in 1 until width - 1 private fun generateFlat(basePos: BlockPos) { // Base - for (w1 in 0 until buildWidth) { - for (w2 in 0 until buildWidth) { - val x = w1 - buildWidth / 2 - val z = w2 - buildWidth / 2 + for (w1 in 0 until width) { + for (w2 in 0 until width) { + val x = w1 - width / 2 + val z = w2 - width / 2 val pos = basePos.add(x, 0, z) blueprint[pos] = material @@ -485,11 +485,11 @@ internal object HighwayTools : Module( // Clear if (!clearSpace) return - for (w1 in -buildWidth..buildWidth) { - for (w2 in -buildWidth..buildWidth) { - for (y in 1 until clearHeight) { - val x = w1 - buildWidth / 2 - val z = w2 - buildWidth / 2 + for (w1 in -width..width) { + for (w2 in -width..width) { + for (y in 1 until height) { + val x = w1 - width / 2 + val z = w2 - width / 2 val pos = basePos.add(x, y, z) blueprint[pos] = Blocks.AIR @@ -673,7 +673,7 @@ internal object HighwayTools : Module( if (update) { when (world.getBlockState(blockTask.blockPos).block) { Blocks.AIR -> { - waitTicks = tickDelayBreak + waitTicks = breakDelay if (blockTask.block == material || blockTask.block == fillerMat) { blockTask.updateState(TaskState.PLACE) } else { @@ -848,7 +848,7 @@ internal object HighwayTools : Module( val hitVecOffset = WorldUtils.getHitVecOffset(pair.first) val currentBlock = world.getBlockState(pair.second).block - waitTicks = tickDelayPlace + waitTicks = placeDelay blockTask.updateState(TaskState.PENDING_PLACED) if (currentBlock in blackList) { @@ -870,7 +870,7 @@ internal object HighwayTools : Module( } } - delay(50L * taskTimeoutTicks) + delay(50L * taskTimeout) if (blockTask.taskState == TaskState.PENDING_PLACED) { blockTask.updateState(TaskState.PLACE) } @@ -982,7 +982,7 @@ internal object HighwayTools : Module( } private fun mineBlockInstant(blockTask: BlockTask, side: EnumFacing) { - waitTicks = tickDelayBreak + waitTicks = breakDelay blockTask.updateState(TaskState.PENDING_BROKEN) defaultScope.launch { @@ -998,7 +998,7 @@ internal object HighwayTools : Module( player.swingArm(EnumHand.MAIN_HAND) } - delay(50L * taskTimeoutTicks) + delay(50L * taskTimeout) if (blockTask.taskState == TaskState.PENDING_BROKEN) { blockTask.updateState(TaskState.BREAK) } From 0b7e8467bb7b795552937e1c47e90714de83f23d Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Wed, 27 Jan 2021 13:56:18 -0500 Subject: [PATCH 260/390] Longer timeout on rubberband --- .../me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index bac31d99f1..3703676484 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -82,7 +82,7 @@ internal object HighwayTools : Module( private val placeDelay by setting("Place Delay", 2, 1..20, 1, { page == Page.BEHAVIOR }) private val breakDelay by setting("Break Delay", 1, 1..20, 1, { page == Page.BEHAVIOR }) private val taskTimeout by setting("Task Timeout", 5, 0..20, 1, { page == Page.BEHAVIOR }) - private val rubberbandTimeout by setting("Rubberband Timeout", 5, 1..20, 1, { page == Page.BEHAVIOR }) + private val rubberbandTimeout by setting("Rubberband Timeout", 50, 5..100, 5, { page == Page.BEHAVIOR }) private val maxReach by setting("MaxReach", 4.5f, 1.0f..6.0f, 0.1f, { page == Page.BEHAVIOR }) // config From 2ee73d3e57c47da31cc0998a94c038c997ffe671 Mon Sep 17 00:00:00 2001 From: Christian Date: Wed, 27 Jan 2021 21:20:07 +0100 Subject: [PATCH 261/390] Remove task if blocked by entitiy --- .../me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 3703676484..03b2853530 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -795,7 +795,8 @@ internal object HighwayTools : Module( } } else { if (!isPlaceable(blockTask.blockPos)) { - if (debugMessages != DebugMessages.OFF) MessageSendHelper.sendChatMessage("Invalid place position: " + blockTask.blockPos) + if (debugMessages != DebugMessages.OFF) MessageSendHelper.sendChatMessage("Invalid place position: ${blockTask.blockPos}. Removing task") + pendingTasks.remove(blockTask.blockPos) refreshData() return } From b8de20c6f3e13c50b5c2851d803ce1e4f7b0a82a Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Wed, 27 Jan 2021 15:28:36 -0500 Subject: [PATCH 262/390] Spam start mining and stop mining packet together --- .../kami/module/modules/misc/HighwayTools.kt | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 3703676484..b26e3daf6c 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -989,11 +989,6 @@ internal object HighwayTools : Module( delay(20L) onMainThreadSafe { connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, blockTask.blockPos, side)) - player.swingArm(EnumHand.MAIN_HAND) - } - - delay(30L) - onMainThreadSafe { connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, blockTask.blockPos, side)) player.swingArm(EnumHand.MAIN_HAND) } @@ -1006,13 +1001,7 @@ internal object HighwayTools : Module( } /* Dispatches a thread to mine any non-netherrack blocks generically */ - private fun mineBlockNormal(blockTask: BlockTask, facing: EnumFacing) { - val action = if (blockTask.taskState == TaskState.BREAKING) { - CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK - } else { - CPacketPlayerDigging.Action.START_DESTROY_BLOCK - } - + private fun mineBlockNormal(blockTask: BlockTask, side: EnumFacing) { if (blockTask.taskState == TaskState.BREAK) { blockTask.updateState(TaskState.BREAKING) } @@ -1020,7 +1009,8 @@ internal object HighwayTools : Module( defaultScope.launch { delay(20L) onMainThreadSafe { - connection.sendPacket(CPacketPlayerDigging(action, blockTask.blockPos, facing)) + connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, blockTask.blockPos, side)) + connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, blockTask.blockPos, side)) player.swingArm(EnumHand.MAIN_HAND) } } From 5ba2a57d643043db684baf819dd7636a2bf3fd3d Mon Sep 17 00:00:00 2001 From: Christian Date: Wed, 27 Jan 2021 22:10:41 +0100 Subject: [PATCH 263/390] Delay for mining --- .../kami/module/modules/misc/HighwayTools.kt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index dbbcf40eb4..2d01670663 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -990,6 +990,11 @@ internal object HighwayTools : Module( delay(20L) onMainThreadSafe { connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, blockTask.blockPos, side)) + player.swingArm(EnumHand.MAIN_HAND) + } + + delay(20L) + onMainThreadSafe { connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, blockTask.blockPos, side)) player.swingArm(EnumHand.MAIN_HAND) } @@ -1011,6 +1016,11 @@ internal object HighwayTools : Module( delay(20L) onMainThreadSafe { connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, blockTask.blockPos, side)) + player.swingArm(EnumHand.MAIN_HAND) + } + + delay(20L) + onMainThreadSafe { connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, blockTask.blockPos, side)) player.swingArm(EnumHand.MAIN_HAND) } From 2f11e00293f43e092666d69393500570d933241d Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Wed, 27 Jan 2021 16:09:16 -0500 Subject: [PATCH 264/390] Added multi break --- .../kami/module/modules/misc/HighwayTools.kt | 63 ++++++++++++++----- .../kami/util/math/BoundingBoxUtils.kt | 31 +++++++++ .../kami/util/math/VectorUtils.kt | 14 +++++ 3 files changed, 94 insertions(+), 14 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 2d01670663..e79cdb395e 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -44,6 +44,7 @@ import net.minecraft.network.play.server.SPacketPlayerPosLook import net.minecraft.util.EnumFacing import net.minecraft.util.EnumHand import net.minecraft.util.SoundCategory +import net.minecraft.util.math.AxisAlignedBB import net.minecraft.util.math.BlockPos import net.minecraft.util.math.Vec3d import net.minecraftforge.fml.common.gameevent.TickEvent @@ -76,11 +77,13 @@ internal object HighwayTools : Module( // behavior settings private val interacting by setting("Rotation Mode", RotationMode.SPOOF, { page == Page.BEHAVIOR }) + private val fastMining by setting("Fast Mining", false, { page == Page.BEHAVIOR }) private val illegalPlacements by setting("Illegal Placements", false, { page == Page.BEHAVIOR }) private val toggleInventoryManager by setting("Toggle InvManager", true, { page == Page.BEHAVIOR }) private val toggleAutoObsidian by setting("Toggle AutoObsidian", true, { page == Page.BEHAVIOR }) private val placeDelay by setting("Place Delay", 2, 1..20, 1, { page == Page.BEHAVIOR }) private val breakDelay by setting("Break Delay", 1, 1..20, 1, { page == Page.BEHAVIOR }) + private val maxBreaks by setting("Multi Break", 1, 1..8, 1, { page == Page.BEHAVIOR }) private val taskTimeout by setting("Task Timeout", 5, 0..20, 1, { page == Page.BEHAVIOR }) private val rubberbandTimeout by setting("Rubberband Timeout", 50, 5..100, 5, { page == Page.BEHAVIOR }) private val maxReach by setting("MaxReach", 4.5f, 1.0f..6.0f, 0.1f, { page == Page.BEHAVIOR }) @@ -988,15 +991,10 @@ internal object HighwayTools : Module( defaultScope.launch { delay(20L) - onMainThreadSafe { - connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, blockTask.blockPos, side)) - player.swingArm(EnumHand.MAIN_HAND) - } + sendMiningPackets(blockTask.blockPos, side) - delay(20L) - onMainThreadSafe { - connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, blockTask.blockPos, side)) - player.swingArm(EnumHand.MAIN_HAND) + if (maxBreaks > 1) { + tryMultiBreak(blockTask) } delay(50L * taskTimeout) @@ -1006,6 +1004,35 @@ internal object HighwayTools : Module( } } + private fun tryMultiBreak(blockTask: BlockTask) { + runSafe { + val eyePos = player.getPositionEyes(1.0f) + val viewVec = lastHitVec.subtract(eyePos).normalize() + var breakCount = 1 + + for (task in sortedTasks) { + if (breakCount >= maxBreaks) break + + if (task == blockTask) continue + if (task.taskState != TaskState.BREAK) continue + if (world.getBlockState(task.blockPos).block != Blocks.NETHERRACK) continue + + val box = AxisAlignedBB(task.blockPos) + val rayTraceResult = box.isInSight(eyePos, viewVec) ?: continue + breakCount++ + + defaultScope.launch { + sendMiningPackets(task.blockPos, rayTraceResult.sideHit) + + delay(50L * taskTimeout) + if (blockTask.taskState == TaskState.PENDING_BROKEN) { + blockTask.updateState(TaskState.BREAK) + } + } + } + } + } + /* Dispatches a thread to mine any non-netherrack blocks generically */ private fun mineBlockNormal(blockTask: BlockTask, side: EnumFacing) { if (blockTask.taskState == TaskState.BREAK) { @@ -1014,14 +1041,22 @@ internal object HighwayTools : Module( defaultScope.launch { delay(20L) - onMainThreadSafe { - connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, blockTask.blockPos, side)) - player.swingArm(EnumHand.MAIN_HAND) - } + sendMiningPackets(blockTask.blockPos, side) + } + } + + private suspend fun sendMiningPackets(pos: BlockPos, side: EnumFacing) { + onMainThreadSafe { + connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, pos, side)) + if (fastMining) connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, pos, side)) + + player.swingArm(EnumHand.MAIN_HAND) + } + if (!fastMining) { delay(20L) onMainThreadSafe { - connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, blockTask.blockPos, side)) + connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, pos, side)) player.swingArm(EnumHand.MAIN_HAND) } } @@ -1042,7 +1077,7 @@ internal object HighwayTools : Module( "\n §9> §rFiller material: §7${fillerMat.localizedName}" + "\n §9> §rIgnored Blocks:") - for (b in ignoreBlocks) append("\n §9> §7${b!!.registryName}") + for (b in ignoreBlocks) append("\n §9> §7${b.registryName}") MessageSendHelper.sendChatMessage(toString()) } diff --git a/src/main/java/me/zeroeightsix/kami/util/math/BoundingBoxUtils.kt b/src/main/java/me/zeroeightsix/kami/util/math/BoundingBoxUtils.kt index 4ab09996d7..f5fbf73840 100644 --- a/src/main/java/me/zeroeightsix/kami/util/math/BoundingBoxUtils.kt +++ b/src/main/java/me/zeroeightsix/kami/util/math/BoundingBoxUtils.kt @@ -1,10 +1,13 @@ package me.zeroeightsix.kami.util.math +import me.zeroeightsix.kami.util.Wrapper import me.zeroeightsix.kami.util.math.VectorUtils.plus import me.zeroeightsix.kami.util.math.VectorUtils.times import me.zeroeightsix.kami.util.math.VectorUtils.toVec3d +import me.zeroeightsix.kami.util.math.VectorUtils.toViewVec import net.minecraft.util.EnumFacing import net.minecraft.util.math.AxisAlignedBB +import net.minecraft.util.math.RayTraceResult import net.minecraft.util.math.Vec3d val AxisAlignedBB.xLength get() = maxX - minX @@ -35,4 +38,32 @@ fun AxisAlignedBB.side(side: EnumFacing, scale: Double = 0.5): Vec3d { val lengths = lengths val sideDirectionVec = side.directionVec.toVec3d() return lengths * sideDirectionVec * scale + center +} + +/** + * Check if a block is in sight + * + * Reverse engineered from HauseMaster's anti cheat plugin + */ +fun AxisAlignedBB.isInSight( + posFrom: Vec3d = Wrapper.player?.getPositionEyes(1.0f) ?: Vec3d.ZERO, + rotation: Vec2f = Wrapper.player?.let { Vec2f(it) } ?: Vec2f.ZERO, + range: Double = 4.25, + tolerance: Double = 1.05 +) = isInSight(posFrom, rotation.toViewVec(), range, tolerance) + +/** + * Check if a block is in sight + * + * Reverse engineered from HauseMaster's anti cheat plugin + */ +fun AxisAlignedBB.isInSight( + posFrom: Vec3d, + viewVec: Vec3d, + range: Double = 4.25, + tolerance: Double = 1.05 +): RayTraceResult? { + val sightEnd = posFrom.add(viewVec.scale(range)) + + return grow(tolerance - 1.0).calculateIntercept(posFrom, sightEnd) } \ No newline at end of file diff --git a/src/main/java/me/zeroeightsix/kami/util/math/VectorUtils.kt b/src/main/java/me/zeroeightsix/kami/util/math/VectorUtils.kt index 32f3613361..7d3fc2641a 100644 --- a/src/main/java/me/zeroeightsix/kami/util/math/VectorUtils.kt +++ b/src/main/java/me/zeroeightsix/kami/util/math/VectorUtils.kt @@ -5,6 +5,7 @@ import net.minecraft.util.math.BlockPos import net.minecraft.util.math.ChunkPos import net.minecraft.util.math.Vec3d import net.minecraft.util.math.Vec3i +import org.kamiblue.commons.extension.PI_FLOAT import org.kamiblue.commons.extension.ceilToInt import org.kamiblue.commons.extension.floorToInt import kotlin.math.* @@ -63,6 +64,19 @@ object VectorUtils { return IntRange((d1 - d2).floorToInt(), (d1 + d2).ceilToInt()) } + fun Vec2f.toViewVec(): Vec3d { + val rotationRad = toRadians() + val yaw = -rotationRad.x - PI_FLOAT + val pitch = -rotationRad.y + + val cosYaw = cos(yaw) + val sinYaw = sin(yaw) + val cosPitch = -cos(pitch) + val sinPitch = sin(pitch) + + return Vec3d((sinYaw * cosPitch).toDouble(), sinPitch.toDouble(), (cosYaw * cosPitch).toDouble()) + } + fun Vec3d.toBlockPos(): BlockPos { return BlockPos(x.floorToInt(), y.floorToInt(), z.floorToInt()) } From eb6b25a30eb76626bd053ed3706a6f875d404cb5 Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Wed, 27 Jan 2021 16:13:16 -0500 Subject: [PATCH 265/390] Renamed fast mining to fast break --- .../zeroeightsix/kami/module/modules/misc/HighwayTools.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index e79cdb395e..b2fcc0207c 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -77,7 +77,7 @@ internal object HighwayTools : Module( // behavior settings private val interacting by setting("Rotation Mode", RotationMode.SPOOF, { page == Page.BEHAVIOR }) - private val fastMining by setting("Fast Mining", false, { page == Page.BEHAVIOR }) + private val fastBreak by setting("Fast Break", false, { page == Page.BEHAVIOR }) private val illegalPlacements by setting("Illegal Placements", false, { page == Page.BEHAVIOR }) private val toggleInventoryManager by setting("Toggle InvManager", true, { page == Page.BEHAVIOR }) private val toggleAutoObsidian by setting("Toggle AutoObsidian", true, { page == Page.BEHAVIOR }) @@ -1048,12 +1048,12 @@ internal object HighwayTools : Module( private suspend fun sendMiningPackets(pos: BlockPos, side: EnumFacing) { onMainThreadSafe { connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, pos, side)) - if (fastMining) connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, pos, side)) + if (fastBreak) connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, pos, side)) player.swingArm(EnumHand.MAIN_HAND) } - if (!fastMining) { + if (!fastBreak) { delay(20L) onMainThreadSafe { connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, pos, side)) From 46229ee3d07f2f8b359c9b0def2de033d77d5cb5 Mon Sep 17 00:00:00 2001 From: Christian Date: Wed, 27 Jan 2021 22:25:27 +0100 Subject: [PATCH 266/390] Fix tunnel blueprint --- .../me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index b2fcc0207c..f072ac7ae3 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -417,8 +417,9 @@ internal object HighwayTools : Module( if (mode != Mode.TUNNEL) generateBase(thisPos, xDirection) } if (mode == Mode.TUNNEL) { - blueprint[basePos.add(zDirection.directionVec.multiply(1))] = fillerMat - blueprint[basePos.add(zDirection.directionVec.multiply(2))] = fillerMat + for (x in 1..maxReach.floorToInt()) { + blueprint[basePos.add(zDirection.directionVec.multiply(x))] = fillerMat + } } pickTasksInRange() From 67e9d456a81419a1367b9cb86dc3919f4dc40fe9 Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Wed, 27 Jan 2021 17:14:45 -0500 Subject: [PATCH 267/390] Fixed break count in breaking task state --- .../kami/module/modules/misc/HighwayTools.kt | 63 +++++++++++-------- 1 file changed, 38 insertions(+), 25 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index f072ac7ae3..c9c551d8c8 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -678,15 +678,15 @@ internal object HighwayTools : Module( when (world.getBlockState(blockTask.blockPos).block) { Blocks.AIR -> { waitTicks = breakDelay - if (blockTask.block == material || blockTask.block == fillerMat) { - blockTask.updateState(TaskState.PLACE) - } else { - blockTask.updateState(TaskState.DONE) - } + blockTask.updateState(TaskState.BROKEN) } is BlockLiquid -> { - var filler = fillerMat - if (isInsideBlueprintBuild(blockTask.blockPos) || fillerMatLeft == 0) filler = material + val filler = if (fillerMatLeft == 0 || isInsideBlueprintBuild(blockTask.blockPos)) { + material + } else { + fillerMat + } + if (world.getBlockState(blockTask.blockPos).getValue(BlockLiquid.LEVEL) != 0) { blockTask.updateState(TaskState.LIQUID_FLOW) blockTask.updateMaterial(filler) @@ -705,17 +705,16 @@ internal object HighwayTools : Module( if (update) { when (world.getBlockState(blockTask.blockPos).block) { Blocks.AIR -> { - if (blockTask.block != Blocks.AIR) { - blockTask.updateState(TaskState.PLACE) - } else { - blockTask.updateState(TaskState.DONE) + totalBlocksDestroyed++ + + if (blockTask.block == Blocks.AIR) { if (fakeSounds) { val soundType = blockTask.block.getSoundType(world.getBlockState(blockTask.blockPos), world, blockTask.blockPos, player) - onMainThread { - world.playSound(player, blockTask.blockPos, soundType.breakSound, SoundCategory.BLOCKS, (soundType.getVolume() + 1.0f) / 2.0f, soundType.getPitch() * 0.8f) - } + world.playSound(player, blockTask.blockPos, soundType.breakSound, SoundCategory.BLOCKS, (soundType.getVolume() + 1.0f) / 2.0f, soundType.getPitch() * 0.8f) } - totalBlocksDestroyed++ + blockTask.updateState(TaskState.DONE) + } else { + blockTask.updateState(TaskState.PLACE) } } else -> { @@ -761,14 +760,15 @@ internal object HighwayTools : Module( when (world.getBlockState(blockTask.blockPos).block) { Blocks.AIR -> { if (blockTask.block == Blocks.AIR) { - blockTask.updateState(TaskState.DONE) + blockTask.updateState(TaskState.BROKEN) } else { blockTask.updateState(TaskState.PLACE) } } is BlockLiquid -> { - var filler = fillerMat - if (isInsideBlueprintBuild(blockTask.blockPos) || fillerMatLeft == 0) filler = material + val filler = if (fillerMatLeft == 0 || isInsideBlueprintBuild(blockTask.blockPos)) material + else fillerMat + if (world.getBlockState(blockTask.blockPos).getValue(BlockLiquid.LEVEL) != 0) { blockTask.updateState(TaskState.LIQUID_FLOW) blockTask.updateMaterial(filler) @@ -787,21 +787,34 @@ internal object HighwayTools : Module( private fun SafeClientEvent.doPlace(blockTask: BlockTask, update: Boolean) { if (update) { - val block = world.getBlockState(blockTask.blockPos).block + val currentBlock = world.getBlockState(blockTask.blockPos).block - when { - block == material && block == blockTask.block -> { - blockTask.updateState(TaskState.PLACED) + when(blockTask.block) { + material -> { + if (currentBlock == material) { + blockTask.updateState(TaskState.PLACED) + } else if (currentBlock != Blocks.AIR) { + blockTask.updateState(TaskState.BREAK) + } } - block == fillerMat && block == blockTask.block -> { - blockTask.updateState(TaskState.PLACED) + fillerMat -> { + if (currentBlock != Blocks.AIR && currentBlock !is BlockLiquid) { + blockTask.updateState(TaskState.PLACED) + } + } + Blocks.AIR -> { + if (currentBlock != Blocks.AIR) { + blockTask.updateState(TaskState.BREAK) + } else { + blockTask.updateState(TaskState.BROKEN) + } } } + } else { if (!isPlaceable(blockTask.blockPos)) { if (debugMessages != DebugMessages.OFF) MessageSendHelper.sendChatMessage("Invalid place position: ${blockTask.blockPos}. Removing task") pendingTasks.remove(blockTask.blockPos) - refreshData() return } From e2de5edc83cc64f201bb6098698b6bfef29f368a Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Wed, 27 Jan 2021 17:33:05 -0500 Subject: [PATCH 268/390] Cleaned up state updating on packet --- .../kami/module/modules/misc/HighwayTools.kt | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index c9c551d8c8..22463a8132 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -264,22 +264,25 @@ internal object HighwayTools : Module( val pos = it.packet.blockPosition if (!isInsideBlueprint(pos)) return@safeListener - val prev = world.getBlockState(pos) - val new = it.packet.getBlockState() + val prev = world.getBlockState(pos).block + val new = it.packet.getBlockState().block - if (prev.block != new.block) { + if (prev != new) { val task = pendingTasks[pos] ?: return@safeListener - when { - task.taskState == TaskState.PENDING_BROKEN && - prev.block != Blocks.AIR && - new.block == Blocks.AIR -> { - task.updateState(TaskState.BROKEN) + when (task.taskState) { + TaskState.PENDING_BROKEN, TaskState.BREAKING -> { + if (new == Blocks.AIR) { + task.updateState(TaskState.BROKEN) + } } - task.taskState == TaskState.PENDING_PLACED && - (task.block == material || task.block == fillerMat) - && task.block == new.block -> { - task.updateState(TaskState.PLACED) + TaskState.PENDING_PLACED -> { + if (task.block != Blocks.AIR && task.block == new) { + task.updateState(TaskState.PLACED) + } + } + else -> { + // Ignored } } } @@ -810,7 +813,6 @@ internal object HighwayTools : Module( } } } - } else { if (!isPlaceable(blockTask.blockPos)) { if (debugMessages != DebugMessages.OFF) MessageSendHelper.sendChatMessage("Invalid place position: ${blockTask.blockPos}. Removing task") From 48c81985a56aefe835d8c68210a7b5c7c89f3eb2 Mon Sep 17 00:00:00 2001 From: Christian Date: Wed, 27 Jan 2021 23:39:02 +0100 Subject: [PATCH 269/390] Temporary prio fix --- .../me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 22463a8132..fb13ff1784 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -606,12 +606,16 @@ internal object HighwayTools : Module( it.taskState.ordinal }.thenBy { it.stuckTicks / 2 + }.thenBy { + startingBlockPos.distanceTo(it.blockPos) }.thenBy { eyePos.distanceTo(it.blockPos) }.thenBy { lastHitVec?.distanceTo(it.blockPos) } ) + + // ToDo: We need a function that makes a score out of all parameters } private fun SafeClientEvent.checkStuckTimeout(blockTask: BlockTask): Boolean { From 3e060eaf875d1518cfb782c1682ce06996ff507b Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Wed, 27 Jan 2021 18:11:35 -0500 Subject: [PATCH 270/390] Always do the check before running the task --- .../kami/module/modules/misc/HighwayTools.kt | 227 +++++++++--------- 1 file changed, 115 insertions(+), 112 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index fb13ff1784..80fbbaf5ad 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -642,30 +642,30 @@ internal object HighwayTools : Module( return true } - private fun SafeClientEvent.doTask(blockTask: BlockTask, update: Boolean) { - if (!update) blockTask.onTick() + private fun SafeClientEvent.doTask(blockTask: BlockTask, updateOnly: Boolean) { + if (!updateOnly) blockTask.onTick() when (blockTask.taskState) { TaskState.DONE -> { - doDone(blockTask, update) + doDone(blockTask) } TaskState.BREAKING -> { - doBreaking(blockTask, update) + doBreaking(blockTask, updateOnly) } TaskState.BROKEN -> { - doBroken(blockTask, update) + doBroken(blockTask, updateOnly) } TaskState.PLACED -> { - doPlaced(blockTask, update) + doPlaced(blockTask) } TaskState.BREAK -> { - doBreak(blockTask, update) + doBreak(blockTask, updateOnly) } TaskState.PLACE, TaskState.LIQUID_SOURCE, TaskState.LIQUID_FLOW -> { - doPlace(blockTask, update) + doPlace(blockTask, updateOnly) } TaskState.PENDING_BROKEN, TaskState.PENDING_PLACED -> { - if (!update && debugMessages == DebugMessages.ALL) { + if (!updateOnly && debugMessages == DebugMessages.ALL) { MessageSendHelper.sendChatMessage("$chatName Currently waiting for blockState updates...") } blockTask.onStuck() @@ -673,151 +673,154 @@ internal object HighwayTools : Module( } } - private fun doDone(blockTask: BlockTask, update: Boolean) { - if (update) { - pendingTasks[blockTask.blockPos] - doneTasks[blockTask.blockPos] = blockTask - } + private fun doDone(blockTask: BlockTask) { + pendingTasks[blockTask.blockPos] + doneTasks[blockTask.blockPos] = blockTask } - private fun SafeClientEvent.doBreaking(blockTask: BlockTask, update: Boolean) { - if (update) { - when (world.getBlockState(blockTask.blockPos).block) { - Blocks.AIR -> { - waitTicks = breakDelay - blockTask.updateState(TaskState.BROKEN) + private fun SafeClientEvent.doBreaking(blockTask: BlockTask, updateOnly: Boolean) { + when (world.getBlockState(blockTask.blockPos).block) { + Blocks.AIR -> { + waitTicks = breakDelay + blockTask.updateState(TaskState.BROKEN) + return + } + is BlockLiquid -> { + val filler = if (fillerMatLeft == 0 || isInsideBlueprintBuild(blockTask.blockPos)) { + material + } else { + fillerMat } - is BlockLiquid -> { - val filler = if (fillerMatLeft == 0 || isInsideBlueprintBuild(blockTask.blockPos)) { - material - } else { - fillerMat - } - if (world.getBlockState(blockTask.blockPos).getValue(BlockLiquid.LEVEL) != 0) { - blockTask.updateState(TaskState.LIQUID_FLOW) - blockTask.updateMaterial(filler) - } else { - blockTask.updateState(TaskState.LIQUID_SOURCE) - blockTask.updateMaterial(filler) - } + if (world.getBlockState(blockTask.blockPos).getValue(BlockLiquid.LEVEL) != 0) { + blockTask.updateState(TaskState.LIQUID_FLOW) + blockTask.updateMaterial(filler) + } else { + blockTask.updateState(TaskState.LIQUID_SOURCE) + blockTask.updateMaterial(filler) } + + return } - } else { + } + + if (!updateOnly) { mineBlock(blockTask) } } - private fun SafeClientEvent.doBroken(blockTask: BlockTask, update: Boolean) { - if (update) { - when (world.getBlockState(blockTask.blockPos).block) { - Blocks.AIR -> { - totalBlocksDestroyed++ + private fun SafeClientEvent.doBroken(blockTask: BlockTask, updateOnly: Boolean) { + when (world.getBlockState(blockTask.blockPos).block) { + Blocks.AIR -> { + totalBlocksDestroyed++ - if (blockTask.block == Blocks.AIR) { - if (fakeSounds) { - val soundType = blockTask.block.getSoundType(world.getBlockState(blockTask.blockPos), world, blockTask.blockPos, player) - world.playSound(player, blockTask.blockPos, soundType.breakSound, SoundCategory.BLOCKS, (soundType.getVolume() + 1.0f) / 2.0f, soundType.getPitch() * 0.8f) - } - blockTask.updateState(TaskState.DONE) - } else { - blockTask.updateState(TaskState.PLACE) + if (blockTask.block == Blocks.AIR) { + if (fakeSounds) { + val soundType = blockTask.block.getSoundType(world.getBlockState(blockTask.blockPos), world, blockTask.blockPos, player) + world.playSound(player, blockTask.blockPos, soundType.breakSound, SoundCategory.BLOCKS, (soundType.getVolume() + 1.0f) / 2.0f, soundType.getPitch() * 0.8f) } + blockTask.updateState(TaskState.DONE) + } else { + blockTask.updateState(TaskState.PLACE) } - else -> { - blockTask.updateState(TaskState.BREAK) - } + } + else -> { + blockTask.updateState(TaskState.BREAK) } } } - private fun SafeClientEvent.doPlaced(blockTask: BlockTask, update: Boolean) { - if (update) { - val currentBlock = world.getBlockState(blockTask.blockPos).block + private fun SafeClientEvent.doPlaced(blockTask: BlockTask) { + val currentBlock = world.getBlockState(blockTask.blockPos).block - when { - blockTask.block == currentBlock && currentBlock != Blocks.AIR -> { - blockTask.updateState(TaskState.DONE) - if (fakeSounds) { - val soundType = currentBlock.getSoundType(world.getBlockState(blockTask.blockPos), world, blockTask.blockPos, player) - world.playSound(player, blockTask.blockPos, soundType.placeSound, SoundCategory.BLOCKS, (soundType.getVolume() + 1.0f) / 2.0f, soundType.getPitch() * 0.8f) - } - totalBlocksPlaced++ - } - blockTask.block == currentBlock && currentBlock == Blocks.AIR -> { - blockTask.updateState(TaskState.BREAK) - } - blockTask.block == Blocks.AIR && currentBlock != Blocks.AIR -> { - blockTask.updateState(TaskState.BREAK) - } - else -> { - blockTask.updateState(TaskState.PLACE) + when { + blockTask.block == currentBlock && currentBlock != Blocks.AIR -> { + blockTask.updateState(TaskState.DONE) + if (fakeSounds) { + val soundType = currentBlock.getSoundType(world.getBlockState(blockTask.blockPos), world, blockTask.blockPos, player) + world.playSound(player, blockTask.blockPos, soundType.placeSound, SoundCategory.BLOCKS, (soundType.getVolume() + 1.0f) / 2.0f, soundType.getPitch() * 0.8f) } + totalBlocksPlaced++ + } + blockTask.block == currentBlock && currentBlock == Blocks.AIR -> { + blockTask.updateState(TaskState.BREAK) + } + blockTask.block == Blocks.AIR && currentBlock != Blocks.AIR -> { + blockTask.updateState(TaskState.BREAK) + } + else -> { + blockTask.updateState(TaskState.PLACE) } } } - private fun SafeClientEvent.doBreak(blockTask: BlockTask, update: Boolean) { + private fun SafeClientEvent.doBreak(blockTask: BlockTask, updateOnly: Boolean) { // ignore blocks if (blockTask.block != Blocks.AIR && ignoreBlocks.contains(blockTask.block)) { blockTask.updateState(TaskState.DONE) } - if (update) { - when (world.getBlockState(blockTask.blockPos).block) { - Blocks.AIR -> { - if (blockTask.block == Blocks.AIR) { - blockTask.updateState(TaskState.BROKEN) - } else { - blockTask.updateState(TaskState.PLACE) - } + when (world.getBlockState(blockTask.blockPos).block) { + Blocks.AIR -> { + if (blockTask.block == Blocks.AIR) { + blockTask.updateState(TaskState.BROKEN) + return + } else { + blockTask.updateState(TaskState.PLACE) + return } - is BlockLiquid -> { - val filler = if (fillerMatLeft == 0 || isInsideBlueprintBuild(blockTask.blockPos)) material - else fillerMat - - if (world.getBlockState(blockTask.blockPos).getValue(BlockLiquid.LEVEL) != 0) { - blockTask.updateState(TaskState.LIQUID_FLOW) - blockTask.updateMaterial(filler) - } else { - blockTask.updateState(TaskState.LIQUID_SOURCE) - blockTask.updateMaterial(filler) - } + } + is BlockLiquid -> { + val filler = if (fillerMatLeft == 0 || isInsideBlueprintBuild(blockTask.blockPos)) material + else fillerMat + + if (world.getBlockState(blockTask.blockPos).getValue(BlockLiquid.LEVEL) != 0) { + blockTask.updateState(TaskState.LIQUID_FLOW) + blockTask.updateMaterial(filler) + } else { + blockTask.updateState(TaskState.LIQUID_SOURCE) + blockTask.updateMaterial(filler) } } - } else { + } + + if (!updateOnly) { if (handleLiquid(blockTask)) return swapOrMoveBestTool(blockTask) mineBlock(blockTask) } } - private fun SafeClientEvent.doPlace(blockTask: BlockTask, update: Boolean) { - if (update) { - val currentBlock = world.getBlockState(blockTask.blockPos).block + private fun SafeClientEvent.doPlace(blockTask: BlockTask, updateOnly: Boolean) { + val currentBlock = world.getBlockState(blockTask.blockPos).block - when(blockTask.block) { - material -> { - if (currentBlock == material) { - blockTask.updateState(TaskState.PLACED) - } else if (currentBlock != Blocks.AIR) { - blockTask.updateState(TaskState.BREAK) - } + when (blockTask.block) { + material -> { + if (currentBlock == material) { + blockTask.updateState(TaskState.PLACED) + return + } else if (currentBlock != Blocks.AIR) { + blockTask.updateState(TaskState.BREAK) + return } - fillerMat -> { - if (currentBlock != Blocks.AIR && currentBlock !is BlockLiquid) { - blockTask.updateState(TaskState.PLACED) - } + } + fillerMat -> { + if (currentBlock != Blocks.AIR && currentBlock !is BlockLiquid) { + blockTask.updateState(TaskState.PLACED) + return } - Blocks.AIR -> { - if (currentBlock != Blocks.AIR) { - blockTask.updateState(TaskState.BREAK) - } else { - blockTask.updateState(TaskState.BROKEN) - } + } + Blocks.AIR -> { + if (currentBlock != Blocks.AIR) { + blockTask.updateState(TaskState.BREAK) + } else { + blockTask.updateState(TaskState.BROKEN) } + return } - } else { + } + + if (!updateOnly) { if (!isPlaceable(blockTask.blockPos)) { if (debugMessages != DebugMessages.OFF) MessageSendHelper.sendChatMessage("Invalid place position: ${blockTask.blockPos}. Removing task") pendingTasks.remove(blockTask.blockPos) From aced23f687d005f86b1129431838b8f88334ed86 Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Wed, 27 Jan 2021 18:30:43 -0500 Subject: [PATCH 271/390] Less weight on stuck tick and start distance --- .../zeroeightsix/kami/module/modules/misc/HighwayTools.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 80fbbaf5ad..df52c194cc 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -184,7 +184,7 @@ internal object HighwayTools : Module( AutoObsidian.enable() } - startingBlockPos = Companion.mc.player.flooredPosition + startingBlockPos = player.flooredPosition currentBlockPos = startingBlockPos startingDirection = Direction.fromEntity(Companion.mc.player) @@ -605,9 +605,9 @@ internal object HighwayTools : Module( compareBy { it.taskState.ordinal }.thenBy { - it.stuckTicks / 2 + it.stuckTicks / 5 }.thenBy { - startingBlockPos.distanceTo(it.blockPos) + startingBlockPos.distanceTo(it.blockPos).toInt() / 2 }.thenBy { eyePos.distanceTo(it.blockPos) }.thenBy { @@ -1255,7 +1255,7 @@ internal object HighwayTools : Module( LIQUID_FLOW(80, 80, ColorHolder(120, 41, 240)), BREAKING(100, 100, ColorHolder(240, 222, 60)), BREAK(20, 20, ColorHolder(222, 0, 0)), - PLACE(20, 10, ColorHolder(35, 188, 254)), + PLACE(20, 20, ColorHolder(35, 188, 254)), PENDING_BROKEN(100, 100, ColorHolder(0, 0, 0)), PENDING_PLACED(100, 100, ColorHolder(0, 0, 0)) } From fbac66df68b85b5fdee117461594ae4ab3c62222 Mon Sep 17 00:00:00 2001 From: Christian Date: Thu, 28 Jan 2021 00:32:54 +0100 Subject: [PATCH 272/390] Better default for range --- .../me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 80fbbaf5ad..164d243099 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -86,7 +86,7 @@ internal object HighwayTools : Module( private val maxBreaks by setting("Multi Break", 1, 1..8, 1, { page == Page.BEHAVIOR }) private val taskTimeout by setting("Task Timeout", 5, 0..20, 1, { page == Page.BEHAVIOR }) private val rubberbandTimeout by setting("Rubberband Timeout", 50, 5..100, 5, { page == Page.BEHAVIOR }) - private val maxReach by setting("MaxReach", 4.5f, 1.0f..6.0f, 0.1f, { page == Page.BEHAVIOR }) + private val maxReach by setting("MaxReach", 5.4f, 1.0f..6.0f, 0.1f, { page == Page.BEHAVIOR }) // config private val fakeSounds by setting("Fake Sounds", true, { page == Page.CONFIG }) From 1e0799ce79db1218dc61f872cd8b6ff1e751760d Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Wed, 27 Jan 2021 18:34:24 -0500 Subject: [PATCH 273/390] Removed useless option --- .../kami/module/modules/misc/HighwayTools.kt | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 6402337862..52d140de68 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -69,15 +69,14 @@ internal object HighwayTools : Module( // build settings private val clearSpace by setting("Clear Space", true, { page == Page.BUILD && mode == Mode.HIGHWAY }) - private val height by setting("Height", 4, 1..6, 1, { page == Page.BUILD && clearSpace }) private val width by setting("Width", 5, 1..9, 1, { page == Page.BUILD }) + private val height by setting("Height", 4, 1..6, 1, { page == Page.BUILD && clearSpace }) private val railing by setting("Railing", true, { page == Page.BUILD && mode == Mode.HIGHWAY }) private val railingHeight by setting("Railing Height", 1, 1..4, 1, { railing && page == Page.BUILD && mode == Mode.HIGHWAY }) private val cornerBlock by setting("Corner Block", false, { page == Page.BUILD && (mode == Mode.HIGHWAY || mode == Mode.TUNNEL) }) // behavior settings private val interacting by setting("Rotation Mode", RotationMode.SPOOF, { page == Page.BEHAVIOR }) - private val fastBreak by setting("Fast Break", false, { page == Page.BEHAVIOR }) private val illegalPlacements by setting("Illegal Placements", false, { page == Page.BEHAVIOR }) private val toggleInventoryManager by setting("Toggle InvManager", true, { page == Page.BEHAVIOR }) private val toggleAutoObsidian by setting("Toggle AutoObsidian", true, { page == Page.BEHAVIOR }) @@ -1071,18 +1070,9 @@ internal object HighwayTools : Module( private suspend fun sendMiningPackets(pos: BlockPos, side: EnumFacing) { onMainThreadSafe { connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, pos, side)) - if (fastBreak) connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, pos, side)) - + connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, pos, side)) player.swingArm(EnumHand.MAIN_HAND) } - - if (!fastBreak) { - delay(20L) - onMainThreadSafe { - connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, pos, side)) - player.swingArm(EnumHand.MAIN_HAND) - } - } } private fun isInsideBlueprint(pos: BlockPos): Boolean { From 0b0f26390917f51b36c4dcbaf2e6c8a4439d45cf Mon Sep 17 00:00:00 2001 From: Christian Date: Thu, 28 Jan 2021 03:21:33 +0100 Subject: [PATCH 274/390] Cleanup and better stats --- .../kami/module/modules/misc/HighwayTools.kt | 60 +++++++++---------- 1 file changed, 28 insertions(+), 32 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 52d140de68..314f8dd32b 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -159,10 +159,13 @@ internal object HighwayTools : Module( private var totalBlocksPlaced = 0 private var totalBlocksDestroyed = 0 private var startTime = 0L + private var runtimeMilliSeconds = 0 private var prevFood = 0 private var foodLoss = 1 private var materialLeft = 0 private var fillerMatLeft = 0 + private var lastDurability = 0 + private var durabilityUsages = 0 private val renderer = ESPRenderer() @@ -313,6 +316,8 @@ internal object HighwayTools : Module( if (!active) { active = true BaritoneUtils.primary?.pathingControlManager?.registerProcess(HighwayToolsProcess) + } else { + runtimeMilliSeconds += 50 } doPathing() @@ -652,7 +657,7 @@ internal object HighwayTools : Module( doBreaking(blockTask, updateOnly) } TaskState.BROKEN -> { - doBroken(blockTask, updateOnly) + doBroken(blockTask) } TaskState.PLACED -> { doPlaced(blockTask) @@ -708,7 +713,7 @@ internal object HighwayTools : Module( } } - private fun SafeClientEvent.doBroken(blockTask: BlockTask, updateOnly: Boolean) { + private fun SafeClientEvent.doBroken(blockTask: BlockTask) { when (world.getBlockState(blockTask.blockPos).block) { Blocks.AIR -> { totalBlocksDestroyed++ @@ -1067,7 +1072,7 @@ internal object HighwayTools : Module( } } - private suspend fun sendMiningPackets(pos: BlockPos, side: EnumFacing) { + private fun sendMiningPackets(pos: BlockPos, side: EnumFacing) { onMainThreadSafe { connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, pos, side)) connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, pos, side)) @@ -1096,21 +1101,6 @@ internal object HighwayTools : Module( } } - // ToDo: Update to new dynamic blueprint - private fun getBlueprintStats(): Pair { - var materialUsed = 0 - var fillerMatUsed = 0 - - for ((_, b) in blueprint) { - when (b) { - material -> materialUsed++ - fillerMat -> fillerMatUsed++ - } - } - - return Pair(materialUsed / 2, fillerMatUsed / 2) - } - fun SafeClientEvent.gatherStatistics(): List { val currentTask = if (sortedTasks.isNotEmpty()) { sortedTasks[0] @@ -1118,26 +1108,31 @@ internal object HighwayTools : Module( null } + val distanceDone = startingBlockPos.distanceTo(currentBlockPos).toInt() + 1 + materialLeft = player.allSlots.countBlock(material) fillerMatLeft = player.allSlots.countBlock(fillerMat) val indirectMaterialLeft = 8 * player.allSlots.countBlock(Blocks.ENDER_CHEST) - val blueprintStats = getBlueprintStats() + val pavingLeft = materialLeft / ((totalBlocksPlaced + 0.001) / (distanceDone + 0.001)) - val pavingLeft = materialLeft / (blueprintStats.first + 1) - val pavingLeftAll = (materialLeft + indirectMaterialLeft) / (blueprintStats.first + 1) + // ToDo: Cache shulker count + val pavingLeftAll = (materialLeft + indirectMaterialLeft) / ((totalBlocksPlaced + 0.001) / (distanceDone + 0.001)) - val runtimeSec = ((System.currentTimeMillis() - startTime) / 1000) + 0.0001 + val runtimeSec = (runtimeMilliSeconds / 1000) + 0.0001 val seconds = (runtimeSec % 60).toInt().toString().padStart(2, '0') val minutes = ((runtimeSec % 3600) / 60).toInt().toString().padStart(2, '0') val hours = (runtimeSec / 3600).toInt().toString().padStart(2, '0') - val distanceDone = startingBlockPos.distanceTo(currentBlockPos).toInt() + val secLeftRefillInv = pavingLeft / (startingBlockPos.distanceTo(currentBlockPos).toInt() / runtimeSec) + val secondsLeftRefillInv = (secLeftRefillInv % 60).toInt().toString().padStart(2, '0') + val minutesLeftRefillInv = ((secLeftRefillInv % 3600) / 60).toInt().toString().padStart(2, '0') + val hoursLeftRefillInv = (secLeftRefillInv / 3600).toInt().toString().padStart(2, '0') - val secLeft = runtimeSec / (distanceDone * pavingLeftAll + 0.0001) - val secondsLeft = (secLeft % 60).toInt().toString().padStart(2, '0') - val minutesLeft = ((secLeft % 3600) / 60).toInt().toString().padStart(2, '0') - val hoursLeft = (secLeft / 3600).toInt().toString().padStart(2, '0') + val secLeftRefillShulker = pavingLeftAll / (startingBlockPos.distanceTo(currentBlockPos).toInt() / runtimeSec) + val secondsLeftRefillShulker = (secLeftRefillShulker % 60).toInt().toString().padStart(2, '0') + val minutesLeftRefillShulker = ((secLeftRefillShulker % 3600) / 60).toInt().toString().padStart(2, '0') + val hoursLeftRefillShulker = (secLeftRefillShulker / 3600).toInt().toString().padStart(2, '0') val statistics = mutableListOf( "§rPerformance", @@ -1157,15 +1152,16 @@ internal object HighwayTools : Module( " §7Status: §9${currentTask?.taskState}", " §7Target state: §9${currentTask?.block?.localizedName}", " §7Position: §9(${currentTask?.blockPos?.asString()})", - "§rDebug", " §7Stuck ticks: §9${currentTask?.stuckTicks.toString()}", -// " §7Pathing: §9$pathing", "§rEstimations", " §7${material.localizedName} (main material): §9$materialLeft + ($indirectMaterialLeft)", " §7${fillerMat.localizedName} (filler material): §9$fillerMatLeft", -// " §7Paving distance left: §9$pavingLeftAll", -// " §7Estimated destination: §9(${currentBlockPos.add(startingDirection.directionVec.multiply(pavingLeft))})", -// " §7ETA: §9$hoursLeft:$minutesLeft:$secondsLeft" + " §7Paving distance left: §9${pavingLeftAll.toInt()}", + " §7Paving distance left till refill: §9${pavingLeft.toInt()}", + " §7Estimated refill position: §9(${currentBlockPos.add(startingDirection.directionVec.multiply(pavingLeft.toInt())).asString()})", + " §7Estimated destination: §9(${currentBlockPos.add(startingDirection.directionVec.multiply(pavingLeftAll.toInt())).asString()})", + " §7ETA for inventory refill: §9$hoursLeftRefillInv:$minutesLeftRefillInv:$secondsLeftRefillInv", + " §7ETA for shulker refill: §9$hoursLeftRefillShulker:$minutesLeftRefillShulker:$secondsLeftRefillShulker" ) if (printDebug) { From 3e700d1ce380edc0c6cd5ad1b4c8990457c9f6e2 Mon Sep 17 00:00:00 2001 From: Christian Date: Thu, 28 Jan 2021 03:49:39 +0100 Subject: [PATCH 275/390] Better default settings --- .../me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 314f8dd32b..caf774a3e3 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -69,7 +69,7 @@ internal object HighwayTools : Module( // build settings private val clearSpace by setting("Clear Space", true, { page == Page.BUILD && mode == Mode.HIGHWAY }) - private val width by setting("Width", 5, 1..9, 1, { page == Page.BUILD }) + private val width by setting("Width", 6, 1..9, 1, { page == Page.BUILD }) private val height by setting("Height", 4, 1..6, 1, { page == Page.BUILD && clearSpace }) private val railing by setting("Railing", true, { page == Page.BUILD && mode == Mode.HIGHWAY }) private val railingHeight by setting("Railing Height", 1, 1..4, 1, { railing && page == Page.BUILD && mode == Mode.HIGHWAY }) @@ -82,7 +82,7 @@ internal object HighwayTools : Module( private val toggleAutoObsidian by setting("Toggle AutoObsidian", true, { page == Page.BEHAVIOR }) private val placeDelay by setting("Place Delay", 2, 1..20, 1, { page == Page.BEHAVIOR }) private val breakDelay by setting("Break Delay", 1, 1..20, 1, { page == Page.BEHAVIOR }) - private val maxBreaks by setting("Multi Break", 1, 1..8, 1, { page == Page.BEHAVIOR }) + private val maxBreaks by setting("Multi Break", 5, 1..8, 1, { page == Page.BEHAVIOR }) private val taskTimeout by setting("Task Timeout", 5, 0..20, 1, { page == Page.BEHAVIOR }) private val rubberbandTimeout by setting("Rubberband Timeout", 50, 5..100, 5, { page == Page.BEHAVIOR }) private val maxReach by setting("MaxReach", 5.4f, 1.0f..6.0f, 0.1f, { page == Page.BEHAVIOR }) From c152b2af21ac548ad545ac3bc59c429f3fe319ff Mon Sep 17 00:00:00 2001 From: Christian Date: Sat, 30 Jan 2021 20:46:59 +0100 Subject: [PATCH 276/390] Dynamic delay and fixes - Fix baritone process assignment - Fix Ignore blocks --- .../kami/module/modules/misc/HighwayTools.kt | 46 +++++++++++-------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index caf774a3e3..f3399f2858 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -77,15 +77,16 @@ internal object HighwayTools : Module( // behavior settings private val interacting by setting("Rotation Mode", RotationMode.SPOOF, { page == Page.BEHAVIOR }) + private val dynamicDelay by setting("Dynamic Place Delay", true, { page == Page.BEHAVIOR }) + private var placeDelay by setting("Place Delay", 3, 1..20, 1, { page == Page.BEHAVIOR }) + private var breakDelay by setting("Break Delay", 1, 1..20, 1, { page == Page.BEHAVIOR }) private val illegalPlacements by setting("Illegal Placements", false, { page == Page.BEHAVIOR }) + private val maxBreaks by setting("Multi Break", 3, 1..8, 1, { page == Page.BEHAVIOR }) private val toggleInventoryManager by setting("Toggle InvManager", true, { page == Page.BEHAVIOR }) private val toggleAutoObsidian by setting("Toggle AutoObsidian", true, { page == Page.BEHAVIOR }) - private val placeDelay by setting("Place Delay", 2, 1..20, 1, { page == Page.BEHAVIOR }) - private val breakDelay by setting("Break Delay", 1, 1..20, 1, { page == Page.BEHAVIOR }) - private val maxBreaks by setting("Multi Break", 5, 1..8, 1, { page == Page.BEHAVIOR }) - private val taskTimeout by setting("Task Timeout", 5, 0..20, 1, { page == Page.BEHAVIOR }) + private val taskTimeout by setting("Task Timeout", 8, 0..20, 1, { page == Page.BEHAVIOR }) private val rubberbandTimeout by setting("Rubberband Timeout", 50, 5..100, 5, { page == Page.BEHAVIOR }) - private val maxReach by setting("MaxReach", 5.4f, 1.0f..6.0f, 0.1f, { page == Page.BEHAVIOR }) + private val maxReach by setting("MaxReach", 4.9f, 1.0f..6.0f, 0.1f, { page == Page.BEHAVIOR }) // config private val fakeSounds by setting("Fake Sounds", true, { page == Page.CONFIG }) @@ -141,6 +142,7 @@ internal object HighwayTools : Module( private val rubberbandTimer = TickTimer(TimeUnit.TICKS) private var active = false private var waitTicks = 0 + private var extraPlaceDelay = 0 // Rotation private var lastHitVec = Vec3d.ZERO @@ -158,7 +160,6 @@ internal object HighwayTools : Module( // Stats private var totalBlocksPlaced = 0 private var totalBlocksDestroyed = 0 - private var startTime = 0L private var runtimeMilliSeconds = 0 private var prevFood = 0 private var foodLoss = 1 @@ -190,7 +191,6 @@ internal object HighwayTools : Module( currentBlockPos = startingBlockPos startingDirection = Direction.fromEntity(Companion.mc.player) - startTime = System.currentTimeMillis() totalBlocksPlaced = 0 totalBlocksDestroyed = 0 @@ -305,11 +305,9 @@ internal object HighwayTools : Module( updateRenderer() updateFood() - if (!rubberbandTimer.tick(rubberbandTimeout.toLong(), false)) { - return@safeListener - } - - if (player.flooredPosition.distanceTo(currentBlockPos) > 2 || AutoObsidian.isActive() || AutoEat.eating) { + if (!rubberbandTimer.tick(rubberbandTimeout.toLong(), false) || + AutoObsidian.isActive() || + AutoEat.eating) { return@safeListener } @@ -439,7 +437,7 @@ internal object HighwayTools : Module( val eyePos = player.getPositionEyes(1f) blueprint.keys.removeIf { - eyePos.distanceTo(it) > maxReach - 0.7 + eyePos.distanceTo(it) > maxReach - 0.3 } } @@ -619,7 +617,7 @@ internal object HighwayTools : Module( } ) - // ToDo: We need a function that makes a score out of all parameters + // ToDo: We need a function that makes a score out of last 3 parameters } private fun SafeClientEvent.checkStuckTimeout(blockTask: BlockTask): Boolean { @@ -637,6 +635,9 @@ internal object HighwayTools : Module( if (debugMessages != DebugMessages.OFF) { MessageSendHelper.sendChatMessage("Stuck while ${blockTask.taskState}@(${blockTask.blockPos.asString()}) for more then $timeout ticks (${blockTask.stuckTicks}), refreshing data.") } + + if (dynamicDelay && blockTask.taskState == TaskState.PLACE && extraPlaceDelay < 10) extraPlaceDelay += 1 + refreshData() return false } @@ -739,12 +740,15 @@ internal object HighwayTools : Module( when { blockTask.block == currentBlock && currentBlock != Blocks.AIR -> { + totalBlocksPlaced++ + + if (dynamicDelay && extraPlaceDelay > 0) extraPlaceDelay -= 1 + blockTask.updateState(TaskState.DONE) if (fakeSounds) { val soundType = currentBlock.getSoundType(world.getBlockState(blockTask.blockPos), world, blockTask.blockPos, player) world.playSound(player, blockTask.blockPos, soundType.placeSound, SoundCategory.BLOCKS, (soundType.getVolume() + 1.0f) / 2.0f, soundType.getPitch() * 0.8f) } - totalBlocksPlaced++ } blockTask.block == currentBlock && currentBlock == Blocks.AIR -> { blockTask.updateState(TaskState.BREAK) @@ -760,7 +764,7 @@ internal object HighwayTools : Module( private fun SafeClientEvent.doBreak(blockTask: BlockTask, updateOnly: Boolean) { // ignore blocks - if (blockTask.block != Blocks.AIR && ignoreBlocks.contains(blockTask.block)) { + if (ignoreBlocks.contains(world.getBlockState(blockTask.blockPos).block)) { blockTask.updateState(TaskState.DONE) } @@ -879,7 +883,7 @@ internal object HighwayTools : Module( val hitVecOffset = WorldUtils.getHitVecOffset(pair.first) val currentBlock = world.getBlockState(pair.second).block - waitTicks = placeDelay + waitTicks = placeDelay + extraPlaceDelay blockTask.updateState(TaskState.PENDING_PLACED) if (currentBlock in blackList) { @@ -904,6 +908,7 @@ internal object HighwayTools : Module( delay(50L * taskTimeout) if (blockTask.taskState == TaskState.PENDING_PLACED) { blockTask.updateState(TaskState.PLACE) + if (dynamicDelay && extraPlaceDelay < 10) extraPlaceDelay += 1 } } } @@ -1148,6 +1153,7 @@ internal object HighwayTools : Module( " §7Blocks placed: §9$totalBlocksPlaced".padStart(6, '0'), " §7Material: §9${material.localizedName}", " §7Filler: §9${fillerMat.localizedName}", + " §7Delays: §9Place(${placeDelay + extraPlaceDelay}) Break($breakDelay)", "§rTask", " §7Status: §9${currentTask?.taskState}", " §7Target state: §9${currentTask?.block?.localizedName}", @@ -1181,7 +1187,7 @@ internal object HighwayTools : Module( } private fun addTaskToMessageList(list: ArrayList, tasks: Collection) { - for (blockTask in tasks) list.add(" ${blockTask.block.localizedName}@(${blockTask.blockPos.asString()}) State: ${blockTask.taskState} Timings: (Threshold: ${blockTask.taskState.stuckThreshold}, Timeout: ${blockTask.taskState.stuckTimeout}) Priority: ${blockTask.taskState.ordinal} Stuck: ${blockTask.stuckTicks}") + for (blockTask in tasks) list.add(" ${blockTask.block.localizedName}@(${blockTask.blockPos.asString()}) State: ${blockTask.taskState} Timings: (Threshold: ${blockTask.taskState.stuckThreshold} Timeout: ${blockTask.taskState.stuckTimeout}) Priority: ${blockTask.taskState.ordinal} Stuck: ${blockTask.stuckTicks}") } class BlockTask( @@ -1237,8 +1243,8 @@ internal object HighwayTools : Module( DONE(69420, 0x22, ColorHolder(50, 50, 50)), BROKEN(1000, 1000, ColorHolder(111, 0, 0)), PLACED(1000, 1000, ColorHolder(53, 222, 66)), - LIQUID_SOURCE(100, 100, ColorHolder(120, 41, 240)), - LIQUID_FLOW(80, 80, ColorHolder(120, 41, 240)), + LIQUID_SOURCE(100, 100, ColorHolder(114, 27, 255)), + LIQUID_FLOW(100, 100, ColorHolder(68, 27, 255)), BREAKING(100, 100, ColorHolder(240, 222, 60)), BREAK(20, 20, ColorHolder(222, 0, 0)), PLACE(20, 20, ColorHolder(35, 188, 254)), From a5708e4881ab129aad16ab96a498072231880477 Mon Sep 17 00:00:00 2001 From: Christian Date: Sat, 30 Jan 2021 21:39:31 +0100 Subject: [PATCH 277/390] Cleanup --- .../kami/module/modules/misc/HighwayTools.kt | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index f3399f2858..614b9235e5 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -273,12 +273,12 @@ internal object HighwayTools : Module( val task = pendingTasks[pos] ?: return@safeListener when (task.taskState) { - TaskState.PENDING_BROKEN, TaskState.BREAKING -> { + TaskState.PENDING_BREAK, TaskState.BREAKING -> { if (new == Blocks.AIR) { task.updateState(TaskState.BROKEN) } } - TaskState.PENDING_PLACED -> { + TaskState.PENDING_PLACE -> { if (task.block != Blocks.AIR && task.block == new) { task.updateState(TaskState.PLACED) } @@ -625,10 +625,10 @@ internal object HighwayTools : Module( if (blockTask.stuckTicks > timeout) { when (blockTask.taskState) { - TaskState.PENDING_BROKEN -> { + TaskState.PENDING_BREAK -> { blockTask.updateState(TaskState.BREAK) } - TaskState.PENDING_PLACED -> { + TaskState.PENDING_PLACE -> { blockTask.updateState(TaskState.PLACE) } else -> { @@ -669,7 +669,7 @@ internal object HighwayTools : Module( TaskState.PLACE, TaskState.LIQUID_SOURCE, TaskState.LIQUID_FLOW -> { doPlace(blockTask, updateOnly) } - TaskState.PENDING_BROKEN, TaskState.PENDING_PLACED -> { + TaskState.PENDING_BREAK, TaskState.PENDING_PLACE -> { if (!updateOnly && debugMessages == DebugMessages.ALL) { MessageSendHelper.sendChatMessage("$chatName Currently waiting for blockState updates...") } @@ -884,7 +884,7 @@ internal object HighwayTools : Module( val currentBlock = world.getBlockState(pair.second).block waitTicks = placeDelay + extraPlaceDelay - blockTask.updateState(TaskState.PENDING_PLACED) + blockTask.updateState(TaskState.PENDING_PLACE) if (currentBlock in blackList) { connection.sendPacket(CPacketEntityAction(player, CPacketEntityAction.Action.START_SNEAKING)) @@ -906,7 +906,7 @@ internal object HighwayTools : Module( } delay(50L * taskTimeout) - if (blockTask.taskState == TaskState.PENDING_PLACED) { + if (blockTask.taskState == TaskState.PENDING_PLACE) { blockTask.updateState(TaskState.PLACE) if (dynamicDelay && extraPlaceDelay < 10) extraPlaceDelay += 1 } @@ -1019,7 +1019,7 @@ internal object HighwayTools : Module( private fun mineBlockInstant(blockTask: BlockTask, side: EnumFacing) { waitTicks = breakDelay - blockTask.updateState(TaskState.PENDING_BROKEN) + blockTask.updateState(TaskState.PENDING_BREAK) defaultScope.launch { delay(20L) @@ -1030,7 +1030,7 @@ internal object HighwayTools : Module( } delay(50L * taskTimeout) - if (blockTask.taskState == TaskState.PENDING_BROKEN) { + if (blockTask.taskState == TaskState.PENDING_BREAK) { blockTask.updateState(TaskState.BREAK) } } @@ -1057,7 +1057,7 @@ internal object HighwayTools : Module( sendMiningPackets(task.blockPos, rayTraceResult.sideHit) delay(50L * taskTimeout) - if (blockTask.taskState == TaskState.PENDING_BROKEN) { + if (blockTask.taskState == TaskState.PENDING_BREAK) { blockTask.updateState(TaskState.BREAK) } } @@ -1155,9 +1155,9 @@ internal object HighwayTools : Module( " §7Filler: §9${fillerMat.localizedName}", " §7Delays: §9Place(${placeDelay + extraPlaceDelay}) Break($breakDelay)", "§rTask", - " §7Status: §9${currentTask?.taskState}", - " §7Target state: §9${currentTask?.block?.localizedName}", - " §7Position: §9(${currentTask?.blockPos?.asString()})", + " §7Status: §9${currentTask?.taskState ?: "N/A"}", + " §7Target state: §9${currentTask?.block?.localizedName ?: "N/A"}", + " §7Position: §9(${currentTask?.blockPos?.asString() ?: "N/A"})", " §7Stuck ticks: §9${currentTask?.stuckTicks.toString()}", "§rEstimations", " §7${material.localizedName} (main material): §9$materialLeft + ($indirectMaterialLeft)", @@ -1248,8 +1248,8 @@ internal object HighwayTools : Module( BREAKING(100, 100, ColorHolder(240, 222, 60)), BREAK(20, 20, ColorHolder(222, 0, 0)), PLACE(20, 20, ColorHolder(35, 188, 254)), - PENDING_BROKEN(100, 100, ColorHolder(0, 0, 0)), - PENDING_PLACED(100, 100, ColorHolder(0, 0, 0)) + PENDING_BREAK(100, 100, ColorHolder(0, 0, 0)), + PENDING_PLACE(100, 100, ColorHolder(0, 0, 0)) } } From 381d4c326eaa2b7a883a1f0da3dc10d57a474136 Mon Sep 17 00:00:00 2001 From: Christian Date: Mon, 1 Feb 2021 01:02:34 +0100 Subject: [PATCH 278/390] Nicer hud --- .../hudgui/elements/misc/HighwayToolsHud.kt | 5 +- .../kami/module/modules/misc/AutoObsidian.kt | 2 +- .../kami/module/modules/misc/HighwayTools.kt | 178 +++++++++++------- 3 files changed, 115 insertions(+), 70 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/gui/hudgui/elements/misc/HighwayToolsHud.kt b/src/main/java/me/zeroeightsix/kami/gui/hudgui/elements/misc/HighwayToolsHud.kt index da5633a0db..f32d7ff14b 100644 --- a/src/main/java/me/zeroeightsix/kami/gui/hudgui/elements/misc/HighwayToolsHud.kt +++ b/src/main/java/me/zeroeightsix/kami/gui/hudgui/elements/misc/HighwayToolsHud.kt @@ -10,9 +10,6 @@ object HighwayToolsHud : LabelHud( description = "Hud for HighwayTools module" ) { override fun SafeClientEvent.updateText() { - val list = gatherStatistics() - for (line in list) { - displayText.addLine(line) - } + gatherStatistics(displayText) } } \ No newline at end of file diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt index de484daa37..53a1188e74 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/AutoObsidian.kt @@ -60,7 +60,7 @@ internal object AutoObsidian : Module( private val searchShulker by setting("SearchShulker", false) private val leaveEmptyShulkers by setting("LeaveEmptyShulkers", true, { searchShulker }) private val autoRefill by setting("AutoRefill", false, { fillMode != FillMode.INFINITE }) - private val threshold by setting("RefillThreshold", 8, 1..63, 1, { autoRefill && fillMode != FillMode.INFINITE }) + val threshold by setting("RefillThreshold", 32, 1..63, 1, { autoRefill && fillMode != FillMode.INFINITE }) private val targetStacks by setting("TargetStacks", 1, 1..20, 1, { fillMode == FillMode.TARGET_STACKS }) private val delayTicks by setting("DelayTicks", 5, 0..10, 1) private val rotationMode by setting("RotationMode", RotationMode.SPOOF) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 614b9235e5..dbb1388af0 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -9,6 +9,8 @@ import me.zeroeightsix.kami.event.events.RenderWorldEvent import me.zeroeightsix.kami.manager.managers.PlayerPacketManager import me.zeroeightsix.kami.module.Category import me.zeroeightsix.kami.module.Module +import me.zeroeightsix.kami.module.modules.client.Hud.primaryColor +import me.zeroeightsix.kami.module.modules.client.Hud.secondaryColor import me.zeroeightsix.kami.module.modules.player.AutoEat import me.zeroeightsix.kami.module.modules.player.InventoryManager import me.zeroeightsix.kami.process.HighwayToolsProcess @@ -20,6 +22,7 @@ import me.zeroeightsix.kami.util.WorldUtils.getNeighbour import me.zeroeightsix.kami.util.WorldUtils.isPlaceable import me.zeroeightsix.kami.util.color.ColorHolder import me.zeroeightsix.kami.util.graphics.* +import me.zeroeightsix.kami.util.graphics.font.TextComponent import me.zeroeightsix.kami.util.items.* import me.zeroeightsix.kami.util.math.* import me.zeroeightsix.kami.util.math.CoordinateConverter.asString @@ -35,12 +38,14 @@ import net.minecraft.enchantment.EnchantmentHelper import net.minecraft.init.Blocks import net.minecraft.init.Enchantments import net.minecraft.init.SoundEvents +import net.minecraft.inventory.Slot import net.minecraft.item.ItemBlock import net.minecraft.network.play.client.CPacketEntityAction import net.minecraft.network.play.client.CPacketPlayerDigging import net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock import net.minecraft.network.play.server.SPacketBlockChange import net.minecraft.network.play.server.SPacketPlayerPosLook +import net.minecraft.network.play.server.SPacketSetSlot import net.minecraft.util.EnumFacing import net.minecraft.util.EnumHand import net.minecraft.util.SoundCategory @@ -88,6 +93,13 @@ internal object HighwayTools : Module( private val rubberbandTimeout by setting("Rubberband Timeout", 50, 5..100, 5, { page == Page.BEHAVIOR }) private val maxReach by setting("MaxReach", 4.9f, 1.0f..6.0f, 0.1f, { page == Page.BEHAVIOR }) + // stats + private val anonymizeStats by setting("Anonymize", false, { page == Page.STATS }) + private val showPerformance by setting("Show Performance", true, { page == Page.STATS }) + private val showEnvironment by setting("Show Environment", true, { page == Page.STATS }) + private val showTask by setting("Show Task", true, { page == Page.STATS }) + private val showEstimations by setting("Show Estimations", true, { page == Page.STATS }) + // config private val fakeSounds by setting("Fake Sounds", true, { page == Page.CONFIG }) private val info by setting("Show Info", true, { page == Page.CONFIG }) @@ -104,7 +116,7 @@ internal object HighwayTools : Module( } private enum class Page { - BUILD, BEHAVIOR, CONFIG + BUILD, BEHAVIOR, STATS, CONFIG } @Suppress("UNUSED") @@ -165,7 +177,7 @@ internal object HighwayTools : Module( private var foodLoss = 1 private var materialLeft = 0 private var fillerMatLeft = 0 - private var lastDurability = 0 + private var lastToolDamage = 0 private var durabilityUsages = 0 private val renderer = ESPRenderer() @@ -235,18 +247,20 @@ internal object HighwayTools : Module( if (info) { MessageSendHelper.sendRawChatMessage(" §9> §7Direction: §a${startingDirection.displayName}§r") - if (startingDirection.isDiagonal) { - MessageSendHelper.sendRawChatMessage(" §9> §7Coordinates: §a${startingBlockPos.x} ${startingBlockPos.z}§r") - } else { - if (startingDirection == Direction.NORTH || startingDirection == Direction.SOUTH) { - MessageSendHelper.sendRawChatMessage(" §9> §7Coordinate: §a${startingBlockPos.x}§r") + if (!anonymizeStats) { + if (startingDirection.isDiagonal) { + MessageSendHelper.sendRawChatMessage(" §9> §7Coordinates: §a${startingBlockPos.x} ${startingBlockPos.z}§r") } else { - MessageSendHelper.sendRawChatMessage(" §9> §7Coordinate: §a${startingBlockPos.z}§r") + if (startingDirection == Direction.NORTH || startingDirection == Direction.SOUTH) { + MessageSendHelper.sendRawChatMessage(" §9> §7Coordinate: §a${startingBlockPos.x}§r") + } else { + MessageSendHelper.sendRawChatMessage(" §9> §7Coordinate: §a${startingBlockPos.z}§r") + } } } - if (startingBlockPos.y in 117..119 && mode != Mode.TUNNEL) { - MessageSendHelper.sendRawChatMessage(" §9> §cCheck coordinate Y / altitude and make sure to move around Y 120 for the correct height") + if (startingBlockPos.y != 120 && mode != Mode.TUNNEL) { + MessageSendHelper.sendRawChatMessage(" §9> §cCheck altitude and make sure to build at Y 120 for the correct height") } } } @@ -292,6 +306,13 @@ internal object HighwayTools : Module( is SPacketPlayerPosLook -> { rubberbandTimer.reset() } + is SPacketSetSlot -> { + val currentToolDamage = it.packet.stack.itemDamage + if (lastToolDamage < currentToolDamage) { + durabilityUsages += currentToolDamage - lastToolDamage + lastToolDamage = it.packet.stack.itemDamage + } + } } } @@ -633,7 +654,11 @@ internal object HighwayTools : Module( } else -> { if (debugMessages != DebugMessages.OFF) { - MessageSendHelper.sendChatMessage("Stuck while ${blockTask.taskState}@(${blockTask.blockPos.asString()}) for more then $timeout ticks (${blockTask.stuckTicks}), refreshing data.") + if (!anonymizeStats) { + MessageSendHelper.sendChatMessage("Stuck while ${blockTask.taskState}@(${blockTask.blockPos.asString()}) for more then $timeout ticks (${blockTask.stuckTicks}), refreshing data.") + } else { + MessageSendHelper.sendChatMessage("Stuck while ${blockTask.taskState} for more then $timeout ticks (${blockTask.stuckTicks}), refreshing data.") + } } if (dynamicDelay && blockTask.taskState == TaskState.PLACE && extraPlaceDelay < 10) extraPlaceDelay += 1 @@ -864,7 +889,11 @@ internal object HighwayTools : Module( ?: run { if (illegalPlacements) { if (debugMessages == DebugMessages.ALL) { - MessageSendHelper.sendChatMessage("Trying to place through wall ${blockTask.blockPos}") + if (!anonymizeStats) { + MessageSendHelper.sendChatMessage("Trying to place through wall ${blockTask.blockPos}") + } else { + MessageSendHelper.sendChatMessage("Trying to place through wall") + } } getNeighbour(blockTask.blockPos, 1, maxReach) ?: return } else { @@ -913,8 +942,8 @@ internal object HighwayTools : Module( } } - private fun SafeClientEvent.swapOrMoveBestTool(blockTask: BlockTask): Boolean { - val slotFrom = player.inventorySlots.asReversed().maxByOrNull { + private fun SafeClientEvent.getBestTool(blockTask: BlockTask): Slot? { + return player.inventorySlots.asReversed().maxByOrNull { val stack = it.stack if (stack.isEmpty) { 0.0f @@ -931,6 +960,10 @@ internal object HighwayTools : Module( speed } } + } + + private fun SafeClientEvent.swapOrMoveBestTool(blockTask: BlockTask): Boolean { + val slotFrom = getBestTool(blockTask) return if (slotFrom != null) { slotFrom.toHotbarSlotOrNull()?.let { @@ -1106,7 +1139,7 @@ internal object HighwayTools : Module( } } - fun SafeClientEvent.gatherStatistics(): List { + fun SafeClientEvent.gatherStatistics(displayText: TextComponent) { val currentTask = if (sortedTasks.isNotEmpty()) { sortedTasks[0] } else { @@ -1122,72 +1155,87 @@ internal object HighwayTools : Module( val pavingLeft = materialLeft / ((totalBlocksPlaced + 0.001) / (distanceDone + 0.001)) // ToDo: Cache shulker count - val pavingLeftAll = (materialLeft + indirectMaterialLeft) / ((totalBlocksPlaced + 0.001) / (distanceDone + 0.001)) +// val pavingLeftAll = (materialLeft + indirectMaterialLeft) / ((totalBlocksPlaced + 0.001) / (distanceDone + 0.001)) val runtimeSec = (runtimeMilliSeconds / 1000) + 0.0001 val seconds = (runtimeSec % 60).toInt().toString().padStart(2, '0') val minutes = ((runtimeSec % 3600) / 60).toInt().toString().padStart(2, '0') val hours = (runtimeSec / 3600).toInt().toString().padStart(2, '0') - val secLeftRefillInv = pavingLeft / (startingBlockPos.distanceTo(currentBlockPos).toInt() / runtimeSec) + val secLeftRefillInv = (pavingLeft - AutoObsidian.threshold) / (startingBlockPos.distanceTo(currentBlockPos).toInt() / runtimeSec) val secondsLeftRefillInv = (secLeftRefillInv % 60).toInt().toString().padStart(2, '0') val minutesLeftRefillInv = ((secLeftRefillInv % 3600) / 60).toInt().toString().padStart(2, '0') val hoursLeftRefillInv = (secLeftRefillInv / 3600).toInt().toString().padStart(2, '0') - val secLeftRefillShulker = pavingLeftAll / (startingBlockPos.distanceTo(currentBlockPos).toInt() / runtimeSec) - val secondsLeftRefillShulker = (secLeftRefillShulker % 60).toInt().toString().padStart(2, '0') - val minutesLeftRefillShulker = ((secLeftRefillShulker % 3600) / 60).toInt().toString().padStart(2, '0') - val hoursLeftRefillShulker = (secLeftRefillShulker / 3600).toInt().toString().padStart(2, '0') - - val statistics = mutableListOf( - "§rPerformance", - " §7Runtime: §9$hours:$minutes:$seconds", - " §7Placements per second: §9%.2f".format(totalBlocksPlaced / runtimeSec), - " §7Breaks per second: §9%.2f".format(totalBlocksDestroyed / runtimeSec), - " §7Distance per hour: §9%.2f".format((startingBlockPos.distanceTo(currentBlockPos).toInt() / runtimeSec) * 60 * 60), - " §7One food loss per §9${totalBlocksDestroyed / foodLoss}§7 blocks mined", - "§rEnvironment", - " §7Starting coordinates: §9(${startingBlockPos.asString()})", - " §7Direction: §9${startingDirection.displayName}", - " §7Blocks destroyed: §9$totalBlocksDestroyed".padStart(6, '0'), - " §7Blocks placed: §9$totalBlocksPlaced".padStart(6, '0'), - " §7Material: §9${material.localizedName}", - " §7Filler: §9${fillerMat.localizedName}", - " §7Delays: §9Place(${placeDelay + extraPlaceDelay}) Break($breakDelay)", - "§rTask", - " §7Status: §9${currentTask?.taskState ?: "N/A"}", - " §7Target state: §9${currentTask?.block?.localizedName ?: "N/A"}", - " §7Position: §9(${currentTask?.blockPos?.asString() ?: "N/A"})", - " §7Stuck ticks: §9${currentTask?.stuckTicks.toString()}", - "§rEstimations", - " §7${material.localizedName} (main material): §9$materialLeft + ($indirectMaterialLeft)", - " §7${fillerMat.localizedName} (filler material): §9$fillerMatLeft", - " §7Paving distance left: §9${pavingLeftAll.toInt()}", - " §7Paving distance left till refill: §9${pavingLeft.toInt()}", - " §7Estimated refill position: §9(${currentBlockPos.add(startingDirection.directionVec.multiply(pavingLeft.toInt())).asString()})", - " §7Estimated destination: §9(${currentBlockPos.add(startingDirection.directionVec.multiply(pavingLeftAll.toInt())).asString()})", - " §7ETA for inventory refill: §9$hoursLeftRefillInv:$minutesLeftRefillInv:$secondsLeftRefillInv", - " §7ETA for shulker refill: §9$hoursLeftRefillShulker:$minutesLeftRefillShulker:$secondsLeftRefillShulker" - ) + if (showPerformance) { + displayText.addLine("Performance", primaryColor) + displayText.add(" Runtime:", primaryColor) + displayText.addLine("$hours:$minutes:$seconds", secondaryColor) + displayText.add(" Placements / s:", primaryColor) + displayText.addLine("%.2f".format(totalBlocksPlaced / runtimeSec), secondaryColor) + displayText.add(" Breaks / s:", primaryColor) + displayText.addLine("%.2f".format(totalBlocksDestroyed / runtimeSec), secondaryColor) + displayText.add(" Distance / h:", primaryColor) + displayText.addLine("%.2f".format(startingBlockPos.distanceTo(currentBlockPos).toInt() / runtimeSec * 60 * 60), secondaryColor) + displayText.add(" Food level loss / h:", primaryColor) + displayText.addLine("%.2f".format(totalBlocksDestroyed / foodLoss.toDouble()), secondaryColor) + displayText.add(" Pickaxes / h:", primaryColor) + displayText.addLine("%.2f".format((durabilityUsages / runtimeSec) * 60 * 60 / 1561), secondaryColor) + } - if (printDebug) { - statistics.addAll(getQueue()) + if (showEnvironment) { + displayText.addLine("Environment", primaryColor) + if (!anonymizeStats) displayText.add(" Starting coordinates:", primaryColor) + if (!anonymizeStats) displayText.addLine("(${startingBlockPos.asString()})", secondaryColor) + displayText.add(" Direction:", primaryColor) + displayText.addLine(startingDirection.displayName, secondaryColor) + displayText.add(" Blocks placed / destroyed:", primaryColor) + displayText.addLine("$totalBlocksDestroyed".padStart(6, '0') + " / $totalBlocksPlaced".padStart(6, '0'), secondaryColor) + displayText.add(" Materials:", primaryColor) + displayText.addLine("Main(${material.localizedName}) Filler(${fillerMat.localizedName})", secondaryColor) + displayText.add(" Delays:", primaryColor) + displayText.addLine("Place(${placeDelay + extraPlaceDelay}) Break($breakDelay)", secondaryColor) } - return statistics - } + if (showTask && currentTask != null) { + displayText.addLine("Task", primaryColor) + displayText.add(" Status:", primaryColor) + displayText.addLine("${currentTask.taskState}", secondaryColor) + displayText.add(" Target block:", primaryColor) + displayText.addLine(currentTask.block.localizedName, secondaryColor) + if (!anonymizeStats) displayText.add(" Position:", primaryColor) + if (!anonymizeStats) displayText.addLine(currentTask.blockPos.asString(), secondaryColor) + displayText.add(" Ticks stuck:", primaryColor) + displayText.addLine("${currentTask.stuckTicks}", secondaryColor) + } - private fun getQueue(): List { - val message = ArrayList() - message.add("Pending Tasks:") - addTaskToMessageList(message, sortedTasks) - message.add("Done Tasks:") - addTaskToMessageList(message, doneTasks.values) - return message + if (showEstimations && mode == Mode.HIGHWAY) { + displayText.addLine("Estimations", primaryColor) + displayText.add(" ${material.localizedName}:", primaryColor) + displayText.addLine("Direct($materialLeft) Indirect($indirectMaterialLeft)", secondaryColor) + displayText.add(" ${fillerMat.localizedName}:", primaryColor) + displayText.addLine("$fillerMatLeft", secondaryColor) + displayText.add(" Distance left:", primaryColor) + displayText.addLine("${pavingLeft.toInt()}", secondaryColor) + displayText.add(" Destination:", primaryColor) + displayText.addLine("(${currentBlockPos.add(startingDirection.directionVec.multiply(pavingLeft.toInt())).asString()})", secondaryColor) + displayText.add(" ETA:", primaryColor) + displayText.addLine("$hoursLeftRefillInv:$minutesLeftRefillInv:$secondsLeftRefillInv", secondaryColor) + } + +// MessageSendHelper.sendChatMessage(StatList.MINE_BLOCK_STATS.toString()) + + if (printDebug) { + displayText.addLine("Pending", primaryColor) + addTaskComponentList(displayText, sortedTasks) + + displayText.addLine("Done", primaryColor) + addTaskComponentList(displayText, doneTasks.values) + } } - private fun addTaskToMessageList(list: ArrayList, tasks: Collection) { - for (blockTask in tasks) list.add(" ${blockTask.block.localizedName}@(${blockTask.blockPos.asString()}) State: ${blockTask.taskState} Timings: (Threshold: ${blockTask.taskState.stuckThreshold} Timeout: ${blockTask.taskState.stuckTimeout}) Priority: ${blockTask.taskState.ordinal} Stuck: ${blockTask.stuckTicks}") + private fun addTaskComponentList(displayText: TextComponent, tasks: Collection) { + for (blockTask in tasks) displayText.add(" ${blockTask.block.localizedName}@(${blockTask.blockPos.asString()}) State: ${blockTask.taskState} Timings: (Threshold: ${blockTask.taskState.stuckThreshold} Timeout: ${blockTask.taskState.stuckTimeout}) Priority: ${blockTask.taskState.ordinal} Stuck: ${blockTask.stuckTicks}") } class BlockTask( From 16b087c08010df91d12548a12575dadc119c5181 Mon Sep 17 00:00:00 2001 From: Christian Date: Mon, 1 Feb 2021 01:08:55 +0100 Subject: [PATCH 279/390] Forgot those --- .../kami/module/modules/misc/HighwayTools.kt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index dbb1388af0..58c349f15e 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -855,7 +855,13 @@ internal object HighwayTools : Module( if (!updateOnly) { if (!isPlaceable(blockTask.blockPos)) { - if (debugMessages != DebugMessages.OFF) MessageSendHelper.sendChatMessage("Invalid place position: ${blockTask.blockPos}. Removing task") + if (debugMessages != DebugMessages.OFF) { + if (!anonymizeStats) { + MessageSendHelper.sendChatMessage("Invalid place position: ${blockTask.blockPos}. Removing task") + } else { + MessageSendHelper.sendChatMessage("Invalid place position. Removing task") + } + } pendingTasks.remove(blockTask.blockPos) return } @@ -1190,7 +1196,7 @@ internal object HighwayTools : Module( displayText.add(" Direction:", primaryColor) displayText.addLine(startingDirection.displayName, secondaryColor) displayText.add(" Blocks placed / destroyed:", primaryColor) - displayText.addLine("$totalBlocksDestroyed".padStart(6, '0') + " / $totalBlocksPlaced".padStart(6, '0'), secondaryColor) + displayText.addLine("$totalBlocksDestroyed".padStart(6, '0') + " / " + "$totalBlocksPlaced".padStart(6, '0'), secondaryColor) displayText.add(" Materials:", primaryColor) displayText.addLine("Main(${material.localizedName}) Filler(${fillerMat.localizedName})", secondaryColor) displayText.add(" Delays:", primaryColor) From 38d52476c6ae15556757ed0c7c869f7e1c366cca Mon Sep 17 00:00:00 2001 From: Christian Date: Mon, 1 Feb 2021 16:03:03 +0100 Subject: [PATCH 280/390] Fixes and setting safe --- .../kami/module/modules/misc/HighwayTools.kt | 46 ++++++++++--------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 58c349f15e..b67efa5e52 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -14,6 +14,7 @@ import me.zeroeightsix.kami.module.modules.client.Hud.secondaryColor import me.zeroeightsix.kami.module.modules.player.AutoEat import me.zeroeightsix.kami.module.modules.player.InventoryManager import me.zeroeightsix.kami.process.HighwayToolsProcess +import me.zeroeightsix.kami.setting.settings.impl.collection.CollectionSetting import me.zeroeightsix.kami.util.* import me.zeroeightsix.kami.util.EntityUtils.flooredPosition import me.zeroeightsix.kami.util.WorldUtils.blackList @@ -67,11 +68,23 @@ internal object HighwayTools : Module( name = "HighwayTools", description = "Be the grief a step a head.", category = Category.MISC, + alias = arrayOf("HT", "HWT"), modulePriority = 10 ) { private val mode by setting("Mode", Mode.HIGHWAY) private val page by setting("Page", Page.BUILD) + val defaultIgnoreList = hashSetOf( + Blocks.STANDING_SIGN, + Blocks.WALL_SIGN, + Blocks.STANDING_BANNER, + Blocks.WALL_BANNER, + Blocks.BEDROCK, + Blocks.END_PORTAL, + Blocks.END_PORTAL_FRAME, + Blocks.PORTAL + ) + // build settings private val clearSpace by setting("Clear Space", true, { page == Page.BUILD && mode == Mode.HIGHWAY }) private val width by setting("Width", 6, 1..9, 1, { page == Page.BUILD }) @@ -99,6 +112,7 @@ internal object HighwayTools : Module( private val showEnvironment by setting("Show Environment", true, { page == Page.STATS }) private val showTask by setting("Show Task", true, { page == Page.STATS }) private val showEstimations by setting("Show Estimations", true, { page == Page.STATS }) + val ignoreBlocks = setting(CollectionSetting("IgnoreList", defaultIgnoreList, { false })) // config private val fakeSounds by setting("Fake Sounds", true, { page == Page.CONFIG }) @@ -129,16 +143,6 @@ internal object HighwayTools : Module( } // internal settings - val ignoreBlocks = hashSetOf( - Blocks.STANDING_SIGN, - Blocks.WALL_SIGN, - Blocks.STANDING_BANNER, - Blocks.WALL_BANNER, - Blocks.BEDROCK, - Blocks.END_PORTAL, - Blocks.END_PORTAL_FRAME, - Blocks.PORTAL - ) var material: Block = Blocks.OBSIDIAN var fillerMat: Block = Blocks.NETHERRACK private var baritoneSettingAllowPlace = false @@ -203,9 +207,6 @@ internal object HighwayTools : Module( currentBlockPos = startingBlockPos startingDirection = Direction.fromEntity(Companion.mc.player) - totalBlocksPlaced = 0 - totalBlocksDestroyed = 0 - baritoneSettingAllowPlace = BaritoneUtils.settings?.allowPlace?.value ?: true BaritoneUtils.settings?.allowPlace?.value = false @@ -329,7 +330,8 @@ internal object HighwayTools : Module( if (!rubberbandTimer.tick(rubberbandTimeout.toLong(), false) || AutoObsidian.isActive() || AutoEat.eating) { - return@safeListener + refreshData() + return@safeListener } if (!active) { @@ -1135,11 +1137,11 @@ internal object HighwayTools : Module( fun printSettings() { StringBuilder(ignoreBlocks.size + 1).run { append("$chatName Settings" + - "\n §9> §rMain material: §7${material.localizedName}" + - "\n §9> §rFiller material: §7${fillerMat.localizedName}" + - "\n §9> §rIgnored Blocks:") + "\n §9> §rMain material: §7${material.localizedName}" + + "\n §9> §rFiller material: §7${fillerMat.localizedName}" + + "\n §9> §rIgnored Blocks:") - for (b in ignoreBlocks) append("\n §9> §7${b.registryName}") + for (b in ignoreBlocks) append("\n §9> §7${b.registryName}") MessageSendHelper.sendChatMessage(toString()) } @@ -1191,7 +1193,7 @@ internal object HighwayTools : Module( if (showEnvironment) { displayText.addLine("Environment", primaryColor) - if (!anonymizeStats) displayText.add(" Starting coordinates:", primaryColor) + if (!anonymizeStats) displayText.add(" Start:", primaryColor) if (!anonymizeStats) displayText.addLine("(${startingBlockPos.asString()})", secondaryColor) displayText.add(" Direction:", primaryColor) displayText.addLine(startingDirection.displayName, secondaryColor) @@ -1210,13 +1212,13 @@ internal object HighwayTools : Module( displayText.add(" Target block:", primaryColor) displayText.addLine(currentTask.block.localizedName, secondaryColor) if (!anonymizeStats) displayText.add(" Position:", primaryColor) - if (!anonymizeStats) displayText.addLine(currentTask.blockPos.asString(), secondaryColor) + if (!anonymizeStats) displayText.addLine("(${currentTask.blockPos.asString()})", secondaryColor) displayText.add(" Ticks stuck:", primaryColor) displayText.addLine("${currentTask.stuckTicks}", secondaryColor) } if (showEstimations && mode == Mode.HIGHWAY) { - displayText.addLine("Estimations", primaryColor) + displayText.addLine("Next refill", primaryColor) displayText.add(" ${material.localizedName}:", primaryColor) displayText.addLine("Direct($materialLeft) Indirect($indirectMaterialLeft)", secondaryColor) displayText.add(" ${fillerMat.localizedName}:", primaryColor) @@ -1241,7 +1243,7 @@ internal object HighwayTools : Module( } private fun addTaskComponentList(displayText: TextComponent, tasks: Collection) { - for (blockTask in tasks) displayText.add(" ${blockTask.block.localizedName}@(${blockTask.blockPos.asString()}) State: ${blockTask.taskState} Timings: (Threshold: ${blockTask.taskState.stuckThreshold} Timeout: ${blockTask.taskState.stuckTimeout}) Priority: ${blockTask.taskState.ordinal} Stuck: ${blockTask.stuckTicks}") + for (blockTask in tasks) displayText.addLine(" ${blockTask.block.localizedName}@(${blockTask.blockPos.asString()}) State: ${blockTask.taskState} Timings: (Threshold: ${blockTask.taskState.stuckThreshold} Timeout: ${blockTask.taskState.stuckTimeout}) Priority: ${blockTask.taskState.ordinal} Stuck: ${blockTask.stuckTicks}") } class BlockTask( From aff99c291a812d166506cc68e882618ff36e61ff Mon Sep 17 00:00:00 2001 From: Christian Date: Mon, 1 Feb 2021 18:56:12 +0100 Subject: [PATCH 281/390] Multi building and rolling average --- .../kami/module/modules/misc/HighwayTools.kt | 94 +++++++++++++------ 1 file changed, 67 insertions(+), 27 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index b67efa5e52..6279beb92f 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -14,7 +14,6 @@ import me.zeroeightsix.kami.module.modules.client.Hud.secondaryColor import me.zeroeightsix.kami.module.modules.player.AutoEat import me.zeroeightsix.kami.module.modules.player.InventoryManager import me.zeroeightsix.kami.process.HighwayToolsProcess -import me.zeroeightsix.kami.setting.settings.impl.collection.CollectionSetting import me.zeroeightsix.kami.util.* import me.zeroeightsix.kami.util.EntityUtils.flooredPosition import me.zeroeightsix.kami.util.WorldUtils.blackList @@ -59,6 +58,7 @@ import org.kamiblue.commons.extension.floorToInt import java.util.* import kotlin.collections.ArrayList import kotlin.collections.LinkedHashMap +import kotlin.random.Random.Default.nextInt /** * @author Avanatiker @@ -74,7 +74,7 @@ internal object HighwayTools : Module( private val mode by setting("Mode", Mode.HIGHWAY) private val page by setting("Page", Page.BUILD) - val defaultIgnoreList = hashSetOf( + val ignoreBlocks = hashSetOf( Blocks.STANDING_SIGN, Blocks.WALL_SIGN, Blocks.STANDING_BANNER, @@ -99,6 +99,7 @@ internal object HighwayTools : Module( private var placeDelay by setting("Place Delay", 3, 1..20, 1, { page == Page.BEHAVIOR }) private var breakDelay by setting("Break Delay", 1, 1..20, 1, { page == Page.BEHAVIOR }) private val illegalPlacements by setting("Illegal Placements", false, { page == Page.BEHAVIOR }) + private val multiBuilding by setting("Multi Builder", false, { page == Page.BEHAVIOR }) private val maxBreaks by setting("Multi Break", 3, 1..8, 1, { page == Page.BEHAVIOR }) private val toggleInventoryManager by setting("Toggle InvManager", true, { page == Page.BEHAVIOR }) private val toggleAutoObsidian by setting("Toggle AutoObsidian", true, { page == Page.BEHAVIOR }) @@ -112,7 +113,7 @@ internal object HighwayTools : Module( private val showEnvironment by setting("Show Environment", true, { page == Page.STATS }) private val showTask by setting("Show Task", true, { page == Page.STATS }) private val showEstimations by setting("Show Estimations", true, { page == Page.STATS }) - val ignoreBlocks = setting(CollectionSetting("IgnoreList", defaultIgnoreList, { false })) +// val ignoreBlocks = setting(CollectionSetting("IgnoreList", defaultIgnoreList, { false })) // config private val fakeSounds by setting("Fake Sounds", true, { page == Page.CONFIG }) @@ -174,8 +175,11 @@ internal object HighwayTools : Module( var lastTask: BlockTask? = null; private set // Stats + private val rollingAveragePlaces = ArrayDeque() + private val rollingAverageBreaks = ArrayDeque() private var totalBlocksPlaced = 0 - private var totalBlocksDestroyed = 0 + private var totalBlocksBroken = 0 + private var totalDistance = 0.0 private var runtimeMilliSeconds = 0 private var prevFood = 0 private var foodLoss = 1 @@ -238,6 +242,7 @@ internal object HighwayTools : Module( active = false goal = null lastTask = null + totalDistance += startingBlockPos.distanceTo(currentBlockPos) printDisable() } @@ -269,7 +274,7 @@ internal object HighwayTools : Module( private fun printDisable() { if (info) { MessageSendHelper.sendRawChatMessage(" §9> §7Placed blocks: §a$totalBlocksPlaced§r") - MessageSendHelper.sendRawChatMessage(" §9> §7Destroyed blocks: §a$totalBlocksDestroyed§r") + MessageSendHelper.sendRawChatMessage(" §9> §7Destroyed blocks: §a$totalBlocksBroken§r") MessageSendHelper.sendRawChatMessage(" §9> §7Distance: §a${startingBlockPos.distanceTo(currentBlockPos).toInt()}§r") } } @@ -309,7 +314,7 @@ internal object HighwayTools : Module( } is SPacketSetSlot -> { val currentToolDamage = it.packet.stack.itemDamage - if (lastToolDamage < currentToolDamage) { + if (lastToolDamage < currentToolDamage && currentToolDamage - lastToolDamage < 100) { durabilityUsages += currentToolDamage - lastToolDamage lastToolDamage = it.packet.stack.itemDamage } @@ -339,6 +344,9 @@ internal object HighwayTools : Module( BaritoneUtils.primary?.pathingControlManager?.registerProcess(HighwayToolsProcess) } else { runtimeMilliSeconds += 50 + while (rollingAveragePlaces.isNotEmpty() && System.currentTimeMillis() - rollingAveragePlaces.first() > 60000L) { + rollingAveragePlaces.removeFirst() + } } doPathing() @@ -445,8 +453,16 @@ internal object HighwayTools : Module( if (mode != Mode.TUNNEL) generateBase(thisPos, xDirection) } if (mode == Mode.TUNNEL) { - for (x in 1..maxReach.floorToInt()) { - blueprint[basePos.add(zDirection.directionVec.multiply(x))] = fillerMat + if (startingDirection.isDiagonal) { + for (x in 1..maxReach.floorToInt()) { + blueprint[basePos.add(zDirection.directionVec.multiply(x))] = fillerMat + } + } else { + for (x in 1..maxReach.floorToInt()) { + val pos = basePos.add(zDirection.directionVec.multiply(x)) + blueprint[pos] = fillerMat + blueprint[pos.add(startingDirection.clockwise(4).directionVec)] = fillerMat + } } } @@ -626,21 +642,35 @@ internal object HighwayTools : Module( private fun SafeClientEvent.sortTasks() { val eyePos = mc.player.getPositionEyes(1.0f) - sortedTasks = pendingTasks.values.sortedWith( - compareBy { - it.taskState.ordinal - }.thenBy { - it.stuckTicks / 5 - }.thenBy { - startingBlockPos.distanceTo(it.blockPos).toInt() / 2 - }.thenBy { - eyePos.distanceTo(it.blockPos) - }.thenBy { - lastHitVec?.distanceTo(it.blockPos) - } - ) + if (multiBuilding) { + sortedTasks = pendingTasks.values.sortedWith( + compareBy { + it.taskState.ordinal + }.thenBy { + it.stuckTicks / 5 + }.thenBy { + nextInt() + } + ) + } else { + sortedTasks = pendingTasks.values.sortedWith( + compareBy { + it.taskState.ordinal + }.thenBy { + it.stuckTicks / 5 + }.thenBy { + startingBlockPos.distanceTo(it.blockPos).toInt() / 2 + }.thenBy { + eyePos.distanceTo(it.blockPos) + }.thenBy { + lastHitVec?.distanceTo(it.blockPos) + } + ) + } + // ToDo: We need a function that makes a score out of last 3 parameters + nextInt() } private fun SafeClientEvent.checkStuckTimeout(blockTask: BlockTask): Boolean { @@ -744,7 +774,8 @@ internal object HighwayTools : Module( private fun SafeClientEvent.doBroken(blockTask: BlockTask) { when (world.getBlockState(blockTask.blockPos).block) { Blocks.AIR -> { - totalBlocksDestroyed++ + totalBlocksBroken++ + rollingAverageBreaks.add(System.currentTimeMillis()) if (blockTask.block == Blocks.AIR) { if (fakeSounds) { @@ -768,6 +799,7 @@ internal object HighwayTools : Module( when { blockTask.block == currentBlock && currentBlock != Blocks.AIR -> { totalBlocksPlaced++ + rollingAveragePlaces.add(System.currentTimeMillis()) if (dynamicDelay && extraPlaceDelay > 0) extraPlaceDelay -= 1 @@ -1179,14 +1211,20 @@ internal object HighwayTools : Module( displayText.addLine("Performance", primaryColor) displayText.add(" Runtime:", primaryColor) displayText.addLine("$hours:$minutes:$seconds", secondaryColor) - displayText.add(" Placements / s:", primaryColor) + displayText.addLine(" Placements / s:", primaryColor) + displayText.add(" Continuous:", primaryColor) displayText.addLine("%.2f".format(totalBlocksPlaced / runtimeSec), secondaryColor) - displayText.add(" Breaks / s:", primaryColor) - displayText.addLine("%.2f".format(totalBlocksDestroyed / runtimeSec), secondaryColor) + displayText.add(" Rolling average:", primaryColor) + displayText.addLine("%.2f".format(rollingAveragePlaces.size / 60.0), secondaryColor) + displayText.addLine(" Breaks / s:", primaryColor) + displayText.add(" Continuous:", primaryColor) + displayText.addLine("%.2f".format(totalBlocksBroken / runtimeSec), secondaryColor) + displayText.add(" Rolling average:", primaryColor) + displayText.addLine("%.2f".format(rollingAverageBreaks.size / 60.0), secondaryColor) displayText.add(" Distance / h:", primaryColor) displayText.addLine("%.2f".format(startingBlockPos.distanceTo(currentBlockPos).toInt() / runtimeSec * 60 * 60), secondaryColor) displayText.add(" Food level loss / h:", primaryColor) - displayText.addLine("%.2f".format(totalBlocksDestroyed / foodLoss.toDouble()), secondaryColor) + displayText.addLine("%.2f".format(totalBlocksBroken / foodLoss.toDouble()), secondaryColor) displayText.add(" Pickaxes / h:", primaryColor) displayText.addLine("%.2f".format((durabilityUsages / runtimeSec) * 60 * 60 / 1561), secondaryColor) } @@ -1198,7 +1236,7 @@ internal object HighwayTools : Module( displayText.add(" Direction:", primaryColor) displayText.addLine(startingDirection.displayName, secondaryColor) displayText.add(" Blocks placed / destroyed:", primaryColor) - displayText.addLine("$totalBlocksDestroyed".padStart(6, '0') + " / " + "$totalBlocksPlaced".padStart(6, '0'), secondaryColor) + displayText.addLine("$totalBlocksBroken".padStart(6, '0') + " / " + "$totalBlocksPlaced".padStart(6, '0'), secondaryColor) displayText.add(" Materials:", primaryColor) displayText.addLine("Main(${material.localizedName}) Filler(${fillerMat.localizedName})", secondaryColor) displayText.add(" Delays:", primaryColor) @@ -1231,6 +1269,8 @@ internal object HighwayTools : Module( displayText.addLine("$hoursLeftRefillInv:$minutesLeftRefillInv:$secondsLeftRefillInv", secondaryColor) } +// displayText.addLine("by Constructor#9948 aka Avanatiker", primaryColor) + // MessageSendHelper.sendChatMessage(StatList.MINE_BLOCK_STATS.toString()) if (printDebug) { From 90820714bd2555a30e0135fe0cd0408120b1fe28 Mon Sep 17 00:00:00 2001 From: Christian Date: Mon, 1 Feb 2021 19:40:39 +0100 Subject: [PATCH 282/390] Small fixes --- .../zeroeightsix/kami/module/modules/misc/HighwayTools.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 6279beb92f..8b2fbe9899 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -1186,7 +1186,7 @@ internal object HighwayTools : Module( null } - val distanceDone = startingBlockPos.distanceTo(currentBlockPos).toInt() + 1 + val distanceDone = startingBlockPos.distanceTo(currentBlockPos).toInt() + totalDistance + 1 materialLeft = player.allSlots.countBlock(material) fillerMatLeft = player.allSlots.countBlock(fillerMat) @@ -1202,7 +1202,7 @@ internal object HighwayTools : Module( val minutes = ((runtimeSec % 3600) / 60).toInt().toString().padStart(2, '0') val hours = (runtimeSec / 3600).toInt().toString().padStart(2, '0') - val secLeftRefillInv = (pavingLeft - AutoObsidian.threshold) / (startingBlockPos.distanceTo(currentBlockPos).toInt() / runtimeSec) + val secLeftRefillInv = (pavingLeft - AutoObsidian.threshold).coerceAtLeast(0.0) / (startingBlockPos.distanceTo(currentBlockPos).toInt() / runtimeSec) val secondsLeftRefillInv = (secLeftRefillInv % 60).toInt().toString().padStart(2, '0') val minutesLeftRefillInv = ((secLeftRefillInv % 3600) / 60).toInt().toString().padStart(2, '0') val hoursLeftRefillInv = (secLeftRefillInv / 3600).toInt().toString().padStart(2, '0') @@ -1263,8 +1263,8 @@ internal object HighwayTools : Module( displayText.addLine("$fillerMatLeft", secondaryColor) displayText.add(" Distance left:", primaryColor) displayText.addLine("${pavingLeft.toInt()}", secondaryColor) - displayText.add(" Destination:", primaryColor) - displayText.addLine("(${currentBlockPos.add(startingDirection.directionVec.multiply(pavingLeft.toInt())).asString()})", secondaryColor) + if (!anonymizeStats) displayText.add(" Destination:", primaryColor) + if (!anonymizeStats) displayText.addLine("(${currentBlockPos.add(startingDirection.directionVec.multiply(pavingLeft.toInt())).asString()})", secondaryColor) displayText.add(" ETA:", primaryColor) displayText.addLine("$hoursLeftRefillInv:$minutesLeftRefillInv:$secondsLeftRefillInv", secondaryColor) } From 4c12fe2ee1e0e8c0b463cd83338f6e71e5f9af63 Mon Sep 17 00:00:00 2001 From: Christian Date: Mon, 1 Feb 2021 22:27:20 +0100 Subject: [PATCH 283/390] Multi Builder fix and rolling avg option --- gradle.properties | 2 +- .../kami/module/modules/misc/HighwayTools.kt | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/gradle.properties b/gradle.properties index 6492aaa779..a22af230b3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ org.gradle.jvmargs=-Xmx3G modGroup=me.zeroeightsix -modVersion=2.01.xx-dev-ht-v08 +modVersion=2.01.xx-dev-ht-v08.5 kotlin_version=1.4.21 kotlinx_coroutines_version=1.4.1 \ No newline at end of file diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 8b2fbe9899..d968839566 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -74,7 +74,7 @@ internal object HighwayTools : Module( private val mode by setting("Mode", Mode.HIGHWAY) private val page by setting("Page", Page.BUILD) - val ignoreBlocks = hashSetOf( + val ignoreBlocks = linkedSetOf( Blocks.STANDING_SIGN, Blocks.WALL_SIGN, Blocks.STANDING_BANNER, @@ -109,6 +109,7 @@ internal object HighwayTools : Module( // stats private val anonymizeStats by setting("Anonymize", false, { page == Page.STATS }) + private val rollingAverageRange by setting("Rolling Average Seconds", 60.0f, 1.0f..3600.0f, 1.0f, { page == Page.STATS }) private val showPerformance by setting("Show Performance", true, { page == Page.STATS }) private val showEnvironment by setting("Show Environment", true, { page == Page.STATS }) private val showTask by setting("Show Task", true, { page == Page.STATS }) @@ -344,7 +345,7 @@ internal object HighwayTools : Module( BaritoneUtils.primary?.pathingControlManager?.registerProcess(HighwayToolsProcess) } else { runtimeMilliSeconds += 50 - while (rollingAveragePlaces.isNotEmpty() && System.currentTimeMillis() - rollingAveragePlaces.first() > 60000L) { + while (rollingAveragePlaces.isNotEmpty() && System.currentTimeMillis() - rollingAveragePlaces.first() > 1000L * rollingAverageRange) { rollingAveragePlaces.removeFirst() } } @@ -643,13 +644,14 @@ internal object HighwayTools : Module( val eyePos = mc.player.getPositionEyes(1.0f) if (multiBuilding) { + for (task in pendingTasks.values) task.shuffle() sortedTasks = pendingTasks.values.sortedWith( compareBy { it.taskState.ordinal }.thenBy { it.stuckTicks / 5 }.thenBy { - nextInt() + it.shuffle } ) } else { @@ -1215,12 +1217,12 @@ internal object HighwayTools : Module( displayText.add(" Continuous:", primaryColor) displayText.addLine("%.2f".format(totalBlocksPlaced / runtimeSec), secondaryColor) displayText.add(" Rolling average:", primaryColor) - displayText.addLine("%.2f".format(rollingAveragePlaces.size / 60.0), secondaryColor) + displayText.addLine("%.2f".format(rollingAveragePlaces.size / rollingAverageRange), secondaryColor) displayText.addLine(" Breaks / s:", primaryColor) displayText.add(" Continuous:", primaryColor) displayText.addLine("%.2f".format(totalBlocksBroken / runtimeSec), secondaryColor) displayText.add(" Rolling average:", primaryColor) - displayText.addLine("%.2f".format(rollingAverageBreaks.size / 60.0), secondaryColor) + displayText.addLine("%.2f".format(rollingAverageBreaks.size / rollingAverageRange), secondaryColor) displayText.add(" Distance / h:", primaryColor) displayText.addLine("%.2f".format(startingBlockPos.distanceTo(currentBlockPos).toInt() / runtimeSec * 60 * 60), secondaryColor) displayText.add(" Food level loss / h:", primaryColor) @@ -1293,6 +1295,7 @@ internal object HighwayTools : Module( ) { private var ranTicks = 0 var stuckTicks = 0; private set + var shuffle = 0 fun updateState(state: TaskState) { if (state == taskState) return @@ -1319,6 +1322,10 @@ internal object HighwayTools : Module( stuckTicks++ } + fun shuffle() { + shuffle = nextInt(0, 1000) + } + private fun onUpdate() { stuckTicks = 0 ranTicks = 0 From a41e1173da0e4e69626082880b7fcd4b5497fcd2 Mon Sep 17 00:00:00 2001 From: Christian Date: Mon, 1 Feb 2021 23:16:34 +0100 Subject: [PATCH 284/390] Bump v09 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index a22af230b3..0e704b205b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ org.gradle.jvmargs=-Xmx3G modGroup=me.zeroeightsix -modVersion=2.01.xx-dev-ht-v08.5 +modVersion=2.01.xx-dev-ht-v09 kotlin_version=1.4.21 kotlinx_coroutines_version=1.4.1 \ No newline at end of file From 455e3dbff7386e9a961803c0543f6ad07dcbc846 Mon Sep 17 00:00:00 2001 From: Christian Date: Mon, 1 Feb 2021 23:51:24 +0100 Subject: [PATCH 285/390] Fix break rolling average --- .../me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index d968839566..2b0b6e296c 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -348,6 +348,9 @@ internal object HighwayTools : Module( while (rollingAveragePlaces.isNotEmpty() && System.currentTimeMillis() - rollingAveragePlaces.first() > 1000L * rollingAverageRange) { rollingAveragePlaces.removeFirst() } + while (rollingAverageBreaks.isNotEmpty() && System.currentTimeMillis() - rollingAverageBreaks.first() > 1000L * rollingAverageRange) { + rollingAverageBreaks.removeFirst() + } } doPathing() From 3c40890655b3f57907e522fc02d7c448a8d52dd6 Mon Sep 17 00:00:00 2001 From: Christian Date: Wed, 3 Feb 2021 06:26:54 +0100 Subject: [PATCH 286/390] Bridging, deep search, liquid handle refactor and better estimations --- .../kami/module/modules/misc/HighwayTools.kt | 177 ++++++++++++------ .../me/zeroeightsix/kami/util/WorldUtils.kt | 2 + 2 files changed, 120 insertions(+), 59 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt index 2b0b6e296c..16ca026609 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/misc/HighwayTools.kt @@ -19,6 +19,7 @@ import me.zeroeightsix.kami.util.EntityUtils.flooredPosition import me.zeroeightsix.kami.util.WorldUtils.blackList import me.zeroeightsix.kami.util.WorldUtils.getMiningSide import me.zeroeightsix.kami.util.WorldUtils.getNeighbour +import me.zeroeightsix.kami.util.WorldUtils.isLiquid import me.zeroeightsix.kami.util.WorldUtils.isPlaceable import me.zeroeightsix.kami.util.color.ColorHolder import me.zeroeightsix.kami.util.graphics.* @@ -29,6 +30,7 @@ import me.zeroeightsix.kami.util.math.CoordinateConverter.asString import me.zeroeightsix.kami.util.math.RotationUtils.getRotationTo import me.zeroeightsix.kami.util.math.VectorUtils.distanceTo import me.zeroeightsix.kami.util.math.VectorUtils.multiply +import me.zeroeightsix.kami.util.math.VectorUtils.toVec3dCenter import me.zeroeightsix.kami.util.text.MessageSendHelper import me.zeroeightsix.kami.util.threads.* import net.minecraft.block.Block @@ -40,6 +42,7 @@ import net.minecraft.init.Enchantments import net.minecraft.init.SoundEvents import net.minecraft.inventory.Slot import net.minecraft.item.ItemBlock +import net.minecraft.item.ItemPickaxe import net.minecraft.network.play.client.CPacketEntityAction import net.minecraft.network.play.client.CPacketPlayerDigging import net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock @@ -99,6 +102,8 @@ internal object HighwayTools : Module( private var placeDelay by setting("Place Delay", 3, 1..20, 1, { page == Page.BEHAVIOR }) private var breakDelay by setting("Break Delay", 1, 1..20, 1, { page == Page.BEHAVIOR }) private val illegalPlacements by setting("Illegal Placements", false, { page == Page.BEHAVIOR }) + private val bridging by setting("Bridging", true, { page == Page.BEHAVIOR }) + private var placementSearch by setting("Place Deep Search", 1, 1..20, 1, { page == Page.BEHAVIOR }) private val multiBuilding by setting("Multi Builder", false, { page == Page.BEHAVIOR }) private val maxBreaks by setting("Multi Break", 3, 1..8, 1, { page == Page.BEHAVIOR }) private val toggleInventoryManager by setting("Toggle InvManager", true, { page == Page.BEHAVIOR }) @@ -252,22 +257,22 @@ internal object HighwayTools : Module( private fun printEnable() { if (info) { - MessageSendHelper.sendRawChatMessage(" §9> §7Direction: §a${startingDirection.displayName}§r") + MessageSendHelper.sendRawChatMessage(" §9> §7Direction: §a${startingDirection.displayName} / ${startingDirection.displayNameXY}§r") if (!anonymizeStats) { if (startingDirection.isDiagonal) { - MessageSendHelper.sendRawChatMessage(" §9> §7Coordinates: §a${startingBlockPos.x} ${startingBlockPos.z}§r") + MessageSendHelper.sendRawChatMessage(" §9> §7Axis offset: §a${startingBlockPos.x} ${startingBlockPos.z}§r") } else { if (startingDirection == Direction.NORTH || startingDirection == Direction.SOUTH) { - MessageSendHelper.sendRawChatMessage(" §9> §7Coordinate: §a${startingBlockPos.x}§r") + MessageSendHelper.sendRawChatMessage(" §9> §7Axis offset: §a${startingBlockPos.x}§r") } else { - MessageSendHelper.sendRawChatMessage(" §9> §7Coordinate: §a${startingBlockPos.z}§r") + MessageSendHelper.sendRawChatMessage(" §9> §7Axis offset: §a${startingBlockPos.z}§r") } } } if (startingBlockPos.y != 120 && mode != Mode.TUNNEL) { - MessageSendHelper.sendRawChatMessage(" §9> §cCheck altitude and make sure to build at Y 120 for the correct height") + MessageSendHelper.sendRawChatMessage(" §9> §cCheck altitude and make sure to build at Y: 120 for the correct height") } } } @@ -317,8 +322,8 @@ internal object HighwayTools : Module( val currentToolDamage = it.packet.stack.itemDamage if (lastToolDamage < currentToolDamage && currentToolDamage - lastToolDamage < 100) { durabilityUsages += currentToolDamage - lastToolDamage - lastToolDamage = it.packet.stack.itemDamage } + lastToolDamage = it.packet.stack.itemDamage } } } @@ -365,6 +370,8 @@ internal object HighwayTools : Module( renderer.aFilled = if (filled) aFilled else 0 renderer.aOutline = if (outline) aOutline else 0 +// renderer.add(world.getBlockState(currentBlockPos).getSelectedBoundingBox(world, currentBlockPos), ColorHolder(255, 255, 255)) + for (blockTask in pendingTasks.values) { if (blockTask.taskState == TaskState.DONE) continue renderer.add(world.getBlockState(blockTask.blockPos).getSelectedBoundingBox(world, blockTask.blockPos), blockTask.taskState.color) @@ -550,7 +557,7 @@ internal object HighwayTools : Module( } } - private fun addTaskToPending(blockPos: BlockPos, taskState: TaskState, material: Block) { + fun addTaskToPending(blockPos: BlockPos, taskState: TaskState, material: Block) { pendingTasks[blockPos] = (BlockTask(blockPos, taskState, material)) } @@ -597,12 +604,8 @@ internal object HighwayTools : Module( private fun SafeClientEvent.runTasks() { if (pendingTasks.isEmpty()) { - if (checkDoneTasks()) { - doneTasks.clear() - refreshData(currentBlockPos.add(startingDirection.directionVec)) - } else { - refreshData() - } + if (checkDoneTasks()) doneTasks.clear() + refreshData() } else { waitTicks-- for (task in pendingTasks.values) { @@ -712,6 +715,7 @@ internal object HighwayTools : Module( private fun SafeClientEvent.doTask(blockTask: BlockTask, updateOnly: Boolean) { if (!updateOnly) blockTask.onTick() + // ToDo: Choose place task with least attempts when (blockTask.taskState) { TaskState.DONE -> { doDone(blockTask) @@ -866,29 +870,42 @@ internal object HighwayTools : Module( private fun SafeClientEvent.doPlace(blockTask: BlockTask, updateOnly: Boolean) { val currentBlock = world.getBlockState(blockTask.blockPos).block + if (bridging && player.positionVector.distanceTo(currentBlockPos) < 1 && shouldBridge()) { + val factor = if (startingDirection.isDiagonal) { + 0.51 + } else { + 0.505 + } + val target = currentBlockPos.toVec3dCenter().add(Vec3d(startingDirection.directionVec).scale(factor)) + player.motionX = (target.x - player.posX).coerceIn(-0.2, 0.2) + player.motionZ = (target.z - player.posZ).coerceIn(-0.2, 0.2) + } + when (blockTask.block) { material -> { if (currentBlock == material) { blockTask.updateState(TaskState.PLACED) return - } else if (currentBlock != Blocks.AIR) { + } else if (currentBlock != Blocks.AIR && !isLiquid(blockTask.blockPos)) { blockTask.updateState(TaskState.BREAK) return } } fillerMat -> { - if (currentBlock != Blocks.AIR && currentBlock !is BlockLiquid) { + if (currentBlock != Blocks.AIR && !isLiquid(blockTask.blockPos)) { blockTask.updateState(TaskState.PLACED) return } } Blocks.AIR -> { - if (currentBlock != Blocks.AIR) { - blockTask.updateState(TaskState.BREAK) - } else { - blockTask.updateState(TaskState.BROKEN) + if (!isLiquid(blockTask.blockPos)) { + if (currentBlock != Blocks.AIR) { + blockTask.updateState(TaskState.BREAK) + } else { + blockTask.updateState(TaskState.BROKEN) + } + return } - return } } @@ -930,7 +947,7 @@ internal object HighwayTools : Module( } private fun SafeClientEvent.placeBlock(blockTask: BlockTask) { - val pair = getNeighbour(blockTask.blockPos, 1, maxReach, true) + val pair = getNeighbour(blockTask.blockPos, placementSearch, maxReach, true) ?: run { if (illegalPlacements) { if (debugMessages == DebugMessages.ALL) { @@ -940,7 +957,7 @@ internal object HighwayTools : Module( MessageSendHelper.sendChatMessage("Trying to place through wall") } } - getNeighbour(blockTask.blockPos, 1, maxReach) ?: return + getNeighbour(blockTask.blockPos, placementSearch, maxReach) ?: return } else { blockTask.onStuck() return @@ -987,6 +1004,19 @@ internal object HighwayTools : Module( } } + private fun SafeClientEvent.shouldBridge(): Boolean { + var containsPlace = false + for (task in sortedTasks) { + if (task.taskState == TaskState.PLACE) { + containsPlace = true + getNeighbour(task.blockPos, placementSearch, maxReach, true) + ?: continue + return false + } + } + return containsPlace + } + private fun SafeClientEvent.getBestTool(blockTask: BlockTask): Slot? { return player.inventorySlots.asReversed().maxByOrNull { val stack = it.stack @@ -1089,9 +1119,10 @@ internal object HighwayTools : Module( lastHitVec = WorldUtils.getHitVec(blockTask.blockPos, side) rotateTimer.reset() - when (world.getBlockState(blockTask.blockPos).block) { - Blocks.NETHERRACK -> mineBlockInstant(blockTask, side) - else -> mineBlockNormal(blockTask, side) + if (world.getBlockState(blockTask.blockPos).getPlayerRelativeBlockHardness(player, world, blockTask.blockPos) > 2.8) { + mineBlockInstant(blockTask, side) + } else { + mineBlockNormal(blockTask, side) } } @@ -1191,28 +1222,14 @@ internal object HighwayTools : Module( null } - val distanceDone = startingBlockPos.distanceTo(currentBlockPos).toInt() + totalDistance + 1 - - materialLeft = player.allSlots.countBlock(material) - fillerMatLeft = player.allSlots.countBlock(fillerMat) - val indirectMaterialLeft = 8 * player.allSlots.countBlock(Blocks.ENDER_CHEST) - - val pavingLeft = materialLeft / ((totalBlocksPlaced + 0.001) / (distanceDone + 0.001)) - - // ToDo: Cache shulker count -// val pavingLeftAll = (materialLeft + indirectMaterialLeft) / ((totalBlocksPlaced + 0.001) / (distanceDone + 0.001)) - val runtimeSec = (runtimeMilliSeconds / 1000) + 0.0001 - val seconds = (runtimeSec % 60).toInt().toString().padStart(2, '0') - val minutes = ((runtimeSec % 3600) / 60).toInt().toString().padStart(2, '0') - val hours = (runtimeSec / 3600).toInt().toString().padStart(2, '0') - - val secLeftRefillInv = (pavingLeft - AutoObsidian.threshold).coerceAtLeast(0.0) / (startingBlockPos.distanceTo(currentBlockPos).toInt() / runtimeSec) - val secondsLeftRefillInv = (secLeftRefillInv % 60).toInt().toString().padStart(2, '0') - val minutesLeftRefillInv = ((secLeftRefillInv % 3600) / 60).toInt().toString().padStart(2, '0') - val hoursLeftRefillInv = (secLeftRefillInv / 3600).toInt().toString().padStart(2, '0') + val distanceDone = startingBlockPos.distanceTo(currentBlockPos).toInt() + totalDistance if (showPerformance) { + val seconds = (runtimeSec % 60).toInt().toString().padStart(2, '0') + val minutes = ((runtimeSec % 3600) / 60).toInt().toString().padStart(2, '0') + val hours = (runtimeSec / 3600).toInt().toString().padStart(2, '0') + displayText.addLine("Performance", primaryColor) displayText.add(" Runtime:", primaryColor) displayText.addLine("$hours:$minutes:$seconds", secondaryColor) @@ -1227,7 +1244,7 @@ internal object HighwayTools : Module( displayText.add(" Rolling average:", primaryColor) displayText.addLine("%.2f".format(rollingAverageBreaks.size / rollingAverageRange), secondaryColor) displayText.add(" Distance / h:", primaryColor) - displayText.addLine("%.2f".format(startingBlockPos.distanceTo(currentBlockPos).toInt() / runtimeSec * 60 * 60), secondaryColor) + displayText.addLine("%.2f".format(distanceDone / runtimeSec * 60 * 60), secondaryColor) displayText.add(" Food level loss / h:", primaryColor) displayText.addLine("%.2f".format(totalBlocksBroken / foodLoss.toDouble()), secondaryColor) displayText.add(" Pickaxes / h:", primaryColor) @@ -1239,9 +1256,9 @@ internal object HighwayTools : Module( if (!anonymizeStats) displayText.add(" Start:", primaryColor) if (!anonymizeStats) displayText.addLine("(${startingBlockPos.asString()})", secondaryColor) displayText.add(" Direction:", primaryColor) - displayText.addLine(startingDirection.displayName, secondaryColor) + displayText.addLine("${startingDirection.displayName} / ${startingDirection.displayNameXY}", secondaryColor) displayText.add(" Blocks placed / destroyed:", primaryColor) - displayText.addLine("$totalBlocksBroken".padStart(6, '0') + " / " + "$totalBlocksPlaced".padStart(6, '0'), secondaryColor) + displayText.addLine("$totalBlocksPlaced".padStart(6, '0') + " / " + "$totalBlocksBroken".padStart(6, '0'), secondaryColor) displayText.add(" Materials:", primaryColor) displayText.addLine("Main(${material.localizedName}) Filler(${fillerMat.localizedName})", secondaryColor) displayText.add(" Delays:", primaryColor) @@ -1260,18 +1277,60 @@ internal object HighwayTools : Module( displayText.addLine("${currentTask.stuckTicks}", secondaryColor) } - if (showEstimations && mode == Mode.HIGHWAY) { - displayText.addLine("Next refill", primaryColor) - displayText.add(" ${material.localizedName}:", primaryColor) - displayText.addLine("Direct($materialLeft) Indirect($indirectMaterialLeft)", secondaryColor) - displayText.add(" ${fillerMat.localizedName}:", primaryColor) - displayText.addLine("$fillerMatLeft", secondaryColor) - displayText.add(" Distance left:", primaryColor) - displayText.addLine("${pavingLeft.toInt()}", secondaryColor) - if (!anonymizeStats) displayText.add(" Destination:", primaryColor) - if (!anonymizeStats) displayText.addLine("(${currentBlockPos.add(startingDirection.directionVec.multiply(pavingLeft.toInt())).asString()})", secondaryColor) - displayText.add(" ETA:", primaryColor) - displayText.addLine("$hoursLeftRefillInv:$minutesLeftRefillInv:$secondsLeftRefillInv", secondaryColor) + if (showEstimations) { + when (mode) { + Mode.HIGHWAY, Mode.FLAT -> { + materialLeft = player.allSlots.countBlock(material) + fillerMatLeft = player.allSlots.countBlock(fillerMat) + val indirectMaterialLeft = 8 * player.allSlots.countBlock(Blocks.ENDER_CHEST) + + val pavingLeft = materialLeft / (totalBlocksPlaced.coerceAtLeast(1) / distanceDone.coerceAtLeast(1.0)) + + // ToDo: Cache shulker count +// val pavingLeftAll = (materialLeft + indirectMaterialLeft) / ((totalBlocksPlaced + 0.001) / (distanceDone + 0.001)) + + val secLeft = (pavingLeft - AutoObsidian.threshold).coerceAtLeast(0.0) / (startingBlockPos.distanceTo(currentBlockPos).toInt() / runtimeSec) + val secondsLeft = (secLeft % 60).toInt().toString().padStart(2, '0') + val minutesLeft = ((secLeft % 3600) / 60).toInt().toString().padStart(2, '0') + val hoursLeft = (secLeft / 3600).toInt().toString().padStart(2, '0') + + displayText.addLine("Next refill", primaryColor) + displayText.add(" ${material.localizedName}:", primaryColor) + if (material == Blocks.OBSIDIAN) { + displayText.addLine("Direct($materialLeft) Indirect($indirectMaterialLeft)", secondaryColor) + } else { + displayText.addLine("$materialLeft", secondaryColor) + } + displayText.add(" ${fillerMat.localizedName}:", primaryColor) + displayText.addLine("$fillerMatLeft", secondaryColor) + displayText.add(" Distance left:", primaryColor) + displayText.addLine("${pavingLeft.toInt()}", secondaryColor) + if (!anonymizeStats) displayText.add(" Destination:", primaryColor) + if (!anonymizeStats) displayText.addLine("(${currentBlockPos.add(startingDirection.directionVec.multiply(pavingLeft.toInt())).asString()})", secondaryColor) + displayText.add(" ETA:", primaryColor) + displayText.addLine("$hoursLeft:$minutesLeft:$secondsLeft", secondaryColor) + } + Mode.TUNNEL -> { + val pickaxesLeft = player.allSlots.countItem() + + val tunnelingLeft = (pickaxesLeft * 1561) / (durabilityUsages.coerceAtLeast(1) / distanceDone.coerceAtLeast(1.0)) + + val secLeft = tunnelingLeft.coerceAtLeast(0.0) / (startingBlockPos.distanceTo(currentBlockPos).toInt() / runtimeSec) + val secondsLeft = (secLeft % 60).toInt().toString().padStart(2, '0') + val minutesLeft = ((secLeft % 3600) / 60).toInt().toString().padStart(2, '0') + val hoursLeft = (secLeft / 3600).toInt().toString().padStart(2, '0') + + displayText.addLine("Destination:", primaryColor) + displayText.add(" Pickaxes:", primaryColor) + displayText.addLine("$pickaxesLeft", secondaryColor) + displayText.add(" Distance left:", primaryColor) + displayText.addLine("${tunnelingLeft.toInt()}", secondaryColor) + if (!anonymizeStats) displayText.add(" Destination:", primaryColor) + if (!anonymizeStats) displayText.addLine("(${currentBlockPos.add(startingDirection.directionVec.multiply(tunnelingLeft.toInt())).asString()})", secondaryColor) + displayText.add(" ETA:", primaryColor) + displayText.addLine("$hoursLeft:$minutesLeft:$secondsLeft", secondaryColor) + } + } } // displayText.addLine("by Constructor#9948 aka Avanatiker", primaryColor) diff --git a/src/main/java/me/zeroeightsix/kami/util/WorldUtils.kt b/src/main/java/me/zeroeightsix/kami/util/WorldUtils.kt index aa2e7a5848..37c7595ac5 100644 --- a/src/main/java/me/zeroeightsix/kami/util/WorldUtils.kt +++ b/src/main/java/me/zeroeightsix/kami/util/WorldUtils.kt @@ -3,6 +3,7 @@ package me.zeroeightsix.kami.util import kotlinx.coroutines.delay import me.zeroeightsix.kami.event.SafeClientEvent import me.zeroeightsix.kami.manager.managers.PlayerPacketManager +import me.zeroeightsix.kami.module.modules.misc.HighwayTools import me.zeroeightsix.kami.util.math.RotationUtils.getRotationTo import me.zeroeightsix.kami.util.math.VectorUtils.toVec3dCenter import me.zeroeightsix.kami.util.threads.runSafeSuspend @@ -246,6 +247,7 @@ object WorldUtils { if (attempts > 1) { toIgnore.add(blockPos) + HighwayTools.addTaskToPending(blockPos, HighwayTools.TaskState.LIQUID_SOURCE, HighwayTools.fillerMat) for (side in sides) { val pos = blockPos.offset(side) if (!isPlaceable(pos)) continue From 0d30f5c85def77c46df41612c389af25ec45d79e Mon Sep 17 00:00:00 2001 From: Christian Date: Wed, 3 Feb 2021 23:00:31 +0100 Subject: [PATCH 287/390] Setting descriptions --- .../module/modules/misc/HighwayTools.kt | 73 ++++++++++--------- 1 file changed, 37 insertions(+), 36 deletions(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index ca0f4b1e5e..2dc0dcd77c 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -93,48 +93,49 @@ internal object HighwayTools : Module( ) // build settings - private val clearSpace by setting("Clear Space", true, { page == Page.BUILD && mode == Mode.HIGHWAY }) - private val width by setting("Width", 6, 1..9, 1, { page == Page.BUILD }) - private val height by setting("Height", 4, 1..6, 1, { page == Page.BUILD && clearSpace }) - private val railing by setting("Railing", true, { page == Page.BUILD && mode == Mode.HIGHWAY }) - private val railingHeight by setting("Railing Height", 1, 1..4, 1, { railing && page == Page.BUILD && mode == Mode.HIGHWAY }) - private val cornerBlock by setting("Corner Block", false, { page == Page.BUILD && (mode == Mode.HIGHWAY || mode == Mode.TUNNEL) }) + private val clearSpace by setting("Clear Space", true, { page == Page.BUILD && mode == Mode.HIGHWAY }, description = "Clears out the tunnel if necessary.") + private val width by setting("Width", 6, 1..11, 1, { page == Page.BUILD }, description = "Sets the width of blueprint.") + private val height by setting("Height", 4, 1..6, 1, { page == Page.BUILD && clearSpace }, description = "Sets height of blueprint.") + private val railing by setting("Railing", true, { page == Page.BUILD && mode == Mode.HIGHWAY }, description = "Adds a railing / rim / border to the highway.") + private val railingHeight by setting("Railing Height", 1, 1..4, 1, { railing && page == Page.BUILD && mode == Mode.HIGHWAY }, description = "Sets height of railing.") + private val cornerBlock by setting("Corner Block", false, { page == Page.BUILD && (mode == Mode.HIGHWAY || mode == Mode.TUNNEL) }, description = "If activated will break the corner in tunnel or place a corner while paving.") +// val ignoreBlocks = setting(CollectionSetting("IgnoreList", defaultIgnoreList, { false })) // behavior settings - private val interacting by setting("Rotation Mode", RotationMode.SPOOF, { page == Page.BEHAVIOR }) - private val dynamicDelay by setting("Dynamic Place Delay", true, { page == Page.BEHAVIOR }) - private var placeDelay by setting("Place Delay", 3, 1..20, 1, { page == Page.BEHAVIOR }) - private var breakDelay by setting("Break Delay", 1, 1..20, 1, { page == Page.BEHAVIOR }) - private val illegalPlacements by setting("Illegal Placements", false, { page == Page.BEHAVIOR }) - private val bridging by setting("Bridging", true, { page == Page.BEHAVIOR }) - private var placementSearch by setting("Place Deep Search", 1, 1..20, 1, { page == Page.BEHAVIOR }) - private val multiBuilding by setting("Multi Builder", false, { page == Page.BEHAVIOR }) - private val maxBreaks by setting("Multi Break", 3, 1..8, 1, { page == Page.BEHAVIOR }) - private val toggleInventoryManager by setting("Toggle InvManager", true, { page == Page.BEHAVIOR }) - private val toggleAutoObsidian by setting("Toggle AutoObsidian", true, { page == Page.BEHAVIOR }) - private val taskTimeout by setting("Task Timeout", 8, 0..20, 1, { page == Page.BEHAVIOR }) - private val rubberbandTimeout by setting("Rubberband Timeout", 50, 5..100, 5, { page == Page.BEHAVIOR }) - private val maxReach by setting("MaxReach", 4.9f, 1.0f..6.0f, 0.1f, { page == Page.BEHAVIOR }) + private val interacting by setting("Rotation Mode", RotationMode.SPOOF, { page == Page.BEHAVIOR }, description = "Force view client side, only server side or no interaction at all.") + private val dynamicDelay by setting("Dynamic Place Delay", true, { page == Page.BEHAVIOR }, description = "Slows down on failed placement attempts") + private var placeDelay by setting("Place Delay", 3, 1..20, 1, { page == Page.BEHAVIOR }, description = "Sets the delay ticks between placement tasks.") + private var breakDelay by setting("Break Delay", 1, 1..20, 1, { page == Page.BEHAVIOR }, description = "Sets the delay ticks between break tasks.") + private val illegalPlacements by setting("Illegal Placements", false, { page == Page.BEHAVIOR }, description = "Do not use on 2b2t. Tries to interact with invisible surfaces.") + private val bridging by setting("Bridging", true, { page == Page.BEHAVIOR }, description = "Tries to bridge / scaffold when stuck placing.") + private var placementSearch by setting("Place Deep Search", 1, 1..20, 1, { page == Page.BEHAVIOR }, description = "Attempts to find a support block for placing against.") + private val multiBuilding by setting("Shuffle Tasks", false, { page == Page.BEHAVIOR }, description = "Only activate when working with several players.") + private val maxBreaks by setting("Multi Break", 3, 1..8, 1, { page == Page.BEHAVIOR }, description = "Breaks multiple instant breaking blocks per tick in view.") + private val toggleInventoryManager by setting("Toggle InvManager", true, { page == Page.BEHAVIOR }, description = "Activates InventoryManager on enable.") + private val toggleAutoObsidian by setting("Toggle AutoObsidian", true, { page == Page.BEHAVIOR }, description = "Activates AutoObsidian on enable.") + private val taskTimeout by setting("Task Timeout", 8, 0..20, 1, { page == Page.BEHAVIOR }, description = "Timeout for waiting for the server to try again.") + private val rubberbandTimeout by setting("Rubberband Timeout", 50, 5..100, 5, { page == Page.BEHAVIOR }, description = "Timeout for pausing after a lag.") + private val maxReach by setting("MaxReach", 4.9f, 1.0f..6.0f, 0.1f, { page == Page.BEHAVIOR }, description = "Sets the range of the blueprint. Decrease when tasks fail!") // stats - private val anonymizeStats by setting("Anonymize", false, { page == Page.STATS }) - private val rollingAverageRange by setting("Rolling Average Seconds", 60.0f, 1.0f..3600.0f, 1.0f, { page == Page.STATS }) - private val showPerformance by setting("Show Performance", true, { page == Page.STATS }) - private val showEnvironment by setting("Show Environment", true, { page == Page.STATS }) - private val showTask by setting("Show Task", true, { page == Page.STATS }) - private val showEstimations by setting("Show Estimations", true, { page == Page.STATS }) -// val ignoreBlocks = setting(CollectionSetting("IgnoreList", defaultIgnoreList, { false })) + private val anonymizeStats by setting("Anonymize", false, { page == Page.STATS }, description = "Censors all coordinates in HUD and Chat.") + private val rollingAverageRange by setting("Rolling Average Seconds", 60, 5..600, 5, { page == Page.STATS }, description = "Sets the timeframe of the average.") + private val showPerformance by setting("Show Performance", true, { page == Page.STATS }, description = "Toggles the Performance section in HUD.") + private val showEnvironment by setting("Show Environment", true, { page == Page.STATS }, description = "Toggles the Environment section in HUD.") + private val showTask by setting("Show Task", true, { page == Page.STATS }, description = "Toggles the Task section in HUD.") + private val showEstimations by setting("Show Estimations", true, { page == Page.STATS }, description = "Toggles the Estimations section in HUD.") + private val resetStats by setting("Reset Stats", false, { page == Page.STATS }, description = "Resets the stats.") // config - private val fakeSounds by setting("Fake Sounds", true, { page == Page.CONFIG }) - private val info by setting("Show Info", true, { page == Page.CONFIG }) - private val printDebug by setting("Show Queue", false, { page == Page.CONFIG }) - private val debugMessages by setting("Debug Messages", DebugMessages.IMPORTANT, { page == Page.CONFIG }) - private val goalRender by setting("Goal Render", false, { page == Page.CONFIG }) - private val filled by setting("Filled", true, { page == Page.CONFIG }) - private val outline by setting("Outline", true, { page == Page.CONFIG }) - private val aFilled by setting("FilledAlpha", 26, 0..255, 1, { filled && page == Page.CONFIG }) - private val aOutline by setting("OutlineAlpha", 91, 0..255, 1, { outline && page == Page.CONFIG }) + private val fakeSounds by setting("Fake Sounds", true, { page == Page.CONFIG }, description = "Adds artificial sounds to the actions.") + private val info by setting("Show Info", true, { page == Page.CONFIG }, description = "Prints session stats in chat.") + private val printDebug by setting("Show Queue", false, { page == Page.CONFIG }, description = "Shows task queue in HUD.") + private val debugMessages by setting("Debug Messages", DebugMessages.IMPORTANT, { page == Page.CONFIG }, description = "Sets the debug log depth level.") + private val goalRender by setting("Goal Render", false, { page == Page.CONFIG }, description = "Renders the baritone goal.") + private val filled by setting("Filled", true, { page == Page.CONFIG }, description = "Renders colored task surfaces.") + private val outline by setting("Outline", true, { page == Page.CONFIG }, description = "Renders colored task outlines.") + private val aFilled by setting("Filled Alpha", 26, 0..255, 1, { filled && page == Page.CONFIG }, description = "Sets the opacity.") + private val aOutline by setting("Outline Alpha", 91, 0..255, 1, { outline && page == Page.CONFIG }, description = "Sets the opacity.") private enum class Mode { HIGHWAY, FLAT, TUNNEL From 49bc3c97149a15ce3dafdad5033d9178a3052882 Mon Sep 17 00:00:00 2001 From: Christian Date: Fri, 5 Feb 2021 01:05:56 +0100 Subject: [PATCH 288/390] Reset stats, less code complexity --- .../module/modules/misc/HighwayTools.kt | 270 ++++++++++-------- 1 file changed, 151 insertions(+), 119 deletions(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index 2dc0dcd77c..dae952cd4e 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -119,12 +119,12 @@ internal object HighwayTools : Module( // stats private val anonymizeStats by setting("Anonymize", false, { page == Page.STATS }, description = "Censors all coordinates in HUD and Chat.") - private val rollingAverageRange by setting("Rolling Average Seconds", 60, 5..600, 5, { page == Page.STATS }, description = "Sets the timeframe of the average.") + private val simpleMovingAverageRange by setting("Simple Moving Average Seconds", 60f, 5f..600f, 5f, { page == Page.STATS }, description = "Sets the timeframe of the average.") private val showPerformance by setting("Show Performance", true, { page == Page.STATS }, description = "Toggles the Performance section in HUD.") private val showEnvironment by setting("Show Environment", true, { page == Page.STATS }, description = "Toggles the Environment section in HUD.") private val showTask by setting("Show Task", true, { page == Page.STATS }, description = "Toggles the Task section in HUD.") private val showEstimations by setting("Show Estimations", true, { page == Page.STATS }, description = "Toggles the Estimations section in HUD.") - private val resetStats by setting("Reset Stats", false, { page == Page.STATS }, description = "Resets the stats.") + private val resetStats = setting("Reset Stats", false, { page == Page.STATS }, description = "Resets the stats.") // config private val fakeSounds by setting("Fake Sounds", true, { page == Page.CONFIG }, description = "Adds artificial sounds to the actions.") @@ -186,8 +186,9 @@ internal object HighwayTools : Module( var lastTask: BlockTask? = null; private set // Stats - private val rollingAveragePlaces = ArrayDeque() - private val rollingAverageBreaks = ArrayDeque() + private val simpleMovingAveragePlaces = ArrayDeque() + private val simpleMovingAverageBreaks = ArrayDeque() + private val simpleMovingAverageDistance = ArrayDeque() private var totalBlocksPlaced = 0 private var totalBlocksBroken = 0 private var totalDistance = 0.0 @@ -258,6 +259,13 @@ internal object HighwayTools : Module( printDisable() } } + + resetStats.listeners.add { + if (resetStats.value) { + resetStats() + resetStats.value = false + } + } } private fun printEnable() { @@ -355,11 +363,14 @@ internal object HighwayTools : Module( BaritoneUtils.primary?.pathingControlManager?.registerProcess(HighwayToolsProcess) } else { runtimeMilliSeconds += 50 - while (rollingAveragePlaces.isNotEmpty() && System.currentTimeMillis() - rollingAveragePlaces.first() > 1000L * rollingAverageRange) { - rollingAveragePlaces.removeFirst() + while (simpleMovingAveragePlaces.isNotEmpty() && System.currentTimeMillis() - simpleMovingAveragePlaces.first() > 1000L * simpleMovingAverageRange) { + simpleMovingAveragePlaces.removeFirst() } - while (rollingAverageBreaks.isNotEmpty() && System.currentTimeMillis() - rollingAverageBreaks.first() > 1000L * rollingAverageRange) { - rollingAverageBreaks.removeFirst() + while (simpleMovingAverageBreaks.isNotEmpty() && System.currentTimeMillis() - simpleMovingAverageBreaks.first() > 1000L * simpleMovingAverageRange) { + simpleMovingAverageBreaks.removeFirst() + } + while (simpleMovingAverageDistance.isNotEmpty() && System.currentTimeMillis() - simpleMovingAverageDistance.first() > 1000L * simpleMovingAverageRange) { + simpleMovingAverageDistance.removeFirst() } } @@ -591,7 +602,10 @@ internal object HighwayTools : Module( if (checkTasks(possiblePos.up())) nextPos = possiblePos - if (currentBlockPos != nextPos) refreshData() + if (currentBlockPos != nextPos) { + simpleMovingAverageDistance.add(System.currentTimeMillis()) + refreshData() + } return nextPos } @@ -789,7 +803,7 @@ internal object HighwayTools : Module( when (world.getBlockState(blockTask.blockPos).block) { Blocks.AIR -> { totalBlocksBroken++ - rollingAverageBreaks.add(System.currentTimeMillis()) + simpleMovingAverageBreaks.add(System.currentTimeMillis()) if (blockTask.block == Blocks.AIR) { if (fakeSounds) { @@ -813,7 +827,7 @@ internal object HighwayTools : Module( when { blockTask.block == currentBlock && currentBlock != Blocks.AIR -> { totalBlocksPlaced++ - rollingAveragePlaces.add(System.currentTimeMillis()) + simpleMovingAveragePlaces.add(System.currentTimeMillis()) if (dynamicDelay && extraPlaceDelay > 0) extraPlaceDelay -= 1 @@ -1221,134 +1235,152 @@ internal object HighwayTools : Module( } fun SafeClientEvent.gatherStatistics(displayText: TextComponent) { - val currentTask = if (sortedTasks.isNotEmpty()) { - sortedTasks[0] - } else { - null - } + val runtimeSec = (runtimeMilliSeconds / 1000) + 0.0001 val distanceDone = startingBlockPos.distanceTo(currentBlockPos).toInt() + totalDistance +// val statList = Gson().fromJson(StatList.MINE_BLOCK_STATS[0], Any::class.java) +// MessageSendHelper.sendChatMessage(statList) + + if (showPerformance) gatherPerformance(displayText, runtimeSec, distanceDone) + + if (showEnvironment) gatherEnvironment(displayText) + + if (showTask) gatherTask(displayText) + + if (showEstimations) gatherEstimations(displayText, runtimeSec, distanceDone) + +// displayText.addLine("by Constructor#9948 aka Avanatiker", primaryColor) + +// MessageSendHelper.sendChatMessage(StatList.MINE_BLOCK_STATS.toString()) + + if (printDebug) { + displayText.addLine("Pending", primaryColor) + addTaskComponentList(displayText, sortedTasks) + + displayText.addLine("Done", primaryColor) + addTaskComponentList(displayText, doneTasks.values) + } + } + + private fun gatherPerformance(displayText: TextComponent, runtimeSec: Double, distanceDone: Double) { + val seconds = (runtimeSec % 60).toInt().toString().padStart(2, '0') + val minutes = ((runtimeSec % 3600) / 60).toInt().toString().padStart(2, '0') + val hours = (runtimeSec / 3600).toInt().toString().padStart(2, '0') + + displayText.addLine("Performance", primaryColor) + displayText.add(" Runtime:", primaryColor) + displayText.addLine("$hours:$minutes:$seconds", secondaryColor) + displayText.add(" Placements / s: ", primaryColor) + displayText.addLine("%.2f SMA(%.2f)".format(totalBlocksPlaced / runtimeSec, simpleMovingAveragePlaces.size / simpleMovingAverageRange), secondaryColor) + displayText.add(" Breaks / s:", primaryColor) + displayText.addLine("%.2f SMA(%.2f)".format(totalBlocksBroken / runtimeSec, simpleMovingAverageBreaks.size / simpleMovingAverageRange), secondaryColor) + displayText.add(" Distance km / h:", primaryColor) + displayText.addLine("%.3f SMA(%.3f)".format((distanceDone / runtimeSec * 60 * 60) / 1000, ((simpleMovingAverageDistance.size / simpleMovingAverageRange) * 60 * 60) / 1000), secondaryColor) + displayText.add(" Food level loss / h:", primaryColor) + displayText.addLine("%.2f".format(totalBlocksBroken / foodLoss.toDouble()), secondaryColor) + displayText.add(" Pickaxes / h:", primaryColor) + displayText.addLine("%.2f".format((durabilityUsages / runtimeSec) * 60 * 60 / 1561), secondaryColor) + } + + private fun gatherEnvironment(displayText: TextComponent) { + displayText.addLine("Environment", primaryColor) + if (!anonymizeStats) displayText.add(" Start:", primaryColor) + if (!anonymizeStats) displayText.addLine("(${startingBlockPos.asString()})", secondaryColor) + displayText.add(" Direction:", primaryColor) + displayText.addLine("${startingDirection.displayName} / ${startingDirection.displayNameXY}", secondaryColor) + displayText.add(" Blocks placed / destroyed:", primaryColor) + displayText.addLine("$totalBlocksPlaced".padStart(6, '0') + " / " + "$totalBlocksBroken".padStart(6, '0'), secondaryColor) + displayText.add(" Materials:", primaryColor) + displayText.addLine("Main(${material.localizedName}) Filler(${fillerMat.localizedName})", secondaryColor) + displayText.add(" Delays:", primaryColor) + displayText.addLine("Place(${placeDelay + extraPlaceDelay}) Break($breakDelay)", secondaryColor) + } - if (showPerformance) { - val seconds = (runtimeSec % 60).toInt().toString().padStart(2, '0') - val minutes = ((runtimeSec % 3600) / 60).toInt().toString().padStart(2, '0') - val hours = (runtimeSec / 3600).toInt().toString().padStart(2, '0') - - displayText.addLine("Performance", primaryColor) - displayText.add(" Runtime:", primaryColor) - displayText.addLine("$hours:$minutes:$seconds", secondaryColor) - displayText.addLine(" Placements / s:", primaryColor) - displayText.add(" Continuous:", primaryColor) - displayText.addLine("%.2f".format(totalBlocksPlaced / runtimeSec), secondaryColor) - displayText.add(" Rolling average:", primaryColor) - displayText.addLine("%.2f".format(rollingAveragePlaces.size / rollingAverageRange), secondaryColor) - displayText.addLine(" Breaks / s:", primaryColor) - displayText.add(" Continuous:", primaryColor) - displayText.addLine("%.2f".format(totalBlocksBroken / runtimeSec), secondaryColor) - displayText.add(" Rolling average:", primaryColor) - displayText.addLine("%.2f".format(rollingAverageBreaks.size / rollingAverageRange), secondaryColor) - displayText.add(" Distance / h:", primaryColor) - displayText.addLine("%.2f".format(distanceDone / runtimeSec * 60 * 60), secondaryColor) - displayText.add(" Food level loss / h:", primaryColor) - displayText.addLine("%.2f".format(totalBlocksBroken / foodLoss.toDouble()), secondaryColor) - displayText.add(" Pickaxes / h:", primaryColor) - displayText.addLine("%.2f".format((durabilityUsages / runtimeSec) * 60 * 60 / 1561), secondaryColor) - } - - if (showEnvironment) { - displayText.addLine("Environment", primaryColor) - if (!anonymizeStats) displayText.add(" Start:", primaryColor) - if (!anonymizeStats) displayText.addLine("(${startingBlockPos.asString()})", secondaryColor) - displayText.add(" Direction:", primaryColor) - displayText.addLine("${startingDirection.displayName} / ${startingDirection.displayNameXY}", secondaryColor) - displayText.add(" Blocks placed / destroyed:", primaryColor) - displayText.addLine("$totalBlocksPlaced".padStart(6, '0') + " / " + "$totalBlocksBroken".padStart(6, '0'), secondaryColor) - displayText.add(" Materials:", primaryColor) - displayText.addLine("Main(${material.localizedName}) Filler(${fillerMat.localizedName})", secondaryColor) - displayText.add(" Delays:", primaryColor) - displayText.addLine("Place(${placeDelay + extraPlaceDelay}) Break($breakDelay)", secondaryColor) - } - - if (showTask && currentTask != null) { + private fun gatherTask(displayText: TextComponent) { + sortedTasks.firstOrNull()?.let { displayText.addLine("Task", primaryColor) displayText.add(" Status:", primaryColor) - displayText.addLine("${currentTask.taskState}", secondaryColor) + displayText.addLine("${it.taskState}", secondaryColor) displayText.add(" Target block:", primaryColor) - displayText.addLine(currentTask.block.localizedName, secondaryColor) + displayText.addLine(it.block.localizedName, secondaryColor) if (!anonymizeStats) displayText.add(" Position:", primaryColor) - if (!anonymizeStats) displayText.addLine("(${currentTask.blockPos.asString()})", secondaryColor) + if (!anonymizeStats) displayText.addLine("(${it.blockPos.asString()})", secondaryColor) displayText.add(" Ticks stuck:", primaryColor) - displayText.addLine("${currentTask.stuckTicks}", secondaryColor) + displayText.addLine("${it.stuckTicks}", secondaryColor) } + } - if (showEstimations) { - when (mode) { - Mode.HIGHWAY, Mode.FLAT -> { - materialLeft = player.allSlots.countBlock(material) - fillerMatLeft = player.allSlots.countBlock(fillerMat) - val indirectMaterialLeft = 8 * player.allSlots.countBlock(Blocks.ENDER_CHEST) + private fun SafeClientEvent.gatherEstimations(displayText: TextComponent, runtimeSec: Double, distanceDone: Double) { + when (mode) { + Mode.HIGHWAY, Mode.FLAT -> { + materialLeft = player.allSlots.countBlock(material) + fillerMatLeft = player.allSlots.countBlock(fillerMat) + val indirectMaterialLeft = 8 * player.allSlots.countBlock(Blocks.ENDER_CHEST) - val pavingLeft = materialLeft / (totalBlocksPlaced.coerceAtLeast(1) / distanceDone.coerceAtLeast(1.0)) + val pavingLeft = materialLeft / (totalBlocksPlaced.coerceAtLeast(1) / distanceDone.coerceAtLeast(1.0)) - // ToDo: Cache shulker count + // ToDo: Cache shulker count // val pavingLeftAll = (materialLeft + indirectMaterialLeft) / ((totalBlocksPlaced + 0.001) / (distanceDone + 0.001)) - val secLeft = (pavingLeft - AutoObsidian.threshold).coerceAtLeast(0.0) / (startingBlockPos.distanceTo(currentBlockPos).toInt() / runtimeSec) - val secondsLeft = (secLeft % 60).toInt().toString().padStart(2, '0') - val minutesLeft = ((secLeft % 3600) / 60).toInt().toString().padStart(2, '0') - val hoursLeft = (secLeft / 3600).toInt().toString().padStart(2, '0') + val secLeft = (pavingLeft - AutoObsidian.threshold).coerceAtLeast(0.0) / (startingBlockPos.distanceTo(currentBlockPos).toInt() / runtimeSec) + val secondsLeft = (secLeft % 60).toInt().toString().padStart(2, '0') + val minutesLeft = ((secLeft % 3600) / 60).toInt().toString().padStart(2, '0') + val hoursLeft = (secLeft / 3600).toInt().toString().padStart(2, '0') - displayText.addLine("Next refill", primaryColor) - displayText.add(" ${material.localizedName}:", primaryColor) - if (material == Blocks.OBSIDIAN) { - displayText.addLine("Direct($materialLeft) Indirect($indirectMaterialLeft)", secondaryColor) - } else { - displayText.addLine("$materialLeft", secondaryColor) - } - displayText.add(" ${fillerMat.localizedName}:", primaryColor) - displayText.addLine("$fillerMatLeft", secondaryColor) - displayText.add(" Distance left:", primaryColor) - displayText.addLine("${pavingLeft.toInt()}", secondaryColor) - if (!anonymizeStats) displayText.add(" Destination:", primaryColor) - if (!anonymizeStats) displayText.addLine("(${currentBlockPos.add(startingDirection.directionVec.multiply(pavingLeft.toInt())).asString()})", secondaryColor) - displayText.add(" ETA:", primaryColor) - displayText.addLine("$hoursLeft:$minutesLeft:$secondsLeft", secondaryColor) - } - Mode.TUNNEL -> { - val pickaxesLeft = player.allSlots.countItem() - - val tunnelingLeft = (pickaxesLeft * 1561) / (durabilityUsages.coerceAtLeast(1) / distanceDone.coerceAtLeast(1.0)) - - val secLeft = tunnelingLeft.coerceAtLeast(0.0) / (startingBlockPos.distanceTo(currentBlockPos).toInt() / runtimeSec) - val secondsLeft = (secLeft % 60).toInt().toString().padStart(2, '0') - val minutesLeft = ((secLeft % 3600) / 60).toInt().toString().padStart(2, '0') - val hoursLeft = (secLeft / 3600).toInt().toString().padStart(2, '0') - - displayText.addLine("Destination:", primaryColor) - displayText.add(" Pickaxes:", primaryColor) - displayText.addLine("$pickaxesLeft", secondaryColor) - displayText.add(" Distance left:", primaryColor) - displayText.addLine("${tunnelingLeft.toInt()}", secondaryColor) - if (!anonymizeStats) displayText.add(" Destination:", primaryColor) - if (!anonymizeStats) displayText.addLine("(${currentBlockPos.add(startingDirection.directionVec.multiply(tunnelingLeft.toInt())).asString()})", secondaryColor) - displayText.add(" ETA:", primaryColor) - displayText.addLine("$hoursLeft:$minutesLeft:$secondsLeft", secondaryColor) + displayText.addLine("Next refill", primaryColor) + displayText.add(" ${material.localizedName}:", primaryColor) + if (material == Blocks.OBSIDIAN) { + displayText.addLine("Direct($materialLeft) Indirect($indirectMaterialLeft)", secondaryColor) + } else { + displayText.addLine("$materialLeft", secondaryColor) } + displayText.add(" ${fillerMat.localizedName}:", primaryColor) + displayText.addLine("$fillerMatLeft", secondaryColor) + displayText.add(" Distance left:", primaryColor) + displayText.addLine("${pavingLeft.toInt()}", secondaryColor) + if (!anonymizeStats) displayText.add(" Destination:", primaryColor) + if (!anonymizeStats) displayText.addLine("(${currentBlockPos.add(startingDirection.directionVec.multiply(pavingLeft.toInt())).asString()})", secondaryColor) + displayText.add(" ETA:", primaryColor) + displayText.addLine("$hoursLeft:$minutesLeft:$secondsLeft", secondaryColor) + } + Mode.TUNNEL -> { + val pickaxesLeft = player.allSlots.countItem() + + val tunnelingLeft = (pickaxesLeft * 1561) / (durabilityUsages.coerceAtLeast(1) / distanceDone.coerceAtLeast(1.0)) + + val secLeft = tunnelingLeft.coerceAtLeast(0.0) / (startingBlockPos.distanceTo(currentBlockPos).toInt() / runtimeSec) + val secondsLeft = (secLeft % 60).toInt().toString().padStart(2, '0') + val minutesLeft = ((secLeft % 3600) / 60).toInt().toString().padStart(2, '0') + val hoursLeft = (secLeft / 3600).toInt().toString().padStart(2, '0') + + displayText.addLine("Destination:", primaryColor) + displayText.add(" Pickaxes:", primaryColor) + displayText.addLine("$pickaxesLeft", secondaryColor) + displayText.add(" Distance left:", primaryColor) + displayText.addLine("${tunnelingLeft.toInt()}", secondaryColor) + if (!anonymizeStats) displayText.add(" Destination:", primaryColor) + if (!anonymizeStats) displayText.addLine("(${currentBlockPos.add(startingDirection.directionVec.multiply(tunnelingLeft.toInt())).asString()})", secondaryColor) + displayText.add(" ETA:", primaryColor) + displayText.addLine("$hoursLeft:$minutesLeft:$secondsLeft", secondaryColor) } } + } -// displayText.addLine("by Constructor#9948 aka Avanatiker", primaryColor) - -// MessageSendHelper.sendChatMessage(StatList.MINE_BLOCK_STATS.toString()) - - if (printDebug) { - displayText.addLine("Pending", primaryColor) - addTaskComponentList(displayText, sortedTasks) - - displayText.addLine("Done", primaryColor) - addTaskComponentList(displayText, doneTasks.values) - } + private fun resetStats() { + simpleMovingAveragePlaces.clear() + simpleMovingAverageBreaks.clear() + simpleMovingAverageDistance.clear() + totalBlocksPlaced = 0 + totalBlocksBroken = 0 + totalDistance = 0.0 + runtimeMilliSeconds = 0 + prevFood = 0 + foodLoss = 1 + materialLeft = 0 + fillerMatLeft = 0 + lastToolDamage = 0 + durabilityUsages = 0 } private fun addTaskComponentList(displayText: TextComponent, tasks: Collection) { From da4ed60f70f877ec1dfffdd3f7e77a1799f954ae Mon Sep 17 00:00:00 2001 From: Christian Date: Fri, 5 Feb 2021 01:55:23 +0100 Subject: [PATCH 289/390] Fix threading --- .../client/module/modules/misc/HighwayTools.kt | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index dae952cd4e..e598c5a13a 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -3,6 +3,7 @@ package org.kamiblue.client.module.modules.misc import baritone.api.pathing.goals.GoalNear import kotlinx.coroutines.delay import kotlinx.coroutines.launch +import kotlinx.coroutines.runBlocking import net.minecraft.block.Block import net.minecraft.block.BlockLiquid import net.minecraft.client.audio.PositionedSoundRecord @@ -1206,10 +1207,12 @@ internal object HighwayTools : Module( } private fun sendMiningPackets(pos: BlockPos, side: EnumFacing) { - onMainThreadSafe { - connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, pos, side)) - connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, pos, side)) - player.swingArm(EnumHand.MAIN_HAND) + runBlocking { + onMainThreadSafe { + connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, pos, side)) + connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, pos, side)) + player.swingArm(EnumHand.MAIN_HAND) + } } } From 0ac106f2570a93b240f5d8646599482e8060b613 Mon Sep 17 00:00:00 2001 From: Christian Date: Fri, 5 Feb 2021 20:31:48 +0100 Subject: [PATCH 290/390] ToDo --- .../org/kamiblue/client/module/modules/misc/HighwayTools.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index e598c5a13a..7d867cddd0 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -611,6 +611,7 @@ internal object HighwayTools : Module( return nextPos } + // ToDo: Check correctly if not in blueprint to avoid baritone stuck private fun isTaskDoneOrNull(pos: BlockPos) = (pendingTasks[pos] ?: doneTasks[pos])?.let { it.taskState == TaskState.DONE From b1abf5b5b4ae6fb22200f611536cb0918d73b0f5 Mon Sep 17 00:00:00 2001 From: Christian Date: Sun, 7 Feb 2021 19:23:18 +0100 Subject: [PATCH 291/390] Merge fixes --- .../kamiblue/client/module/modules/misc/AutoTool.kt | 6 ------ .../client/module/modules/misc/HighwayTools.kt | 2 +- src/main/kotlin/org/kamiblue/client/util/WorldUtils.kt | 10 +++++++--- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/AutoTool.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/AutoTool.kt index 6fb9c0e4a6..34f4768d46 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/AutoTool.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/AutoTool.kt @@ -15,12 +15,6 @@ import org.kamiblue.client.util.combat.CombatUtils import org.kamiblue.client.util.combat.CombatUtils.equipBestWeapon import org.kamiblue.client.util.items.swapToSlot import org.kamiblue.client.util.threads.safeListener -import net.minecraft.block.state.IBlockState -import net.minecraft.enchantment.EnchantmentHelper -import net.minecraft.entity.EntityLivingBase -import net.minecraft.init.Enchantments -import net.minecraftforge.event.entity.player.PlayerInteractEvent.LeftClickBlock -import net.minecraftforge.fml.common.gameevent.TickEvent import org.kamiblue.client.util.items.hotbarSlots import org.lwjgl.input.Mouse diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index 7d867cddd0..39cc8c199c 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -116,7 +116,7 @@ internal object HighwayTools : Module( private val toggleAutoObsidian by setting("Toggle AutoObsidian", true, { page == Page.BEHAVIOR }, description = "Activates AutoObsidian on enable.") private val taskTimeout by setting("Task Timeout", 8, 0..20, 1, { page == Page.BEHAVIOR }, description = "Timeout for waiting for the server to try again.") private val rubberbandTimeout by setting("Rubberband Timeout", 50, 5..100, 5, { page == Page.BEHAVIOR }, description = "Timeout for pausing after a lag.") - private val maxReach by setting("MaxReach", 4.9f, 1.0f..6.0f, 0.1f, { page == Page.BEHAVIOR }, description = "Sets the range of the blueprint. Decrease when tasks fail!") + private val maxReach by setting("Max Reach", 4.9f, 1.0f..6.0f, 0.1f, { page == Page.BEHAVIOR }, description = "Sets the range of the blueprint. Decrease when tasks fail!") // stats private val anonymizeStats by setting("Anonymize", false, { page == Page.STATS }, description = "Censors all coordinates in HUD and Chat.") diff --git a/src/main/kotlin/org/kamiblue/client/util/WorldUtils.kt b/src/main/kotlin/org/kamiblue/client/util/WorldUtils.kt index 6df1e8cb3f..19f1b209fa 100644 --- a/src/main/kotlin/org/kamiblue/client/util/WorldUtils.kt +++ b/src/main/kotlin/org/kamiblue/client/util/WorldUtils.kt @@ -13,11 +13,13 @@ import net.minecraft.util.math.AxisAlignedBB import net.minecraft.util.math.BlockPos import net.minecraft.util.math.RayTraceResult import net.minecraft.util.math.Vec3d +import org.kamiblue.client.event.SafeClientEvent +import org.kamiblue.client.manager.managers.PlayerPacketManager import org.kamiblue.client.module.modules.misc.HighwayTools +import org.kamiblue.client.util.math.RotationUtils.getRotationTo import org.kamiblue.client.util.math.VectorUtils.toVec3dCenter -import org.kamiblue.commons.extension.add +import org.kamiblue.client.util.threads.runSafeSuspend import java.util.* -import kotlin.collections.ArrayList import kotlin.collections.HashSet import kotlin.math.floor @@ -84,7 +86,9 @@ object WorldUtils { for (x in xArray) { for (z in zArray) { val result = rayTraceToGround(Vec3d(x, boundingBox.minY, z), stopOnLiquid) - results.add(result) + if (result != null) { + results.add(result) + } } } From 2163119876591b91a8c778385381c055a133301b Mon Sep 17 00:00:00 2001 From: Christian Date: Sun, 7 Feb 2021 19:28:13 +0100 Subject: [PATCH 292/390] Decomplex --- .../module/modules/misc/HighwayTools.kt | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index 39cc8c199c..fbc3e27bad 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -364,15 +364,7 @@ internal object HighwayTools : Module( BaritoneUtils.primary?.pathingControlManager?.registerProcess(HighwayToolsProcess) } else { runtimeMilliSeconds += 50 - while (simpleMovingAveragePlaces.isNotEmpty() && System.currentTimeMillis() - simpleMovingAveragePlaces.first() > 1000L * simpleMovingAverageRange) { - simpleMovingAveragePlaces.removeFirst() - } - while (simpleMovingAverageBreaks.isNotEmpty() && System.currentTimeMillis() - simpleMovingAverageBreaks.first() > 1000L * simpleMovingAverageRange) { - simpleMovingAverageBreaks.removeFirst() - } - while (simpleMovingAverageDistance.isNotEmpty() && System.currentTimeMillis() - simpleMovingAverageDistance.first() > 1000L * simpleMovingAverageRange) { - simpleMovingAverageDistance.removeFirst() - } + updateDequeues() } doPathing() @@ -408,6 +400,18 @@ internal object HighwayTools : Module( } } + private fun updateDequeues() { + while (simpleMovingAveragePlaces.isNotEmpty() && System.currentTimeMillis() - simpleMovingAveragePlaces.first() > 1000L * simpleMovingAverageRange) { + simpleMovingAveragePlaces.removeFirst() + } + while (simpleMovingAverageBreaks.isNotEmpty() && System.currentTimeMillis() - simpleMovingAverageBreaks.first() > 1000L * simpleMovingAverageRange) { + simpleMovingAverageBreaks.removeFirst() + } + while (simpleMovingAverageDistance.isNotEmpty() && System.currentTimeMillis() - simpleMovingAverageDistance.first() > 1000L * simpleMovingAverageRange) { + simpleMovingAverageDistance.removeFirst() + } + } + private fun SafeClientEvent.doRotation() { if (rotateTimer.tick(20L, false)) return val rotation = lastHitVec?.let { getRotationTo(it) } ?: return From 779dab104df87e98b732c2f1b528c23f6f731001 Mon Sep 17 00:00:00 2001 From: Christian Date: Sun, 7 Feb 2021 19:30:34 +0100 Subject: [PATCH 293/390] Setting descriptions --- .../module/modules/misc/HighwayTools.kt | 70 +++++++++---------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index fbc3e27bad..774df85477 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -79,8 +79,8 @@ internal object HighwayTools : Module( alias = arrayOf("HT", "HWT"), modulePriority = 10 ) { - private val mode by setting("Mode", Mode.HIGHWAY) - private val page by setting("Page", Page.BUILD) + private val mode by setting("Mode", Mode.HIGHWAY, description = "Choose the structure") + private val page by setting("Page", Page.BUILD, description = "Switch between the setting pages") val ignoreBlocks = linkedSetOf( Blocks.STANDING_SIGN, @@ -94,49 +94,49 @@ internal object HighwayTools : Module( ) // build settings - private val clearSpace by setting("Clear Space", true, { page == Page.BUILD && mode == Mode.HIGHWAY }, description = "Clears out the tunnel if necessary.") - private val width by setting("Width", 6, 1..11, 1, { page == Page.BUILD }, description = "Sets the width of blueprint.") - private val height by setting("Height", 4, 1..6, 1, { page == Page.BUILD && clearSpace }, description = "Sets height of blueprint.") - private val railing by setting("Railing", true, { page == Page.BUILD && mode == Mode.HIGHWAY }, description = "Adds a railing / rim / border to the highway.") - private val railingHeight by setting("Railing Height", 1, 1..4, 1, { railing && page == Page.BUILD && mode == Mode.HIGHWAY }, description = "Sets height of railing.") - private val cornerBlock by setting("Corner Block", false, { page == Page.BUILD && (mode == Mode.HIGHWAY || mode == Mode.TUNNEL) }, description = "If activated will break the corner in tunnel or place a corner while paving.") + private val clearSpace by setting("Clear Space", true, { page == Page.BUILD && mode == Mode.HIGHWAY }, description = "Clears out the tunnel if necessary") + private val width by setting("Width", 6, 1..11, 1, { page == Page.BUILD }, description = "Sets the width of blueprint") + private val height by setting("Height", 4, 1..6, 1, { page == Page.BUILD && clearSpace }, description = "Sets height of blueprint") + private val railing by setting("Railing", true, { page == Page.BUILD && mode == Mode.HIGHWAY }, description = "Adds a railing / rim / border to the highway") + private val railingHeight by setting("Railing Height", 1, 1..4, 1, { railing && page == Page.BUILD && mode == Mode.HIGHWAY }, description = "Sets height of railing") + private val cornerBlock by setting("Corner Block", false, { page == Page.BUILD && (mode == Mode.HIGHWAY || mode == Mode.TUNNEL) }, description = "If activated will break the corner in tunnel or place a corner while paving") // val ignoreBlocks = setting(CollectionSetting("IgnoreList", defaultIgnoreList, { false })) // behavior settings - private val interacting by setting("Rotation Mode", RotationMode.SPOOF, { page == Page.BEHAVIOR }, description = "Force view client side, only server side or no interaction at all.") + private val interacting by setting("Rotation Mode", RotationMode.SPOOF, { page == Page.BEHAVIOR }, description = "Force view client side, only server side or no interaction at all") private val dynamicDelay by setting("Dynamic Place Delay", true, { page == Page.BEHAVIOR }, description = "Slows down on failed placement attempts") - private var placeDelay by setting("Place Delay", 3, 1..20, 1, { page == Page.BEHAVIOR }, description = "Sets the delay ticks between placement tasks.") - private var breakDelay by setting("Break Delay", 1, 1..20, 1, { page == Page.BEHAVIOR }, description = "Sets the delay ticks between break tasks.") - private val illegalPlacements by setting("Illegal Placements", false, { page == Page.BEHAVIOR }, description = "Do not use on 2b2t. Tries to interact with invisible surfaces.") - private val bridging by setting("Bridging", true, { page == Page.BEHAVIOR }, description = "Tries to bridge / scaffold when stuck placing.") - private var placementSearch by setting("Place Deep Search", 1, 1..20, 1, { page == Page.BEHAVIOR }, description = "Attempts to find a support block for placing against.") - private val multiBuilding by setting("Shuffle Tasks", false, { page == Page.BEHAVIOR }, description = "Only activate when working with several players.") - private val maxBreaks by setting("Multi Break", 3, 1..8, 1, { page == Page.BEHAVIOR }, description = "Breaks multiple instant breaking blocks per tick in view.") - private val toggleInventoryManager by setting("Toggle InvManager", true, { page == Page.BEHAVIOR }, description = "Activates InventoryManager on enable.") - private val toggleAutoObsidian by setting("Toggle AutoObsidian", true, { page == Page.BEHAVIOR }, description = "Activates AutoObsidian on enable.") - private val taskTimeout by setting("Task Timeout", 8, 0..20, 1, { page == Page.BEHAVIOR }, description = "Timeout for waiting for the server to try again.") - private val rubberbandTimeout by setting("Rubberband Timeout", 50, 5..100, 5, { page == Page.BEHAVIOR }, description = "Timeout for pausing after a lag.") + private var placeDelay by setting("Place Delay", 3, 1..20, 1, { page == Page.BEHAVIOR }, description = "Sets the delay ticks between placement tasks") + private var breakDelay by setting("Break Delay", 1, 1..20, 1, { page == Page.BEHAVIOR }, description = "Sets the delay ticks between break tasks") + private val illegalPlacements by setting("Illegal Placements", false, { page == Page.BEHAVIOR }, description = "Do not use on 2b2t. Tries to interact with invisible surfaces") + private val bridging by setting("Bridging", true, { page == Page.BEHAVIOR }, description = "Tries to bridge / scaffold when stuck placing") + private var placementSearch by setting("Place Deep Search", 1, 1..20, 1, { page == Page.BEHAVIOR }, description = "Attempts to find a support block for placing against") + private val multiBuilding by setting("Shuffle Tasks", false, { page == Page.BEHAVIOR }, description = "Only activate when working with several players") + private val maxBreaks by setting("Multi Break", 3, 1..8, 1, { page == Page.BEHAVIOR }, description = "Breaks multiple instant breaking blocks per tick in view") + private val toggleInventoryManager by setting("Toggle InvManager", true, { page == Page.BEHAVIOR }, description = "Activates InventoryManager on enable") + private val toggleAutoObsidian by setting("Toggle AutoObsidian", true, { page == Page.BEHAVIOR }, description = "Activates AutoObsidian on enable") + private val taskTimeout by setting("Task Timeout", 8, 0..20, 1, { page == Page.BEHAVIOR }, description = "Timeout for waiting for the server to try again") + private val rubberbandTimeout by setting("Rubberband Timeout", 50, 5..100, 5, { page == Page.BEHAVIOR }, description = "Timeout for pausing after a lag") private val maxReach by setting("Max Reach", 4.9f, 1.0f..6.0f, 0.1f, { page == Page.BEHAVIOR }, description = "Sets the range of the blueprint. Decrease when tasks fail!") // stats private val anonymizeStats by setting("Anonymize", false, { page == Page.STATS }, description = "Censors all coordinates in HUD and Chat.") - private val simpleMovingAverageRange by setting("Simple Moving Average Seconds", 60f, 5f..600f, 5f, { page == Page.STATS }, description = "Sets the timeframe of the average.") - private val showPerformance by setting("Show Performance", true, { page == Page.STATS }, description = "Toggles the Performance section in HUD.") - private val showEnvironment by setting("Show Environment", true, { page == Page.STATS }, description = "Toggles the Environment section in HUD.") - private val showTask by setting("Show Task", true, { page == Page.STATS }, description = "Toggles the Task section in HUD.") - private val showEstimations by setting("Show Estimations", true, { page == Page.STATS }, description = "Toggles the Estimations section in HUD.") - private val resetStats = setting("Reset Stats", false, { page == Page.STATS }, description = "Resets the stats.") + private val simpleMovingAverageRange by setting("Simple Moving Average Seconds", 60f, 5f..600f, 5f, { page == Page.STATS }, description = "Sets the timeframe of the average") + private val showPerformance by setting("Show Performance", true, { page == Page.STATS }, description = "Toggles the Performance section in HUD") + private val showEnvironment by setting("Show Environment", true, { page == Page.STATS }, description = "Toggles the Environment section in HUD") + private val showTask by setting("Show Task", true, { page == Page.STATS }, description = "Toggles the Task section in HUD") + private val showEstimations by setting("Show Estimations", true, { page == Page.STATS }, description = "Toggles the Estimations section in HUD") + private val resetStats = setting("Reset Stats", false, { page == Page.STATS }, description = "Resets the stats") // config - private val fakeSounds by setting("Fake Sounds", true, { page == Page.CONFIG }, description = "Adds artificial sounds to the actions.") - private val info by setting("Show Info", true, { page == Page.CONFIG }, description = "Prints session stats in chat.") - private val printDebug by setting("Show Queue", false, { page == Page.CONFIG }, description = "Shows task queue in HUD.") - private val debugMessages by setting("Debug Messages", DebugMessages.IMPORTANT, { page == Page.CONFIG }, description = "Sets the debug log depth level.") - private val goalRender by setting("Goal Render", false, { page == Page.CONFIG }, description = "Renders the baritone goal.") - private val filled by setting("Filled", true, { page == Page.CONFIG }, description = "Renders colored task surfaces.") - private val outline by setting("Outline", true, { page == Page.CONFIG }, description = "Renders colored task outlines.") - private val aFilled by setting("Filled Alpha", 26, 0..255, 1, { filled && page == Page.CONFIG }, description = "Sets the opacity.") - private val aOutline by setting("Outline Alpha", 91, 0..255, 1, { outline && page == Page.CONFIG }, description = "Sets the opacity.") + private val fakeSounds by setting("Fake Sounds", true, { page == Page.CONFIG }, description = "Adds artificial sounds to the actions") + private val info by setting("Show Info", true, { page == Page.CONFIG }, description = "Prints session stats in chat") + private val printDebug by setting("Show Queue", false, { page == Page.CONFIG }, description = "Shows task queue in HUD") + private val debugMessages by setting("Debug Messages", DebugMessages.IMPORTANT, { page == Page.CONFIG }, description = "Sets the debug log depth level") + private val goalRender by setting("Goal Render", false, { page == Page.CONFIG }, description = "Renders the baritone goal") + private val filled by setting("Filled", true, { page == Page.CONFIG }, description = "Renders colored task surfaces") + private val outline by setting("Outline", true, { page == Page.CONFIG }, description = "Renders colored task outlines") + private val aFilled by setting("Filled Alpha", 26, 0..255, 1, { filled && page == Page.CONFIG }, description = "Sets the opacity") + private val aOutline by setting("Outline Alpha", 91, 0..255, 1, { outline && page == Page.CONFIG }, description = "Sets the opacity") private enum class Mode { HIGHWAY, FLAT, TUNNEL From 330d1c3c6f8276b6b16457ec9f2178cfad8275aa Mon Sep 17 00:00:00 2001 From: Christian Date: Sun, 7 Feb 2021 21:05:51 +0100 Subject: [PATCH 294/390] Better neighbours --- .../module/modules/misc/HighwayTools.kt | 52 ++++++++++++------- .../org/kamiblue/client/util/WorldUtils.kt | 38 +++++++++++++- 2 files changed, 69 insertions(+), 21 deletions(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index 774df85477..50d31554ee 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -44,6 +44,7 @@ import org.kamiblue.client.util.TickTimer import org.kamiblue.client.util.TimeUnit import org.kamiblue.client.util.WorldUtils import org.kamiblue.client.util.WorldUtils.blackList +import org.kamiblue.client.util.WorldUtils.getBetterNeighbour import org.kamiblue.client.util.WorldUtils.getMiningSide import org.kamiblue.client.util.WorldUtils.getNeighbour import org.kamiblue.client.util.WorldUtils.isLiquid @@ -692,6 +693,16 @@ internal object HighwayTools : Module( }.thenBy { it.stuckTicks / 5 }.thenBy { + when (it.taskState) { + TaskState.PLACE, TaskState.LIQUID_SOURCE, TaskState.LIQUID_FLOW -> { + getBetterNeighbour(it.blockPos, placementSearch, maxReach, true).size + } + TaskState.BREAK -> { // ToDo: Check for most block interceptions when kick issue solved + 0 + } + else -> 0 + } + }.thenBy { // ToDo: We need a function that makes a score out of those 3 parameters startingBlockPos.distanceTo(it.blockPos).toInt() / 2 }.thenBy { eyePos.distanceTo(it.blockPos) @@ -700,10 +711,6 @@ internal object HighwayTools : Module( } ) } - - - // ToDo: We need a function that makes a score out of last 3 parameters - nextInt() } private fun SafeClientEvent.checkStuckTimeout(blockTask: BlockTask): Boolean { @@ -972,27 +979,32 @@ internal object HighwayTools : Module( } private fun SafeClientEvent.placeBlock(blockTask: BlockTask) { - val pair = getNeighbour(blockTask.blockPos, placementSearch, maxReach, true) - ?: run { - if (illegalPlacements) { - if (debugMessages == DebugMessages.ALL) { - if (!anonymizeStats) { - MessageSendHelper.sendChatMessage("Trying to place through wall ${blockTask.blockPos}") - } else { - MessageSendHelper.sendChatMessage("Trying to place through wall") - } - } - getNeighbour(blockTask.blockPos, placementSearch, maxReach) ?: return + val neighbours = if (illegalPlacements) { + getBetterNeighbour(blockTask.blockPos, 1, maxReach) + } else { + getBetterNeighbour(blockTask.blockPos, placementSearch, maxReach, true) + } + + if (neighbours.isEmpty()) { + if (debugMessages == DebugMessages.ALL) { + if (!anonymizeStats) { + MessageSendHelper.sendChatMessage("No neighbours found for ${blockTask.blockPos}") } else { - blockTask.onStuck() - return + MessageSendHelper.sendChatMessage("No neighbours found") } } + blockTask.onStuck() + return + } else { + for (pair in neighbours) { + addTaskToPending(pair.second, TaskState.PLACE, fillerMat) + } - lastHitVec = WorldUtils.getHitVec(pair.second, pair.first) - rotateTimer.reset() + lastHitVec = WorldUtils.getHitVec(neighbours.last().second, neighbours.last().first) + rotateTimer.reset() - placeBlockNormal(blockTask, pair) + placeBlockNormal(blockTask, neighbours.last()) + } } private fun SafeClientEvent.placeBlockNormal(blockTask: BlockTask, pair: Pair) { diff --git a/src/main/kotlin/org/kamiblue/client/util/WorldUtils.kt b/src/main/kotlin/org/kamiblue/client/util/WorldUtils.kt index 19f1b209fa..e819d6eed6 100644 --- a/src/main/kotlin/org/kamiblue/client/util/WorldUtils.kt +++ b/src/main/kotlin/org/kamiblue/client/util/WorldUtils.kt @@ -20,6 +20,7 @@ import org.kamiblue.client.util.math.RotationUtils.getRotationTo import org.kamiblue.client.util.math.VectorUtils.toVec3dCenter import org.kamiblue.client.util.threads.runSafeSuspend import java.util.* +import kotlin.collections.ArrayList import kotlin.collections.HashSet import kotlin.math.floor @@ -247,7 +248,6 @@ object WorldUtils { if (attempts > 1) { toIgnore.add(blockPos) - HighwayTools.addTaskToPending(blockPos, HighwayTools.TaskState.LIQUID_SOURCE, HighwayTools.fillerMat) for (side in sides) { val pos = blockPos.offset(side) if (!isPlaceable(pos)) continue @@ -258,6 +258,42 @@ object WorldUtils { return null } + fun SafeClientEvent.getBetterNeighbour( + blockPos: BlockPos, + attempts: Int = 3, + range: Float = 4.25f, + visibleSideCheck: Boolean = false, + sides: Array = EnumFacing.values(), + toIgnore: HashSet = HashSet() + ): ArrayList> { + val eyePos = player.getPositionEyes(1.0f) + val candidates = arrayListOf>() + + for (side in sides) { + val offsetPos = blockPos.offset(side) + + if (!toIgnore.add(offsetPos)) continue + if (world.getBlockState(offsetPos).material.isReplaceable) continue + if (eyePos.distanceTo(getHitVec(blockPos, side)) > range) continue + if (visibleSideCheck && !getVisibleSides(offsetPos).contains(side.opposite)) continue + + candidates.add(Pair(side.opposite, offsetPos)) + return candidates + } + + if (attempts > 1 && candidates.isEmpty()) { + toIgnore.add(blockPos) + for (side in sides) { + val pos = blockPos.offset(side) + if (!isPlaceable(pos)) continue + candidates.addAll(getBetterNeighbour(pos, attempts - 1, range, visibleSideCheck, sides, toIgnore)) + return candidates + } + } + + return candidates + } + /** * Placing function for multithreading only */ From eb66a21468a9daec17648d9b0c54df0a4960d76a Mon Sep 17 00:00:00 2001 From: Christian Date: Sun, 7 Feb 2021 23:01:12 +0100 Subject: [PATCH 295/390] Fix logic --- .../org/kamiblue/client/module/modules/misc/HighwayTools.kt | 2 +- src/main/kotlin/org/kamiblue/client/util/WorldUtils.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index 50d31554ee..3ddf28aaba 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -997,7 +997,7 @@ internal object HighwayTools : Module( return } else { for (pair in neighbours) { - addTaskToPending(pair.second, TaskState.PLACE, fillerMat) + if (pair != neighbours.last()) addTaskToPending(pair.second, TaskState.PLACE, fillerMat) } lastHitVec = WorldUtils.getHitVec(neighbours.last().second, neighbours.last().first) diff --git a/src/main/kotlin/org/kamiblue/client/util/WorldUtils.kt b/src/main/kotlin/org/kamiblue/client/util/WorldUtils.kt index e819d6eed6..3ed6e10f02 100644 --- a/src/main/kotlin/org/kamiblue/client/util/WorldUtils.kt +++ b/src/main/kotlin/org/kamiblue/client/util/WorldUtils.kt @@ -281,7 +281,7 @@ object WorldUtils { return candidates } - if (attempts > 1 && candidates.isEmpty()) { + if (attempts > 1) { toIgnore.add(blockPos) for (side in sides) { val pos = blockPos.offset(side) From 9b7e16f07d9768b330e1ef759c2f0c55d9b429c4 Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Mon, 8 Feb 2021 03:54:35 -0500 Subject: [PATCH 296/390] Removed random cross usages --- .../org/kamiblue/client/module/modules/misc/HighwayTools.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index 3ddf28aaba..e59535ca23 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -1343,7 +1343,7 @@ internal object HighwayTools : Module( // ToDo: Cache shulker count // val pavingLeftAll = (materialLeft + indirectMaterialLeft) / ((totalBlocksPlaced + 0.001) / (distanceDone + 0.001)) - val secLeft = (pavingLeft - AutoObsidian.threshold).coerceAtLeast(0.0) / (startingBlockPos.distanceTo(currentBlockPos).toInt() / runtimeSec) + val secLeft = (pavingLeft).coerceAtLeast(0.0) / (startingBlockPos.distanceTo(currentBlockPos).toInt() / runtimeSec) val secondsLeft = (secLeft % 60).toInt().toString().padStart(2, '0') val minutesLeft = ((secLeft % 3600) / 60).toInt().toString().padStart(2, '0') val hoursLeft = (secLeft / 3600).toInt().toString().padStart(2, '0') From 5c8201a9231ca113d8920ae135a0d22c1c53aba7 Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Mon, 8 Feb 2021 17:46:13 -0500 Subject: [PATCH 297/390] Use isFullBox to check the visible/mining side. isFullCube is a troll --- src/main/kotlin/org/kamiblue/client/util/WorldUtils.kt | 10 +++++----- .../kotlin/org/kamiblue/client/util/items/Block.kt | 10 +++++++++- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/org/kamiblue/client/util/WorldUtils.kt b/src/main/kotlin/org/kamiblue/client/util/WorldUtils.kt index 3ed6e10f02..8077be38ff 100644 --- a/src/main/kotlin/org/kamiblue/client/util/WorldUtils.kt +++ b/src/main/kotlin/org/kamiblue/client/util/WorldUtils.kt @@ -15,7 +15,7 @@ import net.minecraft.util.math.RayTraceResult import net.minecraft.util.math.Vec3d import org.kamiblue.client.event.SafeClientEvent import org.kamiblue.client.manager.managers.PlayerPacketManager -import org.kamiblue.client.module.modules.misc.HighwayTools +import org.kamiblue.client.util.items.isFullBox import org.kamiblue.client.util.math.RotationUtils.getRotationTo import org.kamiblue.client.util.math.VectorUtils.toVec3dCenter import org.kamiblue.client.util.threads.runSafeSuspend @@ -138,7 +138,7 @@ object WorldUtils { val eyePos = player.getPositionEyes(1.0f) return getVisibleSides(pos) - .filter { !world.getBlockState(pos.offset(it)).isFullCube } + .filter { !world.getBlockState(pos.offset(it)).isFullBox } .minByOrNull { eyePos.distanceTo(getHitVec(pos, it)) } } @@ -150,14 +150,14 @@ object WorldUtils { fun SafeClientEvent.getVisibleSides(pos: BlockPos): Set { val visibleSides = EnumSet.noneOf(EnumFacing::class.java) - val isFullCube = world.getBlockState(pos).isFullCube + val isFullBox = world.getBlockState(pos).isFullBox val eyePos = player.getPositionEyes(1.0f) val blockCenter = pos.toVec3dCenter() return visibleSides - .checkAxis(eyePos.x - blockCenter.x, EnumFacing.WEST, EnumFacing.EAST, !isFullCube) + .checkAxis(eyePos.x - blockCenter.x, EnumFacing.WEST, EnumFacing.EAST, !isFullBox) .checkAxis(eyePos.y - blockCenter.y, EnumFacing.DOWN, EnumFacing.UP, true) - .checkAxis(eyePos.z - blockCenter.z, EnumFacing.NORTH, EnumFacing.SOUTH, !isFullCube) + .checkAxis(eyePos.z - blockCenter.z, EnumFacing.NORTH, EnumFacing.SOUTH, !isFullBox) } private fun EnumSet.checkAxis(diff: Double, negativeSide: EnumFacing, positiveSide: EnumFacing, bothIfInRange: Boolean) = diff --git a/src/main/kotlin/org/kamiblue/client/util/items/Block.kt b/src/main/kotlin/org/kamiblue/client/util/items/Block.kt index dc98e347cb..20521b3c49 100644 --- a/src/main/kotlin/org/kamiblue/client/util/items/Block.kt +++ b/src/main/kotlin/org/kamiblue/client/util/items/Block.kt @@ -1,8 +1,16 @@ package org.kamiblue.client.util.items import net.minecraft.block.Block +import net.minecraft.block.state.IBlockState import net.minecraft.item.Item +import net.minecraft.util.math.BlockPos +import org.kamiblue.client.util.Wrapper val Block.item: Item get() = Item.getItemFromBlock(this) -val Block.id: Int get() = Block.getIdFromBlock(this) \ No newline at end of file +val Block.id: Int get() = Block.getIdFromBlock(this) + +val IBlockState.isFullBox: Boolean + get() = Wrapper.world?.let { + this.getBoundingBox(it, BlockPos.ORIGIN) + } == Block.FULL_BLOCK_AABB \ No newline at end of file From 0d3ecd34230311be27479fe01969c91b23848fd6 Mon Sep 17 00:00:00 2001 From: Christian Date: Mon, 8 Feb 2021 23:54:38 +0100 Subject: [PATCH 298/390] Fix bridge and better defaults --- .../module/modules/misc/AutoObsidian.kt | 4 ++-- .../module/modules/misc/HighwayTools.kt | 22 +++++++------------ 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/AutoObsidian.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/AutoObsidian.kt index 8b1591008a..ef5a372b13 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/AutoObsidian.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/AutoObsidian.kt @@ -66,12 +66,12 @@ internal object AutoObsidian : Module( private val leaveEmptyShulkers by setting("Leave Empty Shulkers", true, { searchShulker }) private val autoRefill by setting("Auto Refill", false, { fillMode != FillMode.INFINITE }) private val instantMining by setting("Instant Mining", true) - private val instantMiningDelay by setting("Instant Mining Delay", 10, 1..20, 1, { instantMining }) + private val instantMiningDelay by setting("Instant Mining Delay", 5, 1..20, 1, { instantMining }) private val threshold by setting("Refill Threshold", 32, 1..64, 1, { autoRefill && fillMode != FillMode.INFINITE }) private val targetStacks by setting("Target Stacks", 1, 1..20, 1, { fillMode == FillMode.TARGET_STACKS }) private val delayTicks by setting("Delay Ticks", 5, 1..10, 1) private val rotationMode by setting("Rotation Mode", RotationMode.SPOOF) - private val maxReach by setting("Max Reach", 4.5f, 2.0f..6.0f, 0.1f) + private val maxReach by setting("Max Reach", 4.9f, 2.0f..6.0f, 0.1f) private enum class FillMode(override val displayName: String, val message: String) : DisplayEnum { TARGET_STACKS("Target Stacks", "Target stacks reached"), diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index e59535ca23..40adbdf3fa 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -46,9 +46,9 @@ import org.kamiblue.client.util.WorldUtils import org.kamiblue.client.util.WorldUtils.blackList import org.kamiblue.client.util.WorldUtils.getBetterNeighbour import org.kamiblue.client.util.WorldUtils.getMiningSide -import org.kamiblue.client.util.WorldUtils.getNeighbour import org.kamiblue.client.util.WorldUtils.isLiquid import org.kamiblue.client.util.WorldUtils.isPlaceable +import org.kamiblue.client.util.WorldUtils.shulkerList import org.kamiblue.client.util.color.ColorHolder import org.kamiblue.client.util.graphics.ESPRenderer import org.kamiblue.client.util.graphics.font.TextComponent @@ -110,10 +110,10 @@ internal object HighwayTools : Module( private var breakDelay by setting("Break Delay", 1, 1..20, 1, { page == Page.BEHAVIOR }, description = "Sets the delay ticks between break tasks") private val illegalPlacements by setting("Illegal Placements", false, { page == Page.BEHAVIOR }, description = "Do not use on 2b2t. Tries to interact with invisible surfaces") private val bridging by setting("Bridging", true, { page == Page.BEHAVIOR }, description = "Tries to bridge / scaffold when stuck placing") - private var placementSearch by setting("Place Deep Search", 1, 1..20, 1, { page == Page.BEHAVIOR }, description = "Attempts to find a support block for placing against") + private var placementSearch by setting("Place Deep Search", 2, 1..20, 1, { page == Page.BEHAVIOR }, description = "Attempts to find a support block for placing against") private val multiBuilding by setting("Shuffle Tasks", false, { page == Page.BEHAVIOR }, description = "Only activate when working with several players") private val maxBreaks by setting("Multi Break", 3, 1..8, 1, { page == Page.BEHAVIOR }, description = "Breaks multiple instant breaking blocks per tick in view") - private val toggleInventoryManager by setting("Toggle InvManager", true, { page == Page.BEHAVIOR }, description = "Activates InventoryManager on enable") + private val toggleInventoryManager by setting("Toggle InvManager", false, { page == Page.BEHAVIOR }, description = "Activates InventoryManager on enable") private val toggleAutoObsidian by setting("Toggle AutoObsidian", true, { page == Page.BEHAVIOR }, description = "Activates AutoObsidian on enable") private val taskTimeout by setting("Task Timeout", 8, 0..20, 1, { page == Page.BEHAVIOR }, description = "Timeout for waiting for the server to try again") private val rubberbandTimeout by setting("Rubberband Timeout", 50, 5..100, 5, { page == Page.BEHAVIOR }, description = "Timeout for pausing after a lag") @@ -209,6 +209,8 @@ internal object HighwayTools : Module( } init { + ignoreBlocks.addAll(shulkerList) + onEnable { runSafeR { /* Turn on inventory manager if the users wants us to control it */ @@ -509,7 +511,7 @@ internal object HighwayTools : Module( val eyePos = player.getPositionEyes(1f) blueprint.keys.removeIf { - eyePos.distanceTo(it) > maxReach - 0.3 + eyePos.distanceTo(it) > maxReach - 0.7 } } @@ -980,7 +982,7 @@ internal object HighwayTools : Module( private fun SafeClientEvent.placeBlock(blockTask: BlockTask) { val neighbours = if (illegalPlacements) { - getBetterNeighbour(blockTask.blockPos, 1, maxReach) + getBetterNeighbour(blockTask.blockPos, placementSearch, maxReach) } else { getBetterNeighbour(blockTask.blockPos, placementSearch, maxReach, true) } @@ -1046,9 +1048,7 @@ internal object HighwayTools : Module( for (task in sortedTasks) { if (task.taskState == TaskState.PLACE) { containsPlace = true - getNeighbour(task.blockPos, placementSearch, maxReach, true) - ?: continue - return false + if (getBetterNeighbour(task.blockPos, placementSearch, maxReach, true).isNotEmpty()) return false } } return containsPlace @@ -1133,10 +1133,6 @@ internal object HighwayTools : Module( } private fun SafeClientEvent.mineBlock(blockTask: BlockTask) { - if (blockTask.blockPos == player.flooredPosition.down()) { - blockTask.updateState(TaskState.DONE) - return - } /* For fire, we just need to mine the top of the block below the fire */ /* ToDo: This will not work if the top of the block which the fire is on is not visible */ @@ -1272,8 +1268,6 @@ internal object HighwayTools : Module( // displayText.addLine("by Constructor#9948 aka Avanatiker", primaryColor) -// MessageSendHelper.sendChatMessage(StatList.MINE_BLOCK_STATS.toString()) - if (printDebug) { displayText.addLine("Pending", primaryColor) addTaskComponentList(displayText, sortedTasks) From 42e34b083161d1ef1a58b5a0eb41da18b76822c7 Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 9 Feb 2021 00:26:31 +0100 Subject: [PATCH 299/390] Fix reaction time on bridge --- .../org/kamiblue/client/module/modules/misc/AutoObsidian.kt | 4 ++-- .../org/kamiblue/client/module/modules/misc/HighwayTools.kt | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/AutoObsidian.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/AutoObsidian.kt index ef5a372b13..34e5d0b355 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/AutoObsidian.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/AutoObsidian.kt @@ -66,10 +66,10 @@ internal object AutoObsidian : Module( private val leaveEmptyShulkers by setting("Leave Empty Shulkers", true, { searchShulker }) private val autoRefill by setting("Auto Refill", false, { fillMode != FillMode.INFINITE }) private val instantMining by setting("Instant Mining", true) - private val instantMiningDelay by setting("Instant Mining Delay", 5, 1..20, 1, { instantMining }) + private val instantMiningDelay by setting("Instant Mining Delay", 10, 1..20, 1, { instantMining }) private val threshold by setting("Refill Threshold", 32, 1..64, 1, { autoRefill && fillMode != FillMode.INFINITE }) private val targetStacks by setting("Target Stacks", 1, 1..20, 1, { fillMode == FillMode.TARGET_STACKS }) - private val delayTicks by setting("Delay Ticks", 5, 1..10, 1) + private val delayTicks by setting("Delay Ticks", 4, 1..10, 1) private val rotationMode by setting("Rotation Mode", RotationMode.SPOOF) private val maxReach by setting("Max Reach", 4.9f, 2.0f..6.0f, 0.1f) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index 40adbdf3fa..6f81199cbf 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -995,7 +995,7 @@ internal object HighwayTools : Module( MessageSendHelper.sendChatMessage("No neighbours found") } } - blockTask.onStuck() + blockTask.stuck(20) return } else { for (pair in neighbours) { @@ -1435,6 +1435,10 @@ internal object HighwayTools : Module( stuckTicks++ } + fun stuck(weight: Int) { + stuckTicks += weight + } + fun shuffle() { shuffle = nextInt(0, 1000) } From 3e450821bd4fe5e1ea4859583f5df2c190916858 Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Mon, 8 Feb 2021 18:53:20 -0500 Subject: [PATCH 300/390] Removed inappropriate runBlocking usage --- .../client/module/modules/misc/HighwayTools.kt | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index 6f81199cbf..dd930ebfc6 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -3,7 +3,6 @@ package org.kamiblue.client.module.modules.misc import baritone.api.pathing.goals.GoalNear import kotlinx.coroutines.delay import kotlinx.coroutines.launch -import kotlinx.coroutines.runBlocking import net.minecraft.block.Block import net.minecraft.block.BlockLiquid import net.minecraft.client.audio.PositionedSoundRecord @@ -1219,13 +1218,11 @@ internal object HighwayTools : Module( } } - private fun sendMiningPackets(pos: BlockPos, side: EnumFacing) { - runBlocking { - onMainThreadSafe { - connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, pos, side)) - connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, pos, side)) - player.swingArm(EnumHand.MAIN_HAND) - } + private suspend fun sendMiningPackets(pos: BlockPos, side: EnumFacing) { + onMainThreadSafe { + connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, pos, side)) + connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, pos, side)) + player.swingArm(EnumHand.MAIN_HAND) } } From ff3a17ac39c767ba4b551e2206c81ca7351fbbec Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 9 Feb 2021 01:11:55 +0100 Subject: [PATCH 301/390] Rename option --- .../org/kamiblue/client/module/modules/misc/HighwayTools.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index dd930ebfc6..c59e0074f3 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -120,7 +120,7 @@ internal object HighwayTools : Module( // stats private val anonymizeStats by setting("Anonymize", false, { page == Page.STATS }, description = "Censors all coordinates in HUD and Chat.") - private val simpleMovingAverageRange by setting("Simple Moving Average Seconds", 60f, 5f..600f, 5f, { page == Page.STATS }, description = "Sets the timeframe of the average") + private val simpleMovingAverageRange by setting("Rolling Average", 60f, 5f..600f, 5f, { page == Page.STATS }, description = "Sets the timeframe of the average in secconds") private val showPerformance by setting("Show Performance", true, { page == Page.STATS }, description = "Toggles the Performance section in HUD") private val showEnvironment by setting("Show Environment", true, { page == Page.STATS }, description = "Toggles the Environment section in HUD") private val showTask by setting("Show Task", true, { page == Page.STATS }, description = "Toggles the Task section in HUD") From a69e9e989ec7ce82939b7467f25ffe94c6b09d96 Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 9 Feb 2021 01:17:57 +0100 Subject: [PATCH 302/390] Fix spelling --- .../org/kamiblue/client/module/modules/misc/HighwayTools.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index c59e0074f3..2258413603 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -120,7 +120,7 @@ internal object HighwayTools : Module( // stats private val anonymizeStats by setting("Anonymize", false, { page == Page.STATS }, description = "Censors all coordinates in HUD and Chat.") - private val simpleMovingAverageRange by setting("Rolling Average", 60f, 5f..600f, 5f, { page == Page.STATS }, description = "Sets the timeframe of the average in secconds") + private val simpleMovingAverageRange by setting("Moving Average", 60f, 5f..600f, 5f, { page == Page.STATS }, description = "Sets the timeframe of the average in seconds") private val showPerformance by setting("Show Performance", true, { page == Page.STATS }, description = "Toggles the Performance section in HUD") private val showEnvironment by setting("Show Environment", true, { page == Page.STATS }, description = "Toggles the Environment section in HUD") private val showTask by setting("Show Task", true, { page == Page.STATS }, description = "Toggles the Task section in HUD") From cad288d103f0be308aaddbb923f6c0923f6b43d4 Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Mon, 8 Feb 2021 19:34:12 -0500 Subject: [PATCH 303/390] Fixed isFullBox --- src/main/kotlin/org/kamiblue/client/util/items/Block.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/org/kamiblue/client/util/items/Block.kt b/src/main/kotlin/org/kamiblue/client/util/items/Block.kt index 20521b3c49..aa24c5c831 100644 --- a/src/main/kotlin/org/kamiblue/client/util/items/Block.kt +++ b/src/main/kotlin/org/kamiblue/client/util/items/Block.kt @@ -12,5 +12,5 @@ val Block.id: Int get() = Block.getIdFromBlock(this) val IBlockState.isFullBox: Boolean get() = Wrapper.world?.let { - this.getBoundingBox(it, BlockPos.ORIGIN) + this.getCollisionBoundingBox(it, BlockPos.ORIGIN) } == Block.FULL_BLOCK_AABB \ No newline at end of file From 3963b3cee81f3938a58343ff933f0256558da899 Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 9 Feb 2021 01:55:06 +0100 Subject: [PATCH 304/390] Path fix and module warnings --- .../client/module/modules/misc/HighwayTools.kt | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index 2258413603..8110e0394f 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -34,6 +34,8 @@ import org.kamiblue.client.module.Category import org.kamiblue.client.module.Module import org.kamiblue.client.module.modules.client.Hud.primaryColor import org.kamiblue.client.module.modules.client.Hud.secondaryColor +import org.kamiblue.client.module.modules.movement.AntiHunger +import org.kamiblue.client.module.modules.movement.Velocity import org.kamiblue.client.module.modules.player.AutoEat import org.kamiblue.client.module.modules.player.InventoryManager import org.kamiblue.client.process.HighwayToolsProcess @@ -290,6 +292,15 @@ internal object HighwayTools : Module( if (startingBlockPos.y != 120 && mode != Mode.TUNNEL) { MessageSendHelper.sendRawChatMessage(" §9> §cCheck altitude and make sure to build at Y: 120 for the correct height") } + + if (AntiHunger.isEnabled) { + MessageSendHelper.sendRawChatMessage(" §9> §cAntiHunger does slow down block interactions.") + } + + if (multiBuilding && Velocity.isDisabled) { + MessageSendHelper.sendRawChatMessage(" §9> §cMake sure to enable Velocity to not get pushed from your mates.") + } + } } @@ -580,7 +591,7 @@ internal object HighwayTools : Module( } } - fun addTaskToPending(blockPos: BlockPos, taskState: TaskState, material: Block) { + private fun addTaskToPending(blockPos: BlockPos, taskState: TaskState, material: Block) { pendingTasks[blockPos] = (BlockTask(blockPos, taskState, material)) } @@ -621,7 +632,7 @@ internal object HighwayTools : Module( private fun isTaskDoneOrNull(pos: BlockPos) = (pendingTasks[pos] ?: doneTasks[pos])?.let { it.taskState == TaskState.DONE - } ?: true + } ?: false private fun checkTasks(pos: BlockPos): Boolean { return pendingTasks.values.all { From 1e4b75cd1b2df0d94b53b5fea32abc82e78ebd96 Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 9 Feb 2021 03:14:46 +0100 Subject: [PATCH 305/390] Fixed liquid handler --- .../module/modules/misc/HighwayTools.kt | 40 ++++++++++--------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index 8110e0394f..e388b4ae03 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -997,25 +997,29 @@ internal object HighwayTools : Module( getBetterNeighbour(blockTask.blockPos, placementSearch, maxReach, true) } - if (neighbours.isEmpty()) { - if (debugMessages == DebugMessages.ALL) { - if (!anonymizeStats) { - MessageSendHelper.sendChatMessage("No neighbours found for ${blockTask.blockPos}") - } else { - MessageSendHelper.sendChatMessage("No neighbours found") + when (neighbours.size) { + 0 -> { + if (debugMessages == DebugMessages.ALL) { + if (!anonymizeStats) { + MessageSendHelper.sendChatMessage("No neighbours found for ${blockTask.blockPos}") + } else { + MessageSendHelper.sendChatMessage("No neighbours found") + } } + blockTask.stuck(20) + return } - blockTask.stuck(20) - return - } else { - for (pair in neighbours) { - if (pair != neighbours.last()) addTaskToPending(pair.second, TaskState.PLACE, fillerMat) - } - - lastHitVec = WorldUtils.getHitVec(neighbours.last().second, neighbours.last().first) - rotateTimer.reset() + 1 -> { + lastHitVec = WorldUtils.getHitVec(neighbours.last().second, neighbours.last().first) + rotateTimer.reset() - placeBlockNormal(blockTask, neighbours.last()) + placeBlockNormal(blockTask, neighbours.last()) + } + else -> { + for (pair in neighbours) { + addTaskToPending(pair.second, TaskState.PLACE, fillerMat) + } + } } } @@ -1133,8 +1137,8 @@ internal object HighwayTools : Module( } } else { for (triple in found) { - blockTask.updateState(triple.second) - blockTask.updateMaterial(triple.third) + triple.first.updateState(triple.second) + triple.first.updateMaterial(triple.third) } } } From ec80f914476668caec627c321ae6af08aa59543f Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 9 Feb 2021 03:24:45 +0100 Subject: [PATCH 306/390] Make deep search optional --- .../org/kamiblue/client/module/modules/misc/HighwayTools.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index e388b4ae03..73bc049b1e 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -111,7 +111,7 @@ internal object HighwayTools : Module( private var breakDelay by setting("Break Delay", 1, 1..20, 1, { page == Page.BEHAVIOR }, description = "Sets the delay ticks between break tasks") private val illegalPlacements by setting("Illegal Placements", false, { page == Page.BEHAVIOR }, description = "Do not use on 2b2t. Tries to interact with invisible surfaces") private val bridging by setting("Bridging", true, { page == Page.BEHAVIOR }, description = "Tries to bridge / scaffold when stuck placing") - private var placementSearch by setting("Place Deep Search", 2, 1..20, 1, { page == Page.BEHAVIOR }, description = "Attempts to find a support block for placing against") + private var placementSearch by setting("Place Deep Search", 1, 1..20, 1, { page == Page.BEHAVIOR }, description = "Attempts to find a support block for placing against") private val multiBuilding by setting("Shuffle Tasks", false, { page == Page.BEHAVIOR }, description = "Only activate when working with several players") private val maxBreaks by setting("Multi Break", 3, 1..8, 1, { page == Page.BEHAVIOR }, description = "Breaks multiple instant breaking blocks per tick in view") private val toggleInventoryManager by setting("Toggle InvManager", false, { page == Page.BEHAVIOR }, description = "Activates InventoryManager on enable") From fe4ee066bd0ad9a90287d27ee6a92c13f96235c7 Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 9 Feb 2021 03:32:21 +0100 Subject: [PATCH 307/390] Better stuck value for placements --- .../org/kamiblue/client/module/modules/misc/HighwayTools.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index 73bc049b1e..3bd493769d 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -1006,7 +1006,7 @@ internal object HighwayTools : Module( MessageSendHelper.sendChatMessage("No neighbours found") } } - blockTask.stuck(20) + blockTask.stuck(21) return } 1 -> { From 5684850671ad5c0fc7aaaa1552e663e46c37b5d3 Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 9 Feb 2021 03:40:33 +0100 Subject: [PATCH 308/390] Bump v10 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 1787855500..7ae2e6ad1c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ org.gradle.jvmargs=-Xmx3G modGroup=org.kamiblue -modVersion=2.02.xx-dev-ht-v09 +modVersion=2.02.xx-dev-ht-v10 kotlin_version=1.4.30 kotlinx_coroutines_version=1.4.2 \ No newline at end of file From 074dc02c61e1caa08f57c73c68e82f5bfa8e27a4 Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 9 Feb 2021 04:44:09 +0100 Subject: [PATCH 309/390] Fix on dynamic delay off --- .../client/module/modules/misc/HighwayTools.kt | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index 3bd493769d..46f757cac4 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -1027,7 +1027,11 @@ internal object HighwayTools : Module( val hitVecOffset = WorldUtils.getHitVecOffset(pair.first) val currentBlock = world.getBlockState(pair.second).block - waitTicks = placeDelay + extraPlaceDelay + waitTicks = if (dynamicDelay) { + placeDelay + extraPlaceDelay + } else { + placeDelay + } blockTask.updateState(TaskState.PENDING_PLACE) if (currentBlock in blackList) { @@ -1320,7 +1324,11 @@ internal object HighwayTools : Module( displayText.add(" Materials:", primaryColor) displayText.addLine("Main(${material.localizedName}) Filler(${fillerMat.localizedName})", secondaryColor) displayText.add(" Delays:", primaryColor) - displayText.addLine("Place(${placeDelay + extraPlaceDelay}) Break($breakDelay)", secondaryColor) + if (dynamicDelay) { + displayText.addLine("Place(${placeDelay + extraPlaceDelay}) Break($breakDelay)", secondaryColor) + } else { + displayText.addLine("Place($placeDelay) Break($breakDelay)", secondaryColor) + } } private fun gatherTask(displayText: TextComponent) { From e2978032e04a8f2ae7e6488eef51de972834ed98 Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 9 Feb 2021 23:34:58 +0100 Subject: [PATCH 310/390] Attempt to fix random stucks --- .../org/kamiblue/client/module/modules/misc/HighwayTools.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index 46f757cac4..762fd61abe 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -636,7 +636,7 @@ internal object HighwayTools : Module( private fun checkTasks(pos: BlockPos): Boolean { return pendingTasks.values.all { - it.taskState == TaskState.DONE || pos.distanceTo(it.blockPos) < maxReach - 1.0 + it.taskState == TaskState.DONE || pos.distanceTo(it.blockPos) < maxReach - 0.7 } } From 6a1001b5c792984ce16a89952d8a579dd4934ee5 Mon Sep 17 00:00:00 2001 From: Christian Date: Wed, 10 Feb 2021 09:40:03 +0100 Subject: [PATCH 311/390] Fix random stucks, add no tool disable and queue --- .../module/modules/misc/HighwayTools.kt | 32 +++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index 762fd61abe..74d9aabcda 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -9,6 +9,7 @@ import net.minecraft.client.audio.PositionedSoundRecord import net.minecraft.enchantment.EnchantmentHelper import net.minecraft.init.Blocks import net.minecraft.init.Enchantments +import net.minecraft.init.Items import net.minecraft.init.SoundEvents import net.minecraft.inventory.Slot import net.minecraft.item.ItemBlock @@ -119,6 +120,7 @@ internal object HighwayTools : Module( private val taskTimeout by setting("Task Timeout", 8, 0..20, 1, { page == Page.BEHAVIOR }, description = "Timeout for waiting for the server to try again") private val rubberbandTimeout by setting("Rubberband Timeout", 50, 5..100, 5, { page == Page.BEHAVIOR }, description = "Timeout for pausing after a lag") private val maxReach by setting("Max Reach", 4.9f, 1.0f..6.0f, 0.1f, { page == Page.BEHAVIOR }, description = "Sets the range of the blueprint. Decrease when tasks fail!") + private val emptyDisable by setting("Disable on no tool", false, { page == Page.BEHAVIOR }, description = "Disables module when pickaxes are out") // stats private val anonymizeStats by setting("Anonymize", false, { page == Page.STATS }, description = "Censors all coordinates in HUD and Chat.") @@ -367,9 +369,10 @@ internal object HighwayTools : Module( if (!rubberbandTimer.tick(rubberbandTimeout.toLong(), false) || AutoObsidian.isActive() || - AutoEat.eating) { - refreshData() - return@safeListener + AutoEat.eating || + player.isCreative && player.serverBrand.contains("2b2t")) { + refreshData() + return@safeListener } if (!active) { @@ -614,9 +617,9 @@ internal object HighwayTools : Module( val possiblePos = currentBlockPos.add(startingDirection.directionVec) - if (!isTaskDoneOrNull(possiblePos) || - !isTaskDoneOrNull(possiblePos.up()) || - !isTaskDoneOrNull(possiblePos.down())) return nextPos + if (!isTaskDoneOrNull(possiblePos, false) || + !isTaskDoneOrNull(possiblePos.up(), false) || + !isTaskDoneOrNull(possiblePos.down(), true)) return nextPos if (checkTasks(possiblePos.up())) nextPos = possiblePos @@ -628,11 +631,16 @@ internal object HighwayTools : Module( return nextPos } - // ToDo: Check correctly if not in blueprint to avoid baritone stuck - private fun isTaskDoneOrNull(pos: BlockPos) = + private fun SafeClientEvent.isTaskDoneOrNull(pos: BlockPos, solid: Boolean) = (pendingTasks[pos] ?: doneTasks[pos])?.let { it.taskState == TaskState.DONE - } ?: false + } ?: run { + if (solid) { + !isPlaceable(pos, true) + } else { + world.isAirBlock(pos) + } + } private fun checkTasks(pos: BlockPos): Boolean { return pendingTasks.values.all { @@ -1096,6 +1104,11 @@ internal object HighwayTools : Module( val slotFrom = getBestTool(blockTask) return if (slotFrom != null) { + if (emptyDisable && slotFrom.stack.item != Items.DIAMOND_PICKAXE) { + MessageSendHelper.sendChatMessage("$chatName No ${Items.DIAMOND_PICKAXE} was found in inventory, disable") + mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) + disable() + } slotFrom.toHotbarSlotOrNull()?.let { swapToSlot(it) } ?: run { @@ -1271,6 +1284,7 @@ internal object HighwayTools : Module( val runtimeSec = (runtimeMilliSeconds / 1000) + 0.0001 val distanceDone = startingBlockPos.distanceTo(currentBlockPos).toInt() + totalDistance + // val statList = Gson().fromJson(StatList.MINE_BLOCK_STATS[0], Any::class.java) // MessageSendHelper.sendChatMessage(statList) From 06154680d6986ca37a7a1dd95d0fe1b670d7fbd9 Mon Sep 17 00:00:00 2001 From: Christian Date: Fri, 12 Feb 2021 13:17:42 +0100 Subject: [PATCH 312/390] Better fire edge case handling --- .../client/module/modules/misc/HighwayTools.kt | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index 74d9aabcda..a9d2098864 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -48,6 +48,7 @@ import org.kamiblue.client.util.WorldUtils import org.kamiblue.client.util.WorldUtils.blackList import org.kamiblue.client.util.WorldUtils.getBetterNeighbour import org.kamiblue.client.util.WorldUtils.getMiningSide +import org.kamiblue.client.util.WorldUtils.getVisibleSides import org.kamiblue.client.util.WorldUtils.isLiquid import org.kamiblue.client.util.WorldUtils.isPlaceable import org.kamiblue.client.util.WorldUtils.shulkerList @@ -1169,9 +1170,13 @@ internal object HighwayTools : Module( /* ToDo: This will not work if the top of the block which the fire is on is not visible */ if (blockTask.block == Blocks.FIRE) { val blockBelowFire = blockTask.blockPos.down() - playerController.clickBlock(blockBelowFire, EnumFacing.UP) - player.swingArm(EnumHand.MAIN_HAND) - blockTask.updateState(TaskState.BREAKING) + if (getVisibleSides(blockBelowFire).contains(EnumFacing.UP)) { + playerController.clickBlock(blockBelowFire, EnumFacing.UP) + player.swingArm(EnumHand.MAIN_HAND) + blockTask.updateState(TaskState.BREAKING) + } else { + blockTask.updateState(TaskState.LIQUID_FLOW) + } return } From 8f22479bcc4ce23475969e22165ed6a2b5303963 Mon Sep 17 00:00:00 2001 From: Christian Date: Fri, 12 Feb 2021 13:24:42 +0100 Subject: [PATCH 313/390] Command alias --- .../org/kamiblue/client/command/commands/HighwayToolsCommand.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/org/kamiblue/client/command/commands/HighwayToolsCommand.kt b/src/main/kotlin/org/kamiblue/client/command/commands/HighwayToolsCommand.kt index ec5aa8c993..a65d171ce9 100644 --- a/src/main/kotlin/org/kamiblue/client/command/commands/HighwayToolsCommand.kt +++ b/src/main/kotlin/org/kamiblue/client/command/commands/HighwayToolsCommand.kt @@ -6,7 +6,7 @@ import org.kamiblue.client.util.text.MessageSendHelper object HighwayToolsCommand : ClientCommand( name = "highwaytools", - alias = arrayOf("ht"), + alias = arrayOf("ht", "hwt", "high"), description = "Customize settings of HighwayTools." ) { From 80c22d914fe62e7a5308d36c5e24e09ef337e46e Mon Sep 17 00:00:00 2001 From: Christian Date: Fri, 12 Feb 2021 13:54:45 +0100 Subject: [PATCH 314/390] LiquidHandler syntax --- .../kamiblue/client/module/modules/misc/HighwayTools.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index a9d2098864..ca025c644d 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -1139,11 +1139,11 @@ internal object HighwayTools : Module( val found = ArrayList>() val filler = if (isInsideBlueprintBuild(neighbour)) material else fillerMat - for (task in pendingTasks.values) { - if (task.blockPos == neighbour) { + pendingTasks.values.forEach{ + if (it.blockPos == neighbour) { when (isFlowing) { - false -> found.add(Triple(task, TaskState.LIQUID_SOURCE, filler)) - true -> found.add(Triple(task, TaskState.LIQUID_FLOW, filler)) + false -> found.add(Triple(it, TaskState.LIQUID_SOURCE, filler)) + true -> found.add(Triple(it, TaskState.LIQUID_FLOW, filler)) } } } From c58f9e744de7cd9676c9a6765e3a6f6bc27fdd3a Mon Sep 17 00:00:00 2001 From: Christian Date: Fri, 12 Feb 2021 14:48:48 +0100 Subject: [PATCH 315/390] Fix autoeat --- .../kotlin/org/kamiblue/client/module/modules/player/AutoEat.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/player/AutoEat.kt b/src/main/kotlin/org/kamiblue/client/module/modules/player/AutoEat.kt index af3eec33bd..a58c9cdad9 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/player/AutoEat.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/player/AutoEat.kt @@ -33,7 +33,7 @@ internal object AutoEat : Module( private val timer = TickTimer(TimeUnit.TICKS) private var lastSlot = -1 - private var eating = false + var eating = false init { onDisable { From 85bcbd1fec2adb9fd5ef8572434f64a680144e9a Mon Sep 17 00:00:00 2001 From: Christian Date: Fri, 12 Feb 2021 16:13:20 +0100 Subject: [PATCH 316/390] Fix liquids with multibreak --- .../org/kamiblue/client/module/modules/misc/HighwayTools.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index ca025c644d..6ed5f9a867 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -1229,6 +1229,8 @@ internal object HighwayTools : Module( val box = AxisAlignedBB(task.blockPos) val rayTraceResult = box.isInSight(eyePos, viewVec) ?: continue + + if (handleLiquid(task)) break breakCount++ defaultScope.launch { From c761c37e7cdd6e75f85b564b9994df4ebfc9ca29 Mon Sep 17 00:00:00 2001 From: Christian Date: Fri, 12 Feb 2021 16:41:07 +0100 Subject: [PATCH 317/390] Kotlin syntax --- .../module/modules/misc/HighwayTools.kt | 44 +++++++++++-------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index 6ed5f9a867..698b4d27cd 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -83,7 +83,6 @@ internal object HighwayTools : Module( alias = arrayOf("HT", "HWT"), modulePriority = 10 ) { - private val mode by setting("Mode", Mode.HIGHWAY, description = "Choose the structure") private val page by setting("Page", Page.BUILD, description = "Switch between the setting pages") val ignoreBlocks = linkedSetOf( @@ -98,6 +97,7 @@ internal object HighwayTools : Module( ) // build settings + private val mode by setting("Mode", Mode.HIGHWAY, { page == Page.BUILD }, description = "Choose the structure") private val clearSpace by setting("Clear Space", true, { page == Page.BUILD && mode == Mode.HIGHWAY }, description = "Clears out the tunnel if necessary") private val width by setting("Width", 6, 1..11, 1, { page == Page.BUILD }, description = "Sets the width of blueprint") private val height by setting("Height", 4, 1..6, 1, { page == Page.BUILD && clearSpace }, description = "Sets height of blueprint") @@ -371,7 +371,8 @@ internal object HighwayTools : Module( if (!rubberbandTimer.tick(rubberbandTimeout.toLong(), false) || AutoObsidian.isActive() || AutoEat.eating || - player.isCreative && player.serverBrand.contains("2b2t")) { + player.isCreative && player.serverBrand.contains("2b2t") || + !isEnabled) { refreshData() return@safeListener } @@ -398,14 +399,14 @@ internal object HighwayTools : Module( // renderer.add(world.getBlockState(currentBlockPos).getSelectedBoundingBox(world, currentBlockPos), ColorHolder(255, 255, 255)) - for (blockTask in pendingTasks.values) { - if (blockTask.taskState == TaskState.DONE) continue - renderer.add(world.getBlockState(blockTask.blockPos).getSelectedBoundingBox(world, blockTask.blockPos), blockTask.taskState.color) + pendingTasks.values.forEach { + if (it.taskState == TaskState.DONE) return@forEach + renderer.add(world.getBlockState(it.blockPos).getSelectedBoundingBox(world, it.blockPos), it.taskState.color) } - for (blockTask in doneTasks.values) { - if (blockTask.block == Blocks.AIR) continue - renderer.add(world.getBlockState(blockTask.blockPos).getSelectedBoundingBox(world, blockTask.blockPos), blockTask.taskState.color) + doneTasks.values.forEach { + if (it.block == Blocks.AIR) return@forEach + renderer.add(world.getBlockState(it.blockPos).getSelectedBoundingBox(world, it.blockPos), it.taskState.color) } } @@ -456,7 +457,7 @@ internal object HighwayTools : Module( blueprint.clear() generateBluePrint(originPos) - for ((pos, block) in blueprint) { + blueprint.forEach { (pos, block) -> if (block == Blocks.AIR) { addTaskClear(pos) } else { @@ -655,8 +656,8 @@ internal object HighwayTools : Module( refreshData() } else { waitTicks-- - for (task in pendingTasks.values) { - doTask(task, true) + pendingTasks.values.forEach { + doTask(it, true) } sortTasks() @@ -697,7 +698,8 @@ internal object HighwayTools : Module( val eyePos = mc.player.getPositionEyes(1.0f) if (multiBuilding) { - for (task in pendingTasks.values) task.shuffle() + pendingTasks.values.forEach{ it.shuffle() } + sortedTasks = pendingTasks.values.sortedWith( compareBy { it.taskState.ordinal @@ -1025,8 +1027,8 @@ internal object HighwayTools : Module( placeBlockNormal(blockTask, neighbours.last()) } else -> { - for (pair in neighbours) { - addTaskToPending(pair.second, TaskState.PLACE, fillerMat) + neighbours.forEach { + addTaskToPending(it.second, TaskState.PLACE, fillerMat) } } } @@ -1154,9 +1156,9 @@ internal object HighwayTools : Module( true -> addTaskToPending(neighbour, TaskState.LIQUID_FLOW, filler) } } else { - for (triple in found) { - triple.first.updateState(triple.second) - triple.first.updateMaterial(triple.third) + found.forEach { + it.first.updateState(it.second) + it.first.updateMaterial(it.third) } } } @@ -1280,7 +1282,9 @@ internal object HighwayTools : Module( "\n §9> §rFiller material: §7${fillerMat.localizedName}" + "\n §9> §rIgnored Blocks:") - for (b in ignoreBlocks) append("\n §9> §7${b.registryName}") + ignoreBlocks.forEach { + append("\n §9> §7${it.registryName}") + } MessageSendHelper.sendChatMessage(toString()) } @@ -1439,7 +1443,9 @@ internal object HighwayTools : Module( } private fun addTaskComponentList(displayText: TextComponent, tasks: Collection) { - for (blockTask in tasks) displayText.addLine(" ${blockTask.block.localizedName}@(${blockTask.blockPos.asString()}) State: ${blockTask.taskState} Timings: (Threshold: ${blockTask.taskState.stuckThreshold} Timeout: ${blockTask.taskState.stuckTimeout}) Priority: ${blockTask.taskState.ordinal} Stuck: ${blockTask.stuckTicks}") + tasks.forEach { + displayText.addLine(" ${it.block.localizedName}@(${it.blockPos.asString()}) State: ${it.taskState} Timings: (Threshold: ${it.taskState.stuckThreshold} Timeout: ${it.taskState.stuckTimeout}) Priority: ${it.taskState.ordinal} Stuck: ${it.stuckTicks}") + } } class BlockTask( From 9b8b57116fa205622e9903120de9d0eb496d6bbc Mon Sep 17 00:00:00 2001 From: Christian Date: Fri, 12 Feb 2021 16:46:17 +0100 Subject: [PATCH 318/390] Temporary setback --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 7ae2e6ad1c..970664fb07 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ org.gradle.jvmargs=-Xmx3G modGroup=org.kamiblue -modVersion=2.02.xx-dev-ht-v10 +modVersion=2.02.xx-dev-ht-v09.5 kotlin_version=1.4.30 kotlinx_coroutines_version=1.4.2 \ No newline at end of file From 648897dfe36956779ec5a989046fe9b141317198 Mon Sep 17 00:00:00 2001 From: Christian Date: Sat, 13 Feb 2021 01:26:04 +0100 Subject: [PATCH 319/390] Format --- .../client/gui/hudgui/elements/misc/HighwayToolsHud.kt | 2 +- .../org/kamiblue/client/module/modules/misc/HighwayTools.kt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/org/kamiblue/client/gui/hudgui/elements/misc/HighwayToolsHud.kt b/src/main/kotlin/org/kamiblue/client/gui/hudgui/elements/misc/HighwayToolsHud.kt index 982b65866e..82e7c4816b 100644 --- a/src/main/kotlin/org/kamiblue/client/gui/hudgui/elements/misc/HighwayToolsHud.kt +++ b/src/main/kotlin/org/kamiblue/client/gui/hudgui/elements/misc/HighwayToolsHud.kt @@ -5,7 +5,7 @@ import org.kamiblue.client.gui.hudgui.LabelHud import org.kamiblue.client.module.modules.misc.HighwayTools.gatherStatistics object HighwayToolsHud : LabelHud( - name = "HighwayTools", + name = "HighwayToolsHud", category = Category.MISC, description = "Hud for HighwayTools module" ) { diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index 698b4d27cd..cbb89b80ab 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -966,7 +966,7 @@ internal object HighwayTools : Module( if (!updateOnly) { if (!isPlaceable(blockTask.blockPos)) { - if (debugMessages != DebugMessages.OFF) { + if (debugMessages == DebugMessages.ALL) { if (!anonymizeStats) { MessageSendHelper.sendChatMessage("Invalid place position: ${blockTask.blockPos}. Removing task") } else { @@ -1331,7 +1331,7 @@ internal object HighwayTools : Module( displayText.add(" Breaks / s:", primaryColor) displayText.addLine("%.2f SMA(%.2f)".format(totalBlocksBroken / runtimeSec, simpleMovingAverageBreaks.size / simpleMovingAverageRange), secondaryColor) displayText.add(" Distance km / h:", primaryColor) - displayText.addLine("%.3f SMA(%.3f)".format((distanceDone / runtimeSec * 60 * 60) / 1000, ((simpleMovingAverageDistance.size / simpleMovingAverageRange) * 60 * 60) / 1000), secondaryColor) + displayText.addLine("%.3f SMA(%.3f)".format((distanceDone / runtimeSec * 60 * 60) / 1000, (simpleMovingAverageDistance.size / simpleMovingAverageRange * 60 * 60) / 1000), secondaryColor) displayText.add(" Food level loss / h:", primaryColor) displayText.addLine("%.2f".format(totalBlocksBroken / foodLoss.toDouble()), secondaryColor) displayText.add(" Pickaxes / h:", primaryColor) From 5b3ac75bbe78757459a6756d0a0d0c7ed5c1dafd Mon Sep 17 00:00:00 2001 From: Christian Date: Sat, 13 Feb 2021 23:26:43 +0100 Subject: [PATCH 320/390] Fix fix fail --- .../org/kamiblue/client/module/modules/misc/HighwayTools.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index cbb89b80ab..e11f213cfc 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -371,8 +371,7 @@ internal object HighwayTools : Module( if (!rubberbandTimer.tick(rubberbandTimeout.toLong(), false) || AutoObsidian.isActive() || AutoEat.eating || - player.isCreative && player.serverBrand.contains("2b2t") || - !isEnabled) { + player.isCreative && player.serverBrand.contains("2b2t")) { refreshData() return@safeListener } From 69c8c5c2bbd8f02fe95c315128aa532565432141 Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 16 Feb 2021 21:57:01 +0100 Subject: [PATCH 321/390] Fixes and clean tunnel --- .../module/modules/misc/HighwayTools.kt | 97 ++++++++++++++----- 1 file changed, 72 insertions(+), 25 deletions(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index e11f213cfc..87dff06d48 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -99,6 +99,8 @@ internal object HighwayTools : Module( // build settings private val mode by setting("Mode", Mode.HIGHWAY, { page == Page.BUILD }, description = "Choose the structure") private val clearSpace by setting("Clear Space", true, { page == Page.BUILD && mode == Mode.HIGHWAY }, description = "Clears out the tunnel if necessary") + private val cleanFloor by setting("Clean Floor", false, { page == Page.BUILD && mode == Mode.TUNNEL }, description = "Cleans up the tunnels floor") + private val cleanWalls by setting("Clean Walls", false, { page == Page.BUILD && mode == Mode.TUNNEL }, description = "Cleans up the tunnels walls") private val width by setting("Width", 6, 1..11, 1, { page == Page.BUILD }, description = "Sets the width of blueprint") private val height by setting("Height", 4, 1..6, 1, { page == Page.BUILD && clearSpace }, description = "Sets height of blueprint") private val railing by setting("Railing", true, { page == Page.BUILD && mode == Mode.HIGHWAY }, description = "Adds a railing / rim / border to the highway") @@ -498,10 +500,12 @@ internal object HighwayTools : Module( for (x in -maxReach.floorToInt()..maxReach.ceilToInt()) { val thisPos = basePos.add(zDirection.directionVec.multiply(x)) - generateClear(thisPos, xDirection) + if (clearSpace) generateClear(thisPos, xDirection) if (mode != Mode.TUNNEL) generateBase(thisPos, xDirection) + if (mode == Mode.TUNNEL && cleanFloor) generateFloor(thisPos, xDirection) + if (mode == Mode.TUNNEL && cleanWalls) generateWalls(thisPos, xDirection) } - if (mode == Mode.TUNNEL) { + if (mode == Mode.TUNNEL && !cleanFloor) { if (startingDirection.isDiagonal) { for (x in 1..maxReach.floorToInt()) { blueprint[basePos.add(zDirection.directionVec.multiply(x))] = fillerMat @@ -530,8 +534,6 @@ internal object HighwayTools : Module( } private fun generateClear(basePos: BlockPos, xDirection: Direction) { - if (!clearSpace) return - for (w in 0 until width) { for (h in 0 until height) { val x = w - width / 2 @@ -566,6 +568,32 @@ internal object HighwayTools : Module( } } + private fun generateFloor(basePos: BlockPos, xDirection: Direction) { + val wid = if (cornerBlock) { + width + } else { + width - 2 + } + for (w in 0 until wid) { + val x = w - wid / 2 + val pos = basePos.add(xDirection.directionVec.multiply(x)) + blueprint[pos] = fillerMat + } + } + + private fun generateWalls(basePos: BlockPos, xDirection: Direction) { + for (h in 0 until height) { + val cb = if (!cornerBlock && h == 0) { + 1 + } else { + 0 + } + val pos = basePos.add(xDirection.directionVec.multiply(width / 2 - cb)).up(h + 1) + blueprint[pos] = fillerMat + blueprint[pos.add(xDirection.clockwise(4).directionVec.multiply(width + 1))] = fillerMat + } + } + private fun isRail(w: Int) = railing && w !in 1 until width - 1 private fun generateFlat(basePos: BlockPos) { @@ -697,39 +725,44 @@ internal object HighwayTools : Module( val eyePos = mc.player.getPositionEyes(1.0f) if (multiBuilding) { - pendingTasks.values.forEach{ it.shuffle() } + pendingTasks.values.forEach { it.shuffle() } sortedTasks = pendingTasks.values.sortedWith( compareBy { it.taskState.ordinal }.thenBy { - it.stuckTicks / 5 + it.stuckTicks }.thenBy { it.shuffle } ) } else { + pendingTasks.values.forEach { + when (it.taskState) { + TaskState.PLACE -> it.sides = getBetterNeighbour(it.blockPos, placementSearch, maxReach, true).size +// TaskState.BREAK -> + else -> it.sides = 0 + } + + // ToDo: We need a function that makes a score out of those 3 parameters + it.startDistance = (startingBlockPos.distanceTo(it.blockPos) * 100.0).toInt() + it.eyeDistance = (eyePos.distanceTo(it.blockPos) * 100.0).toInt() + it.hitVecDistance = ((lastHitVec?.distanceTo(it.blockPos) ?: 0.0) * 100.0).toInt() + } + sortedTasks = pendingTasks.values.sortedWith( compareBy { it.taskState.ordinal }.thenBy { - it.stuckTicks / 5 + it.stuckTicks }.thenBy { - when (it.taskState) { - TaskState.PLACE, TaskState.LIQUID_SOURCE, TaskState.LIQUID_FLOW -> { - getBetterNeighbour(it.blockPos, placementSearch, maxReach, true).size - } - TaskState.BREAK -> { // ToDo: Check for most block interceptions when kick issue solved - 0 - } - else -> 0 - } - }.thenBy { // ToDo: We need a function that makes a score out of those 3 parameters - startingBlockPos.distanceTo(it.blockPos).toInt() / 2 + it.sides }.thenBy { - eyePos.distanceTo(it.blockPos) + it.startDistance }.thenBy { - lastHitVec?.distanceTo(it.blockPos) + it.eyeDistance + }.thenBy { + it.hitVecDistance } ) } @@ -811,7 +844,7 @@ internal object HighwayTools : Module( return } is BlockLiquid -> { - val filler = if (fillerMatLeft == 0 || isInsideBlueprintBuild(blockTask.blockPos)) { + val filler = if (player.allSlots.countBlock(fillerMat) == 0 || isInsideBlueprintBuild(blockTask.blockPos)) { material } else { fillerMat @@ -901,7 +934,7 @@ internal object HighwayTools : Module( } } is BlockLiquid -> { - val filler = if (fillerMatLeft == 0 || isInsideBlueprintBuild(blockTask.blockPos)) material + val filler = if (player.allSlots.countBlock(fillerMat) == 0 || isInsideBlueprintBuild(blockTask.blockPos)) material else fillerMat if (world.getBlockState(blockTask.blockPos).getValue(BlockLiquid.LEVEL) != 0) { @@ -935,6 +968,13 @@ internal object HighwayTools : Module( player.motionZ = (target.z - player.posZ).coerceIn(-0.2, 0.2) } + if ((blockTask.taskState == TaskState.LIQUID_FLOW || + blockTask.taskState == TaskState.LIQUID_SOURCE) && + !isLiquid(blockTask.blockPos)) { + blockTask.updateState(TaskState.DONE) + return + } + when (blockTask.block) { material -> { if (currentBlock == material) { @@ -1134,13 +1174,16 @@ internal object HighwayTools : Module( it.block is BlockLiquid && it.getValue(BlockLiquid.LEVEL) != 0 } - if (player.distanceTo(neighbour) > maxReach) continue + if (player.distanceTo(neighbour) > maxReach) { + blockTask.updateState(TaskState.DONE) + return true + } foundLiquid = true val found = ArrayList>() val filler = if (isInsideBlueprintBuild(neighbour)) material else fillerMat - pendingTasks.values.forEach{ + pendingTasks.values.forEach { if (it.blockPos == neighbour) { when (isFlowing) { false -> found.add(Triple(it, TaskState.LIQUID_SOURCE, filler)) @@ -1271,7 +1314,7 @@ internal object HighwayTools : Module( } private fun isInsideBlueprintBuild(pos: BlockPos): Boolean { - return blueprint[pos]?.let { it != Blocks.AIR } ?: false + return blueprint[pos]?.let { it == material } ?: false } fun printSettings() { @@ -1455,6 +1498,10 @@ internal object HighwayTools : Module( private var ranTicks = 0 var stuckTicks = 0; private set var shuffle = 0 + var sides = 0 + var startDistance = 0 + var eyeDistance = 0 + var hitVecDistance = 0 fun updateState(state: TaskState) { if (state == taskState) return From 664bd29ef98ccf23969892cd57a74a3c8b08efea Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 16 Feb 2021 23:23:47 +0100 Subject: [PATCH 322/390] Refurbish --- .../client/module/modules/misc/HighwayTools.kt | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index 87dff06d48..b8d38c0f1e 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -39,6 +39,7 @@ import org.kamiblue.client.module.modules.movement.AntiHunger import org.kamiblue.client.module.modules.movement.Velocity import org.kamiblue.client.module.modules.player.AutoEat import org.kamiblue.client.module.modules.player.InventoryManager +import org.kamiblue.client.module.modules.player.LagNotifier import org.kamiblue.client.process.HighwayToolsProcess import org.kamiblue.client.util.BaritoneUtils import org.kamiblue.client.util.EntityUtils.flooredPosition @@ -115,9 +116,9 @@ internal object HighwayTools : Module( private var breakDelay by setting("Break Delay", 1, 1..20, 1, { page == Page.BEHAVIOR }, description = "Sets the delay ticks between break tasks") private val illegalPlacements by setting("Illegal Placements", false, { page == Page.BEHAVIOR }, description = "Do not use on 2b2t. Tries to interact with invisible surfaces") private val bridging by setting("Bridging", true, { page == Page.BEHAVIOR }, description = "Tries to bridge / scaffold when stuck placing") - private var placementSearch by setting("Place Deep Search", 1, 1..20, 1, { page == Page.BEHAVIOR }, description = "Attempts to find a support block for placing against") + private var placementSearch by setting("Place Deep Search", 2, 1..4, 1, { page == Page.BEHAVIOR }, description = "Attempts to find a support block for placing against") private val multiBuilding by setting("Shuffle Tasks", false, { page == Page.BEHAVIOR }, description = "Only activate when working with several players") - private val maxBreaks by setting("Multi Break", 3, 1..8, 1, { page == Page.BEHAVIOR }, description = "Breaks multiple instant breaking blocks per tick in view") + private val maxBreaks by setting("Multi Break", 1, 1..5, 1, { page == Page.BEHAVIOR }, description = "Breaks multiple instant breaking blocks per tick in view") private val toggleInventoryManager by setting("Toggle InvManager", false, { page == Page.BEHAVIOR }, description = "Activates InventoryManager on enable") private val toggleAutoObsidian by setting("Toggle AutoObsidian", true, { page == Page.BEHAVIOR }, description = "Activates AutoObsidian on enable") private val taskTimeout by setting("Task Timeout", 8, 0..20, 1, { page == Page.BEHAVIOR }, description = "Timeout for waiting for the server to try again") @@ -302,6 +303,10 @@ internal object HighwayTools : Module( MessageSendHelper.sendRawChatMessage(" §9> §cAntiHunger does slow down block interactions.") } + if (LagNotifier.isDisabled) { + MessageSendHelper.sendRawChatMessage(" §9> §cYou should activate LagNotifier to make the bot stop on server lag.") + } + if (multiBuilding && Velocity.isDisabled) { MessageSendHelper.sendRawChatMessage(" §9> §cMake sure to enable Velocity to not get pushed from your mates.") } @@ -755,7 +760,7 @@ internal object HighwayTools : Module( it.taskState.ordinal }.thenBy { it.stuckTicks - }.thenBy { + }.thenByDescending { it.sides }.thenBy { it.startDistance @@ -959,7 +964,7 @@ internal object HighwayTools : Module( if (bridging && player.positionVector.distanceTo(currentBlockPos) < 1 && shouldBridge()) { val factor = if (startingDirection.isDiagonal) { - 0.51 + 0.555 } else { 0.505 } @@ -1212,7 +1217,7 @@ internal object HighwayTools : Module( /* For fire, we just need to mine the top of the block below the fire */ /* ToDo: This will not work if the top of the block which the fire is on is not visible */ - if (blockTask.block == Blocks.FIRE) { + if (world.getBlockState(blockTask.blockPos) == Blocks.FIRE) { val blockBelowFire = blockTask.blockPos.down() if (getVisibleSides(blockBelowFire).contains(EnumFacing.UP)) { playerController.clickBlock(blockBelowFire, EnumFacing.UP) From 492fab366765b7bf0c1f5099d862086fa1557a39 Mon Sep 17 00:00:00 2001 From: Christian Date: Wed, 17 Feb 2021 00:17:15 +0100 Subject: [PATCH 323/390] Save all block info --- .../command/commands/HighwayToolsCommand.kt | 6 ++- .../module/modules/misc/HighwayTools.kt | 38 ++++++++++--------- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/src/main/kotlin/org/kamiblue/client/command/commands/HighwayToolsCommand.kt b/src/main/kotlin/org/kamiblue/client/command/commands/HighwayToolsCommand.kt index a65d171ce9..0650575ae5 100644 --- a/src/main/kotlin/org/kamiblue/client/command/commands/HighwayToolsCommand.kt +++ b/src/main/kotlin/org/kamiblue/client/command/commands/HighwayToolsCommand.kt @@ -14,7 +14,7 @@ object HighwayToolsCommand : ClientCommand( literal("add", "new", "+") { block("block") { blockArg -> execute("Add a block to ignore list") { - val added = HighwayTools.ignoreBlocks.add(blockArg.value) + val added = HighwayTools.ignoreBlocks.add(blockArg.value.registryName.toString()) if (added) { HighwayTools.printSettings() MessageSendHelper.sendChatMessage("Added &7${blockArg.value.localizedName}&r to ignore list.") @@ -28,7 +28,7 @@ object HighwayToolsCommand : ClientCommand( literal("del", "rem", "-") { block("block") { blockArg -> execute("Remove a block from ignore list") { - val removed = HighwayTools.ignoreBlocks.remove(blockArg.value) + val removed = HighwayTools.ignoreBlocks.remove(blockArg.value.registryName.toString()) if (removed) { HighwayTools.printSettings() MessageSendHelper.sendChatMessage("Removed &7${blockArg.value.localizedName}&r from ignore list.") @@ -42,6 +42,7 @@ object HighwayToolsCommand : ClientCommand( literal("material", "mat") { block("block") { blockArg -> execute("Set a block as main material") { + HighwayTools.materialSaved.value = blockArg.value.registryName.toString() HighwayTools.material = blockArg.value MessageSendHelper.sendChatMessage("Set your building material to &7${blockArg.value.localizedName}&r.") } @@ -51,6 +52,7 @@ object HighwayToolsCommand : ClientCommand( literal("filler", "fil") { block("block") { blockArg -> execute("Set a block as filler material") { + HighwayTools.fillerMatSaved.value = blockArg.value.registryName.toString() HighwayTools.fillerMat = blockArg.value MessageSendHelper.sendChatMessage("Set your filling material to &7${blockArg.value.localizedName}&r.") } diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index b8d38c0f1e..a213d58ec2 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -41,6 +41,7 @@ import org.kamiblue.client.module.modules.player.AutoEat import org.kamiblue.client.module.modules.player.InventoryManager import org.kamiblue.client.module.modules.player.LagNotifier import org.kamiblue.client.process.HighwayToolsProcess +import org.kamiblue.client.setting.settings.impl.collection.CollectionSetting import org.kamiblue.client.util.BaritoneUtils import org.kamiblue.client.util.EntityUtils.flooredPosition import org.kamiblue.client.util.TickTimer @@ -86,15 +87,15 @@ internal object HighwayTools : Module( ) { private val page by setting("Page", Page.BUILD, description = "Switch between the setting pages") - val ignoreBlocks = linkedSetOf( - Blocks.STANDING_SIGN, - Blocks.WALL_SIGN, - Blocks.STANDING_BANNER, - Blocks.WALL_BANNER, - Blocks.BEDROCK, - Blocks.END_PORTAL, - Blocks.END_PORTAL_FRAME, - Blocks.PORTAL + private val defaultIgnoreBlocks = linkedSetOf( + "minecraft:standing_sign", + "minecraft:wall_sign", + "minecraft:standing_banner", + "minecraft:wall_banner", + "minecraft:bedrock", + "minecraft:end_portal", + "minecraft:end_portal_frame", + "minecraft:portal" ) // build settings @@ -107,7 +108,9 @@ internal object HighwayTools : Module( private val railing by setting("Railing", true, { page == Page.BUILD && mode == Mode.HIGHWAY }, description = "Adds a railing / rim / border to the highway") private val railingHeight by setting("Railing Height", 1, 1..4, 1, { railing && page == Page.BUILD && mode == Mode.HIGHWAY }, description = "Sets height of railing") private val cornerBlock by setting("Corner Block", false, { page == Page.BUILD && (mode == Mode.HIGHWAY || mode == Mode.TUNNEL) }, description = "If activated will break the corner in tunnel or place a corner while paving") -// val ignoreBlocks = setting(CollectionSetting("IgnoreList", defaultIgnoreList, { false })) + val ignoreBlocks = setting(CollectionSetting("IgnoreList", defaultIgnoreBlocks, { false })) + val materialSaved = setting("Material", "minecraft:obsidian", { false }) + val fillerMatSaved = setting("FillerMat", "minecraft:netherrack", { false }) // behavior settings private val interacting by setting("Rotation Mode", RotationMode.SPOOF, { page == Page.BEHAVIOR }, description = "Force view client side, only server side or no interaction at all") @@ -164,8 +167,8 @@ internal object HighwayTools : Module( } // internal settings - var material: Block = Blocks.OBSIDIAN - var fillerMat: Block = Blocks.NETHERRACK + var material: Block = Block.getBlockFromName(materialSaved.value) ?: Blocks.OBSIDIAN + var fillerMat: Block = Block.getBlockFromName(fillerMatSaved.value) ?: Blocks.NETHERRACK private var baritoneSettingAllowPlace = false private var baritoneSettingRenderGoal = false @@ -216,7 +219,9 @@ internal object HighwayTools : Module( } init { - ignoreBlocks.addAll(shulkerList) + shulkerList.forEach { + ignoreBlocks.add(it.registryName.toString()) + } onEnable { runSafeR { @@ -714,7 +719,7 @@ internal object HighwayTools : Module( private fun SafeClientEvent.checkDoneTasks(): Boolean { for (blockTask in doneTasks.values) { val block = world.getBlockState(blockTask.blockPos).block - if (ignoreBlocks.contains(block)) continue + if (ignoreBlocks.contains(block.registryName.toString())) continue when { blockTask.block == material && block != material -> return false @@ -923,8 +928,7 @@ internal object HighwayTools : Module( } private fun SafeClientEvent.doBreak(blockTask: BlockTask, updateOnly: Boolean) { - // ignore blocks - if (ignoreBlocks.contains(world.getBlockState(blockTask.blockPos).block)) { + if (ignoreBlocks.contains(world.getBlockState(blockTask.blockPos).block.registryName.toString())) { blockTask.updateState(TaskState.DONE) } @@ -1330,7 +1334,7 @@ internal object HighwayTools : Module( "\n §9> §rIgnored Blocks:") ignoreBlocks.forEach { - append("\n §9> §7${it.registryName}") + append("\n §9> §7$it") } MessageSendHelper.sendChatMessage(toString()) From 04d19f155ab539a9b94a28de6035cb36c17a4308 Mon Sep 17 00:00:00 2001 From: Christian Date: Wed, 17 Feb 2021 00:25:22 +0100 Subject: [PATCH 324/390] Update ToDo --- .../org/kamiblue/client/module/modules/misc/HighwayTools.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index a213d58ec2..9e16f23dae 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -812,7 +812,6 @@ internal object HighwayTools : Module( private fun SafeClientEvent.doTask(blockTask: BlockTask, updateOnly: Boolean) { if (!updateOnly) blockTask.onTick() - // ToDo: Choose place task with least attempts when (blockTask.taskState) { TaskState.DONE -> { doDone(blockTask) @@ -1220,7 +1219,7 @@ internal object HighwayTools : Module( private fun SafeClientEvent.mineBlock(blockTask: BlockTask) { /* For fire, we just need to mine the top of the block below the fire */ - /* ToDo: This will not work if the top of the block which the fire is on is not visible */ + // ToDo: Fix placement issues if (world.getBlockState(blockTask.blockPos) == Blocks.FIRE) { val blockBelowFire = blockTask.blockPos.down() if (getVisibleSides(blockBelowFire).contains(EnumFacing.UP)) { @@ -1256,6 +1255,7 @@ internal object HighwayTools : Module( delay(20L) sendMiningPackets(blockTask.blockPos, side) + // ToDo: Hard limit for TPS to avoid kicks if (maxBreaks > 1) { tryMultiBreak(blockTask) } @@ -1431,6 +1431,7 @@ internal object HighwayTools : Module( val pavingLeft = materialLeft / (totalBlocksPlaced.coerceAtLeast(1) / distanceDone.coerceAtLeast(1.0)) // ToDo: Cache shulker count + // val pavingLeftAll = (materialLeft + indirectMaterialLeft) / ((totalBlocksPlaced + 0.001) / (distanceDone + 0.001)) val secLeft = (pavingLeft).coerceAtLeast(0.0) / (startingBlockPos.distanceTo(currentBlockPos).toInt() / runtimeSec) From c0acd7a7413c495117ef34b04b66d469d8d458a5 Mon Sep 17 00:00:00 2001 From: Christian Date: Wed, 17 Feb 2021 02:50:09 +0100 Subject: [PATCH 325/390] Clean roof too --- .../client/module/modules/misc/HighwayTools.kt | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index 9e16f23dae..0a4b576bbe 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -103,6 +103,7 @@ internal object HighwayTools : Module( private val clearSpace by setting("Clear Space", true, { page == Page.BUILD && mode == Mode.HIGHWAY }, description = "Clears out the tunnel if necessary") private val cleanFloor by setting("Clean Floor", false, { page == Page.BUILD && mode == Mode.TUNNEL }, description = "Cleans up the tunnels floor") private val cleanWalls by setting("Clean Walls", false, { page == Page.BUILD && mode == Mode.TUNNEL }, description = "Cleans up the tunnels walls") + private val cleanRoof by setting("Clean Roof", false, { page == Page.BUILD && mode == Mode.TUNNEL }, description = "Cleans up the tunnels roof") private val width by setting("Width", 6, 1..11, 1, { page == Page.BUILD }, description = "Sets the width of blueprint") private val height by setting("Height", 4, 1..6, 1, { page == Page.BUILD && clearSpace }, description = "Sets height of blueprint") private val railing by setting("Railing", true, { page == Page.BUILD && mode == Mode.HIGHWAY }, description = "Adds a railing / rim / border to the highway") @@ -514,6 +515,7 @@ internal object HighwayTools : Module( if (mode != Mode.TUNNEL) generateBase(thisPos, xDirection) if (mode == Mode.TUNNEL && cleanFloor) generateFloor(thisPos, xDirection) if (mode == Mode.TUNNEL && cleanWalls) generateWalls(thisPos, xDirection) + if (mode == Mode.TUNNEL && cleanRoof) generateRoof(thisPos, xDirection) } if (mode == Mode.TUNNEL && !cleanFloor) { if (startingDirection.isDiagonal) { @@ -603,6 +605,14 @@ internal object HighwayTools : Module( blueprint[pos.add(xDirection.clockwise(4).directionVec.multiply(width + 1))] = fillerMat } } + private fun generateRoof(basePos: BlockPos, xDirection: Direction) { + for (w in 0 until width) { + val x = w - width / 2 + val pos = basePos.add(xDirection.directionVec.multiply(x)) + blueprint[pos.up(height)] = fillerMat + } + } + private fun isRail(w: Int) = railing && w !in 1 until width - 1 @@ -1431,7 +1441,7 @@ internal object HighwayTools : Module( val pavingLeft = materialLeft / (totalBlocksPlaced.coerceAtLeast(1) / distanceDone.coerceAtLeast(1.0)) // ToDo: Cache shulker count - + // val pavingLeftAll = (materialLeft + indirectMaterialLeft) / ((totalBlocksPlaced + 0.001) / (distanceDone + 0.001)) val secLeft = (pavingLeft).coerceAtLeast(0.0) / (startingBlockPos.distanceTo(currentBlockPos).toInt() / runtimeSec) From bb8d64fcb9e7f4c9e1b1a5d5e1b4866b2c5bf270 Mon Sep 17 00:00:00 2001 From: Christian Date: Thu, 18 Feb 2021 15:12:16 +0100 Subject: [PATCH 326/390] Fix clean options --- .../kamiblue/client/module/modules/misc/HighwayTools.kt | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index 0a4b576bbe..c122e96c55 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -600,16 +600,15 @@ internal object HighwayTools : Module( } else { 0 } - val pos = basePos.add(xDirection.directionVec.multiply(width / 2 - cb)).up(h + 1) - blueprint[pos] = fillerMat - blueprint[pos.add(xDirection.clockwise(4).directionVec.multiply(width + 1))] = fillerMat + blueprint[basePos.add(xDirection.directionVec.multiply(-1 - width / 2 + cb)).up(h + 1)] = fillerMat + blueprint[basePos.add(xDirection.directionVec.multiply(width - width / 2 - cb)).up(h + 1)] = fillerMat } } private fun generateRoof(basePos: BlockPos, xDirection: Direction) { for (w in 0 until width) { val x = w - width / 2 val pos = basePos.add(xDirection.directionVec.multiply(x)) - blueprint[pos.up(height)] = fillerMat + blueprint[pos.up(height + 1)] = fillerMat } } @@ -1368,7 +1367,7 @@ internal object HighwayTools : Module( if (showEstimations) gatherEstimations(displayText, runtimeSec, distanceDone) -// displayText.addLine("by Constructor#9948 aka Avanatiker", primaryColor) +// displayText.addLine("by Constructor#9948 aka Avanatiker", primaryColor, size=8) if (printDebug) { displayText.addLine("Pending", primaryColor) From 7518b5af40689035617525de6174690116f0d79e Mon Sep 17 00:00:00 2001 From: Christian Date: Thu, 18 Feb 2021 23:28:35 +0100 Subject: [PATCH 327/390] Mutex nonBlocking --- .../module/modules/misc/HighwayTools.kt | 80 ++++++++++++------- 1 file changed, 50 insertions(+), 30 deletions(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index c122e96c55..8ec6166c1f 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -3,6 +3,9 @@ package org.kamiblue.client.module.modules.misc import baritone.api.pathing.goals.GoalNear import kotlinx.coroutines.delay import kotlinx.coroutines.launch +import kotlinx.coroutines.runBlocking +import kotlinx.coroutines.sync.Mutex +import kotlinx.coroutines.sync.withLock import net.minecraft.block.Block import net.minecraft.block.BlockLiquid import net.minecraft.client.audio.PositionedSoundRecord @@ -77,6 +80,7 @@ import kotlin.random.Random.Default.nextInt /** * @author Avanatiker * @since 20/08/2020 + * */ internal object HighwayTools : Module( name = "HighwayTools", @@ -168,6 +172,7 @@ internal object HighwayTools : Module( } // internal settings + private val mutex = Mutex() var material: Block = Block.getBlockFromName(materialSaved.value) ?: Blocks.OBSIDIAN var fillerMat: Block = Block.getBlockFromName(fillerMatSaved.value) ?: Blocks.NETHERRACK private var baritoneSettingAllowPlace = false @@ -383,8 +388,8 @@ internal object HighwayTools : Module( if (!rubberbandTimer.tick(rubberbandTimeout.toLong(), false) || AutoObsidian.isActive() || - AutoEat.eating || - player.isCreative && player.serverBrand.contains("2b2t")) { +// AutoEat.eating || + (player.isCreative && player.serverBrand.contains("2b2t"))) { refreshData() return@safeListener } @@ -672,7 +677,9 @@ internal object HighwayTools : Module( if (checkTasks(possiblePos.up())) nextPos = possiblePos if (currentBlockPos != nextPos) { - simpleMovingAverageDistance.add(System.currentTimeMillis()) + for (x in 1 .. currentBlockPos.distanceTo(nextPos).toInt()) { + simpleMovingAverageDistance.add(System.currentTimeMillis()) + } refreshData() } @@ -746,15 +753,19 @@ internal object HighwayTools : Module( if (multiBuilding) { pendingTasks.values.forEach { it.shuffle() } - sortedTasks = pendingTasks.values.sortedWith( - compareBy { - it.taskState.ordinal - }.thenBy { - it.stuckTicks - }.thenBy { - it.shuffle + runBlocking { + mutex.withLock { + sortedTasks = pendingTasks.values.sortedWith( + compareBy { + it.taskState.ordinal + }.thenBy { + it.stuckTicks + }.thenBy { + it.shuffle + } + ) } - ) + } } else { pendingTasks.values.forEach { when (it.taskState) { @@ -769,21 +780,25 @@ internal object HighwayTools : Module( it.hitVecDistance = ((lastHitVec?.distanceTo(it.blockPos) ?: 0.0) * 100.0).toInt() } - sortedTasks = pendingTasks.values.sortedWith( - compareBy { - it.taskState.ordinal - }.thenBy { - it.stuckTicks - }.thenByDescending { - it.sides - }.thenBy { - it.startDistance - }.thenBy { - it.eyeDistance - }.thenBy { - it.hitVecDistance + runBlocking { + mutex.withLock { + sortedTasks = pendingTasks.values.sortedWith( + compareBy { + it.taskState.ordinal + }.thenBy { + it.stuckTicks + }.thenByDescending { + it.sides + }.thenBy { + it.startDistance + }.thenBy { + it.eyeDistance + }.thenBy { + it.hitVecDistance + } + ) } - ) + } } } @@ -1122,7 +1137,9 @@ internal object HighwayTools : Module( delay(50L * taskTimeout) if (blockTask.taskState == TaskState.PENDING_PLACE) { - blockTask.updateState(TaskState.PLACE) + mutex.withLock { + blockTask.updateState(TaskState.PLACE) + } if (dynamicDelay && extraPlaceDelay < 10) extraPlaceDelay += 1 } } @@ -1271,7 +1288,9 @@ internal object HighwayTools : Module( delay(50L * taskTimeout) if (blockTask.taskState == TaskState.PENDING_BREAK) { - blockTask.updateState(TaskState.BREAK) + mutex.withLock { + blockTask.updateState(TaskState.BREAK) + } } } } @@ -1300,7 +1319,9 @@ internal object HighwayTools : Module( delay(50L * taskTimeout) if (blockTask.taskState == TaskState.PENDING_BREAK) { - blockTask.updateState(TaskState.BREAK) + mutex.withLock { + blockTask.updateState(TaskState.BREAK) + } } } } @@ -1584,5 +1605,4 @@ internal object HighwayTools : Module( PENDING_PLACE(100, 100, ColorHolder(0, 0, 0)) } -} - +} \ No newline at end of file From 54ffaaccb11aa6b1362fcb9646d72d38e9ecd3f5 Mon Sep 17 00:00:00 2001 From: Christian Date: Fri, 19 Feb 2021 01:25:43 +0100 Subject: [PATCH 328/390] Working material settings --- .../command/commands/HighwayToolsCommand.kt | 2 -- .../module/modules/misc/HighwayTools.kt | 20 +++++++++++++------ .../client/module/modules/player/AutoEat.kt | 2 +- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/main/kotlin/org/kamiblue/client/command/commands/HighwayToolsCommand.kt b/src/main/kotlin/org/kamiblue/client/command/commands/HighwayToolsCommand.kt index 0650575ae5..28192b4ae8 100644 --- a/src/main/kotlin/org/kamiblue/client/command/commands/HighwayToolsCommand.kt +++ b/src/main/kotlin/org/kamiblue/client/command/commands/HighwayToolsCommand.kt @@ -42,7 +42,6 @@ object HighwayToolsCommand : ClientCommand( literal("material", "mat") { block("block") { blockArg -> execute("Set a block as main material") { - HighwayTools.materialSaved.value = blockArg.value.registryName.toString() HighwayTools.material = blockArg.value MessageSendHelper.sendChatMessage("Set your building material to &7${blockArg.value.localizedName}&r.") } @@ -52,7 +51,6 @@ object HighwayToolsCommand : ClientCommand( literal("filler", "fil") { block("block") { blockArg -> execute("Set a block as filler material") { - HighwayTools.fillerMatSaved.value = blockArg.value.registryName.toString() HighwayTools.fillerMat = blockArg.value MessageSendHelper.sendChatMessage("Set your filling material to &7${blockArg.value.localizedName}&r.") } diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index 8ec6166c1f..3e417b1618 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -40,10 +40,10 @@ import org.kamiblue.client.module.modules.client.Hud.primaryColor import org.kamiblue.client.module.modules.client.Hud.secondaryColor import org.kamiblue.client.module.modules.movement.AntiHunger import org.kamiblue.client.module.modules.movement.Velocity -import org.kamiblue.client.module.modules.player.AutoEat import org.kamiblue.client.module.modules.player.InventoryManager import org.kamiblue.client.module.modules.player.LagNotifier import org.kamiblue.client.process.HighwayToolsProcess +import org.kamiblue.client.process.PauseProcess import org.kamiblue.client.setting.settings.impl.collection.CollectionSetting import org.kamiblue.client.util.BaritoneUtils import org.kamiblue.client.util.EntityUtils.flooredPosition @@ -113,9 +113,9 @@ internal object HighwayTools : Module( private val railing by setting("Railing", true, { page == Page.BUILD && mode == Mode.HIGHWAY }, description = "Adds a railing / rim / border to the highway") private val railingHeight by setting("Railing Height", 1, 1..4, 1, { railing && page == Page.BUILD && mode == Mode.HIGHWAY }, description = "Sets height of railing") private val cornerBlock by setting("Corner Block", false, { page == Page.BUILD && (mode == Mode.HIGHWAY || mode == Mode.TUNNEL) }, description = "If activated will break the corner in tunnel or place a corner while paving") + private val materialSaved = setting("Material", "minecraft:obsidian", { false }) + private val fillerMatSaved = setting("FillerMat", "minecraft:netherrack", { false }) val ignoreBlocks = setting(CollectionSetting("IgnoreList", defaultIgnoreBlocks, { false })) - val materialSaved = setting("Material", "minecraft:obsidian", { false }) - val fillerMatSaved = setting("FillerMat", "minecraft:netherrack", { false }) // behavior settings private val interacting by setting("Rotation Mode", RotationMode.SPOOF, { page == Page.BEHAVIOR }, description = "Force view client side, only server side or no interaction at all") @@ -173,8 +173,16 @@ internal object HighwayTools : Module( // internal settings private val mutex = Mutex() - var material: Block = Block.getBlockFromName(materialSaved.value) ?: Blocks.OBSIDIAN - var fillerMat: Block = Block.getBlockFromName(fillerMatSaved.value) ?: Blocks.NETHERRACK + var material: Block + get() = Block.getBlockFromName(materialSaved.value) ?: Blocks.OBSIDIAN + set(value) { + materialSaved.value = value.registryName.toString() + } + var fillerMat: Block + get() = Block.getBlockFromName(fillerMatSaved.value) ?: Blocks.NETHERRACK + set(value) { + fillerMatSaved.value = value.registryName.toString() + } private var baritoneSettingAllowPlace = false private var baritoneSettingRenderGoal = false @@ -387,8 +395,8 @@ internal object HighwayTools : Module( updateFood() if (!rubberbandTimer.tick(rubberbandTimeout.toLong(), false) || + PauseProcess.isActive || AutoObsidian.isActive() || -// AutoEat.eating || (player.isCreative && player.serverBrand.contains("2b2t"))) { refreshData() return@safeListener diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/player/AutoEat.kt b/src/main/kotlin/org/kamiblue/client/module/modules/player/AutoEat.kt index ebfd0256d8..164c25a0ed 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/player/AutoEat.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/player/AutoEat.kt @@ -32,7 +32,7 @@ internal object AutoEat : Module( private val pauseBaritone by setting("Pause Baritone", true) private var lastSlot = -1 - var eating = false + private var eating = false override fun isActive(): Boolean { return isEnabled && eating From 9f59e3718669b32e41f3986ce7fce5be56801ca3 Mon Sep 17 00:00:00 2001 From: Christian Date: Fri, 19 Feb 2021 01:47:06 +0100 Subject: [PATCH 329/390] Fix fire replacements --- .../org/kamiblue/client/module/modules/misc/HighwayTools.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index 3e417b1618..3c286728a9 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -1026,7 +1026,7 @@ internal object HighwayTools : Module( } } fillerMat -> { - if (currentBlock != Blocks.AIR && !isLiquid(blockTask.blockPos)) { + if (currentBlock == fillerMat) { blockTask.updateState(TaskState.PLACED) return } From 7b55001df73962991033a936ac02bd423c2f84c2 Mon Sep 17 00:00:00 2001 From: Christian Date: Fri, 19 Feb 2021 02:40:33 +0100 Subject: [PATCH 330/390] Fix diagonal support --- .../module/modules/misc/HighwayTools.kt | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index 3c286728a9..6de2e22fd1 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -124,15 +124,15 @@ internal object HighwayTools : Module( private var breakDelay by setting("Break Delay", 1, 1..20, 1, { page == Page.BEHAVIOR }, description = "Sets the delay ticks between break tasks") private val illegalPlacements by setting("Illegal Placements", false, { page == Page.BEHAVIOR }, description = "Do not use on 2b2t. Tries to interact with invisible surfaces") private val bridging by setting("Bridging", true, { page == Page.BEHAVIOR }, description = "Tries to bridge / scaffold when stuck placing") - private var placementSearch by setting("Place Deep Search", 2, 1..4, 1, { page == Page.BEHAVIOR }, description = "Attempts to find a support block for placing against") private val multiBuilding by setting("Shuffle Tasks", false, { page == Page.BEHAVIOR }, description = "Only activate when working with several players") - private val maxBreaks by setting("Multi Break", 1, 1..5, 1, { page == Page.BEHAVIOR }, description = "Breaks multiple instant breaking blocks per tick in view") private val toggleInventoryManager by setting("Toggle InvManager", false, { page == Page.BEHAVIOR }, description = "Activates InventoryManager on enable") private val toggleAutoObsidian by setting("Toggle AutoObsidian", true, { page == Page.BEHAVIOR }, description = "Activates AutoObsidian on enable") private val taskTimeout by setting("Task Timeout", 8, 0..20, 1, { page == Page.BEHAVIOR }, description = "Timeout for waiting for the server to try again") private val rubberbandTimeout by setting("Rubberband Timeout", 50, 5..100, 5, { page == Page.BEHAVIOR }, description = "Timeout for pausing after a lag") private val maxReach by setting("Max Reach", 4.9f, 1.0f..6.0f, 0.1f, { page == Page.BEHAVIOR }, description = "Sets the range of the blueprint. Decrease when tasks fail!") private val emptyDisable by setting("Disable on no tool", false, { page == Page.BEHAVIOR }, description = "Disables module when pickaxes are out") + private var placementSearch by setting("Place Deep Search", 2, 1..4, 1, { page == Page.BEHAVIOR }, description = "EXPERIMENTAL: Attempts to find a support block for placing against") + private val maxBreaks by setting("Multi Break", 1, 1..5, 1, { page == Page.BEHAVIOR }, description = "EXPERIMENTAL: Breaks multiple instant breaking blocks per tick in view") // stats private val anonymizeStats by setting("Anonymize", false, { page == Page.STATS }, description = "Censors all coordinates in HUD and Chat.") @@ -583,6 +583,7 @@ internal object HighwayTools : Module( val pos = basePos.add(xDirection.directionVec.multiply(x)) if (mode == Mode.HIGHWAY && isRail(w)) { + if (!cornerBlock && startingDirection.isDiagonal) blueprint[pos] = fillerMat val startHeight = if (cornerBlock) 0 else 1 for (y in startHeight..railingHeight) { blueprint[pos.up(y)] = material @@ -617,6 +618,7 @@ internal object HighwayTools : Module( blueprint[basePos.add(xDirection.directionVec.multiply(width - width / 2 - cb)).up(h + 1)] = fillerMat } } + private fun generateRoof(basePos: BlockPos, xDirection: Direction) { for (w in 0 until width) { val x = w - width / 2 @@ -685,7 +687,7 @@ internal object HighwayTools : Module( if (checkTasks(possiblePos.up())) nextPos = possiblePos if (currentBlockPos != nextPos) { - for (x in 1 .. currentBlockPos.distanceTo(nextPos).toInt()) { + for (x in 1..currentBlockPos.distanceTo(nextPos).toInt()) { simpleMovingAverageDistance.add(System.currentTimeMillis()) } refreshData() @@ -963,6 +965,13 @@ internal object HighwayTools : Module( blockTask.updateState(TaskState.DONE) } + if (blockTask.block == fillerMat && + mode == Mode.HIGHWAY && + world.getBlockState(blockTask.blockPos.up()).block == material) { + blockTask.updateState(TaskState.DONE) + return + } + when (world.getBlockState(blockTask.blockPos).block) { Blocks.AIR -> { if (blockTask.block == Blocks.AIR) { @@ -1029,6 +1038,11 @@ internal object HighwayTools : Module( if (currentBlock == fillerMat) { blockTask.updateState(TaskState.PLACED) return + } else if (currentBlock != fillerMat && + mode == Mode.HIGHWAY && + world.getBlockState(blockTask.blockPos.up()).block == material) { + blockTask.updateState(TaskState.DONE) + return } } Blocks.AIR -> { @@ -1254,14 +1268,14 @@ internal object HighwayTools : Module( /* For fire, we just need to mine the top of the block below the fire */ // ToDo: Fix placement issues - if (world.getBlockState(blockTask.blockPos) == Blocks.FIRE) { + if (world.getBlockState(blockTask.blockPos).block == Blocks.FIRE) { val blockBelowFire = blockTask.blockPos.down() if (getVisibleSides(blockBelowFire).contains(EnumFacing.UP)) { playerController.clickBlock(blockBelowFire, EnumFacing.UP) player.swingArm(EnumHand.MAIN_HAND) blockTask.updateState(TaskState.BREAKING) } else { - blockTask.updateState(TaskState.LIQUID_FLOW) + blockTask.updateState(TaskState.PLACE) } return } From 500826f39eaeddae2389f38f1a4a83a451464aaf Mon Sep 17 00:00:00 2001 From: Christian Date: Fri, 19 Feb 2021 02:48:23 +0100 Subject: [PATCH 331/390] Block backup usage --- .../kamiblue/client/module/modules/misc/HighwayTools.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index 6de2e22fd1..0389a8f6c6 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -1080,7 +1080,14 @@ internal object HighwayTools : Module( } private fun SafeClientEvent.swapOrMoveBlock(blockTask: BlockTask): Boolean { - val success = swapToBlockOrMove(blockTask.block, predicateSlot = { + val useBlock = when { + player.allSlots.countBlock(blockTask.block) > 0 -> blockTask.block + player.allSlots.countBlock(material) > 0 -> material + player.allSlots.countBlock(fillerMat) > 0 -> fillerMat + else -> blockTask.block + } + + val success = swapToBlockOrMove(useBlock, predicateSlot = { it.item is ItemBlock }) From 2d3f137dc219f22e54eb8959649356a005b5d57f Mon Sep 17 00:00:00 2001 From: Christian Date: Fri, 19 Feb 2021 02:52:40 +0100 Subject: [PATCH 332/390] Settings val --- .../org/kamiblue/client/module/modules/misc/HighwayTools.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index 0389a8f6c6..7dfdf32ebd 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -120,8 +120,8 @@ internal object HighwayTools : Module( // behavior settings private val interacting by setting("Rotation Mode", RotationMode.SPOOF, { page == Page.BEHAVIOR }, description = "Force view client side, only server side or no interaction at all") private val dynamicDelay by setting("Dynamic Place Delay", true, { page == Page.BEHAVIOR }, description = "Slows down on failed placement attempts") - private var placeDelay by setting("Place Delay", 3, 1..20, 1, { page == Page.BEHAVIOR }, description = "Sets the delay ticks between placement tasks") - private var breakDelay by setting("Break Delay", 1, 1..20, 1, { page == Page.BEHAVIOR }, description = "Sets the delay ticks between break tasks") + private val placeDelay by setting("Place Delay", 3, 1..20, 1, { page == Page.BEHAVIOR }, description = "Sets the delay ticks between placement tasks") + private val breakDelay by setting("Break Delay", 1, 1..20, 1, { page == Page.BEHAVIOR }, description = "Sets the delay ticks between break tasks") private val illegalPlacements by setting("Illegal Placements", false, { page == Page.BEHAVIOR }, description = "Do not use on 2b2t. Tries to interact with invisible surfaces") private val bridging by setting("Bridging", true, { page == Page.BEHAVIOR }, description = "Tries to bridge / scaffold when stuck placing") private val multiBuilding by setting("Shuffle Tasks", false, { page == Page.BEHAVIOR }, description = "Only activate when working with several players") @@ -131,7 +131,7 @@ internal object HighwayTools : Module( private val rubberbandTimeout by setting("Rubberband Timeout", 50, 5..100, 5, { page == Page.BEHAVIOR }, description = "Timeout for pausing after a lag") private val maxReach by setting("Max Reach", 4.9f, 1.0f..6.0f, 0.1f, { page == Page.BEHAVIOR }, description = "Sets the range of the blueprint. Decrease when tasks fail!") private val emptyDisable by setting("Disable on no tool", false, { page == Page.BEHAVIOR }, description = "Disables module when pickaxes are out") - private var placementSearch by setting("Place Deep Search", 2, 1..4, 1, { page == Page.BEHAVIOR }, description = "EXPERIMENTAL: Attempts to find a support block for placing against") + private val placementSearch by setting("Place Deep Search", 2, 1..4, 1, { page == Page.BEHAVIOR }, description = "EXPERIMENTAL: Attempts to find a support block for placing against") private val maxBreaks by setting("Multi Break", 1, 1..5, 1, { page == Page.BEHAVIOR }, description = "EXPERIMENTAL: Breaks multiple instant breaking blocks per tick in view") // stats From ba6656a234280626dd0af3ff0e76de20b7315dbb Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Thu, 18 Feb 2021 21:11:39 -0500 Subject: [PATCH 333/390] Cleaned up SMA code --- .../module/modules/misc/HighwayTools.kt | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index 7dfdf32ebd..00828d6eec 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -72,7 +72,6 @@ import org.kamiblue.client.util.text.MessageSendHelper import org.kamiblue.client.util.threads.* import org.kamiblue.commons.extension.ceilToInt import org.kamiblue.commons.extension.floorToInt -import java.util.* import kotlin.collections.ArrayList import kotlin.collections.LinkedHashMap import kotlin.random.Random.Default.nextInt @@ -136,7 +135,7 @@ internal object HighwayTools : Module( // stats private val anonymizeStats by setting("Anonymize", false, { page == Page.STATS }, description = "Censors all coordinates in HUD and Chat.") - private val simpleMovingAverageRange by setting("Moving Average", 60f, 5f..600f, 5f, { page == Page.STATS }, description = "Sets the timeframe of the average in seconds") + private val simpleMovingAverageRange by setting("Moving Average", 60, 5..600, 5, { page == Page.STATS }, description = "Sets the timeframe of the average in seconds") private val showPerformance by setting("Show Performance", true, { page == Page.STATS }, description = "Toggles the Performance section in HUD") private val showEnvironment by setting("Show Environment", true, { page == Page.STATS }, description = "Toggles the Environment section in HUD") private val showTask by setting("Show Task", true, { page == Page.STATS }, description = "Toggles the Task section in HUD") @@ -444,14 +443,16 @@ internal object HighwayTools : Module( } private fun updateDequeues() { - while (simpleMovingAveragePlaces.isNotEmpty() && System.currentTimeMillis() - simpleMovingAveragePlaces.first() > 1000L * simpleMovingAverageRange) { - simpleMovingAveragePlaces.removeFirst() - } - while (simpleMovingAverageBreaks.isNotEmpty() && System.currentTimeMillis() - simpleMovingAverageBreaks.first() > 1000L * simpleMovingAverageRange) { - simpleMovingAverageBreaks.removeFirst() - } - while (simpleMovingAverageDistance.isNotEmpty() && System.currentTimeMillis() - simpleMovingAverageDistance.first() > 1000L * simpleMovingAverageRange) { - simpleMovingAverageDistance.removeFirst() + val removeTime = System.currentTimeMillis() - simpleMovingAverageRange * 1000L + + updateDeque(simpleMovingAveragePlaces, removeTime) + updateDeque(simpleMovingAverageBreaks, removeTime) + updateDeque(simpleMovingAverageDistance, removeTime) + } + + private fun updateDeque(deque: ArrayDeque, removeTime: Long) { + while (deque.isNotEmpty() && deque.first() < removeTime) { + deque.removeFirst() } } @@ -1429,23 +1430,23 @@ internal object HighwayTools : Module( } private fun gatherPerformance(displayText: TextComponent, runtimeSec: Double, distanceDone: Double) { - val seconds = (runtimeSec % 60).toInt().toString().padStart(2, '0') - val minutes = ((runtimeSec % 3600) / 60).toInt().toString().padStart(2, '0') - val hours = (runtimeSec / 3600).toInt().toString().padStart(2, '0') + val seconds = (runtimeSec % 60.0).toInt().toString().padStart(2, '0') + val minutes = ((runtimeSec % 3600.0) / 60.0).toInt().toString().padStart(2, '0') + val hours = (runtimeSec / 3600.0).toInt().toString().padStart(2, '0') displayText.addLine("Performance", primaryColor) displayText.add(" Runtime:", primaryColor) displayText.addLine("$hours:$minutes:$seconds", secondaryColor) displayText.add(" Placements / s: ", primaryColor) - displayText.addLine("%.2f SMA(%.2f)".format(totalBlocksPlaced / runtimeSec, simpleMovingAveragePlaces.size / simpleMovingAverageRange), secondaryColor) + displayText.addLine("%.2f SMA(%.2f)".format(totalBlocksPlaced / runtimeSec, simpleMovingAveragePlaces.size / simpleMovingAverageRange.toDouble()), secondaryColor) displayText.add(" Breaks / s:", primaryColor) - displayText.addLine("%.2f SMA(%.2f)".format(totalBlocksBroken / runtimeSec, simpleMovingAverageBreaks.size / simpleMovingAverageRange), secondaryColor) + displayText.addLine("%.2f SMA(%.2f)".format(totalBlocksBroken / runtimeSec, simpleMovingAverageBreaks.size / simpleMovingAverageRange.toDouble()), secondaryColor) displayText.add(" Distance km / h:", primaryColor) - displayText.addLine("%.3f SMA(%.3f)".format((distanceDone / runtimeSec * 60 * 60) / 1000, (simpleMovingAverageDistance.size / simpleMovingAverageRange * 60 * 60) / 1000), secondaryColor) + displayText.addLine("%.3f SMA(%.3f)".format((distanceDone / runtimeSec * 60.0 * 60.0) / 1000.0, (simpleMovingAverageDistance.size / simpleMovingAverageRange * 60.0 * 60.0) / 1000.0), secondaryColor) displayText.add(" Food level loss / h:", primaryColor) displayText.addLine("%.2f".format(totalBlocksBroken / foodLoss.toDouble()), secondaryColor) displayText.add(" Pickaxes / h:", primaryColor) - displayText.addLine("%.2f".format((durabilityUsages / runtimeSec) * 60 * 60 / 1561), secondaryColor) + displayText.addLine("%.2f".format((durabilityUsages / runtimeSec) * 60.0 * 60.0 / 1561.0), secondaryColor) } private fun gatherEnvironment(displayText: TextComponent) { From cb538dc835a4f5d72d88c08a37dbd26b5f104d2c Mon Sep 17 00:00:00 2001 From: Christian Date: Fri, 19 Feb 2021 04:06:26 +0100 Subject: [PATCH 334/390] Fix filler on diags --- .../client/module/modules/misc/HighwayTools.kt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index 00828d6eec..c58dce187b 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -965,12 +965,12 @@ internal object HighwayTools : Module( if (ignoreBlocks.contains(world.getBlockState(blockTask.blockPos).block.registryName.toString())) { blockTask.updateState(TaskState.DONE) } - - if (blockTask.block == fillerMat && - mode == Mode.HIGHWAY && - world.getBlockState(blockTask.blockPos.up()).block == material) { - blockTask.updateState(TaskState.DONE) - return + if (blockTask.block == fillerMat && mode == Mode.HIGHWAY) { + if (world.getBlockState(blockTask.blockPos.up()).block == material || + !isPlaceable(blockTask.blockPos)) { + blockTask.updateState(TaskState.DONE) + return + } } when (world.getBlockState(blockTask.blockPos).block) { From 58da797d9431243edd620543b214a7e4a9edaed7 Mon Sep 17 00:00:00 2001 From: Christian Date: Fri, 19 Feb 2021 14:48:34 +0100 Subject: [PATCH 335/390] Enable AntiAFK on empty --- .../org/kamiblue/client/module/modules/misc/HighwayTools.kt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index c58dce187b..2a65968d69 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -130,6 +130,7 @@ internal object HighwayTools : Module( private val rubberbandTimeout by setting("Rubberband Timeout", 50, 5..100, 5, { page == Page.BEHAVIOR }, description = "Timeout for pausing after a lag") private val maxReach by setting("Max Reach", 4.9f, 1.0f..6.0f, 0.1f, { page == Page.BEHAVIOR }, description = "Sets the range of the blueprint. Decrease when tasks fail!") private val emptyDisable by setting("Disable on no tool", false, { page == Page.BEHAVIOR }, description = "Disables module when pickaxes are out") + private val activateAntiAFK by setting("Activate AntiAFK on done", false, { page == Page.BEHAVIOR }, description = "Enables AntiAFK when out of materials") private val placementSearch by setting("Place Deep Search", 2, 1..4, 1, { page == Page.BEHAVIOR }, description = "EXPERIMENTAL: Attempts to find a support block for placing against") private val maxBreaks by setting("Multi Break", 1, 1..5, 1, { page == Page.BEHAVIOR }, description = "EXPERIMENTAL: Breaks multiple instant breaking blocks per tick in view") @@ -1096,6 +1097,7 @@ internal object HighwayTools : Module( MessageSendHelper.sendChatMessage("$chatName No ${blockTask.block.localizedName} was found in inventory") mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) disable() + if (activateAntiAFK) AntiAFK.enable() false } else { true @@ -1214,6 +1216,7 @@ internal object HighwayTools : Module( MessageSendHelper.sendChatMessage("$chatName No ${Items.DIAMOND_PICKAXE} was found in inventory, disable") mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) disable() + if (activateAntiAFK) AntiAFK.enable() } slotFrom.toHotbarSlotOrNull()?.let { swapToSlot(it) From 043b1ec3430127cc5061eaba76f114635dcf4a47 Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 23 Feb 2021 02:29:54 +0100 Subject: [PATCH 336/390] Cleanup blueprint logic --- .../client/module/modules/misc/HighwayTools.kt | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index 2a65968d69..1a8c57f2cb 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -527,10 +527,13 @@ internal object HighwayTools : Module( for (x in -maxReach.floorToInt()..maxReach.ceilToInt()) { val thisPos = basePos.add(zDirection.directionVec.multiply(x)) if (clearSpace) generateClear(thisPos, xDirection) - if (mode != Mode.TUNNEL) generateBase(thisPos, xDirection) - if (mode == Mode.TUNNEL && cleanFloor) generateFloor(thisPos, xDirection) - if (mode == Mode.TUNNEL && cleanWalls) generateWalls(thisPos, xDirection) - if (mode == Mode.TUNNEL && cleanRoof) generateRoof(thisPos, xDirection) + if (mode == Mode.TUNNEL) { + if (cleanFloor) generateFloor(thisPos, xDirection) + if (cleanWalls) generateWalls(thisPos, xDirection) + if (cleanRoof) generateRoof(thisPos, xDirection) + } else { + generateBase(thisPos, xDirection) + } } if (mode == Mode.TUNNEL && !cleanFloor) { if (startingDirection.isDiagonal) { From 283a015e6eb8559474e7417bd6d5c6c2d1b71a47 Mon Sep 17 00:00:00 2001 From: Christian Date: Fri, 19 Feb 2021 14:48:34 +0100 Subject: [PATCH 337/390] Revert "Enable AntiAFK on empty" This reverts commit 58da797d9431243edd620543b214a7e4a9edaed7. --- .../org/kamiblue/client/module/modules/misc/HighwayTools.kt | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index 1a8c57f2cb..b7290f11a6 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -130,7 +130,6 @@ internal object HighwayTools : Module( private val rubberbandTimeout by setting("Rubberband Timeout", 50, 5..100, 5, { page == Page.BEHAVIOR }, description = "Timeout for pausing after a lag") private val maxReach by setting("Max Reach", 4.9f, 1.0f..6.0f, 0.1f, { page == Page.BEHAVIOR }, description = "Sets the range of the blueprint. Decrease when tasks fail!") private val emptyDisable by setting("Disable on no tool", false, { page == Page.BEHAVIOR }, description = "Disables module when pickaxes are out") - private val activateAntiAFK by setting("Activate AntiAFK on done", false, { page == Page.BEHAVIOR }, description = "Enables AntiAFK when out of materials") private val placementSearch by setting("Place Deep Search", 2, 1..4, 1, { page == Page.BEHAVIOR }, description = "EXPERIMENTAL: Attempts to find a support block for placing against") private val maxBreaks by setting("Multi Break", 1, 1..5, 1, { page == Page.BEHAVIOR }, description = "EXPERIMENTAL: Breaks multiple instant breaking blocks per tick in view") @@ -1100,7 +1099,6 @@ internal object HighwayTools : Module( MessageSendHelper.sendChatMessage("$chatName No ${blockTask.block.localizedName} was found in inventory") mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) disable() - if (activateAntiAFK) AntiAFK.enable() false } else { true @@ -1219,7 +1217,6 @@ internal object HighwayTools : Module( MessageSendHelper.sendChatMessage("$chatName No ${Items.DIAMOND_PICKAXE} was found in inventory, disable") mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) disable() - if (activateAntiAFK) AntiAFK.enable() } slotFrom.toHotbarSlotOrNull()?.let { swapToSlot(it) From b4e95333b5f684d68c3b2e58310da523a12ca72d Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 23 Feb 2021 04:49:42 +0100 Subject: [PATCH 338/390] Fixed fire and better tunnel corner block --- .../module/modules/misc/HighwayTools.kt | 76 +++++++++++-------- 1 file changed, 43 insertions(+), 33 deletions(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index b7290f11a6..0222dffd18 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -53,7 +53,6 @@ import org.kamiblue.client.util.WorldUtils import org.kamiblue.client.util.WorldUtils.blackList import org.kamiblue.client.util.WorldUtils.getBetterNeighbour import org.kamiblue.client.util.WorldUtils.getMiningSide -import org.kamiblue.client.util.WorldUtils.getVisibleSides import org.kamiblue.client.util.WorldUtils.isLiquid import org.kamiblue.client.util.WorldUtils.isPlaceable import org.kamiblue.client.util.WorldUtils.shulkerList @@ -107,11 +106,12 @@ internal object HighwayTools : Module( private val cleanFloor by setting("Clean Floor", false, { page == Page.BUILD && mode == Mode.TUNNEL }, description = "Cleans up the tunnels floor") private val cleanWalls by setting("Clean Walls", false, { page == Page.BUILD && mode == Mode.TUNNEL }, description = "Cleans up the tunnels walls") private val cleanRoof by setting("Clean Roof", false, { page == Page.BUILD && mode == Mode.TUNNEL }, description = "Cleans up the tunnels roof") + private val cleanCorner by setting("Clean Corner", false, { page == Page.BUILD && mode == Mode.TUNNEL && !cornerBlock }, description = "Cleans up the tunnels corner") + private val cornerBlock by setting("Corner Block", false, { page == Page.BUILD && (mode == Mode.HIGHWAY || mode == Mode.TUNNEL) }, description = "If activated will break the corner in tunnel or place a corner while paving") private val width by setting("Width", 6, 1..11, 1, { page == Page.BUILD }, description = "Sets the width of blueprint") private val height by setting("Height", 4, 1..6, 1, { page == Page.BUILD && clearSpace }, description = "Sets height of blueprint") private val railing by setting("Railing", true, { page == Page.BUILD && mode == Mode.HIGHWAY }, description = "Adds a railing / rim / border to the highway") private val railingHeight by setting("Railing Height", 1, 1..4, 1, { railing && page == Page.BUILD && mode == Mode.HIGHWAY }, description = "Sets height of railing") - private val cornerBlock by setting("Corner Block", false, { page == Page.BUILD && (mode == Mode.HIGHWAY || mode == Mode.TUNNEL) }, description = "If activated will break the corner in tunnel or place a corner while paving") private val materialSaved = setting("Material", "minecraft:obsidian", { false }) private val fillerMatSaved = setting("FillerMat", "minecraft:netherrack", { false }) val ignoreBlocks = setting(CollectionSetting("IgnoreList", defaultIgnoreBlocks, { false })) @@ -329,6 +329,10 @@ internal object HighwayTools : Module( MessageSendHelper.sendRawChatMessage(" §9> §cMake sure to enable Velocity to not get pushed from your mates.") } + if (material == fillerMat) { + MessageSendHelper.sendRawChatMessage(" §9> §cMake sure to use §aTunnel Mode§c instead of having same material for both main and filler!") + } + } } @@ -530,6 +534,7 @@ internal object HighwayTools : Module( if (cleanFloor) generateFloor(thisPos, xDirection) if (cleanWalls) generateWalls(thisPos, xDirection) if (cleanRoof) generateRoof(thisPos, xDirection) + if (cleanCorner && !cornerBlock) generateCorner(thisPos, xDirection) } else { generateBase(thisPos, xDirection) } @@ -612,14 +617,14 @@ internal object HighwayTools : Module( } private fun generateWalls(basePos: BlockPos, xDirection: Direction) { - for (h in 0 until height) { - val cb = if (!cornerBlock && h == 0) { - 1 - } else { - 0 - } - blueprint[basePos.add(xDirection.directionVec.multiply(-1 - width / 2 + cb)).up(h + 1)] = fillerMat - blueprint[basePos.add(xDirection.directionVec.multiply(width - width / 2 - cb)).up(h + 1)] = fillerMat + val cb = if (!cornerBlock) { + 1 + } else { + 0 + } + for (h in cb until height) { + blueprint[basePos.add(xDirection.directionVec.multiply(-1 - width / 2)).up(h + 1)] = fillerMat + blueprint[basePos.add(xDirection.directionVec.multiply(width - width / 2)).up(h + 1)] = fillerMat } } @@ -631,6 +636,10 @@ internal object HighwayTools : Module( } } + private fun generateCorner(basePos: BlockPos, xDirection: Direction) { + blueprint[basePos.add(xDirection.directionVec.multiply(-1 - width / 2 + 1)).up()] = fillerMat + blueprint[basePos.add(xDirection.directionVec.multiply(width - width / 2 - 1)).up()] = fillerMat + } private fun isRail(w: Int) = railing && w !in 1 until width - 1 @@ -968,7 +977,8 @@ internal object HighwayTools : Module( if (ignoreBlocks.contains(world.getBlockState(blockTask.blockPos).block.registryName.toString())) { blockTask.updateState(TaskState.DONE) } - if (blockTask.block == fillerMat && mode == Mode.HIGHWAY) { + + if (blockTask.block == fillerMat) { if (world.getBlockState(blockTask.blockPos.up()).block == material || !isPlaceable(blockTask.blockPos)) { blockTask.updateState(TaskState.DONE) @@ -1214,7 +1224,7 @@ internal object HighwayTools : Module( return if (slotFrom != null) { if (emptyDisable && slotFrom.stack.item != Items.DIAMOND_PICKAXE) { - MessageSendHelper.sendChatMessage("$chatName No ${Items.DIAMOND_PICKAXE} was found in inventory, disable") + MessageSendHelper.sendChatMessage("$chatName No ${Items.DIAMOND_PICKAXE.registryName} was found in inventory, disable") mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) disable() } @@ -1276,34 +1286,34 @@ internal object HighwayTools : Module( } private fun SafeClientEvent.mineBlock(blockTask: BlockTask) { - - /* For fire, we just need to mine the top of the block below the fire */ - // ToDo: Fix placement issues if (world.getBlockState(blockTask.blockPos).block == Blocks.FIRE) { - val blockBelowFire = blockTask.blockPos.down() - if (getVisibleSides(blockBelowFire).contains(EnumFacing.UP)) { - playerController.clickBlock(blockBelowFire, EnumFacing.UP) - player.swingArm(EnumHand.MAIN_HAND) - blockTask.updateState(TaskState.BREAKING) - } else { + val sides = getBetterNeighbour(blockTask.blockPos, 1, maxReach, true) + if (sides.isEmpty()) { blockTask.updateState(TaskState.PLACE) + return } - return - } - val side = getMiningSide(blockTask.blockPos) ?: run { - blockTask.onStuck() - return - } + lastHitVec = WorldUtils.getHitVec(sides.last().second, sides.last().first) + rotateTimer.reset() - lastHitVec = WorldUtils.getHitVec(blockTask.blockPos, side) - rotateTimer.reset() - - if (world.getBlockState(blockTask.blockPos).getPlayerRelativeBlockHardness(player, world, blockTask.blockPos) > 2.8) { - mineBlockInstant(blockTask, side) + mineBlockNormal(blockTask, sides.last().first) } else { - mineBlockNormal(blockTask, side) + val side = getMiningSide(blockTask.blockPos) ?: run { + blockTask.onStuck() + return + } + + lastHitVec = WorldUtils.getHitVec(blockTask.blockPos, side) + rotateTimer.reset() + + // ToDo: Check for tool dependent speed + if (world.getBlockState(blockTask.blockPos).getPlayerRelativeBlockHardness(player, world, blockTask.blockPos) > 2.8) { + mineBlockInstant(blockTask, side) + } else { + mineBlockNormal(blockTask, side) + } } + } private fun mineBlockInstant(blockTask: BlockTask, side: EnumFacing) { From e7194c9741aceb37daaf00e8760a45be8519a906 Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 23 Feb 2021 05:38:37 +0100 Subject: [PATCH 339/390] Fix fallback --- .../org/kamiblue/client/module/modules/misc/HighwayTools.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index 0222dffd18..510ae701c4 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -1097,7 +1097,7 @@ internal object HighwayTools : Module( val useBlock = when { player.allSlots.countBlock(blockTask.block) > 0 -> blockTask.block player.allSlots.countBlock(material) > 0 -> material - player.allSlots.countBlock(fillerMat) > 0 -> fillerMat + player.allSlots.countBlock(fillerMat) > 0 && mode == Mode.TUNNEL -> fillerMat else -> blockTask.block } From b1d3d6b9c0198698cd5fab11f45c702cc54ab17e Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 23 Feb 2021 15:16:17 +0100 Subject: [PATCH 340/390] Remove ToDo --- .../org/kamiblue/client/module/modules/misc/HighwayTools.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index 510ae701c4..baf31b9ce9 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -1306,7 +1306,6 @@ internal object HighwayTools : Module( lastHitVec = WorldUtils.getHitVec(blockTask.blockPos, side) rotateTimer.reset() - // ToDo: Check for tool dependent speed if (world.getBlockState(blockTask.blockPos).getPlayerRelativeBlockHardness(player, world, blockTask.blockPos) > 2.8) { mineBlockInstant(blockTask, side) } else { From 8dbb917596463844852594767cbac63bcc8c596e Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Tue, 23 Feb 2021 19:03:30 -0500 Subject: [PATCH 341/390] Attempt to fix comparing crash --- .../client/module/modules/misc/HighwayTools.kt | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index baf31b9ce9..cf6ac76df8 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -360,12 +360,20 @@ internal object HighwayTools : Module( when (task.taskState) { TaskState.PENDING_BREAK, TaskState.BREAKING -> { if (new == Blocks.AIR) { - task.updateState(TaskState.BROKEN) + runBlocking { + mutex.withLock { + task.updateState(TaskState.BROKEN) + } + } } } TaskState.PENDING_PLACE -> { if (task.block != Blocks.AIR && task.block == new) { - task.updateState(TaskState.PLACED) + runBlocking { + mutex.withLock { + task.updateState(TaskState.PLACED) + } + } } } else -> { From f3a3aa83da70c94cef0a40410cceb434e02bb922 Mon Sep 17 00:00:00 2001 From: Christian Date: Wed, 24 Feb 2021 01:05:54 +0100 Subject: [PATCH 342/390] Fix double comparing and bump to v09.7 --- gradle.properties | 2 +- .../client/module/modules/misc/HighwayTools.kt | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/gradle.properties b/gradle.properties index 970664fb07..3f18905e42 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ org.gradle.jvmargs=-Xmx3G modGroup=org.kamiblue -modVersion=2.02.xx-dev-ht-v09.5 +modVersion=2.02.xx-dev-ht-v09.7 kotlin_version=1.4.30 kotlinx_coroutines_version=1.4.2 \ No newline at end of file diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index cf6ac76df8..283c1e7e04 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -806,9 +806,9 @@ internal object HighwayTools : Module( } // ToDo: We need a function that makes a score out of those 3 parameters - it.startDistance = (startingBlockPos.distanceTo(it.blockPos) * 100.0).toInt() - it.eyeDistance = (eyePos.distanceTo(it.blockPos) * 100.0).toInt() - it.hitVecDistance = ((lastHitVec?.distanceTo(it.blockPos) ?: 0.0) * 100.0).toInt() + it.startDistance = startingBlockPos.distanceTo(it.blockPos) + it.eyeDistance = eyePos.distanceTo(it.blockPos) + it.hitVecDistance = (lastHitVec?.distanceTo(it.blockPos) ?: 0.0) } runBlocking { @@ -1589,9 +1589,9 @@ internal object HighwayTools : Module( var stuckTicks = 0; private set var shuffle = 0 var sides = 0 - var startDistance = 0 - var eyeDistance = 0 - var hitVecDistance = 0 + var startDistance = 0.0 + var eyeDistance = 0.0 + var hitVecDistance = 0.0 fun updateState(state: TaskState) { if (state == taskState) return From 0fbf3a016e2a1c2f70703f1941c5d0d47db6e396 Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Tue, 23 Feb 2021 19:28:09 -0500 Subject: [PATCH 343/390] Cleaned up codes a bit --- .../module/modules/misc/HighwayTools.kt | 81 ++++++++++--------- 1 file changed, 43 insertions(+), 38 deletions(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index 283c1e7e04..9e0b32705e 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -71,8 +71,6 @@ import org.kamiblue.client.util.text.MessageSendHelper import org.kamiblue.client.util.threads.* import org.kamiblue.commons.extension.ceilToInt import org.kamiblue.commons.extension.floorToInt -import kotlin.collections.ArrayList -import kotlin.collections.LinkedHashMap import kotlin.random.Random.Default.nextInt /** @@ -171,7 +169,6 @@ internal object HighwayTools : Module( } // internal settings - private val mutex = Mutex() var material: Block get() = Block.getBlockFromName(materialSaved.value) ?: Blocks.OBSIDIAN set(value) { @@ -225,6 +222,7 @@ internal object HighwayTools : Module( private var lastToolDamage = 0 private var durabilityUsages = 0 + private val mutex = Mutex() private val renderer = ESPRenderer() override fun isActive(): Boolean { @@ -250,7 +248,7 @@ internal object HighwayTools : Module( startingBlockPos = player.flooredPosition currentBlockPos = startingBlockPos - startingDirection = Direction.fromEntity(Companion.mc.player) + startingDirection = Direction.fromEntity(player) baritoneSettingAllowPlace = BaritoneUtils.settings?.allowPlace?.value ?: true BaritoneUtils.settings?.allowPlace?.value = false @@ -289,11 +287,9 @@ internal object HighwayTools : Module( } } - resetStats.listeners.add { - if (resetStats.value) { - resetStats() - resetStats.value = false - } + resetStats.consumers.add { _, it -> + if (it) resetStats() + false } } @@ -387,9 +383,12 @@ internal object HighwayTools : Module( } is SPacketSetSlot -> { val currentToolDamage = it.packet.stack.itemDamage - if (lastToolDamage < currentToolDamage && currentToolDamage - lastToolDamage < 100) { - durabilityUsages += currentToolDamage - lastToolDamage + val duraUsage = currentToolDamage - lastToolDamage + + if (duraUsage in 1..100) { + durabilityUsages += duraUsage } + lastToolDamage = it.packet.stack.itemDamage } } @@ -740,9 +739,11 @@ internal object HighwayTools : Module( refreshData() } else { waitTicks-- + pendingTasks.values.forEach { doTask(it, true) } + sortTasks() for (task in sortedTasks) { @@ -779,10 +780,11 @@ internal object HighwayTools : Module( } private fun SafeClientEvent.sortTasks() { - val eyePos = mc.player.getPositionEyes(1.0f) if (multiBuilding) { - pendingTasks.values.forEach { it.shuffle() } + pendingTasks.values.forEach { + it.shuffle() + } runBlocking { mutex.withLock { @@ -798,17 +800,10 @@ internal object HighwayTools : Module( } } } else { - pendingTasks.values.forEach { - when (it.taskState) { - TaskState.PLACE -> it.sides = getBetterNeighbour(it.blockPos, placementSearch, maxReach, true).size -// TaskState.BREAK -> - else -> it.sides = 0 - } + val eyePos = player.getPositionEyes(1.0f) - // ToDo: We need a function that makes a score out of those 3 parameters - it.startDistance = startingBlockPos.distanceTo(it.blockPos) - it.eyeDistance = eyePos.distanceTo(it.blockPos) - it.hitVecDistance = (lastHitVec?.distanceTo(it.blockPos) ?: 0.0) + pendingTasks.values.forEach { + it.prepareSortInfo(this, eyePos) } runBlocking { @@ -1139,7 +1134,7 @@ internal object HighwayTools : Module( MessageSendHelper.sendChatMessage("No neighbours found") } } - blockTask.stuck(21) + blockTask.onStuck(21) return } 1 -> { @@ -1294,7 +1289,9 @@ internal object HighwayTools : Module( } private fun SafeClientEvent.mineBlock(blockTask: BlockTask) { - if (world.getBlockState(blockTask.blockPos).block == Blocks.FIRE) { + val blockState = world.getBlockState(blockTask.blockPos) + + if (blockState.block == Blocks.FIRE) { val sides = getBetterNeighbour(blockTask.blockPos, 1, maxReach, true) if (sides.isEmpty()) { blockTask.updateState(TaskState.PLACE) @@ -1314,13 +1311,12 @@ internal object HighwayTools : Module( lastHitVec = WorldUtils.getHitVec(blockTask.blockPos, side) rotateTimer.reset() - if (world.getBlockState(blockTask.blockPos).getPlayerRelativeBlockHardness(player, world, blockTask.blockPos) > 2.8) { + if (blockState.getPlayerRelativeBlockHardness(player, world, blockTask.blockPos) > 2.8) { mineBlockInstant(blockTask, side) } else { mineBlockNormal(blockTask, side) } } - } private fun mineBlockInstant(blockTask: BlockTask, side: EnumFacing) { @@ -1422,8 +1418,6 @@ internal object HighwayTools : Module( } fun SafeClientEvent.gatherStatistics(displayText: TextComponent) { - - val runtimeSec = (runtimeMilliSeconds / 1000) + 0.0001 val distanceDone = startingBlockPos.distanceTo(currentBlockPos).toInt() + totalDistance @@ -1587,14 +1581,15 @@ internal object HighwayTools : Module( ) { private var ranTicks = 0 var stuckTicks = 0; private set - var shuffle = 0 - var sides = 0 - var startDistance = 0.0 - var eyeDistance = 0.0 - var hitVecDistance = 0.0 + var shuffle = 0; private set + var sides = 0; private set + var startDistance = 0.0; private set + var eyeDistance = 0.0; private set + var hitVecDistance = 0.0; private set fun updateState(state: TaskState) { if (state == taskState) return + taskState = state if (state == TaskState.DONE || state == TaskState.PLACED || state == TaskState.BROKEN) { onUpdate() @@ -1603,6 +1598,7 @@ internal object HighwayTools : Module( fun updateMaterial(material: Block) { if (material == block) return + block = material onUpdate() } @@ -1614,12 +1610,21 @@ internal object HighwayTools : Module( } } - fun onStuck() { - stuckTicks++ + fun onStuck(weight: Int = 1) { + stuckTicks += weight } - fun stuck(weight: Int) { - stuckTicks += weight + fun prepareSortInfo(event: SafeClientEvent, eyePos: Vec3d) { + sides = when (taskState) { + TaskState.PLACE -> event.getBetterNeighbour(blockPos, placementSearch, maxReach, true).size + //TaskState.BREAK -> + else -> 0 + } + + // ToDo: We need a function that makes a score out of those 3 parameters + startDistance = startingBlockPos.distanceTo(blockPos) + eyeDistance = eyePos.distanceTo(blockPos) + hitVecDistance = (lastHitVec?.distanceTo(blockPos) ?: 0.0) } fun shuffle() { From 49d7cba59c53b73bd0922a739872f28e02a0ed2a Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Tue, 23 Feb 2021 19:36:44 -0500 Subject: [PATCH 344/390] Cleaned up liquid handling code --- .../module/modules/misc/HighwayTools.kt | 54 +++++++++---------- 1 file changed, 25 insertions(+), 29 deletions(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index 9e0b32705e..9337e744b1 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -1245,46 +1245,42 @@ internal object HighwayTools : Module( private fun SafeClientEvent.handleLiquid(blockTask: BlockTask): Boolean { var foundLiquid = false + for (side in EnumFacing.values()) { - val neighbour = blockTask.blockPos.offset(side) - val neighbourBlock = world.getBlockState(neighbour).block + val neighbourPos = blockTask.blockPos.offset(side) - if (neighbourBlock is BlockLiquid) { - val isFlowing = world.getBlockState(blockTask.blockPos).let { - it.block is BlockLiquid && it.getValue(BlockLiquid.LEVEL) != 0 - } + if (world.getBlockState(neighbourPos).block !is BlockLiquid) continue - if (player.distanceTo(neighbour) > maxReach) { - blockTask.updateState(TaskState.DONE) - return true - } + if (player.distanceTo(neighbourPos) > maxReach) { + blockTask.updateState(TaskState.DONE) + return true + } - foundLiquid = true - val found = ArrayList>() - val filler = if (isInsideBlueprintBuild(neighbour)) material else fillerMat + foundLiquid = true - pendingTasks.values.forEach { - if (it.blockPos == neighbour) { - when (isFlowing) { - false -> found.add(Triple(it, TaskState.LIQUID_SOURCE, filler)) - true -> found.add(Triple(it, TaskState.LIQUID_FLOW, filler)) - } - } + val isFlowing = world.getBlockState(blockTask.blockPos).let { + it.block is BlockLiquid && it.getValue(BlockLiquid.LEVEL) != 0 + } + + val filler = if (isInsideBlueprintBuild(neighbourPos)) material else fillerMat + + pendingTasks[neighbourPos]?.let { + if (isFlowing) { + it.updateState(TaskState.LIQUID_FLOW) + } else { + it.updateState(TaskState.LIQUID_FLOW) } - if (found.isEmpty()) { - when (isFlowing) { - false -> addTaskToPending(neighbour, TaskState.LIQUID_SOURCE, filler) - true -> addTaskToPending(neighbour, TaskState.LIQUID_FLOW, filler) - } + it.updateMaterial(filler) + } ?: run { + if (isFlowing) { + addTaskToPending(neighbourPos, TaskState.LIQUID_FLOW, filler) } else { - found.forEach { - it.first.updateState(it.second) - it.first.updateMaterial(it.third) - } + addTaskToPending(neighbourPos, TaskState.LIQUID_SOURCE, filler) } } } + return foundLiquid } From b34af3d0859345fe2dd0ec1f8c8f94e3b66d13a1 Mon Sep 17 00:00:00 2001 From: Christian Date: Wed, 24 Feb 2021 03:09:29 +0100 Subject: [PATCH 345/390] First packet limiter attempt I got kicked... --- .../module/modules/misc/HighwayTools.kt | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index 9337e744b1..44bc34f434 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -45,11 +45,8 @@ import org.kamiblue.client.module.modules.player.LagNotifier import org.kamiblue.client.process.HighwayToolsProcess import org.kamiblue.client.process.PauseProcess import org.kamiblue.client.setting.settings.impl.collection.CollectionSetting -import org.kamiblue.client.util.BaritoneUtils +import org.kamiblue.client.util.* import org.kamiblue.client.util.EntityUtils.flooredPosition -import org.kamiblue.client.util.TickTimer -import org.kamiblue.client.util.TimeUnit -import org.kamiblue.client.util.WorldUtils import org.kamiblue.client.util.WorldUtils.blackList import org.kamiblue.client.util.WorldUtils.getBetterNeighbour import org.kamiblue.client.util.WorldUtils.getMiningSide @@ -206,6 +203,7 @@ internal object HighwayTools : Module( private val doneTasks = LinkedHashMap() private var sortedTasks: List = emptyList() var lastTask: BlockTask? = null; private set + private val packetLimiter = ArrayDeque() // Stats private val simpleMovingAveragePlaces = ArrayDeque() @@ -459,6 +457,8 @@ internal object HighwayTools : Module( updateDeque(simpleMovingAveragePlaces, removeTime) updateDeque(simpleMovingAverageBreaks, removeTime) updateDeque(simpleMovingAverageDistance, removeTime) + + updateDeque(packetLimiter, System.currentTimeMillis() - 1000L) } private fun updateDeque(deque: ArrayDeque, removeTime: Long) { @@ -1317,6 +1317,8 @@ internal object HighwayTools : Module( private fun mineBlockInstant(blockTask: BlockTask, side: EnumFacing) { waitTicks = breakDelay + packetLimiter.add(System.currentTimeMillis()) + MessageSendHelper.sendChatMessage("${packetLimiter.size}") blockTask.updateState(TaskState.PENDING_BREAK) defaultScope.launch { @@ -1325,7 +1327,14 @@ internal object HighwayTools : Module( // ToDo: Hard limit for TPS to avoid kicks if (maxBreaks > 1) { - tryMultiBreak(blockTask) + if (packetLimiter.size < TpsCalculator.tickRate) { + tryMultiBreak(blockTask) + } else { + if (debugMessages == DebugMessages.ALL) { + MessageSendHelper.sendChatMessage("$chatName Dropped possible instant mine action @ TPS(${TpsCalculator.tickRate}) Actions(${packetLimiter.size})") + } + } + } delay(50L * taskTimeout) @@ -1614,7 +1623,7 @@ internal object HighwayTools : Module( sides = when (taskState) { TaskState.PLACE -> event.getBetterNeighbour(blockPos, placementSearch, maxReach, true).size //TaskState.BREAK -> - else -> 0 + else -> 0 } // ToDo: We need a function that makes a score out of those 3 parameters From 0a7db74834bfccc66af8c29f7a200b88bc833286 Mon Sep 17 00:00:00 2001 From: Christian Date: Wed, 24 Feb 2021 05:15:48 +0100 Subject: [PATCH 346/390] Fix attempt multi break --- .../module/modules/misc/HighwayTools.kt | 51 +++++++++++++++---- 1 file changed, 41 insertions(+), 10 deletions(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index 44bc34f434..eb2d362850 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -1,6 +1,7 @@ package org.kamiblue.client.module.modules.misc import baritone.api.pathing.goals.GoalNear +import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.delay import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking @@ -23,6 +24,7 @@ import net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock import net.minecraft.network.play.server.SPacketBlockChange import net.minecraft.network.play.server.SPacketPlayerPosLook import net.minecraft.network.play.server.SPacketSetSlot +import net.minecraft.stats.StatList import net.minecraft.util.EnumFacing import net.minecraft.util.EnumHand import net.minecraft.util.SoundCategory @@ -30,6 +32,7 @@ import net.minecraft.util.math.AxisAlignedBB import net.minecraft.util.math.BlockPos import net.minecraft.util.math.Vec3d import net.minecraftforge.fml.common.gameevent.TickEvent +import org.kamiblue.client.KamiMod import org.kamiblue.client.event.SafeClientEvent import org.kamiblue.client.event.events.PacketEvent import org.kamiblue.client.event.events.RenderWorldEvent @@ -68,6 +71,10 @@ import org.kamiblue.client.util.text.MessageSendHelper import org.kamiblue.client.util.threads.* import org.kamiblue.commons.extension.ceilToInt import org.kamiblue.commons.extension.floorToInt +import java.io.File +import java.io.FileWriter +import java.time.LocalTime +import java.time.format.DateTimeFormatter import kotlin.random.Random.Default.nextInt /** @@ -127,6 +134,7 @@ internal object HighwayTools : Module( private val emptyDisable by setting("Disable on no tool", false, { page == Page.BEHAVIOR }, description = "Disables module when pickaxes are out") private val placementSearch by setting("Place Deep Search", 2, 1..4, 1, { page == Page.BEHAVIOR }, description = "EXPERIMENTAL: Attempts to find a support block for placing against") private val maxBreaks by setting("Multi Break", 1, 1..5, 1, { page == Page.BEHAVIOR }, description = "EXPERIMENTAL: Breaks multiple instant breaking blocks per tick in view") + private val limitFactor by setting("Limit Factor", 1.0f, 0.5f..2.0f, 0.01f, { page == Page.BEHAVIOR }, description = "EXPERIMENTAL: Factor for TPS wich acts as limit for maximum breaks per second.") // stats private val anonymizeStats by setting("Anonymize", false, { page == Page.STATS }, description = "Censors all coordinates in HUD and Chat.") @@ -136,6 +144,7 @@ internal object HighwayTools : Module( private val showTask by setting("Show Task", true, { page == Page.STATS }, description = "Toggles the Task section in HUD") private val showEstimations by setting("Show Estimations", true, { page == Page.STATS }, description = "Toggles the Estimations section in HUD") private val resetStats = setting("Reset Stats", false, { page == Page.STATS }, description = "Resets the stats") + private val safeStats = setting("Safe Stats", false, { page == Page.STATS }, description = "Safes the stats to json to /kamiblue/stats") // config private val fakeSounds by setting("Fake Sounds", true, { page == Page.CONFIG }, description = "Adds artificial sounds to the actions") @@ -289,6 +298,11 @@ internal object HighwayTools : Module( if (it) resetStats() false } + + safeStats.consumers.add { _, it -> + if (it) safeStats() + false + } } private fun printEnable() { @@ -1318,23 +1332,14 @@ internal object HighwayTools : Module( private fun mineBlockInstant(blockTask: BlockTask, side: EnumFacing) { waitTicks = breakDelay packetLimiter.add(System.currentTimeMillis()) - MessageSendHelper.sendChatMessage("${packetLimiter.size}") blockTask.updateState(TaskState.PENDING_BREAK) defaultScope.launch { delay(20L) sendMiningPackets(blockTask.blockPos, side) - // ToDo: Hard limit for TPS to avoid kicks if (maxBreaks > 1) { - if (packetLimiter.size < TpsCalculator.tickRate) { - tryMultiBreak(blockTask) - } else { - if (debugMessages == DebugMessages.ALL) { - MessageSendHelper.sendChatMessage("$chatName Dropped possible instant mine action @ TPS(${TpsCalculator.tickRate}) Actions(${packetLimiter.size})") - } - } - + tryMultiBreak(blockTask) } delay(50L * taskTimeout) @@ -1354,6 +1359,12 @@ internal object HighwayTools : Module( for (task in sortedTasks) { if (breakCount >= maxBreaks) break + if (packetLimiter.size > TpsCalculator.tickRate * limitFactor) { + if (debugMessages == DebugMessages.ALL) { + MessageSendHelper.sendChatMessage("$chatName Dropped possible instant mine action @ TPS(${TpsCalculator.tickRate}) Actions(${packetLimiter.size})") + } + break + } if (task == blockTask) continue if (task.taskState != TaskState.BREAK) continue @@ -1366,6 +1377,7 @@ internal object HighwayTools : Module( breakCount++ defaultScope.launch { + packetLimiter.add(System.currentTimeMillis()) sendMiningPackets(task.blockPos, rayTraceResult.sideHit) delay(50L * taskTimeout) @@ -1573,6 +1585,25 @@ internal object HighwayTools : Module( durabilityUsages = 0 } + private fun safeStats() { + defaultScope.launch(Dispatchers.IO) { + val directory = "${KamiMod.DIRECTORY}stats" + val filename = "${DateTimeFormatter.ofPattern("HH-mm-ss_SSS").format(LocalTime.now())}.json" + + try { + with(File(directory)) { + if (!exists()) mkdir() + } + + FileWriter("$directory/$filename", true).buffered().use { + it.write(StatList.ALL_STATS.toString()) + } + } catch (e: Exception) { + KamiMod.LOG.warn("$chatName Failed saving stats json!", e) + } + } + } + private fun addTaskComponentList(displayText: TextComponent, tasks: Collection) { tasks.forEach { displayText.addLine(" ${it.block.localizedName}@(${it.blockPos.asString()}) State: ${it.taskState} Timings: (Threshold: ${it.taskState.stuckThreshold} Timeout: ${it.taskState.stuckTimeout}) Priority: ${it.taskState.ordinal} Stuck: ${it.stuckTicks}") From 6007423a04b29ded2cce76869940032cd2ce7f09 Mon Sep 17 00:00:00 2001 From: Christian Date: Wed, 24 Feb 2021 05:55:50 +0100 Subject: [PATCH 347/390] Fix out of food and add factor for packet limit --- .../module/modules/misc/HighwayTools.kt | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index eb2d362850..c22bef2c45 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -13,7 +13,6 @@ import net.minecraft.client.audio.PositionedSoundRecord import net.minecraft.enchantment.EnchantmentHelper import net.minecraft.init.Blocks import net.minecraft.init.Enchantments -import net.minecraft.init.Items import net.minecraft.init.SoundEvents import net.minecraft.inventory.Slot import net.minecraft.item.ItemBlock @@ -131,10 +130,9 @@ internal object HighwayTools : Module( private val taskTimeout by setting("Task Timeout", 8, 0..20, 1, { page == Page.BEHAVIOR }, description = "Timeout for waiting for the server to try again") private val rubberbandTimeout by setting("Rubberband Timeout", 50, 5..100, 5, { page == Page.BEHAVIOR }, description = "Timeout for pausing after a lag") private val maxReach by setting("Max Reach", 4.9f, 1.0f..6.0f, 0.1f, { page == Page.BEHAVIOR }, description = "Sets the range of the blueprint. Decrease when tasks fail!") - private val emptyDisable by setting("Disable on no tool", false, { page == Page.BEHAVIOR }, description = "Disables module when pickaxes are out") - private val placementSearch by setting("Place Deep Search", 2, 1..4, 1, { page == Page.BEHAVIOR }, description = "EXPERIMENTAL: Attempts to find a support block for placing against") private val maxBreaks by setting("Multi Break", 1, 1..5, 1, { page == Page.BEHAVIOR }, description = "EXPERIMENTAL: Breaks multiple instant breaking blocks per tick in view") - private val limitFactor by setting("Limit Factor", 1.0f, 0.5f..2.0f, 0.01f, { page == Page.BEHAVIOR }, description = "EXPERIMENTAL: Factor for TPS wich acts as limit for maximum breaks per second.") + private val limitFactor by setting("Limit Factor", 1.0f, 0.5f..2.0f, 0.01f, { page == Page.BEHAVIOR }, description = "EXPERIMENTAL: Factor for TPS witch acts as limit for maximum breaks per second.") + private val placementSearch by setting("Place Deep Search", 2, 1..4, 1, { page == Page.BEHAVIOR }, description = "EXPERIMENTAL: Attempts to find a support block for placing against") // stats private val anonymizeStats by setting("Anonymize", false, { page == Page.STATS }, description = "Censors all coordinates in HUD and Chat.") @@ -144,7 +142,7 @@ internal object HighwayTools : Module( private val showTask by setting("Show Task", true, { page == Page.STATS }, description = "Toggles the Task section in HUD") private val showEstimations by setting("Show Estimations", true, { page == Page.STATS }, description = "Toggles the Estimations section in HUD") private val resetStats = setting("Reset Stats", false, { page == Page.STATS }, description = "Resets the stats") - private val safeStats = setting("Safe Stats", false, { page == Page.STATS }, description = "Safes the stats to json to /kamiblue/stats") + private val safeStats = setting("Safe Stats", false, { page == Page.STATS }, description = "Safes the stats as json to /kamiblue/stats") // config private val fakeSounds by setting("Fake Sounds", true, { page == Page.CONFIG }, description = "Adds artificial sounds to the actions") @@ -395,10 +393,10 @@ internal object HighwayTools : Module( } is SPacketSetSlot -> { val currentToolDamage = it.packet.stack.itemDamage - val duraUsage = currentToolDamage - lastToolDamage + val durabilityUsage = currentToolDamage - lastToolDamage - if (duraUsage in 1..100) { - durabilityUsages += duraUsage + if (durabilityUsage in 1..100) { + durabilityUsages += durabilityUsage } lastToolDamage = it.packet.stack.itemDamage @@ -459,6 +457,11 @@ internal object HighwayTools : Module( private fun SafeClientEvent.updateFood() { val currentFood = player.foodStats.foodLevel + if (currentFood < 7.0) { + MessageSendHelper.sendChatMessage("$chatName Out of food, disabling") + mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) + disable() + } if (currentFood != prevFood) { if (currentFood < prevFood) foodLoss++ prevFood = currentFood @@ -1240,11 +1243,11 @@ internal object HighwayTools : Module( val slotFrom = getBestTool(blockTask) return if (slotFrom != null) { - if (emptyDisable && slotFrom.stack.item != Items.DIAMOND_PICKAXE) { - MessageSendHelper.sendChatMessage("$chatName No ${Items.DIAMOND_PICKAXE.registryName} was found in inventory, disable") - mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) - disable() - } +// if (emptyDisable && slotFrom.stack.item != Items.DIAMOND_PICKAXE) { +// MessageSendHelper.sendChatMessage("$chatName No ${Items.DIAMOND_PICKAXE.registryName} was found in inventory, disable") +// mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) +// disable() +// } slotFrom.toHotbarSlotOrNull()?.let { swapToSlot(it) } ?: run { From 57540c7a6b0f8729ba4631c5ab0f73fd79ef9ca2 Mon Sep 17 00:00:00 2001 From: Christian Date: Wed, 24 Feb 2021 07:03:23 +0100 Subject: [PATCH 348/390] Add chatName to log --- .../kamiblue/client/module/modules/misc/HighwayTools.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index c22bef2c45..56a63796bf 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -1095,9 +1095,9 @@ internal object HighwayTools : Module( if (!isPlaceable(blockTask.blockPos)) { if (debugMessages == DebugMessages.ALL) { if (!anonymizeStats) { - MessageSendHelper.sendChatMessage("Invalid place position: ${blockTask.blockPos}. Removing task") + MessageSendHelper.sendChatMessage("$chatName Invalid place position: ${blockTask.blockPos}. Removing task") } else { - MessageSendHelper.sendChatMessage("Invalid place position. Removing task") + MessageSendHelper.sendChatMessage("$chatName Invalid place position. Removing task") } } pendingTasks.remove(blockTask.blockPos) @@ -1146,9 +1146,9 @@ internal object HighwayTools : Module( 0 -> { if (debugMessages == DebugMessages.ALL) { if (!anonymizeStats) { - MessageSendHelper.sendChatMessage("No neighbours found for ${blockTask.blockPos}") + MessageSendHelper.sendChatMessage("$chatName No neighbours found for ${blockTask.blockPos}") } else { - MessageSendHelper.sendChatMessage("No neighbours found") + MessageSendHelper.sendChatMessage("$chatName No neighbours found") } } blockTask.onStuck(21) From 260fab26074c9b79a2ba1e63f2b9d53d00d00d7d Mon Sep 17 00:00:00 2001 From: Christian Date: Thu, 25 Feb 2021 02:01:05 +0100 Subject: [PATCH 349/390] Pause when in queue and break check --- .../module/modules/misc/AutoObsidian.kt | 6 +++- .../module/modules/misc/HighwayTools.kt | 29 ++++++++++++++----- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/AutoObsidian.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/AutoObsidian.kt index 97246aa4d3..822fa096d7 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/AutoObsidian.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/AutoObsidian.kt @@ -26,6 +26,7 @@ import net.minecraft.util.EnumHand import net.minecraft.util.math.BlockPos import net.minecraft.util.math.RayTraceResult import net.minecraft.util.math.Vec3d +import net.minecraft.world.EnumDifficulty import net.minecraftforge.fml.common.gameevent.TickEvent import org.kamiblue.client.event.SafeClientEvent import org.kamiblue.client.event.events.BlockBreakEvent @@ -171,7 +172,10 @@ internal object AutoObsidian : Module( } safeListener(69) { - if (it.phase != TickEvent.Phase.START || PauseProcess.isActive) return@safeListener + if (it.phase != TickEvent.Phase.START || PauseProcess.isActive || + (world.difficulty == EnumDifficulty.PEACEFUL && + player.dimension == 1 && + player.serverBrand.contains("2b2t"))) return@safeListener updateMiningMap() runAutoObby() diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index 56a63796bf..e8f7896bb8 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -30,6 +30,7 @@ import net.minecraft.util.SoundCategory import net.minecraft.util.math.AxisAlignedBB import net.minecraft.util.math.BlockPos import net.minecraft.util.math.Vec3d +import net.minecraft.world.EnumDifficulty import net.minecraftforge.fml.common.gameevent.TickEvent import org.kamiblue.client.KamiMod import org.kamiblue.client.event.SafeClientEvent @@ -417,7 +418,9 @@ internal object HighwayTools : Module( if (!rubberbandTimer.tick(rubberbandTimeout.toLong(), false) || PauseProcess.isActive || AutoObsidian.isActive() || - (player.isCreative && player.serverBrand.contains("2b2t"))) { + (world.difficulty == EnumDifficulty.PEACEFUL && + player.dimension == 1 && + player.serverBrand.contains("2b2t"))) { refreshData() return@safeListener } @@ -994,19 +997,29 @@ internal object HighwayTools : Module( } private fun SafeClientEvent.doBreak(blockTask: BlockTask, updateOnly: Boolean) { - if (ignoreBlocks.contains(world.getBlockState(blockTask.blockPos).block.registryName.toString())) { + val currentBlock = world.getBlockState(blockTask.blockPos).block + + if (ignoreBlocks.contains(currentBlock.registryName.toString())) { blockTask.updateState(TaskState.DONE) } - if (blockTask.block == fillerMat) { - if (world.getBlockState(blockTask.blockPos.up()).block == material || - !isPlaceable(blockTask.blockPos)) { - blockTask.updateState(TaskState.DONE) - return + when (blockTask.block) { + fillerMat -> { + if (world.getBlockState(blockTask.blockPos.up()).block == material || + !isPlaceable(blockTask.blockPos)) { + blockTask.updateState(TaskState.DONE) + return + } + } + material -> { + if (currentBlock == material) { + blockTask.updateState(TaskState.DONE) + return + } } } - when (world.getBlockState(blockTask.blockPos).block) { + when (currentBlock) { Blocks.AIR -> { if (blockTask.block == Blocks.AIR) { blockTask.updateState(TaskState.BROKEN) From 5908a6d1ab2b862e5df3f379c3ee803ec527e133 Mon Sep 17 00:00:00 2001 From: Christian Date: Fri, 26 Feb 2021 03:02:24 +0100 Subject: [PATCH 350/390] Life stats, supress disable --- .../module/modules/misc/AutoObsidian.kt | 11 +-- .../module/modules/misc/HighwayTools.kt | 80 +++++++++++-------- 2 files changed, 51 insertions(+), 40 deletions(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/AutoObsidian.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/AutoObsidian.kt index 822fa096d7..6ff3f3f10b 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/AutoObsidian.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/AutoObsidian.kt @@ -70,6 +70,7 @@ internal object AutoObsidian : Module( private val instantMiningDelay by setting("Instant Mining Delay", 10, 1..20, 1, { instantMining }) private val threshold by setting("Refill Threshold", 32, 1..64, 1, { autoRefill && fillMode != FillMode.INFINITE }) private val targetStacks by setting("Target Stacks", 1, 1..20, 1, { fillMode == FillMode.TARGET_STACKS }) + private val noDisable by setting("No Disable", false) private val delayTicks by setting("Delay Ticks", 4, 1..10, 1) private val rotationMode by setting("Rotation Mode", RotationMode.SPOOF) private val maxReach by setting("Max Reach", 4.9f, 2.0f..6.0f, 0.1f) @@ -283,7 +284,7 @@ internal object AutoObsidian : Module( } else { MessageSendHelper.sendChatMessage("$chatName No valid position for placing shulker box / ender chest nearby, disabling.") mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) - disable() + if (!noDisable) disable() } } @@ -462,7 +463,7 @@ internal object AutoObsidian : Module( if (!moved) { MessageSendHelper.sendChatMessage("$chatName No shulker box was found in inventory, disabling.") mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) - disable() + if (!noDisable) disable() } onInventoryOperation() @@ -487,7 +488,7 @@ internal object AutoObsidian : Module( if (!moved) { MessageSendHelper.sendChatMessage("$chatName No ender chest was found in inventory, disabling.") mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) - disable() + if (!noDisable) disable() } onInventoryOperation() @@ -512,7 +513,7 @@ internal object AutoObsidian : Module( } else { MessageSendHelper.sendChatMessage("$chatName No ender chest was found in shulker, disabling.") mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) - disable() + if (!noDisable) disable() } } } else { @@ -626,7 +627,7 @@ internal object AutoObsidian : Module( if (!moved) { MessageSendHelper.sendChatMessage("No valid pickaxe was found in inventory.") mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) - disable() + if (!noDisable) disable() } onInventoryOperation() diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index e8f7896bb8..45d60e6352 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -17,6 +17,7 @@ import net.minecraft.init.SoundEvents import net.minecraft.inventory.Slot import net.minecraft.item.ItemBlock import net.minecraft.item.ItemPickaxe +import net.minecraft.network.play.client.CPacketClientStatus import net.minecraft.network.play.client.CPacketEntityAction import net.minecraft.network.play.client.CPacketPlayerDigging import net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock @@ -138,12 +139,13 @@ internal object HighwayTools : Module( // stats private val anonymizeStats by setting("Anonymize", false, { page == Page.STATS }, description = "Censors all coordinates in HUD and Chat.") private val simpleMovingAverageRange by setting("Moving Average", 60, 5..600, 5, { page == Page.STATS }, description = "Sets the timeframe of the average in seconds") + private val statUpdateSpeed by setting("Update Speed Seconds", 60, 1..600, 5, { page == Page.STATS }, description = "Sets the frequency of the stat updating in seconds") + private val showSession by setting("Show Session", true, { page == Page.STATS }, description = "Toggles the Session section in HUD") private val showPerformance by setting("Show Performance", true, { page == Page.STATS }, description = "Toggles the Performance section in HUD") private val showEnvironment by setting("Show Environment", true, { page == Page.STATS }, description = "Toggles the Environment section in HUD") private val showTask by setting("Show Task", true, { page == Page.STATS }, description = "Toggles the Task section in HUD") private val showEstimations by setting("Show Estimations", true, { page == Page.STATS }, description = "Toggles the Estimations section in HUD") private val resetStats = setting("Reset Stats", false, { page == Page.STATS }, description = "Resets the stats") - private val safeStats = setting("Safe Stats", false, { page == Page.STATS }, description = "Safes the stats as json to /kamiblue/stats") // config private val fakeSounds by setting("Fake Sounds", true, { page == Page.CONFIG }, description = "Adds artificial sounds to the actions") @@ -297,11 +299,6 @@ internal object HighwayTools : Module( if (it) resetStats() false } - - safeStats.consumers.add { _, it -> - if (it) safeStats() - false - } } private fun printEnable() { @@ -429,6 +426,9 @@ internal object HighwayTools : Module( active = true BaritoneUtils.primary?.pathingControlManager?.registerProcess(HighwayToolsProcess) } else { + if (runtimeMilliSeconds % (1000 * statUpdateSpeed) == 0) { + connection.sendPacket(CPacketClientStatus(CPacketClientStatus.State.REQUEST_STATS)) + } runtimeMilliSeconds += 50 updateDequeues() } @@ -1454,8 +1454,7 @@ internal object HighwayTools : Module( val runtimeSec = (runtimeMilliSeconds / 1000) + 0.0001 val distanceDone = startingBlockPos.distanceTo(currentBlockPos).toInt() + totalDistance -// val statList = Gson().fromJson(StatList.MINE_BLOCK_STATS[0], Any::class.java) -// MessageSendHelper.sendChatMessage(statList) + if (showSession) gatherSession(displayText, runtimeSec) if (showPerformance) gatherPerformance(displayText, runtimeSec, distanceDone) @@ -1476,36 +1475,66 @@ internal object HighwayTools : Module( } } - private fun gatherPerformance(displayText: TextComponent, runtimeSec: Double, distanceDone: Double) { + private fun SafeClientEvent.gatherSession(displayText: TextComponent, runtimeSec: Double) { val seconds = (runtimeSec % 60.0).toInt().toString().padStart(2, '0') val minutes = ((runtimeSec % 3600.0) / 60.0).toInt().toString().padStart(2, '0') val hours = (runtimeSec / 3600.0).toInt().toString().padStart(2, '0') - displayText.addLine("Performance", primaryColor) + displayText.addLine("Session", primaryColor) + displayText.add(" Runtime:", primaryColor) displayText.addLine("$hours:$minutes:$seconds", secondaryColor) + + displayText.add(" Direction:", primaryColor) + displayText.addLine("${startingDirection.displayName} / ${startingDirection.displayNameXY}", secondaryColor) + + if (!anonymizeStats) displayText.add(" Start:", primaryColor) + if (!anonymizeStats) displayText.addLine("(${startingBlockPos.asString()})", secondaryColor) + + displayText.add(" Session placed / destroyed:", primaryColor) + displayText.addLine("%,d".format(totalBlocksPlaced).padStart(7, '0') + " / " + "%,d".format(totalBlocksBroken).padStart(7, '0'), secondaryColor) + + displayText.add(" ${material.localizedName} placed:", primaryColor) + StatList.getObjectUseStats(material.item)?.let { + displayText.addLine("%,d".format(player.statFileWriter.readStat(it)).padStart(11, '0'), secondaryColor) + } + + displayText.add(" ${Blocks.NETHERRACK.localizedName} mined:", primaryColor) + StatList.getBlockStats(Blocks.NETHERRACK)?.let { + displayText.addLine("%,d".format(player.statFileWriter.readStat(it)).padStart(11, '0'), secondaryColor) + } + + displayText.add(" ${Blocks.ENDER_CHEST.localizedName} mined:", primaryColor) + StatList.getBlockStats(Blocks.ENDER_CHEST)?.let { + displayText.addLine("%,d".format(player.statFileWriter.readStat(it)).padStart(11, '0'), secondaryColor) + } + } + + private fun gatherPerformance(displayText: TextComponent, runtimeSec: Double, distanceDone: Double) { + displayText.addLine("Performance", primaryColor) + displayText.add(" Placements / s: ", primaryColor) displayText.addLine("%.2f SMA(%.2f)".format(totalBlocksPlaced / runtimeSec, simpleMovingAveragePlaces.size / simpleMovingAverageRange.toDouble()), secondaryColor) + displayText.add(" Breaks / s:", primaryColor) displayText.addLine("%.2f SMA(%.2f)".format(totalBlocksBroken / runtimeSec, simpleMovingAverageBreaks.size / simpleMovingAverageRange.toDouble()), secondaryColor) + displayText.add(" Distance km / h:", primaryColor) displayText.addLine("%.3f SMA(%.3f)".format((distanceDone / runtimeSec * 60.0 * 60.0) / 1000.0, (simpleMovingAverageDistance.size / simpleMovingAverageRange * 60.0 * 60.0) / 1000.0), secondaryColor) + displayText.add(" Food level loss / h:", primaryColor) displayText.addLine("%.2f".format(totalBlocksBroken / foodLoss.toDouble()), secondaryColor) + displayText.add(" Pickaxes / h:", primaryColor) displayText.addLine("%.2f".format((durabilityUsages / runtimeSec) * 60.0 * 60.0 / 1561.0), secondaryColor) } private fun gatherEnvironment(displayText: TextComponent) { displayText.addLine("Environment", primaryColor) - if (!anonymizeStats) displayText.add(" Start:", primaryColor) - if (!anonymizeStats) displayText.addLine("(${startingBlockPos.asString()})", secondaryColor) - displayText.add(" Direction:", primaryColor) - displayText.addLine("${startingDirection.displayName} / ${startingDirection.displayNameXY}", secondaryColor) - displayText.add(" Blocks placed / destroyed:", primaryColor) - displayText.addLine("$totalBlocksPlaced".padStart(6, '0') + " / " + "$totalBlocksBroken".padStart(6, '0'), secondaryColor) displayText.add(" Materials:", primaryColor) displayText.addLine("Main(${material.localizedName}) Filler(${fillerMat.localizedName})", secondaryColor) + displayText.add(" Dimensions:", primaryColor) + displayText.addLine("Width($width) Height($height)", secondaryColor) displayText.add(" Delays:", primaryColor) if (dynamicDelay) { displayText.addLine("Place(${placeDelay + extraPlaceDelay}) Break($breakDelay)", secondaryColor) @@ -1601,25 +1630,6 @@ internal object HighwayTools : Module( durabilityUsages = 0 } - private fun safeStats() { - defaultScope.launch(Dispatchers.IO) { - val directory = "${KamiMod.DIRECTORY}stats" - val filename = "${DateTimeFormatter.ofPattern("HH-mm-ss_SSS").format(LocalTime.now())}.json" - - try { - with(File(directory)) { - if (!exists()) mkdir() - } - - FileWriter("$directory/$filename", true).buffered().use { - it.write(StatList.ALL_STATS.toString()) - } - } catch (e: Exception) { - KamiMod.LOG.warn("$chatName Failed saving stats json!", e) - } - } - } - private fun addTaskComponentList(displayText: TextComponent, tasks: Collection) { tasks.forEach { displayText.addLine(" ${it.block.localizedName}@(${it.blockPos.asString()}) State: ${it.taskState} Timings: (Threshold: ${it.taskState.stuckThreshold} Timeout: ${it.taskState.stuckTimeout}) Priority: ${it.taskState.ordinal} Stuck: ${it.stuckTicks}") From 11206d1dfdf59b0bdb67097f7f19ebc026f7a861 Mon Sep 17 00:00:00 2001 From: Christian Date: Fri, 26 Feb 2021 03:05:13 +0100 Subject: [PATCH 351/390] Clean imports --- .../org/kamiblue/client/module/modules/misc/HighwayTools.kt | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index 45d60e6352..221f1be97e 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -1,7 +1,6 @@ package org.kamiblue.client.module.modules.misc import baritone.api.pathing.goals.GoalNear -import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.delay import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking @@ -33,7 +32,6 @@ import net.minecraft.util.math.BlockPos import net.minecraft.util.math.Vec3d import net.minecraft.world.EnumDifficulty import net.minecraftforge.fml.common.gameevent.TickEvent -import org.kamiblue.client.KamiMod import org.kamiblue.client.event.SafeClientEvent import org.kamiblue.client.event.events.PacketEvent import org.kamiblue.client.event.events.RenderWorldEvent @@ -72,10 +70,6 @@ import org.kamiblue.client.util.text.MessageSendHelper import org.kamiblue.client.util.threads.* import org.kamiblue.commons.extension.ceilToInt import org.kamiblue.commons.extension.floorToInt -import java.io.File -import java.io.FileWriter -import java.time.LocalTime -import java.time.format.DateTimeFormatter import kotlin.random.Random.Default.nextInt /** From a1fb286c8f12075457a6bbb39ae6cac98129dcf6 Mon Sep 17 00:00:00 2001 From: Christian Date: Fri, 26 Feb 2021 03:24:38 +0100 Subject: [PATCH 352/390] Better structure --- .../client/module/modules/misc/HighwayTools.kt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index 221f1be97e..70928e327c 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -1525,10 +1525,13 @@ internal object HighwayTools : Module( private fun gatherEnvironment(displayText: TextComponent) { displayText.addLine("Environment", primaryColor) + displayText.add(" Materials:", primaryColor) displayText.addLine("Main(${material.localizedName}) Filler(${fillerMat.localizedName})", secondaryColor) + displayText.add(" Dimensions:", primaryColor) displayText.addLine("Width($width) Height($height)", secondaryColor) + displayText.add(" Delays:", primaryColor) if (dynamicDelay) { displayText.addLine("Place(${placeDelay + extraPlaceDelay}) Break($breakDelay)", secondaryColor) @@ -1540,12 +1543,16 @@ internal object HighwayTools : Module( private fun gatherTask(displayText: TextComponent) { sortedTasks.firstOrNull()?.let { displayText.addLine("Task", primaryColor) + displayText.add(" Status:", primaryColor) displayText.addLine("${it.taskState}", secondaryColor) + displayText.add(" Target block:", primaryColor) displayText.addLine(it.block.localizedName, secondaryColor) + if (!anonymizeStats) displayText.add(" Position:", primaryColor) if (!anonymizeStats) displayText.addLine("(${it.blockPos.asString()})", secondaryColor) + displayText.add(" Ticks stuck:", primaryColor) displayText.addLine("${it.stuckTicks}", secondaryColor) } @@ -1571,17 +1578,22 @@ internal object HighwayTools : Module( displayText.addLine("Next refill", primaryColor) displayText.add(" ${material.localizedName}:", primaryColor) + if (material == Blocks.OBSIDIAN) { displayText.addLine("Direct($materialLeft) Indirect($indirectMaterialLeft)", secondaryColor) } else { displayText.addLine("$materialLeft", secondaryColor) } + displayText.add(" ${fillerMat.localizedName}:", primaryColor) displayText.addLine("$fillerMatLeft", secondaryColor) + displayText.add(" Distance left:", primaryColor) displayText.addLine("${pavingLeft.toInt()}", secondaryColor) + if (!anonymizeStats) displayText.add(" Destination:", primaryColor) if (!anonymizeStats) displayText.addLine("(${currentBlockPos.add(startingDirection.directionVec.multiply(pavingLeft.toInt())).asString()})", secondaryColor) + displayText.add(" ETA:", primaryColor) displayText.addLine("$hoursLeft:$minutesLeft:$secondsLeft", secondaryColor) } @@ -1596,12 +1608,16 @@ internal object HighwayTools : Module( val hoursLeft = (secLeft / 3600).toInt().toString().padStart(2, '0') displayText.addLine("Destination:", primaryColor) + displayText.add(" Pickaxes:", primaryColor) displayText.addLine("$pickaxesLeft", secondaryColor) + displayText.add(" Distance left:", primaryColor) displayText.addLine("${tunnelingLeft.toInt()}", secondaryColor) + if (!anonymizeStats) displayText.add(" Destination:", primaryColor) if (!anonymizeStats) displayText.addLine("(${currentBlockPos.add(startingDirection.directionVec.multiply(tunnelingLeft.toInt())).asString()})", secondaryColor) + displayText.add(" ETA:", primaryColor) displayText.addLine("$hoursLeft:$minutesLeft:$secondsLeft", secondaryColor) } From 6610a2bb129a1d8790716f95812a05c5eeee6aed Mon Sep 17 00:00:00 2001 From: Christian Date: Fri, 26 Feb 2021 04:16:29 +0100 Subject: [PATCH 353/390] Refurbish --- .../module/modules/misc/HighwayTools.kt | 47 ++++++++++++++----- 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index 70928e327c..00ab42995e 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -12,6 +12,7 @@ import net.minecraft.client.audio.PositionedSoundRecord import net.minecraft.enchantment.EnchantmentHelper import net.minecraft.init.Blocks import net.minecraft.init.Enchantments +import net.minecraft.init.Items import net.minecraft.init.SoundEvents import net.minecraft.inventory.Slot import net.minecraft.item.ItemBlock @@ -133,7 +134,6 @@ internal object HighwayTools : Module( // stats private val anonymizeStats by setting("Anonymize", false, { page == Page.STATS }, description = "Censors all coordinates in HUD and Chat.") private val simpleMovingAverageRange by setting("Moving Average", 60, 5..600, 5, { page == Page.STATS }, description = "Sets the timeframe of the average in seconds") - private val statUpdateSpeed by setting("Update Speed Seconds", 60, 1..600, 5, { page == Page.STATS }, description = "Sets the frequency of the stat updating in seconds") private val showSession by setting("Show Session", true, { page == Page.STATS }, description = "Toggles the Session section in HUD") private val showPerformance by setting("Show Performance", true, { page == Page.STATS }, description = "Toggles the Performance section in HUD") private val showEnvironment by setting("Show Environment", true, { page == Page.STATS }, description = "Toggles the Environment section in HUD") @@ -420,7 +420,8 @@ internal object HighwayTools : Module( active = true BaritoneUtils.primary?.pathingControlManager?.registerProcess(HighwayToolsProcess) } else { - if (runtimeMilliSeconds % (1000 * statUpdateSpeed) == 0) { + // Cant update at higher frequency + if (runtimeMilliSeconds % 15000 == 0) { connection.sendPacket(CPacketClientStatus(CPacketClientStatus.State.REQUEST_STATS)) } runtimeMilliSeconds += 50 @@ -1486,22 +1487,44 @@ internal object HighwayTools : Module( if (!anonymizeStats) displayText.addLine("(${startingBlockPos.asString()})", secondaryColor) displayText.add(" Session placed / destroyed:", primaryColor) - displayText.addLine("%,d".format(totalBlocksPlaced).padStart(7, '0') + " / " + "%,d".format(totalBlocksBroken).padStart(7, '0'), secondaryColor) + displayText.addLine("%,d".format(totalBlocksPlaced) + " / " + "%,d".format(totalBlocksBroken), secondaryColor) - displayText.add(" ${material.localizedName} placed:", primaryColor) - StatList.getObjectUseStats(material.item)?.let { - displayText.addLine("%,d".format(player.statFileWriter.readStat(it)).padStart(11, '0'), secondaryColor) + if (mode == Mode.HIGHWAY || mode == Mode.FLAT) { + val matMined = StatList.getObjectUseStats(material.item)?.let { + player.statFileWriter.readStat(it) + } ?: 0 + val enderMined = StatList.getBlockStats(Blocks.ENDER_CHEST)?.let { + player.statFileWriter.readStat(it) + } ?: 0 + + if (matMined > 0) { + displayText.add(" ${material.localizedName} placed:", primaryColor) + displayText.addLine("%,d".format(matMined), secondaryColor) + } + + if (enderMined > 0) { + displayText.add(" ${Blocks.ENDER_CHEST.localizedName} mined:", primaryColor) + displayText.addLine("%,d".format(enderMined), secondaryColor) + } } - displayText.add(" ${Blocks.NETHERRACK.localizedName} mined:", primaryColor) - StatList.getBlockStats(Blocks.NETHERRACK)?.let { - displayText.addLine("%,d".format(player.statFileWriter.readStat(it)).padStart(11, '0'), secondaryColor) + val netherrackMined = StatList.getBlockStats(Blocks.NETHERRACK)?.let { + player.statFileWriter.readStat(it) + } ?: 0 + val pickaxeBroken = StatList.getObjectBreakStats(Items.DIAMOND_PICKAXE)?.let { + player.statFileWriter.readStat(it) + } ?: 0 + + if (netherrackMined > 0) { + displayText.add(" ${Blocks.NETHERRACK.localizedName} mined:", primaryColor) + displayText.addLine("%,d".format(netherrackMined), secondaryColor) } - displayText.add(" ${Blocks.ENDER_CHEST.localizedName} mined:", primaryColor) - StatList.getBlockStats(Blocks.ENDER_CHEST)?.let { - displayText.addLine("%,d".format(player.statFileWriter.readStat(it)).padStart(11, '0'), secondaryColor) + if (pickaxeBroken > 0) { + displayText.add(" Diamond Pickaxe broken:", primaryColor) + displayText.addLine("%,d".format(pickaxeBroken), secondaryColor) } + } private fun gatherPerformance(displayText: TextComponent, runtimeSec: Double, distanceDone: Double) { From 43ac19cf56e56fafc75cae9e5660cfa7392f9768 Mon Sep 17 00:00:00 2001 From: Christian Date: Fri, 26 Feb 2021 04:20:49 +0100 Subject: [PATCH 354/390] New section --- .../client/module/modules/misc/HighwayTools.kt | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index 00ab42995e..732fd063cb 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -135,6 +135,7 @@ internal object HighwayTools : Module( private val anonymizeStats by setting("Anonymize", false, { page == Page.STATS }, description = "Censors all coordinates in HUD and Chat.") private val simpleMovingAverageRange by setting("Moving Average", 60, 5..600, 5, { page == Page.STATS }, description = "Sets the timeframe of the average in seconds") private val showSession by setting("Show Session", true, { page == Page.STATS }, description = "Toggles the Session section in HUD") + private val showLifeTime by setting("Show Lifetime", true, { page == Page.STATS }, description = "Toggles the Lifetime section in HUD") private val showPerformance by setting("Show Performance", true, { page == Page.STATS }, description = "Toggles the Performance section in HUD") private val showEnvironment by setting("Show Environment", true, { page == Page.STATS }, description = "Toggles the Environment section in HUD") private val showTask by setting("Show Task", true, { page == Page.STATS }, description = "Toggles the Task section in HUD") @@ -1451,6 +1452,8 @@ internal object HighwayTools : Module( if (showSession) gatherSession(displayText, runtimeSec) + if (showLifeTime) gatherLifeTime(displayText) + if (showPerformance) gatherPerformance(displayText, runtimeSec, distanceDone) if (showEnvironment) gatherEnvironment(displayText) @@ -1470,7 +1473,7 @@ internal object HighwayTools : Module( } } - private fun SafeClientEvent.gatherSession(displayText: TextComponent, runtimeSec: Double) { + private fun gatherSession(displayText: TextComponent, runtimeSec: Double) { val seconds = (runtimeSec % 60.0).toInt().toString().padStart(2, '0') val minutes = ((runtimeSec % 3600.0) / 60.0).toInt().toString().padStart(2, '0') val hours = (runtimeSec / 3600.0).toInt().toString().padStart(2, '0') @@ -1489,6 +1492,11 @@ internal object HighwayTools : Module( displayText.add(" Session placed / destroyed:", primaryColor) displayText.addLine("%,d".format(totalBlocksPlaced) + " / " + "%,d".format(totalBlocksBroken), secondaryColor) + + + } + + private fun SafeClientEvent.gatherLifeTime(displayText: TextComponent) { if (mode == Mode.HIGHWAY || mode == Mode.FLAT) { val matMined = StatList.getObjectUseStats(material.item)?.let { player.statFileWriter.readStat(it) @@ -1524,7 +1532,6 @@ internal object HighwayTools : Module( displayText.add(" Diamond Pickaxe broken:", primaryColor) displayText.addLine("%,d".format(pickaxeBroken), secondaryColor) } - } private fun gatherPerformance(displayText: TextComponent, runtimeSec: Double, distanceDone: Double) { From 972122b1ebcd99ed27fa8a5e6975254f37fa0344 Mon Sep 17 00:00:00 2001 From: Christian Date: Fri, 26 Feb 2021 04:28:42 +0100 Subject: [PATCH 355/390] Header --- .../org/kamiblue/client/module/modules/misc/HighwayTools.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index 732fd063cb..4708a9edab 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -1497,6 +1497,8 @@ internal object HighwayTools : Module( } private fun SafeClientEvent.gatherLifeTime(displayText: TextComponent) { + displayText.addLine("Lifetime", primaryColor) + if (mode == Mode.HIGHWAY || mode == Mode.FLAT) { val matMined = StatList.getObjectUseStats(material.item)?.let { player.statFileWriter.readStat(it) From 9bc73705cc58a7612116dda388df784f1fb082be Mon Sep 17 00:00:00 2001 From: Christian Date: Fri, 26 Feb 2021 04:31:18 +0100 Subject: [PATCH 356/390] Fix dequeue crash --- .../org/kamiblue/client/module/modules/misc/HighwayTools.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index 4708a9edab..5847e78724 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -1387,9 +1387,9 @@ internal object HighwayTools : Module( if (handleLiquid(task)) break breakCount++ + packetLimiter.add(System.currentTimeMillis()) defaultScope.launch { - packetLimiter.add(System.currentTimeMillis()) sendMiningPackets(task.blockPos, rayTraceResult.sideHit) delay(50L * taskTimeout) From 1f455f76515f992f20e8d5f75c2f006eafc2d65a Mon Sep 17 00:00:00 2001 From: Christian Date: Fri, 26 Feb 2021 04:42:23 +0100 Subject: [PATCH 357/390] Fix heading --- .../module/modules/misc/HighwayTools.kt | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index 5847e78724..82e3474332 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -1497,16 +1497,24 @@ internal object HighwayTools : Module( } private fun SafeClientEvent.gatherLifeTime(displayText: TextComponent) { - displayText.addLine("Lifetime", primaryColor) + val matMined = StatList.getObjectUseStats(material.item)?.let { + player.statFileWriter.readStat(it) + } ?: 0 + val enderMined = StatList.getBlockStats(Blocks.ENDER_CHEST)?.let { + player.statFileWriter.readStat(it) + } ?: 0 + val netherrackMined = StatList.getBlockStats(Blocks.NETHERRACK)?.let { + player.statFileWriter.readStat(it) + } ?: 0 + val pickaxeBroken = StatList.getObjectBreakStats(Items.DIAMOND_PICKAXE)?.let { + player.statFileWriter.readStat(it) + } ?: 0 - if (mode == Mode.HIGHWAY || mode == Mode.FLAT) { - val matMined = StatList.getObjectUseStats(material.item)?.let { - player.statFileWriter.readStat(it) - } ?: 0 - val enderMined = StatList.getBlockStats(Blocks.ENDER_CHEST)?.let { - player.statFileWriter.readStat(it) - } ?: 0 + if (matMined + enderMined + netherrackMined + pickaxeBroken > 0) { + displayText.addLine("Lifetime", primaryColor) + } + if (mode == Mode.HIGHWAY || mode == Mode.FLAT) { if (matMined > 0) { displayText.add(" ${material.localizedName} placed:", primaryColor) displayText.addLine("%,d".format(matMined), secondaryColor) @@ -1518,13 +1526,6 @@ internal object HighwayTools : Module( } } - val netherrackMined = StatList.getBlockStats(Blocks.NETHERRACK)?.let { - player.statFileWriter.readStat(it) - } ?: 0 - val pickaxeBroken = StatList.getObjectBreakStats(Items.DIAMOND_PICKAXE)?.let { - player.statFileWriter.readStat(it) - } ?: 0 - if (netherrackMined > 0) { displayText.add(" ${Blocks.NETHERRACK.localizedName} mined:", primaryColor) displayText.addLine("%,d".format(netherrackMined), secondaryColor) From 572223b2d5a4b811cc360cfded62b6e47eede156 Mon Sep 17 00:00:00 2001 From: Christian Date: Fri, 26 Feb 2021 04:58:07 +0100 Subject: [PATCH 358/390] Fixed support block check --- .../client/module/modules/misc/HighwayTools.kt | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index 82e3474332..6e44d2150a 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -71,6 +71,7 @@ import org.kamiblue.client.util.text.MessageSendHelper import org.kamiblue.client.util.threads.* import org.kamiblue.commons.extension.ceilToInt import org.kamiblue.commons.extension.floorToInt +import kotlin.math.abs import kotlin.random.Random.Default.nextInt /** @@ -131,7 +132,7 @@ internal object HighwayTools : Module( private val limitFactor by setting("Limit Factor", 1.0f, 0.5f..2.0f, 0.01f, { page == Page.BEHAVIOR }, description = "EXPERIMENTAL: Factor for TPS witch acts as limit for maximum breaks per second.") private val placementSearch by setting("Place Deep Search", 2, 1..4, 1, { page == Page.BEHAVIOR }, description = "EXPERIMENTAL: Attempts to find a support block for placing against") - // stats + // stat settings private val anonymizeStats by setting("Anonymize", false, { page == Page.STATS }, description = "Censors all coordinates in HUD and Chat.") private val simpleMovingAverageRange by setting("Moving Average", 60, 5..600, 5, { page == Page.STATS }, description = "Sets the timeframe of the average in seconds") private val showSession by setting("Show Session", true, { page == Page.STATS }, description = "Toggles the Session section in HUD") @@ -309,6 +310,10 @@ internal object HighwayTools : Module( } else { MessageSendHelper.sendRawChatMessage(" §9> §7Axis offset: §a${startingBlockPos.z}§r") } + + if (abs(startingBlockPos.x) != abs(startingBlockPos.z)) { + MessageSendHelper.sendRawChatMessage(" §9> §cYou may have an offset to diagonal highway position!") + } } } @@ -530,7 +535,14 @@ internal object HighwayTools : Module( addTaskToPending(pos, TaskState.PLACE, block) } else -> { - addTaskToPending(pos, TaskState.BREAK, block) + if (mode == Mode.HIGHWAY && + startingDirection.isDiagonal && + world.getBlockState(pos.up()).block == material && + block == fillerMat) { + addTaskToDone(pos, block) + } else { + addTaskToPending(pos, TaskState.BREAK, block) + } } } } From 27452d18134beb7855de7c1149375012bbbe5bed Mon Sep 17 00:00:00 2001 From: Christian Date: Fri, 26 Feb 2021 06:25:36 +0100 Subject: [PATCH 359/390] Fix support blocks again --- .../module/modules/misc/HighwayTools.kt | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index 6e44d2150a..b5b036814c 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -304,6 +304,10 @@ internal object HighwayTools : Module( if (!anonymizeStats) { if (startingDirection.isDiagonal) { MessageSendHelper.sendRawChatMessage(" §9> §7Axis offset: §a${startingBlockPos.x} ${startingBlockPos.z}§r") + + if (abs(startingBlockPos.x) != abs(startingBlockPos.z)) { + MessageSendHelper.sendRawChatMessage(" §9> §cYou may have an offset to diagonal highway position!") + } } else { if (startingDirection == Direction.NORTH || startingDirection == Direction.SOUTH) { MessageSendHelper.sendRawChatMessage(" §9> §7Axis offset: §a${startingBlockPos.x}§r") @@ -311,9 +315,6 @@ internal object HighwayTools : Module( MessageSendHelper.sendRawChatMessage(" §9> §7Axis offset: §a${startingBlockPos.z}§r") } - if (abs(startingBlockPos.x) != abs(startingBlockPos.z)) { - MessageSendHelper.sendRawChatMessage(" §9> §cYou may have an offset to diagonal highway position!") - } } } @@ -532,7 +533,14 @@ internal object HighwayTools : Module( addTaskToDone(pos, block) } blockState.material.isReplaceable -> { - addTaskToPending(pos, TaskState.PLACE, block) + if (mode == Mode.HIGHWAY && + startingDirection.isDiagonal && + world.getBlockState(pos.up()).block == material && + block == fillerMat) { + addTaskToDone(pos, block) + } else { + addTaskToPending(pos, TaskState.PLACE, block) + } } else -> { if (mode == Mode.HIGHWAY && @@ -870,9 +878,9 @@ internal object HighwayTools : Module( else -> { if (debugMessages != DebugMessages.OFF) { if (!anonymizeStats) { - MessageSendHelper.sendChatMessage("Stuck while ${blockTask.taskState}@(${blockTask.blockPos.asString()}) for more then $timeout ticks (${blockTask.stuckTicks}), refreshing data.") + MessageSendHelper.sendChatMessage("$chatName Stuck while ${blockTask.taskState}@(${blockTask.blockPos.asString()}) for more then $timeout ticks (${blockTask.stuckTicks}), refreshing data.") } else { - MessageSendHelper.sendChatMessage("Stuck while ${blockTask.taskState} for more then $timeout ticks (${blockTask.stuckTicks}), refreshing data.") + MessageSendHelper.sendChatMessage("$chatName Stuck while ${blockTask.taskState} for more then $timeout ticks (${blockTask.stuckTicks}), refreshing data.") } } From 600382cd8407ef3789ccdb8ae27654ea3b30cf10 Mon Sep 17 00:00:00 2001 From: Christian Date: Fri, 26 Feb 2021 06:36:36 +0100 Subject: [PATCH 360/390] Better blueprint check --- .../module/modules/misc/HighwayTools.kt | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index b5b036814c..12d906541a 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -532,21 +532,15 @@ internal object HighwayTools : Module( blockState.block == block -> { addTaskToDone(pos, block) } - blockState.material.isReplaceable -> { - if (mode == Mode.HIGHWAY && - startingDirection.isDiagonal && - world.getBlockState(pos.up()).block == material && - block == fillerMat) { + isPlaceable(pos, true) -> { + if (checkSupport(pos, block)) { addTaskToDone(pos, block) } else { addTaskToPending(pos, TaskState.PLACE, block) } } else -> { - if (mode == Mode.HIGHWAY && - startingDirection.isDiagonal && - world.getBlockState(pos.up()).block == material && - block == fillerMat) { + if (checkSupport(pos, block)) { addTaskToDone(pos, block) } else { addTaskToPending(pos, TaskState.BREAK, block) @@ -555,6 +549,13 @@ internal object HighwayTools : Module( } } + private fun SafeClientEvent.checkSupport(pos: BlockPos, block: Block): Boolean { + return mode == Mode.HIGHWAY && + startingDirection.isDiagonal && + world.getBlockState(pos.up()).block == material && + block == fillerMat + } + private fun SafeClientEvent.addTaskClear(pos: BlockPos) { if (world.isAirBlock(pos)) { addTaskToDone(pos, Blocks.AIR) From 2b5ff4457823e5642134233e9056dffcf9cd8c6f Mon Sep 17 00:00:00 2001 From: Christian Date: Mon, 1 Mar 2021 00:19:08 +0100 Subject: [PATCH 361/390] Added backfill mode --- .../module/modules/misc/HighwayTools.kt | 54 +++++++++++++------ 1 file changed, 38 insertions(+), 16 deletions(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index 12d906541a..aaec23065a 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -101,14 +101,15 @@ internal object HighwayTools : Module( // build settings private val mode by setting("Mode", Mode.HIGHWAY, { page == Page.BUILD }, description = "Choose the structure") - private val clearSpace by setting("Clear Space", true, { page == Page.BUILD && mode == Mode.HIGHWAY }, description = "Clears out the tunnel if necessary") - private val cleanFloor by setting("Clean Floor", false, { page == Page.BUILD && mode == Mode.TUNNEL }, description = "Cleans up the tunnels floor") - private val cleanWalls by setting("Clean Walls", false, { page == Page.BUILD && mode == Mode.TUNNEL }, description = "Cleans up the tunnels walls") - private val cleanRoof by setting("Clean Roof", false, { page == Page.BUILD && mode == Mode.TUNNEL }, description = "Cleans up the tunnels roof") - private val cleanCorner by setting("Clean Corner", false, { page == Page.BUILD && mode == Mode.TUNNEL && !cornerBlock }, description = "Cleans up the tunnels corner") - private val cornerBlock by setting("Corner Block", false, { page == Page.BUILD && (mode == Mode.HIGHWAY || mode == Mode.TUNNEL) }, description = "If activated will break the corner in tunnel or place a corner while paving") private val width by setting("Width", 6, 1..11, 1, { page == Page.BUILD }, description = "Sets the width of blueprint") private val height by setting("Height", 4, 1..6, 1, { page == Page.BUILD && clearSpace }, description = "Sets height of blueprint") + private val backfill by setting("Backfill", false, { page == Page.BUILD && mode == Mode.TUNNEL }, description = "Backfills tunnel") + private val clearSpace by setting("Clear Space", true, { page == Page.BUILD && mode == Mode.HIGHWAY}, description = "Clears out the tunnel if necessary") + private val cleanFloor by setting("Clean Floor", false, { page == Page.BUILD && mode == Mode.TUNNEL && !backfill }, description = "Cleans up the tunnels floor") + private val cleanWalls by setting("Clean Walls", false, { page == Page.BUILD && mode == Mode.TUNNEL && !backfill }, description = "Cleans up the tunnels walls") + private val cleanRoof by setting("Clean Roof", false, { page == Page.BUILD && mode == Mode.TUNNEL && !backfill }, description = "Cleans up the tunnels roof") + private val cleanCorner by setting("Clean Corner", false, { page == Page.BUILD && mode == Mode.TUNNEL && !cornerBlock && !backfill && width > 2 }, description = "Cleans up the tunnels corner") + private val cornerBlock by setting("Corner Block", false, { page == Page.BUILD && (mode == Mode.HIGHWAY || mode == Mode.TUNNEL) && !backfill && width > 2 }, description = "If activated will break the corner in tunnel or place a corner while paving") private val railing by setting("Railing", true, { page == Page.BUILD && mode == Mode.HIGHWAY }, description = "Adds a railing / rim / border to the highway") private val railingHeight by setting("Railing Height", 1, 1..4, 1, { railing && page == Page.BUILD && mode == Mode.HIGHWAY }, description = "Sets height of railing") private val materialSaved = setting("Material", "minecraft:obsidian", { false }) @@ -129,7 +130,7 @@ internal object HighwayTools : Module( private val rubberbandTimeout by setting("Rubberband Timeout", 50, 5..100, 5, { page == Page.BEHAVIOR }, description = "Timeout for pausing after a lag") private val maxReach by setting("Max Reach", 4.9f, 1.0f..6.0f, 0.1f, { page == Page.BEHAVIOR }, description = "Sets the range of the blueprint. Decrease when tasks fail!") private val maxBreaks by setting("Multi Break", 1, 1..5, 1, { page == Page.BEHAVIOR }, description = "EXPERIMENTAL: Breaks multiple instant breaking blocks per tick in view") - private val limitFactor by setting("Limit Factor", 1.0f, 0.5f..2.0f, 0.01f, { page == Page.BEHAVIOR }, description = "EXPERIMENTAL: Factor for TPS witch acts as limit for maximum breaks per second.") + private val limitFactor by setting("Limit Factor", 1.0f, 0.5f..2.0f, 0.01f, { page == Page.BEHAVIOR }, description = "EXPERIMENTAL: Factor for TPS which acts as limit for maximum breaks per second.") private val placementSearch by setting("Place Deep Search", 2, 1..4, 1, { page == Page.BEHAVIOR }, description = "EXPERIMENTAL: Attempts to find a support block for placing against") // stat settings @@ -338,6 +339,10 @@ internal object HighwayTools : Module( MessageSendHelper.sendRawChatMessage(" §9> §cMake sure to use §aTunnel Mode§c instead of having same material for both main and filler!") } + if (mode == Mode.HIGHWAY && height < 3) { + MessageSendHelper.sendRawChatMessage(" §9> §cYou may increase the height to at least 3") + } + } } @@ -575,10 +580,14 @@ internal object HighwayTools : Module( val thisPos = basePos.add(zDirection.directionVec.multiply(x)) if (clearSpace) generateClear(thisPos, xDirection) if (mode == Mode.TUNNEL) { - if (cleanFloor) generateFloor(thisPos, xDirection) - if (cleanWalls) generateWalls(thisPos, xDirection) - if (cleanRoof) generateRoof(thisPos, xDirection) - if (cleanCorner && !cornerBlock) generateCorner(thisPos, xDirection) + if (backfill) { + generateBackfill(thisPos, xDirection) + } else { + if (cleanFloor) generateFloor(thisPos, xDirection) + if (cleanWalls) generateWalls(thisPos, xDirection) + if (cleanRoof) generateRoof(thisPos, xDirection) + if (cleanCorner && !cornerBlock && width > 2) generateCorner(thisPos, xDirection) + } } else { generateBase(thisPos, xDirection) } @@ -624,7 +633,7 @@ internal object HighwayTools : Module( if (mode == Mode.HIGHWAY) { blueprint[pos] = Blocks.AIR } else { - if (!(isRail(w) && h == 0 && !cornerBlock)) blueprint[pos.up()] = Blocks.AIR + if (!(isRail(w) && h == 0 && !cornerBlock && width > 2)) blueprint[pos.up()] = Blocks.AIR } } } @@ -636,8 +645,8 @@ internal object HighwayTools : Module( val pos = basePos.add(xDirection.directionVec.multiply(x)) if (mode == Mode.HIGHWAY && isRail(w)) { - if (!cornerBlock && startingDirection.isDiagonal) blueprint[pos] = fillerMat - val startHeight = if (cornerBlock) 0 else 1 + if (!cornerBlock && width > 2 && startingDirection.isDiagonal) blueprint[pos] = fillerMat + val startHeight = if (cornerBlock && width > 2) 0 else 1 for (y in startHeight..railingHeight) { blueprint[pos.up(y)] = material } @@ -648,7 +657,7 @@ internal object HighwayTools : Module( } private fun generateFloor(basePos: BlockPos, xDirection: Direction) { - val wid = if (cornerBlock) { + val wid = if (cornerBlock && width > 2) { width } else { width - 2 @@ -661,7 +670,7 @@ internal object HighwayTools : Module( } private fun generateWalls(basePos: BlockPos, xDirection: Direction) { - val cb = if (!cornerBlock) { + val cb = if (!cornerBlock && width > 2) { 1 } else { 0 @@ -685,6 +694,19 @@ internal object HighwayTools : Module( blueprint[basePos.add(xDirection.directionVec.multiply(width - width / 2 - 1)).up()] = fillerMat } + private fun generateBackfill(basePos: BlockPos, xDirection: Direction) { + for (w in 0 until width) { + for (h in 0 until height) { + val x = w - width / 2 + val pos = basePos.add(xDirection.directionVec.multiply(x)).up(h + 1) + + if (startingBlockPos.distanceTo(pos) < startingBlockPos.distanceTo(currentBlockPos)) { + blueprint[pos] = fillerMat + } + } + } + } + private fun isRail(w: Int) = railing && w !in 1 until width - 1 private fun generateFlat(basePos: BlockPos) { From d296972c6ae1b39167ed5c4642c57f231c4a9091 Mon Sep 17 00:00:00 2001 From: Christian Date: Mon, 1 Mar 2021 03:52:57 +0100 Subject: [PATCH 362/390] Fix setting --- .../org/kamiblue/client/module/modules/misc/HighwayTools.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index aaec23065a..7edba8fcbf 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -109,7 +109,7 @@ internal object HighwayTools : Module( private val cleanWalls by setting("Clean Walls", false, { page == Page.BUILD && mode == Mode.TUNNEL && !backfill }, description = "Cleans up the tunnels walls") private val cleanRoof by setting("Clean Roof", false, { page == Page.BUILD && mode == Mode.TUNNEL && !backfill }, description = "Cleans up the tunnels roof") private val cleanCorner by setting("Clean Corner", false, { page == Page.BUILD && mode == Mode.TUNNEL && !cornerBlock && !backfill && width > 2 }, description = "Cleans up the tunnels corner") - private val cornerBlock by setting("Corner Block", false, { page == Page.BUILD && (mode == Mode.HIGHWAY || mode == Mode.TUNNEL) && !backfill && width > 2 }, description = "If activated will break the corner in tunnel or place a corner while paving") + private val cornerBlock by setting("Corner Block", false, { page == Page.BUILD && (mode == Mode.HIGHWAY || (mode == Mode.TUNNEL && !backfill && width > 2)) }, description = "If activated will break the corner in tunnel or place a corner while paving") private val railing by setting("Railing", true, { page == Page.BUILD && mode == Mode.HIGHWAY }, description = "Adds a railing / rim / border to the highway") private val railingHeight by setting("Railing Height", 1, 1..4, 1, { railing && page == Page.BUILD && mode == Mode.HIGHWAY }, description = "Sets height of railing") private val materialSaved = setting("Material", "minecraft:obsidian", { false }) From 12cdf12a5f0c6502e825cc0d2d1841d24f9979d6 Mon Sep 17 00:00:00 2001 From: Christian Date: Mon, 1 Mar 2021 04:24:51 +0100 Subject: [PATCH 363/390] Add FOMO back --- .../org/kamiblue/client/module/modules/misc/HighwayTools.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index 7edba8fcbf..020899b7a8 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -616,7 +616,8 @@ internal object HighwayTools : Module( val eyePos = player.getPositionEyes(1f) blueprint.keys.removeIf { - eyePos.distanceTo(it) > maxReach - 0.7 + eyePos.distanceTo(it) > maxReach - 0.7 || + startingBlockPos.add(startingDirection.clockwise(4).directionVec.multiply(maxReach.toInt())).distanceTo(it) < maxReach - 1 } } From fc79383d5713db70e06e8553c76f906a6775d707 Mon Sep 17 00:00:00 2001 From: Christian Date: Mon, 1 Mar 2021 04:31:17 +0100 Subject: [PATCH 364/390] Correct version --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 3f18905e42..c34557662a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ org.gradle.jvmargs=-Xmx3G modGroup=org.kamiblue -modVersion=2.02.xx-dev-ht-v09.7 +modVersion=2.02.xx-dev-ht-v09.8 kotlin_version=1.4.30 kotlinx_coroutines_version=1.4.2 \ No newline at end of file From 2c140f4c7179b0aee237d9dae3367810b77e09f3 Mon Sep 17 00:00:00 2001 From: Christian Date: Mon, 1 Mar 2021 04:39:51 +0100 Subject: [PATCH 365/390] Bump v09.9 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index c34557662a..c0bbd140be 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ org.gradle.jvmargs=-Xmx3G modGroup=org.kamiblue -modVersion=2.02.xx-dev-ht-v09.8 +modVersion=2.02.xx-dev-ht-v09.9 kotlin_version=1.4.30 kotlinx_coroutines_version=1.4.2 \ No newline at end of file From b5fcd9f24f25e57edc06c2675543a8f9b1c87e0d Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Mon, 1 Mar 2021 10:24:30 -0500 Subject: [PATCH 366/390] Wrap up packet limiter deque with mutex --- .../module/modules/misc/HighwayTools.kt | 31 ++++++++++++++----- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index 020899b7a8..ded65f3e25 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -210,6 +210,8 @@ internal object HighwayTools : Module( private val doneTasks = LinkedHashMap() private var sortedTasks: List = emptyList() var lastTask: BlockTask? = null; private set + + private val packetLimiterMutex = Mutex() private val packetLimiter = ArrayDeque() // Stats @@ -485,7 +487,11 @@ internal object HighwayTools : Module( updateDeque(simpleMovingAverageBreaks, removeTime) updateDeque(simpleMovingAverageDistance, removeTime) - updateDeque(packetLimiter, System.currentTimeMillis() - 1000L) + runBlocking { + packetLimiterMutex.withLock { + updateDeque(packetLimiter, System.currentTimeMillis() - 1000L) + } + } } private fun updateDeque(deque: ArrayDeque, removeTime: Long) { @@ -1387,10 +1393,13 @@ internal object HighwayTools : Module( private fun mineBlockInstant(blockTask: BlockTask, side: EnumFacing) { waitTicks = breakDelay - packetLimiter.add(System.currentTimeMillis()) blockTask.updateState(TaskState.PENDING_BREAK) defaultScope.launch { + packetLimiterMutex.withLock { + packetLimiter.add(System.currentTimeMillis()) + } + delay(20L) sendMiningPackets(blockTask.blockPos, side) @@ -1407,17 +1416,22 @@ internal object HighwayTools : Module( } } - private fun tryMultiBreak(blockTask: BlockTask) { - runSafe { + private suspend fun tryMultiBreak(blockTask: BlockTask) { + runSafeSuspend { val eyePos = player.getPositionEyes(1.0f) val viewVec = lastHitVec.subtract(eyePos).normalize() var breakCount = 1 for (task in sortedTasks) { if (breakCount >= maxBreaks) break - if (packetLimiter.size > TpsCalculator.tickRate * limitFactor) { + + val size = packetLimiterMutex.withLock { + packetLimiter.size + } + + if (size > TpsCalculator.tickRate * limitFactor) { if (debugMessages == DebugMessages.ALL) { - MessageSendHelper.sendChatMessage("$chatName Dropped possible instant mine action @ TPS(${TpsCalculator.tickRate}) Actions(${packetLimiter.size})") + MessageSendHelper.sendChatMessage("$chatName Dropped possible instant mine action @ TPS(${TpsCalculator.tickRate}) Actions(${size})") } break } @@ -1430,8 +1444,11 @@ internal object HighwayTools : Module( val rayTraceResult = box.isInSight(eyePos, viewVec) ?: continue if (handleLiquid(task)) break + breakCount++ - packetLimiter.add(System.currentTimeMillis()) + packetLimiterMutex.withLock { + packetLimiter.add(System.currentTimeMillis()) + } defaultScope.launch { sendMiningPackets(task.blockPos, rayTraceResult.sideHit) From e9a9fb2267b43f562425c6fbf069062bcc39ede2 Mon Sep 17 00:00:00 2001 From: Christian Date: Mon, 1 Mar 2021 19:15:40 +0100 Subject: [PATCH 367/390] Mining hotfix and dequeue crash fix --- .../module/modules/misc/AutoObsidian.kt | 32 ++++++++++++------ .../module/modules/misc/HighwayTools.kt | 33 +++++++++++-------- 2 files changed, 42 insertions(+), 23 deletions(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/AutoObsidian.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/AutoObsidian.kt index 6ff3f3f10b..a1c69536fd 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/AutoObsidian.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/AutoObsidian.kt @@ -84,6 +84,7 @@ internal object AutoObsidian : Module( enum class State(override val displayName: String) : DisplayEnum { SEARCHING("Searching"), PLACING("Placing"), + PRE_MINING("Pre Mining"), MINING("Mining"), COLLECTING("Collecting"), DONE("Done") @@ -92,6 +93,7 @@ internal object AutoObsidian : Module( enum class SearchingState(override val displayName: String) : DisplayEnum { PLACING("Placing"), OPENING("Opening"), + PRE_MINING("Pre Mining"), MINING("Mining"), COLLECTING("Collecting"), DONE("Done") @@ -220,8 +222,11 @@ internal object AutoObsidian : Module( State.PLACING -> { placeEnderChest(placingPos) } + State.PRE_MINING -> { + mineBlock(placingPos, true) + } State.MINING -> { - mineBlock(placingPos) + mineBlock(placingPos, false) } State.COLLECTING -> { collectDroppedItem(Blocks.OBSIDIAN.id) @@ -312,7 +317,7 @@ internal object AutoObsidian : Module( startPlacing() } state == State.PLACING && !world.isAirBlock(placingPos) -> { - State.MINING + State.PRE_MINING } state == State.SEARCHING && searchingState == SearchingState.DONE && passCountCheck -> { startPlacing() @@ -401,14 +406,14 @@ internal object AutoObsidian : Module( } searchingState == SearchingState.OPENING && (enderChestCount > 0 || player.inventorySlots.firstEmpty() == null) -> { - SearchingState.MINING + SearchingState.PRE_MINING } searchingState == SearchingState.PLACING && !world.isAirBlock(placingPos) -> { if (world.getBlockState(placingPos).block is BlockShulkerBox) { SearchingState.OPENING } else { // In case if the shulker wasn't placed due to server lag - SearchingState.MINING + SearchingState.PRE_MINING } } else -> { @@ -430,8 +435,11 @@ internal object AutoObsidian : Module( SearchingState.OPENING -> { openShulker(placingPos) } + SearchingState.PRE_MINING -> { + mineBlock(placingPos, true) + } SearchingState.MINING -> { - mineBlock(placingPos) + mineBlock(placingPos, false) } SearchingState.COLLECTING -> { collectDroppedItem(shulkerID) @@ -508,7 +516,7 @@ internal object AutoObsidian : Module( player.closeScreen() } else if (shulkerOpenTimer.tick(100, false)) { // Wait for maximum of 5 seconds if (leaveEmptyShulkers && container.inventory.subList(0, 27).all { it.isEmpty }) { - searchingState = SearchingState.MINING + searchingState = SearchingState.PRE_MINING player.closeScreen() } else { MessageSendHelper.sendChatMessage("$chatName No ender chest was found in shulker, disabling.") @@ -570,8 +578,8 @@ internal object AutoObsidian : Module( } } - private fun SafeClientEvent.mineBlock(pos: BlockPos) { - if (!swapToValidPickaxe()) return + private fun SafeClientEvent.mineBlock(pos: BlockPos, pre: Boolean) { + if (pre && !swapToValidPickaxe()) return val center = pos.toVec3dCenter() val diff = player.getPositionEyes(1.0f).subtract(center) @@ -594,8 +602,12 @@ internal object AutoObsidian : Module( defaultScope.launch { delay(20L) onMainThreadSafe { - connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, pos, side)) - connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, pos, side)) + if (pre) { + connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, pos, side)) + if (state != State.SEARCHING) state = State.MINING else searchingState = SearchingState.MINING + } else { + connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, pos, side)) + } player.swingArm(EnumHand.MAIN_HAND) lastMiningSide = side } diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index ded65f3e25..ab97acd806 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -229,7 +229,7 @@ internal object HighwayTools : Module( private var lastToolDamage = 0 private var durabilityUsages = 0 - private val mutex = Mutex() + private val stateUpdateMutex = Mutex() private val renderer = ESPRenderer() override fun isActive(): Boolean { @@ -373,7 +373,7 @@ internal object HighwayTools : Module( TaskState.PENDING_BREAK, TaskState.BREAKING -> { if (new == Blocks.AIR) { runBlocking { - mutex.withLock { + stateUpdateMutex.withLock { task.updateState(TaskState.BROKEN) } } @@ -382,7 +382,7 @@ internal object HighwayTools : Module( TaskState.PENDING_PLACE -> { if (task.block != Blocks.AIR && task.block == new) { runBlocking { - mutex.withLock { + stateUpdateMutex.withLock { task.updateState(TaskState.PLACED) } } @@ -853,7 +853,7 @@ internal object HighwayTools : Module( } runBlocking { - mutex.withLock { + stateUpdateMutex.withLock { sortedTasks = pendingTasks.values.sortedWith( compareBy { it.taskState.ordinal @@ -873,7 +873,7 @@ internal object HighwayTools : Module( } runBlocking { - mutex.withLock { + stateUpdateMutex.withLock { sortedTasks = pendingTasks.values.sortedWith( compareBy { it.taskState.ordinal @@ -1259,7 +1259,7 @@ internal object HighwayTools : Module( delay(50L * taskTimeout) if (blockTask.taskState == TaskState.PENDING_PLACE) { - mutex.withLock { + stateUpdateMutex.withLock { blockTask.updateState(TaskState.PLACE) } if (dynamicDelay && extraPlaceDelay < 10) extraPlaceDelay += 1 @@ -1409,7 +1409,7 @@ internal object HighwayTools : Module( delay(50L * taskTimeout) if (blockTask.taskState == TaskState.PENDING_BREAK) { - mutex.withLock { + stateUpdateMutex.withLock { blockTask.updateState(TaskState.BREAK) } } @@ -1455,7 +1455,7 @@ internal object HighwayTools : Module( delay(50L * taskTimeout) if (blockTask.taskState == TaskState.PENDING_BREAK) { - mutex.withLock { + stateUpdateMutex.withLock { blockTask.updateState(TaskState.BREAK) } } @@ -1466,13 +1466,20 @@ internal object HighwayTools : Module( /* Dispatches a thread to mine any non-netherrack blocks generically */ private fun mineBlockNormal(blockTask: BlockTask, side: EnumFacing) { - if (blockTask.taskState == TaskState.BREAK) { - blockTask.updateState(TaskState.BREAKING) - } - defaultScope.launch { delay(20L) - sendMiningPackets(blockTask.blockPos, side) + if (blockTask.taskState == TaskState.BREAK) { + blockTask.updateState(TaskState.BREAKING) + onMainThreadSafe { + connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, blockTask.blockPos, side)) + player.swingArm(EnumHand.MAIN_HAND) + } + } else { + onMainThreadSafe { + connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, blockTask.blockPos, side)) + player.swingArm(EnumHand.MAIN_HAND) + } + } } } From 6e7c69d22ade3c58e7e08f9e90bdd2a5ef14c2bb Mon Sep 17 00:00:00 2001 From: Christian Date: Mon, 1 Mar 2021 19:23:42 +0100 Subject: [PATCH 368/390] Remove InstaBreak :c --- .../module/modules/misc/AutoObsidian.kt | 25 ++----------------- 1 file changed, 2 insertions(+), 23 deletions(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/AutoObsidian.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/AutoObsidian.kt index a1c69536fd..49f77554c4 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/AutoObsidian.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/AutoObsidian.kt @@ -52,7 +52,6 @@ import org.kamiblue.client.util.math.VectorUtils.toVec3dCenter import org.kamiblue.client.util.text.MessageSendHelper import org.kamiblue.client.util.threads.* import org.kamiblue.commons.interfaces.DisplayEnum -import org.kamiblue.event.listener.asyncListener import org.kamiblue.event.listener.listener import kotlin.math.ceil @@ -66,8 +65,6 @@ internal object AutoObsidian : Module( private val searchShulker by setting("Search Shulker", false) private val leaveEmptyShulkers by setting("Leave Empty Shulkers", true, { searchShulker }) private val autoRefill by setting("Auto Refill", false, { fillMode != FillMode.INFINITE }) - private val instantMining by setting("Instant Mining", true) - private val instantMiningDelay by setting("Instant Mining Delay", 10, 1..20, 1, { instantMining }) private val threshold by setting("Refill Threshold", 32, 1..64, 1, { autoRefill && fillMode != FillMode.INFINITE }) private val targetStacks by setting("Target Stacks", 1, 1..20, 1, { fillMode == FillMode.TARGET_STACKS }) private val noDisable by setting("No Disable", false) @@ -146,16 +143,8 @@ internal object AutoObsidian : Module( } } - asyncListener { - if (!instantMining || it.packet !is CPacketPlayerDigging) return@asyncListener - - if (it.packet.position != placingPos || it.packet.facing != lastMiningSide) { - canInstantMine = false - } - } - safeAsyncListener { - if (!instantMining || it.packet !is SPacketBlockChange) return@safeAsyncListener + if (it.packet !is SPacketBlockChange) return@safeAsyncListener if (it.packet.blockPosition != placingPos) return@safeAsyncListener val prevBlock = world.getBlockState(it.packet.blockPosition).block @@ -584,21 +573,11 @@ internal object AutoObsidian : Module( val center = pos.toVec3dCenter() val diff = player.getPositionEyes(1.0f).subtract(center) val normalizedVec = diff.normalize() - var side = EnumFacing.getFacingFromVector(normalizedVec.x.toFloat(), normalizedVec.y.toFloat(), normalizedVec.z.toFloat()) + val side = EnumFacing.getFacingFromVector(normalizedVec.x.toFloat(), normalizedVec.y.toFloat(), normalizedVec.z.toFloat()) lastHitVec = center rotateTimer.reset() - if (instantMining && canInstantMine) { - if (!miningTimer.tick(instantMiningDelay.toLong(), false)) return - - if (!miningTimeoutTimer.tick(2L, false)) { - side = side.opposite - } else { - canInstantMine = false - } - } - defaultScope.launch { delay(20L) onMainThreadSafe { From 6ff368fd16ef49efc7cba77867a926f8712ffc59 Mon Sep 17 00:00:00 2001 From: Christian Date: Mon, 1 Mar 2021 19:32:30 +0100 Subject: [PATCH 369/390] Version setback --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index c0bbd140be..2e671bf664 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ org.gradle.jvmargs=-Xmx3G modGroup=org.kamiblue -modVersion=2.02.xx-dev-ht-v09.9 +modVersion=2.02.xx-dev-ht-v09.8.5 kotlin_version=1.4.30 kotlinx_coroutines_version=1.4.2 \ No newline at end of file From 2b8f14858a4c1794e2b91fc7ffe7e874dc16dfed Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 2 Mar 2021 04:40:19 +0100 Subject: [PATCH 370/390] Version bump done stuck fix attempt --- gradle.properties | 2 +- .../org/kamiblue/client/module/modules/misc/HighwayTools.kt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/gradle.properties b/gradle.properties index 2e671bf664..c0bbd140be 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ org.gradle.jvmargs=-Xmx3G modGroup=org.kamiblue -modVersion=2.02.xx-dev-ht-v09.8.5 +modVersion=2.02.xx-dev-ht-v09.9 kotlin_version=1.4.30 kotlinx_coroutines_version=1.4.2 \ No newline at end of file diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index ab97acd806..34a7a3aeff 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -806,7 +806,7 @@ internal object HighwayTools : Module( } else { waitTicks-- - pendingTasks.values.forEach { + pendingTasks.values.toList().forEach { doTask(it, true) } @@ -957,7 +957,7 @@ internal object HighwayTools : Module( } private fun doDone(blockTask: BlockTask) { - pendingTasks[blockTask.blockPos] + pendingTasks.remove(blockTask.blockPos) doneTasks[blockTask.blockPos] = blockTask } From 16876e73e8ac7b305342ec5b04b1e21bb6da0a3d Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 2 Mar 2021 17:51:26 +0100 Subject: [PATCH 371/390] Revert AutoObby to master version --- .../module/modules/misc/AutoObsidian.kt | 36 ++++++++++++++----- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/AutoObsidian.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/AutoObsidian.kt index bf2e8fed53..f3d8bf1992 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/AutoObsidian.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/AutoObsidian.kt @@ -52,6 +52,7 @@ import org.kamiblue.client.util.math.VectorUtils.toVec3dCenter import org.kamiblue.client.util.text.MessageSendHelper import org.kamiblue.client.util.threads.* import org.kamiblue.commons.interfaces.DisplayEnum +import org.kamiblue.event.listener.asyncListener import org.kamiblue.event.listener.listener import kotlin.math.ceil @@ -65,9 +66,10 @@ internal object AutoObsidian : Module( private val searchShulker by setting("Search Shulker", false) private val leaveEmptyShulkers by setting("Leave Empty Shulkers", true, { searchShulker }) private val autoRefill by setting("Auto Refill", false, { fillMode != FillMode.INFINITE }) + private val instantMining by setting("Instant Mining", true) + private val instantMiningDelay by setting("Instant Mining Delay", 10, 1..20, 1, { instantMining }) private val threshold by setting("Refill Threshold", 32, 1..64, 1, { autoRefill && fillMode != FillMode.INFINITE }) private val targetStacks by setting("Target Stacks", 1, 1..20, 1, { fillMode == FillMode.TARGET_STACKS }) - private val noDisable by setting("No Disable", false) private val delayTicks by setting("Delay Ticks", 4, 1..10, 1) private val rotationMode by setting("Rotation Mode", RotationMode.SPOOF) private val maxReach by setting("Max Reach", 4.9f, 2.0f..6.0f, 0.1f) @@ -143,8 +145,16 @@ internal object AutoObsidian : Module( } } + asyncListener { + if (!instantMining || it.packet !is CPacketPlayerDigging) return@asyncListener + + if (it.packet.position != placingPos || it.packet.facing != lastMiningSide) { + canInstantMine = false + } + } + safeAsyncListener { - if (it.packet !is SPacketBlockChange) return@safeAsyncListener + if (!instantMining || it.packet !is SPacketBlockChange) return@safeAsyncListener if (it.packet.blockPosition != placingPos) return@safeAsyncListener val prevBlock = world.getBlockState(it.packet.blockPosition).block @@ -278,7 +288,7 @@ internal object AutoObsidian : Module( } else { MessageSendHelper.sendChatMessage("$chatName No valid position for placing shulker box / ender chest nearby, disabling.") mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) - if (!noDisable) disable() + disable() } } @@ -460,7 +470,7 @@ internal object AutoObsidian : Module( if (!moved) { MessageSendHelper.sendChatMessage("$chatName No shulker box was found in inventory, disabling.") mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) - if (!noDisable) disable() + disable() } onInventoryOperation() @@ -485,7 +495,7 @@ internal object AutoObsidian : Module( if (!moved) { MessageSendHelper.sendChatMessage("$chatName No ender chest was found in inventory, disabling.") mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) - if (!noDisable) disable() + disable() } onInventoryOperation() @@ -510,7 +520,7 @@ internal object AutoObsidian : Module( } else { MessageSendHelper.sendChatMessage("$chatName No ender chest was found in shulker, disabling.") mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) - if (!noDisable) disable() + disable() } } } else { @@ -573,11 +583,21 @@ internal object AutoObsidian : Module( val center = pos.toVec3dCenter() val diff = player.getPositionEyes(1.0f).subtract(center) val normalizedVec = diff.normalize() - val side = EnumFacing.getFacingFromVector(normalizedVec.x.toFloat(), normalizedVec.y.toFloat(), normalizedVec.z.toFloat()) + var side = EnumFacing.getFacingFromVector(normalizedVec.x.toFloat(), normalizedVec.y.toFloat(), normalizedVec.z.toFloat()) lastHitVec = center rotateTimer.reset() + if (instantMining && canInstantMine) { + if (!miningTimer.tick(instantMiningDelay.toLong(), false)) return + + if (!miningTimeoutTimer.tick(2L, false)) { + side = side.opposite + } else { + canInstantMine = false + } + } + defaultScope.launch { delay(20L) onMainThreadSafe { @@ -618,7 +638,7 @@ internal object AutoObsidian : Module( if (!moved) { MessageSendHelper.sendChatMessage("No valid pickaxe was found in inventory.") mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) - if (!noDisable) disable() + disable() } onInventoryOperation() From f6860ead4d75d757eaa95a1f75b8d57170362eef Mon Sep 17 00:00:00 2001 From: Christian Date: Sun, 14 Mar 2021 02:40:02 +0100 Subject: [PATCH 372/390] Cramped commits - Added LimitOrigin - Changed back to old mining packets - Revived disable on no tool - Fixed minor bugs - Improved code --- .../module/modules/misc/HighwayTools.kt | 89 ++++++++++--------- 1 file changed, 46 insertions(+), 43 deletions(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index 2742142c1b..2fc1a933f7 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -72,7 +72,6 @@ import kotlin.random.Random.Default.nextInt /** * @author Avanatiker * @since 20/08/2020 - * */ internal object HighwayTools : Module( name = "HighwayTools", @@ -125,11 +124,13 @@ internal object HighwayTools : Module( private val rubberbandTimeout by setting("Rubberband Timeout", 50, 5..100, 5, { page == Page.BEHAVIOR }, description = "Timeout for pausing after a lag") private val maxReach by setting("Max Reach", 4.9f, 1.0f..6.0f, 0.1f, { page == Page.BEHAVIOR }, description = "Sets the range of the blueprint. Decrease when tasks fail!") private val maxBreaks by setting("Multi Break", 1, 1..5, 1, { page == Page.BEHAVIOR }, description = "EXPERIMENTAL: Breaks multiple instant breaking blocks per tick in view") + private val limitOrigin by setting("Limited by", LimitMode.FIXED, { page == Page.BEHAVIOR }, description = "Changes the origin of limit: Client / Server TPS") private val limitFactor by setting("Limit Factor", 1.0f, 0.5f..2.0f, 0.01f, { page == Page.BEHAVIOR }, description = "EXPERIMENTAL: Factor for TPS which acts as limit for maximum breaks per second.") + private val emptyDisable by setting("Disable on no Tools", true, { page == Page.BEHAVIOR }, description = "Disables when no pickaxes are left") private val placementSearch by setting("Place Deep Search", 2, 1..4, 1, { page == Page.BEHAVIOR }, description = "EXPERIMENTAL: Attempts to find a support block for placing against") // stat settings - private val anonymizeStats by setting("Anonymize", false, { page == Page.STATS }, description = "Censors all coordinates in HUD and Chat.") + private val anonymizeStats by setting("Anonymize", false, { page == Page.STATS }, description = "Censors all coordinates in HUD and Chat") private val simpleMovingAverageRange by setting("Moving Average", 60, 5..600, 5, { page == Page.STATS }, description = "Sets the timeframe of the average in seconds") private val showSession by setting("Show Session", true, { page == Page.STATS }, description = "Toggles the Session section in HUD") private val showLifeTime by setting("Show Lifetime", true, { page == Page.STATS }, description = "Toggles the Lifetime section in HUD") @@ -163,6 +164,10 @@ internal object HighwayTools : Module( OFF, SPOOF, VIEW_LOCK } + private enum class LimitMode { + FIXED, SERVER + } + private enum class DebugMessages { OFF, IMPORTANT, ALL } @@ -301,16 +306,16 @@ internal object HighwayTools : Module( if (!anonymizeStats) { if (startingDirection.isDiagonal) { - MessageSendHelper.sendRawChatMessage(" §9> §7Axis offset: §a${startingBlockPos.x} ${startingBlockPos.z}§r") + MessageSendHelper.sendRawChatMessage(" §9> §7Axis offset: §a%,d %,d§r".format(startingBlockPos.x, startingBlockPos.z)) if (abs(startingBlockPos.x) != abs(startingBlockPos.z)) { MessageSendHelper.sendRawChatMessage(" §9> §cYou may have an offset to diagonal highway position!") } } else { if (startingDirection == Direction.NORTH || startingDirection == Direction.SOUTH) { - MessageSendHelper.sendRawChatMessage(" §9> §7Axis offset: §a${startingBlockPos.x}§r") + MessageSendHelper.sendRawChatMessage(" §9> §7Axis offset: §a%,d§r".format(startingBlockPos.x)) } else { - MessageSendHelper.sendRawChatMessage(" §9> §7Axis offset: §a${startingBlockPos.z}§r") + MessageSendHelper.sendRawChatMessage(" §9> §7Axis offset: §a%,d§r".format(startingBlockPos.z)) } } @@ -345,9 +350,9 @@ internal object HighwayTools : Module( private fun printDisable() { if (info) { - MessageSendHelper.sendRawChatMessage(" §9> §7Placed blocks: §a$totalBlocksPlaced§r") - MessageSendHelper.sendRawChatMessage(" §9> §7Destroyed blocks: §a$totalBlocksBroken§r") - MessageSendHelper.sendRawChatMessage(" §9> §7Distance: §a${startingBlockPos.distanceTo(currentBlockPos).toInt()}§r") + MessageSendHelper.sendRawChatMessage(" §9> §7Placed blocks: §a%,d§r".format(totalBlocksPlaced)) + MessageSendHelper.sendRawChatMessage(" §9> §7Destroyed blocks: §a%,d§r".format(totalBlocksBroken)) + MessageSendHelper.sendRawChatMessage(" §9> §7Distance: §a%,d§r".format(startingBlockPos.distanceTo(currentBlockPos).toInt())) } } @@ -420,7 +425,9 @@ internal object HighwayTools : Module( AutoObsidian.isActive() || (world.difficulty == EnumDifficulty.PEACEFUL && player.dimension == 1 && - player.serverBrand.contains("2b2t"))) { + @Suppress("UNNECESSARY_SAFE_CALL") + player.serverBrand?.contains("2b2t") == true + )) { refreshData() return@safeListener } @@ -578,7 +585,7 @@ internal object HighwayTools : Module( val zDirection = startingDirection val xDirection = zDirection.clockwise(if (zDirection.isDiagonal) 1 else 2) - for (x in -maxReach.floorToInt()..maxReach.ceilToInt()) { + for (x in -maxReach.floorToInt() * 2..maxReach.ceilToInt() * 2) { val thisPos = basePos.add(zDirection.directionVec.multiply(x)) if (clearSpace) generateClear(thisPos, xDirection) if (mode == Mode.TUNNEL) { @@ -594,16 +601,16 @@ internal object HighwayTools : Module( generateBase(thisPos, xDirection) } } - if (mode == Mode.TUNNEL && !cleanFloor) { + if (mode == Mode.TUNNEL && (!cleanFloor || backfill)) { if (startingDirection.isDiagonal) { - for (x in 1..maxReach.floorToInt()) { - blueprint[basePos.add(zDirection.directionVec.multiply(x))] = fillerMat - } - } else { - for (x in 1..maxReach.floorToInt()) { + for (x in 0..maxReach.floorToInt()) { val pos = basePos.add(zDirection.directionVec.multiply(x)) blueprint[pos] = fillerMat - blueprint[pos.add(startingDirection.clockwise(4).directionVec)] = fillerMat + blueprint[pos.add(startingDirection.clockwise(7).directionVec)] = fillerMat + } + } else { + for (x in 0..maxReach.floorToInt()) { + blueprint[basePos.add(zDirection.directionVec.multiply(x))] = fillerMat } } } @@ -1265,14 +1272,11 @@ internal object HighwayTools : Module( } private fun SafeClientEvent.shouldBridge(): Boolean { - var containsPlace = false - for (task in sortedTasks) { - if (task.taskState == TaskState.PLACE) { - containsPlace = true - if (getNeighbourSequence(task.blockPos, placementSearch, maxReach, true).isNotEmpty()) return false + return world.isAirBlock(currentBlockPos.add(startingDirection.directionVec).down()) && + !sortedTasks.any { + it.taskState == TaskState.PLACE && + getNeighbourSequence(it.blockPos, placementSearch, maxReach, true).isNotEmpty() } - } - return containsPlace } private fun SafeClientEvent.getBestTool(blockTask: BlockTask): Slot? { @@ -1296,14 +1300,15 @@ internal object HighwayTools : Module( } private fun SafeClientEvent.swapOrMoveBestTool(blockTask: BlockTask): Boolean { + if (emptyDisable && player.allSlots.countItem(Items.DIAMOND_PICKAXE) == 0) { + MessageSendHelper.sendChatMessage("$chatName No Diamond Pickaxe was found in inventory, disable") + mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) + disable() + } + val slotFrom = getBestTool(blockTask) return if (slotFrom != null) { -// if (emptyDisable && slotFrom.stack.item != Items.DIAMOND_PICKAXE) { -// MessageSendHelper.sendChatMessage("$chatName No ${Items.DIAMOND_PICKAXE.registryName} was found in inventory, disable") -// mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) -// disable() -// } slotFrom.toHotbarSlotOrNull()?.let { swapToSlot(it) } ?: run { @@ -1426,9 +1431,14 @@ internal object HighwayTools : Module( packetLimiter.size } - if (size > TpsCalculator.tickRate * limitFactor) { + val limit = when (limitOrigin) { + LimitMode.FIXED -> 20.0f + LimitMode.SERVER -> TpsCalculator.tickRate + } + + if (size > limit * limitFactor) { if (debugMessages == DebugMessages.ALL) { - MessageSendHelper.sendChatMessage("$chatName Dropped possible instant mine action @ TPS(${TpsCalculator.tickRate}) Actions(${size})") + MessageSendHelper.sendChatMessage("$chatName Dropped possible instant mine action @ TPS($limit) Actions(${size})") } break } @@ -1463,20 +1473,13 @@ internal object HighwayTools : Module( /* Dispatches a thread to mine any non-netherrack blocks generically */ private fun mineBlockNormal(blockTask: BlockTask, side: EnumFacing) { + if (blockTask.taskState == TaskState.BREAK) { + blockTask.updateState(TaskState.BREAKING) + } + defaultScope.launch { delay(20L) - if (blockTask.taskState == TaskState.BREAK) { - blockTask.updateState(TaskState.BREAKING) - onMainThreadSafe { - connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, blockTask.blockPos, side)) - player.swingArm(EnumHand.MAIN_HAND) - } - } else { - onMainThreadSafe { - connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, blockTask.blockPos, side)) - player.swingArm(EnumHand.MAIN_HAND) - } - } + sendMiningPackets(blockTask.blockPos, side) } } From 83c7ac01dc24b1acd245ccde4c810a42badcf4b3 Mon Sep 17 00:00:00 2001 From: Christian Date: Sun, 14 Mar 2021 03:10:55 +0100 Subject: [PATCH 373/390] Fix wrong ignore and collidables --- .../client/module/modules/misc/HighwayTools.kt | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index 2fc1a933f7..52213d876c 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -1048,14 +1048,16 @@ internal object HighwayTools : Module( private fun SafeClientEvent.doBreak(blockTask: BlockTask, updateOnly: Boolean) { val currentBlock = world.getBlockState(blockTask.blockPos).block - if (ignoreBlocks.contains(currentBlock.registryName.toString())) { + if (ignoreBlocks.contains(currentBlock.registryName.toString()) && + !isInsideBlueprintBuild(blockTask.blockPos)) { blockTask.updateState(TaskState.DONE) } when (blockTask.block) { fillerMat -> { if (world.getBlockState(blockTask.blockPos.up()).block == material || - !world.isPlaceable(blockTask.blockPos)) { + (!world.isPlaceable(blockTask.blockPos) && + world.getCollisionBox(blockTask.blockPos) != null)) { blockTask.updateState(TaskState.DONE) return } @@ -1496,7 +1498,11 @@ internal object HighwayTools : Module( } private fun isInsideBlueprintBuild(pos: BlockPos): Boolean { - return blueprint[pos]?.let { it == material } ?: false + val mat = when (mode) { + Mode.HIGHWAY, Mode.FLAT -> material + Mode.TUNNEL -> fillerMat + } + return blueprint[pos]?.let { it == mat } ?: false } fun printSettings() { From 013ba5a89233469deafe66266ce55f84a9a9dc4c Mon Sep 17 00:00:00 2001 From: Christian Date: Thu, 18 Mar 2021 07:49:39 +0100 Subject: [PATCH 374/390] Fix portal path tests with ghost items --- .../module/modules/misc/HighwayTools.kt | 22 ++++++++++++++----- .../kamiblue/client/util/world/Interact.kt | 8 +++++-- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index 52213d876c..6eb3d8e64f 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -14,6 +14,7 @@ import net.minecraft.init.Blocks import net.minecraft.init.Enchantments import net.minecraft.init.Items import net.minecraft.init.SoundEvents +import net.minecraft.inventory.ClickType import net.minecraft.inventory.Slot import net.minecraft.item.ItemBlock import net.minecraft.item.ItemPickaxe @@ -787,7 +788,7 @@ internal object HighwayTools : Module( private fun SafeClientEvent.isTaskDoneOrNull(pos: BlockPos, solid: Boolean) = (pendingTasks[pos] ?: doneTasks[pos])?.let { - it.taskState == TaskState.DONE + it.taskState == TaskState.DONE && world.getBlockState(pos).block != Blocks.PORTAL } ?: run { if (solid) { !world.isPlaceable(pos, true) @@ -917,7 +918,16 @@ internal object HighwayTools : Module( } } - if (dynamicDelay && blockTask.taskState == TaskState.PLACE && extraPlaceDelay < 10) extraPlaceDelay += 1 + if (blockTask.taskState == TaskState.PLACE) { + if (dynamicDelay && extraPlaceDelay < 10) extraPlaceDelay += 1 + + // is supposed to click the itemstack in selected slot +// player.hotbarSlots.firstByStack { +// player.heldItemMainhand == it +// }?.let { +// playerController.windowClick(player.openContainer.windowId, it.slotIndex, 0, ClickType.PICKUP, player) +// } + } refreshData() return false @@ -1571,7 +1581,7 @@ internal object HighwayTools : Module( } private fun SafeClientEvent.gatherLifeTime(displayText: TextComponent) { - val matMined = StatList.getObjectUseStats(material.item)?.let { + val matPlaced = StatList.getObjectUseStats(material.item)?.let { player.statFileWriter.readStat(it) } ?: 0 val enderMined = StatList.getBlockStats(Blocks.ENDER_CHEST)?.let { @@ -1584,14 +1594,14 @@ internal object HighwayTools : Module( player.statFileWriter.readStat(it) } ?: 0 - if (matMined + enderMined + netherrackMined + pickaxeBroken > 0) { + if (matPlaced + enderMined + netherrackMined + pickaxeBroken > 0) { displayText.addLine("Lifetime", primaryColor) } if (mode == Mode.HIGHWAY || mode == Mode.FLAT) { - if (matMined > 0) { + if (matPlaced > 0) { displayText.add(" ${material.localizedName} placed:", primaryColor) - displayText.addLine("%,d".format(matMined), secondaryColor) + displayText.addLine("%,d".format(matPlaced), secondaryColor) } if (enderMined > 0) { diff --git a/src/main/kotlin/org/kamiblue/client/util/world/Interact.kt b/src/main/kotlin/org/kamiblue/client/util/world/Interact.kt index 556cdef2bb..c408e9a04c 100644 --- a/src/main/kotlin/org/kamiblue/client/util/world/Interact.kt +++ b/src/main/kotlin/org/kamiblue/client/util/world/Interact.kt @@ -55,8 +55,12 @@ private fun SafeClientEvent.getNeighbourSequence( val newSequence = ArrayList(sequence) newSequence.add(placeInfo) - return getNeighbourSequence(eyePos, newPos, attempts - 1, range, visibleSideCheck, sides, newSequence, toIgnore) - ?: continue + val neigh = getNeighbourSequence(eyePos, newPos, attempts - 1, range, visibleSideCheck, sides, newSequence, toIgnore) + if (neigh.isNotEmpty()) { + return neigh + } else { + continue + } } } From ce2f0f192c3bfbdb1532b7383ad26cfb786d3046 Mon Sep 17 00:00:00 2001 From: Christian Date: Sat, 20 Mar 2021 05:55:53 +0100 Subject: [PATCH 375/390] Fix breaking unbreakables --- .../org/kamiblue/client/module/modules/misc/HighwayTools.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index 6eb3d8e64f..01e16591f9 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -1059,7 +1059,11 @@ internal object HighwayTools : Module( val currentBlock = world.getBlockState(blockTask.blockPos).block if (ignoreBlocks.contains(currentBlock.registryName.toString()) && - !isInsideBlueprintBuild(blockTask.blockPos)) { + !isInsideBlueprintBuild(blockTask.blockPos) || + currentBlock == Blocks.PORTAL || + currentBlock == Blocks.END_PORTAL || + currentBlock == Blocks.END_PORTAL_FRAME || + currentBlock == Blocks.BEDROCK) { blockTask.updateState(TaskState.DONE) } From e75479cbfa76d32edbf62f596e39614dad5af4cc Mon Sep 17 00:00:00 2001 From: Christian Date: Thu, 25 Mar 2021 18:31:36 +0100 Subject: [PATCH 376/390] Added storage management sketch - DiscordRPC Highway mode - better version --- .../kotlin/org/kamiblue/client/KamiMod.kt | 2 +- .../client/module/modules/misc/DiscordRPC.kt | 42 +- .../module/modules/misc/HighwayTools.kt | 469 ++++++++++++++---- 3 files changed, 410 insertions(+), 103 deletions(-) diff --git a/src/main/kotlin/org/kamiblue/client/KamiMod.kt b/src/main/kotlin/org/kamiblue/client/KamiMod.kt index 976b53fe7e..f301ac8de7 100644 --- a/src/main/kotlin/org/kamiblue/client/KamiMod.kt +++ b/src/main/kotlin/org/kamiblue/client/KamiMod.kt @@ -26,7 +26,7 @@ class KamiMod { const val DIRECTORY = "kamiblue/" const val VERSION = "2.03.xx-dev" // Used for debugging. R.MM.DD-hash format. - const val VERSION_SIMPLE = "2.03.xx-dev" // Shown to the user. R.MM.DD[-beta] format. + const val VERSION_SIMPLE = "ht-v9.9" // Shown to the user. R.MM.DD[-beta] format. const val VERSION_MAJOR = "2.03.01" // Used for update checking. RR.MM.01 format. const val BUILD_NUMBER = -1 // Do not remove, currently unused but will be used in the future. diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/DiscordRPC.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/DiscordRPC.kt index 19119e177c..699fc1811a 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/DiscordRPC.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/DiscordRPC.kt @@ -3,6 +3,7 @@ package org.kamiblue.client.module.modules.misc import club.minnced.discord.rpc.DiscordEventHandlers import club.minnced.discord.rpc.DiscordRichPresence import net.minecraft.client.Minecraft +import net.minecraft.init.Blocks import net.minecraftforge.fml.common.gameevent.TickEvent import org.kamiblue.capeapi.CapeType import org.kamiblue.client.KamiMod @@ -30,14 +31,15 @@ internal object DiscordRPC : Module( description = "Discord Rich Presence", enabledByDefault = true ) { - private val line1Left by setting("Line 1 Left", LineInfo.VERSION) // details left - private val line1Right by setting("Line 1 Right", LineInfo.USERNAME) // details right - private val line2Left by setting("Line 2 Left", LineInfo.SERVER_IP) // state left - private val line2Right by setting("Line 2 Right", LineInfo.HEALTH) // state right - private val coordsConfirm by setting("Coords Confirm", false, { showCoordsConfirm() }) + private val highwayMode by setting("HighwayMode", false) + private val line1Left by setting("Line 1 Left", LineInfo.VERSION, { !highwayMode }) // details left + private val line1Right by setting("Line 1 Right", LineInfo.USERNAME, { !highwayMode }) // details right + private val line2Left by setting("Line 2 Left", LineInfo.SERVER_IP, { !highwayMode }) // state left + private val line2Right by setting("Line 2 Right", LineInfo.HEALTH, { !highwayMode }) // state right + private val coordsConfirm by setting("Coords Confirm", false, { showCoordsConfirm() && !highwayMode }) private enum class LineInfo { - VERSION, WORLD, DIMENSION, USERNAME, HEALTH, HUNGER, SERVER_IP, COORDS, SPEED, HELD_ITEM, FPS, TPS, HIGHWAY__WORK, NONE + VERSION, WORLD, DIMENSION, USERNAME, HEALTH, HUNGER, SERVER_IP, COORDS, SPEED, HELD_ITEM, FPS, TPS, NONE } private val presence = DiscordRichPresence() @@ -98,8 +100,28 @@ internal object DiscordRPC : Module( } private fun updateRPC() { - presence.details = getLine(line1Left) + getSeparator(0) + getLine(line1Right) - presence.state = getLine(line2Left) + getSeparator(1) + getLine(line2Right) + if (highwayMode) { + if (HighwayTools.matPlaced + HighwayTools.netherrackMined > 0) { + var pre = "" + when (HighwayTools.mode) { + HighwayTools.Mode.HIGHWAY, HighwayTools.Mode.FLAT -> { + presence.details = "%,d ${HighwayTools.material.localizedName}".format(HighwayTools.matPlaced) + pre = "placed" + } + HighwayTools.Mode.TUNNEL -> { + presence.details = "%,d ${Blocks.NETHERRACK.localizedName}".format(HighwayTools.netherrackMined) + pre = "mined" + } + } + presence.state = "$pre with ${KamiMod.VERSION_SIMPLE}" + } else { + presence.details = "running ${KamiMod.VERSION_SIMPLE}" + presence.state = "" + } + } else { + presence.details = getLine(line1Left) + getSeparator(0) + getLine(line1Right) + presence.state = getLine(line2Left) + getSeparator(1) + getLine(line2Right) + } rpc.Discord_UpdatePresence(presence) } @@ -118,10 +140,6 @@ internal object DiscordRPC : Module( LineInfo.DIMENSION -> { InfoCalculator.dimension() } - LineInfo.HIGHWAY__WORK -> { - if (HighwayTools.isEnabled) "Making Highways" - else "Doing Nothing" - } LineInfo.USERNAME -> { mc.session.username } diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index 01e16591f9..450a6f50b2 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -15,25 +15,23 @@ import net.minecraft.init.Enchantments import net.minecraft.init.Items import net.minecraft.init.SoundEvents import net.minecraft.inventory.ClickType +import net.minecraft.inventory.ItemStackHelper import net.minecraft.inventory.Slot -import net.minecraft.item.ItemBlock -import net.minecraft.item.ItemPickaxe -import net.minecraft.network.play.client.CPacketClientStatus -import net.minecraft.network.play.client.CPacketEntityAction -import net.minecraft.network.play.client.CPacketPlayerDigging -import net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock -import net.minecraft.network.play.server.SPacketBlockChange -import net.minecraft.network.play.server.SPacketPlayerPosLook -import net.minecraft.network.play.server.SPacketSetSlot +import net.minecraft.item.* +import net.minecraft.network.play.client.* +import net.minecraft.network.play.server.* import net.minecraft.stats.StatList import net.minecraft.util.EnumFacing import net.minecraft.util.EnumHand +import net.minecraft.util.NonNullList import net.minecraft.util.SoundCategory import net.minecraft.util.math.AxisAlignedBB import net.minecraft.util.math.BlockPos +import net.minecraft.util.math.RayTraceResult import net.minecraft.util.math.Vec3d import net.minecraft.world.EnumDifficulty import net.minecraftforge.fml.common.gameevent.TickEvent +import org.kamiblue.client.KamiMod import org.kamiblue.client.event.SafeClientEvent import org.kamiblue.client.event.events.PacketEvent import org.kamiblue.client.event.events.RenderWorldEvent @@ -51,6 +49,7 @@ import org.kamiblue.client.process.PauseProcess import org.kamiblue.client.setting.settings.impl.collection.CollectionSetting import org.kamiblue.client.util.* import org.kamiblue.client.util.EntityUtils.flooredPosition +import org.kamiblue.client.util.EntityUtils.getDroppedItem import org.kamiblue.client.util.color.ColorHolder import org.kamiblue.client.util.graphics.ESPRenderer import org.kamiblue.client.util.graphics.font.TextComponent @@ -58,6 +57,7 @@ import org.kamiblue.client.util.items.* import org.kamiblue.client.util.math.CoordinateConverter.asString import org.kamiblue.client.util.math.Direction import org.kamiblue.client.util.math.RotationUtils.getRotationTo +import org.kamiblue.client.util.math.VectorUtils import org.kamiblue.client.util.math.VectorUtils.distanceTo import org.kamiblue.client.util.math.VectorUtils.multiply import org.kamiblue.client.util.math.VectorUtils.toVec3dCenter @@ -95,11 +95,11 @@ internal object HighwayTools : Module( ) // build settings - private val mode by setting("Mode", Mode.HIGHWAY, { page == Page.BUILD }, description = "Choose the structure") + val mode by setting("Mode", Mode.HIGHWAY, { page == Page.BUILD }, description = "Choose the structure") private val width by setting("Width", 6, 1..11, 1, { page == Page.BUILD }, description = "Sets the width of blueprint") private val height by setting("Height", 4, 1..6, 1, { page == Page.BUILD && clearSpace }, description = "Sets height of blueprint") private val backfill by setting("Backfill", false, { page == Page.BUILD && mode == Mode.TUNNEL }, description = "Backfills tunnel") - private val clearSpace by setting("Clear Space", true, { page == Page.BUILD && mode == Mode.HIGHWAY}, description = "Clears out the tunnel if necessary") + private val clearSpace by setting("Clear Space", true, { page == Page.BUILD && mode == Mode.HIGHWAY }, description = "Clears out the tunnel if necessary") private val cleanFloor by setting("Clean Floor", false, { page == Page.BUILD && mode == Mode.TUNNEL && !backfill }, description = "Cleans up the tunnels floor") private val cleanWalls by setting("Clean Walls", false, { page == Page.BUILD && mode == Mode.TUNNEL && !backfill }, description = "Cleans up the tunnels walls") private val cleanRoof by setting("Clean Roof", false, { page == Page.BUILD && mode == Mode.TUNNEL && !backfill }, description = "Cleans up the tunnels roof") @@ -127,9 +127,15 @@ internal object HighwayTools : Module( private val maxBreaks by setting("Multi Break", 1, 1..5, 1, { page == Page.BEHAVIOR }, description = "EXPERIMENTAL: Breaks multiple instant breaking blocks per tick in view") private val limitOrigin by setting("Limited by", LimitMode.FIXED, { page == Page.BEHAVIOR }, description = "Changes the origin of limit: Client / Server TPS") private val limitFactor by setting("Limit Factor", 1.0f, 0.5f..2.0f, 0.01f, { page == Page.BEHAVIOR }, description = "EXPERIMENTAL: Factor for TPS which acts as limit for maximum breaks per second.") - private val emptyDisable by setting("Disable on no Tools", true, { page == Page.BEHAVIOR }, description = "Disables when no pickaxes are left") private val placementSearch by setting("Place Deep Search", 2, 1..4, 1, { page == Page.BEHAVIOR }, description = "EXPERIMENTAL: Attempts to find a support block for placing against") + // storage management + private val packetInteraction by setting("Packet Interaction", false, { page == Page.STORE_MANAGEMENT }, description = "Choose to interact with container using only packets.") + private val leaveEmptyShulkers by setting("Leave Empty Shulkers", true, { page == Page.STORE_MANAGEMENT }, description = "Does not break empty shulkers.") + private val saveMaterial by setting("Save Material", 12, 0..64, 1, { page == Page.STORE_MANAGEMENT }, description = "How many material blocks are saved") + private val saveTools by setting("Save Tools", 1, 0..64, 1, { page == Page.STORE_MANAGEMENT }, description = "How many tools are saved") + private val enableAntiAFK by setting("AntiAFK", true, { page == Page.STORE_MANAGEMENT }, description = "Enables AntiAFK on empty") + // stat settings private val anonymizeStats by setting("Anonymize", false, { page == Page.STATS }, description = "Censors all coordinates in HUD and Chat") private val simpleMovingAverageRange by setting("Moving Average", 60, 5..600, 5, { page == Page.STATS }, description = "Sets the timeframe of the average in seconds") @@ -152,12 +158,12 @@ internal object HighwayTools : Module( private val aFilled by setting("Filled Alpha", 26, 0..255, 1, { filled && page == Page.CONFIG }, description = "Sets the opacity") private val aOutline by setting("Outline Alpha", 91, 0..255, 1, { outline && page == Page.CONFIG }, description = "Sets the opacity") - private enum class Mode { + enum class Mode { HIGHWAY, FLAT, TUNNEL } private enum class Page { - BUILD, BEHAVIOR, STATS, CONFIG + BUILD, BEHAVIOR, STORE_MANAGEMENT, STATS, CONFIG } @Suppress("UNUSED") @@ -205,6 +211,7 @@ internal object HighwayTools : Module( // Pathing var goal: GoalNear? = null; private set + private var moveState = MovementState.RUNNING // Tasks private val pendingTasks = LinkedHashMap() @@ -215,6 +222,11 @@ internal object HighwayTools : Module( private val packetLimiterMutex = Mutex() private val packetLimiter = ArrayDeque() + // Long term inventory management + private val shulkerOpenTimer = TickTimer(TimeUnit.TICKS) + private var nextShulker: Slot? = null + private var nextShulkerID = 0 + // Stats private val simpleMovingAveragePlaces = ArrayDeque() private val simpleMovingAverageBreaks = ArrayDeque() @@ -229,6 +241,10 @@ internal object HighwayTools : Module( private var fillerMatLeft = 0 private var lastToolDamage = 0 private var durabilityUsages = 0 + var matPlaced = 0 + private var enderMined = 0 + var netherrackMined = 0 + private var pickaxeBroken = 0 private val stateUpdateMutex = Mutex() private val renderer = ESPRenderer() @@ -245,7 +261,7 @@ internal object HighwayTools : Module( onEnable { runSafeR { /* Turn on inventory manager if the users wants us to control it */ - if (toggleInventoryManager && InventoryManager.isDisabled) { + if (toggleInventoryManager && InventoryManager.isDisabled && mode != Mode.TUNNEL) { InventoryManager.enable() } @@ -358,14 +374,14 @@ internal object HighwayTools : Module( } init { - safeListener { - when (it.packet) { + safeListener { event -> + when (event.packet) { is SPacketBlockChange -> { - val pos = it.packet.blockPosition + val pos = event.packet.blockPosition if (!isInsideBlueprint(pos)) return@safeListener val prev = world.getBlockState(pos).block - val new = it.packet.getBlockState().block + val new = event.packet.getBlockState().block if (prev != new) { val task = pendingTasks[pos] ?: return@safeListener @@ -398,15 +414,33 @@ internal object HighwayTools : Module( is SPacketPlayerPosLook -> { rubberbandTimer.reset() } - is SPacketSetSlot -> { - val currentToolDamage = it.packet.stack.itemDamage - val durabilityUsage = currentToolDamage - lastToolDamage - - if (durabilityUsage in 1..100) { - durabilityUsages += durabilityUsage + is SPacketOpenWindow -> { + if (event.packet.guiId == "minecraft:shulker_box") { + @Suppress("UNNECESSARY_SAFE_CALL") + sortedTasks.first { it.isShulker }?.let { it.isOpen = true } + event.cancel() + } + } + is SPacketWindowItems -> { + @Suppress("UNNECESSARY_SAFE_CALL") + sortedTasks.first { it.isShulker }?.let { + if (it.isOpen) { + it.inventory = event.packet.itemStacks.take(27) + it.windowID = event.packet.windowId + event.cancel() + } + } + } + is SPacketConfirmTransaction -> { + @Suppress("UNNECESSARY_SAFE_CALL") + sortedTasks.first { it.isShulker }?.let { + if (it.isOpen) { // why does event.packet.wasAccepted() returns always false? + it.isConfirmed = true + } } - - lastToolDamage = it.packet.stack.itemDamage + } + else -> { + // Nothing } } } @@ -465,7 +499,7 @@ internal object HighwayTools : Module( } doneTasks.values.forEach { - if (it.block == Blocks.AIR) return@forEach + if (it.block == Blocks.AIR || it.isShulker) return@forEach renderer.add(world.getBlockState(it.blockPos).getSelectedBoundingBox(world, it.blockPos), it.taskState.color) } } @@ -524,8 +558,10 @@ internal object HighwayTools : Module( } private fun SafeClientEvent.refreshData(originPos: BlockPos = currentBlockPos) { - doneTasks.clear() +// pendingTasks.values.removeAll { !it.isShulker } + moveState = MovementState.RUNNING pendingTasks.clear() + doneTasks.clear() lastTask = null blueprint.clear() @@ -627,7 +663,7 @@ internal object HighwayTools : Module( blueprint.keys.removeIf { eyePos.distanceTo(it) > maxReach - 0.7 || - startingBlockPos.add(startingDirection.clockwise(4).directionVec.multiply(maxReach.toInt())).distanceTo(it) < maxReach - 1 + startingBlockPos.add(startingDirection.clockwise(4).directionVec.multiply(maxReach.toInt())).distanceTo(it) < maxReach - 1 } } @@ -747,8 +783,8 @@ internal object HighwayTools : Module( } } - private fun addTaskToPending(blockPos: BlockPos, taskState: TaskState, material: Block) { - pendingTasks[blockPos] = (BlockTask(blockPos, taskState, material)) + private fun addTaskToPending(blockPos: BlockPos, taskState: TaskState, material: Block, item: Item = Items.AIR) { + pendingTasks[blockPos] = (BlockTask(blockPos, taskState, material, item = item)) } private fun addTaskToDone(blockPos: BlockPos, material: Block) { @@ -756,13 +792,30 @@ internal object HighwayTools : Module( } private fun SafeClientEvent.doPathing() { - val nextPos = getNextPos() + when (moveState) { + MovementState.RUNNING -> { + val nextPos = getNextPos() - if (player.flooredPosition.distanceTo(nextPos) < 2.0) { - currentBlockPos = nextPos - } + if (player.flooredPosition.distanceTo(nextPos) < 2.0) { + currentBlockPos = nextPos + } - goal = GoalNear(nextPos, 0) + goal = GoalNear(nextPos, 0) + } + MovementState.PICKUP -> { + nextShulker?.let { + val droppedItemPos = getDroppedItem(nextShulkerID, 8.0f) + goal = if (droppedItemPos != null) { + GoalNear(droppedItemPos, 0) + } else { + null + } + } + } + MovementState.BRIDGE -> { + // Bridge update + } + } } private fun SafeClientEvent.getNextPos(): BlockPos { @@ -860,7 +913,11 @@ internal object HighwayTools : Module( stateUpdateMutex.withLock { sortedTasks = pendingTasks.values.sortedWith( compareBy { - it.taskState.ordinal + if (it.isShulker) { + -69420 + } else { + it.taskState.ordinal + } }.thenBy { it.stuckTicks }.thenBy { @@ -880,7 +937,11 @@ internal object HighwayTools : Module( stateUpdateMutex.withLock { sortedTasks = pendingTasks.values.sortedWith( compareBy { - it.taskState.ordinal + if (it.isShulker) { + -69420 + } else { + it.taskState.ordinal + } }.thenBy { it.stuckTicks }.thenByDescending { @@ -918,15 +979,20 @@ internal object HighwayTools : Module( } } - if (blockTask.taskState == TaskState.PLACE) { - if (dynamicDelay && extraPlaceDelay < 10) extraPlaceDelay += 1 + when (blockTask.taskState) { + TaskState.PLACE -> { + if (dynamicDelay && extraPlaceDelay < 10) extraPlaceDelay += 1 - // is supposed to click the itemstack in selected slot -// player.hotbarSlots.firstByStack { -// player.heldItemMainhand == it -// }?.let { -// playerController.windowClick(player.openContainer.windowId, it.slotIndex, 0, ClickType.PICKUP, player) -// } + playerController.windowClick(player.openContainer.windowId, player.inventory.currentItem, 0, ClickType.PICKUP, player) + playerController.updateController() + } + TaskState.BREAK -> { + playerController.windowClick(player.openContainer.windowId, player.inventory.currentItem, 0, ClickType.PICKUP, player) + playerController.updateController() + } + else -> { + // Nothing + } } refreshData() @@ -945,6 +1011,21 @@ internal object HighwayTools : Module( TaskState.DONE -> { doDone(blockTask) } + TaskState.OPEN_CONTAINER -> { + doOpenContainer(blockTask) + } + TaskState.MOVE_ITEM -> { + doMoveItem(blockTask) + } + TaskState.MOVING_ITEM -> { + doMovingItem(blockTask) + } + TaskState.CLOSE_CONTAINER -> { + doCloseContainer(blockTask) + } + TaskState.PICKUP -> { + doPickup(blockTask) + } TaskState.BREAKING -> { doBreaking(blockTask, updateOnly) } @@ -974,6 +1055,89 @@ internal object HighwayTools : Module( doneTasks[blockTask.blockPos] = blockTask } + private fun SafeClientEvent.doOpenContainer(blockTask: BlockTask) { + + if (blockTask.isOpen && blockTask.inventory.isNotEmpty()) { + blockTask.updateState(TaskState.MOVE_ITEM) + } else { + val center = blockTask.blockPos.toVec3dCenter() + val diff = player.getPositionEyes(1f).subtract(center) + val normalizedVec = diff.normalize() + + val side = EnumFacing.getFacingFromVector(normalizedVec.x.toFloat(), normalizedVec.y.toFloat(), normalizedVec.z.toFloat()) + val hitVecOffset = getHitVecOffset(side) + + lastHitVec = getHitVec(blockTask.blockPos, side) + rotateTimer.reset() + + if (shulkerOpenTimer.tick(50)) { + defaultScope.launch { + delay(20L) + onMainThreadSafe { + connection.sendPacket(CPacketPlayerTryUseItemOnBlock(blockTask.blockPos, side, EnumHand.MAIN_HAND, hitVecOffset.x.toFloat(), hitVecOffset.y.toFloat(), hitVecOffset.z.toFloat())) + player.swingArm(EnumHand.MAIN_HAND) + } + } + } + } + } + + private fun SafeClientEvent.doMoveItem(blockTask: BlockTask) { + + val moveSlot = blockTask.inventory.indexOfFirst { it.item == blockTask.item } + + blockTask.updateState(TaskState.MOVING_ITEM) + + defaultScope.launch { + delay(10L) + connection.sendPacket(CPacketClickWindow(blockTask.windowID, moveSlot, 0, ClickType.QUICK_MOVE, blockTask.inventory[moveSlot], ++blockTask.transactionID)) + + delay(50L * taskTimeout) + if (blockTask.taskState == TaskState.MOVING_ITEM) { + stateUpdateMutex.withLock { + blockTask.updateState(TaskState.MOVE_ITEM) + } + } + } + } + + private fun doMovingItem(blockTask: BlockTask) { + if (blockTask.isConfirmed) { + blockTask.updateState(TaskState.CLOSE_CONTAINER) + } + } + + private fun SafeClientEvent.doCloseContainer(blockTask: BlockTask) { + + if (leaveEmptyShulkers && + blockTask.inventory.none { it.item != Items.AIR }) { + if (debugMessages == DebugMessages.IMPORTANT) MessageSendHelper.sendChatMessage("$chatName Left empty ${blockTask.block.localizedName}@(${blockTask.blockPos.asString()})") + blockTask.updateState(TaskState.DONE) + } else { + blockTask.updateState(TaskState.BREAK) + } + + blockTask.isOpen = false + blockTask.inventory = emptyList() + blockTask.isConfirmed = false + + defaultScope.launch { + delay(10L) + connection.sendPacket(CPacketCloseWindow(blockTask.windowID)) + } + } + + + private fun SafeClientEvent.doPickup(blockTask: BlockTask) { + moveState = MovementState.PICKUP + nextShulker?.let { + if (getDroppedItem(nextShulkerID, 8.0f) == null) { + moveState = MovementState.RUNNING + blockTask.updateState(TaskState.DONE) + } + } + } + private fun SafeClientEvent.doBreaking(blockTask: BlockTask, updateOnly: Boolean) { when (world.getBlockState(blockTask.blockPos).block) { Blocks.AIR -> { @@ -1001,6 +1165,7 @@ internal object HighwayTools : Module( } if (!updateOnly) { + swapOrMoveBestTool(blockTask) mineBlock(blockTask) } } @@ -1011,14 +1176,20 @@ internal object HighwayTools : Module( totalBlocksBroken++ simpleMovingAverageBreaks.add(System.currentTimeMillis()) - if (blockTask.block == Blocks.AIR) { - if (fakeSounds) { - val soundType = blockTask.block.getSoundType(world.getBlockState(blockTask.blockPos), world, blockTask.blockPos, player) - world.playSound(player, blockTask.blockPos, soundType.breakSound, SoundCategory.BLOCKS, (soundType.getVolume() + 1.0f) / 2.0f, soundType.getPitch() * 0.8f) + when { + blockTask.block == Blocks.AIR -> { + if (fakeSounds) { + val soundType = blockTask.block.getSoundType(world.getBlockState(blockTask.blockPos), world, blockTask.blockPos, player) + world.playSound(player, blockTask.blockPos, soundType.breakSound, SoundCategory.BLOCKS, (soundType.getVolume() + 1.0f) / 2.0f, soundType.getPitch() * 0.8f) + } + blockTask.updateState(TaskState.DONE) + } + blockTask.isShulker -> { + blockTask.updateState(TaskState.PICKUP) + } + else -> { + blockTask.updateState(TaskState.PLACE) } - blockTask.updateState(TaskState.DONE) - } else { - blockTask.updateState(TaskState.PLACE) } } else -> { @@ -1037,7 +1208,11 @@ internal object HighwayTools : Module( if (dynamicDelay && extraPlaceDelay > 0) extraPlaceDelay -= 1 - blockTask.updateState(TaskState.DONE) + if (blockTask.isShulker) { + blockTask.updateState(TaskState.OPEN_CONTAINER) + } else { + blockTask.updateState(TaskState.DONE) + } if (fakeSounds) { val soundType = currentBlock.getSoundType(world.getBlockState(blockTask.blockPos), world, blockTask.blockPos, player) world.playSound(player, blockTask.blockPos, soundType.placeSound, SoundCategory.BLOCKS, (soundType.getVolume() + 1.0f) / 2.0f, soundType.getPitch() * 0.8f) @@ -1059,6 +1234,7 @@ internal object HighwayTools : Module( val currentBlock = world.getBlockState(blockTask.blockPos).block if (ignoreBlocks.contains(currentBlock.registryName.toString()) && + !blockTask.isShulker && !isInsideBlueprintBuild(blockTask.blockPos) || currentBlock == Blocks.PORTAL || currentBlock == Blocks.END_PORTAL || @@ -1108,7 +1284,7 @@ internal object HighwayTools : Module( } } - if (!updateOnly) { + if (!updateOnly && player.onGround) { if (handleLiquid(blockTask)) return swapOrMoveBestTool(blockTask) mineBlock(blockTask) @@ -1191,28 +1367,6 @@ internal object HighwayTools : Module( } } - private fun SafeClientEvent.swapOrMoveBlock(blockTask: BlockTask): Boolean { - val useBlock = when { - player.allSlots.countBlock(blockTask.block) > 0 -> blockTask.block - player.allSlots.countBlock(material) > 0 -> material - player.allSlots.countBlock(fillerMat) > 0 && mode == Mode.TUNNEL -> fillerMat - else -> blockTask.block - } - - val success = swapToBlockOrMove(useBlock, predicateSlot = { - it.item is ItemBlock - }) - - return if (!success) { - MessageSendHelper.sendChatMessage("$chatName No ${blockTask.block.localizedName} was found in inventory") - mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) - disable() - false - } else { - true - } - } - private fun SafeClientEvent.placeBlock(blockTask: BlockTask) { val neighbours = if (illegalPlacements) { getNeighbourSequence(blockTask.blockPos, placementSearch, maxReach) @@ -1315,11 +1469,55 @@ internal object HighwayTools : Module( } } + + private fun SafeClientEvent.swapOrMoveBlock(blockTask: BlockTask): Boolean { + if (blockTask.isShulker) { + nextShulker?.let { slot -> + slot.toHotbarSlotOrNull()?.let { + swapToSlot(it) + } ?: run { + val slotTo = player.hotbarSlots.firstEmpty()?.hotbarSlot ?: 0 + moveToHotbar(slot.slotNumber, slotTo) + } + } + return true + } else { + if (mode != Mode.TUNNEL && + player.allSlots.countBlock(material) < saveMaterial) { + if (player.allSlots.countItem(Items.DIAMOND_PICKAXE) >= saveTools) { + handleRestock(blockTask, material.item) + } else { + handleRestock(blockTask, Items.DIAMOND_PICKAXE) + } + return false + } + + val useBlock = when { + player.allSlots.countBlock(blockTask.block) > 0 -> blockTask.block + player.allSlots.countBlock(material) > 0 -> material + player.allSlots.countBlock(fillerMat) > 0 && mode == Mode.TUNNEL -> fillerMat + else -> blockTask.block + } + + val success = swapToBlockOrMove(useBlock, predicateSlot = { + it.item is ItemBlock + }) + + return if (!success) { + MessageSendHelper.sendChatMessage("$chatName No ${blockTask.block.localizedName} was found in inventory") + mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) + disable() + false + } else { + true + } + } + } + private fun SafeClientEvent.swapOrMoveBestTool(blockTask: BlockTask): Boolean { - if (emptyDisable && player.allSlots.countItem(Items.DIAMOND_PICKAXE) == 0) { - MessageSendHelper.sendChatMessage("$chatName No Diamond Pickaxe was found in inventory, disable") - mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) - disable() + + if (player.allSlots.countItem(Items.DIAMOND_PICKAXE) < saveTools) { + handleRestock(blockTask, Items.DIAMOND_PICKAXE) } val slotFrom = getBestTool(blockTask) @@ -1337,6 +1535,75 @@ internal object HighwayTools : Module( } } + private fun SafeClientEvent.handleRestock(blockTask: BlockTask, item: Item) { + if (pendingTasks.filter { + it.value.isShulker + }.isEmpty()) { + nextShulker = getShulkerWith(item) + if (nextShulker != null) { + val shulkerItem = nextShulker!!.stack.item + + nextShulkerID = shulkerItem.id + + getRemotePos()?.let { pos -> + addTaskToPending(pos, TaskState.PLACE, shulkerItem.block, item = item) + pendingTasks[pos]?.let { + it.isShulker = true + } + blockTask.updateState(TaskState.BREAK) + } + } else { + MessageSendHelper.sendChatMessage("$chatName No shulker box with pickaxe was found in inventory.") + mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1f, 1f)) + disable() + if (enableAntiAFK) { + MessageSendHelper.sendChatMessage("$chatName Going into AFK mode.") + AntiAFK.enable() + } + } + } + } + + private fun SafeClientEvent.getRemotePos(): BlockPos? { + val eyePos = player.getPositionEyes(1f) + + return VectorUtils.getBlockPosInSphere(eyePos, maxReach).asSequence() + .filter { pos -> + !isInsideBlueprintBuild(pos) && + pos != currentBlockPos && + world.isPlaceable(pos) && + !world.getBlockState(pos.down()).isReplaceable && + world.isAirBlock(pos.up()) && + world.rayTraceBlocks(eyePos, pos.toVec3dCenter())?.let { it.typeOfHit == RayTraceResult.Type.MISS } ?: true + } + .sortedBy { it.distanceSqToCenter(eyePos.x, eyePos.y, eyePos.z) } + .firstOrNull() + } + + private fun SafeClientEvent.getShulkerWith(item: Item): Slot? { + return player.allSlots.filter { + it.stack.item is ItemShulkerBox && getShulkerData(it.stack, item) > 0 + }.minByOrNull { + getShulkerData(it.stack, item) + } + } + + @JvmStatic + fun getShulkerData(stack: ItemStack, item: Item): Int { + val tagCompound = if (stack.item is ItemShulkerBox) stack.tagCompound else return 0 + + if (tagCompound != null && tagCompound.hasKey("BlockEntityTag", 10)) { + val blockEntityTag = tagCompound.getCompoundTag("BlockEntityTag") + if (blockEntityTag.hasKey("Items", 9)) { + val shulkerInventory = NonNullList.withSize(27, ItemStack.EMPTY) + ItemStackHelper.loadAllItems(blockEntityTag, shulkerInventory) + return shulkerInventory.count { it.item == item } + } + } + + return 0 + } + private fun SafeClientEvent.handleLiquid(blockTask: BlockTask): Boolean { var foundLiquid = false @@ -1487,7 +1754,6 @@ internal object HighwayTools : Module( } } - /* Dispatches a thread to mine any non-netherrack blocks generically */ private fun mineBlockNormal(blockTask: BlockTask, side: EnumFacing) { if (blockTask.taskState == TaskState.BREAK) { blockTask.updateState(TaskState.BREAKING) @@ -1550,7 +1816,9 @@ internal object HighwayTools : Module( if (showEstimations) gatherEstimations(displayText, runtimeSec, distanceDone) -// displayText.addLine("by Constructor#9948 aka Avanatiker", primaryColor, size=8) + displayText.add(KamiMod.VERSION_SIMPLE, secondaryColor, scale = 0.8f) + + displayText.addLine("by Constructor#9948 aka Avanatiker", primaryColor, scale = 0.7f) if (printDebug) { displayText.addLine("Pending", primaryColor) @@ -1581,20 +1849,19 @@ internal object HighwayTools : Module( displayText.addLine("%,d".format(totalBlocksPlaced) + " / " + "%,d".format(totalBlocksBroken), secondaryColor) - } private fun SafeClientEvent.gatherLifeTime(displayText: TextComponent) { - val matPlaced = StatList.getObjectUseStats(material.item)?.let { + matPlaced = StatList.getObjectUseStats(material.item)?.let { player.statFileWriter.readStat(it) } ?: 0 - val enderMined = StatList.getBlockStats(Blocks.ENDER_CHEST)?.let { + enderMined = StatList.getBlockStats(Blocks.ENDER_CHEST)?.let { player.statFileWriter.readStat(it) } ?: 0 - val netherrackMined = StatList.getBlockStats(Blocks.NETHERRACK)?.let { + netherrackMined = StatList.getBlockStats(Blocks.NETHERRACK)?.let { player.statFileWriter.readStat(it) } ?: 0 - val pickaxeBroken = StatList.getObjectBreakStats(Items.DIAMOND_PICKAXE)?.let { + pickaxeBroken = StatList.getObjectBreakStats(Items.DIAMOND_PICKAXE)?.let { player.statFileWriter.readStat(it) } ?: 0 @@ -1659,6 +1926,9 @@ internal object HighwayTools : Module( } else { displayText.addLine("Place($placeDelay) Break($breakDelay)", secondaryColor) } + + displayText.add(" Movement:", primaryColor) + displayText.addLine("$moveState", secondaryColor) } private fun gatherTask(displayText: TextComponent) { @@ -1770,7 +2040,8 @@ internal object HighwayTools : Module( class BlockTask( val blockPos: BlockPos, var taskState: TaskState, - var block: Block + var block: Block, + var item: Item = Items.AIR ) { private var ranTicks = 0 var stuckTicks = 0; private set @@ -1780,6 +2051,15 @@ internal object HighwayTools : Module( var eyeDistance = 0.0; private set var hitVecDistance = 0.0; private set + var isShulker = false + var inventory = emptyList() + var isOpen = false + var isConfirmed = false + var windowID = 0 + var transactionID: Short = 0 + +// var bridge = false ToDo: Implement + fun updateState(state: TaskState) { if (state == taskState) return @@ -1842,12 +2122,21 @@ internal object HighwayTools : Module( override fun hashCode() = blockPos.hashCode() } + enum class MovementState { + RUNNING, PICKUP, BRIDGE + } + enum class TaskState(val stuckThreshold: Int, val stuckTimeout: Int, val color: ColorHolder) { DONE(69420, 0x22, ColorHolder(50, 50, 50)), BROKEN(1000, 1000, ColorHolder(111, 0, 0)), PLACED(1000, 1000, ColorHolder(53, 222, 66)), LIQUID_SOURCE(100, 100, ColorHolder(114, 27, 255)), LIQUID_FLOW(100, 100, ColorHolder(68, 27, 255)), + PICKUP(1000, 1000, ColorHolder(252, 3, 207)), + CLOSE_CONTAINER(1000, 1000, ColorHolder(252, 3, 207)), + MOVING_ITEM(1000, 1000, ColorHolder(252, 3, 207)), + MOVE_ITEM(1000, 1000, ColorHolder(252, 3, 207)), + OPEN_CONTAINER(1000, 1000, ColorHolder(252, 3, 207)), BREAKING(100, 100, ColorHolder(240, 222, 60)), BREAK(20, 20, ColorHolder(222, 0, 0)), PLACE(20, 20, ColorHolder(35, 188, 254)), From 32607659e303fb1ff0d260a237cb3c86e9e28223 Mon Sep 17 00:00:00 2001 From: Christian Date: Thu, 25 Mar 2021 22:50:45 +0100 Subject: [PATCH 377/390] Storage management works now --- .../module/modules/misc/HighwayTools.kt | 96 +++++++++---------- .../module/modules/player/InventoryManager.kt | 2 +- 2 files changed, 47 insertions(+), 51 deletions(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index 450a6f50b2..c976ef3fc1 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -31,7 +31,6 @@ import net.minecraft.util.math.RayTraceResult import net.minecraft.util.math.Vec3d import net.minecraft.world.EnumDifficulty import net.minecraftforge.fml.common.gameevent.TickEvent -import org.kamiblue.client.KamiMod import org.kamiblue.client.event.SafeClientEvent import org.kamiblue.client.event.events.PacketEvent import org.kamiblue.client.event.events.RenderWorldEvent @@ -43,6 +42,7 @@ import org.kamiblue.client.module.modules.client.Hud.secondaryColor import org.kamiblue.client.module.modules.movement.AntiHunger import org.kamiblue.client.module.modules.movement.Velocity import org.kamiblue.client.module.modules.player.InventoryManager +import org.kamiblue.client.module.modules.player.InventoryManager.eject import org.kamiblue.client.module.modules.player.LagNotifier import org.kamiblue.client.process.HighwayToolsProcess import org.kamiblue.client.process.PauseProcess @@ -130,11 +130,12 @@ internal object HighwayTools : Module( private val placementSearch by setting("Place Deep Search", 2, 1..4, 1, { page == Page.BEHAVIOR }, description = "EXPERIMENTAL: Attempts to find a support block for placing against") // storage management - private val packetInteraction by setting("Packet Interaction", false, { page == Page.STORE_MANAGEMENT }, description = "Choose to interact with container using only packets.") - private val leaveEmptyShulkers by setting("Leave Empty Shulkers", true, { page == Page.STORE_MANAGEMENT }, description = "Does not break empty shulkers.") - private val saveMaterial by setting("Save Material", 12, 0..64, 1, { page == Page.STORE_MANAGEMENT }, description = "How many material blocks are saved") - private val saveTools by setting("Save Tools", 1, 0..64, 1, { page == Page.STORE_MANAGEMENT }, description = "How many tools are saved") - private val enableAntiAFK by setting("AntiAFK", true, { page == Page.STORE_MANAGEMENT }, description = "Enables AntiAFK on empty") + private val storageManagement by setting("Manage Storage", false, { page == Page.STORAGE_MANAGEMENT }, description = "Choose to interact with container using only packets.") + private val packetInteraction by setting("Packet Interaction", false, { page == Page.STORAGE_MANAGEMENT && storageManagement }, description = "Choose to interact with container using only packets.") + private val leaveEmptyShulkers by setting("Leave Empty Shulkers", true, { page == Page.STORAGE_MANAGEMENT && storageManagement }, description = "Does not break empty shulkers.") + private val saveMaterial by setting("Save Material", 12, 0..64, 1, { page == Page.STORAGE_MANAGEMENT }, description = "How many material blocks are saved") + private val saveTools by setting("Save Tools", 1, 0..64, 1, { page == Page.STORAGE_MANAGEMENT }, description = "How many tools are saved") + private val enableAntiAFK by setting("AntiAFK", true, { page == Page.STORAGE_MANAGEMENT }, description = "Enables AntiAFK on empty") // stat settings private val anonymizeStats by setting("Anonymize", false, { page == Page.STATS }, description = "Censors all coordinates in HUD and Chat") @@ -163,7 +164,7 @@ internal object HighwayTools : Module( } private enum class Page { - BUILD, BEHAVIOR, STORE_MANAGEMENT, STATS, CONFIG + BUILD, BEHAVIOR, STORAGE_MANAGEMENT, STATS, CONFIG } @Suppress("UNUSED") @@ -416,14 +417,12 @@ internal object HighwayTools : Module( } is SPacketOpenWindow -> { if (event.packet.guiId == "minecraft:shulker_box") { - @Suppress("UNNECESSARY_SAFE_CALL") - sortedTasks.first { it.isShulker }?.let { it.isOpen = true } + sortedTasks.firstOrNull { it.isShulker }?.let { it.isOpen = true } event.cancel() } } is SPacketWindowItems -> { - @Suppress("UNNECESSARY_SAFE_CALL") - sortedTasks.first { it.isShulker }?.let { + sortedTasks.firstOrNull { it.isShulker }?.let { if (it.isOpen) { it.inventory = event.packet.itemStacks.take(27) it.windowID = event.packet.windowId @@ -432,10 +431,10 @@ internal object HighwayTools : Module( } } is SPacketConfirmTransaction -> { - @Suppress("UNNECESSARY_SAFE_CALL") - sortedTasks.first { it.isShulker }?.let { - if (it.isOpen) { // why does event.packet.wasAccepted() returns always false? - it.isConfirmed = true + sortedTasks.firstOrNull { it.isShulker }?.let { + if (it.isOpen && + event.packet.wasAccepted()) { + it.updateState(TaskState.CLOSE_CONTAINER) } } } @@ -608,10 +607,16 @@ internal object HighwayTools : Module( } private fun SafeClientEvent.addTaskClear(pos: BlockPos) { - if (world.isAirBlock(pos)) { - addTaskToDone(pos, Blocks.AIR) - } else { - addTaskToPending(pos, TaskState.BREAK, Blocks.AIR) + when { + world.isAirBlock(pos) -> { + addTaskToDone(pos, Blocks.AIR) + } + ignoreBlocks.contains(world.getBlockState(pos).block.registryName.toString()) -> { + addTaskToDone(pos, world.getBlockState(pos).block) + } + else -> { + addTaskToPending(pos, TaskState.BREAK, Blocks.AIR) + } } } @@ -842,13 +847,14 @@ internal object HighwayTools : Module( private fun SafeClientEvent.isTaskDoneOrNull(pos: BlockPos, solid: Boolean) = (pendingTasks[pos] ?: doneTasks[pos])?.let { it.taskState == TaskState.DONE && world.getBlockState(pos).block != Blocks.PORTAL - } ?: run { - if (solid) { - !world.isPlaceable(pos, true) - } else { - world.isAirBlock(pos) - } - } + } ?: false +// } ?: run { +// if (solid) { +// !world.isPlaceable(pos, true) +// } else { +// world.isAirBlock(pos) +// } +// } private fun checkTasks(pos: BlockPos): Boolean { return pendingTasks.values.all { @@ -1017,9 +1023,6 @@ internal object HighwayTools : Module( TaskState.MOVE_ITEM -> { doMoveItem(blockTask) } - TaskState.MOVING_ITEM -> { - doMovingItem(blockTask) - } TaskState.CLOSE_CONTAINER -> { doCloseContainer(blockTask) } @@ -1041,7 +1044,7 @@ internal object HighwayTools : Module( TaskState.PLACE, TaskState.LIQUID_SOURCE, TaskState.LIQUID_FLOW -> { doPlace(blockTask, updateOnly) } - TaskState.PENDING_BREAK, TaskState.PENDING_PLACE -> { + TaskState.PENDING_BREAK, TaskState.PENDING_PLACE, TaskState.PENDING_TRANSACTION -> { if (!updateOnly && debugMessages == DebugMessages.ALL) { MessageSendHelper.sendChatMessage("$chatName Currently waiting for blockState updates...") } @@ -1086,14 +1089,14 @@ internal object HighwayTools : Module( val moveSlot = blockTask.inventory.indexOfFirst { it.item == blockTask.item } - blockTask.updateState(TaskState.MOVING_ITEM) + blockTask.updateState(TaskState.PENDING_TRANSACTION) defaultScope.launch { delay(10L) - connection.sendPacket(CPacketClickWindow(blockTask.windowID, moveSlot, 0, ClickType.QUICK_MOVE, blockTask.inventory[moveSlot], ++blockTask.transactionID)) + connection.sendPacket(CPacketClickWindow(blockTask.windowID, moveSlot, 0, ClickType.QUICK_MOVE, player.inventory.itemStack, ++blockTask.transactionID)) delay(50L * taskTimeout) - if (blockTask.taskState == TaskState.MOVING_ITEM) { + if (blockTask.taskState == TaskState.PENDING_TRANSACTION) { stateUpdateMutex.withLock { blockTask.updateState(TaskState.MOVE_ITEM) } @@ -1101,12 +1104,6 @@ internal object HighwayTools : Module( } } - private fun doMovingItem(blockTask: BlockTask) { - if (blockTask.isConfirmed) { - blockTask.updateState(TaskState.CLOSE_CONTAINER) - } - } - private fun SafeClientEvent.doCloseContainer(blockTask: BlockTask) { if (leaveEmptyShulkers && @@ -1119,7 +1116,6 @@ internal object HighwayTools : Module( blockTask.isOpen = false blockTask.inventory = emptyList() - blockTask.isConfirmed = false defaultScope.launch { delay(10L) @@ -1129,6 +1125,10 @@ internal object HighwayTools : Module( private fun SafeClientEvent.doPickup(blockTask: BlockTask) { + if (player.inventorySlots.firstEmpty() == null) { + eject() + } + moveState = MovementState.PICKUP nextShulker?.let { if (getDroppedItem(nextShulkerID, 8.0f) == null) { @@ -1164,8 +1164,7 @@ internal object HighwayTools : Module( } } - if (!updateOnly) { - swapOrMoveBestTool(blockTask) + if (!updateOnly && swapOrMoveBestTool(blockTask)) { mineBlock(blockTask) } } @@ -1284,9 +1283,8 @@ internal object HighwayTools : Module( } } - if (!updateOnly && player.onGround) { + if (!updateOnly && player.onGround && swapOrMoveBestTool(blockTask)) { if (handleLiquid(blockTask)) return - swapOrMoveBestTool(blockTask) mineBlock(blockTask) } } @@ -1518,6 +1516,7 @@ internal object HighwayTools : Module( if (player.allSlots.countItem(Items.DIAMOND_PICKAXE) < saveTools) { handleRestock(blockTask, Items.DIAMOND_PICKAXE) + return false } val slotFrom = getBestTool(blockTask) @@ -1816,9 +1815,7 @@ internal object HighwayTools : Module( if (showEstimations) gatherEstimations(displayText, runtimeSec, distanceDone) - displayText.add(KamiMod.VERSION_SIMPLE, secondaryColor, scale = 0.8f) - - displayText.addLine("by Constructor#9948 aka Avanatiker", primaryColor, scale = 0.7f) + displayText.add("by Constructor#9948/Avanatiker", primaryColor, scale = 0.6f) if (printDebug) { displayText.addLine("Pending", primaryColor) @@ -2052,10 +2049,9 @@ internal object HighwayTools : Module( var hitVecDistance = 0.0; private set var isShulker = false - var inventory = emptyList() var isOpen = false - var isConfirmed = false var windowID = 0 + var inventory = emptyList() var transactionID: Short = 0 // var bridge = false ToDo: Implement @@ -2134,7 +2130,7 @@ internal object HighwayTools : Module( LIQUID_FLOW(100, 100, ColorHolder(68, 27, 255)), PICKUP(1000, 1000, ColorHolder(252, 3, 207)), CLOSE_CONTAINER(1000, 1000, ColorHolder(252, 3, 207)), - MOVING_ITEM(1000, 1000, ColorHolder(252, 3, 207)), + PENDING_TRANSACTION(1000, 1000, ColorHolder(252, 3, 207)), MOVE_ITEM(1000, 1000, ColorHolder(252, 3, 207)), OPEN_CONTAINER(1000, 1000, ColorHolder(252, 3, 207)), BREAKING(100, 100, ColorHolder(240, 222, 60)), diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/player/InventoryManager.kt b/src/main/kotlin/org/kamiblue/client/module/modules/player/InventoryManager.kt index ed1c13cc79..f577eac2d2 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/player/InventoryManager.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/player/InventoryManager.kt @@ -166,7 +166,7 @@ internal object InventoryManager : Module( moveToSlot(slotFrom, slotTo) } - private fun SafeClientEvent.eject() { + fun SafeClientEvent.eject() { getEjectSlot()?.let { throwAllInSlot(it) } From b445ee61268adffd7f1959afac3d30142eee1360 Mon Sep 17 00:00:00 2001 From: Christian Date: Sun, 28 Mar 2021 04:49:05 +0200 Subject: [PATCH 378/390] Packet based inventory task system --- .../module/modules/misc/HighwayTools.kt | 446 +++++++++++------- .../module/modules/player/InventoryManager.kt | 2 +- 2 files changed, 289 insertions(+), 159 deletions(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index c976ef3fc1..5354467d24 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -39,10 +39,11 @@ import org.kamiblue.client.module.Category import org.kamiblue.client.module.Module import org.kamiblue.client.module.modules.client.Hud.primaryColor import org.kamiblue.client.module.modules.client.Hud.secondaryColor +import org.kamiblue.client.module.modules.combat.AutoLog import org.kamiblue.client.module.modules.movement.AntiHunger import org.kamiblue.client.module.modules.movement.Velocity +import org.kamiblue.client.module.modules.player.AutoEat import org.kamiblue.client.module.modules.player.InventoryManager -import org.kamiblue.client.module.modules.player.InventoryManager.eject import org.kamiblue.client.module.modules.player.LagNotifier import org.kamiblue.client.process.HighwayToolsProcess import org.kamiblue.client.process.PauseProcess @@ -67,6 +68,9 @@ import org.kamiblue.client.util.threads.* import org.kamiblue.client.util.world.* import org.kamiblue.commons.extension.ceilToInt import org.kamiblue.commons.extension.floorToInt +import java.util.* +import kotlin.collections.ArrayDeque +import kotlin.collections.LinkedHashMap import kotlin.math.abs import kotlin.random.Random.Default.nextInt @@ -98,7 +102,7 @@ internal object HighwayTools : Module( val mode by setting("Mode", Mode.HIGHWAY, { page == Page.BUILD }, description = "Choose the structure") private val width by setting("Width", 6, 1..11, 1, { page == Page.BUILD }, description = "Sets the width of blueprint") private val height by setting("Height", 4, 1..6, 1, { page == Page.BUILD && clearSpace }, description = "Sets height of blueprint") - private val backfill by setting("Backfill", false, { page == Page.BUILD && mode == Mode.TUNNEL }, description = "Backfills tunnel") + private val backfill by setting("Backfill", false, { page == Page.BUILD && mode == Mode.TUNNEL }, description = "Fills the tunnel behind you") private val clearSpace by setting("Clear Space", true, { page == Page.BUILD && mode == Mode.HIGHWAY }, description = "Clears out the tunnel if necessary") private val cleanFloor by setting("Clean Floor", false, { page == Page.BUILD && mode == Mode.TUNNEL && !backfill }, description = "Cleans up the tunnels floor") private val cleanWalls by setting("Clean Walls", false, { page == Page.BUILD && mode == Mode.TUNNEL && !backfill }, description = "Cleans up the tunnels walls") @@ -131,11 +135,10 @@ internal object HighwayTools : Module( // storage management private val storageManagement by setting("Manage Storage", false, { page == Page.STORAGE_MANAGEMENT }, description = "Choose to interact with container using only packets.") - private val packetInteraction by setting("Packet Interaction", false, { page == Page.STORAGE_MANAGEMENT && storageManagement }, description = "Choose to interact with container using only packets.") private val leaveEmptyShulkers by setting("Leave Empty Shulkers", true, { page == Page.STORAGE_MANAGEMENT && storageManagement }, description = "Does not break empty shulkers.") private val saveMaterial by setting("Save Material", 12, 0..64, 1, { page == Page.STORAGE_MANAGEMENT }, description = "How many material blocks are saved") private val saveTools by setting("Save Tools", 1, 0..64, 1, { page == Page.STORAGE_MANAGEMENT }, description = "How many tools are saved") - private val enableAntiAFK by setting("AntiAFK", true, { page == Page.STORAGE_MANAGEMENT }, description = "Enables AntiAFK on empty") + private val disableMode by setting("Disable Mode", DisableMode.NONE, { page == Page.STORAGE_MANAGEMENT }, description = "Choose action when bot is out of materials or tools") // stat settings private val anonymizeStats by setting("Anonymize", false, { page == Page.STATS }, description = "Censors all coordinates in HUD and Chat") @@ -176,6 +179,10 @@ internal object HighwayTools : Module( FIXED, SERVER } + private enum class DisableMode { + NONE, ANTI_AFK, LOGOUT + } + private enum class DebugMessages { OFF, IMPORTANT, ALL } @@ -192,6 +199,7 @@ internal object HighwayTools : Module( fillerMatSaved.value = value.registryName.toString() } private var baritoneSettingAllowPlace = false + private var baritoneSettingAllowBreak = false private var baritoneSettingRenderGoal = false // Blue print @@ -218,16 +226,15 @@ internal object HighwayTools : Module( private val pendingTasks = LinkedHashMap() private val doneTasks = LinkedHashMap() private var sortedTasks: List = emptyList() + private val inventoryTasks: Queue = LinkedList() var lastTask: BlockTask? = null; private set + private var containerTask = BlockTask(BlockPos.ORIGIN, TaskState.DONE, Blocks.AIR, Items.AIR) + private val shulkerOpenTimer = TickTimer(TimeUnit.TICKS) + private val packetLimiterMutex = Mutex() private val packetLimiter = ArrayDeque() - // Long term inventory management - private val shulkerOpenTimer = TickTimer(TimeUnit.TICKS) - private var nextShulker: Slot? = null - private var nextShulkerID = 0 - // Stats private val simpleMovingAveragePlaces = ArrayDeque() private val simpleMovingAverageBreaks = ArrayDeque() @@ -276,13 +283,17 @@ internal object HighwayTools : Module( startingDirection = Direction.fromEntity(player) baritoneSettingAllowPlace = BaritoneUtils.settings?.allowPlace?.value ?: true + baritoneSettingAllowBreak = BaritoneUtils.settings?.allowBreak?.value ?: true BaritoneUtils.settings?.allowPlace?.value = false + BaritoneUtils.settings?.allowBreak?.value = false if (!goalRender) { baritoneSettingRenderGoal = BaritoneUtils.settings?.renderGoal?.value ?: true BaritoneUtils.settings?.renderGoal?.value = false } + pendingTasks.clear() + containerTask.updateState(TaskState.DONE) refreshData() printEnable() } ?: disable() @@ -301,7 +312,8 @@ internal object HighwayTools : Module( } BaritoneUtils.settings?.allowPlace?.value = baritoneSettingAllowPlace - if (!goalRender) BaritoneUtils.settings?.renderGoal?.value = baritoneSettingRenderGoal + BaritoneUtils.settings?.allowBreak?.value = baritoneSettingAllowBreak + BaritoneUtils.settings?.renderGoal?.value = baritoneSettingRenderGoal active = false goal = null @@ -351,6 +363,14 @@ internal object HighwayTools : Module( MessageSendHelper.sendRawChatMessage(" §9> §cYou should activate LagNotifier to make the bot stop on server lag.") } + if (AutoEat.isDisabled) { + MessageSendHelper.sendRawChatMessage(" §9> §cYou should activate AutoEat to not die on starvation.") + } + + if (AutoLog.isDisabled) { + MessageSendHelper.sendRawChatMessage(" §9> §cYou should activate AutoLog to prevent most deaths when afk.") + } + if (multiBuilding && Velocity.isDisabled) { MessageSendHelper.sendRawChatMessage(" §9> §cMake sure to enable Velocity to not get pushed from your mates.") } @@ -385,7 +405,11 @@ internal object HighwayTools : Module( val new = event.packet.getBlockState().block if (prev != new) { - val task = pendingTasks[pos] ?: return@safeListener + val task = if (pos == containerTask.blockPos) { + containerTask + } else { + pendingTasks[pos] ?: return@safeListener + } when (task.taskState) { TaskState.PENDING_BREAK, TaskState.BREAKING -> { @@ -417,24 +441,24 @@ internal object HighwayTools : Module( } is SPacketOpenWindow -> { if (event.packet.guiId == "minecraft:shulker_box") { - sortedTasks.firstOrNull { it.isShulker }?.let { it.isOpen = true } + containerTask.isOpen = true event.cancel() } } is SPacketWindowItems -> { - sortedTasks.firstOrNull { it.isShulker }?.let { - if (it.isOpen) { - it.inventory = event.packet.itemStacks.take(27) - it.windowID = event.packet.windowId - event.cancel() - } + if (containerTask.isOpen) { + containerTask.inventory = event.packet.itemStacks + containerTask.windowID = event.packet.windowId + event.cancel() } } is SPacketConfirmTransaction -> { - sortedTasks.firstOrNull { it.isShulker }?.let { - if (it.isOpen && - event.packet.wasAccepted()) { - it.updateState(TaskState.CLOSE_CONTAINER) + if (containerTask.isOpen && + event.packet.wasAccepted() && + inventoryTasks.isNotEmpty()) { + inventoryTasks.peek().inventoryState = InventoryState.DONE + runBlocking { + onMainThreadSafe { playerController.updateController() } } } } @@ -492,6 +516,8 @@ internal object HighwayTools : Module( // renderer.add(world.getBlockState(currentBlockPos).getSelectedBoundingBox(world, currentBlockPos), ColorHolder(255, 255, 255)) + if (containerTask.taskState != TaskState.DONE) renderer.add(world.getBlockState(containerTask.blockPos).getSelectedBoundingBox(world, containerTask.blockPos), containerTask.taskState.color) + pendingTasks.values.forEach { if (it.taskState == TaskState.DONE) return@forEach renderer.add(world.getBlockState(it.blockPos).getSelectedBoundingBox(world, it.blockPos), it.taskState.color) @@ -557,10 +583,10 @@ internal object HighwayTools : Module( } private fun SafeClientEvent.refreshData(originPos: BlockPos = currentBlockPos) { -// pendingTasks.values.removeAll { !it.isShulker } moveState = MovementState.RUNNING - pendingTasks.clear() +// pendingTasks.clear() doneTasks.clear() + inventoryTasks.clear() lastTask = null blueprint.clear() @@ -788,8 +814,8 @@ internal object HighwayTools : Module( } } - private fun addTaskToPending(blockPos: BlockPos, taskState: TaskState, material: Block, item: Item = Items.AIR) { - pendingTasks[blockPos] = (BlockTask(blockPos, taskState, material, item = item)) + private fun addTaskToPending(blockPos: BlockPos, taskState: TaskState, material: Block) { + pendingTasks[blockPos] = (BlockTask(blockPos, taskState, material)) } private fun addTaskToDone(blockPos: BlockPos, material: Block) { @@ -808,13 +834,11 @@ internal object HighwayTools : Module( goal = GoalNear(nextPos, 0) } MovementState.PICKUP -> { - nextShulker?.let { - val droppedItemPos = getDroppedItem(nextShulkerID, 8.0f) - goal = if (droppedItemPos != null) { - GoalNear(droppedItemPos, 0) - } else { - null - } + val droppedItemPos = getDroppedItem(containerTask.itemID, 8.0f) + goal = if (droppedItemPos != null) { + GoalNear(droppedItemPos, 0) + } else { + null } } MovementState.BRIDGE -> { @@ -828,14 +852,14 @@ internal object HighwayTools : Module( val possiblePos = currentBlockPos.add(startingDirection.directionVec) - if (!isTaskDoneOrNull(possiblePos, false) || - !isTaskDoneOrNull(possiblePos.up(), false) || - !isTaskDoneOrNull(possiblePos.down(), true)) return nextPos + if (!isTaskDone(possiblePos) || + !isTaskDone(possiblePos.up()) || + !isTaskDone(possiblePos.down())) return nextPos if (checkTasks(possiblePos.up())) nextPos = possiblePos if (currentBlockPos != nextPos) { - for (x in 1..currentBlockPos.distanceTo(nextPos).toInt()) { + for (x in 0..currentBlockPos.distanceTo(nextPos).toInt()) { simpleMovingAverageDistance.add(System.currentTimeMillis()) } refreshData() @@ -844,17 +868,10 @@ internal object HighwayTools : Module( return nextPos } - private fun SafeClientEvent.isTaskDoneOrNull(pos: BlockPos, solid: Boolean) = + private fun SafeClientEvent.isTaskDone(pos: BlockPos) = (pendingTasks[pos] ?: doneTasks[pos])?.let { it.taskState == TaskState.DONE && world.getBlockState(pos).block != Blocks.PORTAL } ?: false -// } ?: run { -// if (solid) { -// !world.isPlaceable(pos, true) -// } else { -// world.isAirBlock(pos) -// } -// } private fun checkTasks(pos: BlockPos): Boolean { return pendingTasks.values.all { @@ -863,30 +880,36 @@ internal object HighwayTools : Module( } private fun SafeClientEvent.runTasks() { - if (pendingTasks.isEmpty()) { - if (checkDoneTasks()) doneTasks.clear() - refreshData() - } else { - waitTicks-- - - pendingTasks.values.toList().forEach { - doTask(it, true) + when { + pendingTasks.isEmpty() -> { + if (checkDoneTasks()) doneTasks.clear() + refreshData() + } + containerTask.taskState != TaskState.DONE -> { + doTask(containerTask, false) } + else -> { + waitTicks-- + + pendingTasks.values.toList().forEach { + doTask(it, true) + } - sortTasks() + sortTasks() - for (task in sortedTasks) { - if (!checkStuckTimeout(task)) return - if (task.taskState != TaskState.DONE && waitTicks > 0) return + for (task in sortedTasks) { + if (!checkStuckTimeout(task)) return + if (task.taskState != TaskState.DONE && waitTicks > 0) return - doTask(task, false) + doTask(task, false) - when (task.taskState) { - TaskState.DONE, TaskState.BROKEN, TaskState.PLACED -> { - continue - } - else -> { - break + when (task.taskState) { + TaskState.DONE, TaskState.BROKEN, TaskState.PLACED -> { + continue + } + else -> { + break + } } } } @@ -919,11 +942,7 @@ internal object HighwayTools : Module( stateUpdateMutex.withLock { sortedTasks = pendingTasks.values.sortedWith( compareBy { - if (it.isShulker) { - -69420 - } else { - it.taskState.ordinal - } + it.taskState.ordinal }.thenBy { it.stuckTicks }.thenBy { @@ -943,11 +962,7 @@ internal object HighwayTools : Module( stateUpdateMutex.withLock { sortedTasks = pendingTasks.values.sortedWith( compareBy { - if (it.isShulker) { - -69420 - } else { - it.taskState.ordinal - } + it.taskState.ordinal }.thenBy { it.stuckTicks }.thenByDescending { @@ -989,11 +1004,14 @@ internal object HighwayTools : Module( TaskState.PLACE -> { if (dynamicDelay && extraPlaceDelay < 10) extraPlaceDelay += 1 - playerController.windowClick(player.openContainer.windowId, player.inventory.currentItem, 0, ClickType.PICKUP, player) - playerController.updateController() + // ToDo: get slot of material +// getBestTool(blockTask)?.let { +// clickSlot(0, it.slotIndex, 0, ClickType.PICKUP) +// playerController.updateController() +// } } TaskState.BREAK -> { - playerController.windowClick(player.openContainer.windowId, player.inventory.currentItem, 0, ClickType.PICKUP, player) + clickSlot(0, player.inventory.currentItem, 0, ClickType.PICKUP) playerController.updateController() } else -> { @@ -1017,18 +1035,18 @@ internal object HighwayTools : Module( TaskState.DONE -> { doDone(blockTask) } - TaskState.OPEN_CONTAINER -> { - doOpenContainer(blockTask) - } - TaskState.MOVE_ITEM -> { - doMoveItem(blockTask) + TaskState.PENDING_RESTOCK -> { + doPendingRestock(blockTask) } - TaskState.CLOSE_CONTAINER -> { - doCloseContainer(blockTask) + TaskState.RESTOCK -> { + doRestock(blockTask) } TaskState.PICKUP -> { doPickup(blockTask) } + TaskState.OPEN_CONTAINER -> { + doOpenContainer(blockTask) + } TaskState.BREAKING -> { doBreaking(blockTask, updateOnly) } @@ -1044,15 +1062,19 @@ internal object HighwayTools : Module( TaskState.PLACE, TaskState.LIQUID_SOURCE, TaskState.LIQUID_FLOW -> { doPlace(blockTask, updateOnly) } - TaskState.PENDING_BREAK, TaskState.PENDING_PLACE, TaskState.PENDING_TRANSACTION -> { - if (!updateOnly && debugMessages == DebugMessages.ALL) { - MessageSendHelper.sendChatMessage("$chatName Currently waiting for blockState updates...") - } + TaskState.PENDING_BREAK, TaskState.PENDING_PLACE -> { +// if (!updateOnly && debugMessages == DebugMessages.ALL) { +// MessageSendHelper.sendChatMessage("$chatName Currently waiting for blockState updates...") +// } blockTask.onStuck() } } } + private fun addInventoryTask(packet: CPacketClickWindow) { + inventoryTasks.add(InventoryTask(packet, InventoryState.TRANSACTION)) + } + private fun doDone(blockTask: BlockTask) { pendingTasks.remove(blockTask.blockPos) doneTasks[blockTask.blockPos] = blockTask @@ -1060,8 +1082,8 @@ internal object HighwayTools : Module( private fun SafeClientEvent.doOpenContainer(blockTask: BlockTask) { - if (blockTask.isOpen && blockTask.inventory.isNotEmpty()) { - blockTask.updateState(TaskState.MOVE_ITEM) + if (blockTask.isOpen && blockTask.inventory.take(27).isNotEmpty()) { + blockTask.updateState(TaskState.RESTOCK) } else { val center = blockTask.blockPos.toVec3dCenter() val diff = player.getPositionEyes(1f).subtract(center) @@ -1085,56 +1107,115 @@ internal object HighwayTools : Module( } } - private fun SafeClientEvent.doMoveItem(blockTask: BlockTask) { + private fun SafeClientEvent.doPendingRestock(blockTask: BlockTask) { + if (inventoryTasks.isEmpty()) { + connection.sendPacket(CPacketCloseWindow(blockTask.windowID)) - val moveSlot = blockTask.inventory.indexOfFirst { it.item == blockTask.item } + if (leaveEmptyShulkers && + blockTask.inventory.take(27).filter { it.item != Items.AIR && !InventoryManager.ejectList.contains(it.item.registryName.toString()) }.size < 2) { + if (debugMessages != DebugMessages.OFF) MessageSendHelper.sendChatMessage("$chatName Left empty ${blockTask.block.localizedName}@(${blockTask.blockPos.asString()})") + blockTask.updateState(TaskState.DONE) + } else { + blockTask.updateState(TaskState.BREAK) + } - blockTask.updateState(TaskState.PENDING_TRANSACTION) + blockTask.isOpen = false + blockTask.inventory = emptyList() + } else { + val inventoryTask = inventoryTasks.peek() - defaultScope.launch { - delay(10L) - connection.sendPacket(CPacketClickWindow(blockTask.windowID, moveSlot, 0, ClickType.QUICK_MOVE, player.inventory.itemStack, ++blockTask.transactionID)) + when (inventoryTask.inventoryState) { + InventoryState.TRANSACTION -> { + inventoryTask.inventoryState = InventoryState.PENDING_TRANSACTION - delay(50L * taskTimeout) - if (blockTask.taskState == TaskState.PENDING_TRANSACTION) { - stateUpdateMutex.withLock { - blockTask.updateState(TaskState.MOVE_ITEM) + defaultScope.launch { + delay(10L) + connection.sendPacket(inventoryTask.packet) + + delay(50L * taskTimeout) + if (inventoryTask.inventoryState == InventoryState.PENDING_TRANSACTION) { + if (debugMessages == DebugMessages.ALL) MessageSendHelper.sendChatMessage("$chatName Inventory task $inventoryTask timed out") + inventoryTask.inventoryState = InventoryState.TRANSACTION + } + } + } + InventoryState.PENDING_TRANSACTION -> { + blockTask.onStuck() + } + InventoryState.DONE -> { + inventoryTasks.poll() } } } } - private fun SafeClientEvent.doCloseContainer(blockTask: BlockTask) { + private fun SafeClientEvent.doRestock(blockTask: BlockTask) { + val moveSlot = blockTask.inventory.take(27).indexOfFirst { it.item == blockTask.item } - if (leaveEmptyShulkers && - blockTask.inventory.none { it.item != Items.AIR }) { - if (debugMessages == DebugMessages.IMPORTANT) MessageSendHelper.sendChatMessage("$chatName Left empty ${blockTask.block.localizedName}@(${blockTask.blockPos.asString()})") - blockTask.updateState(TaskState.DONE) - } else { - blockTask.updateState(TaskState.BREAK) - } + var slot = getFreeSlot(blockTask.inventory.takeLast(9)) - blockTask.isOpen = false - blockTask.inventory = emptyList() + if (slot != -1) { + addInventoryTask(CPacketClickWindow(blockTask.windowID, moveSlot, slot, ClickType.SWAP, player.inventory.itemStack, ++blockTask.transactionID)) + } else { + slot = getFreeSlot(blockTask.inventory.drop(27)) - defaultScope.launch { - delay(10L) - connection.sendPacket(CPacketCloseWindow(blockTask.windowID)) + if (slot != -1) { + addInventoryTask(CPacketClickWindow(blockTask.windowID, moveSlot, 0, ClickType.PICKUP, blockTask.inventory[moveSlot], ++blockTask.transactionID)) + addInventoryTask(CPacketClickWindow(blockTask.windowID, slot, 0, ClickType.PICKUP, blockTask.inventory[slot], ++blockTask.transactionID)) + } else { + MessageSendHelper.sendChatMessage("$chatName You have no inventory space left") + disable() + } } - } - - private fun SafeClientEvent.doPickup(blockTask: BlockTask) { - if (player.inventorySlots.firstEmpty() == null) { - eject() + if (debugMessages == DebugMessages.ALL) { + inventoryTasks.forEach { + MessageSendHelper.sendChatMessage("$chatName $it ${it.inventoryState}") + } } moveState = MovementState.PICKUP - nextShulker?.let { - if (getDroppedItem(nextShulkerID, 8.0f) == null) { + blockTask.updateState(TaskState.PENDING_RESTOCK) + } + + private fun SafeClientEvent.doPickup(blockTask: BlockTask) { + if (eject()) { + if (getDroppedItem(containerTask.itemID, 8.0f) == null) { moveState = MovementState.RUNNING blockTask.updateState(TaskState.DONE) } +// } else { +// blockTask.onStuck() +// } + } + } + + private fun SafeClientEvent.eject(): Boolean { + return if (player.inventorySlots.firstEmpty() == null) { + getEjectSlot()?.let { + throwAllInSlot(it) + } + false + } else { +// player.inventorySlots.firstEmpty()?.let { +// clickSlot(0, it.slotIndex, 0, ClickType.PICKUP) +// playerController.updateController() +// } + true + } + } + + private fun SafeClientEvent.getEjectSlot(): Slot? { + return player.inventorySlots.firstByStack { + !it.isEmpty && + InventoryManager.ejectList.contains(it.item.registryName.toString()) + } + } + + private fun getFreeSlot(inventory: List): Int { + return inventory.indexOfFirst { + it.isEmpty || + InventoryManager.ejectList.contains(it.item.registryName.toString()) } } @@ -1341,6 +1422,11 @@ internal object HighwayTools : Module( return } } +// is BlockShulkerBox -> { +// if (currentBlock == blockTask.block) { +// blockTask.updateState(TaskState.OPEN_CONTAINER) +// } +// } } if (!updateOnly) { @@ -1352,7 +1438,12 @@ internal object HighwayTools : Module( MessageSendHelper.sendChatMessage("$chatName Invalid place position. Removing task") } } - pendingTasks.remove(blockTask.blockPos) + + if (blockTask == containerTask) { + containerTask.updateState(TaskState.BREAK) + } else { + pendingTasks.remove(blockTask.blockPos) + } return } @@ -1470,7 +1561,8 @@ internal object HighwayTools : Module( private fun SafeClientEvent.swapOrMoveBlock(blockTask: BlockTask): Boolean { if (blockTask.isShulker) { - nextShulker?.let { slot -> + getShulkerWith(blockTask.item)?.let { slot -> + blockTask.itemID = slot.stack.item.id slot.toHotbarSlotOrNull()?.let { swapToSlot(it) } ?: run { @@ -1483,9 +1575,9 @@ internal object HighwayTools : Module( if (mode != Mode.TUNNEL && player.allSlots.countBlock(material) < saveMaterial) { if (player.allSlots.countItem(Items.DIAMOND_PICKAXE) >= saveTools) { - handleRestock(blockTask, material.item) + handleRestock(material.item) } else { - handleRestock(blockTask, Items.DIAMOND_PICKAXE) + handleRestock(Items.DIAMOND_PICKAXE) } return false } @@ -1515,7 +1607,7 @@ internal object HighwayTools : Module( private fun SafeClientEvent.swapOrMoveBestTool(blockTask: BlockTask): Boolean { if (player.allSlots.countItem(Items.DIAMOND_PICKAXE) < saveTools) { - handleRestock(blockTask, Items.DIAMOND_PICKAXE) + handleRestock(Items.DIAMOND_PICKAXE) return false } @@ -1534,32 +1626,47 @@ internal object HighwayTools : Module( } } - private fun SafeClientEvent.handleRestock(blockTask: BlockTask, item: Item) { - if (pendingTasks.filter { - it.value.isShulker - }.isEmpty()) { - nextShulker = getShulkerWith(item) - if (nextShulker != null) { - val shulkerItem = nextShulker!!.stack.item - - nextShulkerID = shulkerItem.id - - getRemotePos()?.let { pos -> - addTaskToPending(pos, TaskState.PLACE, shulkerItem.block, item = item) - pendingTasks[pos]?.let { - it.isShulker = true + private fun SafeClientEvent.handleRestock(item: Item) { + when (containerTask.taskState) { + TaskState.DONE -> { + getShulkerWith(item)?.let { slot -> + getRemotePos()?.let { pos -> + containerTask = BlockTask(pos, TaskState.PLACE, slot.stack.item.block, item) + containerTask.isShulker = true + } ?: run { + MessageSendHelper.sendChatMessage("$chatName Cant find possible container position.") + mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1f, 1f)) + disable() + } + } ?: run { + MessageSendHelper.sendChatMessage("$chatName No shulker box with ${item.registryName} was found in inventory.") + mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1f, 1f)) + disable() + when (disableMode) { + DisableMode.ANTI_AFK -> { + MessageSendHelper.sendChatMessage("$chatName Going into AFK mode.") + AntiAFK.enable() + } + DisableMode.LOGOUT -> { + MessageSendHelper.sendChatMessage("$chatName CAUTION: Logging of in X Minutes.") + } + DisableMode.NONE -> { + // Nothing + } } - blockTask.updateState(TaskState.BREAK) } - } else { - MessageSendHelper.sendChatMessage("$chatName No shulker box with pickaxe was found in inventory.") - mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1f, 1f)) - disable() - if (enableAntiAFK) { - MessageSendHelper.sendChatMessage("$chatName Going into AFK mode.") - AntiAFK.enable() + } + TaskState.BREAK -> { + if (containerTask.restockTries > 10) { + containerTask.updateState(TaskState.OPEN_CONTAINER) + containerTask.restockTries = 0 + } else { + containerTask.restockTries++ } } + else -> { + // Hmm + } } } @@ -1815,15 +1922,22 @@ internal object HighwayTools : Module( if (showEstimations) gatherEstimations(displayText, runtimeSec, distanceDone) - displayText.add("by Constructor#9948/Avanatiker", primaryColor, scale = 0.6f) - if (printDebug) { - displayText.addLine("Pending", primaryColor) - addTaskComponentList(displayText, sortedTasks) + displayText.addLine("Container", primaryColor, scale = 0.6f) + displayText.addLine(" $containerTask", scale = 0.6f) - displayText.addLine("Done", primaryColor) - addTaskComponentList(displayText, doneTasks.values) + if (sortedTasks.isNotEmpty()) { + displayText.addLine("Pending", primaryColor, scale = 0.6f) + addTaskComponentList(displayText, sortedTasks) + } + + if (sortedTasks.isNotEmpty()) { + displayText.addLine("Done", primaryColor, scale = 0.6f) + addTaskComponentList(displayText, doneTasks.values) + } } + + displayText.addLine("by Constructor#9948/Avanatiker", primaryColor, scale = 0.6f) } private fun gatherSession(displayText: TextComponent, runtimeSec: Double) { @@ -2030,10 +2144,25 @@ internal object HighwayTools : Module( private fun addTaskComponentList(displayText: TextComponent, tasks: Collection) { tasks.forEach { - displayText.addLine(" ${it.block.localizedName}@(${it.blockPos.asString()}) State: ${it.taskState} Timings: (Threshold: ${it.taskState.stuckThreshold} Timeout: ${it.taskState.stuckTimeout}) Priority: ${it.taskState.ordinal} Stuck: ${it.stuckTicks}") + displayText.addLine(" ${it.block.localizedName}@(${it.blockPos.asString()}) State: ${it.taskState} Timings: (Threshold: ${it.taskState.stuckThreshold} Timeout: ${it.taskState.stuckTimeout}) Priority: ${it.taskState.ordinal} Stuck: ${it.stuckTicks}", primaryColor, scale = 0.6f) } } + class InventoryTask( + val packet: CPacketClickWindow, + var inventoryState: InventoryState + ) { + override fun toString(): String { + return "windowId: ${packet.windowId} slotId: ${packet.slotId} usedButton: ${packet.usedButton} clickType: ${packet.clickType} clickedItem: ${packet.clickedItem.displayName} actionNumber: ${packet.actionNumber}" + } + } + + enum class InventoryState { + DONE, + TRANSACTION, + PENDING_TRANSACTION + } + class BlockTask( val blockPos: BlockPos, var taskState: TaskState, @@ -2051,10 +2180,12 @@ internal object HighwayTools : Module( var isShulker = false var isOpen = false var windowID = 0 + var itemID = 0 var inventory = emptyList() var transactionID: Short = 0 + var restockTries = 0 -// var bridge = false ToDo: Implement +// var isBridge = false ToDo: Implement fun updateState(state: TaskState) { if (state == taskState) return @@ -2129,9 +2260,8 @@ internal object HighwayTools : Module( LIQUID_SOURCE(100, 100, ColorHolder(114, 27, 255)), LIQUID_FLOW(100, 100, ColorHolder(68, 27, 255)), PICKUP(1000, 1000, ColorHolder(252, 3, 207)), - CLOSE_CONTAINER(1000, 1000, ColorHolder(252, 3, 207)), - PENDING_TRANSACTION(1000, 1000, ColorHolder(252, 3, 207)), - MOVE_ITEM(1000, 1000, ColorHolder(252, 3, 207)), + PENDING_RESTOCK(1000, 1000, ColorHolder(252, 3, 207)), + RESTOCK(1000, 1000, ColorHolder(252, 3, 207)), OPEN_CONTAINER(1000, 1000, ColorHolder(252, 3, 207)), BREAKING(100, 100, ColorHolder(240, 222, 60)), BREAK(20, 20, ColorHolder(222, 0, 0)), diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/player/InventoryManager.kt b/src/main/kotlin/org/kamiblue/client/module/modules/player/InventoryManager.kt index f577eac2d2..ed1c13cc79 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/player/InventoryManager.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/player/InventoryManager.kt @@ -166,7 +166,7 @@ internal object InventoryManager : Module( moveToSlot(slotFrom, slotTo) } - fun SafeClientEvent.eject() { + private fun SafeClientEvent.eject() { getEjectSlot()?.let { throwAllInSlot(it) } From 6c0aa374838acb34aa7c3eb77ab30a11aa0733c7 Mon Sep 17 00:00:00 2001 From: Christian Date: Sun, 28 Mar 2021 19:32:18 +0200 Subject: [PATCH 379/390] A lot of fixes --- .../module/modules/misc/HighwayTools.kt | 485 ++++++++++-------- 1 file changed, 258 insertions(+), 227 deletions(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index 5354467d24..3928839237 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -8,6 +8,7 @@ import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock import net.minecraft.block.Block import net.minecraft.block.BlockLiquid +import net.minecraft.block.BlockShulkerBox import net.minecraft.client.audio.PositionedSoundRecord import net.minecraft.enchantment.EnchantmentHelper import net.minecraft.init.Blocks @@ -51,6 +52,7 @@ import org.kamiblue.client.setting.settings.impl.collection.CollectionSetting import org.kamiblue.client.util.* import org.kamiblue.client.util.EntityUtils.flooredPosition import org.kamiblue.client.util.EntityUtils.getDroppedItem +import org.kamiblue.client.util.EntityUtils.getDroppedItems import org.kamiblue.client.util.color.ColorHolder import org.kamiblue.client.util.graphics.ESPRenderer import org.kamiblue.client.util.graphics.font.TextComponent @@ -61,6 +63,7 @@ import org.kamiblue.client.util.math.RotationUtils.getRotationTo import org.kamiblue.client.util.math.VectorUtils import org.kamiblue.client.util.math.VectorUtils.distanceTo import org.kamiblue.client.util.math.VectorUtils.multiply +import org.kamiblue.client.util.math.VectorUtils.toBlockPos import org.kamiblue.client.util.math.VectorUtils.toVec3dCenter import org.kamiblue.client.util.math.isInSight import org.kamiblue.client.util.text.MessageSendHelper @@ -453,12 +456,20 @@ internal object HighwayTools : Module( } } is SPacketConfirmTransaction -> { - if (containerTask.isOpen && - event.packet.wasAccepted() && - inventoryTasks.isNotEmpty()) { - inventoryTasks.peek().inventoryState = InventoryState.DONE - runBlocking { - onMainThreadSafe { playerController.updateController() } + if (containerTask.isOpen && inventoryTasks.isNotEmpty()) { + if (event.packet.wasAccepted()) { + inventoryTasks.peek()?.let { + it.inventoryState = InventoryState.DONE + runBlocking { + onMainThreadSafe { playerController.updateController() } + } + } + } else { + inventoryTasks.peek()?.let { + if (debugMessages == DebugMessages.ALL) MessageSendHelper.sendChatMessage("$chatName InventoryTask: $it was not accepted.") + inventoryTasks.clear() + containerTask.updateState(TaskState.BREAK) + } } } } @@ -834,7 +845,7 @@ internal object HighwayTools : Module( goal = GoalNear(nextPos, 0) } MovementState.PICKUP -> { - val droppedItemPos = getDroppedItem(containerTask.itemID, 8.0f) + val droppedItemPos = getCollectingPosition() goal = if (droppedItemPos != null) { GoalNear(droppedItemPos, 0) } else { @@ -1004,15 +1015,10 @@ internal object HighwayTools : Module( TaskState.PLACE -> { if (dynamicDelay && extraPlaceDelay < 10) extraPlaceDelay += 1 - // ToDo: get slot of material -// getBestTool(blockTask)?.let { -// clickSlot(0, it.slotIndex, 0, ClickType.PICKUP) -// playerController.updateController() -// } + updateCurrentSlot() } TaskState.BREAK -> { - clickSlot(0, player.inventory.currentItem, 0, ClickType.PICKUP) - playerController.updateController() + updateCurrentSlot() } else -> { // Nothing @@ -1113,7 +1119,15 @@ internal object HighwayTools : Module( if (leaveEmptyShulkers && blockTask.inventory.take(27).filter { it.item != Items.AIR && !InventoryManager.ejectList.contains(it.item.registryName.toString()) }.size < 2) { - if (debugMessages != DebugMessages.OFF) MessageSendHelper.sendChatMessage("$chatName Left empty ${blockTask.block.localizedName}@(${blockTask.blockPos.asString()})") + if (debugMessages != DebugMessages.OFF) { + if (debugMessages == DebugMessages.ALL) { + if (!anonymizeStats) { + MessageSendHelper.sendChatMessage("$chatName Left empty ${blockTask.block.localizedName}@(${blockTask.blockPos.asString()})") + } else { + MessageSendHelper.sendChatMessage("$chatName Left empty ${blockTask.block.localizedName}") + } + } + } blockTask.updateState(TaskState.DONE) } else { blockTask.updateState(TaskState.BREAK) @@ -1134,7 +1148,7 @@ internal object HighwayTools : Module( delay(50L * taskTimeout) if (inventoryTask.inventoryState == InventoryState.PENDING_TRANSACTION) { - if (debugMessages == DebugMessages.ALL) MessageSendHelper.sendChatMessage("$chatName Inventory task $inventoryTask timed out") + if (debugMessages == DebugMessages.ALL) MessageSendHelper.sendChatMessage("$chatName Timed out - InventoryTask: $inventoryTask") inventoryTask.inventoryState = InventoryState.TRANSACTION } } @@ -1161,7 +1175,7 @@ internal object HighwayTools : Module( if (slot != -1) { addInventoryTask(CPacketClickWindow(blockTask.windowID, moveSlot, 0, ClickType.PICKUP, blockTask.inventory[moveSlot], ++blockTask.transactionID)) - addInventoryTask(CPacketClickWindow(blockTask.windowID, slot, 0, ClickType.PICKUP, blockTask.inventory[slot], ++blockTask.transactionID)) + addInventoryTask(CPacketClickWindow(blockTask.windowID, slot + 27, 0, ClickType.PICKUP, blockTask.inventory[slot + 27], ++blockTask.transactionID)) } else { MessageSendHelper.sendChatMessage("$chatName You have no inventory space left") disable() @@ -1170,7 +1184,7 @@ internal object HighwayTools : Module( if (debugMessages == DebugMessages.ALL) { inventoryTasks.forEach { - MessageSendHelper.sendChatMessage("$chatName $it ${it.inventoryState}") + MessageSendHelper.sendChatMessage("$chatName InventoryTask: $it State: ${it.inventoryState}") } } @@ -1180,42 +1194,12 @@ internal object HighwayTools : Module( private fun SafeClientEvent.doPickup(blockTask: BlockTask) { if (eject()) { - if (getDroppedItem(containerTask.itemID, 8.0f) == null) { + if (getCollectingPosition() == null) { moveState = MovementState.RUNNING blockTask.updateState(TaskState.DONE) + } else { + blockTask.onStuck() } -// } else { -// blockTask.onStuck() -// } - } - } - - private fun SafeClientEvent.eject(): Boolean { - return if (player.inventorySlots.firstEmpty() == null) { - getEjectSlot()?.let { - throwAllInSlot(it) - } - false - } else { -// player.inventorySlots.firstEmpty()?.let { -// clickSlot(0, it.slotIndex, 0, ClickType.PICKUP) -// playerController.updateController() -// } - true - } - } - - private fun SafeClientEvent.getEjectSlot(): Slot? { - return player.inventorySlots.firstByStack { - !it.isEmpty && - InventoryManager.ejectList.contains(it.item.registryName.toString()) - } - } - - private fun getFreeSlot(inventory: List): Int { - return inventory.indexOfFirst { - it.isEmpty || - InventoryManager.ejectList.contains(it.item.registryName.toString()) } } @@ -1422,25 +1406,24 @@ internal object HighwayTools : Module( return } } -// is BlockShulkerBox -> { -// if (currentBlock == blockTask.block) { -// blockTask.updateState(TaskState.OPEN_CONTAINER) -// } -// } } if (!updateOnly) { if (!world.isPlaceable(blockTask.blockPos)) { if (debugMessages == DebugMessages.ALL) { if (!anonymizeStats) { - MessageSendHelper.sendChatMessage("$chatName Invalid place position: ${blockTask.blockPos}. Removing task") + MessageSendHelper.sendChatMessage("$chatName Invalid place position @(${blockTask.blockPos.asString()}) Removing task") } else { MessageSendHelper.sendChatMessage("$chatName Invalid place position. Removing task") } } if (blockTask == containerTask) { - containerTask.updateState(TaskState.BREAK) + if (containerTask.block == currentBlock) { + containerTask.updateState(TaskState.BREAK) + } else { + containerTask.updateState(TaskState.DONE) + } } else { pendingTasks.remove(blockTask.blockPos) } @@ -1530,6 +1513,134 @@ internal object HighwayTools : Module( } } + private fun SafeClientEvent.mineBlock(blockTask: BlockTask) { + val blockState = world.getBlockState(blockTask.blockPos) + + if (blockState.block == Blocks.FIRE) { + val sides = getNeighbourSequence(blockTask.blockPos, 1, maxReach, true) + if (sides.isEmpty()) { + blockTask.updateState(TaskState.PLACE) + return + } + + lastHitVec = getHitVec(sides.last().pos, sides.last().side) + rotateTimer.reset() + + mineBlockNormal(blockTask, sides.last().side) + } else { + val side = getMiningSide(blockTask.blockPos) ?: run { + blockTask.onStuck() + return + } + + lastHitVec = getHitVec(blockTask.blockPos, side) + rotateTimer.reset() + + if (blockState.getPlayerRelativeBlockHardness(player, world, blockTask.blockPos) > 2.8) { + mineBlockInstant(blockTask, side) + } else { + mineBlockNormal(blockTask, side) + } + } + } + + private fun mineBlockInstant(blockTask: BlockTask, side: EnumFacing) { + waitTicks = breakDelay + blockTask.updateState(TaskState.PENDING_BREAK) + + defaultScope.launch { + packetLimiterMutex.withLock { + packetLimiter.add(System.currentTimeMillis()) + } + + delay(20L) + sendMiningPackets(blockTask.blockPos, side) + + if (maxBreaks > 1) { + tryMultiBreak(blockTask) + } + + delay(50L * taskTimeout) + if (blockTask.taskState == TaskState.PENDING_BREAK) { + stateUpdateMutex.withLock { + blockTask.updateState(TaskState.BREAK) + } + } + } + } + + private suspend fun tryMultiBreak(blockTask: BlockTask) { + runSafeSuspend { + val eyePos = player.getPositionEyes(1.0f) + val viewVec = lastHitVec.subtract(eyePos).normalize() + var breakCount = 1 + + for (task in sortedTasks) { + if (breakCount >= maxBreaks) break + + val size = packetLimiterMutex.withLock { + packetLimiter.size + } + + val limit = when (limitOrigin) { + LimitMode.FIXED -> 20.0f + LimitMode.SERVER -> TpsCalculator.tickRate + } + + if (size > limit * limitFactor) { + if (debugMessages == DebugMessages.ALL) { + MessageSendHelper.sendChatMessage("$chatName Dropped possible instant mine action @ TPS($limit) Actions(${size})") + } + break + } + + if (task == blockTask) continue + if (task.taskState != TaskState.BREAK) continue + if (world.getBlockState(task.blockPos).block != Blocks.NETHERRACK) continue + + val box = AxisAlignedBB(task.blockPos) + val rayTraceResult = box.isInSight(eyePos, viewVec) ?: continue + + if (handleLiquid(task)) break + + breakCount++ + packetLimiterMutex.withLock { + packetLimiter.add(System.currentTimeMillis()) + } + + defaultScope.launch { + sendMiningPackets(task.blockPos, rayTraceResult.sideHit) + + delay(50L * taskTimeout) + if (blockTask.taskState == TaskState.PENDING_BREAK) { + stateUpdateMutex.withLock { + blockTask.updateState(TaskState.BREAK) + } + } + } + } + } + } + + private fun mineBlockNormal(blockTask: BlockTask, side: EnumFacing) { + if (blockTask.taskState == TaskState.BREAK) { + blockTask.updateState(TaskState.BREAKING) + } + + defaultScope.launch { + delay(20L) + sendMiningPackets(blockTask.blockPos, side) + } + } + + private suspend fun sendMiningPackets(pos: BlockPos, side: EnumFacing) { + onMainThreadSafe { + connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, pos, side)) + connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, pos, side)) + player.swingArm(EnumHand.MAIN_HAND) + } + } + private fun SafeClientEvent.shouldBridge(): Boolean { return world.isAirBlock(currentBlockPos.add(startingDirection.directionVec).down()) && !sortedTasks.any { @@ -1558,7 +1669,6 @@ internal object HighwayTools : Module( } } - private fun SafeClientEvent.swapOrMoveBlock(blockTask: BlockTask): Boolean { if (blockTask.isShulker) { getShulkerWith(blockTask.item)?.let { slot -> @@ -1606,7 +1716,8 @@ internal object HighwayTools : Module( private fun SafeClientEvent.swapOrMoveBestTool(blockTask: BlockTask): Boolean { - if (player.allSlots.countItem(Items.DIAMOND_PICKAXE) < saveTools) { + if (player.allSlots.countItem(Items.DIAMOND_PICKAXE) < saveTools && + containerTask.taskState == TaskState.DONE) { handleRestock(Items.DIAMOND_PICKAXE) return false } @@ -1627,45 +1738,30 @@ internal object HighwayTools : Module( } private fun SafeClientEvent.handleRestock(item: Item) { - when (containerTask.taskState) { - TaskState.DONE -> { - getShulkerWith(item)?.let { slot -> - getRemotePos()?.let { pos -> - containerTask = BlockTask(pos, TaskState.PLACE, slot.stack.item.block, item) - containerTask.isShulker = true - } ?: run { - MessageSendHelper.sendChatMessage("$chatName Cant find possible container position.") - mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1f, 1f)) - disable() - } - } ?: run { - MessageSendHelper.sendChatMessage("$chatName No shulker box with ${item.registryName} was found in inventory.") - mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1f, 1f)) - disable() - when (disableMode) { - DisableMode.ANTI_AFK -> { - MessageSendHelper.sendChatMessage("$chatName Going into AFK mode.") - AntiAFK.enable() - } - DisableMode.LOGOUT -> { - MessageSendHelper.sendChatMessage("$chatName CAUTION: Logging of in X Minutes.") - } - DisableMode.NONE -> { - // Nothing - } - } - } + getShulkerWith(item)?.let { slot -> + getRemotePos()?.let { pos -> + containerTask = BlockTask(pos, TaskState.PLACE, slot.stack.item.block, item) + containerTask.isShulker = true + } ?: run { + MessageSendHelper.sendChatMessage("$chatName Cant find possible container position.") + mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1f, 1f)) + disable() } - TaskState.BREAK -> { - if (containerTask.restockTries > 10) { - containerTask.updateState(TaskState.OPEN_CONTAINER) - containerTask.restockTries = 0 - } else { - containerTask.restockTries++ + } ?: run { + MessageSendHelper.sendChatMessage("$chatName No shulker box with ${item.registryName} was found in inventory.") + mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1f, 1f)) + disable() + when (disableMode) { + DisableMode.ANTI_AFK -> { + MessageSendHelper.sendChatMessage("$chatName Going into AFK mode.") + AntiAFK.enable() + } + DisableMode.LOGOUT -> { + MessageSendHelper.sendChatMessage("$chatName CAUTION: Logging of in X Minutes.") + } + DisableMode.NONE -> { + // Nothing } - } - else -> { - // Hmm } } } @@ -1682,8 +1778,13 @@ internal object HighwayTools : Module( world.isAirBlock(pos.up()) && world.rayTraceBlocks(eyePos, pos.toVec3dCenter())?.let { it.typeOfHit == RayTraceResult.Type.MISS } ?: true } - .sortedBy { it.distanceSqToCenter(eyePos.x, eyePos.y, eyePos.z) } - .firstOrNull() + .sortedWith( + compareBy { + it.distanceSqToCenter(eyePos.x, eyePos.y, eyePos.z).ceilToInt() + }.thenBy { + it.y + } + ).firstOrNull() } private fun SafeClientEvent.getShulkerWith(item: Item): Slot? { @@ -1710,6 +1811,64 @@ internal object HighwayTools : Module( return 0 } + private fun SafeClientEvent.getCollectingPosition(): BlockPos? { + getDroppedItems(containerTask.itemID, range = 8f) + .minByOrNull { player.getDistance(it) } + ?.positionVector + ?.let { itemVec -> + return VectorUtils.getBlockPosInSphere(itemVec, 5f).asSequence() + .filter { pos -> + world.isAirBlock(pos.up()) && + world.isAirBlock(pos) && + !world.isPlaceable(pos.down()) + } + .sortedWith( + compareBy { + it.distanceSqToCenter(itemVec.x, itemVec.y, itemVec.z) + }.thenBy { + it.y + } + ).firstOrNull() + } + return null + } + + private fun SafeClientEvent.eject(): Boolean { + return if (player.inventorySlots.firstEmpty() == null) { + getEjectSlot()?.let { + throwAllInSlot(it) + } + false + } else { +// player.inventorySlots.firstEmpty()?.let { +// clickSlot(0, it.slotIndex, 0, ClickType.PICKUP) +// playerController.updateController() +// } + true + } + } + + private fun SafeClientEvent.getEjectSlot(): Slot? { + return player.inventorySlots.firstByStack { + !it.isEmpty && + InventoryManager.ejectList.contains(it.item.registryName.toString()) + } + } + + private fun getFreeSlot(inventory: List): Int { + return inventory.indexOfFirst { + it.isEmpty || + InventoryManager.ejectList.contains(it.item.registryName.toString()) + } + } + + private fun SafeClientEvent.updateCurrentSlot() { + clickSlot(0, player.inventory.currentItem + 36, 0, ClickType.PICKUP) + runBlocking { + onMainThreadSafe { playerController.updateController() } + } + } + private fun SafeClientEvent.handleLiquid(blockTask: BlockTask): Boolean { var foundLiquid = false @@ -1751,134 +1910,6 @@ internal object HighwayTools : Module( return foundLiquid } - private fun SafeClientEvent.mineBlock(blockTask: BlockTask) { - val blockState = world.getBlockState(blockTask.blockPos) - - if (blockState.block == Blocks.FIRE) { - val sides = getNeighbourSequence(blockTask.blockPos, 1, maxReach, true) - if (sides.isEmpty()) { - blockTask.updateState(TaskState.PLACE) - return - } - - lastHitVec = getHitVec(sides.last().pos, sides.last().side) - rotateTimer.reset() - - mineBlockNormal(blockTask, sides.last().side) - } else { - val side = getMiningSide(blockTask.blockPos) ?: run { - blockTask.onStuck() - return - } - - lastHitVec = getHitVec(blockTask.blockPos, side) - rotateTimer.reset() - - if (blockState.getPlayerRelativeBlockHardness(player, world, blockTask.blockPos) > 2.8) { - mineBlockInstant(blockTask, side) - } else { - mineBlockNormal(blockTask, side) - } - } - } - - private fun mineBlockInstant(blockTask: BlockTask, side: EnumFacing) { - waitTicks = breakDelay - blockTask.updateState(TaskState.PENDING_BREAK) - - defaultScope.launch { - packetLimiterMutex.withLock { - packetLimiter.add(System.currentTimeMillis()) - } - - delay(20L) - sendMiningPackets(blockTask.blockPos, side) - - if (maxBreaks > 1) { - tryMultiBreak(blockTask) - } - - delay(50L * taskTimeout) - if (blockTask.taskState == TaskState.PENDING_BREAK) { - stateUpdateMutex.withLock { - blockTask.updateState(TaskState.BREAK) - } - } - } - } - - private suspend fun tryMultiBreak(blockTask: BlockTask) { - runSafeSuspend { - val eyePos = player.getPositionEyes(1.0f) - val viewVec = lastHitVec.subtract(eyePos).normalize() - var breakCount = 1 - - for (task in sortedTasks) { - if (breakCount >= maxBreaks) break - - val size = packetLimiterMutex.withLock { - packetLimiter.size - } - - val limit = when (limitOrigin) { - LimitMode.FIXED -> 20.0f - LimitMode.SERVER -> TpsCalculator.tickRate - } - - if (size > limit * limitFactor) { - if (debugMessages == DebugMessages.ALL) { - MessageSendHelper.sendChatMessage("$chatName Dropped possible instant mine action @ TPS($limit) Actions(${size})") - } - break - } - - if (task == blockTask) continue - if (task.taskState != TaskState.BREAK) continue - if (world.getBlockState(task.blockPos).block != Blocks.NETHERRACK) continue - - val box = AxisAlignedBB(task.blockPos) - val rayTraceResult = box.isInSight(eyePos, viewVec) ?: continue - - if (handleLiquid(task)) break - - breakCount++ - packetLimiterMutex.withLock { - packetLimiter.add(System.currentTimeMillis()) - } - - defaultScope.launch { - sendMiningPackets(task.blockPos, rayTraceResult.sideHit) - - delay(50L * taskTimeout) - if (blockTask.taskState == TaskState.PENDING_BREAK) { - stateUpdateMutex.withLock { - blockTask.updateState(TaskState.BREAK) - } - } - } - } - } - } - - private fun mineBlockNormal(blockTask: BlockTask, side: EnumFacing) { - if (blockTask.taskState == TaskState.BREAK) { - blockTask.updateState(TaskState.BREAKING) - } - - defaultScope.launch { - delay(20L) - sendMiningPackets(blockTask.blockPos, side) - } - } - - private suspend fun sendMiningPackets(pos: BlockPos, side: EnumFacing) { - onMainThreadSafe { - connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, pos, side)) - connection.sendPacket(CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, pos, side)) - player.swingArm(EnumHand.MAIN_HAND) - } - } - private fun isInsideBlueprint(pos: BlockPos): Boolean { return blueprint.containsKey(pos) } From de4214edd0730bbbc9fec19e17874c4d9f181496 Mon Sep 17 00:00:00 2001 From: Christian Date: Sun, 28 Mar 2021 20:04:04 +0200 Subject: [PATCH 380/390] Fix ghost items lul --- .../org/kamiblue/client/module/modules/misc/HighwayTools.kt | 4 +++- src/main/kotlin/org/kamiblue/client/util/items/Operation.kt | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index 3928839237..3a8d77df9d 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -595,7 +595,7 @@ internal object HighwayTools : Module( private fun SafeClientEvent.refreshData(originPos: BlockPos = currentBlockPos) { moveState = MovementState.RUNNING -// pendingTasks.clear() + pendingTasks.clear() doneTasks.clear() inventoryTasks.clear() lastTask = null @@ -1837,6 +1837,7 @@ internal object HighwayTools : Module( return if (player.inventorySlots.firstEmpty() == null) { getEjectSlot()?.let { throwAllInSlot(it) +// connection.sendPacket(CPacketCloseWindow(0)) } false } else { @@ -1864,6 +1865,7 @@ internal object HighwayTools : Module( private fun SafeClientEvent.updateCurrentSlot() { clickSlot(0, player.inventory.currentItem + 36, 0, ClickType.PICKUP) +// connection.sendPacket(CPacketCloseWindow(0)) runBlocking { onMainThreadSafe { playerController.updateController() } } diff --git a/src/main/kotlin/org/kamiblue/client/util/items/Operation.kt b/src/main/kotlin/org/kamiblue/client/util/items/Operation.kt index 9e032aeb1f..ef5f4765f4 100644 --- a/src/main/kotlin/org/kamiblue/client/util/items/Operation.kt +++ b/src/main/kotlin/org/kamiblue/client/util/items/Operation.kt @@ -8,6 +8,7 @@ import net.minecraft.inventory.Slot import net.minecraft.item.Item import net.minecraft.item.ItemStack import net.minecraft.network.play.client.CPacketClickWindow +import net.minecraft.network.play.client.CPacketCloseWindow import org.kamiblue.client.event.SafeClientEvent import org.kamiblue.client.util.threads.onMainThreadSafe @@ -363,6 +364,7 @@ fun SafeClientEvent.clickSlot(windowId: Int = 0, slot: Int, mouseButton: Int = 0 val itemStack = container.slotClick(slot, mouseButton, type, player) connection.sendPacket(CPacketClickWindow(windowId, slot, mouseButton, type, itemStack, transactionID)) + connection.sendPacket(CPacketCloseWindow(0)) runBlocking { onMainThreadSafe { playerController.updateController() } } From b727bb82be69682880580dc0a17510d45417b008 Mon Sep 17 00:00:00 2001 From: Christian Date: Fri, 2 Apr 2021 22:50:36 +0200 Subject: [PATCH 381/390] Wrong name format --- .../client/accessor/network/AccessorCPacketCloseWindow.java | 2 +- .../kotlin/org/kamiblue/client/mixin/extension/Network.kt | 4 ++-- .../org/kamiblue/client/module/modules/player/PacketLogger.kt | 2 +- .../org/kamiblue/client/module/modules/player/XCarry.kt | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/kamiblue/client/mixin/client/accessor/network/AccessorCPacketCloseWindow.java b/src/main/java/org/kamiblue/client/mixin/client/accessor/network/AccessorCPacketCloseWindow.java index 00e2ef7555..5b1d054cbb 100644 --- a/src/main/java/org/kamiblue/client/mixin/client/accessor/network/AccessorCPacketCloseWindow.java +++ b/src/main/java/org/kamiblue/client/mixin/client/accessor/network/AccessorCPacketCloseWindow.java @@ -8,6 +8,6 @@ public interface AccessorCPacketCloseWindow { @Accessor("windowId") - int kbGetWindowID(); + int kbGetWindowId(); } diff --git a/src/main/kotlin/org/kamiblue/client/mixin/extension/Network.kt b/src/main/kotlin/org/kamiblue/client/mixin/extension/Network.kt index c515a6bf28..48fb190cc6 100644 --- a/src/main/kotlin/org/kamiblue/client/mixin/extension/Network.kt +++ b/src/main/kotlin/org/kamiblue/client/mixin/extension/Network.kt @@ -17,8 +17,8 @@ var CPacketChatMessage.packetMessage: String (this as AccessorCPacketChatMessage).setMessage(value) } -val CPacketCloseWindow.windowID: Int - get() = (this as AccessorCPacketCloseWindow).kbGetWindowID() +val CPacketCloseWindow.windowId: Int + get() = (this as AccessorCPacketCloseWindow).kbGetWindowId() var CPacketPlayer.x: Double diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/player/PacketLogger.kt b/src/main/kotlin/org/kamiblue/client/module/modules/player/PacketLogger.kt index e92b34f35b..9382a760e7 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/player/PacketLogger.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/player/PacketLogger.kt @@ -458,7 +458,7 @@ internal object PacketLogger : Module( } is CPacketCloseWindow -> { logClient (packet) { - "windowID" to packet.windowID + "windowId" to packet.windowId } } else -> { diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/player/XCarry.kt b/src/main/kotlin/org/kamiblue/client/module/modules/player/XCarry.kt index bed505056e..550f170164 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/player/XCarry.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/player/XCarry.kt @@ -2,7 +2,7 @@ package org.kamiblue.client.module.modules.player import net.minecraft.network.play.client.CPacketCloseWindow import org.kamiblue.client.event.events.PacketEvent -import org.kamiblue.client.mixin.extension.windowID +import org.kamiblue.client.mixin.extension.windowId import org.kamiblue.client.module.Category import org.kamiblue.client.module.Module import org.kamiblue.event.listener.listener @@ -14,7 +14,7 @@ internal object XCarry : Module( ) { init { listener { - if (it.packet is CPacketCloseWindow && it.packet.windowID == 0) { + if (it.packet is CPacketCloseWindow && it.packet.windowId == 0) { it.cancel() } } From 585df128f06adbe5d3c2d69a642846b3c7497213 Mon Sep 17 00:00:00 2001 From: Christian Date: Sun, 11 Apr 2021 21:16:59 +0200 Subject: [PATCH 382/390] Limit command --- .../command/commands/HighwayToolsCommand.kt | 32 +++++++++ .../module/modules/misc/HighwayTools.kt | 68 +++++++++++++------ 2 files changed, 78 insertions(+), 22 deletions(-) diff --git a/src/main/kotlin/org/kamiblue/client/command/commands/HighwayToolsCommand.kt b/src/main/kotlin/org/kamiblue/client/command/commands/HighwayToolsCommand.kt index 28192b4ae8..a8d3dace90 100644 --- a/src/main/kotlin/org/kamiblue/client/command/commands/HighwayToolsCommand.kt +++ b/src/main/kotlin/org/kamiblue/client/command/commands/HighwayToolsCommand.kt @@ -2,6 +2,7 @@ package org.kamiblue.client.command.commands import org.kamiblue.client.command.ClientCommand import org.kamiblue.client.module.modules.misc.HighwayTools +import org.kamiblue.client.util.math.CoordinateConverter.asString import org.kamiblue.client.util.text.MessageSendHelper object HighwayToolsCommand : ClientCommand( @@ -39,6 +40,37 @@ object HighwayToolsCommand : ClientCommand( } } + literal("from", "start") { + blockPos("position") { blockPosArg -> + execute("Sets starting coordinates") { + // ToDo: Make starting position for next instance +// HighwayTools.startingPos = blockPosArg.value + } + } + } + + literal("to", "stop") { + blockPos("position") { blockPosArg -> + execute("Sets stopping coordinates and starts bot") { + if (HighwayTools.isEnabled) { + MessageSendHelper.sendChatMessage("Run this command when the bot is not running") + } else { + HighwayTools.targetBlockPos = blockPosArg.value + MessageSendHelper.sendChatMessage("Started HighwayTools with target @(${blockPosArg.value.asString()})") + HighwayTools.enable() + } + } + } + } + + literal("distance") { + int("distance") { distanceArg -> + execute("Set the target distance until the bot stops") { + HighwayTools.distancePending = distanceArg.value + } + } + } + literal("material", "mat") { block("block") { blockArg -> execute("Set a block as main material") { diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index 3a8d77df9d..6869f9ea68 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -8,7 +8,6 @@ import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock import net.minecraft.block.Block import net.minecraft.block.BlockLiquid -import net.minecraft.block.BlockShulkerBox import net.minecraft.client.audio.PositionedSoundRecord import net.minecraft.enchantment.EnchantmentHelper import net.minecraft.init.Blocks @@ -51,7 +50,6 @@ import org.kamiblue.client.process.PauseProcess import org.kamiblue.client.setting.settings.impl.collection.CollectionSetting import org.kamiblue.client.util.* import org.kamiblue.client.util.EntityUtils.flooredPosition -import org.kamiblue.client.util.EntityUtils.getDroppedItem import org.kamiblue.client.util.EntityUtils.getDroppedItems import org.kamiblue.client.util.color.ColorHolder import org.kamiblue.client.util.graphics.ESPRenderer @@ -63,7 +61,6 @@ import org.kamiblue.client.util.math.RotationUtils.getRotationTo import org.kamiblue.client.util.math.VectorUtils import org.kamiblue.client.util.math.VectorUtils.distanceTo import org.kamiblue.client.util.math.VectorUtils.multiply -import org.kamiblue.client.util.math.VectorUtils.toBlockPos import org.kamiblue.client.util.math.VectorUtils.toVec3dCenter import org.kamiblue.client.util.math.isInSight import org.kamiblue.client.util.text.MessageSendHelper @@ -209,6 +206,8 @@ internal object HighwayTools : Module( private var startingDirection = Direction.NORTH private var currentBlockPos = BlockPos(0, -1, 0) private var startingBlockPos = BlockPos(0, -1, 0) + var targetBlockPos = BlockPos(0, -1, 0) + var distancePending = 0 private val blueprint = LinkedHashMap() // State @@ -838,7 +837,15 @@ internal object HighwayTools : Module( MovementState.RUNNING -> { val nextPos = getNextPos() - if (player.flooredPosition.distanceTo(nextPos) < 2.0) { + if (currentBlockPos.distanceTo(targetBlockPos) < 2 || + (distancePending > 0 && currentBlockPos.distanceTo(startingDirection.directionVec.multiply(distancePending)) < 2)) { + MessageSendHelper.sendChatMessage("$chatName Reached target destination") + mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0f, 1.0f)) + disable() + return + } + + if (player.flooredPosition.distanceTo(nextPos) < 2) { currentBlockPos = nextPos } @@ -897,6 +904,19 @@ internal object HighwayTools : Module( refreshData() } containerTask.taskState != TaskState.DONE -> { + if (containerTask.stuckTicks > containerTask.taskState.stuckTimeout) { + when (containerTask.taskState) { + TaskState.PICKUP -> { + player.inventorySlots.firstEmpty()?.let { + updateSlot(it.slotNumber) + } + containerTask.updateState(TaskState.DONE) + } + else -> { + // Nothing + } + } + } doTask(containerTask, false) } else -> { @@ -1005,9 +1025,9 @@ internal object HighwayTools : Module( else -> { if (debugMessages != DebugMessages.OFF) { if (!anonymizeStats) { - MessageSendHelper.sendChatMessage("$chatName Stuck while ${blockTask.taskState}@(${blockTask.blockPos.asString()}) for more then $timeout ticks (${blockTask.stuckTicks}), refreshing data.") + MessageSendHelper.sendChatMessage("$chatName Stuck while ${blockTask.taskState}@(${blockTask.blockPos.asString()}) for more than $timeout ticks (${blockTask.stuckTicks}), refreshing data.") } else { - MessageSendHelper.sendChatMessage("$chatName Stuck while ${blockTask.taskState} for more then $timeout ticks (${blockTask.stuckTicks}), refreshing data.") + MessageSendHelper.sendChatMessage("$chatName Stuck while ${blockTask.taskState} for more than $timeout ticks (${blockTask.stuckTicks}), refreshing data.") } } @@ -1015,10 +1035,10 @@ internal object HighwayTools : Module( TaskState.PLACE -> { if (dynamicDelay && extraPlaceDelay < 10) extraPlaceDelay += 1 - updateCurrentSlot() + updateSlot() } TaskState.BREAK -> { - updateCurrentSlot() + updateSlot() } else -> { // Nothing @@ -1722,9 +1742,7 @@ internal object HighwayTools : Module( return false } - val slotFrom = getBestTool(blockTask) - - return if (slotFrom != null) { + return getBestTool(blockTask)?.let { slotFrom -> slotFrom.toHotbarSlotOrNull()?.let { swapToSlot(it) } ?: run { @@ -1732,7 +1750,7 @@ internal object HighwayTools : Module( moveToHotbar(slotFrom.slotNumber, slotTo) } true - } else { + } ?: run { false } } @@ -1863,9 +1881,9 @@ internal object HighwayTools : Module( } } - private fun SafeClientEvent.updateCurrentSlot() { - clickSlot(0, player.inventory.currentItem + 36, 0, ClickType.PICKUP) -// connection.sendPacket(CPacketCloseWindow(0)) + private fun SafeClientEvent.updateSlot(slot: Int = player.inventory.currentItem + 36) { + clickSlot(0, slot, 0, ClickType.PICKUP) + connection.sendPacket(CPacketCloseWindow(0)) runBlocking { onMainThreadSafe { playerController.updateController() } } @@ -1956,8 +1974,10 @@ internal object HighwayTools : Module( if (showEstimations) gatherEstimations(displayText, runtimeSec, distanceDone) if (printDebug) { - displayText.addLine("Container", primaryColor, scale = 0.6f) - displayText.addLine(" $containerTask", scale = 0.6f) + if (containerTask.taskState != TaskState.DONE) { + displayText.addLine("Container", primaryColor, scale = 0.6f) + displayText.addLine(containerTask.prettyPrint(), primaryColor, scale = 0.6f) + } if (sortedTasks.isNotEmpty()) { displayText.addLine("Pending", primaryColor, scale = 0.6f) @@ -2177,7 +2197,7 @@ internal object HighwayTools : Module( private fun addTaskComponentList(displayText: TextComponent, tasks: Collection) { tasks.forEach { - displayText.addLine(" ${it.block.localizedName}@(${it.blockPos.asString()}) State: ${it.taskState} Timings: (Threshold: ${it.taskState.stuckThreshold} Timeout: ${it.taskState.stuckTimeout}) Priority: ${it.taskState.ordinal} Stuck: ${it.stuckTicks}", primaryColor, scale = 0.6f) + displayText.addLine(it.prettyPrint(), primaryColor, scale = 0.6f) } } @@ -2266,6 +2286,10 @@ internal object HighwayTools : Module( shuffle = nextInt(0, 1000) } + fun prettyPrint(): String { + return " ${block.localizedName}@(${blockPos.asString()}) State: $taskState Timings: (Threshold: ${taskState.stuckThreshold} Timeout: ${taskState.stuckTimeout}) Priority: ${taskState.ordinal} Stuck: $stuckTicks" + } + private fun onUpdate() { stuckTicks = 0 ranTicks = 0 @@ -2292,10 +2316,10 @@ internal object HighwayTools : Module( PLACED(1000, 1000, ColorHolder(53, 222, 66)), LIQUID_SOURCE(100, 100, ColorHolder(114, 27, 255)), LIQUID_FLOW(100, 100, ColorHolder(68, 27, 255)), - PICKUP(1000, 1000, ColorHolder(252, 3, 207)), - PENDING_RESTOCK(1000, 1000, ColorHolder(252, 3, 207)), - RESTOCK(1000, 1000, ColorHolder(252, 3, 207)), - OPEN_CONTAINER(1000, 1000, ColorHolder(252, 3, 207)), + PICKUP(500, 500, ColorHolder(252, 3, 207)), + PENDING_RESTOCK(500, 500, ColorHolder(252, 3, 207)), + RESTOCK(500, 500, ColorHolder(252, 3, 207)), + OPEN_CONTAINER(500, 500, ColorHolder(252, 3, 207)), BREAKING(100, 100, ColorHolder(240, 222, 60)), BREAK(20, 20, ColorHolder(222, 0, 0)), PLACE(20, 20, ColorHolder(35, 188, 254)), From 45fa2cca83f410159ae31d08330a1b88600319df Mon Sep 17 00:00:00 2001 From: Christian Date: Wed, 21 Apr 2021 02:48:47 +0200 Subject: [PATCH 383/390] Try to fix desyncs --- .../module/modules/misc/HighwayTools.kt | 42 +++++++++++++------ 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index 6869f9ea68..18e8814fdb 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -137,7 +137,7 @@ internal object HighwayTools : Module( private val storageManagement by setting("Manage Storage", false, { page == Page.STORAGE_MANAGEMENT }, description = "Choose to interact with container using only packets.") private val leaveEmptyShulkers by setting("Leave Empty Shulkers", true, { page == Page.STORAGE_MANAGEMENT && storageManagement }, description = "Does not break empty shulkers.") private val saveMaterial by setting("Save Material", 12, 0..64, 1, { page == Page.STORAGE_MANAGEMENT }, description = "How many material blocks are saved") - private val saveTools by setting("Save Tools", 1, 0..64, 1, { page == Page.STORAGE_MANAGEMENT }, description = "How many tools are saved") + private val saveTools by setting("Save Tools", 1, 0..36, 1, { page == Page.STORAGE_MANAGEMENT }, description = "How many tools are saved") private val disableMode by setting("Disable Mode", DisableMode.NONE, { page == Page.STORAGE_MANAGEMENT }, description = "Choose action when bot is out of materials or tools") // stat settings @@ -459,9 +459,9 @@ internal object HighwayTools : Module( if (event.packet.wasAccepted()) { inventoryTasks.peek()?.let { it.inventoryState = InventoryState.DONE - runBlocking { - onMainThreadSafe { playerController.updateController() } - } +// runBlocking { +// onMainThreadSafe { playerController.updateController() } +// } } } else { inventoryTasks.peek()?.let { @@ -1022,6 +1022,9 @@ internal object HighwayTools : Module( TaskState.PENDING_PLACE -> { blockTask.updateState(TaskState.PLACE) } + TaskState.PENDING_RESTOCK -> { + blockTask.updateState(TaskState.DONE) + } else -> { if (debugMessages != DebugMessages.OFF) { if (!anonymizeStats) { @@ -1150,6 +1153,7 @@ internal object HighwayTools : Module( } blockTask.updateState(TaskState.DONE) } else { +// waitTicks = 20 blockTask.updateState(TaskState.BREAK) } @@ -1735,14 +1739,30 @@ internal object HighwayTools : Module( } private fun SafeClientEvent.swapOrMoveBestTool(blockTask: BlockTask): Boolean { - - if (player.allSlots.countItem(Items.DIAMOND_PICKAXE) < saveTools && - containerTask.taskState == TaskState.DONE) { - handleRestock(Items.DIAMOND_PICKAXE) - return false + // ToDo: Fix controller desync +// MessageSendHelper.sendChatMessage("${player.allSlots.countItem(Items.DIAMOND_PICKAXE)}") + if (player.allSlots.countItem(Items.DIAMOND_PICKAXE) <= saveTools) { + return when { + containerTask.taskState == TaskState.DONE -> { + handleRestock(Items.DIAMOND_PICKAXE) + false + } + (containerTask.taskState == TaskState.BREAK || containerTask.taskState == TaskState.BREAKING) && + containerTask.item == Items.DIAMOND_PICKAXE -> { + containerTask.updateState(TaskState.OPEN_CONTAINER) + false + } + else -> { + swapOrMoveTool(blockTask) + } + } } - return getBestTool(blockTask)?.let { slotFrom -> + return swapOrMoveTool(blockTask) + } + + private fun SafeClientEvent.swapOrMoveTool(blockTask: BlockTask) = + getBestTool(blockTask)?.let { slotFrom -> slotFrom.toHotbarSlotOrNull()?.let { swapToSlot(it) } ?: run { @@ -1753,7 +1773,6 @@ internal object HighwayTools : Module( } ?: run { false } - } private fun SafeClientEvent.handleRestock(item: Item) { getShulkerWith(item)?.let { slot -> @@ -2236,7 +2255,6 @@ internal object HighwayTools : Module( var itemID = 0 var inventory = emptyList() var transactionID: Short = 0 - var restockTries = 0 // var isBridge = false ToDo: Implement From dd0ea4cde2f34989e0928db173dfa894f5da5d5b Mon Sep 17 00:00:00 2001 From: Christian Date: Thu, 22 Apr 2021 03:49:50 +0200 Subject: [PATCH 384/390] Built in AutoObsidian --- .../client/module/modules/misc/DiscordRPC.kt | 2 +- .../module/modules/misc/HighwayTools.kt | 108 +++++++++++------- 2 files changed, 65 insertions(+), 45 deletions(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/DiscordRPC.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/DiscordRPC.kt index 699fc1811a..7dcd843774 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/DiscordRPC.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/DiscordRPC.kt @@ -34,7 +34,7 @@ internal object DiscordRPC : Module( private val highwayMode by setting("HighwayMode", false) private val line1Left by setting("Line 1 Left", LineInfo.VERSION, { !highwayMode }) // details left private val line1Right by setting("Line 1 Right", LineInfo.USERNAME, { !highwayMode }) // details right - private val line2Left by setting("Line 2 Left", LineInfo.SERVER_IP, { !highwayMode }) // state left + private val line2Left by setting("Line 2 Left", LineInfo.DIMENSION, { !highwayMode }) // state left private val line2Right by setting("Line 2 Right", LineInfo.HEALTH, { !highwayMode }) // state right private val coordsConfirm by setting("Coords Confirm", false, { showCoordsConfirm() && !highwayMode }) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index 18e8814fdb..2c2c146042 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -138,6 +138,7 @@ internal object HighwayTools : Module( private val leaveEmptyShulkers by setting("Leave Empty Shulkers", true, { page == Page.STORAGE_MANAGEMENT && storageManagement }, description = "Does not break empty shulkers.") private val saveMaterial by setting("Save Material", 12, 0..64, 1, { page == Page.STORAGE_MANAGEMENT }, description = "How many material blocks are saved") private val saveTools by setting("Save Tools", 1, 0..36, 1, { page == Page.STORAGE_MANAGEMENT }, description = "How many tools are saved") + private val saveEnder by setting("Save Ender Chests", 1, 0..64, 1, { page == Page.STORAGE_MANAGEMENT }, description = "How many ender chests are saved") private val disableMode by setting("Disable Mode", DisableMode.NONE, { page == Page.STORAGE_MANAGEMENT }, description = "Choose action when bot is out of materials or tools") // stat settings @@ -459,9 +460,6 @@ internal object HighwayTools : Module( if (event.packet.wasAccepted()) { inventoryTasks.peek()?.let { it.inventoryState = InventoryState.DONE -// runBlocking { -// onMainThreadSafe { playerController.updateController() } -// } } } else { inventoryTasks.peek()?.let { @@ -1235,20 +1233,7 @@ internal object HighwayTools : Module( return } is BlockLiquid -> { - val filler = if (player.allSlots.countBlock(fillerMat) == 0 || isInsideBlueprintBuild(blockTask.blockPos)) { - material - } else { - fillerMat - } - - if (world.getBlockState(blockTask.blockPos).getValue(BlockLiquid.LEVEL) != 0) { - blockTask.updateState(TaskState.LIQUID_FLOW) - blockTask.updateMaterial(filler) - } else { - blockTask.updateState(TaskState.LIQUID_SOURCE) - blockTask.updateMaterial(filler) - } - + updateLiquidTask(blockTask) return } } @@ -1272,7 +1257,7 @@ internal object HighwayTools : Module( } blockTask.updateState(TaskState.DONE) } - blockTask.isShulker -> { + blockTask == containerTask -> { blockTask.updateState(TaskState.PICKUP) } else -> { @@ -1296,8 +1281,12 @@ internal object HighwayTools : Module( if (dynamicDelay && extraPlaceDelay > 0) extraPlaceDelay -= 1 - if (blockTask.isShulker) { - blockTask.updateState(TaskState.OPEN_CONTAINER) + if (blockTask == containerTask) { + if (blockTask.destroy) { + blockTask.updateState(TaskState.BREAK) + } else { + blockTask.updateState(TaskState.OPEN_CONTAINER) + } } else { blockTask.updateState(TaskState.DONE) } @@ -1359,16 +1348,8 @@ internal object HighwayTools : Module( } } is BlockLiquid -> { - val filler = if (player.allSlots.countBlock(fillerMat) == 0 || isInsideBlueprintBuild(blockTask.blockPos)) material - else fillerMat - - if (world.getBlockState(blockTask.blockPos).getValue(BlockLiquid.LEVEL) != 0) { - blockTask.updateState(TaskState.LIQUID_FLOW) - blockTask.updateMaterial(filler) - } else { - blockTask.updateState(TaskState.LIQUID_SOURCE) - blockTask.updateMaterial(filler) - } + updateLiquidTask(blockTask) + return } } @@ -1707,8 +1688,9 @@ internal object HighwayTools : Module( return true } else { if (mode != Mode.TUNNEL && + containerTask.taskState == TaskState.DONE && player.allSlots.countBlock(material) < saveMaterial) { - if (player.allSlots.countItem(Items.DIAMOND_PICKAXE) >= saveTools) { + if (player.allSlots.countItem(Items.DIAMOND_PICKAXE) > saveTools) { handleRestock(material.item) } else { handleRestock(Items.DIAMOND_PICKAXE) @@ -1740,7 +1722,6 @@ internal object HighwayTools : Module( private fun SafeClientEvent.swapOrMoveBestTool(blockTask: BlockTask): Boolean { // ToDo: Fix controller desync -// MessageSendHelper.sendChatMessage("${player.allSlots.countItem(Items.DIAMOND_PICKAXE)}") if (player.allSlots.countItem(Items.DIAMOND_PICKAXE) <= saveTools) { return when { containerTask.taskState == TaskState.DONE -> { @@ -1785,19 +1766,44 @@ internal object HighwayTools : Module( disable() } } ?: run { - MessageSendHelper.sendChatMessage("$chatName No shulker box with ${item.registryName} was found in inventory.") - mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1f, 1f)) - disable() - when (disableMode) { - DisableMode.ANTI_AFK -> { - MessageSendHelper.sendChatMessage("$chatName Going into AFK mode.") - AntiAFK.enable() - } - DisableMode.LOGOUT -> { - MessageSendHelper.sendChatMessage("$chatName CAUTION: Logging of in X Minutes.") + if (item.block == Blocks.OBSIDIAN) { + if (player.allSlots.countBlock(Blocks.ENDER_CHEST) <= saveEnder) { + getShulkerWith(Blocks.ENDER_CHEST.item)?.let { slot -> + getRemotePos()?.let { pos -> + containerTask = BlockTask(pos, TaskState.PLACE, slot.stack.item.block, Blocks.ENDER_CHEST.item) + containerTask.isShulker = true + } ?: run { + MessageSendHelper.sendChatMessage("$chatName Cant find possible container position.") + mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1f, 1f)) + disable() + } + } + } else { + getRemotePos()?.let { pos -> + containerTask = BlockTask(pos, TaskState.PLACE, Blocks.ENDER_CHEST) +// containerTask.isShulker = true + containerTask.destroy = true + } ?: run { + MessageSendHelper.sendChatMessage("$chatName Cant find possible container position.") + mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1f, 1f)) + disable() + } } - DisableMode.NONE -> { - // Nothing + } else { + MessageSendHelper.sendChatMessage("$chatName No shulker box with ${item.registryName} was found in inventory.") + mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1f, 1f)) + disable() + when (disableMode) { + DisableMode.ANTI_AFK -> { + MessageSendHelper.sendChatMessage("$chatName Going into AFK mode.") + AntiAFK.enable() + } + DisableMode.LOGOUT -> { + MessageSendHelper.sendChatMessage("$chatName CAUTION: Logging of in X Minutes.") + } + DisableMode.NONE -> { + // Nothing + } } } } @@ -1949,6 +1955,19 @@ internal object HighwayTools : Module( return foundLiquid } + private fun SafeClientEvent.updateLiquidTask(blockTask: BlockTask) { + val filler = if (player.allSlots.countBlock(fillerMat) == 0 || isInsideBlueprintBuild(blockTask.blockPos)) material + else fillerMat + + if (world.getBlockState(blockTask.blockPos).getValue(BlockLiquid.LEVEL) != 0) { + blockTask.updateState(TaskState.LIQUID_FLOW) + blockTask.updateMaterial(filler) + } else { + blockTask.updateState(TaskState.LIQUID_SOURCE) + blockTask.updateMaterial(filler) + } + } + private fun isInsideBlueprint(pos: BlockPos): Boolean { return blueprint.containsKey(pos) } @@ -2255,6 +2274,7 @@ internal object HighwayTools : Module( var itemID = 0 var inventory = emptyList() var transactionID: Short = 0 + var destroy = false // var isBridge = false ToDo: Implement From a967a2b958b5149163f8cbbdc2906142f0bdeaaf Mon Sep 17 00:00:00 2001 From: Christian Date: Thu, 22 Apr 2021 05:50:55 +0200 Subject: [PATCH 385/390] Instant mine and pickup --- .../module/modules/misc/HighwayTools.kt | 35 ++++++++++++------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index 2c2c146042..d8f7faa838 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -1258,6 +1258,7 @@ internal object HighwayTools : Module( blockTask.updateState(TaskState.DONE) } blockTask == containerTask -> { + moveState = MovementState.PICKUP blockTask.updateState(TaskState.PICKUP) } else -> { @@ -1533,11 +1534,16 @@ internal object HighwayTools : Module( mineBlockNormal(blockTask, sides.last().side) } else { - val side = getMiningSide(blockTask.blockPos) ?: run { + var side = getMiningSide(blockTask.blockPos) ?: run { blockTask.onStuck() return } + if (blockTask.primed && blockTask.destroy) { + side = side.opposite + } else { + blockTask.primed + } lastHitVec = getHitVec(blockTask.blockPos, side) rotateTimer.reset() @@ -1761,9 +1767,7 @@ internal object HighwayTools : Module( containerTask = BlockTask(pos, TaskState.PLACE, slot.stack.item.block, item) containerTask.isShulker = true } ?: run { - MessageSendHelper.sendChatMessage("$chatName Cant find possible container position.") - mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1f, 1f)) - disable() + disableNoPosition() } } ?: run { if (item.block == Blocks.OBSIDIAN) { @@ -1773,24 +1777,24 @@ internal object HighwayTools : Module( containerTask = BlockTask(pos, TaskState.PLACE, slot.stack.item.block, Blocks.ENDER_CHEST.item) containerTask.isShulker = true } ?: run { - MessageSendHelper.sendChatMessage("$chatName Cant find possible container position.") - mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1f, 1f)) - disable() + disableNoPosition() } + } ?: run { + MessageSendHelper.sendChatMessage("$chatName No shulker left containing ender chests (Getting material from e chests coming soon)") + Companion.mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1f, 1f)) + disable() } } else { getRemotePos()?.let { pos -> containerTask = BlockTask(pos, TaskState.PLACE, Blocks.ENDER_CHEST) -// containerTask.isShulker = true containerTask.destroy = true + containerTask.itemID = Blocks.OBSIDIAN.id } ?: run { - MessageSendHelper.sendChatMessage("$chatName Cant find possible container position.") - mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1f, 1f)) - disable() + disableNoPosition() } } } else { - MessageSendHelper.sendChatMessage("$chatName No shulker box with ${item.registryName} was found in inventory.") + MessageSendHelper.sendChatMessage("$chatName No shulker box with ${item.registryName} was found in inventory. (Getting material from e chests coming soon)") mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1f, 1f)) disable() when (disableMode) { @@ -1809,6 +1813,12 @@ internal object HighwayTools : Module( } } + private fun disableNoPosition() { + MessageSendHelper.sendChatMessage("$chatName Cant find possible container position.") + mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1f, 1f)) + disable() + } + private fun SafeClientEvent.getRemotePos(): BlockPos? { val eyePos = player.getPositionEyes(1f) @@ -2275,6 +2285,7 @@ internal object HighwayTools : Module( var inventory = emptyList() var transactionID: Short = 0 var destroy = false + var primed = false // var isBridge = false ToDo: Implement From 228e21903b0ff1aca69bbdc0940625b50455fdde Mon Sep 17 00:00:00 2001 From: Christian Date: Thu, 22 Apr 2021 06:39:12 +0200 Subject: [PATCH 386/390] No AutoObsidian module --- .../org/kamiblue/client/module/modules/misc/HighwayTools.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index d8f7faa838..e7777708eb 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -124,7 +124,7 @@ internal object HighwayTools : Module( private val bridging by setting("Bridging", true, { page == Page.BEHAVIOR }, description = "Tries to bridge / scaffold when stuck placing") private val multiBuilding by setting("Shuffle Tasks", false, { page == Page.BEHAVIOR }, description = "Only activate when working with several players") private val toggleInventoryManager by setting("Toggle InvManager", false, { page == Page.BEHAVIOR }, description = "Activates InventoryManager on enable") - private val toggleAutoObsidian by setting("Toggle AutoObsidian", true, { page == Page.BEHAVIOR }, description = "Activates AutoObsidian on enable") + private val toggleAutoObsidian by setting("Toggle AutoObsidian", false, { page == Page.BEHAVIOR }, description = "Activates AutoObsidian on enable") private val taskTimeout by setting("Task Timeout", 8, 0..20, 1, { page == Page.BEHAVIOR }, description = "Timeout for waiting for the server to try again") private val rubberbandTimeout by setting("Rubberband Timeout", 50, 5..100, 5, { page == Page.BEHAVIOR }, description = "Timeout for pausing after a lag") private val maxReach by setting("Max Reach", 4.9f, 1.0f..6.0f, 0.1f, { page == Page.BEHAVIOR }, description = "Sets the range of the blueprint. Decrease when tasks fail!") From 2648f3b576b7a68b57966f35cc7a3cd9e456127b Mon Sep 17 00:00:00 2001 From: Christian Date: Thu, 22 Apr 2021 09:08:53 +0200 Subject: [PATCH 387/390] Moving on --- gradle.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gradle.properties b/gradle.properties index 22fb2f2248..39b5abad11 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ org.gradle.jvmargs=-Xmx3G -modGroup=org.kamiblue -modVersion=2.04.xx-dev-ht-v09.9 +modGroup=me.constructor +modVersion=ht-v09.9 kotlin_version=1.4.30 kotlinx_coroutines_version=1.4.2 \ No newline at end of file From d5f05197ac4f247237b61e4492f07c7f951eec67 Mon Sep 17 00:00:00 2001 From: Christian Date: Fri, 23 Apr 2021 02:22:42 +0200 Subject: [PATCH 388/390] Get from e chest and no water mark --- .../kotlin/org/kamiblue/client/KamiMod.kt | 2 +- .../gui/hudgui/elements/client/WaterMark.kt | 4 +- .../module/modules/misc/HighwayTools.kt | 118 +++++++++++------- 3 files changed, 77 insertions(+), 47 deletions(-) diff --git a/src/main/kotlin/org/kamiblue/client/KamiMod.kt b/src/main/kotlin/org/kamiblue/client/KamiMod.kt index 3ca4be1ab6..3b4d878d55 100644 --- a/src/main/kotlin/org/kamiblue/client/KamiMod.kt +++ b/src/main/kotlin/org/kamiblue/client/KamiMod.kt @@ -26,7 +26,7 @@ class KamiMod { const val DIRECTORY = "kamiblue/" const val VERSION = "2.04.xx-dev" // Used for debugging. R.MM.DD-hash format. - const val VERSION_SIMPLE = "ht-v9.9" // Shown to the user. R.MM.DD[-beta] format. + const val VERSION_SIMPLE = "ht-v9.9-dev" // Shown to the user. R.MM.DD[-beta] format. const val VERSION_MAJOR = "2.04.01" // Used for update checking. RR.MM.01 format. const val BUILD_NUMBER = -1 // Do not remove, currently unused but will be used in the future. diff --git a/src/main/kotlin/org/kamiblue/client/gui/hudgui/elements/client/WaterMark.kt b/src/main/kotlin/org/kamiblue/client/gui/hudgui/elements/client/WaterMark.kt index fa2ec124da..392b587aea 100644 --- a/src/main/kotlin/org/kamiblue/client/gui/hudgui/elements/client/WaterMark.kt +++ b/src/main/kotlin/org/kamiblue/client/gui/hudgui/elements/client/WaterMark.kt @@ -11,14 +11,12 @@ internal object WaterMark : LabelHud( name = "Watermark", category = Category.CLIENT, description = "KAMI Blue watermark", - enabledByDefault = true + enabledByDefault = false ) { override val hudWidth: Float get() = (displayText.getWidth() + 2.0f) / scale override val hudHeight: Float get() = displayText.getHeight(2) / scale - override val closeable: Boolean get() = !Capes.updated || Capes.isPremium - override fun SafeClientEvent.updateText() { displayText.add(KamiMod.NAME, primaryColor) displayText.add(KamiMod.VERSION_SIMPLE, secondaryColor) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index e7777708eb..bf7d4cd447 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -140,6 +140,7 @@ internal object HighwayTools : Module( private val saveTools by setting("Save Tools", 1, 0..36, 1, { page == Page.STORAGE_MANAGEMENT }, description = "How many tools are saved") private val saveEnder by setting("Save Ender Chests", 1, 0..64, 1, { page == Page.STORAGE_MANAGEMENT }, description = "How many ender chests are saved") private val disableMode by setting("Disable Mode", DisableMode.NONE, { page == Page.STORAGE_MANAGEMENT }, description = "Choose action when bot is out of materials or tools") + private val tryRefreshSlots by setting("Try refresh slot", false, { page == Page.STORAGE_MANAGEMENT }, description = "Clicks a slot on desync") // stat settings private val anonymizeStats by setting("Anonymize", false, { page == Page.STATS }, description = "Censors all coordinates in HUD and Chat") @@ -304,12 +305,10 @@ internal object HighwayTools : Module( onDisable { runSafe { - /* Turn off inventory manager if the users wants us to control it */ if (toggleInventoryManager && InventoryManager.isEnabled) { InventoryManager.disable() } - /* Turn off auto obsidian if the user wants us to control it */ if (toggleAutoObsidian && AutoObsidian.isEnabled) { AutoObsidian.disable() } @@ -443,7 +442,8 @@ internal object HighwayTools : Module( rubberbandTimer.reset() } is SPacketOpenWindow -> { - if (event.packet.guiId == "minecraft:shulker_box") { + if (event.packet.guiId == "minecraft:shulker_box" || + event.packet.guiId == "minecraft:container") { containerTask.isOpen = true event.cancel() } @@ -906,7 +906,7 @@ internal object HighwayTools : Module( when (containerTask.taskState) { TaskState.PICKUP -> { player.inventorySlots.firstEmpty()?.let { - updateSlot(it.slotNumber) + if (tryRefreshSlots) updateSlot(it.slotNumber) } containerTask.updateState(TaskState.DONE) } @@ -915,6 +915,9 @@ internal object HighwayTools : Module( } } } + pendingTasks.values.toList().forEach { + doTask(it, true) + } doTask(containerTask, false) } else -> { @@ -1036,10 +1039,10 @@ internal object HighwayTools : Module( TaskState.PLACE -> { if (dynamicDelay && extraPlaceDelay < 10) extraPlaceDelay += 1 - updateSlot() + if (tryRefreshSlots) updateSlot() } TaskState.BREAK -> { - updateSlot() + if (tryRefreshSlots) updateSlot() } else -> { // Nothing @@ -1141,12 +1144,10 @@ internal object HighwayTools : Module( if (leaveEmptyShulkers && blockTask.inventory.take(27).filter { it.item != Items.AIR && !InventoryManager.ejectList.contains(it.item.registryName.toString()) }.size < 2) { if (debugMessages != DebugMessages.OFF) { - if (debugMessages == DebugMessages.ALL) { - if (!anonymizeStats) { - MessageSendHelper.sendChatMessage("$chatName Left empty ${blockTask.block.localizedName}@(${blockTask.blockPos.asString()})") - } else { - MessageSendHelper.sendChatMessage("$chatName Left empty ${blockTask.block.localizedName}") - } + if (!anonymizeStats) { + MessageSendHelper.sendChatMessage("$chatName Left empty ${blockTask.block.localizedName}@(${blockTask.blockPos.asString()})") + } else { + MessageSendHelper.sendChatMessage("$chatName Left empty ${blockTask.block.localizedName}") } } blockTask.updateState(TaskState.DONE) @@ -1186,7 +1187,28 @@ internal object HighwayTools : Module( } private fun SafeClientEvent.doRestock(blockTask: BlockTask) { - val moveSlot = blockTask.inventory.take(27).indexOfFirst { it.item == blockTask.item } + var moveSlot = blockTask.inventory.take(27).indexOfFirst { it.item == blockTask.item } + + if (moveSlot == -1) { + moveSlot = getShulkerFromContainer(blockTask.item) + if (moveSlot == -1) { + MessageSendHelper.sendChatMessage("$chatName No material left in ender chest.") + mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1f, 1f)) + disable() + when (disableMode) { + DisableMode.ANTI_AFK -> { + MessageSendHelper.sendChatMessage("$chatName Going into AFK mode.") + AntiAFK.enable() + } + DisableMode.LOGOUT -> { + MessageSendHelper.sendChatMessage("$chatName CAUTION: Logging of in X Minutes.") + } + DisableMode.NONE -> { + // Nothing + } + } + } + } var slot = getFreeSlot(blockTask.inventory.takeLast(9)) @@ -1461,6 +1483,7 @@ internal object HighwayTools : Module( MessageSendHelper.sendChatMessage("$chatName No neighbours found") } } + if (blockTask == containerTask) blockTask.updateState(TaskState.DONE) blockTask.onStuck(21) return } @@ -1727,21 +1750,12 @@ internal object HighwayTools : Module( } private fun SafeClientEvent.swapOrMoveBestTool(blockTask: BlockTask): Boolean { - // ToDo: Fix controller desync if (player.allSlots.countItem(Items.DIAMOND_PICKAXE) <= saveTools) { - return when { - containerTask.taskState == TaskState.DONE -> { - handleRestock(Items.DIAMOND_PICKAXE) - false - } - (containerTask.taskState == TaskState.BREAK || containerTask.taskState == TaskState.BREAKING) && - containerTask.item == Items.DIAMOND_PICKAXE -> { - containerTask.updateState(TaskState.OPEN_CONTAINER) - false - } - else -> { - swapOrMoveTool(blockTask) - } + return if (containerTask.taskState == TaskState.DONE) { + handleRestock(Items.DIAMOND_PICKAXE) + false + } else { + swapOrMoveTool(blockTask) } } @@ -1780,9 +1794,7 @@ internal object HighwayTools : Module( disableNoPosition() } } ?: run { - MessageSendHelper.sendChatMessage("$chatName No shulker left containing ender chests (Getting material from e chests coming soon)") - Companion.mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1f, 1f)) - disable() + dispatchEnderChest(Blocks.ENDER_CHEST.item) } } else { getRemotePos()?.let { pos -> @@ -1794,21 +1806,31 @@ internal object HighwayTools : Module( } } } else { - MessageSendHelper.sendChatMessage("$chatName No shulker box with ${item.registryName} was found in inventory. (Getting material from e chests coming soon)") + dispatchEnderChest(item) + } + } + } + + private fun SafeClientEvent.dispatchEnderChest(item: Item) { + if (player.allSlots.countBlock(Blocks.ENDER_CHEST) > 0) { + getRemotePos()?.let { pos -> + containerTask = BlockTask(pos, TaskState.PLACE, Blocks.ENDER_CHEST, item) + containerTask.itemID = Blocks.OBSIDIAN.id + } ?: run { + disableNoPosition() + } + } else { + getShulkerWith(Blocks.ENDER_CHEST.item)?.let { slot -> + getRemotePos()?.let { pos -> + containerTask = BlockTask(pos, TaskState.PLACE, slot.stack.item.block, Blocks.ENDER_CHEST.item) + containerTask.isShulker = true + } ?: run { + disableNoPosition() + } + } ?: run { + MessageSendHelper.sendChatMessage("$chatName No Ender Chest was found in inventory.") mc.soundHandler.playSound(PositionedSoundRecord.getRecord(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, 1f, 1f)) disable() - when (disableMode) { - DisableMode.ANTI_AFK -> { - MessageSendHelper.sendChatMessage("$chatName Going into AFK mode.") - AntiAFK.enable() - } - DisableMode.LOGOUT -> { - MessageSendHelper.sendChatMessage("$chatName CAUTION: Logging of in X Minutes.") - } - DisableMode.NONE -> { - // Nothing - } - } } } } @@ -1848,6 +1870,16 @@ internal object HighwayTools : Module( } } + private fun getShulkerFromContainer(item: Item): Int { + return containerTask.inventory.take(27).indexOfFirst { index -> + containerTask.inventory.take(27).filter { + it.item is ItemShulkerBox && getShulkerData(it, item) > 0 + }.minByOrNull { + getShulkerData(it, item) + } == index + } + } + @JvmStatic fun getShulkerData(stack: ItemStack, item: Item): Int { val tagCompound = if (stack.item is ItemShulkerBox) stack.tagCompound else return 0 From 2f3249fb5ed574d0905b7d9b69810ae3b055c1b5 Mon Sep 17 00:00:00 2001 From: Christian Date: Fri, 23 Apr 2021 22:39:59 +0200 Subject: [PATCH 389/390] Fix brainded AutoEat code --- .../client/module/modules/player/AutoEat.kt | 66 +++++-------------- 1 file changed, 17 insertions(+), 49 deletions(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/player/AutoEat.kt b/src/main/kotlin/org/kamiblue/client/module/modules/player/AutoEat.kt index 0e59c76751..72ffc893c4 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/player/AutoEat.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/player/AutoEat.kt @@ -1,10 +1,10 @@ package org.kamiblue.client.module.modules.player -import net.minecraft.client.settings.KeyBinding import net.minecraft.init.Items import net.minecraft.init.MobEffects import net.minecraft.inventory.Slot import net.minecraft.item.* +import net.minecraft.network.play.client.CPacketPlayerTryUseItem import net.minecraft.util.EnumHand import net.minecraftforge.fml.common.gameevent.TickEvent import org.kamiblue.client.event.SafeClientEvent @@ -12,7 +12,6 @@ import org.kamiblue.client.module.Category import org.kamiblue.client.module.Module import org.kamiblue.client.process.PauseProcess.pauseBaritone import org.kamiblue.client.process.PauseProcess.unpauseBaritone -import org.kamiblue.client.util.* import org.kamiblue.client.util.combat.CombatUtils.scaledHealth import org.kamiblue.client.util.items.* import org.kamiblue.client.util.threads.runSafe @@ -76,34 +75,24 @@ internal object AutoEat : Module( else -> PreferredFood.NORMAL } - val hand = when { - !shouldEat(preferredFood) -> { - null // Null = stop eating + if (shouldEat(preferredFood)) { + when { + isValidAndPreferred(player.heldItemOffhand, preferredFood) -> eat(EnumHand.OFF_HAND) + isValidAndPreferred(player.heldItemMainhand, preferredFood) -> eat(EnumHand.MAIN_HAND) + swapToFood(preferredFood) -> { + when { + isValidAndPreferredRecursive(player.heldItemOffhand, preferredFood) -> eat(EnumHand.OFF_HAND) + isValidAndPreferredRecursive(player.heldItemMainhand, preferredFood) -> eat(EnumHand.MAIN_HAND) + } + } } - isValidAndPreferred(player.heldItemOffhand, preferredFood) -> { - EnumHand.OFF_HAND - } - isValidAndPreferred(player.heldItemMainhand, preferredFood) -> { - EnumHand.MAIN_HAND - } - swapToFood(preferredFood) -> { // If we found valid food and moved - // Set eating and pause then wait until next tick - startEating() - return@safeListener - } - // If there isn't valid food in inventory or directly valid food in hand, do recursive check on items in hand - isValidAndPreferredRecursive(player.heldItemOffhand, preferredFood) -> { - EnumHand.OFF_HAND - } - isValidAndPreferredRecursive(player.heldItemMainhand, preferredFood) -> { - EnumHand.MAIN_HAND - } - else -> { - null // If we can't find any valid food then stop eating + } else { + if (eating) { + stopEating() + } else { + swapBack() } } - - eatOrStop(hand) } } @@ -117,27 +106,10 @@ internal object AutoEat : Module( player.foodStats.foodLevel < belowHunger || preferredFood != PreferredFood.NORMAL - private fun SafeClientEvent.eatOrStop(hand: EnumHand?) { - if (hand != null) { - eat(hand) - } else { - // Stop eating first and swap back in the next tick - if (eating) { - stopEating() - } else { - swapBack() - } - } - } - private fun SafeClientEvent.eat(hand: EnumHand) { if (!eating || !player.isHandActive || player.activeHand != hand) { - KeyBinding.setKeyBindState(mc.gameSettings.keyBindUseItem.keyCode, true) - - // Vanilla Minecraft prioritize offhand so we need to force it using the specific hand - playerController.processRightClick(player, world, hand) + connection.sendPacket(CPacketPlayerTryUseItem(hand)) } - startEating() } @@ -149,10 +121,6 @@ internal object AutoEat : Module( private fun stopEating() { unpauseBaritone() - runSafe { - KeyBinding.setKeyBindState(mc.gameSettings.keyBindUseItem.keyCode, false) - } - eating = false } From 864ab4a1b709f73f766f862cee4a63a5428cbb06 Mon Sep 17 00:00:00 2001 From: Christian Date: Sat, 24 Apr 2021 00:05:54 +0200 Subject: [PATCH 390/390] Better remote pos --- .../kamiblue/client/module/modules/misc/HighwayTools.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt index bf7d4cd447..09d09c271f 100644 --- a/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt +++ b/src/main/kotlin/org/kamiblue/client/module/modules/misc/HighwayTools.kt @@ -1842,20 +1842,20 @@ internal object HighwayTools : Module( } private fun SafeClientEvent.getRemotePos(): BlockPos? { - val eyePos = player.getPositionEyes(1f) + val origin = currentBlockPos.up().toVec3dCenter() - return VectorUtils.getBlockPosInSphere(eyePos, maxReach).asSequence() + return VectorUtils.getBlockPosInSphere(origin, maxReach).asSequence() .filter { pos -> !isInsideBlueprintBuild(pos) && pos != currentBlockPos && world.isPlaceable(pos) && !world.getBlockState(pos.down()).isReplaceable && world.isAirBlock(pos.up()) && - world.rayTraceBlocks(eyePos, pos.toVec3dCenter())?.let { it.typeOfHit == RayTraceResult.Type.MISS } ?: true + world.rayTraceBlocks(origin, pos.toVec3dCenter())?.let { it.typeOfHit == RayTraceResult.Type.MISS } ?: true } .sortedWith( compareBy { - it.distanceSqToCenter(eyePos.x, eyePos.y, eyePos.z).ceilToInt() + it.distanceSqToCenter(origin.x, origin.y, origin.z).ceilToInt() }.thenBy { it.y }