Skip to content

Commit

Permalink
Run emitBlockQuads for each render type
Browse files Browse the repository at this point in the history
  • Loading branch information
IMS212 committed Jul 9, 2024
1 parent 01d8f33 commit 31a0855
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import net.fabricmc.fabric.api.renderer.v1.model.FabricBakedModel;
import net.fabricmc.fabric.api.util.TriState;
import net.minecraft.client.renderer.ItemBlockRenderTypes;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.block.state.BlockState;
Expand Down Expand Up @@ -88,7 +89,12 @@ public void renderModel(BakedModel model, BlockState state, BlockPos pos, BlockP

modelData = PlatformModelAccess.getInstance().getModelData(slice, model, state, pos, slice.getPlatformModelData(pos));

((FabricBakedModel) model).emitBlockQuads(this.level, state, pos, this.randomSupplier, this);
Iterable<RenderType> renderTypes = PlatformModelAccess.getInstance().getModelRenderTypes(level, model, state, pos, random, modelData);

for (RenderType type : renderTypes) {
this.type = type;
((FabricBakedModel) model).emitBlockQuads(this.level, state, pos, this.randomSupplier, this);
}

type = null;
modelData = SodiumModelData.EMPTY;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ protected void shadeQuad(MutableQuadViewImpl quad, LightMode lightMode, boolean
/* Handling of vanilla models - this is the hot path for non-modded models */
public void bufferDefaultModel(BakedModel model, @Nullable BlockState state) {
MutableQuadViewImpl editorQuad = this.editorQuad;
Iterable<RenderType> types = PlatformModelAccess.getInstance().getModelRenderTypes(level, model, state, pos, random, modelData);


// If there is no transform, we can check the culling face once for all the quads,
Expand All @@ -226,37 +225,32 @@ public void bufferDefaultModel(BakedModel model, @Nullable BlockState state) {
final Direction cullFace = ModelHelper.faceFromIndex(i);

RandomSource random = this.randomSupplier.get();
RenderType prevType = type;
for (RenderType type : types) {
this.type = type;
TriState ao = PlatformBlockAccess.getInstance().usesAmbientOcclusion(model, state, modelData, type, slice, pos);
if (noTransform) {
if (!this.isFaceCulled(cullFace)) {
final List<BakedQuad> quads = PlatformModelAccess.getInstance().getQuads(level, pos, model, state, cullFace, random, type, modelData);
final int count = quads.size();

for (int j = 0; j < count; j++) {
final BakedQuad q = quads.get(j);
editorQuad.fromVanilla(q, (type == RenderType.tripwire() || type == RenderType.translucent()) ? TRANSLUCENT_MATERIAL : STANDARD_MATERIALS[ao.ordinal()], cullFace);
// Call processQuad instead of emit for efficiency
// (avoid unnecessarily clearing data, trying to apply transforms, and performing cull check again)

this.processQuad(editorQuad);
}
}
} else {
TriState ao = PlatformBlockAccess.getInstance().usesAmbientOcclusion(model, state, modelData, type, slice, pos);
if (noTransform) {
if (!this.isFaceCulled(cullFace)) {
final List<BakedQuad> quads = PlatformModelAccess.getInstance().getQuads(level, pos, model, state, cullFace, random, type, modelData);
final int count = quads.size();

for (int j = 0; j < count; j++) {
final BakedQuad q = quads.get(j);
editorQuad.fromVanilla(q, (type == RenderType.tripwire() || type == RenderType.translucent()) ? TRANSLUCENT_MATERIAL : STANDARD_MATERIALS[ao.ordinal()], cullFace);
// Call renderQuad instead of emit for efficiency
// (avoid unnecessarily clearing data)
this.renderQuad(editorQuad);
// Call processQuad instead of emit for efficiency
// (avoid unnecessarily clearing data, trying to apply transforms, and performing cull check again)

this.processQuad(editorQuad);
}
}
this.type = prevType;
} else {
final List<BakedQuad> quads = PlatformModelAccess.getInstance().getQuads(level, pos, model, state, cullFace, random, type, modelData);
final int count = quads.size();

for (int j = 0; j < count; j++) {
final BakedQuad q = quads.get(j);
editorQuad.fromVanilla(q, (type == RenderType.tripwire() || type == RenderType.translucent()) ? TRANSLUCENT_MATERIAL : STANDARD_MATERIALS[ao.ordinal()], cullFace);
// Call renderQuad instead of emit for efficiency
// (avoid unnecessarily clearing data)
this.renderQuad(editorQuad);
}
}
}

Expand Down

0 comments on commit 31a0855

Please sign in to comment.