Don't use a random vanilla model for the parent

This commit is contained in:
quat1024 2023-07-03 20:02:52 -04:00
parent 9e86b33f0a
commit 2646ce2df9
5 changed files with 52 additions and 18 deletions

View File

@ -16,6 +16,8 @@ Template blocks can be placed in the world, then right-clicked with a full-size
## Todo ## 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... * Upside-down slopes would be nice...
* More templates !! * More templates !!

View File

@ -1,6 +1,7 @@
package io.github.cottonmc.templates; 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.api.ClientModInitializer;
import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap; import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap;
import net.fabricmc.fabric.api.client.model.ModelLoadingRegistry; import net.fabricmc.fabric.api.client.model.ModelLoadingRegistry;
@ -54,7 +55,7 @@ public class TemplatesClient implements ClientModInitializer {
BlockRenderLayerMap.INSTANCE.putBlock(Templates.SLOPE, RenderLayer.getCutout()); 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); provider.assignItemModel(Templates.id("slope_special"), Templates.SLOPE);
} }
} }

View File

@ -1,8 +1,7 @@
package io.github.cottonmc.templates.model; package io.github.cottonmc.templates.model;
import io.github.cottonmc.templates.TemplatesClient; import io.github.cottonmc.templates.TemplatesClient;
import net.minecraft.block.Blocks; import net.fabricmc.fabric.api.renderer.v1.mesh.Mesh;
import net.minecraft.client.render.block.BlockModels;
import net.minecraft.client.render.model.BakedModel; import net.minecraft.client.render.model.BakedModel;
import net.minecraft.client.render.model.Baker; import net.minecraft.client.render.model.Baker;
import net.minecraft.client.render.model.ModelBakeSettings; import net.minecraft.client.render.model.ModelBakeSettings;
@ -14,28 +13,35 @@ import net.minecraft.util.Identifier;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.function.Function; 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<Mesh> baseMeshFactory) {
this.parent = parent;
this.baseMeshFactory = baseMeshFactory;
}
protected final Identifier parent;
protected final Supplier<Mesh> baseMeshFactory;
@Override @Override
public Collection<Identifier> getModelDependencies() { public Collection<Identifier> getModelDependencies() {
return Collections.emptyList(); return Collections.singletonList(parent);
} }
@Override @Override
public void setParents(Function<Identifier, UnbakedModel> function) { public void setParents(Function<Identifier, UnbakedModel> function) {
//nothing to see here function.apply(parent).setParents(function); //Still not sure what this function does lol
} }
@Override @Override
public BakedModel bake(Baker baker, Function<SpriteIdentifier, Sprite> spriteLookup, ModelBakeSettings modelBakeSettings, Identifier identifier) { public BakedModel bake(Baker baker, Function<SpriteIdentifier, Sprite> spriteLookup, ModelBakeSettings modelBakeSettings, Identifier identifier) {
return new TemplateBakedModel( return new TemplateBakedModel(
//TODO: this is weird, should use my own model instead. baker.bake(parent, modelBakeSettings),
// 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),
TemplatesClient.provider.getOrCreateTemplateApperanceManager(spriteLookup), TemplatesClient.provider.getOrCreateTemplateApperanceManager(spriteLookup),
modelBakeSettings.getRotation(), modelBakeSettings.getRotation(),
SlopeBaseMesh.make() baseMeshFactory.get()
); );
} }
} }

View File

@ -72,12 +72,6 @@ public final class TemplateBakedModel extends ForwardingBakedModel {
context.popTransform(); 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<Random> randomSupplier) { public @NotNull RenderContext.QuadTransform retexturingBlockTransformer(BlockRenderView blockView, BlockState state, BlockPos pos, Supplier<Random> randomSupplier) {
BlockState template = (((RenderAttachedBlockView) blockView).getBlockEntityRenderAttachment(pos) instanceof BlockState s) ? s : null; BlockState template = (((RenderAttachedBlockView) blockView).getBlockEntityRenderAttachment(pos) instanceof BlockState s) ? s : null;
if(template == null || template.isAir()) return new RetexturingTransformer(tam.getDefaultAppearance(), 0xFFFFFFFF, facePermutation); if(template == null || template.isAir()) return new RetexturingTransformer(tam.getDefaultAppearance(), 0xFFFFFFFF, facePermutation);

View File

@ -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 ]
}
}
}