aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/com/ambientaddons/features/dungeon/CloseChest.kt
blob: ffaab8dfa7a4934a04f5776fc7500fca0f6895e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package com.ambientaddons.features.dungeon

import AmbientAddons.Companion.config
import AmbientAddons.Companion.mc
import com.ambientaddons.events.ReceivePacketEvent
import com.ambientaddons.utils.LocationUtils
import net.minecraft.network.play.client.C0DPacketCloseWindow
import net.minecraft.network.play.server.S2DPacketOpenWindow
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent

object CloseChest {
    @SubscribeEvent
    fun onOpenWindow(event: ReceivePacketEvent) {
        if (!config.closeSecretChests || LocationUtils.location != "Catacombs") return
        if (event.packet !is S2DPacketOpenWindow) return
        if (event.packet.windowTitle.unformattedText == "Chest") {
            mc.netHandler.networkManager.sendPacket(C0DPacketCloseWindow(event.packet.windowId))
            event.isCanceled = true
        }
    }
}