slight model simplification (eh)
This commit is contained in:
parent
c671a68354
commit
5c980183e3
@ -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<Random> randomSupplier);
|
|
||||||
|
|
||||||
MeshTransformer prepare(ItemStack stack, Supplier<Random> randomSupplier);
|
|
||||||
}
|
|
@ -18,15 +18,12 @@ import java.util.function.Supplier;
|
|||||||
public final class SlopeBakedModel extends ForwardingBakedModel {
|
public final class SlopeBakedModel extends ForwardingBakedModel {
|
||||||
public SlopeBakedModel(BakedModel baseModel, BlockState slopeState, Function<SpriteIdentifier, Sprite> spriteLookup) {
|
public SlopeBakedModel(BakedModel baseModel, BlockState slopeState, Function<SpriteIdentifier, Sprite> spriteLookup) {
|
||||||
this.wrapped = baseModel;
|
this.wrapped = baseModel;
|
||||||
this.slopeState = slopeState;
|
|
||||||
|
|
||||||
this.xform = new SlopeMeshTransformer(spriteLookup);
|
this.preparer = new SlopeMeshTransformPreparer(spriteLookup);
|
||||||
this.baseMesh = SlopeBaseMesh.make(slopeState);
|
this.baseMesh = SlopeBaseMesh.make(slopeState);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final BlockState slopeState;
|
private final TemplateQuadTransformPreparer preparer;
|
||||||
|
|
||||||
private final MeshTransformer xform;
|
|
||||||
private final Mesh baseMesh;
|
private final Mesh baseMesh;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -36,27 +33,15 @@ public final class SlopeBakedModel extends ForwardingBakedModel {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void emitBlockQuads(BlockRenderView blockView, BlockState state, BlockPos pos, Supplier<Random> randomSupplier, RenderContext context) {
|
public void emitBlockQuads(BlockRenderView blockView, BlockState state, BlockPos pos, Supplier<Random> randomSupplier, RenderContext context) {
|
||||||
MeshTransformer xform2 = xform.prepare(blockView, state, pos, randomSupplier);
|
context.pushTransform(preparer.blockTransformer(blockView, state, pos, randomSupplier));
|
||||||
|
context.meshConsumer().accept(baseMesh);
|
||||||
if(xform2 != null) {
|
context.popTransform();
|
||||||
context.pushTransform(xform2);
|
|
||||||
context.meshConsumer().accept(baseMesh);
|
|
||||||
context.popTransform();
|
|
||||||
} else {
|
|
||||||
context.meshConsumer().accept(baseMesh);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void emitItemQuads(ItemStack stack, Supplier<Random> randomSupplier, RenderContext context) {
|
public void emitItemQuads(ItemStack stack, Supplier<Random> randomSupplier, RenderContext context) {
|
||||||
MeshTransformer xform2 = xform.prepare(stack, randomSupplier);
|
context.pushTransform(preparer.itemTransformer(stack, randomSupplier));
|
||||||
|
context.meshConsumer().accept(baseMesh);
|
||||||
if(xform2 != null) {
|
context.popTransform();
|
||||||
context.pushTransform(xform2);
|
|
||||||
context.meshConsumer().accept(baseMesh);
|
|
||||||
context.popTransform();
|
|
||||||
} else {
|
|
||||||
context.meshConsumer().accept(baseMesh);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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.MaterialFinder;
|
||||||
import net.fabricmc.fabric.api.renderer.v1.material.RenderMaterial;
|
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.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.rendering.data.v1.RenderAttachedBlockView;
|
||||||
import net.fabricmc.fabric.api.util.TriState;
|
import net.fabricmc.fabric.api.util.TriState;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
@ -28,8 +29,8 @@ import net.minecraft.world.BlockRenderView;
|
|||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
public class SlopeMeshTransformer implements MeshTransformer {
|
public class SlopeMeshTransformPreparer implements TemplateQuadTransformPreparer, RenderContext.QuadTransform {
|
||||||
public SlopeMeshTransformer(Function<SpriteIdentifier, Sprite> spriteLookup) {
|
public SlopeMeshTransformPreparer(Function<SpriteIdentifier, Sprite> spriteLookup) {
|
||||||
this.sprites = new SpriteSet(spriteLookup);
|
this.sprites = new SpriteSet(spriteLookup);
|
||||||
|
|
||||||
Renderer r = RendererAccess.INSTANCE.getRenderer();
|
Renderer r = RendererAccess.INSTANCE.getRenderer();
|
||||||
@ -45,7 +46,7 @@ public class SlopeMeshTransformer implements MeshTransformer {
|
|||||||
private RenderMaterial material;
|
private RenderMaterial material;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MeshTransformer prepare(BlockRenderView blockView, BlockState state, BlockPos pos, Supplier<Random> randomSupplier) {
|
public RenderContext.QuadTransform blockTransformer(BlockRenderView blockView, BlockState state, BlockPos pos, Supplier<Random> randomSupplier) {
|
||||||
dir = state.get(Properties.HORIZONTAL_FACING);
|
dir = state.get(Properties.HORIZONTAL_FACING);
|
||||||
color = 0xffffff;
|
color = 0xffffff;
|
||||||
|
|
||||||
@ -73,7 +74,7 @@ public class SlopeMeshTransformer implements MeshTransformer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MeshTransformer prepare(ItemStack stack, Supplier<Random> randomSupplier) {
|
public RenderContext.QuadTransform itemTransformer(ItemStack stack, Supplier<Random> randomSupplier) {
|
||||||
dir = Direction.NORTH;
|
dir = Direction.NORTH;
|
||||||
color = 0xffffff;
|
color = 0xffffff;
|
||||||
sprites.clear();
|
sprites.clear();
|
@ -21,7 +21,7 @@ public class TemplateModelVariantProvider implements ModelVariantProvider {
|
|||||||
private final Map<ModelIdentifier, UnbakedModel> cache = new HashMap<>();
|
private final Map<ModelIdentifier, UnbakedModel> cache = new HashMap<>();
|
||||||
|
|
||||||
@Override
|
@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);
|
UnbakedModel cacheResult = cache.get(modelId);
|
||||||
if(cacheResult != null) return cacheResult;
|
if(cacheResult != null) return cacheResult;
|
||||||
|
|
||||||
|
@ -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<Random> randomSupplier);
|
||||||
|
@NotNull RenderContext.QuadTransform itemTransformer(ItemStack stack, Supplier<Random> randomSupplier);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user