Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
MukjepScarlet committed Feb 19, 2025
1 parent 87aecf6 commit aa2906b
Showing 1 changed file with 16 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import net.ccbluex.liquidbounce.utils.math.sq
import net.minecraft.entity.player.PlayerEntity
import net.minecraft.item.ArmorItem
import net.minecraft.item.Item
import net.minecraft.item.equipment.ArmorMaterial
import net.minecraft.item.equipment.ArmorMaterials
import net.minecraft.item.equipment.EquipmentType
import net.minecraft.network.packet.s2c.play.EntitiesDestroyS2CPacket
Expand Down Expand Up @@ -74,38 +73,25 @@ object CustomAntiBotMode : Choice("Custom"), ModuleAntiBot.IAntiBotMode {
val minimum by int("Minimum", 20, 0..120, "ticks")
}

private object Armor : ToggleableConfigurable(ModuleAntiBot, "Armor", false) {

@Suppress("unused")
private enum class ArmorMaterialChoice(
override val choiceName: String,
val material: ArmorMaterial?,
) : NamedChoice {
NOTHING("Nothing", null),
LEATHER("Leather", ArmorMaterials.LEATHER),
GOLD("Gold", ArmorMaterials.GOLD),
CHAIN("Chain", ArmorMaterials.CHAIN),
IRON("Iron", ArmorMaterials.IRON),
DIAMOND("Diamond", ArmorMaterials.DIAMOND),
NETHERITE("Netherite", ArmorMaterials.NETHERITE)
}
private object ArmorMaterial : ToggleableConfigurable(ModuleAntiBot, "ArmorMaterial", false) {

private class ArmorConfigurable(
name: String, val equipmentType: EquipmentType
) : ToggleableConfigurable(this, name, false) {

val mode by enumChoice("Mode", Filter.BLACKLIST)

// TODO: replace with multiple choice
val materialChoice by enumChoice("Material", ArmorMaterialChoice.LEATHER)
private val materialValues = mapOf(
null to boolean("Nothing", true),
ArmorMaterials.LEATHER to boolean("Leather", true),
ArmorMaterials.GOLD to boolean("Gold", true),
ArmorMaterials.CHAIN to boolean("Chain", true),
ArmorMaterials.IRON to boolean("Iron", true),
ArmorMaterials.DIAMOND to boolean("Diamond", true),
ArmorMaterials.NETHERITE to boolean("Netherite", true)
)

fun isValid(item: Item): Boolean {
with((item as? ArmorItem)?.material() == materialChoice.material) {
return when (mode) {
Filter.WHITELIST -> this
Filter.BLACKLIST -> !this
}
}
// TURTLE_SCUTE or ARMADILLO_SCUTE -> valid
return materialValues[(item as? ArmorItem)?.material()]?.get() ?: true
}
}

Expand All @@ -127,7 +113,7 @@ object CustomAntiBotMode : Choice("Custom"), ModuleAntiBot.IAntiBotMode {
tree(InvalidGround)
tree(AlwaysInRadius)
tree(Age)
tree(Armor)
tree(ArmorMaterial)
}

private val flyingSet = Int2IntOpenHashMap()
Expand All @@ -152,7 +138,7 @@ object CustomAntiBotMode : Choice("Custom"), ModuleAntiBot.IAntiBotMode {
ageSet.add(entity.id)
}

if (Armor.enabled && !Armor.isValid(entity)) {
if (ArmorMaterial.enabled && !ArmorMaterial.isValid(entity)) {
armorSet.add(entity.id)
}
}
Expand All @@ -169,7 +155,7 @@ object CustomAntiBotMode : Choice("Custom"), ModuleAntiBot.IAntiBotMode {
with(armorSet.intIterator()) {
while (hasNext()) {
val entity = world.getEntityById(nextInt()) as? PlayerEntity
if (entity == null || Armor.isValid(entity)) {
if (entity == null || ArmorMaterial.isValid(entity)) {
remove()
}
}
Expand Down Expand Up @@ -267,7 +253,7 @@ object CustomAntiBotMode : Choice("Custom"), ModuleAntiBot.IAntiBotMode {
illegalPitch && abs(player.pitch) > 90 -> true
AlwaysInRadius.enabled && !notAlwaysInRadiusSet.contains(playerId) -> true
Age.enabled && ageSet.contains(playerId) -> true
Armor.enabled && armorSet.contains(playerId) -> true
ArmorMaterial.enabled && armorSet.contains(playerId) -> true
needHit && !hitListSet.contains(playerId) -> true
health && player.health > 20f -> true
swung && !swungSet.contains(playerId) -> true
Expand Down

0 comments on commit aa2906b

Please sign in to comment.