Skip to content

Commit

Permalink
Added ProjectilePuncher module. (CCBlueX#631)
Browse files Browse the repository at this point in the history
* Added FireballKicker module.

* Improved FireballKicker module code.

* Renamed FireballKicker to ProjectilePuncher.

* test

* Added description.

* Added range setting.

* added cps option

Co-authored-by: kawaiinekololis <[email protected]>
  • Loading branch information
mems01 and 1zun4 authored Oct 18, 2021
1 parent 3ce6b23 commit 854b338
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ object ModuleManager : Listenable, Iterable<Module> by modules {
ModuleAutoFish,
ModuleMobOwners,
ModuleGhostHand,
ModuleAirJump,
ModuleProjectilePuncher,
ModuleAutoPot,
ModuleAirJump
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/*
* This file is part of LiquidBounce (https://github.com/CCBlueX/LiquidBounce)
*
* Copyright (c) 2016 - 2021 CCBlueX
*
* LiquidBounce is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LiquidBounce is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LiquidBounce. If not, see <https://www.gnu.org/licenses/>.
*/

package net.ccbluex.liquidbounce.features.module.modules.world

import net.ccbluex.liquidbounce.event.AttackEvent
import net.ccbluex.liquidbounce.event.EventManager
import net.ccbluex.liquidbounce.event.repeatable
import net.ccbluex.liquidbounce.features.module.Category
import net.ccbluex.liquidbounce.features.module.Module
import net.ccbluex.liquidbounce.utils.aiming.RotationManager
import net.ccbluex.liquidbounce.utils.aiming.RotationsConfigurable
import net.ccbluex.liquidbounce.utils.client.MC_1_8
import net.ccbluex.liquidbounce.utils.client.protocolVersion
import net.ccbluex.liquidbounce.utils.combat.CpsScheduler
import net.ccbluex.liquidbounce.utils.combat.TargetTracker
import net.ccbluex.liquidbounce.utils.entity.eyesPos
import net.ccbluex.liquidbounce.utils.entity.squaredBoxedDistanceTo
import net.minecraft.entity.Entity
import net.minecraft.entity.projectile.FireballEntity
import net.minecraft.entity.projectile.ShulkerBulletEntity
import net.minecraft.network.packet.c2s.play.PlayerInteractEntityC2SPacket
import net.minecraft.util.Hand

/**
* ProjectilePuncher module
*
* Shoots back incoming projectiles around you.
*/

object ModuleProjectilePuncher : Module("ProjectilePuncher", Category.WORLD) {

private val cps by intRange("CPS", 5..8, 1..20)
private val swing by boolean("Swing", true)
private val range by float("Range", 3f, 3f..6f)

// Target
private val targetTracker = tree(TargetTracker())

// Rotation
private val rotations = RotationsConfigurable()

private val cpsTimer = CpsScheduler()

override fun disable() {
targetTracker.cleanup()
}

val repeatable = repeatable {
attack()
}

private fun attack() {
if (player.isSpectator) {
return
}

val squaredRange = range * range

targetTracker.validateLock { it.squaredBoxedDistanceTo(player) <= squaredRange }

for (entity in world.entities) {
if (entity is FireballEntity || entity is ShulkerBulletEntity) {
if (entity.squaredBoxedDistanceTo(player) > squaredRange) {
continue
}

// find best spot (and skip if no spot was found)
val (rotation, _) = RotationManager.raytraceBox(
player.eyesPos,
entity.boundingBox,
range = range.toDouble(),
wallsRange = 0.0
) ?: continue

// lock on target tracker
targetTracker.lock(entity)

// aim at target
RotationManager.aimAt(rotation, configurable = rotations)
break
}
}

val entity = targetTracker.lockedOnTarget ?: return
val clicks = cpsTimer.clicks(condition = { true },
cps
)

// There is no need for multiple clicks on one target.
if (clicks > 0) {
// Yeet away the projectile
attackEntity(entity)
targetTracker.cleanup()
}
}

private fun attackEntity(entity: Entity) {
EventManager.callEvent(AttackEvent(entity))

// Swing before attacking (on 1.8)
if (swing && protocolVersion == MC_1_8) {
player.swingHand(Hand.MAIN_HAND)
}

network.sendPacket(PlayerInteractEntityC2SPacket.attack(entity, player.isSneaking))

// Swing after attacking (on 1.9+)
if (swing && protocolVersion != MC_1_8) {
player.swingHand(Hand.MAIN_HAND)
}

// Reset cool down
player.resetLastAttackedTicks()
}
}
4 changes: 3 additions & 1 deletion src/main/resources/assets/liquidbounce/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,9 @@
"liquidbounce.module.sleepWalker.description": "Allows you to walk while sleeping, also makes your hitbox small.",

"liquidbounce.module.dankBobbing.description": "Adds more bobbing effect.",


"liquidbounce.module.projectilePuncher.description": "Shoots back incoming projectiles around you.",

"liquidbounce.module.autoPot.description": "Automatically throws healing potions whenever your health is low."

}

0 comments on commit 854b338

Please sign in to comment.