diff --git a/src/main/java/io/github/cottonmc/templates/model/MeshTransformer.java b/src/main/java/io/github/cottonmc/templates/model/MeshTransformer.java deleted file mode 100644 index 0c5cd4f..0000000 --- a/src/main/java/io/github/cottonmc/templates/model/MeshTransformer.java +++ /dev/null @@ -1,16 +0,0 @@ -package io.github.cottonmc.templates.model; - -import net.fabricmc.fabric.api.renderer.v1.render.RenderContext.QuadTransform; -import net.minecraft.block.BlockState; -import net.minecraft.item.ItemStack; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.random.Random; -import net.minecraft.world.BlockRenderView; - -import java.util.function.Supplier; - -public interface MeshTransformer extends QuadTransform { - MeshTransformer prepare(BlockRenderView blockView, BlockState state, BlockPos pos, Supplier randomSupplier); - - MeshTransformer prepare(ItemStack stack, Supplier randomSupplier); -} diff --git a/src/main/java/io/github/cottonmc/templates/model/SlopeBakedModel.java b/src/main/java/io/github/cottonmc/templates/model/SlopeBakedModel.java index 0bf0e1c..dccbab5 100644 --- a/src/main/java/io/github/cottonmc/templates/model/SlopeBakedModel.java +++ b/src/main/java/io/github/cottonmc/templates/model/SlopeBakedModel.java @@ -18,15 +18,12 @@ import java.util.function.Supplier; public final class SlopeBakedModel extends ForwardingBakedModel { public SlopeBakedModel(BakedModel baseModel, BlockState slopeState, Function spriteLookup) { this.wrapped = baseModel; - this.slopeState = slopeState; - this.xform = new SlopeMeshTransformer(spriteLookup); + this.preparer = new SlopeMeshTransformPreparer(spriteLookup); this.baseMesh = SlopeBaseMesh.make(slopeState); } - public final BlockState slopeState; - - private final MeshTransformer xform; + private final TemplateQuadTransformPreparer preparer; private final Mesh baseMesh; @Override @@ -36,27 +33,15 @@ public final class SlopeBakedModel extends ForwardingBakedModel { @Override public void emitBlockQuads(BlockRenderView blockView, BlockState state, BlockPos pos, Supplier randomSupplier, RenderContext context) { - MeshTransformer xform2 = xform.prepare(blockView, state, pos, randomSupplier); - - if(xform2 != null) { - context.pushTransform(xform2); - context.meshConsumer().accept(baseMesh); - context.popTransform(); - } else { - context.meshConsumer().accept(baseMesh); - } + context.pushTransform(preparer.blockTransformer(blockView, state, pos, randomSupplier)); + context.meshConsumer().accept(baseMesh); + context.popTransform(); } @Override public void emitItemQuads(ItemStack stack, Supplier randomSupplier, RenderContext context) { - MeshTransformer xform2 = xform.prepare(stack, randomSupplier); - - if(xform2 != null) { - context.pushTransform(xform2); - context.meshConsumer().accept(baseMesh); - context.popTransform(); - } else { - context.meshConsumer().accept(baseMesh); - } + context.pushTransform(preparer.itemTransformer(stack, randomSupplier)); + context.meshConsumer().accept(baseMesh); + context.popTransform(); } } diff --git a/src/main/java/io/github/cottonmc/templates/model/SlopeMeshTransformer.java b/src/main/java/io/github/cottonmc/templates/model/SlopeMeshTransformPreparer.java similarity index 93% rename from src/main/java/io/github/cottonmc/templates/model/SlopeMeshTransformer.java rename to src/main/java/io/github/cottonmc/templates/model/SlopeMeshTransformPreparer.java index b45010b..d13bf11 100644 --- a/src/main/java/io/github/cottonmc/templates/model/SlopeMeshTransformer.java +++ b/src/main/java/io/github/cottonmc/templates/model/SlopeMeshTransformPreparer.java @@ -7,6 +7,7 @@ import net.fabricmc.fabric.api.renderer.v1.material.BlendMode; import net.fabricmc.fabric.api.renderer.v1.material.MaterialFinder; import net.fabricmc.fabric.api.renderer.v1.material.RenderMaterial; import net.fabricmc.fabric.api.renderer.v1.mesh.MutableQuadView; +import net.fabricmc.fabric.api.renderer.v1.render.RenderContext; import net.fabricmc.fabric.api.rendering.data.v1.RenderAttachedBlockView; import net.fabricmc.fabric.api.util.TriState; import net.minecraft.block.Block; @@ -28,8 +29,8 @@ import net.minecraft.world.BlockRenderView; import java.util.function.Function; import java.util.function.Supplier; -public class SlopeMeshTransformer implements MeshTransformer { - public SlopeMeshTransformer(Function spriteLookup) { +public class SlopeMeshTransformPreparer implements TemplateQuadTransformPreparer, RenderContext.QuadTransform { + public SlopeMeshTransformPreparer(Function spriteLookup) { this.sprites = new SpriteSet(spriteLookup); Renderer r = RendererAccess.INSTANCE.getRenderer(); @@ -45,7 +46,7 @@ public class SlopeMeshTransformer implements MeshTransformer { private RenderMaterial material; @Override - public MeshTransformer prepare(BlockRenderView blockView, BlockState state, BlockPos pos, Supplier randomSupplier) { + public RenderContext.QuadTransform blockTransformer(BlockRenderView blockView, BlockState state, BlockPos pos, Supplier randomSupplier) { dir = state.get(Properties.HORIZONTAL_FACING); color = 0xffffff; @@ -73,7 +74,7 @@ public class SlopeMeshTransformer implements MeshTransformer { } @Override - public MeshTransformer prepare(ItemStack stack, Supplier randomSupplier) { + public RenderContext.QuadTransform itemTransformer(ItemStack stack, Supplier randomSupplier) { dir = Direction.NORTH; color = 0xffffff; sprites.clear(); diff --git a/src/main/java/io/github/cottonmc/templates/model/TemplateModelVariantProvider.java b/src/main/java/io/github/cottonmc/templates/model/TemplateModelVariantProvider.java index 3b4cc18..93fc4fc 100644 --- a/src/main/java/io/github/cottonmc/templates/model/TemplateModelVariantProvider.java +++ b/src/main/java/io/github/cottonmc/templates/model/TemplateModelVariantProvider.java @@ -21,7 +21,7 @@ public class TemplateModelVariantProvider implements ModelVariantProvider { private final Map cache = new HashMap<>(); @Override - public UnbakedModel loadModelVariant(ModelIdentifier modelId, ModelProviderContext context) throws ModelProviderException { + public @Nullable UnbakedModel loadModelVariant(ModelIdentifier modelId, ModelProviderContext context) throws ModelProviderException { UnbakedModel cacheResult = cache.get(modelId); if(cacheResult != null) return cacheResult; diff --git a/src/main/java/io/github/cottonmc/templates/model/TemplateQuadTransformPreparer.java b/src/main/java/io/github/cottonmc/templates/model/TemplateQuadTransformPreparer.java new file mode 100644 index 0000000..64f5c10 --- /dev/null +++ b/src/main/java/io/github/cottonmc/templates/model/TemplateQuadTransformPreparer.java @@ -0,0 +1,19 @@ +package io.github.cottonmc.templates.model; + +import net.fabricmc.fabric.api.renderer.v1.render.RenderContext; +import net.minecraft.block.BlockState; +import net.minecraft.item.ItemStack; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.random.Random; +import net.minecraft.world.BlockRenderView; +import org.jetbrains.annotations.NotNull; + +import java.util.function.Supplier; + +/** + * You're allowed (and encouraged) to also implement `QuadTransform` and return `this` from both of these methods. + */ +public interface TemplateQuadTransformPreparer { + @NotNull RenderContext.QuadTransform blockTransformer(BlockRenderView blockView, BlockState state, BlockPos pos, Supplier randomSupplier); + @NotNull RenderContext.QuadTransform itemTransformer(ItemStack stack, Supplier randomSupplier); +}