Search in sources :

Example 11 with BakedQuad

use of net.minecraft.client.renderer.block.model.BakedQuad in project ImmersiveEngineering by BluSunrize.

the class ClientUtils method getSideTexture.

public static ResourceLocation getSideTexture(@Nonnull IBlockState state, EnumFacing side) {
    IBakedModel model = mc().getBlockRendererDispatcher().getModelForState(state);
    List<BakedQuad> quads = model.getQuads(state, side, 0);
    if (//no quads for the specified side D:
    quads == null || quads.isEmpty())
        quads = model.getQuads(state, null, 0);
    if (//no quads at all D:
    quads == null || quads.isEmpty())
        return null;
    return new ResourceLocation(quads.get(0).getSprite().getIconName());
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) UnpackedBakedQuad(net.minecraftforge.client.model.pipeline.UnpackedBakedQuad) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel)

Example 12 with BakedQuad

use of net.minecraft.client.renderer.block.model.BakedQuad in project ImmersiveEngineering by BluSunrize.

the class ClientUtils method renderQuads.

public static void renderQuads(Collection<BakedQuad> quads, float brightness, float red, float green, float blue) {
    Tessellator tessellator = Tessellator.getInstance();
    VertexBuffer vertexbuffer = tessellator.getBuffer();
    for (BakedQuad bakedquad : quads) {
        vertexbuffer.begin(7, DefaultVertexFormats.ITEM);
        vertexbuffer.addVertexData(bakedquad.getVertexData());
        if (bakedquad.hasTintIndex())
            vertexbuffer.putColorRGB_F4(red * brightness, green * brightness, blue * brightness);
        else
            vertexbuffer.putColorRGB_F4(brightness, brightness, brightness);
        Vec3i vec3i = bakedquad.getFace().getDirectionVec();
        vertexbuffer.putNormal((float) vec3i.getX(), (float) vec3i.getY(), (float) vec3i.getZ());
        tessellator.draw();
    }
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) UnpackedBakedQuad(net.minecraftforge.client.model.pipeline.UnpackedBakedQuad) Vec3i(net.minecraft.util.math.Vec3i)

Example 13 with BakedQuad

use of net.minecraft.client.renderer.block.model.BakedQuad in project ImmersiveEngineering by BluSunrize.

the class TileRenderBucketWheel method renderTileEntityAt.

