diff --git a/model_loader/src/main/java/io/github/fabricators_of_create/porting_lib/model/RenderMaterialModel.java b/model_loader/src/main/java/io/github/fabricators_of_create/porting_lib/model/RenderMaterialModel.java new file mode 100644 index 000000000..e361cbcd3 --- /dev/null +++ b/model_loader/src/main/java/io/github/fabricators_of_create/porting_lib/model/RenderMaterialModel.java @@ -0,0 +1,47 @@ +package io.github.fabricators_of_create.porting_lib.model; + +import java.util.function.Supplier; + +import net.fabricmc.fabric.api.renderer.v1.material.RenderMaterial; +import net.fabricmc.fabric.api.renderer.v1.model.ForwardingBakedModel; +import net.fabricmc.fabric.api.renderer.v1.render.RenderContext; +import net.minecraft.client.resources.model.BakedModel; +import net.minecraft.core.BlockPos; +import net.minecraft.util.RandomSource; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.BlockAndTintGetter; +import net.minecraft.world.level.block.state.BlockState; + +public class RenderMaterialModel extends ForwardingBakedModel { + protected final RenderMaterial material; + + public RenderMaterialModel(BakedModel owner, RenderMaterial material) { + this.wrapped = owner; + this.material = material; + } + + @Override + public boolean isVanillaAdapter() { + return false; + } + + @Override + public void emitBlockQuads(BlockAndTintGetter blockView, BlockState state, BlockPos pos, Supplier randomSupplier, RenderContext context) { + context.pushTransform(quad -> { + quad.material(this.material); + return true; + }); + super.emitBlockQuads(blockView, state, pos, randomSupplier, context); + context.popTransform(); + } + + @Override + public void emitItemQuads(ItemStack stack, Supplier randomSupplier, RenderContext context) { + context.pushTransform(quad -> { + quad.material(this.material); + return true; + }); + super.emitItemQuads(stack, randomSupplier, context); + context.popTransform(); + } +} diff --git a/model_loader/src/main/java/io/github/fabricators_of_create/porting_lib/model/geometry/UnbakedGeometryHelper.java b/model_loader/src/main/java/io/github/fabricators_of_create/porting_lib/model/geometry/UnbakedGeometryHelper.java index 4d2375499..1dd5a8e6a 100644 --- a/model_loader/src/main/java/io/github/fabricators_of_create/porting_lib/model/geometry/UnbakedGeometryHelper.java +++ b/model_loader/src/main/java/io/github/fabricators_of_create/porting_lib/model/geometry/UnbakedGeometryHelper.java @@ -8,7 +8,11 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import io.github.fabricators_of_create.porting_lib.client.RenderTypeGroup; +import io.github.fabricators_of_create.porting_lib.model.RenderMaterialModel; +import net.fabricmc.fabric.api.renderer.v1.Renderer; +import net.fabricmc.fabric.api.renderer.v1.RendererAccess; +import net.fabricmc.fabric.api.renderer.v1.material.BlendMode; +import net.fabricmc.fabric.api.renderer.v1.material.RenderMaterial; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; @@ -19,6 +23,7 @@ import io.github.fabricators_of_create.porting_lib.model.IModelBuilder; import io.github.fabricators_of_create.porting_lib.model.SimpleModelState; import net.minecraft.Util; +import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.block.model.BakedQuad; import net.minecraft.client.renderer.block.model.BlockElement; import net.minecraft.client.renderer.block.model.BlockElementFace; @@ -100,9 +105,21 @@ public static BakedModel bake(BlockModel blockModel, ModelBakery modelBakery, Bl if (blockModel.getRootModel() == ModelBakery.GENERATION_MARKER) return ITEM_MODEL_GENERATOR.generateBlockModel(spriteGetter, blockModel).bake(modelBakery, blockModel, spriteGetter, modelState, modelLocation, guiLight3d); - var renderTypeHint = blockModel.getGeometry().getRenderTypeHint(); - var renderTypes = renderTypeHint != null ? blockModel.getGeometry().getRenderType(renderTypeHint) : RenderTypeGroup.EMPTY; - return blockModel.bake(modelBakery, owner, spriteGetter, modelState, modelLocation, guiLight3d); + BakedModel baked = blockModel.bake(modelBakery, owner, spriteGetter, modelState, modelLocation, guiLight3d); + + ResourceLocation renderTypeHint = blockModel.getGeometry().getRenderTypeHint(); + if (renderTypeHint != null) { + RenderType type = blockModel.getGeometry().getRenderType(renderTypeHint).block(); + if (type != null) { + Renderer renderer = RendererAccess.INSTANCE.getRenderer(); + if (renderer != null) { + RenderMaterial material = renderer.materialFinder().blendMode(0, BlendMode.fromRenderLayer(type)).find(); + baked = new RenderMaterialModel(baked, material); + } + } + } + + return baked; } /**