fix: resolving of custom block textures

This commit is contained in:
Linnea Gräf
2025-04-09 18:34:25 +02:00
parent 72044baeff
commit 76f86b5407
3 changed files with 44 additions and 2 deletions

View File

@@ -24,7 +24,7 @@ object ItemResources {
} }
fun loadSNbt(path: String): NbtCompound { fun loadSNbt(path: String): NbtCompound {
return StringNbtReader.parse(loadString(path)) return StringNbtReader.readCompound(loadString(path))
} }
fun getNbtOps(): RegistryOps<NbtElement> = MC.currentOrDefaultRegistries.getOps(NbtOps.INSTANCE) fun getNbtOps(): RegistryOps<NbtElement> = MC.currentOrDefaultRegistries.getOps(NbtOps.INSTANCE)

View File

@@ -23,6 +23,7 @@ import net.minecraft.block.Block
import net.minecraft.block.BlockState import net.minecraft.block.BlockState
import net.minecraft.client.render.model.Baker import net.minecraft.client.render.model.Baker
import net.minecraft.client.render.model.BlockStateModel import net.minecraft.client.render.model.BlockStateModel
import net.minecraft.client.render.model.ReferencedModelsCollector
import net.minecraft.client.render.model.SimpleBlockStateModel import net.minecraft.client.render.model.SimpleBlockStateModel
import net.minecraft.client.render.model.json.ModelVariant import net.minecraft.client.render.model.json.ModelVariant
import net.minecraft.registry.RegistryKey import net.minecraft.registry.RegistryKey
@@ -308,6 +309,19 @@ object CustomBlockTextures {
}) })
} }
fun simpleBlockModel(blockId: Identifier): SimpleBlockStateModel.Unbaked {
// TODO: does this need to be shared between resolving and baking? I think not, but it would probably be wise to do so in the future.
return SimpleBlockStateModel.Unbaked(
ModelVariant(blockId)
)
}
@JvmStatic
fun collectExtraModels(modelsCollector: ReferencedModelsCollector) {
preparationFuture.join().collectAllReplacements()
.forEach { modelsCollector.resolve(simpleBlockModel(it.blockModelIdentifier)) }
}
@JvmStatic @JvmStatic
fun createBakedModels(baker: Baker, executor: Executor): CompletableFuture<Void?> { fun createBakedModels(baker: Baker, executor: Executor): CompletableFuture<Void?> {
return preparationFuture.thenComposeAsync(Function { replacements -> return preparationFuture.thenComposeAsync(Function { replacements ->
@@ -315,7 +329,7 @@ object CustomBlockTextures {
val modelBakingTask = AsyncHelper.mapValues(byModel, { blockId, replacements -> val modelBakingTask = AsyncHelper.mapValues(byModel, { blockId, replacements ->
val unbakedModel = SimpleBlockStateModel.Unbaked( val unbakedModel = SimpleBlockStateModel.Unbaked(
ModelVariant(blockId) ModelVariant(blockId)
) // TODO: do i need to resolve models here? Maybe this needs to be resolved earlier before baking. )
val baked = unbakedModel.bake(baker) val baked = unbakedModel.bake(baker)
replacements.forEach { replacements.forEach {
it.blockModel = baked it.blockModel = baked

View File

@@ -0,0 +1,28 @@
package moe.nea.firmament.mixins.custommodels;
import com.llamalad7.mixinextras.sugar.Local;
import moe.nea.firmament.features.texturepack.CustomBlockTextures;
import net.minecraft.client.item.ItemAssetsLoader;
import net.minecraft.client.render.model.BakedModelManager;
import net.minecraft.client.render.model.BlockStatesLoader;
import net.minecraft.client.render.model.ReferencedModelsCollector;
import net.minecraft.client.render.model.UnbakedModel;
import net.minecraft.util.Identifier;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import java.util.Map;
@Mixin(BakedModelManager.class)
public class InsertExtraBlockModelDependencies {
@Inject(method = "collect", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/model/ReferencedModelsCollector;addSpecialModel(Lnet/minecraft/util/Identifier;Lnet/minecraft/client/render/model/UnbakedModel;)V", shift = At.Shift.AFTER))
private static void insertExtraModels(
Map<Identifier, UnbakedModel> modelMap,
BlockStatesLoader.LoadedModels stateDefinition,
ItemAssetsLoader.Result result,
CallbackInfoReturnable cir, @Local ReferencedModelsCollector modelsCollector) {
CustomBlockTextures.collectExtraModels(modelsCollector);
}
}