[enhancement] Added options to copy potion effect, adding max armor and gapple effect to FakePlayer

This commit is contained in:
Xiaro 2021-01-09 21:15:16 -05:00
parent 6bfdecb1f1
commit e581c0ac13
No known key found for this signature in database
GPG Key ID: 996D265D6E155377
1 changed files with 94 additions and 22 deletions

View File

@ -2,6 +2,7 @@ package me.zeroeightsix.kami.module.modules.misc
import com.mojang.authlib.GameProfile
import me.zeroeightsix.kami.command.CommandManager
import me.zeroeightsix.kami.event.SafeClientEvent
import me.zeroeightsix.kami.event.events.ConnectionEvent
import me.zeroeightsix.kami.event.events.GuiEvent
import me.zeroeightsix.kami.module.Module
@ -12,6 +13,13 @@ import me.zeroeightsix.kami.util.threads.onMainThreadSafe
import me.zeroeightsix.kami.util.threads.runSafeR
import net.minecraft.client.entity.EntityOtherPlayerMP
import net.minecraft.client.gui.GuiGameOver
import net.minecraft.enchantment.Enchantment
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.init.Enchantments
import net.minecraft.init.Items
import net.minecraft.init.MobEffects
import net.minecraft.item.ItemStack
import net.minecraft.potion.PotionEffect
import org.kamiblue.event.listener.listener
import java.util.*
@ -20,35 +28,21 @@ object FakePlayer : Module(
description = "Spawns a client sided fake player",
category = Category.MISC
) {
private val copyInventory by setting("CopyInventory", false)
private val copyInventory by setting("CopyInventory", true)
private val copyPotions by setting("CopyPotions", true)
private val maxArmor by setting("MaxArmor", false)
private val gappleEffects by setting("GappleEffects", false)
val playerName by setting("PlayerName", "Player")
private const val ENTITY_ID = -696969420
private var fakePlayer: EntityOtherPlayerMP? = null
private const val ENTITY_ID = -7170400
init {
listener<ConnectionEvent.Disconnect> {
disable()
}
listener<GuiEvent.Displayed> {
if (it.screen is GuiGameOver) disable()
}
onEnable {
runSafeR {
if (playerName == "Player") {
MessageSendHelper.sendChatMessage("You can use " +
formatValue("${CommandManager.prefix}set FakePlayer PlayerName <name>") +
" to set a custom name")
}
fakePlayer = EntityOtherPlayerMP(Companion.mc.world, GameProfile(UUID.randomUUID(), playerName)).apply {
copyLocationAndAnglesFrom(Companion.mc.player)
rotationYawHead = Companion.mc.player.rotationYawHead
if (copyInventory) inventory.copyInventory(Companion.mc.player.inventory)
}.also {
Companion.mc.world.addEntityToWorld(ENTITY_ID, it)
MessageSendHelper.sendChatMessage("You can use ${formatValue("${CommandManager.prefix}set FakePlayer PlayerName <name>")} to set a custom name")
spawnFakePlayer()
}
} ?: disable()
}
@ -56,8 +50,86 @@ object FakePlayer : Module(
onDisable {
onMainThreadSafe {
fakePlayer?.setDead()
world.removeEntityFromWorld(-911)
world.removeEntityFromWorld(ENTITY_ID)
fakePlayer = null
}
}
listener<ConnectionEvent.Disconnect> {
disable()
}
listener<GuiEvent.Displayed> {
if (it.screen is GuiGameOver) disable()
}
}
private fun SafeClientEvent.spawnFakePlayer() {
fakePlayer = EntityOtherPlayerMP(world, GameProfile(UUID.randomUUID(), playerName)).apply {
copyLocationAndAnglesFrom(player)
rotationYawHead = player.rotationYawHead
if (copyInventory) inventory.copyInventory(player.inventory)
if (copyPotions) copyPotions(player)
if (maxArmor) addMaxArmor()
if (gappleEffects) addGappleEffects()
}.also {
onMainThreadSafe {
world.addEntityToWorld(ENTITY_ID, it)
}
}
}
private fun EntityPlayer.copyPotions(otherPlayer: EntityPlayer) {
for (potionEffect in otherPlayer.activePotionEffects) {
addPotionEffectForce(PotionEffect(potionEffect.potion, Int.MAX_VALUE, potionEffect.amplifier))
}
}
private fun EntityPlayer.addMaxArmor() {
inventory.armorInventory[3] = ItemStack(Items.DIAMOND_HELMET).apply {
addMaxEnchantment(Enchantments.PROTECTION)
addMaxEnchantment(Enchantments.UNBREAKING)
addMaxEnchantment(Enchantments.RESPIRATION)
addMaxEnchantment(Enchantments.AQUA_AFFINITY)
addMaxEnchantment(Enchantments.MENDING)
}
inventory.armorInventory[2] = ItemStack(Items.DIAMOND_CHESTPLATE).apply {
addMaxEnchantment(Enchantments.PROTECTION)
addMaxEnchantment(Enchantments.UNBREAKING)
addMaxEnchantment(Enchantments.MENDING)
}
inventory.armorInventory[1] = ItemStack(Items.DIAMOND_LEGGINGS).apply {
addMaxEnchantment(Enchantments.BLAST_PROTECTION)
addMaxEnchantment(Enchantments.UNBREAKING)
addMaxEnchantment(Enchantments.MENDING)
}
inventory.armorInventory[0] = ItemStack(Items.DIAMOND_BOOTS).apply {
addMaxEnchantment(Enchantments.PROTECTION)
addMaxEnchantment(Enchantments.FEATHER_FALLING)
addMaxEnchantment(Enchantments.DEPTH_STRIDER)
addMaxEnchantment(Enchantments.UNBREAKING)
addMaxEnchantment(Enchantments.MENDING)
}
}
private fun ItemStack.addMaxEnchantment(enchantment: Enchantment) {
addEnchantment(enchantment, enchantment.maxLevel)
}
private fun EntityPlayer.addGappleEffects() {
addPotionEffectForce(PotionEffect(MobEffects.REGENERATION, Int.MAX_VALUE, 1))
addPotionEffectForce(PotionEffect(MobEffects.ABSORPTION, Int.MAX_VALUE, 3))
addPotionEffectForce(PotionEffect(MobEffects.RESISTANCE, Int.MAX_VALUE, 0))
addPotionEffectForce(PotionEffect(MobEffects.FIRE_RESISTANCE, Int.MAX_VALUE, 0))
}
private fun EntityPlayer.addPotionEffectForce(potionEffect: PotionEffect) {
addPotionEffect(potionEffect)
potionEffect.potion.applyAttributesModifiersToEntity(this, this.attributeMap, potionEffect.amplifier)
}
}