Search in sources :

Example 1 with IModelData

use of net.minecraftforge.client.model.data.IModelData in project Bookshelf by Darkhax-Minecraft.

the class RenderUtils method renderModel.

/**
 * Renders a block model. Allows the sites rendered to be specifically controlled by the
 * caller.
 *
 * @param renderer The block model renderer instance.
 * @param world The world instance.
 * @param model The model to render.
 * @param state The state of the block.
 * @param pos The position of the block.
 * @param matrix The render matrix.
 * @param buffer The render buffer.
 * @param sides The sides of the model to render.
 */
public static void renderModel(BlockModelRenderer renderer, IBlockDisplayReader world, IBakedModel model, BlockState state, BlockPos pos, MatrixStack matrix, IVertexBuilder buffer, Direction[] sides) {
    final IModelData modelData = model.getModelData(world, pos, state, EmptyModelData.INSTANCE);
    // Renders only the sided model quads.
    for (final Direction side : sides) {
        RANDOM.setSeed(0L);
        final List<BakedQuad> sidedQuads = model.getQuads(state, side, RANDOM, modelData);
        if (!sidedQuads.isEmpty()) {
            final int lightForSide = WorldRenderer.getLightColor(world, state, pos.relative(side));
            renderer.renderModelFaceFlat(world, state, pos, lightForSide, OverlayTexture.NO_OVERLAY, false, matrix, buffer, sidedQuads, BITS);
        }
    }
    // Renders the non-sided model quads.
    RANDOM.setSeed(0L);
    final List<BakedQuad> unsidedQuads = model.getQuads(state, null, RANDOM, modelData);
    if (!unsidedQuads.isEmpty()) {
        renderer.renderModelFaceFlat(world, state, pos, -1, OverlayTexture.NO_OVERLAY, true, matrix, buffer, unsidedQuads, BITS);
    }
}
Also used : BakedQuad(net.minecraft.client.renderer.model.BakedQuad) Direction(net.minecraft.util.Direction) IModelData(net.minecraftforge.client.model.data.IModelData)

Example 2 with IModelData

use of net.minecraftforge.client.model.data.IModelData in project BluePower by Qmunity.

the class BPMultipartModel method getQuads.

@Nonnull
@Override
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, @Nonnull Random rand, @Nonnull IModelData extraData) {
    BlockRendererDispatcher brd = Minecraft.getInstance().getBlockRenderer();
    Map<BlockState, IModelData> stateInfo = extraData.getData(TileBPMultipart.STATE_INFO);
    if (stateInfo != null) {
        return stateInfo.keySet().stream().flatMap(i -> brd.getBlockModel(i).getQuads(i, side, rand, stateInfo.get(i)).stream().map(q -> stateInfo.get(i).hasProperty(TileWire.COLOR_INFO) ? transform(q, stateInfo.get(i).getData(TileWire.COLOR_INFO), stateInfo.get(i).hasProperty(TileWire.LIGHT_INFO) ? stateInfo.get(i).getData(TileWire.LIGHT_INFO) : false) : q)).collect(Collectors.toList());
    } else {
        return Collections.emptyList();
    }
}
Also used : BakedQuadBuilder(net.minecraftforge.client.model.pipeline.BakedQuadBuilder) java.util(java.util) IBakedModel(net.minecraft.client.renderer.model.IBakedModel) ItemOverrideList(net.minecraft.client.renderer.model.ItemOverrideList) Direction(net.minecraft.util.Direction) RayTraceResult(net.minecraft.util.math.RayTraceResult) Minecraft(net.minecraft.client.Minecraft) BlockState(net.minecraft.block.BlockState) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) MultipartUtils(com.bluepowermod.util.MultipartUtils) TileWire(com.bluepowermod.tile.tier1.TileWire) VertexTransformer(net.minecraftforge.client.model.pipeline.VertexTransformer) BlockRendererDispatcher(net.minecraft.client.renderer.BlockRendererDispatcher) IModelData(net.minecraftforge.client.model.data.IModelData) IVertexConsumer(net.minecraftforge.client.model.pipeline.IVertexConsumer) Collectors(java.util.stream.Collectors) TileBPMultipart(com.bluepowermod.tile.TileBPMultipart) Pair(com.mojang.datafixers.util.Pair) BakedQuad(net.minecraft.client.renderer.model.BakedQuad) BlockRayTraceResult(net.minecraft.util.math.BlockRayTraceResult) VertexFormatElement(net.minecraft.client.renderer.vertex.VertexFormatElement) LightUtil(net.minecraftforge.client.model.pipeline.LightUtil) ModelResourceLocation(net.minecraft.client.renderer.model.ModelResourceLocation) BlockState(net.minecraft.block.BlockState) IModelData(net.minecraftforge.client.model.data.IModelData) BlockRendererDispatcher(net.minecraft.client.renderer.BlockRendererDispatcher) Nonnull(javax.annotation.Nonnull)

Example 3 with IModelData

use of net.minecraftforge.client.model.data.IModelData in project MinecraftForge by MinecraftForge.

the class ModelDataManager method refreshModelData.

private static void refreshModelData(Level world, ChunkPos chunk) {
    cleanCaches(world);
    Set<BlockPos> needUpdate = needModelDataRefresh.remove(chunk);
    if (needUpdate != null) {
        Map<BlockPos, IModelData> data = modelDataCache.computeIfAbsent(chunk, $ -> new ConcurrentHashMap<>());
        for (BlockPos pos : needUpdate) {
            BlockEntity toUpdate = world.getBlockEntity(pos);
            if (toUpdate != null && !toUpdate.isRemoved()) {
                data.put(pos, toUpdate.getModelData());
            } else {
                data.remove(pos);
            }
        }
    }
}
Also used : BlockPos(net.minecraft.core.BlockPos) IModelData(net.minecraftforge.client.model.data.IModelData) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity)

Aggregations

IModelData (net.minecraftforge.client.model.data.IModelData)3 BakedQuad (net.minecraft.client.renderer.model.BakedQuad)2 Direction (net.minecraft.util.Direction)2 TileBPMultipart (com.bluepowermod.tile.TileBPMultipart)1 TileWire (com.bluepowermod.tile.tier1.TileWire)1 MultipartUtils (com.bluepowermod.util.MultipartUtils)1 Pair (com.mojang.datafixers.util.Pair)1 java.util (java.util)1 Collectors (java.util.stream.Collectors)1 Nonnull (javax.annotation.Nonnull)1 Nullable (javax.annotation.Nullable)1 BlockState (net.minecraft.block.BlockState)1 Minecraft (net.minecraft.client.Minecraft)1 BlockRendererDispatcher (net.minecraft.client.renderer.BlockRendererDispatcher)1 IBakedModel (net.minecraft.client.renderer.model.IBakedModel)1 ItemOverrideList (net.minecraft.client.renderer.model.ItemOverrideList)1 ModelResourceLocation (net.minecraft.client.renderer.model.ModelResourceLocation)1 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)1 VertexFormatElement (net.minecraft.client.renderer.vertex.VertexFormatElement)1 BlockPos (net.minecraft.core.BlockPos)1