From 9929b1b60f22a087369d7a8560d5388f8168872c Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Wed, 17 Jan 2024 21:59:35 +0100 Subject: Fixing Ghost Entities. --- src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt | 4 +- .../skyhanni/config/features/misc/MiscConfig.java | 6 +++ .../skyhanni/features/misc/FixGhostEntities.kt | 58 ++++++++++++++++++++++ .../at/hannibal2/skyhanni/utils/LorenzUtils.kt | 4 +- 4 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 src/main/java/at/hannibal2/skyhanni/features/misc/FixGhostEntities.kt (limited to 'src/main/java/at/hannibal2') diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index 16499a6a9..cb9e5f1a3 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -232,6 +232,7 @@ import at.hannibal2.skyhanni.features.misc.CurrentPetDisplay import at.hannibal2.skyhanni.features.misc.CustomTextBox import at.hannibal2.skyhanni.features.misc.ExpOrbsOnGroundHider import at.hannibal2.skyhanni.features.misc.FandomWikiFromMenus +import at.hannibal2.skyhanni.features.misc.FixGhostEntities import at.hannibal2.skyhanni.features.misc.FixNEUHeavyPearls import at.hannibal2.skyhanni.features.misc.HideArmor import at.hannibal2.skyhanni.features.misc.InGameDateDisplay @@ -368,7 +369,7 @@ import org.apache.logging.log4j.Logger clientSideOnly = true, useMetadata = true, guiFactory = "at.hannibal2.skyhanni.config.ConfigGuiForgeInterop", - version = "0.23.Beta.8", + version = "0.23.Beta.9", ) class SkyHanniMod { @@ -710,6 +711,7 @@ class SkyHanniMod { // test stuff loadModule(SkyHanniDebugsAndTests()) + loadModule(FixGhostEntities) loadModule(CopyNearbyParticlesCommand) loadModule(ButtonOnPause()) loadModule(PacketTest()) diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/misc/MiscConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/misc/MiscConfig.java index 69db7f53d..9b3f41417 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/misc/MiscConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/misc/MiscConfig.java @@ -229,4 +229,10 @@ public class MiscConfig { @Expose public int limboTimePB = 0; + + @Expose + @ConfigOption(name = "Fix Ghost Entities", desc = "Removes ghost entities caused by a Hypixel bug.") + @ConfigEditorBoolean + @FeatureToggle + public boolean fixGhostEntities = true; } diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/FixGhostEntities.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/FixGhostEntities.kt new file mode 100644 index 000000000..69a1c6ee6 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/FixGhostEntities.kt @@ -0,0 +1,58 @@ +package at.hannibal2.skyhanni.features.misc + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent +import at.hannibal2.skyhanni.events.PacketEvent +import at.hannibal2.skyhanni.utils.LorenzUtils +import net.minecraft.network.play.server.S0CPacketSpawnPlayer +import net.minecraft.network.play.server.S0FPacketSpawnMob +import net.minecraft.network.play.server.S13PacketDestroyEntities +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +/** + * This feature fixes ghost entities sent by hypixel that are not properly deleted in the correct order. + * E.g. Diana or Dingeon mobs or nametags. + */ +object FixGhostEntities { + + private val config get() = SkyHanniMod.feature.misc + + private var recentlyRemovedEntities = ArrayDeque() + + @SubscribeEvent + fun onWorldChange(event: LorenzWorldChangeEvent) { + recentlyRemovedEntities = ArrayDeque() + } + + @SubscribeEvent + fun onReceiveCurrentShield(event: PacketEvent.ReceiveEvent) { + if (!isEnabled()) return + + val packet = event.packet + + if (packet is S0CPacketSpawnPlayer) { + if (packet.entityID in recentlyRemovedEntities) { + event.cancel() + LorenzUtils.debug("Removed bugged hypixel mob id Player") + } + } + + if (packet is S0FPacketSpawnMob) { + if (packet.entityID in recentlyRemovedEntities) { + event.cancel() + LorenzUtils.debug("Removed bugged hypixel mob id Mob") + } + } + + if (packet is S13PacketDestroyEntities) { + for (entityID in packet.entityIDs) { + recentlyRemovedEntities.add(entityID) + if (recentlyRemovedEntities.size == 10) { + recentlyRemovedEntities.removeFirst() + } + } + } + } + + fun isEnabled() = LorenzUtils.connectedToHypixel && config.fixGhostEntities +} diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt index f931e0f1d..c86dd3688 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt @@ -52,7 +52,9 @@ import kotlin.time.Duration.Companion.seconds object LorenzUtils { - val onHypixel get() = (HypixelData.hypixelLive || HypixelData.hypixelAlpha) && Minecraft.getMinecraft().thePlayer != null + val connectedToHypixel get() = HypixelData.hypixelLive || HypixelData.hypixelAlpha + + val onHypixel get() = connectedToHypixel && Minecraft.getMinecraft().thePlayer != null val isOnAlphaServer get() = onHypixel && HypixelData.hypixelAlpha -- cgit