Try to get things working
This commit is contained in:
parent
c3f5be60ed
commit
e10f66a0c0
@ -13,36 +13,71 @@ import net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent
|
||||
object CaneMacroer {
|
||||
var isMacroToggled: Boolean = false
|
||||
val mc = Minecraft.getMinecraft()
|
||||
var activeKeys: MutableList<KeyBindingAccessor> = mutableListOf()
|
||||
val allowedScreens = listOf(GuiChat::class.java)
|
||||
|
||||
@SubscribeEvent
|
||||
fun onTick(event: ClientTickEvent) {
|
||||
if (event.phase != TickEvent.Phase.END) return
|
||||
|
||||
if (!isMacroToggled) return
|
||||
|
||||
val canRunMacro = mc.currentScreen == null || mc.currentScreen is GuiChat
|
||||
if (!canRunMacro) {
|
||||
isMacroToggled = false
|
||||
Chatterbox.say("Disabled macro!")
|
||||
val currentScreen = mc.currentScreen
|
||||
|
||||
if (currentScreen != null && allowedScreens.none { it.isInstance(currentScreen) }) {
|
||||
Chatterbox.say("Macro stopped: Invalid screen")
|
||||
stop()
|
||||
return
|
||||
}
|
||||
|
||||
val mop = mc.objectMouseOver
|
||||
|
||||
if (mop == null || mop.typeOfHit?.name != "BLOCK") return
|
||||
|
||||
val blockPos = mop.blockPos
|
||||
val facing = mop.sideHit
|
||||
|
||||
val player = mc.thePlayer
|
||||
val blockCenter = blockPos.add(0.5, 0.5, 0.5)
|
||||
val distanceSq = player.getDistanceSq(blockCenter.x.toDouble(), blockCenter.y.toDouble(), blockCenter.z.toDouble())
|
||||
|
||||
if (distanceSq > 25) {
|
||||
Chatterbox.say("Macro stopped: Too far from block")
|
||||
stop()
|
||||
return
|
||||
}
|
||||
|
||||
if (isEntityBlockingView()) {
|
||||
Chatterbox.say("Macro stopped: Entity in the way")
|
||||
stop()
|
||||
return
|
||||
}
|
||||
|
||||
val myKey = mc.gameSettings.keyBindForward as KeyBindingAccessor
|
||||
pressKey(mc.gameSettings.keyBindForward.keyCode)
|
||||
mc.playerController.onPlayerDamageBlock(blockPos, facing)
|
||||
player.swingItem()
|
||||
}
|
||||
|
||||
fun stop() {
|
||||
KeyBinding.setKeyBindState(mc.gameSettings.keyBindForward.keyCode, false)
|
||||
KeyBinding.setKeyBindState(mc.gameSettings.keyBindAttack.keyCode, false)
|
||||
isMacroToggled = false
|
||||
}
|
||||
|
||||
// private fun pressKey(key: KeyBindingAccessor) {
|
||||
// key.setPressed(true)
|
||||
// activeKeys.add(key)
|
||||
// }
|
||||
|
||||
private fun pressKey(keyCode: Int) {
|
||||
KeyBinding.setKeyBindState(keyCode, true)
|
||||
}
|
||||
|
||||
private fun isEntityBlockingView(): Boolean {
|
||||
val lookVec = mc.thePlayer.lookVec
|
||||
val eyePos = mc.thePlayer.getPositionEyes(1f)
|
||||
|
||||
val entities = mc.theWorld.getEntitiesWithinAABBExcludingEntity(
|
||||
mc.thePlayer,
|
||||
mc.thePlayer.entityBoundingBox.expand(lookVec.xCoord * 5, lookVec.yCoord * 5, lookVec.zCoord * 5)
|
||||
)
|
||||
|
||||
return entities.any {
|
||||
it.canBeCollidedWith() &&
|
||||
it.entityBoundingBox.isVecInside(eyePos)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user