Skip to content

Commit

Permalink
feat(legacy): f*cker module improvement (#5565)
Browse files Browse the repository at this point in the history
  • Loading branch information
RtxOP authored Feb 8, 2025
1 parent 4ab1656 commit 8b5e9e6
Showing 1 changed file with 88 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ object Fucker : Module("Fucker", Category.WORLD) {
/**
* SETTINGS
*/

private val hypixel by boolean("Hypixel", false)

private val block by block("Block", 26)
Expand Down Expand Up @@ -75,9 +74,9 @@ object Fucker : Module("Fucker", Category.WORLD) {
/**
* VALUES
*/

var pos: BlockPos? = null
private set
private var obstructingPos: BlockPos? = null
private var spawnLocation: Vec3? = null
private var oldPos: BlockPos? = null
private var blockHitDelay = 0
Expand All @@ -95,16 +94,15 @@ object Fucker : Module("Fucker", Category.WORLD) {

currentDamage = 0F
pos = null
obstructingPos = null
areSurroundings = false
isOwnBed = false
}

val onPacket = handler<PacketEvent> { event ->
if (mc.thePlayer == null || mc.theWorld == null)
return@handler
if (mc.thePlayer == null || mc.theWorld == null) return@handler

val packet = event.packet

if (packet is S08PacketPlayerPosLook) {
spawnLocation = Vec3(packet.x, packet.y, packet.z)
}
Expand All @@ -114,64 +112,84 @@ object Fucker : Module("Fucker", Category.WORLD) {
val player = mc.thePlayer ?: return@handler
val world = mc.theWorld ?: return@handler

if (noHit && KillAura.handleEvents() && KillAura.target != null) {
return@handler
}
if (noHit && KillAura.handleEvents() && KillAura.target != null) return@handler

val targetId = block

if (pos == null || pos!!.block!!.id != targetId || getCenterDistance(pos!!) > range) {
pos = find(targetId)
obstructingPos = null
}

// Reset current breaking when there is no target block
if (pos == null) {
currentDamage = 0F
areSurroundings = false
isOwnBed = false
obstructingPos = null
return@handler
}

var currentPos = pos ?: return@handler
var spot = faceBlock(currentPos) ?: return@handler

// Check if it is the player's own bed
isOwnBed = ignoreOwnBed && isBedNearSpawn(currentPos)
if (isOwnBed) {
obstructingPos = null
return@handler
}

if (surroundings || hypixel) {
val eyes = player.eyes

val blockPos = if (hypixel) {
currentPos.up()
} else {
world.rayTraceBlocks(eyes, spot.vec, false, false, true)?.blockPos
}

if (blockPos != null && blockPos.block != Blocks.air) {
if (currentPos.x != blockPos.x || currentPos.y != blockPos.y || currentPos.z != blockPos.z) {
areSurroundings = true
if (hypixel && obstructingPos == null) {
val abovePos = currentPos.up()
if (abovePos.block != Blocks.air && isHittable(abovePos)) {
obstructingPos = abovePos
currentPos = obstructingPos!!
}
} else if (surroundings && obstructingPos == null) {
val eyes = player.eyes
val spotToBed = faceBlock(currentPos) ?: return@handler
val blockPos = world.rayTraceBlocks(eyes, spotToBed.vec, false, false, true)?.blockPos
if (blockPos != null && blockPos.block != Blocks.air && blockPos != currentPos) {
obstructingPos = blockPos
currentPos = obstructingPos!!
}
} else if (obstructingPos != null) {
currentPos = obstructingPos!!
if (surroundings) {
val eyes = player.eyes
val spotToObstruction = faceBlock(currentPos) ?: return@handler
val rayTraceResultToObstruction = world.rayTraceBlocks(eyes, spotToObstruction.vec, false, false, true)
// If a new block is blocking it, reset and re-evaluate next cycle.
if (rayTraceResultToObstruction?.blockPos != currentPos &&
rayTraceResultToObstruction?.typeOfHit == net.minecraft.util.MovingObjectPosition.MovingObjectType.BLOCK
) {
obstructingPos = null
return@handler
}
val spotToBed = faceBlock(pos!!) ?: return@handler
val rayTraceToBed = world.rayTraceBlocks(eyes, spotToBed.vec, false, false, true)
// Target bed if it's open
if (rayTraceToBed?.blockPos == pos &&
rayTraceToBed.typeOfHit == net.minecraft.util.MovingObjectPosition.MovingObjectType.BLOCK
) {
obstructingPos = null
currentPos = pos!!
}
}

pos = blockPos
currentPos = pos ?: return@handler
spot = faceBlock(currentPos) ?: return@handler
}
}

// Reset switch timer when position changed
val spot = faceBlock(currentPos) ?: return@handler

// Reset switch timer when position changes
if (oldPos != null && oldPos != currentPos) {
currentDamage = 0F
switchTimer.reset()
}

oldPos = currentPos

if (!switchTimer.hasTimePassed(switch)) {
return@handler
}
if (!switchTimer.hasTimePassed(switch)) return@handler

// Block hit delay
if (blockHitDelay > 0) {
Expand All @@ -192,17 +210,18 @@ object Fucker : Module("Fucker", Category.WORLD) {
if (currentPos.block != Block.getBlockById(block) || spawnLocation == null) {
return false
}

return spawnLocation!!.squareDistanceTo(currentPos.center) < ownBedDist * ownBedDist
}

val onUpdate = loopHandler {
val player = mc.thePlayer ?: return@loopHandler
val world = mc.theWorld ?: return@loopHandler

val controller = mc.playerController ?: return@loopHandler

val currentPos = pos ?: return@loopHandler
var currentPos = pos ?: return@loopHandler
if (obstructingPos != null) {
currentPos = obstructingPos!!
}

val targetRotation = if (options.rotationsActive) {
currentRotation ?: player.rotation
Expand All @@ -215,131 +234,98 @@ object Fucker : Module("Fucker", Category.WORLD) {
when {
// Destroy block
action == "Destroy" || areSurroundings -> {
// Check if it is the player's own bed
isOwnBed = ignoreOwnBed && isBedNearSpawn(currentPos)
if (isOwnBed) {
obstructingPos = null
return@loopHandler
}

EventManager.call(ClickBlockEvent(currentPos, raytrace.sideHit))

// Break block
if (instant && !hypixel) {
// CivBreak style block breaking
sendPacket(C07PacketPlayerDigging(START_DESTROY_BLOCK, currentPos, raytrace.sideHit))

if (swing) {
player.swingItem()
}

if (swing) player.swingItem()
sendPacket(C07PacketPlayerDigging(STOP_DESTROY_BLOCK, currentPos, raytrace.sideHit))
currentDamage = 0F
clearTarget(currentPos)
return@loopHandler
}

// Minecraft block breaking
val block = currentPos.block ?: return@loopHandler

if (currentDamage == 0F) {
// Prevent from flagging FastBreak
// Prevent flagging FastBreak
sendPacket(C07PacketPlayerDigging(STOP_DESTROY_BLOCK, currentPos, raytrace.sideHit))
WaitTickUtils.schedule(1) {
sendPacket(C07PacketPlayerDigging(START_DESTROY_BLOCK, currentPos, raytrace.sideHit))
}

if (player.capabilities.isCreativeMode || block.getPlayerRelativeBlockHardness(
player,
world,
currentPos
) >= 1f
if (player.capabilities.isCreativeMode ||
block.getPlayerRelativeBlockHardness(player, world, currentPos) >= 1f
) {
if (swing) {
player.swingItem()
}

if (swing) player.swingItem()
controller.onPlayerDestroyBlock(currentPos, raytrace.sideHit)

currentDamage = 0F
pos = null
areSurroundings = false
clearTarget(currentPos)
return@loopHandler
}
}

if (swing) {
player.swingItem()
}

if (swing) player.swingItem()
currentDamage += block.getPlayerRelativeBlockHardness(player, world, currentPos)
world.sendBlockBreakProgress(player.entityId, currentPos, (currentDamage * 10F).toInt() - 1)

if (currentDamage >= 1F) {
sendPacket(C07PacketPlayerDigging(STOP_DESTROY_BLOCK, currentPos, raytrace.sideHit))
controller.onPlayerDestroyBlock(currentPos, raytrace.sideHit)
blockHitDelay = 4
currentDamage = 0F
pos = null
areSurroundings = false
clearTarget(currentPos)
}
}

// Use block
action == "Use" -> {
if (player.onPlayerRightClick(currentPos, raytrace.sideHit, raytrace.hitVec, player.heldItem)) {
if (swing) player.swingItem()
else sendPacket(C0APacketAnimation())

if (swing) player.swingItem() else sendPacket(C0APacketAnimation())
blockHitDelay = 4
currentDamage = 0F
pos = null
areSurroundings = false
clearTarget(currentPos)
}
}
}
}

val onRender3D = handler<Render3DEvent> {
val pos = pos ?: return@handler
val renderPos = obstructingPos ?: pos
val posToDraw = renderPos ?: return@handler

// Check if it is the player's own bed
isOwnBed = ignoreOwnBed && isBedNearSpawn(pos)
if (mc.thePlayer == null || isOwnBed) {
return@handler
}
isOwnBed = ignoreOwnBed && isBedNearSpawn(posToDraw)
if (mc.thePlayer == null || isOwnBed) return@handler

if (block.blockById == Blocks.air) return@handler

if (blockProgress) {
pos.drawBlockDamageText(
posToDraw.drawBlockDamageText(
currentDamage,
font,
fontShadow,
color.rgb,
scale,
scale
)
}

// Render block box
drawBlockBox(pos, Color.RED, true)
drawBlockBox(posToDraw, Color.RED, true)
}

/**
* Find new target block by [targetID]
* Finds a new target block by [targetID]
*/
private fun find(targetID: Int): BlockPos? {
val eyes = mc.thePlayer?.eyes ?: return null

var nearestBlockDistanceSq = Double.MAX_VALUE
val nearestBlock = BlockPos.MutableBlockPos()

val rangeSq = range * range

eyes.getAllInBoxMutable(range + 1.0).forEach {
val distSq = it.distanceSqToCenter(eyes.xCoord, eyes.yCoord, eyes.zCoord)

if (it.block?.id != targetID
|| distSq > rangeSq || distSq > nearestBlockDistanceSq
|| !isHittable(it) && !surroundings && !hypixel
if (it.block?.id != targetID || distSq > rangeSq || distSq > nearestBlockDistanceSq ||
!isHittable(it) && !surroundings && !hypixel
) return@forEach

nearestBlockDistanceSq = distSq
Expand All @@ -350,25 +336,35 @@ object Fucker : Module("Fucker", Category.WORLD) {
}

/**
* Check if block is hittable (or allowed to hit through walls)
* Checks if the block is hittable (or allowed to be hit through walls)
*/
private fun isHittable(blockPos: BlockPos): Boolean {
val thePlayer = mc.thePlayer ?: return false

return when (throughWalls.lowercase()) {
"raycast" -> {
val eyesPos = thePlayer.eyes
val movingObjectPosition = mc.theWorld.rayTraceBlocks(eyesPos, blockPos.center, false, true, false)

movingObjectPosition != null && movingObjectPosition.blockPos == blockPos
}

"around" -> EnumFacing.entries.any { !isBlockBBValid(blockPos.offset(it)) }

else -> true
}
}

/**
* Clears the current target if it matches [currentPos] and resets related values.
*/
private fun clearTarget(currentPos: BlockPos) {
if (currentPos == obstructingPos) {
obstructingPos = null
}
if (currentPos == pos) {
pos = null
}
areSurroundings = false
currentDamage = 0F
}

override val tag
get() = getBlockName(block)
}

0 comments on commit 8b5e9e6

Please sign in to comment.