Search in sources :

Example 1 with FabricBakedModel

use of net.fabricmc.fabric.api.renderer.v1.model.FabricBakedModel in project Botania by VazkiiMods.

the class FabricPlatformModel method emitBlockQuads.

@Override
public void emitBlockQuads(BlockAndTintGetter blockView, BlockState state, BlockPos pos, Supplier<Random> randomSupplier, RenderContext context) {
    if (!(state.getBlock() instanceof BlockPlatform)) {
        context.fallbackConsumer().accept(Minecraft.getInstance().getBlockRenderer().getBlockModelShaper().getModelManager().getMissingModel());
        return;
    }
    Object data = ((RenderAttachedBlockView) blockView).getBlockEntityRenderAttachment(pos);
    if (data instanceof TilePlatform.PlatformData) {
        BlockPos heldPos = ((TilePlatform.PlatformData) data).pos();
        BlockState heldState = ((TilePlatform.PlatformData) data).state();
        if (heldState == null) {
            // No camo
            super.emitBlockQuads(blockView, state, pos, randomSupplier, context);
        } else {
            // Some people used this to get an invisible block in the past, accommodate that.
            if (heldState.is(ModBlocks.manaGlass)) {
                return;
            }
            BakedModel model = Minecraft.getInstance().getBlockRenderer().getBlockModelShaper().getBlockModel(heldState);
            if (model instanceof FabricBakedModel) {
                // Steal camo's model
                ((FabricBakedModel) model).emitBlockQuads(blockView, heldState, heldPos, randomSupplier, context);
            }
        }
    }
}
Also used : RenderAttachedBlockView(net.fabricmc.fabric.api.rendering.data.v1.RenderAttachedBlockView) BlockState(net.minecraft.world.level.block.state.BlockState) BakedModel(net.minecraft.client.resources.model.BakedModel) FabricBakedModel(net.fabricmc.fabric.api.renderer.v1.model.FabricBakedModel) ForwardingBakedModel(net.fabricmc.fabric.api.renderer.v1.model.ForwardingBakedModel) BlockPos(net.minecraft.core.BlockPos) FabricBakedModel(net.fabricmc.fabric.api.renderer.v1.model.FabricBakedModel) BlockPlatform(vazkii.botania.common.block.BlockPlatform)

Example 2 with FabricBakedModel

use of net.fabricmc.fabric.api.renderer.v1.model.FabricBakedModel in project Indium by comp500.

the class IndiumTerrainRenderContext method tesselateBlock.

/**
 * Called from chunk renderer hook.
 */
public boolean tesselateBlock(BlockState blockState, BlockPos blockPos, final BakedModel model, MatrixStack matrixStack) {
    this.matrix = matrixStack.peek().getModel();
    this.normalMatrix = matrixStack.peek().getNormal();
    try {
        aoCalc.clear();
        blockInfo.prepareForBlock(blockState, blockPos, model.useAmbientOcclusion());
        ((FabricBakedModel) model).emitBlockQuads(blockInfo.blockView, blockInfo.blockState, blockInfo.blockPos, blockInfo.randomSupplier, this);
    } catch (Throwable var9) {
        CrashReport crashReport_1 = CrashReport.create(var9, "Tesselating block in world - Indium Renderer");
        CrashReportSection crashReportElement_1 = crashReport_1.addElement("Block being tesselated");
        CrashReportSection.addBlockInfo(crashReportElement_1, blockPos, blockState);
        throw new CrashException(crashReport_1);
    }
    // false because we've already marked the chunk as populated - caller doesn't need to
    return false;
}
Also used : CrashException(net.minecraft.util.crash.CrashException) CrashReport(net.minecraft.util.crash.CrashReport) FabricBakedModel(net.fabricmc.fabric.api.renderer.v1.model.FabricBakedModel) CrashReportSection(net.minecraft.util.crash.CrashReportSection)

Example 3 with FabricBakedModel

use of net.fabricmc.fabric.api.renderer.v1.model.FabricBakedModel in project Indium by comp500.

the class MixinItemRenderer method hook_method_23179.

