Search in sources :

Example 71 with IBakedModel

use of net.minecraft.client.renderer.block.model.IBakedModel in project Adventurers-Toolbox by the-realest-stu.

the class MaceModel method bake.

@Override
public IBakedModel bake(IModelState state, VertexFormat format, java.util.function.Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter) {
    ImmutableMap<TransformType, TRSRTransformation> transformMap = PerspectiveMapWrapper.getTransforms(state);
    TRSRTransformation transform = (TRSRTransformation.identity());
    ImmutableList.Builder<BakedQuad> builder = ImmutableList.builder();
    if (headTexture != null && haftTexture != null && handleTexture != null) {
        ImmutableList.Builder<ResourceLocation> texBuilder = ImmutableList.builder();
        if (haftTexture != null) {
            texBuilder.add(haftTexture);
        }
        if (headTexture != null) {
            texBuilder.add(headTexture);
        }
        if (handleTexture != null) {
            texBuilder.add(handleTexture);
        }
        if (adornmentTexture != null) {
            texBuilder.add(adornmentTexture);
        }
        ImmutableList<ResourceLocation> textures = texBuilder.build();
        IBakedModel model = (new ItemLayerModel(textures)).bake(state, format, bakedTextureGetter);
        builder.addAll(model.getQuads(null, null, 0));
    }
    return new BakedMaceModel(this, builder.build(), format, Maps.immutableEnumMap(transformMap), Maps.<String, IBakedModel>newHashMap());
}
Also used : TRSRTransformation(net.minecraftforge.common.model.TRSRTransformation) BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) ImmutableList(com.google.common.collect.ImmutableList) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ResourceLocation(net.minecraft.util.ResourceLocation) ItemLayerModel(net.minecraftforge.client.model.ItemLayerModel) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) TransformType(net.minecraft.client.renderer.block.model.ItemCameraTransforms.TransformType) ItemOverride(net.minecraft.client.renderer.block.model.ItemOverride)

Example 72 with IBakedModel

use of net.minecraft.client.renderer.block.model.IBakedModel in project Adventurers-Toolbox by the-realest-stu.

the class ShovelModel method bake.

@Override
public IBakedModel bake(IModelState state, VertexFormat format, java.util.function.Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter) {
    ImmutableMap<TransformType, TRSRTransformation> transformMap = PerspectiveMapWrapper.getTransforms(state);
    TRSRTransformation transform = (TRSRTransformation.identity());
    ImmutableList.Builder<BakedQuad> builder = ImmutableList.builder();
    if (headTexture != null && haftTexture != null && handleTexture != null) {
        ImmutableList.Builder<ResourceLocation> texBuilder = ImmutableList.builder();
        if (haftTexture != null) {
            texBuilder.add(haftTexture);
        }
        if (headTexture != null) {
            texBuilder.add(headTexture);
        }
        if (handleTexture != null) {
            texBuilder.add(handleTexture);
        }
        if (adornmentTexture != null) {
            texBuilder.add(adornmentTexture);
        }
        ImmutableList<ResourceLocation> textures = texBuilder.build();
        IBakedModel model = (new ItemLayerModel(textures)).bake(state, format, bakedTextureGetter);
        builder.addAll(model.getQuads(null, null, 0));
    }
    return new BakedShovelModel(this, builder.build(), format, Maps.immutableEnumMap(transformMap), Maps.<String, IBakedModel>newHashMap());
}
Also used : TRSRTransformation(net.minecraftforge.common.model.TRSRTransformation) BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) ImmutableList(com.google.common.collect.ImmutableList) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ResourceLocation(net.minecraft.util.ResourceLocation) ItemLayerModel(net.minecraftforge.client.model.ItemLayerModel) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) TransformType(net.minecraft.client.renderer.block.model.ItemCameraTransforms.TransformType) ItemOverride(net.minecraft.client.renderer.block.model.ItemOverride)

Example 73 with IBakedModel

use of net.minecraft.client.renderer.block.model.IBakedModel in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class FastBlockModelRenderer method generateRenderDataFor.

private static void generateRenderDataFor(World world, IBlockState state) {
    VERTEX_BUILDER.begin(7, DefaultVertexFormats.BLOCK);
    BlockRendererDispatcher blockrendererdispatcher = Minecraft.getMinecraft().getBlockRendererDispatcher();
    IBakedModel modelFromState = blockrendererdispatcher.getModelForState(state);
    blockrendererdispatcher.getBlockModelRenderer().renderModel(Minecraft.getMinecraft().world, modelFromState, Blocks.AIR.getDefaultState(), offsetPos, VERTEX_BUILDER, false, 0);
    BufferBuilder.State toReturn = VERTEX_BUILDER.getVertexState();
    VERTEX_BUILDER.finishDrawing();
    VERTEX_BUILDER.reset();
    blockstateToVertexData.put(state, toReturn);
}
Also used : BufferBuilder(net.minecraft.client.renderer.BufferBuilder) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) BlockRendererDispatcher(net.minecraft.client.renderer.BlockRendererDispatcher)

