1.21.3 WIP
This commit is contained in:
@@ -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>()
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
9
src/main/kotlin/events/DebugInstantiateEvent.kt
Normal file
9
src/main/kotlin/events/DebugInstantiateEvent.kt
Normal file
@@ -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>()
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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>()
|
||||
|
||||
@@ -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
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -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>()
|
||||
|
||||
Reference in New Issue
Block a user