Skip to content

Commit

Permalink
Some utils replaced with extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
ya-ilya committed Sep 24, 2023
1 parent 13c432f commit 5fe6312
Show file tree
Hide file tree
Showing 13 changed files with 140 additions and 142 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import org.progreso.api.module.AbstractModule
import org.progreso.client.Client.Companion.mc
import org.progreso.client.events.misc.TickEvent
import org.progreso.client.events.safeEventListener
import org.progreso.client.util.entity.EntityUtil.canBeAttacked
import org.progreso.client.util.player.PlayerUtil
import org.progreso.client.util.entity.canBeAttacked
import org.progreso.client.util.player.attack

@AbstractModule.AutoRegister
object KillAura : AbstractModule() {
Expand Down Expand Up @@ -53,7 +53,7 @@ object KillAura : AbstractModule() {
}

if (entity != null) {
PlayerUtil.attack(entity)
mc.interactionManager.attack(entity)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import org.progreso.api.module.AbstractModule
import org.progreso.client.Client.Companion.mc
import org.progreso.client.events.misc.TickEvent
import org.progreso.client.events.safeEventListener
import org.progreso.client.util.player.InventoryUtil
import org.progreso.client.util.player.findItem
import org.progreso.client.util.player.moveItem

@AbstractModule.AutoRegister
object Offhand : AbstractModule() {
Expand All @@ -33,10 +34,10 @@ object Offhand : AbstractModule() {

fun switch() {
if (mc.player.offHandStack.item == item) return
val slot = InventoryUtil.findItem(fromIndex = 9) { _, stack -> stack.item == item }
val slot = mc.player.inventory.findItem(fromIndex = 9) { _, stack -> stack.item == item }

if (slot != null) {
InventoryUtil.moveItem(slot.index, 45)
mc.interactionManager.moveItem(slot.index, 45)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,19 @@ import org.progreso.api.module.AbstractModule
import org.progreso.client.Client.Companion.mc
import org.progreso.client.events.block.DamageBlockEvent
import org.progreso.client.events.safeEventListener
import org.progreso.client.util.player.InventoryUtil
import org.progreso.client.util.player.hotbar
import org.progreso.client.util.player.updateSelectedSlot

@AbstractModule.AutoRegister
object AutoTool : AbstractModule() {
init {
safeEventListener<DamageBlockEvent> { event ->
val best = InventoryUtil.hotbar
val best = mc.player.inventory.hotbar
.associateWith { getDestroySpeedForBlock(it.stack, event.pos) }
.maxByOrNull { it.value }

if (best != null && best.value > getDestroySpeedForBlock(mc.player.mainHandStack, event.pos)) {
InventoryUtil.updateSelectedSlot(best.key.index)
mc.player.inventory.updateSelectedSlot(best.key.index)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import org.progreso.api.module.AbstractModule
import org.progreso.client.Client.Companion.mc
import org.progreso.client.events.input.MouseEvent
import org.progreso.client.events.safeEventListener
import org.progreso.client.util.player.InventoryUtil
import org.progreso.client.util.player.findItemInHotbar

@AbstractModule.AutoRegister
object MiddleClickPearl : AbstractModule() {
Expand All @@ -17,7 +17,8 @@ object MiddleClickPearl : AbstractModule() {
return@safeEventListener

val previousSelectedSlot = mc.player.inventory.selectedSlot
val enderPearl = InventoryUtil.findItemInHotbar { _, stack -> stack.item == Items.ENDER_PEARL }
val enderPearl = mc.player.inventory
.findItemInHotbar { _, stack -> stack.item == Items.ENDER_PEARL }
?: return@safeEventListener

mc.player.inventory.selectedSlot = enderPearl.index
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import org.progreso.client.events.safeEventListener
import org.progreso.client.gui.clickgui.element.elements.ColorElement.Companion.copy
import org.progreso.client.modules.render.ESP.espSetting
import org.progreso.client.util.render.*
import org.progreso.client.util.world.WorldUtil.blockEntities
import org.progreso.client.util.world.blockEntities
import java.awt.Color

@AbstractModule.AutoRegister
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.progreso.client.util.entity

import net.minecraft.entity.Entity
import net.minecraft.entity.player.PlayerEntity
import org.progreso.api.managers.FriendManager
import org.progreso.client.Client

val Entity.canBeAttacked: Boolean
get() {
if (this == Client.mc.player) return false
if (!isAlive) return false
if (!isAttackable) return false
return !(this is PlayerEntity && FriendManager.isFriend(name.string))
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.progreso.client.util.player

import net.minecraft.client.network.ClientPlayerInteractionManager
import net.minecraft.entity.LivingEntity
import net.minecraft.util.Hand
import org.progreso.client.Client.Companion.mc

fun ClientPlayerInteractionManager.attack(entity: LivingEntity, checkStrength: Boolean = true) {
if (checkStrength && mc.player.getAttackCooldownProgress(mc.tickDelta) != 1.0f) {
return
}

attackEntity(mc.player, entity)
mc.player.swingHand(Hand.MAIN_HAND)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package org.progreso.client.util.player

import net.minecraft.client.network.ClientPlayerInteractionManager
import net.minecraft.entity.player.PlayerInventory
import net.minecraft.item.ItemStack
import net.minecraft.network.packet.c2s.play.UpdateSelectedSlotC2SPacket
import net.minecraft.screen.slot.SlotActionType
import org.progreso.client.Client.Companion.mc

data class Slot(val index: Int, val stack: ItemStack)

val PlayerInventory.hotbar get() = findItems(0, 9) { _, _ -> true }

fun PlayerInventory.findItemInHotbar(predicate: (Int, ItemStack) -> Boolean): Slot? {
return findItem(0, 9, predicate)
}

fun PlayerInventory.findItem(
fromIndex: Int? = null,
toIndex: Int? = null,
predicate: (Int, ItemStack) -> Boolean
): Slot? {
return findItems(fromIndex, toIndex, predicate).firstOrNull()
}

fun PlayerInventory.findItems(
fromIndex: Int? = null,
toIndex: Int? = null,
predicate: (Int, ItemStack) -> Boolean
): List<Slot> {
val result = mutableListOf<Slot>()

for (i in (fromIndex ?: 0)..<(toIndex ?: size())) {
val itemStack = getStack(i)

if (predicate(i, itemStack)) {
result.add(Slot(i, itemStack))
}
}

return result
}

fun PlayerInventory.updateSelectedSlot(index: Int) {
mc.networkHandler.sendPacket(UpdateSelectedSlotC2SPacket(index))
selectedSlot = index
}

fun ClientPlayerInteractionManager.moveItem(fromIndex: Int, toIndex: Int) {
val syncId = mc.player.currentScreenHandler?.syncId ?: 0

clickSlot(syncId, fromIndex, 0, SlotActionType.PICKUP, mc.player)
clickSlot(syncId, toIndex, 0, SlotActionType.PICKUP, mc.player)
clickSlot(syncId, fromIndex, 0, SlotActionType.PICKUP, mc.player)
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.progreso.client.util.world

import net.minecraft.block.entity.BlockEntity
import net.minecraft.util.math.ChunkPos
import net.minecraft.world.World
import net.minecraft.world.chunk.WorldChunk
import org.progreso.client.Client
import java.util.stream.Collectors
import java.util.stream.Stream
import kotlin.math.max

val World.blockEntities: List<BlockEntity>
get() {
return loadedChunks
.flatMap { it.blockEntities.values.stream() }
.collect(Collectors.toList())
}

val World.loadedChunks: Stream<WorldChunk>
get() {
val radius = max(2, Client.mc.options!!.clampedViewDistance) + 3
val diameter = radius * 2 + 1
val center = Client.mc.player.chunkPos
val min = ChunkPos(center.x - radius, center.z - radius)
val max = ChunkPos(center.x + radius, center.z + radius)

return Stream.iterate(min) {
var x = it.x
var z = it.z
x++
if (x > max.x) {
x = min.x
z++
}
check(z <= max.z)
ChunkPos(x, z)
}
.limit((diameter * diameter).toLong())
.filter { isChunkLoaded(it.x, it.z) }
.map { getChunk(it.x, it.z) }
}

This file was deleted.

0 comments on commit 5fe6312

Please sign in to comment.