Search in sources :

Example 66 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)

Example 67 with BakedQuad

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

the class ItemLayerModel method bake.

public IBakedModel bake(IModelState state, final VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter) {
    ImmutableList.Builder<BakedQuad> builder = ImmutableList.builder();
    Optional<TRSRTransformation> transform = state.apply(Optional.<IModelPart>absent());
    for (int i = 0; i < textures.size(); i++) {
        TextureAtlasSprite sprite = bakedTextureGetter.apply(textures.get(i));
        builder.addAll(getQuadsForSprite(i, sprite, format, transform));
    }
    TextureAtlasSprite particle = bakedTextureGetter.apply(textures.isEmpty() ? new ResourceLocation("missingno") : textures.get(0));
    ImmutableMap<TransformType, TRSRTransformation> map = IPerspectiveAwareModel.MapWrapper.getTransforms(state);
    return new BakedItemModel(builder.build(), particle, map, overrides, null);
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) UnpackedBakedQuad(net.minecraftforge.client.model.pipeline.UnpackedBakedQuad) TRSRTransformation(net.minecraftforge.common.model.TRSRTransformation) ImmutableList(com.google.common.collect.ImmutableList) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) ResourceLocation(net.minecraft.util.ResourceLocation) TransformType(net.minecraft.client.renderer.block.model.ItemCameraTransforms.TransformType)

Example 68 with BakedQuad

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

the class ModelDynBucket method bake.

@Override
public IBakedModel bake(IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter) {
    ImmutableMap<TransformType, TRSRTransformation> transformMap = IPerspectiveAwareModel.MapWrapper.getTransforms(state);
    // if the fluid is a gas wi manipulate the initial state to be rotated 180° to turn it upside down
    if (flipGas && fluid != null && fluid.isGaseous()) {
        state = new ModelStateComposition(state, TRSRTransformation.blockCenterToCorner(new TRSRTransformation(null, new Quat4f(0, 0, 1, 0), null, null)));
    }
    TRSRTransformation transform = state.apply(Optional.<IModelPart>absent()).or(TRSRTransformation.identity());
    TextureAtlasSprite fluidSprite = null;
    ImmutableList.Builder<BakedQuad> builder = ImmutableList.builder();
    if (fluid != null) {
        fluidSprite = bakedTextureGetter.apply(fluid.getStill());
    }
    if (baseLocation != null) {
        // build base (insidest)
        IBakedModel model = (new ItemLayerModel(ImmutableList.of(baseLocation))).bake(state, format, bakedTextureGetter);
        builder.addAll(model.getQuads(null, null, 0));
    }
    if (liquidLocation != null && fluidSprite != null) {
        TextureAtlasSprite liquid = bakedTextureGetter.apply(liquidLocation);
        // build liquid layer (inside)
        builder.addAll(ItemTextureQuadConverter.convertTexture(format, transform, liquid, fluidSprite, NORTH_Z_FLUID, EnumFacing.NORTH, fluid.getColor()));
        builder.addAll(ItemTextureQuadConverter.convertTexture(format, transform, liquid, fluidSprite, SOUTH_Z_FLUID, EnumFacing.SOUTH, fluid.getColor()));
    }
    if (coverLocation != null) {
        // cover (the actual item around the other two)
        TextureAtlasSprite base = bakedTextureGetter.apply(coverLocation);
        builder.add(ItemTextureQuadConverter.genQuad(format, transform, 0, 0, 16, 16, NORTH_Z_BASE, base, EnumFacing.NORTH, 0xffffffff));
        builder.add(ItemTextureQuadConverter.genQuad(format, transform, 0, 0, 16, 16, SOUTH_Z_BASE, base, EnumFacing.SOUTH, 0xffffffff));
    }
    return new BakedDynBucket(this, builder.build(), fluidSprite, format, Maps.immutableEnumMap(transformMap), Maps.<String, IBakedModel>newHashMap());
}
Also used : TRSRTransformation(net.minecraftforge.common.model.TRSRTransformation) BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) ImmutableList(com.google.common.collect.ImmutableList) TransformType(net.minecraft.client.renderer.block.model.ItemCameraTransforms.TransformType) IModelPart(net.minecraftforge.common.model.IModelPart) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) Quat4f(javax.vecmath.Quat4f) ItemOverride(net.minecraft.client.renderer.block.model.ItemOverride)

