Search in sources :

Example 1 with QuadCollector

use of crazypants.enderio.base.render.util.QuadCollector in project EnderIO by SleepyTrousers.

the class BlockStateWrapperBase method bakeModel.

@Override
public void bakeModel() {
    long start = Profiler.instance.start();
    QuadCollector quads = null;
    QuadCollector overlayQuads = null;
    @Nonnull QuadCollector paintQuads = new QuadCollector();
    boolean hasPaintRendered = false;
    String cacheResult;
    if (block instanceof IBlockPaintableBlock && (!(block instanceof IWrenchHideablePaint) || !getYetaDisplayMode().isHideFacades())) {
        hasPaintRendered = PaintWrangler.wrangleBakedModel(world, pos, ((IBlockPaintableBlock) block).getPaintSource(state, world, pos), paintQuads);
    }
    boolean fromCache = doCaching && MinecraftForgeClient.getRenderLayer() != null;
    if (!hasPaintRendered || renderMapper instanceof IRenderMapper.IBlockRenderMapper.IRenderLayerAware.IPaintAware) {
        if (fromCache) {
            quads = getFromCache();
            cacheResult = quads == null ? "miss" : "hit";
        } else {
            cacheResult = "not cachable";
        }
        if (quads == null) {
            quads = new QuadCollector();
            bakeBlockLayer(quads);
            if (fromCache) {
                putIntoCache(quads);
            }
        }
    } else {
        cacheResult = "paint only";
    }
    overlayQuads = OverlayHolder.getOverlay(renderMapper.mapOverlayLayer(this, world, pos, hasPaintRendered));
    model = new CollectedQuadBakedBlockModel(paintQuads.combine(overlayQuads).combine(quads));
    Profiler.instance.stop(start, state.getBlock().getLocalizedName() + " (bake, cache=" + cacheResult + ")");
}
Also used : IWrenchHideablePaint(crazypants.enderio.base.paint.IPaintable.IWrenchHideablePaint) QuadCollector(crazypants.enderio.base.render.util.QuadCollector) Nonnull(javax.annotation.Nonnull) IRenderMapper(crazypants.enderio.base.render.IRenderMapper) IBlockPaintableBlock(crazypants.enderio.base.paint.IPaintable.IBlockPaintableBlock) CollectedQuadBakedBlockModel(crazypants.enderio.base.render.model.CollectedQuadBakedBlockModel)

Example 2 with QuadCollector

use of crazypants.enderio.base.render.util.QuadCollector in project EnderIO by SleepyTrousers.

the class BlockStateWrapperRelay method bakeModel.

@Override
public void bakeModel() {
    long start = Profiler.instance.start();
    @Nonnull QuadCollector paintQuads = new QuadCollector();
    boolean hasPaintRendered = false;
    String cacheResult;
    if (block instanceof IBlockPaintableBlock && (!(block instanceof IWrenchHideablePaint) || !getYetaDisplayMode().isHideFacades())) {
        hasPaintRendered = PaintWrangler.wrangleBakedModel(world, pos, ((IBlockPaintableBlock) block).getPaintSource(state, world, pos), paintQuads);
    }
    if (!hasPaintRendered) {
        if (MinecraftForgeClient.getRenderLayer() == null || MinecraftForgeClient.getRenderLayer() == block.getBlockLayer()) {
            model = null;
            cacheResult = "relaying";
        } else {
            model = NULL;
            cacheResult = "none";
        }
    } else {
        model = new CollectedQuadBakedBlockModel(paintQuads);
        cacheResult = "paint only";
    }
    Profiler.instance.stop(start, state.getBlock().getLocalizedName() + " (bake, cache=" + cacheResult + ")");
}
Also used : IWrenchHideablePaint(crazypants.enderio.base.paint.IPaintable.IWrenchHideablePaint) Nonnull(javax.annotation.Nonnull) QuadCollector(crazypants.enderio.base.render.util.QuadCollector) IBlockPaintableBlock(crazypants.enderio.base.paint.IPaintable.IBlockPaintableBlock) CollectedQuadBakedBlockModel(crazypants.enderio.base.render.model.CollectedQuadBakedBlockModel)

