Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backend: Remove more neu dependent code !!! #2738

Open
wants to merge 30 commits into
base: beta
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
2aea746
Backend: Add skyhanni notifications
CalMWolfs Oct 1, 2024
50e7a93
finish and use SkyHanniNotification
CalMWolfs Oct 1, 2024
faa5c81
display more info in the notification
CalMWolfs Oct 1, 2024
3216ae7
rename variable
CalMWolfs Oct 12, 2024
6461aa4
dont use neu button
CalMWolfs Oct 12, 2024
b1067b5
Merge branch 'refs/heads/beta' into buttoning
CalMWolfs Oct 14, 2024
5c9f15e
Merge branch 'refs/heads/beta' into notifications
CalMWolfs Oct 14, 2024
154319e
use new command system
CalMWolfs Oct 14, 2024
9cf9c02
Merge branch 'refs/heads/beta' into notifications
CalMWolfs Oct 14, 2024
68409ee
use new event name
CalMWolfs Oct 14, 2024
1a9f9f3
this code is nonsense rn but it will be useful in the future
NopoTheGamer Oct 14, 2024
a5b7425
neuapi
NopoTheGamer Oct 14, 2024
68ed9e4
pv
NopoTheGamer Oct 14, 2024
c50865e
delete fix neu heavy pearls (neu fixed the issue like 1 week later)
NopoTheGamer Oct 14, 2024
37c092c
dont use neu for locraw + locraw command
NopoTheGamer Oct 14, 2024
994e440
add Pseudo to neu mixin
NopoTheGamer Oct 14, 2024
6767f77
add checks when using neu config
NopoTheGamer Oct 14, 2024
da69890
calculator (this is probably weird behaviour but wtv rn
NopoTheGamer Oct 14, 2024
6bb14d8
forgot to remove config option for the pearls
NopoTheGamer Oct 14, 2024
d4d3a19
add check to neu has focus, didnt do the todo yet
NopoTheGamer Oct 14, 2024
d738048
Merge remote-tracking branch 'refs/remotes/CalMWolfs/buttoning' into …
NopoTheGamer Oct 14, 2024
9c6d984
Merge remote-tracking branch 'refs/remotes/CalMWolfs/notifications' i…
NopoTheGamer Oct 14, 2024
9e0278c
change horse mixin to be after neu (so never ?)
NopoTheGamer Oct 14, 2024
8b99634
add sh module flag to only load if neu, rn used for using neu events
NopoTheGamer Oct 14, 2024
15ee619
fix horse again
NopoTheGamer Oct 14, 2024
a833996
add comment
NopoTheGamer Oct 14, 2024
0b1ad9b
add locraw not delete users
NopoTheGamer Oct 14, 2024
ebaebe4
Merge branch 'beta' into remove-neus
CalMWolfs Oct 16, 2024
0f2837b
there was already a similar variable
CalMWolfs Oct 16, 2024
0ab0de1
Merge branch 'beta' into remove-neus
NopoTheGamer Oct 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ class ModuleProcessor(private val codeGenerator: CodeGenerator, private val logg
return annotation.arguments.find { it.name?.asString() == "devOnly" }?.value as? Boolean ?: false
}

private fun isNEUAnnotation(klass: KSClassDeclaration): Boolean {
val annotation = klass.annotations.find { it.shortName.asString() == "SkyHanniModule" } ?: return false
return annotation.arguments.find { it.name?.asString() == "neuRequired" }?.value as? Boolean ?: false
}

// TODO use Kotlin Poet once KMixins is merged
private fun generateFile(symbols: List<KSClassDeclaration>) {

Expand All @@ -99,11 +104,14 @@ class ModuleProcessor(private val codeGenerator: CodeGenerator, private val logg
it.write("package at.hannibal2.skyhanni.skyhannimodule\n\n")
it.write("object LoadedModules {\n")
it.write(" val isDev: Boolean = at.hannibal2.skyhanni.utils.system.PlatformUtils.isDevEnvironment\n")
it.write(" val hasNeu: Boolean get() = at.hannibal2.skyhanni.utils.system.PlatformUtils.isNeuLoaded()\n")
it.write(" val modules: List<Any> = buildList {\n")

symbols.forEach { symbol ->
if (isDevAnnotation(symbol)) {
it.write(" if (isDev) add(${symbol.qualifiedName!!.asString()})\n")
} else if (isNEUAnnotation(symbol)) {
it.write(" if (hasNeu) add(${symbol.qualifiedName!!.asString()})\n")
} else {
it.write(" add(${symbol.qualifiedName!!.asString()})\n")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@ annotation class SkyHanniModule(
* If the module will only be loaded in a development environment.
*/
val devOnly: Boolean = false,
/**
* If the module will only be loaded while neu is installed
*/
val neuRequired: Boolean = false,
)
Original file line number Diff line number Diff line change
Expand Up @@ -231,12 +231,6 @@ public class MiscConfig {
@FeatureToggle
public boolean accountUpgradeReminder = true;

@Expose
@ConfigOption(name = "NEU Heavy Pearls", desc = "Fix NEU's Heavy Pearl detection.")
@ConfigEditorBoolean
@FeatureToggle
public boolean fixNeuHeavyPearls = true;

@Expose
@ConfigOption(
name = "Fix Patcher Lines",
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/at/hannibal2/skyhanni/data/ChatManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import net.minecraftforge.client.event.ClientChatReceivedEvent
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import net.minecraftforge.fml.relauncher.ReflectionHelper
import java.lang.invoke.MethodHandles
import kotlin.time.Duration.Companion.seconds

@SkyHanniModule
object ChatManager {
Expand Down Expand Up @@ -125,6 +126,9 @@ object ChatManager {

if (message.startsWith("§f{\"server\":\"")) {
HypixelData.checkForLocraw(message)
if (HypixelData.lastLocRaw.passedSince() < 4.seconds) {
event.isCanceled = true
}
return
}
val key = IdentityCharacteristics(original)
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/at/hannibal2/skyhanni/data/GuiData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import at.hannibal2.skyhanni.features.inventory.wardrobe.CustomWardrobeKeybinds
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.utils.DelayedRun
import at.hannibal2.skyhanni.utils.KeyboardManager.isKeyHeld
import at.hannibal2.skyhanni.utils.system.PlatformUtils
import io.github.moulberry.notenoughupdates.NEUApi
import net.minecraft.client.Minecraft
import net.minecraft.client.gui.inventory.GuiChest
Expand Down Expand Up @@ -81,7 +82,7 @@ object GuiData {
@SubscribeEvent(priority = EventPriority.LOW)
fun onGuiOpen(event: GuiOpenEvent) {
if (preDrawEventCancelled) {
NEUApi.setInventoryButtonsToDisabled()
if (PlatformUtils.isNeuLoaded()) NEUApi.setInventoryButtonsToDisabled()
}
}
}
14 changes: 6 additions & 8 deletions src/main/java/at/hannibal2/skyhanni/data/GuiEditManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@ import at.hannibal2.skyhanni.test.SkyHanniDebugsAndTests
import at.hannibal2.skyhanni.utils.ChatUtils
import at.hannibal2.skyhanni.utils.LorenzUtils.isRancherSign
import at.hannibal2.skyhanni.utils.NEUItems
import at.hannibal2.skyhanni.utils.ReflectionUtils.getPropertiesWithType
import at.hannibal2.skyhanni.utils.SimpleTimeMark
import at.hannibal2.skyhanni.utils.TimeLimitedCache
import io.github.moulberry.notenoughupdates.itemeditor.GuiElementTextField
import io.github.moulberry.notenoughupdates.profileviewer.GuiProfileViewer
import net.minecraft.client.Minecraft
import net.minecraft.client.gui.inventory.GuiChest
import net.minecraft.client.gui.inventory.GuiContainer
Expand Down Expand Up @@ -50,8 +47,12 @@ object GuiEditManager {
}
if (isInGui()) return

Minecraft.getMinecraft().currentScreen?.let {
if (it !is GuiInventory && it !is GuiChest && it !is GuiEditSign && !(it is GuiProfileViewer && !it.anyTextBoxFocused())) return
val guiScreen = Minecraft.getMinecraft().currentScreen
val openGui = guiScreen?.javaClass?.name ?: "none"
val isInNeuPv = openGui == "io.github.moulberry.notenoughupdates.profileviewer.GuiProfileViewer"
if (isInNeuPv) return
guiScreen?.let {
if (it !is GuiInventory && it !is GuiChest && it !is GuiEditSign) return
if (it is GuiEditSign && !it.isRancherSign()) return
}

Expand Down Expand Up @@ -136,9 +137,6 @@ object GuiEditManager {

fun Position.getAbsY() = getAbsY0(getDummySize(true).y)

fun GuiProfileViewer.anyTextBoxFocused() =
this.getPropertiesWithType<GuiElementTextField>().any { it.focus }

fun handleGuiPositionMoved(guiName: String) {
lastMovedGui = guiName
}
Expand Down
15 changes: 5 additions & 10 deletions src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import at.hannibal2.skyhanni.features.rift.RiftAPI
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.test.command.ErrorManager
import at.hannibal2.skyhanni.utils.ChatUtils
import at.hannibal2.skyhanni.utils.HypixelCommands
import at.hannibal2.skyhanni.utils.LorenzLogger
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.RegexUtils.matchFirst
Expand All @@ -32,7 +33,6 @@ import at.hannibal2.skyhanni.utils.TabListData
import at.hannibal2.skyhanni.utils.UtilsPatterns
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import com.google.gson.JsonObject
import io.github.moulberry.notenoughupdates.NotEnoughUpdates
import net.minecraft.client.Minecraft
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import kotlin.concurrent.thread
Expand Down Expand Up @@ -110,7 +110,7 @@ object HypixelData {
"\\s*§(?<symbol>7⏣|5ф) §(?<color>.)(?<area>.*)",
)

private var lastLocRaw = SimpleTimeMark.farPast()
var lastLocRaw = SimpleTimeMark.farPast()
private var hasScoreboardUpdated = false

var hypixelLive = false
Expand Down Expand Up @@ -354,7 +354,7 @@ object HypixelData {
@SubscribeEvent
fun onTick(event: LorenzTickEvent) {
if (!LorenzUtils.inSkyBlock) {
checkNEULocraw()
sendLocraw()
}

if (LorenzUtils.onHypixel && LorenzUtils.inSkyBlock) {
Expand Down Expand Up @@ -396,17 +396,12 @@ object HypixelData {
skyBlock = inSkyBlock
}

// Modified from NEU.
// NEU does not send locraw when not in SkyBlock.
// So, as requested by Hannibal, use locraw from
// NEU and have NEU send it.
// Remove this when NEU dependency is removed
private fun checkNEULocraw() {
private fun sendLocraw() {
if (LorenzUtils.onHypixel && locrawData == null && lastLocRaw.passedSince() > 15.seconds) {
lastLocRaw = SimpleTimeMark.now()
thread(start = true) {
Thread.sleep(1000)
NotEnoughUpdates.INSTANCE.sendChatMessage("/locraw")
HypixelCommands.locraw()
}
}
}
Expand Down
6 changes: 1 addition & 5 deletions src/main/java/at/hannibal2/skyhanni/data/repo/RepoManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package at.hannibal2.skyhanni.data.repo

import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.config.ConfigManager
import at.hannibal2.skyhanni.events.DebugDataCollectEvent
import at.hannibal2.skyhanni.events.NeuRepositoryReloadEvent
import at.hannibal2.skyhanni.events.RepositoryReloadEvent
import at.hannibal2.skyhanni.test.command.ErrorManager
Expand Down Expand Up @@ -311,11 +312,6 @@ class RepoManager(private val configLocation: File) {
).use { writer -> writer.write(gson.toJson(json)) }
}

@SubscribeEvent
fun onNeuRepoReload(event: io.github.moulberry.notenoughupdates.events.RepositoryReloadEvent) {
NeuRepositoryReloadEvent().postAndCatch()
}

fun resetRepositoryLocation(manual: Boolean = false) {
val defaultUser = "hannibal002"
val defaultName = "SkyHanni-Repo"
Expand Down
75 changes: 75 additions & 0 deletions src/main/java/at/hannibal2/skyhanni/events/NeuEventWrappers.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package at.hannibal2.skyhanni.events

import at.hannibal2.skyhanni.data.jsonobjects.other.HypixelApiTrophyFish
import at.hannibal2.skyhanni.data.jsonobjects.other.HypixelPlayerApiJson
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.test.command.ErrorManager
import at.hannibal2.skyhanni.utils.NumberUtil.isInt
import at.hannibal2.skyhanni.utils.json.BaseGsonBuilder
import at.hannibal2.skyhanni.utils.json.fromJson
import com.google.gson.TypeAdapter
import com.google.gson.stream.JsonReader
import com.google.gson.stream.JsonToken
import com.google.gson.stream.JsonWriter
import io.github.moulberry.notenoughupdates.events.ProfileDataLoadedEvent
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent

@SkyHanniModule(neuRequired = true)
object NeuEventWrappers {

private val hypixelApiGson by lazy {
BaseGsonBuilder.gson()
.registerTypeAdapter(
HypixelApiTrophyFish::class.java,
object : TypeAdapter<HypixelApiTrophyFish>() {
@Suppress("EmptyFunctionBlock")
override fun write(out: JsonWriter, value: HypixelApiTrophyFish) {}

override fun read(reader: JsonReader): HypixelApiTrophyFish {
val trophyFish = mutableMapOf<String, Int>()
var totalCaught = 0
reader.beginObject()
while (reader.hasNext()) {
val key = reader.nextName()
if (key == "total_caught") {
totalCaught = reader.nextInt()
continue
}
if (reader.peek() == JsonToken.NUMBER) {
val valueAsString = reader.nextString()
if (valueAsString.isInt()) {
trophyFish[key] = valueAsString.toInt()
continue
}
}
reader.skipValue()
}
reader.endObject()
return HypixelApiTrophyFish(totalCaught, trophyFish)
}
}.nullSafe(),
)
.create()
}


@SubscribeEvent
fun onProfileDataLoaded(event: ProfileDataLoadedEvent) {
val apiData = event.data ?: return
try {
val playerData = hypixelApiGson.fromJson<HypixelPlayerApiJson>(apiData)
NeuProfileDataLoadedEvent(playerData).postAndCatch()

} catch (e: Exception) {
ErrorManager.logErrorWithData(
e, "Error reading hypixel player api data",
"data" to apiData,
)
}
}

@SubscribeEvent
fun onNeuRepoReload(event: RepositoryReloadEvent) {
NeuRepositoryReloadEvent().postAndCatch()
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import at.hannibal2.skyhanni.utils.NEUInternalName
import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators
import at.hannibal2.skyhanni.utils.NumberUtil.shortFormat
import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems
import at.hannibal2.skyhanni.utils.system.PlatformUtils
import io.github.moulberry.notenoughupdates.profileviewer.GuiProfileViewer
import net.minecraft.client.Minecraft
import net.minecraft.init.Items
Expand Down Expand Up @@ -65,7 +66,7 @@ object EstimatedItemValue {
@HandleEvent(onlyOnSkyblock = true)
fun onTooltip(event: ItemHoverEvent) {
if (!config.enabled) return
if (Minecraft.getMinecraft().currentScreen !is GuiProfileViewer) return
if (PlatformUtils.isNeuLoaded() && Minecraft.getMinecraft().currentScreen !is GuiProfileViewer) return

if (renderedItems == 0) {
updateItem(event.itemStack)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import at.hannibal2.skyhanni.utils.NumberUtil.shortFormat
import at.hannibal2.skyhanni.utils.ReflectionUtils.makeAccessible
import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getPetExp
import at.hannibal2.skyhanni.utils.StringUtils
import at.hannibal2.skyhanni.utils.system.PlatformUtils
import io.github.moulberry.notenoughupdates.NotEnoughUpdates
import net.minecraftforge.fml.common.eventhandler.EventPriority
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
Expand Down Expand Up @@ -80,7 +81,7 @@ object PetExpTooltip {
index = toolTip.indexOfFirst { it.contains("Progress to Level") }
if (index != -1) {

val offset = if (isNeuExtendedExpEnabled) 4 else 3
val offset = if (PlatformUtils.isNeuLoaded() && isNeuExtendedExpEnabled) 4 else 3
return index + offset
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import at.hannibal2.skyhanni.events.GuiContainerEvent.CloseWindowEvent
import at.hannibal2.skyhanni.events.GuiContainerEvent.SlotClickEvent
import at.hannibal2.skyhanni.test.SkyHanniDebugsAndTests
import at.hannibal2.skyhanni.utils.DelayedRun
import at.hannibal2.skyhanni.utils.system.PlatformUtils
import io.github.moulberry.notenoughupdates.NEUApi
import net.minecraft.client.gui.inventory.GuiContainer
import net.minecraft.inventory.Slot
Expand Down Expand Up @@ -37,7 +38,7 @@ class GuiContainerHook(guiAny: Any) {
) {
if (!SkyHanniDebugsAndTests.globalRender) return
if (GuiContainerEvent.PreDraw(gui, gui.inventorySlots, mouseX, mouseY, partialTicks).postAndCatch()) {
NEUApi.setInventoryButtonsToDisabled()
if (PlatformUtils.isNeuLoaded()) NEUApi.setInventoryButtonsToDisabled()
GuiData.preDrawEventCancelled = true
ci.cancel()
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package at.hannibal2.skyhanni.mixins.transformers;

import net.minecraft.entity.passive.EntityHorse;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

//from neu
@Mixin(value = EntityHorse.class)
public class MixinEntityHorse {
@Redirect(method = "updateHorseSlots", at = @At(value = "FIELD", target = "Lnet/minecraft/world/World;isRemote:Z"), expect = 0)
public boolean onUpdateHorseSlots(World instance) {
if (instance == null)
return true;
return instance.isRemote;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import at.hannibal2.skyhanni.events.NEURenderEvent;
import io.github.moulberry.notenoughupdates.NEUOverlay;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Pseudo;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Pseudo
@Mixin(NEUOverlay.class)
public class MixinNEUOverlay {

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/at/hannibal2/skyhanni/utils/HypixelCommands.kt
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ object HypixelCommands {
send("viewstash $type")
}

fun locraw() {
send("locraw")
}

private fun send(command: String) {
@Suppress("DEPRECATION")
// TODO rename function
Expand Down
Loading
Loading