From 2646ce2df94f1bc8bdc448f36cc2421bb83be960 Mon Sep 17 00:00:00 2001 From: quat1024 Date: Mon, 3 Jul 2023 20:02:52 -0400 Subject: [PATCH] Don't use a random vanilla model for the parent --- README.md | 2 ++ .../cottonmc/templates/TemplatesClient.java | 5 +-- ....java => RetexturedMeshTemplateModel.java} | 26 ++++++++++------ .../templates/model/TemplateBakedModel.java | 6 ---- .../templates/models/block/slope_base.json | 31 +++++++++++++++++++ 5 files changed, 52 insertions(+), 18 deletions(-) rename src/main/java/io/github/cottonmc/templates/model/{SlopeUnbakedModel.java => RetexturedMeshTemplateModel.java} (61%) create mode 100644 src/main/resources/assets/templates/models/block/slope_base.json diff --git a/README.md b/README.md index 270a79e..66b8fe1 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,8 @@ Template blocks can be placed in the world, then right-clicked with a full-size ## Todo +* Evaluate whether I need to keep the `Supplier` in TemplatesModelProvider, or whether I can reuse my `UnbakedModel`s indefinitely +* `templates:block/slope_base` needs a suspicious amount of custom rotations. Maybe the model is pointing the wrong way. * Upside-down slopes would be nice... * More templates !! diff --git a/src/main/java/io/github/cottonmc/templates/TemplatesClient.java b/src/main/java/io/github/cottonmc/templates/TemplatesClient.java index a5ed8cd..fa9f9b1 100644 --- a/src/main/java/io/github/cottonmc/templates/TemplatesClient.java +++ b/src/main/java/io/github/cottonmc/templates/TemplatesClient.java @@ -1,6 +1,7 @@ package io.github.cottonmc.templates; -import io.github.cottonmc.templates.model.SlopeUnbakedModel; +import io.github.cottonmc.templates.model.RetexturedMeshTemplateModel; +import io.github.cottonmc.templates.model.SlopeBaseMesh; import net.fabricmc.api.ClientModInitializer; import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap; import net.fabricmc.fabric.api.client.model.ModelLoadingRegistry; @@ -54,7 +55,7 @@ public class TemplatesClient implements ClientModInitializer { BlockRenderLayerMap.INSTANCE.putBlock(Templates.SLOPE, RenderLayer.getCutout()); - provider.addTemplateModel(Templates.id("slope_special"), SlopeUnbakedModel::new); + provider.addTemplateModel(Templates.id("slope_special"), () -> new RetexturedMeshTemplateModel(Templates.id("block/slope_base"), SlopeBaseMesh::make)); provider.assignItemModel(Templates.id("slope_special"), Templates.SLOPE); } } diff --git a/src/main/java/io/github/cottonmc/templates/model/SlopeUnbakedModel.java b/src/main/java/io/github/cottonmc/templates/model/RetexturedMeshTemplateModel.java similarity index 61% rename from src/main/java/io/github/cottonmc/templates/model/SlopeUnbakedModel.java rename to src/main/java/io/github/cottonmc/templates/model/RetexturedMeshTemplateModel.java index a982b4c..ca74b19 100644 --- a/src/main/java/io/github/cottonmc/templates/model/SlopeUnbakedModel.java +++ b/src/main/java/io/github/cottonmc/templates/model/RetexturedMeshTemplateModel.java @@ -1,8 +1,7 @@ package io.github.cottonmc.templates.model; import io.github.cottonmc.templates.TemplatesClient; -import net.minecraft.block.Blocks; -import net.minecraft.client.render.block.BlockModels; +import net.fabricmc.fabric.api.renderer.v1.mesh.Mesh; import net.minecraft.client.render.model.BakedModel; import net.minecraft.client.render.model.Baker; import net.minecraft.client.render.model.ModelBakeSettings; @@ -14,28 +13,35 @@ import net.minecraft.util.Identifier; import java.util.Collection; import java.util.Collections; import java.util.function.Function; +import java.util.function.Supplier; -public class SlopeUnbakedModel implements UnbakedModel { +@SuppressWarnings("ClassCanBeRecord") +public class RetexturedMeshTemplateModel implements UnbakedModel { + public RetexturedMeshTemplateModel(Identifier parent, Supplier baseMeshFactory) { + this.parent = parent; + this.baseMeshFactory = baseMeshFactory; + } + + protected final Identifier parent; + protected final Supplier baseMeshFactory; + @Override public Collection getModelDependencies() { - return Collections.emptyList(); + return Collections.singletonList(parent); } @Override public void setParents(Function function) { - //nothing to see here + function.apply(parent).setParents(function); //Still not sure what this function does lol } @Override public BakedModel bake(Baker baker, Function spriteLookup, ModelBakeSettings modelBakeSettings, Identifier identifier) { return new TemplateBakedModel( - //TODO: this is weird, should use my own model instead. - // I should also adjust the item frame/first-person rotations (previously I used SANDSTONE_STAIRS, which has models/block/stairs.json as a parent, - // and that one brings some extra custom rotations along for the ride - baker.bake(BlockModels.getModelId(Blocks.SANDSTONE.getDefaultState()), modelBakeSettings), + baker.bake(parent, modelBakeSettings), TemplatesClient.provider.getOrCreateTemplateApperanceManager(spriteLookup), modelBakeSettings.getRotation(), - SlopeBaseMesh.make() + baseMeshFactory.get() ); } } diff --git a/src/main/java/io/github/cottonmc/templates/model/TemplateBakedModel.java b/src/main/java/io/github/cottonmc/templates/model/TemplateBakedModel.java index ded3e04..64f62c4 100644 --- a/src/main/java/io/github/cottonmc/templates/model/TemplateBakedModel.java +++ b/src/main/java/io/github/cottonmc/templates/model/TemplateBakedModel.java @@ -72,12 +72,6 @@ public final class TemplateBakedModel extends ForwardingBakedModel { context.popTransform(); } - @Override - public boolean isSideLit() { - //Makes item models look less bad. TODO: possibly a weird spot to put this. corresponds to `gui_light: front` in the json - return false; - } - public @NotNull RenderContext.QuadTransform retexturingBlockTransformer(BlockRenderView blockView, BlockState state, BlockPos pos, Supplier randomSupplier) { BlockState template = (((RenderAttachedBlockView) blockView).getBlockEntityRenderAttachment(pos) instanceof BlockState s) ? s : null; if(template == null || template.isAir()) return new RetexturingTransformer(tam.getDefaultAppearance(), 0xFFFFFFFF, facePermutation); diff --git a/src/main/resources/assets/templates/models/block/slope_base.json b/src/main/resources/assets/templates/models/block/slope_base.json new file mode 100644 index 0000000..8855a16 --- /dev/null +++ b/src/main/resources/assets/templates/models/block/slope_base.json @@ -0,0 +1,31 @@ +{ + "parent": "block/block", + "gui_light": "front", + "display": { + "firstperson_righthand": { + "rotation": [ 0, 135, 0 ], + "translation": [ 0, 0, 0 ], + "scale": [ 0.40, 0.40, 0.40 ] + }, + "firstperson_lefthand": { + "rotation": [ 0, 135, 0 ], + "translation": [ 0, 0, 0 ], + "scale": [ 0.40, 0.40, 0.40 ] + }, + "thirdperson_righthand": { + "rotation": [ 75, -225, 0 ], + "translation": [ 0, 2.5, 0], + "scale": [ 0.375, 0.375, 0.375 ] + }, + "thirdperson_lefthand": { + "rotation": [ 75, -225, 0 ], + "translation": [ 0, 2.5, 0], + "scale": [ 0.375, 0.375, 0.375 ] + }, + "fixed": { + "rotation": [ 0, 90, 0 ], + "translation": [ 0, 0, 0], + "scale":[ 0.5, 0.5, 0.5 ] + } + } +} \ No newline at end of file