mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2025-01-14 08:16:13 +01:00
Fix and optimize model hacks
- Remove isVanillaAdapter check from CullingBakingModel.wrap - Optimize model wrapping in ModelUtil.getBufferBuilderFromTemplate
This commit is contained in:
parent
2b5e71e172
commit
59c4ac3cb8
4 changed files with 21 additions and 7 deletions
|
@ -8,6 +8,7 @@ import java.util.function.Supplier;
|
|||
import com.jozufozu.flywheel.core.virtual.VirtualEmptyBlockGetter;
|
||||
import com.jozufozu.flywheel.fabric.model.CullingBakedModel;
|
||||
import com.jozufozu.flywheel.fabric.model.DefaultLayerFilteringBakedModel;
|
||||
import com.jozufozu.flywheel.fabric.model.FabricModelUtil;
|
||||
import com.jozufozu.flywheel.fabric.model.LayerFilteringBakedModel;
|
||||
import com.jozufozu.flywheel.util.Lazy;
|
||||
import com.jozufozu.flywheel.util.transform.TransformStack;
|
||||
|
@ -16,6 +17,7 @@ import com.mojang.blaze3d.vertex.DefaultVertexFormat;
|
|||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.blaze3d.vertex.VertexFormat;
|
||||
|
||||
import net.fabricmc.fabric.api.renderer.v1.model.FabricBakedModel;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.client.renderer.block.BlockModelShaper;
|
||||
|
@ -68,13 +70,20 @@ public class ModelUtil {
|
|||
if (state.getRenderShape() != RenderShape.MODEL)
|
||||
continue;
|
||||
|
||||
BakedModel model = blockModels.getBlockModel(state);
|
||||
if (((FabricBakedModel) model).isVanillaAdapter()) {
|
||||
if (!FabricModelUtil.doesLayerMatch(state, layer)) {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
model = CullingBakedModel.wrap(model);
|
||||
model = LayerFilteringBakedModel.wrap(model, layer);
|
||||
}
|
||||
|
||||
BlockPos pos = info.pos;
|
||||
|
||||
ms.pushPose();
|
||||
ms.translate(pos.getX(), pos.getY(), pos.getZ());
|
||||
BakedModel model = blockModels.getBlockModel(state);
|
||||
model = CullingBakedModel.wrap(model);
|
||||
model = LayerFilteringBakedModel.wrap(model, layer);
|
||||
modelRenderer.tesselateBlock(renderWorld, model, state, pos, ms, builder,
|
||||
true, random, 42, OverlayTexture.NO_OVERLAY);
|
||||
ms.popPose();
|
||||
|
|
|
@ -3,7 +3,6 @@ package com.jozufozu.flywheel.fabric.model;
|
|||
import java.util.Random;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import net.fabricmc.fabric.api.renderer.v1.model.FabricBakedModel;
|
||||
import net.fabricmc.fabric.api.renderer.v1.model.ForwardingBakedModel;
|
||||
import net.fabricmc.fabric.api.renderer.v1.render.RenderContext;
|
||||
import net.minecraft.client.resources.model.BakedModel;
|
||||
|
@ -22,7 +21,7 @@ public class CullingBakedModel extends ForwardingBakedModel {
|
|||
protected final BlockPos.MutableBlockPos mutablePos = new BlockPos.MutableBlockPos();
|
||||
|
||||
public static BakedModel wrap(BakedModel model) {
|
||||
if (!FabricModelUtil.FREX_LOADED && !((FabricBakedModel) model).isVanillaAdapter()) {
|
||||
if (!FabricModelUtil.FREX_LOADED) {
|
||||
CullingBakedModel wrapper = THREAD_LOCAL.get();
|
||||
wrapper.wrapped = model;
|
||||
return wrapper;
|
||||
|
|
|
@ -10,6 +10,9 @@ import net.fabricmc.fabric.api.renderer.v1.material.BlendMode;
|
|||
import net.fabricmc.fabric.api.renderer.v1.material.RenderMaterial;
|
||||
import net.fabricmc.fabric.impl.client.indigo.renderer.RenderMaterialImpl;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.client.renderer.ItemBlockRenderTypes;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
public class FabricModelUtil {
|
||||
public static final boolean INDIUM_LOADED = FabricLoader.getInstance().isModLoaded("indium");
|
||||
|
@ -61,6 +64,10 @@ public class FabricModelUtil {
|
|||
return BLEND_MODE_GETTER.getBlendMode(material);
|
||||
}
|
||||
|
||||
public static boolean doesLayerMatch(BlockState modelState, RenderType layer) {
|
||||
return ItemBlockRenderTypes.getChunkRenderType(modelState) == layer;
|
||||
}
|
||||
|
||||
private interface BlendModeGetter {
|
||||
BlendMode getBlendMode(RenderMaterial material);
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ package com.jozufozu.flywheel.fabric.model;
|
|||
import java.util.Random;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import net.fabricmc.fabric.api.renderer.v1.model.FabricBakedModel;
|
||||
import net.fabricmc.fabric.api.renderer.v1.model.ForwardingBakedModel;
|
||||
import net.fabricmc.fabric.api.renderer.v1.render.RenderContext;
|
||||
import net.minecraft.client.renderer.ItemBlockRenderTypes;
|
||||
|
@ -36,7 +35,7 @@ public class LayerFilteringBakedModel extends ForwardingBakedModel {
|
|||
@Override
|
||||
public void emitBlockQuads(BlockAndTintGetter blockView, BlockState state, BlockPos pos, Supplier<Random> randomSupplier, RenderContext context) {
|
||||
RenderType defaultLayer = ItemBlockRenderTypes.getChunkRenderType(state);
|
||||
if (((FabricBakedModel) wrapped).isVanillaAdapter()) {
|
||||
if (super.isVanillaAdapter()) {
|
||||
if (defaultLayer == targetLayer) {
|
||||
super.emitBlockQuads(blockView, state, pos, randomSupplier, context);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue