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

Commit

Permalink
[refactor] Rewrote InventoryUtils (#1837)
Browse files Browse the repository at this point in the history
Co-authored-by: Dominika <[email protected]>
  • Loading branch information
Luna5ama and 5HT2 authored Jan 11, 2021
1 parent 4ea6fd9 commit 566e9c5
Show file tree
Hide file tree
Showing 57 changed files with 1,152 additions and 988 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ object DiscordNotifsCommand : ClientCommand(
literal("id") {
long("discord user id") { idArg ->
execute("Set the ID of the user to be pinged") {
DiscordNotifs.pingID.value = idArg.value.toString()
DiscordNotifs.pingID.value = idArg.value.toString()
MessageSendHelper.sendChatMessage("Set Discord User ID to ${formatValue(idArg.value.toString())}!")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package me.zeroeightsix.kami.command.commands

import me.zeroeightsix.kami.command.ClientCommand
import me.zeroeightsix.kami.event.SafeExecuteEvent
import me.zeroeightsix.kami.util.itemPayload
import me.zeroeightsix.kami.util.items.itemPayload
import me.zeroeightsix.kami.util.text.MessageSendHelper
import net.minecraft.item.ItemWritableBook
import net.minecraft.nbt.NBTTagList
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package me.zeroeightsix.kami.command.commands

import me.zeroeightsix.kami.command.ClientCommand
import me.zeroeightsix.kami.module.modules.player.InventoryManager
import me.zeroeightsix.kami.util.block
import me.zeroeightsix.kami.util.id
import me.zeroeightsix.kami.util.items.block
import me.zeroeightsix.kami.util.items.id
import me.zeroeightsix.kami.util.text.MessageSendHelper
import net.minecraft.block.BlockAir

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package me.zeroeightsix.kami.command.commands

import me.zeroeightsix.kami.command.ClientCommand
import me.zeroeightsix.kami.util.itemPayload
import me.zeroeightsix.kami.util.items.itemPayload
import me.zeroeightsix.kami.util.text.MessageSendHelper
import me.zeroeightsix.kami.util.text.MessageSendHelper.sendChatMessage
import me.zeroeightsix.kami.util.text.formatValue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package me.zeroeightsix.kami.gui.hudgui.elements.combat

import me.zeroeightsix.kami.gui.hudgui.HudElement
import me.zeroeightsix.kami.setting.GuiConfig.setting
import me.zeroeightsix.kami.util.InventoryUtils
import me.zeroeightsix.kami.util.color.ColorGradient
import me.zeroeightsix.kami.util.color.ColorHolder
import me.zeroeightsix.kami.util.graphics.RenderUtils2D
import me.zeroeightsix.kami.util.graphics.VertexHelper
import me.zeroeightsix.kami.util.graphics.font.FontRenderAdapter
import me.zeroeightsix.kami.util.graphics.font.HAlign
import me.zeroeightsix.kami.util.graphics.font.VAlign
import me.zeroeightsix.kami.util.items.allSlots
import me.zeroeightsix.kami.util.items.countItem
import me.zeroeightsix.kami.util.threads.safeAsyncListener
import net.minecraft.client.renderer.GlStateManager
import net.minecraft.init.Items
Expand Down Expand Up @@ -55,13 +56,15 @@ object Armor : HudElement(
safeAsyncListener<TickEvent.ClientTickEvent> { event ->
if (event.phase != TickEvent.Phase.END) return@safeAsyncListener

armorCounts[0] = InventoryUtils.countItemAll(Items.DIAMOND_HELMET)
armorCounts[1] = InventoryUtils.countItemAll(
val slots = player.allSlots

armorCounts[0] = slots.countItem(Items.DIAMOND_HELMET)
armorCounts[1] = slots.countItem(
if (countElytras.value && player.inventory.getStackInSlot(38).item == Items.ELYTRA) Items.ELYTRA
else Items.DIAMOND_CHESTPLATE
)
armorCounts[2] = InventoryUtils.countItemAll(Items.DIAMOND_LEGGINGS)
armorCounts[3] = InventoryUtils.countItemAll(Items.DIAMOND_BOOTS)
armorCounts[2] = slots.countItem(Items.DIAMOND_LEGGINGS)
armorCounts[3] = slots.countItem(Items.DIAMOND_BOOTS)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import me.zeroeightsix.kami.event.SafeClientEvent
import me.zeroeightsix.kami.gui.hudgui.HudElement
import me.zeroeightsix.kami.gui.hudgui.LabelHud
import me.zeroeightsix.kami.setting.GuiConfig.setting
import me.zeroeightsix.kami.util.InventoryUtils
import me.zeroeightsix.kami.util.graphics.RenderUtils2D
import me.zeroeightsix.kami.util.graphics.VertexHelper
import me.zeroeightsix.kami.util.items.allSlots
import me.zeroeightsix.kami.util.items.countItem
import net.minecraft.client.renderer.GlStateManager
import net.minecraft.init.Items
import net.minecraft.item.ItemStack
Expand Down Expand Up @@ -64,8 +65,10 @@ object CombatItemCount : LabelHud(
}

override fun SafeClientEvent.updateText() {
val slots = player.allSlots

for ((index, entry) in itemSettings.entries.withIndex()) {
val count = if (entry.key.value) entry.value.sumBy { InventoryUtils.countItemAll(it) }
val count = if (entry.key.value) entry.value.sumBy { slots.countItem(it) }
else -1

if (showIcon) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import me.zeroeightsix.kami.setting.GuiConfig.setting
import me.zeroeightsix.kami.util.EntityUtils.isHostile
import me.zeroeightsix.kami.util.EntityUtils.isNeutral
import me.zeroeightsix.kami.util.EntityUtils.isPassive
import me.zeroeightsix.kami.util.originalName
import me.zeroeightsix.kami.util.items.originalName
import me.zeroeightsix.kami.util.threads.defaultScope
import net.minecraft.entity.Entity
import net.minecraft.entity.item.*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ object FriendManager : Manager {
}

data class FriendFile(
@SerializedName("Enabled")
var enabled: Boolean = true,
@SerializedName("Enabled")
var enabled: Boolean = true,

@SerializedName("Friends")
val friends: MutableSet<PlayerProfile> = Collections.synchronizedSet(LinkedHashSet<PlayerProfile>())
@SerializedName("Friends")
val friends: MutableSet<PlayerProfile> = Collections.synchronizedSet(LinkedHashSet<PlayerProfile>())
) {
override fun equals(other: Any?): Boolean {
if (this === other) return true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ object MessageManager : Manager {
if (it.packet !is CPacketChatMessage || packetSet.remove(it.packet)) return@listener
it.cancel()
if (it.packet.message != lastPlayerMessage) addMessageToQueue(it.packet, it)
else addMessageToQueue(it.packet, mc.player?: it, Int.MAX_VALUE - 1)
else addMessageToQueue(it.packet, mc.player ?: it, Int.MAX_VALUE - 1)
}

safeListener<TickEvent.ClientTickEvent>(-69420) { event ->
Expand Down Expand Up @@ -80,11 +80,11 @@ object MessageManager : Manager {
}

data class QueuedMessage(
private val id: Int,
private val priority: Int,
val source: Any,
val packet: CPacketChatMessage,
val state: TaskState = TaskState()
private val id: Int,
private val priority: Int,
val source: Any,
val packet: CPacketChatMessage,
val state: TaskState = TaskState()
) : Comparable<QueuedMessage> {

override fun compareTo(other: QueuedMessage): Int {
Expand All @@ -96,14 +96,14 @@ object MessageManager : Manager {
}

fun Module.newMessageModifier(filter: (QueuedMessage) -> Boolean = { true }, modifier: (QueuedMessage) -> String) =
MessageModifier(modifierId++, modulePriority, filter, modifier)
MessageModifier(modifierId++, modulePriority, filter, modifier)

class MessageModifier(
private val id: Int,
private val priority: Int,
private val filter: (QueuedMessage) -> Boolean = {true},
private val modifier: (QueuedMessage) -> String
): Comparable<MessageModifier> {
private val id: Int,
private val priority: Int,
private val filter: (QueuedMessage) -> Boolean = { true },
private val modifier: (QueuedMessage) -> String
) : Comparable<MessageModifier> {

/**
* Adds this modifier to the active modifier set [activeModifiers]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import me.zeroeightsix.kami.event.events.RenderOverlayEvent
import me.zeroeightsix.kami.manager.Manager
import me.zeroeightsix.kami.module.Module
import me.zeroeightsix.kami.util.*
import me.zeroeightsix.kami.util.items.clickSlot
import me.zeroeightsix.kami.util.items.removeHoldingItem
import me.zeroeightsix.kami.util.threads.safeListener
import net.minecraft.client.gui.inventory.GuiContainer
import net.minecraft.inventory.ClickType
import org.kamiblue.event.listener.listener
import java.util.*

object PlayerInventoryManager : Manager {
private val mc = Wrapper.minecraft
private val timer = TickTimer()
private val lockObject = Any()
private val actionQueue = TreeSet<InventoryTask>(Comparator.reverseOrder())
Expand All @@ -20,18 +22,18 @@ object PlayerInventoryManager : Manager {
private var currentTask: InventoryTask? = null

init {
listener<RenderOverlayEvent>(0) {
if (mc.player == null || !timer.tick((1000.0f / TpsCalculator.tickRate).toLong())) return@listener
safeListener<RenderOverlayEvent>(0) {
if (!timer.tick((1000.0f / TpsCalculator.tickRate).toLong())) return@safeListener

if (!mc.player.inventory.itemStack.isEmpty) {
if (!player.inventory.itemStack.isEmpty) {
if (mc.currentScreen is GuiContainer) timer.reset(250L) // Wait for 5 extra ticks if player is moving item
else InventoryUtils.removeHoldingItem()
return@listener
else removeHoldingItem()
return@safeListener
}

getTaskOrNext()?.nextInfo()?.let {
InventoryUtils.inventoryClick(it.windowId, it.slot, it.mouseButton, it.type)
mc.playerController?.updateController()
clickSlot(it.windowId, it.slot, it.mouseButton, it.type)
playerController.updateController()
}

if (actionQueue.isEmpty()) currentId = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ object PlayerPacketManager : Manager {
fun resetHotbar() {
if (!spoofingHotbar) return
spoofingHotbar = false
Wrapper.minecraft.connection?.sendPacket(CPacketHeldItemChange(Wrapper.minecraft.playerController?.currentPlayerItem ?: 0))
Wrapper.minecraft.connection?.sendPacket(CPacketHeldItemChange(Wrapper.minecraft.playerController?.currentPlayerItem
?: 0))
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ object WaypointManager : Manager {

fun genServer(): String? {
return Wrapper.minecraft.currentServerData?.serverIP
?: if (Wrapper.minecraft.isIntegratedServerRunning) "Singleplayer"
else null
?: if (Wrapper.minecraft.isIntegratedServerRunning) "Singleplayer"
else null
}

fun genDimension(): Int {
Expand All @@ -147,12 +147,12 @@ object WaypointManager : Manager {
}

class Waypoint(
@SerializedName("position")
val pos: BlockPos,
val name: String,
@SerializedName("position")
val pos: BlockPos,
val name: String,

@SerializedName(value = "date", alternate = ["time"])
val date: String
@SerializedName(value = "date", alternate = ["time"])
val date: String
) {
val id: Int = genID()
val server: String? = genServer() /* can be null from old configs */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package me.zeroeightsix.kami.module.modules.chat

import me.zeroeightsix.kami.KamiMod
import me.zeroeightsix.kami.command.CommandManager
import me.zeroeightsix.kami.event.events.PacketEvent
import me.zeroeightsix.kami.manager.managers.FriendManager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package me.zeroeightsix.kami.module.modules.combat
import me.zeroeightsix.kami.manager.managers.CombatManager
import me.zeroeightsix.kami.module.Module
import me.zeroeightsix.kami.setting.ModuleConfig.setting
import me.zeroeightsix.kami.util.InventoryUtils
import me.zeroeightsix.kami.util.items.swapToItem
import me.zeroeightsix.kami.util.math.RotationUtils.faceEntityClosest
import me.zeroeightsix.kami.util.threads.safeListener
import net.minecraft.init.Items
Expand All @@ -16,15 +16,16 @@ object AimBot : Module(
category = Category.COMBAT,
modulePriority = 20
) {
private val bowOnly = setting("BowOnly", true)
private val autoSwap = setting("AutoSwap", false, { bowOnly.value })
private val bowOnly by setting("BowOnly", true)
private val autoSwap by setting("AutoSwap", false)

init {
safeListener<TickEvent.ClientTickEvent> {
if (bowOnly.value && player.heldItemMainhand.item != Items.BOW) {
if (autoSwap.value) InventoryUtils.swapSlotToItem(261)
return@safeListener
if (player.heldItemMainhand.item != Items.BOW) {
if (autoSwap) swapToItem(Items.BOW)
if (bowOnly) return@safeListener
}

CombatManager.target?.let {
faceEntityClosest(it)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package me.zeroeightsix.kami.module.modules.combat
import me.zeroeightsix.kami.event.events.PacketEvent
import me.zeroeightsix.kami.module.Module
import me.zeroeightsix.kami.setting.ModuleConfig.setting
import me.zeroeightsix.kami.util.InventoryUtils
import me.zeroeightsix.kami.util.items.allSlots
import me.zeroeightsix.kami.util.items.countItem
import me.zeroeightsix.kami.util.threads.safeListener
import net.minecraft.init.Items
import net.minecraft.network.play.server.SPacketEntityStatus
import net.minecraftforge.fml.common.gameevent.TickEvent

Expand Down Expand Up @@ -32,7 +34,7 @@ object AntiChainPop : Module(
safeListener<TickEvent.ClientTickEvent> {
if (mode == Mode.ITEMS) return@safeListener
val old = totems
val new = InventoryUtils.countItemAll(449)
val new = player.allSlots.countItem(Items.TOTEM_OF_UNDYING)
if (new < old) Surround.enable()
totems = new
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import me.zeroeightsix.kami.manager.managers.PlayerInventoryManager.addInventory
import me.zeroeightsix.kami.module.Module
import me.zeroeightsix.kami.setting.ModuleConfig.setting
import me.zeroeightsix.kami.util.*
import me.zeroeightsix.kami.util.items.removeHoldingItem
import me.zeroeightsix.kami.util.threads.safeListener
import net.minecraft.client.gui.inventory.GuiContainer
import net.minecraft.init.Items
Expand All @@ -31,7 +32,7 @@ object AutoArmor : Module(

if (!player.inventory.itemStack.isEmpty) {
if (mc.currentScreen is GuiContainer) timer.reset(150L) // Wait for 3 extra ticks if player is moving item
else InventoryUtils.removeHoldingItem()
else removeHoldingItem()
return@safeListener
}
// store slots and values of best armor pieces, initialize with currently equipped armor
Expand Down
Loading

0 comments on commit 566e9c5

Please sign in to comment.