Skip to content
This repository has been archived by the owner on Apr 22, 2021. It is now read-only.

Commit

Permalink
[enhancement] Rewrote World Utils (#2100)
Browse files Browse the repository at this point in the history
Co-authored-by: Xiaro <[email protected]>
  • Loading branch information
Avanatiker and Luna5ama authored Mar 12, 2021
1 parent 8410e4f commit ab34717
Show file tree
Hide file tree
Showing 22 changed files with 656 additions and 385 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ import org.kamiblue.client.manager.managers.CombatManager
import org.kamiblue.client.manager.managers.PlayerPacketManager
import org.kamiblue.client.module.Category
import org.kamiblue.client.module.Module
import org.kamiblue.client.setting.settings.impl.primitive.BooleanSetting
import org.kamiblue.client.module.modules.combat.Surround.setting
import org.kamiblue.client.util.*
import org.kamiblue.client.util.WorldUtils.buildStructure
import org.kamiblue.client.util.WorldUtils.getPlaceInfo
import org.kamiblue.client.util.WorldUtils.isPlaceable
import org.kamiblue.client.util.EntityUtils.flooredPosition
import org.kamiblue.client.util.combat.SurroundUtils
import org.kamiblue.client.util.items.HotbarSlot
import org.kamiblue.client.util.items.firstBlock
import org.kamiblue.client.util.items.hotbarSlots
Expand All @@ -24,6 +23,8 @@ import org.kamiblue.client.util.text.MessageSendHelper
import org.kamiblue.client.util.threads.defaultScope
import org.kamiblue.client.util.threads.isActiveOrFalse
import org.kamiblue.client.util.threads.safeListener
import org.kamiblue.client.util.world.buildStructure
import org.kamiblue.client.util.world.isPlaceable
import org.kamiblue.event.listener.listener
import org.lwjgl.input.Keyboard

Expand All @@ -38,6 +39,7 @@ internal object AutoTrap : Module(
private val selfTrap = setting("Self Trap", false)
private val bindSelfTrap = setting("Bind Self Trap", Bind())
private val autoDisable = setting("Auto Disable", true)
private val strictDirection by setting("Strict Direction", false)
private val placeSpeed = setting("Places Per Tick", 4f, 0.25f..5f, 0.25f)

private var job: Job? = null
Expand Down Expand Up @@ -67,17 +69,14 @@ internal object AutoTrap : Module(
listener<InputEvent.KeyInputEvent> {
if (bindSelfTrap.value.isDown(Keyboard.getEventKey())) {
selfTrap.value = !selfTrap.value
MessageSendHelper.sendChatMessage(selfTrap.toggleMsg())
}
}
}

private fun BooleanSetting.toggleMsg() = "$chatName Turned ${this.name} ${if (this.value) "&aon" else "&coff"}&f!"

private fun SafeClientEvent.canRun(): Boolean {
(if (selfTrap.value) player else CombatManager.target)?.positionVector?.toBlockPos()?.let {
for (offset in trapMode.value.offset) {
if (!isPlaceable(it.add(offset))) continue
if (!world.isPlaceable(it.add(offset))) continue
return true
}
}
Expand All @@ -97,14 +96,19 @@ internal object AutoTrap : Module(
}

private fun SafeClientEvent.runAutoTrap() = defaultScope.launch {
buildStructure(placeSpeed.value) {
if (isEnabled && CombatManager.isOnTopPriority(this@AutoTrap)) {
val center = (if (selfTrap.value) player else CombatManager.target)?.positionVector?.toBlockPos()
getPlaceInfo(center, trapMode.value.offset, it, 3)
} else {
null
}
val entity = if (selfTrap.value) player else CombatManager.target ?: return@launch

buildStructure(
entity.flooredPosition,
SurroundUtils.surroundOffset,
placeSpeed.value,
3,
4.25f,
strictDirection
) {
isEnabled && CombatManager.isOnTopPriority(AutoTrap)
}

if (autoDisable.value) disable()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ import org.kamiblue.client.manager.managers.PlayerPacketManager
import org.kamiblue.client.module.Category
import org.kamiblue.client.module.Module
import org.kamiblue.client.util.*
import org.kamiblue.client.util.WorldUtils.getHitSide
import org.kamiblue.client.util.WorldUtils.rayTraceTo
import org.kamiblue.client.util.combat.CrystalUtils.calcCrystalDamage
import org.kamiblue.client.util.items.*
import org.kamiblue.client.util.math.RotationUtils
import org.kamiblue.client.util.math.RotationUtils.getRotationTo
import org.kamiblue.client.util.math.Vec2f
import org.kamiblue.client.util.math.VectorUtils
import org.kamiblue.client.util.math.VectorUtils.distanceTo
import org.kamiblue.client.util.math.VectorUtils.toVec3d
import org.kamiblue.client.util.threads.safeListener
import org.kamiblue.client.util.world.*
import java.util.*
import kotlin.collections.HashMap

Expand Down Expand Up @@ -79,8 +79,8 @@ internal object BedAura : Module(
if (!CombatManager.isOnTopPriority(this@BedAura) || it.packet !is CPacketPlayer || state == State.NONE || CombatSetting.pause) return@safeListener

val hand = getBedHand() ?: EnumHand.MAIN_HAND
val facing = if (state == State.PLACE) EnumFacing.UP else getHitSide(clickPos)
val hitVecOffset = WorldUtils.getHitVecOffset(facing)
val facing = if (state == State.PLACE) EnumFacing.UP else getClosestVisibleSide(clickPos) ?: EnumFacing.UP
val hitVecOffset = getHitVecOffset(facing)
val packet = CPacketPlayerTryUseItemOnBlock(clickPos, facing, hand, hitVecOffset.x.toFloat(), hitVecOffset.y.toFloat(), hitVecOffset.z.toFloat())

connection.sendPacket(packet)
Expand Down Expand Up @@ -126,18 +126,25 @@ internal object BedAura : Module(
val cacheMap = CombatManager.target?.let {
val posList = VectorUtils.getBlockPosInSphere(player.getPositionEyes(1f), range.value)
val damagePosMap = HashMap<Pair<Float, Float>, BlockPos>()
val eyePos = player.getPositionEyes(1.0f)

for (pos in posList) {
val dist = player.distanceTo(pos)
if (rayTraceTo(pos) == null && dist > wallRange.value) continue
val topSideVec = Vec3d(pos).add(0.5, 1.0, 0.5)

if (!world.isVisible(pos) && dist > wallRange.value) continue

val topSideVec = pos.toVec3d(0.5, 1.0, 0.5)
val rotation = getRotationTo(topSideVec)
val facing = EnumFacing.fromAngle(rotation.x.toDouble())
if (!canPlaceBed(pos)) continue

val targetDamage = calcCrystalDamage(pos.offset(facing), it)
val selfDamage = calcCrystalDamage(pos.offset(facing), player)
if (targetDamage < minDamage.value && (suicideMode.value || selfDamage > maxSelfDamage.value))
if (targetDamage < minDamage.value && (suicideMode.value || selfDamage > maxSelfDamage.value)) {
damagePosMap[Pair(targetDamage, selfDamage)] = pos
}
}

damagePosMap
}
placeMap.clear()
Expand All @@ -151,8 +158,8 @@ internal object BedAura : Module(
return (!ignoreSecondBaseBlock.value || world.getBlockState(bedPos2.down()).isSideSolid(world, bedPos2.down(), EnumFacing.UP))
&& !isFire(bedPos1)
&& !isFire(bedPos2)
&& world.getBlockState(bedPos1).material.isReplaceable
&& (!ignoreSecondBaseBlock.value || world.getBlockState(bedPos2).material.isReplaceable)
&& world.getBlockState(bedPos1).isReplaceable
&& (!ignoreSecondBaseBlock.value || world.getBlockState(bedPos2).isReplaceable)
}

private fun SafeClientEvent.isFire(pos: BlockPos): Boolean {
Expand All @@ -165,9 +172,11 @@ internal object BedAura : Module(
for (tileEntity in world.loadedTileEntityList) {
if (tileEntity !is TileEntityBed) continue
if (!tileEntity.isHeadPiece) continue

val dist = player.distanceTo(tileEntity.pos).toFloat()
if (dist > range.value) continue
if (rayTraceTo(tileEntity.pos) == null && dist > wallRange.value) continue
if (!world.isVisible(tileEntity.pos) && dist > wallRange.value) continue

damagePosMap[dist] = tileEntity.pos
}
damagePosMap
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock
import net.minecraft.network.play.client.CPacketUseEntity
import net.minecraft.network.play.server.SPacketSoundEffect
import net.minecraft.network.play.server.SPacketSpawnObject
import net.minecraft.util.EnumFacing
import net.minecraft.util.EnumHand
import net.minecraft.util.SoundCategory
import net.minecraft.util.math.AxisAlignedBB
Expand All @@ -31,7 +32,6 @@ import org.kamiblue.client.mixin.extension.packetAction
import org.kamiblue.client.module.Category
import org.kamiblue.client.module.Module
import org.kamiblue.client.util.*
import org.kamiblue.client.util.WorldUtils.getHitSide
import org.kamiblue.client.util.combat.CombatUtils.equipBestWeapon
import org.kamiblue.client.util.combat.CombatUtils.scaledHealth
import org.kamiblue.client.util.combat.CrystalUtils.canPlaceCollide
Expand All @@ -48,6 +48,7 @@ import org.kamiblue.client.util.math.VectorUtils.toVec3dCenter
import org.kamiblue.client.util.text.MessageSendHelper
import org.kamiblue.client.util.threads.runSafeR
import org.kamiblue.client.util.threads.safeListener
import org.kamiblue.client.util.world.getClosestVisibleSide
import org.kamiblue.commons.extension.synchronized
import org.kamiblue.commons.interfaces.DisplayEnum
import org.kamiblue.event.listener.listener
Expand Down Expand Up @@ -317,8 +318,10 @@ internal object CrystalAura : Module(
}
}

private fun SafeClientEvent.getPlacePacket(pos: BlockPos, hand: EnumHand) =
CPacketPlayerTryUseItemOnBlock(pos, getHitSide(pos), hand, 0.5f, placeOffset, 0.5f)
private fun SafeClientEvent.getPlacePacket(pos: BlockPos, hand: EnumHand): CPacketPlayerTryUseItemOnBlock {
val side = getClosestVisibleSide(pos) ?: EnumFacing.UP
return CPacketPlayerTryUseItemOnBlock(pos, side, hand, 0.5f, placeOffset, 0.5f)
}

private fun SafeClientEvent.packetExplode(entityID: Int, pos: BlockPos, vec3d: Vec3d) {
if (!preExplode()) return
Expand Down Expand Up @@ -564,4 +567,4 @@ internal object CrystalAura : Module(
lastLookAt = CombatManager.target?.positionVector ?: Vec3d.ZERO
}
/* End of rotation */
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import net.minecraft.entity.EntityLivingBase
import net.minecraft.init.Blocks
import net.minecraft.item.ItemStack
import net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock
import net.minecraft.util.EnumFacing
import net.minecraft.util.EnumHand
import net.minecraft.util.math.AxisAlignedBB
import net.minecraft.util.math.BlockPos
Expand All @@ -18,9 +17,6 @@ import org.kamiblue.client.manager.managers.PlayerPacketManager
import org.kamiblue.client.module.Category
import org.kamiblue.client.module.Module
import org.kamiblue.client.util.*
import org.kamiblue.client.util.WorldUtils.getNeighbour
import org.kamiblue.client.util.WorldUtils.hasNeighbour
import org.kamiblue.client.util.WorldUtils.isPlaceable
import org.kamiblue.client.util.color.ColorHolder
import org.kamiblue.client.util.combat.CrystalUtils.calcCrystalDamage
import org.kamiblue.client.util.graphics.ESPRenderer
Expand All @@ -31,6 +27,10 @@ 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.threads.safeListener
import org.kamiblue.client.util.world.PlaceInfo
import org.kamiblue.client.util.world.getNeighbour
import org.kamiblue.client.util.world.hasNeighbour
import org.kamiblue.client.util.world.isPlaceable
import org.kamiblue.event.listener.listener
import org.lwjgl.input.Keyboard
import java.util.*
Expand Down Expand Up @@ -117,21 +117,22 @@ internal object CrystalBasePlace : Module(
private fun SafeClientEvent.prePlace(entity: EntityLivingBase) {
if (rotationTo != null || !timer.tick((delay.value * 50.0f).toLong(), false)) return
val placeInfo = getPlaceInfo(entity)

if (placeInfo != null) {
val offset = WorldUtils.getHitVecOffset(placeInfo.first)
val hitVec = Vec3d(placeInfo.second).add(offset)
rotationTo = hitVec
placePacket = CPacketPlayerTryUseItemOnBlock(placeInfo.second, placeInfo.first, EnumHand.MAIN_HAND, offset.x.toFloat(), offset.y.toFloat(), offset.z.toFloat())
rotationTo = placeInfo.hitVec
placePacket = CPacketPlayerTryUseItemOnBlock(placeInfo.pos, placeInfo.side, EnumHand.MAIN_HAND, placeInfo.hitVecOffset.x.toFloat(), placeInfo.hitVecOffset.y.toFloat(), placeInfo.hitVecOffset.z.toFloat())

renderer.clear()
renderer.add(placeInfo.second.offset(placeInfo.first), ColorHolder(255, 255, 255))
renderer.add(placeInfo.placedPos, ColorHolder(255, 255, 255))

inactiveTicks = 0
timer.reset()
} else {
timer.reset((delay.value * -25.0f).toLong())
}
}

private fun SafeClientEvent.getPlaceInfo(entity: EntityLivingBase): Pair<EnumFacing, BlockPos>? {
private fun SafeClientEvent.getPlaceInfo(entity: EntityLivingBase): PlaceInfo? {
val cacheMap = TreeMap<Float, BlockPos>(compareByDescending { it })
val prediction = CombatSetting.getPrediction(entity)
val eyePos = player.getPositionEyes(1.0f)
Expand All @@ -143,7 +144,7 @@ internal object CrystalBasePlace : Module(

for (pos in posList) {
// Placeable check
if (!isPlaceable(pos, false)) continue
if (!world.isPlaceable(pos)) continue

// Neighbour blocks check
if (!hasNeighbour(pos)) continue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ import org.kamiblue.client.module.Category
import org.kamiblue.client.module.Module
import org.kamiblue.client.module.modules.movement.Strafe
import org.kamiblue.client.util.*
import org.kamiblue.client.util.EntityUtils.flooredPosition
import org.kamiblue.client.util.MovementUtils.centerPlayer
import org.kamiblue.client.util.MovementUtils.speed
import org.kamiblue.client.util.WorldUtils.buildStructure
import org.kamiblue.client.util.WorldUtils.getPlaceInfo
import org.kamiblue.client.util.WorldUtils.isPlaceable
import org.kamiblue.client.util.combat.SurroundUtils
import org.kamiblue.client.util.combat.SurroundUtils.checkHole
import org.kamiblue.client.util.items.firstBlock
Expand All @@ -26,6 +24,8 @@ import org.kamiblue.client.util.text.MessageSendHelper
import org.kamiblue.client.util.threads.defaultScope
import org.kamiblue.client.util.threads.isActiveOrFalse
import org.kamiblue.client.util.threads.safeListener
import org.kamiblue.client.util.world.buildStructure
import org.kamiblue.client.util.world.isPlaceable

@CombatManager.CombatModule
internal object Surround : Module(
Expand All @@ -36,6 +36,7 @@ internal object Surround : Module(
) {
private val placeSpeed by setting("Places Per Tick", 4f, 0.25f..5f, 0.25f)
private val disableStrafe by setting("Disable Strafe", true)
private val strictDirection by setting("Strict Direction", false)
private val autoDisable by setting("Auto Disable", AutoDisableMode.OUT_OF_HOLE)
private val outOfHoleTimeout by setting("Out Of Hole Timeout", 10, 1..50, 5, { autoDisable == AutoDisableMode.OUT_OF_HOLE }, description = "Delay before disabling Surround when you are out of hole, in ticks")
private val enableInHole = setting("Enable In Hole", false)
Expand Down Expand Up @@ -155,19 +156,22 @@ internal object Surround : Module(
private fun SafeClientEvent.canRun(): Boolean {
val playerPos = player.positionVector.toBlockPos()
return SurroundUtils.surroundOffset.any {
isPlaceable(playerPos.add(it), true)
world.isPlaceable(playerPos.add(it), true)
}
}

private fun SafeClientEvent.runSurround() = defaultScope.launch {
spoofHotbar()

buildStructure(placeSpeed) {
if (isEnabled && CombatManager.isOnTopPriority(this@Surround)) {
getPlaceInfo(player.positionVector.toBlockPos(), SurroundUtils.surroundOffset, it, 2)
} else {
null
}
buildStructure(
player.flooredPosition,
SurroundUtils.surroundOffset,
placeSpeed,
2,
4.25f,
strictDirection
) {
isEnabled && CombatManager.isOnTopPriority(Surround)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import org.kamiblue.client.mixin.extension.rightClickMouse
import org.kamiblue.client.module.Category
import org.kamiblue.client.module.Module
import org.kamiblue.client.util.TickTimer
import org.kamiblue.client.util.WorldUtils.isWater
import org.kamiblue.client.util.threads.safeListener
import org.kamiblue.client.util.world.isWater
import java.lang.Math.random
import kotlin.math.abs

Expand Down Expand Up @@ -88,7 +88,7 @@ internal object AutoFish : Module(
private fun SafeClientEvent.isOnWater(): Boolean {
if (player.fishEntity?.isAirBorne != false) return false
val pos = player.fishEntity!!.position
return isWater(pos) || isWater(pos.down())
return world.isWater(pos) || world.isWater(pos.down())
}

private fun SafeClientEvent.isSplash(packet: SPacketSoundEffect): Boolean {
Expand Down
Loading

0 comments on commit ab34717

Please sign in to comment.