diff options
| author | Lorenz <lo.scherf@gmail.com> | 2022-08-17 03:05:34 +0200 |
|---|---|---|
| committer | Lorenz <lo.scherf@gmail.com> | 2022-08-17 03:05:34 +0200 |
| commit | ef58a94bf31868c4b53218474f0be04c1cd93d97 (patch) | |
| tree | cb56d5969f8bebf586298475a61c521229663fda /src/main/java/at/hannibal2/skyhanni/features | |
| parent | 5669dbf6f68e7cacb2df6a4e37d703df8635353e (diff) | |
| download | skyhanni-ef58a94bf31868c4b53218474f0be04c1cd93d97.tar.gz skyhanni-ef58a94bf31868c4b53218474f0be04c1cd93d97.tar.bz2 skyhanni-ef58a94bf31868c4b53218474f0be04c1cd93d97.zip | |
moving packets around
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features')
41 files changed, 4426 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/ButtonOnPause.kt b/src/main/java/at/hannibal2/skyhanni/features/ButtonOnPause.kt new file mode 100644 index 000000000..4e85f4399 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/ButtonOnPause.kt @@ -0,0 +1,51 @@ +package at.hannibal2.skyhanni.features + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.config.gui.config.ConfigEditor +import at.hannibal2.skyhanni.config.gui.core.GuiScreenElementWrapper +import at.hannibal2.skyhanni.utils.LorenzUtils +import net.minecraft.client.gui.GuiButton +import net.minecraft.client.gui.GuiIngameMenu +import net.minecraftforge.client.event.GuiScreenEvent +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +class ButtonOnPause { + private val buttonId = System.nanoTime().toInt() + + @SubscribeEvent + fun onGuiAction(event: GuiScreenEvent.ActionPerformedEvent.Post) { + if (!LorenzUtils.isOnHypixel) return + + if (SkyHanniMod.feature.misc.configButtonOnPause && event.gui is GuiIngameMenu && event.button.id == buttonId) { + SkyHanniMod.screenToOpen = GuiScreenElementWrapper( + ConfigEditor( + SkyHanniMod.feature + ) + ) + } + } + + @SubscribeEvent + fun onGuiInitPost(event: GuiScreenEvent.InitGuiEvent.Post) { + if (!LorenzUtils.isOnHypixel) return + + if (SkyHanniMod.feature.misc.configButtonOnPause && event.gui is GuiIngameMenu) { + val x = event.gui.width - 105 + val x2 = x + 100 + var y = event.gui.height - 22 + var y2 = y + 20 + val sorted = event.buttonList.sortedWith { a, b -> b.yPosition + b.height - a.yPosition + a.height } + for (button in sorted) { + val otherX = button.xPosition + val otherX2 = button.xPosition + button.width + val otherY = button.yPosition + val otherY2 = button.yPosition + button.height + if (otherX2 > x && otherX < x2 && otherY2 > y && otherY < y2) { + y = otherY - 20 - 2 + y2 = y + 20 + } + } + event.buttonList.add(GuiButton(buttonId, x, 0.coerceAtLeast(y), 100, 20, "SkyHanni")) + } + } +}
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/CurrentPetDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/CurrentPetDisplay.kt new file mode 100644 index 000000000..f0e8e033e --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/CurrentPetDisplay.kt @@ -0,0 +1,47 @@ +package at.hannibal2.skyhanni.features + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.events.LorenzChatEvent +import at.hannibal2.skyhanni.utils.GuiRender.renderString +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.LorenzUtils.between +import at.hannibal2.skyhanni.utils.LorenzUtils.matchRegex +import net.minecraftforge.client.event.RenderGameOverlayEvent +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +class CurrentPetDisplay { + + @SubscribeEvent + fun onChatMessage(event: LorenzChatEvent) { + if (!LorenzUtils.inSkyblock) return + + var blocked = false + + val message = event.message + if (message.matchRegex("§aYou summoned your §r(.*)§r§a!")) { + SkyHanniMod.feature.hidden.currentPet = message.between("your §r", "§r§a") + blocked = true + } + if (message.matchRegex("§cAutopet §eequipped your §7(.*)§e! §a§lVIEW RULE")) { + SkyHanniMod.feature.hidden.currentPet = message.between("] ", "§e!") + blocked = true + } + if (message.matchRegex("§aYou despawned your §r(.*)§r§a!")) { + SkyHanniMod.feature.hidden.currentPet = "" + blocked = true + } + + if (blocked && SkyHanniMod.feature.misc.petDisplay) { + event.blockedReason = "pets" + } + } + + @SubscribeEvent + fun renderOverlay(event: RenderGameOverlayEvent.Post) { + if (!LorenzUtils.inSkyblock) return + + if (!SkyHanniMod.feature.misc.petDisplay) return + + SkyHanniMod.feature.misc.petDisplayPos.renderString(SkyHanniMod.feature.hidden.currentPet) + } +}
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/ExpBottleOnGroundHider.kt b/src/main/java/at/hannibal2/skyhanni/features/ExpBottleOnGroundHider.kt new file mode 100644 index 000000000..c9e2b4bf4 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/ExpBottleOnGroundHider.kt @@ -0,0 +1,19 @@ +package at.hannibal2.skyhanni.features + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.events.CheckRenderEntityEvent +import at.hannibal2.skyhanni.utils.LorenzUtils +import net.minecraft.entity.item.EntityXPOrb +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +class ExpBottleOnGroundHider { + @SubscribeEvent + fun onCheckRender(event: CheckRenderEntityEvent<*>) { + if (!LorenzUtils.inSkyblock) return + if (!SkyHanniMod.feature.misc.hideExpBottles) return + + if (event.entity is EntityXPOrb) { + event.isCanceled = true + } + } +}
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/SummoningSoulsName.kt b/src/main/java/at/hannibal2/skyhanni/features/SummoningSoulsName.kt new file mode 100644 index 000000000..478cdc100 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/SummoningSoulsName.kt @@ -0,0 +1,135 @@ +package at.hannibal2.skyhanni.features + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.features.damageindicator.hasNameTagWith +import at.hannibal2.skyhanni.test.GriffinJavaUtils +import at.hannibal2.skyhanni.utils.ItemUtils.getSkullTexture +import at.hannibal2.skyhanni.utils.LocationUtils +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.LorenzVec +import at.hannibal2.skyhanni.utils.RenderUtils.drawString +import at.hannibal2.skyhanni.utils.getLorenzVec +import net.minecraft.client.Minecraft +import net.minecraft.entity.EntityLiving +import net.minecraft.entity.item.EntityArmorStand +import net.minecraftforge.client.event.RenderWorldLastEvent +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import net.minecraftforge.fml.common.gameevent.TickEvent +import java.util.concurrent.atomic.AtomicReference + +class SummoningSoulsName { + + var tick = 0 + val texture = + "ewogICJ0aW1lc3RhbXAiIDogMTYwMTQ3OTI2NjczMywKICAicHJvZmlsZUlkIiA6ICJmMzA1ZjA5NDI0NTg0ZjU" + + "4YmEyYjY0ZjAyZDcyNDYyYyIsCiAgInByb2ZpbGVOYW1lIiA6ICJqcm9ja2EzMyIsCiAgInNpZ25hdH" + + "VyZVJlcXVpcmVkIiA6IHRydWUsCiAgInRleHR1cmVzIiA6IHsKICAgICJTS0lOIiA6IHsKICAgICAgI" + + "nVybCIgOiAiaHR0cDovL3RleHR1cmVzLm1pbmVjcmFmdC5uZXQvdGV4dHVyZS81YWY0MDM1ZWMwZGMx" + + "NjkxNzc4ZDVlOTU4NDAxNzAyMjdlYjllM2UyOTQzYmVhODUzOTI5Y2U5MjNjNTk4OWFkIgogICAgfQogIH0KfQ" + + val souls = mutableMapOf<EntityArmorStand, String>() + val mobsLastLocation = mutableMapOf<EntityLiving, LorenzVec>() + val mobsName = mutableMapOf<EntityLiving, String>() + + @SubscribeEvent + fun onTick(event: TickEvent.ClientTickEvent) { + if (!isEnabled()) return + + tick++ + //TODO use packets instead of this + if (tick % 1 == 0) { + check() + } + } + + private fun check() { + val minecraft = Minecraft.getMinecraft() + val world = minecraft.theWorld + for (entity in world.loadedEntityList) { + if (souls.contains(entity)) continue + + if (entity is EntityArmorStand) { + if (isSoul(entity)) { + val soulLocation = entity.getLorenzVec() + + val map = mutableMapOf<EntityLiving, Double>() + for ((mob, loc) in mobsLastLocation) { + val distance = loc.distance(soulLocation) + map[mob] = distance + } + + val nearestMob = GriffinJavaUtils.sortByValueAsc(map).firstNotNullOfOrNull { it.key } + if (nearestMob != null) { +// val mobDistance = nearestMob.getLorenzVec().add(0.0, -1.4375, 0.0) +// val distance = mobDistance.distance(soulLocation) +// val diff = mobDistance.add(soulLocation.multiply(-1)) + +// println(" ") +// println("mobDistance: $mobDistance") +// println("soulLocation: $soulLocation") +// println("diff: $diff") +// LorenzUtils.chat("distance: $distance") + val name = mobsName[nearestMob]!! +// LorenzUtils.chat("maybe its $name") + souls[entity] = name + } + + } + } + } + + for (entity in world.loadedEntityList) { + + if (entity is EntityLiving) { + val boo = AtomicReference<String>() + if (entity.hasNameTagWith(2, "§c❤", consumer = { + if (!it.name.contains("§e0")) { + boo.set(it.name) + } + })) { + val name = boo.get() + if (name != null) { + mobsLastLocation[entity] = entity.getLorenzVec() + mobsName[entity] = name + } + } + } + } + + souls.keys.removeIf { it !in world.loadedEntityList } + //TODO fix overhead! +// mobs.keys.removeIf { it !in world.loadedEntityList } + } + + @SubscribeEvent + fun onWorldRender(event: RenderWorldLastEvent) { + if (!isEnabled()) return + + val playerLocation = LocationUtils.playerEyeLocation() + for ((entity, name) in souls) { + val vec = entity.getLorenzVec() + if (LocationUtils.canSee(playerLocation, vec.add(0.0, 2.0, 0.0))) { + event.drawString(vec.add(0.0, 2.5, 0.0), name, true) + } + } + } + + private fun isSoul(entity: EntityArmorStand): Boolean { + for (stack in entity.inventory) { + if (stack != null) { + val skullTexture = stack.getSkullTexture() + if (skullTexture != null) { + if (skullTexture == texture) { + return true + } + } + } + } + + return false + } + + private fun isEnabled(): Boolean { + return LorenzUtils.inSkyblock && SkyHanniMod.feature.misc.summonSoulDisplay + } +}
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/anvil/AnvilCombineHelper.kt b/src/main/java/at/hannibal2/skyhanni/features/anvil/AnvilCombineHelper.kt new file mode 100644 index 000000000..251c4e7a6 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/anvil/AnvilCombineHelper.kt @@ -0,0 +1,82 @@ +package at.hannibal2.skyhanni.features.anvil + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.events.GuiContainerEvent +import at.hannibal2.skyhanni.utils.ItemUtils.getLore +import at.hannibal2.skyhanni.utils.LorenzColor +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.RenderUtils.highlight +import net.minecraft.client.gui.inventory.GuiChest +import net.minecraft.client.renderer.GlStateManager +import net.minecraft.inventory.ContainerChest +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import org.lwjgl.opengl.GL11 + +class AnvilCombineHelper { + + @SubscribeEvent + fun onBackgroundDrawn(event: GuiContainerEvent.BackgroundDrawnEvent) { + if (!LorenzUtils.inSkyblock) return + if (!SkyHanniMod.feature.inventory.anvilCombineHelper) return + + if (event.gui !is GuiChest) return + val guiChest = event.gui + val chest = guiChest.inventorySlots as ContainerChest + val chestName = chest.lowerChestInventory.displayName.unformattedText.trim() + + if (chestName != "Anvil") return + + val matchLore = mutableListOf<String>() +// var compareItem: ItemStack? = null + + for (slot in chest.inventorySlots) { + if (slot == null) continue + + if (slot.slotNumber != slot.slotIndex) continue + if (slot.stack == null) continue + + if (slot.slotNumber == 29) { +// slot highlight LorenzColor.GREEN + val lore = slot.stack.getLore() +// compareItem = slot.stack + matchLore.addAll(lore) + break +// } else if (slot.slotIndex == 29) { +// slot highlight LorenzColor.YELLOW + } + } + + val lightingState = GL11.glIsEnabled(GL11.GL_LIGHTING) + GlStateManager.disableLighting() + GlStateManager.color(1f, 1f, 1f, 1f) + + if (matchLore.isEmpty()) return + + for (slot in chest.inventorySlots) { + if (slot == null) continue + + if (slot.slotNumber == slot.slotIndex) continue + if (slot.stack == null) continue + + + if (matchLore == slot.stack.getLore()) { + slot highlight LorenzColor.GREEN + } + +// if (compareItem == slot.stack) { +// slot highlight LorenzColor.GREEN +// } else if (compareItem.metadata == slot.stack.metadata) { +// slot highlight LorenzColor.YELLOW +// } + +// if (slot.slotNumber == 3) { +//// slot highlight LorenzColor.GREEN +//// } else if (slot.slotIndex == 4) { +//// slot highlight LorenzColor.YELLOW +//// } +// } + + if (lightingState) GlStateManager.enableLighting() + } + } +}
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarApi.kt b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarApi.kt new file mode 100644 index 000000000..3de78206b --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarApi.kt @@ -0,0 +1,59 @@ +package at.hannibal2.skyhanni.features.bazaar + +import at.hannibal2.skyhanni.utils.LorenzUtils + +class BazaarApi { + + companion object { + private val bazaarMap = mutableMapOf<String, BazaarData>() + + fun isBazaarInventory(inventoryName: String): Boolean { + if (inventoryName.contains(" ➜ ") && !inventoryName.contains("Museum")) return true + if (BazaarOrderHelper.isBazaarOrderInventory(inventoryName)) return true + + return when (inventoryName) { + "Your Bazaar Orders" -> true + "How many do you want?" -> true + "How much do you want to pay?" -> true + "Confirm Buy Order" -> true + "Confirm Instant Buy" -> true + "At what price are you selling?" -> true + "Confirm Sell Offer" -> true + "Order options" -> true + + else -> false + } + } + + fun getCleanBazaarName(name: String): String { + if (name.endsWith(" Gemstone")) { + return name.substring(6) + } + if (name.startsWith("§")) { + return name.substring(2) + } + + return name + } + + fun getBazaarDataForName(name: String): BazaarData { + if (bazaarMap.containsKey(name)) { + val bazaarData = bazaarMap[name] + if (bazaarData != null) { + return bazaarData + } + LorenzUtils.error("Bazaar data is null for item '$name'") + } + throw Error("no bz data found for name '$name'") + } + + fun isBazaarItem(name: String): Boolean { + val bazaarName = getCleanBazaarName(name) + return bazaarMap.containsKey(bazaarName) + } + } + + init { + BazaarDataGrabber(bazaarMap).start() + } +}
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarBestSellMethod.kt b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarBestSellMethod.kt new file mode 100644 index 000000000..c4afc33fc --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarBestSellMethod.kt @@ -0,0 +1,79 @@ +package at.hannibal2.skyhanni.features.bazaar + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.events.GuiContainerEvent +import at.hannibal2.skyhanni.utils.GuiRender.renderString +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.NumberUtil +import net.minecraft.client.gui.inventory.GuiChest +import net.minecraft.inventory.ContainerChest +import net.minecraftforge.client.event.GuiScreenEvent +import net.minecraftforge.fml.common.eventhandler.EventPriority +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +class BazaarBestSellMethod { + + companion object { + private var textToRender = "" + } + + @SubscribeEvent + fun onBackgroundDrawn(event: GuiContainerEvent.CloseWindowEvent) { + textToRender = "" + } + + @SubscribeEvent + fun onGuiDrawEvent(event: GuiScreenEvent.DrawScreenEvent.Post) { + if (!isEnabled()) return + textToRender = getNewText(event) + } + + private fun getNewText(event: GuiScreenEvent.DrawScreenEvent.Post): String { + try { + if (event.gui !is GuiChest) return "" + val chest = (event.gui as GuiChest).inventorySlots as ContainerChest + + val inv = chest.lowerChestInventory ?: return "" + + val buyInstantly = inv.getStackInSlot(10) + if (buyInstantly == null || buyInstantly.displayName != "§aBuy Instantly") return "" + val bazaarItem = inv.getStackInSlot(13) ?: return "" + var name = bazaarItem.displayName + name = BazaarApi.getCleanBazaarName(name) + val data = BazaarApi.getBazaarDataForName(name) + + var having = 0 + for (slot in chest.inventorySlots) { + if (slot == null) continue + if (slot.slotNumber == slot.slotIndex) continue + if (slot.stack == null) continue + val stack = slot.stack + val displayName = stack.displayName + if (BazaarApi.getCleanBazaarName(displayName) == name) { + having += stack.stackSize + } + } + + if (having <= 0) return "" + + val totalDiff = (data.buyPrice - data.sellPrice) * having + val result = NumberUtil.format(totalDiff.toInt()) + + return "§b$name§f sell difference: §e$result coins" + } catch (e: Error) { + e.printStackTrace() + return "" + } + } + + @SubscribeEvent(priority = EventPriority.LOWEST) + fun renderOverlay(event: GuiScreenEvent.BackgroundDrawnEvent) { + if (!isEnabled()) return + + SkyHanniMod.feature.bazaar.bestSellMethodPos.renderString(textToRender) + } + + private fun isEnabled(): Boolean { + return LorenzUtils.inSkyblock && SkyHanniMod.feature.bazaar.bestSellMethod + } +}
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarData.kt b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarData.kt new file mode 100644 index 000000000..b43cb1eb3 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarData.kt @@ -0,0 +1,3 @@ +package at.hannibal2.skyhanni.features.bazaar + +data class BazaarData(val apiName: String, val itemName: String, val sellPrice: Double, val buyPrice: Double)
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarDataGrabber.kt b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarDataGrabber.kt new file mode 100644 index 000000000..324f180de --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarDataGrabber.kt @@ -0,0 +1,113 @@ +package at.hannibal2.skyhanni.features.bazaar + +import at.hannibal2.skyhanni.utils.APIUtil +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.LorenzUtils.round +import kotlin.concurrent.fixedRateTimer + +internal class BazaarDataGrabber(private var bazaarMap: MutableMap<String, BazaarData>) { + + companion object { + private val itemNames = mutableMapOf<String, String>() + + private var lastData = "" + var lastTime = 0L + var blockNoChange = false + var currentlyUpdating = false + } + + private fun loadItemNames(): Boolean { + currentlyUpdating = true + try { + val itemsData = APIUtil.getJSONResponse("https://api.hypixel.net/resources/skyblock/items") + for (element in itemsData["items"].asJsonArray) { + val jsonObject = element.asJsonObject + val name = jsonObject["name"].asString + val id = jsonObject["id"].asString + itemNames[id] = name + } + currentlyUpdating = false + return true + } catch (e: Throwable) { + e.printStackTrace() + LorenzUtils.error("Error while trying to read bazaar item list from api: " + e.message) + currentlyUpdating = false + return false + } + } + + fun start() { + fixedRateTimer(name = "skyhanni-bazaar-update", period = 1000L) { + if (!LorenzUtils.inSkyblock) { + return@fixedRateTimer + } + + if (currentlyUpdating) { + LorenzUtils.error("Bazaar update took too long! Error?") + return@fixedRateTimer |