@Override
public void renderTileEntityAt(TileEntityBucketWheel tile, double x, double y, double z, float f, int destroyStage) {
    if (!tile.formed || !tile.getWorld().isBlockLoaded(tile.getPos(), false) || tile.isDummy())
        return;
    final BlockRendererDispatcher blockRenderer = Minecraft.getMinecraft().getBlockRendererDispatcher();
    IBlockState state = tile.getWorld().getBlockState(tile.getPos());
    if (state.getBlock() != IEContent.blockMetalMultiblock)
        return;
    if (model == null) {
        state = state.withProperty(IEProperties.DYNAMICRENDER, true);
        model = blockRenderer.getModelForState(state);
    }
    OBJState objState = null;
    HashMap<String, String> texMap = new HashMap<>();
    if (state instanceof IExtendedBlockState) {
        ArrayList<String> list = Lists.newArrayList("bucketWheel");
        synchronized (tile.digStacks) {
            for (int i = 0; i < tile.digStacks.length; i++) if (tile.digStacks[i] != null) {
                list.add("dig" + i);
                Block b = Block.getBlockFromItem(tile.digStacks[i].getItem());
                IBlockState digState = b != null ? b.getStateFromMeta(tile.digStacks[i].getMetadata()) : Blocks.STONE.getDefaultState();
                IBakedModel digModel = Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes().getModelForState(digState);
                if (digModel != null && digModel.getParticleTexture() != null)
                    texMap.put("dig" + i, digModel.getParticleTexture().getIconName());
            }
        }
        objState = new OBJState(list, true);
    }
    Tessellator tessellator = Tessellator.getInstance();
    GlStateManager.pushMatrix();
    GlStateManager.translate(x + .5, y + .5, z + .5);
    GlStateManager.blendFunc(770, 771);
    GlStateManager.enableBlend();
    GlStateManager.disableCull();
    EnumFacing facing = tile.facing;
    if (tile.mirrored) {
        GlStateManager.scale(facing.getAxis() == Axis.X ? -1 : 1, 1, facing.getAxis() == Axis.Z ? -1 : 1);
        GlStateManager.disableCull();
    }
    float dir = tile.facing == EnumFacing.SOUTH ? 90 : tile.facing == EnumFacing.NORTH ? -90 : tile.facing == EnumFacing.EAST ? 180 : 0;
    GlStateManager.rotate(dir, 0, 1, 0);
    float rot = tile.rotation + (float) (tile.active ? IEConfig.Machines.excavator_speed * f : 0);
    GlStateManager.rotate(rot, 1, 0, 0);
    RenderHelper.disableStandardItemLighting();
    Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
    VertexBuffer worldRenderer = tessellator.getBuffer();
    worldRenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
    worldRenderer.setTranslation(-.5, -.5, -.5);
    List<BakedQuad> quads;
    if (model instanceof IESmartObjModel)
        quads = ((IESmartObjModel) model).getQuads(state, null, 0, objState, texMap, true);
    else
        quads = model.getQuads(state, null, 0);
    ClientUtils.renderModelTESR(quads, worldRenderer, tile.getWorld().getCombinedLight(tile.getPos(), 0));
    worldRenderer.setTranslation(0, 0, 0);
    tessellator.draw();
    GlStateManager.popMatrix();
    RenderHelper.enableStandardItemLighting();
    GlStateManager.disableBlend();
    GlStateManager.enableCull();
    if (tile.mirrored) {
        GlStateManager.enableCull();
    }
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) IBlockState(net.minecraft.block.state.IBlockState) HashMap(java.util.HashMap) EnumFacing(net.minecraft.util.EnumFacing) IExtendedBlockState(net.minecraftforge.common.property.IExtendedBlockState) IESmartObjModel(blusunrize.immersiveengineering.client.models.IESmartObjModel) Block(net.minecraft.block.Block) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) OBJState(net.minecraftforge.client.model.obj.OBJModel.OBJState)

Example 14 with BakedQuad

use of net.minecraft.client.renderer.block.model.BakedQuad in project MorePlanets by SteveKunG.

the class ClientRendererUtil method renderModelBrightnessColorQuads.

private static void renderModelBrightnessColorQuads(float brightness, float red, float green, float blue, List<BakedQuad> listQuads) {
    Tessellator tessellator = Tessellator.getInstance();
    BufferBuilder vertexbuffer = tessellator.getBuffer();
    int i = 0;
    for (int j = listQuads.size(); i < j; ++i) {
        BakedQuad bakedquad = listQuads.get(i);
        vertexbuffer.begin(7, DefaultVertexFormats.ITEM);
        vertexbuffer.addVertexData(bakedquad.getVertexData());
        if (bakedquad.hasTintIndex()) {
            ClientRendererUtil.putColorRGB_F4(vertexbuffer, red * brightness, green * brightness, blue * brightness);
        } else {
            ClientRendererUtil.putColorRGB_F4(vertexbuffer, brightness, brightness, brightness);
        }
        Vec3i vec3i = bakedquad.getFace().getDirectionVec();
        vertexbuffer.putNormal(vec3i.getX(), vec3i.getY(), vec3i.getZ());
        tessellator.draw();
    }
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) Vec3i(net.minecraft.util.math.Vec3i) Tessellator(net.minecraft.client.renderer.Tessellator) BufferBuilder(net.minecraft.client.renderer.BufferBuilder)

Example 15 with BakedQuad

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

the class AnimationModelBase method render.