@Inject(at = @At("HEAD"), method = "renderItem(Lnet/minecraft/item/ItemStack;Lnet/minecraft/client/render/model/json/ModelTransformation$Mode;ZLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;IILnet/minecraft/client/render/model/BakedModel;)V", cancellable = true)
public void hook_method_23179(ItemStack stack, ModelTransformation.Mode transformMode, boolean invert, MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int light, int overlay, BakedModel model, CallbackInfo ci) {
    final FabricBakedModel fabricModel = (FabricBakedModel) model;
    if (!(stack.isEmpty() || fabricModel.isVanillaAdapter())) {
        CONTEXTS.get().renderModel(stack, transformMode, invert, matrixStack, vertexConsumerProvider, light, overlay, fabricModel, vanillaHandler);
        ci.cancel();
    }
}
Also used : FabricBakedModel(net.fabricmc.fabric.api.renderer.v1.model.FabricBakedModel) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 4 with FabricBakedModel

use of net.fabricmc.fabric.api.renderer.v1.model.FabricBakedModel in project fabric by FabricMC.

the class MixinItemRenderer method hookRenderModel.

@Inject(at = @At("HEAD"), method = "renderModel", cancellable = true)
private void hookRenderModel(BakedModel model, int color, ItemStack stack, CallbackInfo ci) {
    FabricBakedModel fabricModel = (FabricBakedModel) model;
    if (!fabricModel.isVanillaAdapter()) {
        CONTEXTS.get().renderModel(fabricModel, color, stack, this::renderQuads);
        ci.cancel();
    }
}
Also used : FabricBakedModel(net.fabricmc.fabric.api.renderer.v1.model.FabricBakedModel) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 5 with FabricBakedModel

use of net.fabricmc.fabric.api.renderer.v1.model.FabricBakedModel in project fabric by FabricMC.

the class TerrainRenderContext method tesselateBlock.

/**
 * Called from chunk renderer hook.
 */
public boolean tesselateBlock(BlockState blockState, BlockPos blockPos, final BakedModel model) {
    try {
        aoCalc.clear();
        blockInfo.prepareForBlock(blockState, blockPos, model.useAmbientOcclusion());
        chunkInfo.beginBlock();
        ((FabricBakedModel) model).emitBlockQuads(blockInfo.blockView, blockInfo.blockState, blockInfo.blockPos, blockInfo.randomSupplier, this);
    } catch (Throwable var9) {
        CrashReport crashReport_1 = CrashReport.create(var9, "Tesselating block in world - Indigo Renderer");
        CrashReportSection crashReportElement_1 = crashReport_1.addElement("Block being tesselated");
        CrashReportSection.addBlockInfo(crashReportElement_1, blockPos, blockState);
        throw new CrashException(crashReport_1);
    }
    return chunkInfo.resultFlags[blockInfo.defaultLayerIndex];
}
Also used : CrashException(net.minecraft.util.crash.CrashException) CrashReport(net.minecraft.util.crash.CrashReport) FabricBakedModel(net.fabricmc.fabric.api.renderer.v1.model.FabricBakedModel) CrashReportSection(net.minecraft.util.crash.CrashReportSection)

Aggregations

FabricBakedModel (net.fabricmc.fabric.api.renderer.v1.model.FabricBakedModel)5 CrashException (net.minecraft.util.crash.CrashException)2 CrashReport (net.minecraft.util.crash.CrashReport)2 CrashReportSection (net.minecraft.util.crash.CrashReportSection)2 Inject (org.spongepowered.asm.mixin.injection.Inject)2 ForwardingBakedModel (net.fabricmc.fabric.api.renderer.v1.model.ForwardingBakedModel)1 RenderAttachedBlockView (net.fabricmc.fabric.api.rendering.data.v1.RenderAttachedBlockView)1 BakedModel (net.minecraft.client.resources.model.BakedModel)1 BlockPos (net.minecraft.core.BlockPos)1 BlockState (net.minecraft.world.level.block.state.BlockState)1 BlockPlatform (vazkii.botania.common.block.BlockPlatform)1