Example 74 with IBakedModel

use of net.minecraft.client.renderer.block.model.IBakedModel in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class GibsModelRegistry method renderGibsModel.

/**
 * Note this method is very unfinished, and really is only confirmed to work on obj models.
 */
public static void renderGibsModel(String name, int brightness) {
    if (!NAMES_TO_RESOURCE_LOCATION.containsKey(name)) {
        throw new IllegalArgumentException("No registed gibs model with the name " + name + "!");
    }
    // If we don't have an IBakedModel for this gib then make one.
    if (!NAMES_TO_BAKED_MODELS.containsKey(name)) {
        ResourceLocation location = NAMES_TO_RESOURCE_LOCATION.get(name);
        try {
            IModel model = ModelLoaderRegistry.getModel(location).process(FLIP_UV_CUSTOM_DATA);
            IBakedModel bakedModel = model.bake(model.getDefaultState(), DefaultVertexFormats.ITEM, ModelLoader.defaultTextureGetter());
            NAMES_TO_BAKED_MODELS.put(name, bakedModel);
        } catch (Exception e) {
            System.err.println("No model found for: " + name);
            e.printStackTrace();
            throw new IllegalStateException();
        }
    }
    // Then if we don't have a BufferBuilder.State for this gib then make one.
    if (!NAMES_TO_BUFFER_STATES.containsKey(name)) {
        FastBlockModelRenderer.VERTEX_BUILDER.begin(7, DefaultVertexFormats.BLOCK);
        BlockRendererDispatcher blockrendererdispatcher = Minecraft.getMinecraft().getBlockRendererDispatcher();
        IBakedModel modelFromState = NAMES_TO_BAKED_MODELS.get(name);
        blockrendererdispatcher.getBlockModelRenderer().renderModel(Minecraft.getMinecraft().world, modelFromState, Blocks.AIR.getDefaultState(), offsetPos, FastBlockModelRenderer.VERTEX_BUILDER, false, 0);
        BufferBuilder.State bufferState = FastBlockModelRenderer.VERTEX_BUILDER.getVertexState();
        FastBlockModelRenderer.VERTEX_BUILDER.finishDrawing();
        FastBlockModelRenderer.VERTEX_BUILDER.reset();
        NAMES_TO_BUFFER_STATES.put(name, bufferState);
    }
    // Then if we don't have a brightness to VertexBuffer map for this gib then make one.
    if (!NAMES_AND_BRIGHTNESS_TO_VERTEX_BUFFER.containsKey(name)) {
        NAMES_AND_BRIGHTNESS_TO_VERTEX_BUFFER.put(name, new HashMap<Integer, VertexBuffer>());
    }
    // Then if the brightness to VertexBuffer map doesn't have a VertexBuffer for the given brightness then make one.
    if (!NAMES_AND_BRIGHTNESS_TO_VERTEX_BUFFER.get(name).containsKey(brightness)) {
        BufferBuilder.State bufferState = NAMES_TO_BUFFER_STATES.get(name);
        FastBlockModelRenderer.VERTEX_BUILDER.setTranslation(0, 0, 0);
        FastBlockModelRenderer.VERTEX_BUILDER.begin(7, DefaultVertexFormats.BLOCK);
        FastBlockModelRenderer.VERTEX_BUILDER.setVertexState(bufferState);
        // This code adjusts the brightness of the model rendered.
        int j = FastBlockModelRenderer.VERTEX_BUILDER.vertexFormat.getSize() >> 2;
        int cont = FastBlockModelRenderer.VERTEX_BUILDER.getVertexCount();
        int offsetUV = FastBlockModelRenderer.VERTEX_BUILDER.vertexFormat.getUvOffsetById(1) / 4;
        int bufferNextSize = FastBlockModelRenderer.VERTEX_BUILDER.vertexFormat.getIntegerSize();
        // Set the brightness manually, so that we don't have to create a new IBakedModel for each brightness.
        for (int contont = 0; contont < cont; contont += 4) {
            try {
                int i = (contont) * bufferNextSize + offsetUV;
                FastBlockModelRenderer.VERTEX_BUILDER.rawIntBuffer.put(i, brightness);
                FastBlockModelRenderer.VERTEX_BUILDER.rawIntBuffer.put(i + j, brightness);
                FastBlockModelRenderer.VERTEX_BUILDER.rawIntBuffer.put(i + j * 2, brightness);
                FastBlockModelRenderer.VERTEX_BUILDER.rawIntBuffer.put(i + j * 3, brightness);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        VertexBuffer gibVertexBuffer = new VertexBuffer(DefaultVertexFormats.BLOCK);
        // Now that the VERTEX_BUILDER has been filled with all the render data, we must
        // upload it to the gpu.
        // The VERTEX_UPLOADER copies the state of the VERTEX_BUILDER to
        // blockVertexBuffer, and then uploads it to the gpu.
        FastBlockModelRenderer.VERTEX_BUILDER.finishDrawing();
        FastBlockModelRenderer.VERTEX_BUILDER.reset();
        // Copy the data over from the BufferBuilder into the VertexBuffer, and then
        // upload that data to the gpu memory.
        gibVertexBuffer.bufferData(FastBlockModelRenderer.VERTEX_BUILDER.getByteBuffer());
        NAMES_AND_BRIGHTNESS_TO_VERTEX_BUFFER.get(name).put(brightness, gibVertexBuffer);
    }
    // Finally, once past all these checks, we can render it.
    GlStateManager.pushMatrix();
    GlStateManager.translate(-offsetPos.getX(), -offsetPos.getY(), -offsetPos.getZ());
    FastBlockModelRenderer.renderVertexBuffer(NAMES_AND_BRIGHTNESS_TO_VERTEX_BUFFER.get(name).get(brightness));
    GlStateManager.popMatrix();
}
Also used : IModel(net.minecraftforge.client.model.IModel) VertexBuffer(net.minecraft.client.renderer.vertex.VertexBuffer) BufferBuilder(net.minecraft.client.renderer.BufferBuilder) ResourceLocation(net.minecraft.util.ResourceLocation) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) BlockRendererDispatcher(net.minecraft.client.renderer.BlockRendererDispatcher)

Example 75 with IBakedModel

use of net.minecraft.client.renderer.block.model.IBakedModel in project Railcraft by Railcraft.

the class FluidModelRenderer method renderFluid.

/**
 * @param level Ranges from 1 to 16 inclusively, 0 will crash
 */
public void renderFluid(FluidStack fluidStack, int level) {
    IBakedModel bakedModel = new FluidModel(fluidStack, false).bake(TRSRTransformation.identity(), DefaultVertexFormats.BLOCK, RenderTools::getTexture);
    Minecraft mc = Minecraft.getMinecraft();
    mc.getTextureManager().bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
    mc.getTextureManager().getTexture(TextureMap.LOCATION_BLOCKS_TEXTURE).setBlurMipmap(false, false);
    Tessellator tess = Tessellator.getInstance();
    BufferBuilder buffer = tess.getBuffer();
    buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.ITEM);
    IExtendedBlockState state = (IExtendedBlockState) new ExtendedBlockState(Blocks.WATER, new IProperty[] { BlockFluidBase.LEVEL }, BlockFluidBase.FLUID_RENDER_PROPS.toArray(new IUnlistedProperty<?>[0])).getBaseState();
    for (int i = 0; i < 4; i++) state = state.withProperty(BlockFluidBase.LEVEL_CORNERS[i], level / 16F);
    state = (IExtendedBlockState) state.withProperty(BlockFluidBase.LEVEL, level - 1);
    state = state.withProperty(BlockFluidBase.FLOW_DIRECTION, -1000F);
    putQuads(buffer, bakedModel.getQuads(state, null, 1234));
    for (EnumFacing side : EnumFacing.VALUES) {
        putQuads(buffer, bakedModel.getQuads(state, side, 1234));
    }
    tess.draw();
    mc.getTextureManager().getTexture(TextureMap.LOCATION_BLOCKS_TEXTURE).restoreLastBlurMipmap();
}
Also used : Tessellator(net.minecraft.client.renderer.Tessellator) IUnlistedProperty(net.minecraftforge.common.property.IUnlistedProperty) IExtendedBlockState(net.minecraftforge.common.property.IExtendedBlockState) BufferBuilder(net.minecraft.client.renderer.BufferBuilder) IExtendedBlockState(net.minecraftforge.common.property.IExtendedBlockState) ExtendedBlockState(net.minecraftforge.common.property.ExtendedBlockState) EnumFacing(net.minecraft.util.EnumFacing) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) RenderTools(mods.railcraft.client.render.tools.RenderTools) Minecraft(net.minecraft.client.Minecraft)

Aggregations

IBakedModel (net.minecraft.client.renderer.block.model.IBakedModel)197 IBlockState (net.minecraft.block.state.IBlockState)94 BakedQuad (net.minecraft.client.renderer.block.model.BakedQuad)42 BlockPos (net.minecraft.util.math.BlockPos)40 ModelResourceLocation (net.minecraft.client.renderer.block.model.ModelResourceLocation)38 EnumFacing (net.minecraft.util.EnumFacing)38 ResourceLocation (net.minecraft.util.ResourceLocation)36 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)30 ItemStack (net.minecraft.item.ItemStack)27 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)24 Block (net.minecraft.block.Block)23 IModel (net.minecraftforge.client.model.IModel)22 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)22 ArrayList (java.util.ArrayList)20 IExtendedBlockState (net.minecraftforge.common.property.IExtendedBlockState)17 Minecraft (net.minecraft.client.Minecraft)15 BlockRendererDispatcher (net.minecraft.client.renderer.BlockRendererDispatcher)15 List (java.util.List)14 ItemOverride (net.minecraft.client.renderer.block.model.ItemOverride)14 ImmutableList (com.google.common.collect.ImmutableList)13