Example 69 with BakedQuad

use of net.minecraft.client.renderer.block.model.BakedQuad in project Overloaded by CJ-MC-Mods.

the class ModelUtils method renderQuadsARGB.

public static void renderQuadsARGB(List<BakedQuad> listQuads, int ARGB_Hex) {
    Tessellator tessellator = Tessellator.getInstance();
    VertexBuffer vertexbuffer = tessellator.getBuffer();
    int i = 0;
    for (int j = listQuads.size(); i < j; ++i) {
        BakedQuad bakedquad = (BakedQuad) listQuads.get(i);
        vertexbuffer.begin(7, DefaultVertexFormats.ITEM);
        vertexbuffer.addVertexData(bakedquad.getVertexData());
        vertexbuffer.putColor4(ARGB_Hex);
        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) Vec3i(net.minecraft.util.math.Vec3i) Tessellator(net.minecraft.client.renderer.Tessellator) VertexBuffer(net.minecraft.client.renderer.VertexBuffer)

Example 70 with BakedQuad

use of net.minecraft.client.renderer.block.model.BakedQuad in project Overloaded by CJ-MC-Mods.

the class ModelUtils method getModelQuads.

public static List<BakedQuad> getModelQuads(IBlockState state) {
    if (!quadCache.containsKey(state)) {
        IBakedModel blockModel = Minecraft.getMinecraft().getBlockRendererDispatcher().getModelForState(state);
        List<BakedQuad> listQuads = new ArrayList<BakedQuad>();
        if (blockModel instanceof OBJModel.OBJBakedModel) {
            listQuads.addAll(blockModel.getQuads(state, null, 0));
        } else {
            for (EnumFacing face : EnumFacing.VALUES) {
                listQuads.addAll(blockModel.getQuads(state, face, 0));
            }
        }
        quadCache.put(state, listQuads);
    }
    if (quadCache.containsKey(state)) {
        return quadCache.get(state);
    }
    return new ArrayList<BakedQuad>();
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) EnumFacing(net.minecraft.util.EnumFacing) ArrayList(java.util.ArrayList) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel)

Aggregations

BakedQuad (net.minecraft.client.renderer.block.model.BakedQuad)130 IBakedModel (net.minecraft.client.renderer.block.model.IBakedModel)43 EnumFacing (net.minecraft.util.EnumFacing)39 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)36 ArrayList (java.util.ArrayList)27 IBlockState (net.minecraft.block.state.IBlockState)24 ResourceLocation (net.minecraft.util.ResourceLocation)23 ImmutableList (com.google.common.collect.ImmutableList)22 MutableQuad (buildcraft.lib.client.model.MutableQuad)19 UnpackedBakedQuad (net.minecraftforge.client.model.pipeline.UnpackedBakedQuad)17 TRSRTransformation (net.minecraftforge.common.model.TRSRTransformation)16 ModelResourceLocation (net.minecraft.client.renderer.block.model.ModelResourceLocation)15 TransformType (net.minecraft.client.renderer.block.model.ItemCameraTransforms.TransformType)14 IExtendedBlockState (net.minecraftforge.common.property.IExtendedBlockState)14 List (java.util.List)13 IModel (net.minecraftforge.client.model.IModel)13 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)13 Matrix4f (javax.vecmath.Matrix4f)12 Tessellator (net.minecraft.client.renderer.Tessellator)12 ItemLayerModel (net.minecraftforge.client.model.ItemLayerModel)12