@SuppressWarnings("unchecked")
@Override
public void render(Entity entity, float limbSwing, float limbSwingSpeed, float timeAlive, float yawHead, float rotationPitch, float scale) {
    IAnimationStateMachine capability = entity.getCapability(CapabilityAnimation.ANIMATION_CAPABILITY, null);
    if (capability == null) {
        return;
    }
    Pair<IModelState, Iterable<Event>> pair = capability.apply(timeAlive / 20);
    handleEvents((T) entity, timeAlive / 20, pair.getRight());
    IModel model = ModelLoaderRegistry.getModelOrMissing(modelLocation);
    IBakedModel bakedModel = model.bake(pair.getLeft(), DefaultVertexFormats.ITEM, ModelLoader.defaultTextureGetter());
    BlockPos pos = new BlockPos(entity.posX, entity.posY + entity.height, entity.posZ);
    RenderHelper.disableStandardItemLighting();
    GlStateManager.pushMatrix();
    GlStateManager.rotate(180, 0, 0, 1);
    Tessellator tessellator = Tessellator.getInstance();
    VertexBuffer VertexBuffer = tessellator.getBuffer();
    VertexBuffer.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
    VertexBuffer.setTranslation(-0.5, -1.5, -0.5);
    lighter.setParent(new VertexBufferConsumer(VertexBuffer));
    lighter.setWorld(entity.world);
    lighter.setState(Blocks.AIR.getDefaultState());
    lighter.setBlockPos(pos);
    boolean empty = true;
    List<BakedQuad> quads = bakedModel.getQuads(null, null, 0);
    if (!quads.isEmpty()) {
        lighter.updateBlockInfo();
        empty = false;
        for (BakedQuad quad : quads) {
            quad.pipe(lighter);
        }
    }
    for (EnumFacing side : EnumFacing.values()) {
        quads = bakedModel.getQuads(null, side, 0);
        if (!quads.isEmpty()) {
            if (empty)
                lighter.updateBlockInfo();
            empty = false;
            for (BakedQuad quad : quads) {
                quad.pipe(lighter);
            }
        }
    }
    // debug quad
    /*VertexBuffer.pos(0, 1, 0).color(0xFF, 0xFF, 0xFF, 0xFF).tex(0, 0).lightmap(240, 0).endVertex();
        VertexBuffer.pos(0, 1, 1).color(0xFF, 0xFF, 0xFF, 0xFF).tex(0, 1).lightmap(240, 0).endVertex();
        VertexBuffer.pos(1, 1, 1).color(0xFF, 0xFF, 0xFF, 0xFF).tex(1, 1).lightmap(240, 0).endVertex();
        VertexBuffer.pos(1, 1, 0).color(0xFF, 0xFF, 0xFF, 0xFF).tex(1, 0).lightmap(240, 0).endVertex();*/
    VertexBuffer.setTranslation(0, 0, 0);
    tessellator.draw();
    GlStateManager.popMatrix();
    RenderHelper.enableStandardItemLighting();
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) IModel(net.minecraftforge.client.model.IModel) Tessellator(net.minecraft.client.renderer.Tessellator) VertexBufferConsumer(net.minecraftforge.client.model.pipeline.VertexBufferConsumer) VertexBuffer(net.minecraft.client.renderer.VertexBuffer) EnumFacing(net.minecraft.util.EnumFacing) IModelState(net.minecraftforge.common.model.IModelState) IAnimationStateMachine(net.minecraftforge.common.model.animation.IAnimationStateMachine) BlockPos(net.minecraft.util.math.BlockPos) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel)

Aggregations

BakedQuad (net.minecraft.client.renderer.block.model.BakedQuad)30 UnpackedBakedQuad (net.minecraftforge.client.model.pipeline.UnpackedBakedQuad)13 IBakedModel (net.minecraft.client.renderer.block.model.IBakedModel)12 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)8 EnumFacing (net.minecraft.util.EnumFacing)8 Tessellator (net.minecraft.client.renderer.Tessellator)6 Vec3i (net.minecraft.util.math.Vec3i)6 VertexBuffer (net.minecraft.client.renderer.VertexBuffer)5 IExtendedBlockState (net.minecraftforge.common.property.IExtendedBlockState)5 Vector3f (org.lwjgl.util.vector.Vector3f)5 Matrix4 (blusunrize.immersiveengineering.common.util.chickenbones.Matrix4)4 ImmutableList (com.google.common.collect.ImmutableList)4 IBlockState (net.minecraft.block.state.IBlockState)4 ResourceLocation (net.minecraft.util.ResourceLocation)4 BlockPos (net.minecraft.util.math.BlockPos)4 TRSRTransformation (net.minecraftforge.common.model.TRSRTransformation)4 HashMap (java.util.HashMap)3 TransformType (net.minecraft.client.renderer.block.model.ItemCameraTransforms.TransformType)3 Connection (blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Connection)2 ConveyorDirection (blusunrize.immersiveengineering.api.tool.ConveyorHandler.ConveyorDirection)2