aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/data/BlockData.kt
blob: c43fe9ad08e9fbc1744fb1a7940e2f5bba2b80f9 (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
package at.hannibal2.skyhanni.data

import at.hannibal2.skyhanni.events.PacketEvent
import at.hannibal2.skyhanni.events.ServerBlockChangeEvent
import net.minecraft.network.play.server.S22PacketMultiBlockChange
import net.minecraft.network.play.server.S23PacketBlockChange
import net.minecraftforge.fml.common.eventhandler.EventPriority
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent

class BlockData {

    @SubscribeEvent(priority = EventPriority.LOW, receiveCanceled = true)
    fun onChatPacket(event: PacketEvent.ReceiveEvent) {
        @Suppress("USELESS_ELVIS")
        val packet = event.packet ?: return

        if (packet is S23PacketBlockChange) {
            val blockPos = packet.blockPosition ?: return
            val blockState = packet.blockState ?: return
            ServerBlockChangeEvent(blockPos, blockState).postAndCatch()
        } else if (packet is S22PacketMultiBlockChange) {
            for (block in packet.changedBlocks) {
                ServerBlockChangeEvent(block.pos, block.blockState).postAndCatch()
            }
        }
    }
}