aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/events
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/kotlin/events')
-rw-r--r--src/main/kotlin/events/BakeExtraModelsEvent.kt25
-rw-r--r--src/main/kotlin/events/CustomItemModelEvent.kt46
-rw-r--r--src/main/kotlin/events/DebugInstantiateEvent.kt9
-rw-r--r--src/main/kotlin/events/FinalizeResourceManagerEvent.kt41
-rw-r--r--src/main/kotlin/events/IsSlotProtectedEvent.kt2
-rw-r--r--src/main/kotlin/events/RegisterCustomShadersEvent.kt24
-rw-r--r--src/main/kotlin/events/SlotRenderEvents.kt15
-rw-r--r--src/main/kotlin/events/WorldReadyEvent.kt9
-rw-r--r--src/main/kotlin/events/WorldRenderLastEvent.kt3
9 files changed, 77 insertions, 97 deletions
diff --git a/src/main/kotlin/events/BakeExtraModelsEvent.kt b/src/main/kotlin/events/BakeExtraModelsEvent.kt
index f75bedc..adaa495 100644
--- a/src/main/kotlin/events/BakeExtraModelsEvent.kt
+++ b/src/main/kotlin/events/BakeExtraModelsEvent.kt
@@ -1,21 +1,24 @@
-
package moe.nea.firmament.events
-import java.util.function.Consumer
+import java.util.function.BiConsumer
+import net.minecraft.client.render.model.ReferencedModelsCollector
import net.minecraft.client.util.ModelIdentifier
+import net.minecraft.util.Identifier
+// TODO: Rename this event, since it is not really directly baking models anymore
class BakeExtraModelsEvent(
- private val addItemModel: Consumer<ModelIdentifier>,
- private val addAnyModel: Consumer<ModelIdentifier>,
+ private val addAnyModel: BiConsumer<ModelIdentifier, Identifier>,
) : FirmamentEvent() {
- fun addNonItemModel(modelIdentifier: ModelIdentifier) {
- this.addAnyModel.accept(modelIdentifier)
- }
+ fun addNonItemModel(modelIdentifier: ModelIdentifier, identifier: Identifier) {
+ this.addAnyModel.accept(modelIdentifier, identifier)
+ }
- fun addItemModel(modelIdentifier: ModelIdentifier) {
- this.addItemModel.accept(modelIdentifier)
- }
+ fun addItemModel(modelIdentifier: ModelIdentifier) {
+ addNonItemModel(
+ modelIdentifier,
+ modelIdentifier.id.withPrefixedPath(ReferencedModelsCollector.ITEM_DIRECTORY))
+ }
- companion object : FirmamentEventBus<BakeExtraModelsEvent>()
+ companion object : FirmamentEventBus<BakeExtraModelsEvent>()
}
diff --git a/src/main/kotlin/events/CustomItemModelEvent.kt b/src/main/kotlin/events/CustomItemModelEvent.kt
index e50eca4..4328d77 100644
--- a/src/main/kotlin/events/CustomItemModelEvent.kt
+++ b/src/main/kotlin/events/CustomItemModelEvent.kt
@@ -2,35 +2,37 @@ package moe.nea.firmament.events
import java.util.Optional
import kotlin.jvm.optionals.getOrNull
+import net.minecraft.client.render.item.ItemModels
import net.minecraft.client.render.model.BakedModel
-import net.minecraft.client.render.model.BakedModelManager
import net.minecraft.client.util.ModelIdentifier
import net.minecraft.item.ItemStack
+import moe.nea.firmament.util.ErrorUtil
import moe.nea.firmament.util.collections.WeakCache
data class CustomItemModelEvent(
- val itemStack: ItemStack,
- var overrideModel: ModelIdentifier? = null,
+ val itemStack: ItemStack,
+ var overrideModel: ModelIdentifier? = null,
) : FirmamentEvent() {
- companion object : FirmamentEventBus<CustomItemModelEvent>() {
- val cache =
- WeakCache.memoize<ItemStack, BakedModelManager, Optional<BakedModel>>("CustomItemModels") { stack, models ->
- val modelId = getModelIdentifier(stack) ?: return@memoize Optional.empty()
- val bakedModel = models.getModel(modelId)
- if (bakedModel === models.missingModel) return@memoize Optional.empty()
- Optional.of(bakedModel)
- }
+ companion object : FirmamentEventBus<CustomItemModelEvent>() {
+ val cache =
+ WeakCache.memoize<ItemStack, ItemModels, Optional<BakedModel>>("CustomItemModels") { stack, models ->
+ val modelId = getModelIdentifier(stack) ?: return@memoize Optional.empty()
+ ErrorUtil.softCheck("Model Id needs to have an inventory variant", modelId.variant() == "inventory")
+ val bakedModel = models.getModel(modelId.id)
+ if (bakedModel == null || bakedModel === models.missingModelSupplier.get()) return@memoize Optional.empty()
+ Optional.of(bakedModel)
+ }
- @JvmStatic
- fun getModelIdentifier(itemStack: ItemStack?): ModelIdentifier? {
- if (itemStack == null) return null
- return publish(CustomItemModelEvent(itemStack)).overrideModel
- }
+ @JvmStatic
+ fun getModelIdentifier(itemStack: ItemStack?): ModelIdentifier? {
+ if (itemStack == null) return null
+ return publish(CustomItemModelEvent(itemStack)).overrideModel
+ }
- @JvmStatic
- fun getModel(itemStack: ItemStack?, thing: BakedModelManager): BakedModel? {
- if (itemStack == null) return null
- return cache.invoke(itemStack, thing).getOrNull()
- }
- }
+ @JvmStatic
+ fun getModel(itemStack: ItemStack?, thing: ItemModels): BakedModel? {
+ if (itemStack == null) return null
+ return cache.invoke(itemStack, thing).getOrNull()
+ }
+ }
}
diff --git a/src/main/kotlin/events/DebugInstantiateEvent.kt b/src/main/kotlin/events/DebugInstantiateEvent.kt
new file mode 100644
index 0000000..3470a8c
--- /dev/null
+++ b/src/main/kotlin/events/DebugInstantiateEvent.kt
@@ -0,0 +1,9 @@
+package moe.nea.firmament.events
+
+/**
+ * Called in a devenv after minecraft has been initialized. This event should be used to force instantiation of lazy
+ * variables (and similar late init) to cause any possible issues to materialize.
+ */
+class DebugInstantiateEvent : FirmamentEvent() {
+ companion object : FirmamentEventBus<DebugInstantiateEvent>()
+}
diff --git a/src/main/kotlin/events/FinalizeResourceManagerEvent.kt b/src/main/kotlin/events/FinalizeResourceManagerEvent.kt
index 0d411f1..12167f8 100644
--- a/src/main/kotlin/events/FinalizeResourceManagerEvent.kt
+++ b/src/main/kotlin/events/FinalizeResourceManagerEvent.kt
@@ -5,31 +5,28 @@ import java.util.concurrent.Executor
import net.minecraft.resource.ReloadableResourceManagerImpl
import net.minecraft.resource.ResourceManager
import net.minecraft.resource.ResourceReloader
-import net.minecraft.util.profiler.Profiler
data class FinalizeResourceManagerEvent(
- val resourceManager: ReloadableResourceManagerImpl,
+ val resourceManager: ReloadableResourceManagerImpl,
) : FirmamentEvent() {
- companion object : FirmamentEventBus<FinalizeResourceManagerEvent>()
+ companion object : FirmamentEventBus<FinalizeResourceManagerEvent>()
- inline fun registerOnApply(name: String, crossinline function: () -> Unit) {
- resourceManager.registerReloader(object : ResourceReloader {
- override fun reload(
- synchronizer: ResourceReloader.Synchronizer,
- manager: ResourceManager?,
- prepareProfiler: Profiler?,
- applyProfiler: Profiler?,
- prepareExecutor: Executor?,
- applyExecutor: Executor
- ): CompletableFuture<Void> {
- return CompletableFuture.completedFuture(Unit)
- .thenCompose(synchronizer::whenPrepared)
- .thenAcceptAsync({ function() }, applyExecutor)
- }
+ inline fun registerOnApply(name: String, crossinline function: () -> Unit) {
+ resourceManager.registerReloader(object : ResourceReloader {
+ override fun reload(
+ synchronizer: ResourceReloader.Synchronizer,
+ manager: ResourceManager,
+ prepareExecutor: Executor,
+ applyExecutor: Executor
+ ): CompletableFuture<Void> {
+ return CompletableFuture.completedFuture(Unit)
+ .thenCompose(synchronizer::whenPrepared)
+ .thenAcceptAsync({ function() }, applyExecutor)
+ }
- override fun getName(): String {
- return name
- }
- })
- }
+ override fun getName(): String {
+ return name
+ }
+ })
+ }
}
diff --git a/src/main/kotlin/events/IsSlotProtectedEvent.kt b/src/main/kotlin/events/IsSlotProtectedEvent.kt
index cd431f7..cd2b676 100644
--- a/src/main/kotlin/events/IsSlotProtectedEvent.kt
+++ b/src/main/kotlin/events/IsSlotProtectedEvent.kt
@@ -37,7 +37,7 @@ data class IsSlotProtectedEvent(
val event = IsSlotProtectedEvent(slot, action, false, itemStackOverride)
publish(event)
if (event.isProtected && !event.silent) {
- MC.player?.sendMessage(Text.translatable("firmament.protectitem").append(event.itemStack.name))
+ MC.sendChat(Text.translatable("firmament.protectitem").append(event.itemStack.name))
CommonSoundEffects.playFailure()
}
return event.isProtected
diff --git a/src/main/kotlin/events/RegisterCustomShadersEvent.kt b/src/main/kotlin/events/RegisterCustomShadersEvent.kt
deleted file mode 100644
index 2f6d1f8..0000000
--- a/src/main/kotlin/events/RegisterCustomShadersEvent.kt
+++ /dev/null
@@ -1,24 +0,0 @@
-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)
- }
- }
-}
diff --git a/src/main/kotlin/events/SlotRenderEvents.kt b/src/main/kotlin/events/SlotRenderEvents.kt
index 5431573..5234176 100644
--- a/src/main/kotlin/events/SlotRenderEvents.kt
+++ b/src/main/kotlin/events/SlotRenderEvents.kt
@@ -3,20 +3,19 @@
package moe.nea.firmament.events
import net.minecraft.client.gui.DrawContext
+import net.minecraft.client.render.RenderLayer
import net.minecraft.client.texture.Sprite
import net.minecraft.screen.slot.Slot
import net.minecraft.util.Identifier
import moe.nea.firmament.util.MC
+import moe.nea.firmament.util.render.drawGuiTexture
interface SlotRenderEvents {
val context: DrawContext
val slot: Slot
- val mouseX: Int
- val mouseY: Int
- val delta: Float
- fun highlight(sprite: Sprite) {
- context.drawSprite(
+ fun highlight(sprite: Identifier) {
+ context.drawGuiTexture(
slot.x, slot.y, 0, 16, 16,
sprite
)
@@ -24,9 +23,6 @@ interface SlotRenderEvents {
data class Before(
override val context: DrawContext, override val slot: Slot,
- override val mouseX: Int,
- override val mouseY: Int,
- override val delta: Float
) : FirmamentEvent(),
SlotRenderEvents {
companion object : FirmamentEventBus<Before>()
@@ -34,9 +30,6 @@ interface SlotRenderEvents {
data class After(
override val context: DrawContext, override val slot: Slot,
- override val mouseX: Int,
- override val mouseY: Int,
- override val delta: Float
) : FirmamentEvent(),
SlotRenderEvents {
companion object : FirmamentEventBus<After>()
diff --git a/src/main/kotlin/events/WorldReadyEvent.kt b/src/main/kotlin/events/WorldReadyEvent.kt
index 2c76c44..c79b100 100644
--- a/src/main/kotlin/events/WorldReadyEvent.kt
+++ b/src/main/kotlin/events/WorldReadyEvent.kt
@@ -1,7 +1,10 @@
-
-
package moe.nea.firmament.events
class WorldReadyEvent : FirmamentEvent() {
- companion object : FirmamentEventBus<WorldReadyEvent>()
+ companion object : FirmamentEventBus<WorldReadyEvent>()
+// class FullyLoaded : FirmamentEvent() {
+// companion object : FirmamentEventBus<FullyLoaded>() {
+// TODO: check WorldLoadingState
+// }
+// }
}
diff --git a/src/main/kotlin/events/WorldRenderLastEvent.kt b/src/main/kotlin/events/WorldRenderLastEvent.kt
index 21a670d..3c2103d 100644
--- a/src/main/kotlin/events/WorldRenderLastEvent.kt
+++ b/src/main/kotlin/events/WorldRenderLastEvent.kt
@@ -17,10 +17,7 @@ import net.minecraft.util.math.Vec3d
data class WorldRenderLastEvent(
val matrices: MatrixStack,
val tickCounter: RenderTickCounter,
- val renderBlockOutline: Boolean,
val camera: Camera,
- val gameRenderer: GameRenderer,
- val lightmapTextureManager: LightmapTextureManager,
val vertexConsumers: VertexConsumerProvider.Immediate,
) : FirmamentEvent() {
companion object : FirmamentEventBus<WorldRenderLastEvent>()