blob: a5b3a97b8b3ac5823778ca4fda8a4cc7c3b96497 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
package at.hannibal2.skyhanni.features.misc
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.api.event.HandleEvent
import at.hannibal2.skyhanni.events.CheckRenderEntityEvent
import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent
import at.hannibal2.skyhanni.events.minecraft.packet.PacketReceivedEvent
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.MobUtils.isDefaultValue
import net.minecraft.entity.item.EntityArmorStand
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.
* This included Diana, Dungeon and Crimson Isle mobs and nametags.
*/
@SkyHanniModule
object FixGhostEntities {
private val config get() = SkyHanniMod.feature.misc
private var recentlyRemovedEntities = ArrayDeque<Int>()
private var recentlySpawnedEntities = ArrayDeque<Int>()
@SubscribeEvent
fun onWorldChange(event: LorenzWorldChangeEvent) {
recentlyRemovedEntities = ArrayDeque()
recentlySpawnedEntities = ArrayDeque()
}
@HandleEvent(onlyOnSkyblock = true)
fun onReceiveCurrentShield(event: PacketReceivedEvent) {
if (!isEnabled()) return
val packet = event.packet
if (packet is S0CPacketSpawnPlayer) {
if (packet.entityID in recentlyRemovedEntities) {
event.cancel()
}
recentlySpawnedEntities.addLast(packet.entityID)
} else if (packet is S0FPacketSpawnMob) {
if (packet.entityID in recentlyRemovedEntities) {
event.cancel()
}
recentlySpawnedEntities.addLast(packet.entityID)
} else if (packet is S13PacketDestroyEntities) {
for (entityID in packet.entityIDs) {
// ignore entities that got properly spawned and then removed
if (entityID !in recentlySpawnedEntities) {
recentlyRemovedEntities.addLast(entityID)
if (recentlyRemovedEntities.size == 10) {
recentlyRemovedEntities.removeFirst()
}
}
}
}
}
@SubscribeEvent
fun onCheckRender(event: CheckRenderEntityEvent<*>) {
if (!LorenzUtils.inSkyBlock || !config.hideTemporaryArmorstands) return
if (event.entity !is EntityArmorStand) return
with(event.entity) {
if (ticksExisted < 10 && isDefaultValue() && inventory.all { it == null }) event.cancel()
}
}
fun isEnabled() = config.fixGhostEntities
}
|