Search in sources :

Example 1 with BakedQuad

use of net.minecraft.client.renderer.model.BakedQuad 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 BakedQuad

use of net.minecraft.client.renderer.model.BakedQuad in project AgriCraft by AgriCraft.

the class MysticalAgricultureCompatClient method bakeQuadsForMystical.

@Nonnull
private static List<BakedQuad> bakeQuadsForMystical(IAgriGrowable growable, IAgriGrowthStage stage, @Nullable Direction face, IntFunction<TextureAtlasSprite> spriteFunc) {
    if (face != null) {
        return ImmutableList.of();
    }
    ITessellator tessellator = AgriPlantQuadGenerator.getInstance().getTessellator();
    TextureAtlasSprite sprite = spriteFunc.apply(0);
    tessellator.startDrawingQuads();
    tessellator.setFace((Direction) null);
    tessellator.pushMatrix();
    tessellator.drawScaledFaceDouble(-2, 0, 10, 12, Direction.NORTH, sprite, 4.001F, 0, 0, 16, 16);
    tessellator.drawScaledFaceDouble(6, 0, 18, 12, Direction.NORTH, sprite, 3.999F, 0, 0, 16, 16);
    tessellator.drawScaledFaceDouble(-2, 0, 10, 12, Direction.EAST, sprite, 4.001F, 0, 0, 16, 16);
    tessellator.drawScaledFaceDouble(6, 0, 18, 12, Direction.EAST, sprite, 3.999F, 0, 0, 16, 16);
    tessellator.drawScaledFaceDouble(-2, 0, 10, 12, Direction.NORTH, sprite, 12.001F, 0, 0, 16, 16);
    tessellator.drawScaledFaceDouble(6, 0, 18, 12, Direction.NORTH, sprite, 11.999F, 0, 0, 16, 16);
    tessellator.drawScaledFaceDouble(-2, 0, 10, 12, Direction.EAST, sprite, 12.001F, 0, 0, 16, 16);
    tessellator.drawScaledFaceDouble(6, 0, 18, 12, Direction.EAST, sprite, 11.999F, 0, 0, 16, 16);
    if (stage.isFinal()) {
        IAgriPlant plant = ((IAgriPlant) growable);
        int flowerColor = MysticalAgricultureCompatClient.colorForFlower(plant.getId());
        TextureAtlasSprite flowerSprite = spriteFunc.apply(1);
        if (flowerColor != -1) {
            tessellator.setColorRGB(((flowerColor >> 16) & 0xFF) / 255.0F, ((flowerColor >> 8) & 0xFF) / 255.0F, ((flowerColor) & 0xFF) / 255.0F);
        }
        tessellator.drawScaledFaceDouble(-2, 0, 10, 12, Direction.NORTH, flowerSprite, 4.001F, 0, 0, 16, 16);
        tessellator.drawScaledFaceDouble(6, 0, 18, 12, Direction.NORTH, flowerSprite, 3.999F, 0, 0, 16, 16);
        tessellator.drawScaledFaceDouble(-2, 0, 10, 12, Direction.EAST, flowerSprite, 4.001F, 0, 0, 16, 16);
        tessellator.drawScaledFaceDouble(6, 0, 18, 12, Direction.EAST, flowerSprite, 3.999F, 0, 0, 16, 16);
        tessellator.drawScaledFaceDouble(-2, 0, 10, 12, Direction.NORTH, flowerSprite, 12.001F, 0, 0, 16, 16);
        tessellator.drawScaledFaceDouble(6, 0, 18, 12, Direction.NORTH, flowerSprite, 11.999F, 0, 0, 16, 16);
        tessellator.drawScaledFaceDouble(-2, 0, 10, 12, Direction.EAST, flowerSprite, 12.001F, 0, 0, 16, 16);
        tessellator.drawScaledFaceDouble(6, 0, 18, 12, Direction.EAST, flowerSprite, 11.999F, 0, 0, 16, 16);
    }
    tessellator.translate(0, 12.0F / 16.0F, 0);
    tessellator.popMatrix();
    List<BakedQuad> quads = tessellator.getQuads();
    tessellator.draw();
    return quads;
}
Also used : ITessellator(com.infinityraider.infinitylib.render.tessellation.ITessellator) BakedQuad(net.minecraft.client.renderer.model.BakedQuad) IAgriPlant(com.infinityraider.agricraft.api.v1.plant.IAgriPlant) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) Nonnull(javax.annotation.Nonnull)

