aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/events/RegisterCustomShadersEvent.kt
blob: 2f6d1f8129c454a19b2d106827b36218aae03e99 (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
package moe.nea.firmament.events

import com.mojang.datafixers.util.Pair
import java.util.function.Consumer
import net.minecraft.client.gl.ShaderProgram
import net.minecraft.client.render.VertexFormat
import net.minecraft.resource.ResourceFactory
import moe.nea.firmament.Firmament

data class RegisterCustomShadersEvent(
    val list: MutableList<Pair<ShaderProgram, Consumer<ShaderProgram>>>,
    val resourceFactory: ResourceFactory,
) : FirmamentEvent() {
    companion object : FirmamentEventBus<RegisterCustomShadersEvent>()

    fun register(name: String, vertexFormat: VertexFormat, saver: Consumer<ShaderProgram>) {
        require(name.startsWith("firmament_"))
        try {
            list.add(Pair.of(ShaderProgram(resourceFactory, name, vertexFormat), saver))
        } catch (ex: Exception) {
            Firmament.logger.fatal("Could not load firmament shader $name", ex)
        }
    }
}