Example 3 with QuadCollector

use of crazypants.enderio.base.render.util.QuadCollector in project EnderIO by SleepyTrousers.

the class OverlayHolder method collectOverlayQuads.

public static void collectOverlayQuads(@Nonnull ModelBakeEvent event) {
    final Block block = ModObject.block_machine_io.getBlockNN();
    Map<IBlockState, ModelResourceLocation> locations = event.getModelManager().getBlockModelShapes().getBlockStateMapper().getVariants(block);
    NNIterator<IOMode> modes = crazypants.enderio.base.render.property.IOMode.MODES.iterator();
    while (modes.hasNext()) {
        IOMode mode = modes.next();
        IBlockState state = block.getDefaultState().withProperty(IOMode.IO, mode);
        ModelResourceLocation mrl = locations.get(state);
        if (mrl == null) {
            throw new RuntimeException("Model for state " + state + " failed to load from " + mrl + ". ");
        }
        IBakedModel model = event.getModelRegistry().getObject(mrl);
        if (model == null) {
            Log.warn("Model for state " + state + " failed to load from " + mrl + ".");
            continue;
        }
        QuadCollector quads = new QuadCollector();
        BlockRenderLayer oldRenderLayer = MinecraftForgeClient.getRenderLayer();
        BlockRenderLayer layer = block.getBlockLayer();
        ForgeHooksClient.setRenderLayer(layer);
        List<BakedQuad> generalQuads = model.getQuads(state, null, 0);
        if (!generalQuads.isEmpty()) {
            quads.addQuads(null, layer, generalQuads);
        }
        for (EnumFacing face1 : EnumFacing.values()) {
            List<BakedQuad> faceQuads = model.getQuads(state, mode.getDirection(), 0);
            if (!faceQuads.isEmpty()) {
                quads.addQuads(face1, layer, faceQuads);
            }
        }
        ForgeHooksClient.setRenderLayer(oldRenderLayer);
        data[mode.getDirection().ordinal()][mode.getIomode().ordinal()] = quads;
    }
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) IBlockState(net.minecraft.block.state.IBlockState) EnumIOMode(crazypants.enderio.base.render.property.IOMode.EnumIOMode) IOMode(crazypants.enderio.base.render.property.IOMode) EnumFacing(net.minecraft.util.EnumFacing) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) QuadCollector(crazypants.enderio.base.render.util.QuadCollector) Block(net.minecraft.block.Block) BlockRenderLayer(net.minecraft.util.BlockRenderLayer) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel)

Aggregations

QuadCollector (crazypants.enderio.base.render.util.QuadCollector)3 IBlockPaintableBlock (crazypants.enderio.base.paint.IPaintable.IBlockPaintableBlock)2 IWrenchHideablePaint (crazypants.enderio.base.paint.IPaintable.IWrenchHideablePaint)2 CollectedQuadBakedBlockModel (crazypants.enderio.base.render.model.CollectedQuadBakedBlockModel)2 Nonnull (javax.annotation.Nonnull)2 IRenderMapper (crazypants.enderio.base.render.IRenderMapper)1 IOMode (crazypants.enderio.base.render.property.IOMode)1 EnumIOMode (crazypants.enderio.base.render.property.IOMode.EnumIOMode)1 Block (net.minecraft.block.Block)1 IBlockState (net.minecraft.block.state.IBlockState)1 BakedQuad (net.minecraft.client.renderer.block.model.BakedQuad)1 IBakedModel (net.minecraft.client.renderer.block.model.IBakedModel)1 ModelResourceLocation (net.minecraft.client.renderer.block.model.ModelResourceLocation)1 BlockRenderLayer (net.minecraft.util.BlockRenderLayer)1 EnumFacing (net.minecraft.util.EnumFacing)1