Example 3 with BakedQuad

use of net.minecraft.client.renderer.model.BakedQuad in project AgriCraft by AgriCraft.

the class BotanyPotsPlantRenderer method fetchQuads.

protected List<BakedQuad> fetchQuads(IAgriWeed weed, IAgriGrowthStage stage, Direction... sides) {
    List<BakedQuad> quads = Lists.newArrayList();
    for (Direction dir : sides) {
        quads.addAll(AgriPlantModelBridge.getOrBakeQuads(weed, stage, dir));
    }
    quads.addAll(AgriPlantModelBridge.getOrBakeQuads(weed, stage, null));
    return quads;
}
Also used : BakedQuad(net.minecraft.client.renderer.model.BakedQuad) Direction(net.minecraft.util.Direction)

Example 4 with BakedQuad

use of net.minecraft.client.renderer.model.BakedQuad 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 5 with BakedQuad

use of net.minecraft.client.renderer.model.BakedQuad in project BluePower by Qmunity.

the class BPMultipartModel method transform.

private static BakedQuad transform(BakedQuad quad, Pair<Integer, Integer> colorPair, Boolean fullBright) {
    BakedQuadBuilder builder = new BakedQuadBuilder();
    final IVertexConsumer consumer = new VertexTransformer(builder) {

        @Override
        public void put(int element, float... data) {
            VertexFormatElement e = this.getVertexFormat().getElements().get(element);
            if (e.getUsage() == VertexFormatElement.Usage.COLOR) {
                int color = quad.getTintIndex() == 2 ? colorPair.getSecond() : colorPair.getFirst();
                int redMask = 0xFF0000, greenMask = 0xFF00, blueMask = 0xFF;
                int r = (color & redMask) >> 16;
                int g = (color & greenMask) >> 8;
                int b = (color & blueMask);
                parent.put(element, r / 255F, g / 255F, b / 255F, 1);
            } else {
                parent.put(element, data);
            }
        }
    };
    LightUtil.putBakedQuad(consumer, quad);
    BakedQuad finalQuad = builder.build();
    if (fullBright)
        LightUtil.setLightData(finalQuad, 240);
    return finalQuad;
}
Also used : BakedQuad(net.minecraft.client.renderer.model.BakedQuad) IVertexConsumer(net.minecraftforge.client.model.pipeline.IVertexConsumer) VertexTransformer(net.minecraftforge.client.model.pipeline.VertexTransformer) VertexFormatElement(net.minecraft.client.renderer.vertex.VertexFormatElement) BakedQuadBuilder(net.minecraftforge.client.model.pipeline.BakedQuadBuilder)

Aggregations

BakedQuad (net.minecraft.client.renderer.model.BakedQuad)7 Direction (net.minecraft.util.Direction)4 Nonnull (javax.annotation.Nonnull)2 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)2 VertexFormatElement (net.minecraft.client.renderer.vertex.VertexFormatElement)2 IModelData (net.minecraftforge.client.model.data.IModelData)2 BakedQuadBuilder (net.minecraftforge.client.model.pipeline.BakedQuadBuilder)2 IVertexConsumer (net.minecraftforge.client.model.pipeline.IVertexConsumer)2 VertexTransformer (net.minecraftforge.client.model.pipeline.VertexTransformer)2 TileBPMultipart (com.bluepowermod.tile.TileBPMultipart)1 TileWire (com.bluepowermod.tile.tier1.TileWire)1 MultipartUtils (com.bluepowermod.util.MultipartUtils)1 IAgriPlant (com.infinityraider.agricraft.api.v1.plant.IAgriPlant)1 ITessellator (com.infinityraider.infinitylib.render.tessellation.ITessellator)1 Pair (com.mojang.datafixers.util.Pair)1 java.util (java.util)1 Collectors (java.util.stream.Collectors)1 Nullable (javax.annotation.Nullable)1 BlockState (net.minecraft.block.BlockState)1 Minecraft (net.minecraft.client.Minecraft)1