Search in sources :

Example 11 with BlockRendererDispatcher

use of net.minecraft.client.renderer.BlockRendererDispatcher 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 12 with BlockRendererDispatcher

use of net.minecraft.client.renderer.BlockRendererDispatcher in project Bookshelf by Darkhax-Minecraft.

the class RenderUtils method renderBlock.

/**
 * Renders a block state into the world. This only exists for optifine compatibility mode.
 *
 * @param state The state to render.
 * @param world The world context to render into.
 * @param pos The position of the block.
 * @param matrix The render matrix.
 * @param buffer The render buffer.
 */
private static void renderBlock(BlockState state, World world, BlockPos pos, MatrixStack matrix, IRenderTypeBuffer buffer) {
    final BlockRendererDispatcher dispatcher = Minecraft.getInstance().getBlockRenderer();
    final IBakedModel model = dispatcher.getBlockModel(state);
    final boolean useAO = Minecraft.useAmbientOcclusion() && state.getLightValue(world, pos) == 0 && model.useAmbientOcclusion();
    final RenderType type = RenderUtils.findRenderType(state);
    if (type != null) {
        ForgeHooksClient.setRenderLayer(type);
        final IVertexBuilder builder = buffer.getBuffer(type);
        renderModel(dispatcher.getModelRenderer(), useAO, world, model, state, pos, matrix, builder, false, OverlayTexture.NO_OVERLAY);
        ForgeHooksClient.setRenderLayer(null);
    }
}
Also used : IBakedModel(net.minecraft.client.renderer.model.IBakedModel) RenderType(net.minecraft.client.renderer.RenderType) BlockRendererDispatcher(net.minecraft.client.renderer.BlockRendererDispatcher) IVertexBuilder(com.mojang.blaze3d.vertex.IVertexBuilder)

Example 13 with BlockRendererDispatcher

use of net.minecraft.client.renderer.BlockRendererDispatcher in project ImmersiveEngineering by BluSunrize.

the class AttainedDropsHelper method init.

@Override
public void init() {
    seed = ForgeRegistries.ITEMS.getValue(new ResourceLocation(AD_MODID, "seed"));
    plant = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(AD_MODID, "plant"));
    bulb = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(AD_MODID, "bulb"));
    soil = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(AD_MODID, "soil"));
    soilItem = Item.getItemFromBlock(soil);
    addTypes();
    BelljarHandler.registerHandler(new IPlantHandler() {

        @Override
        public boolean isCorrectSoil(ItemStack seed, ItemStack soil) {
            return soil.getItem() == AttainedDropsHelper.this.soilItem && soil.getMetadata() > 0 && soil.getMetadata() <= 15;
        }

        @Override
        public float getGrowthStep(ItemStack seed, ItemStack soil, float growth, TileEntity tile, float fertilizer, boolean render) {
            return (growth < .5 ? .003125f : .0015625f) * fertilizer;
        }

        @Override
        public float resetGrowth(ItemStack seed, ItemStack soil, float growth, TileEntity tile, boolean render) {
            return .5f;
        }

        @Override
        public ItemStack[] getOutput(ItemStack seed, ItemStack soil, TileEntity tile) {
            ItemStack[] out = outputMap.get(soil.getMetadata());
            if (out == null)
                return new ItemStack[0];
            return out;
        }

        @Override
        public boolean isValid(ItemStack seed) {
            return seed.getItem() == AttainedDropsHelper.this.seed;
        }

        @Override
        @SideOnly(Side.CLIENT)
        public IBlockState[] getRenderedPlant(ItemStack seed, ItemStack soil, float growth, TileEntity tile) {
            return new IBlockState[0];
        }

        @Override
        @SideOnly(Side.CLIENT)
        public float getRenderSize(ItemStack seed, ItemStack soil, float growth, TileEntity tile) {
            return .875f;
        }

        @Override
        @SideOnly(Side.CLIENT)
        public boolean overrideRender(ItemStack seed, ItemStack soil, float growth, TileEntity tile, BlockRendererDispatcher blockRenderer) {
            IBlockState state = plant.getDefaultState().withProperty(BlockCrops.AGE, growth >= .5 ? 7 : Math.min(7, Math.round(7 * growth * 2)));
            IBakedModel model = blockRenderer.getModelForState(state);
            GlStateManager.pushMatrix();
            GlStateManager.translate(0, 0, 1);
            blockRenderer.getBlockModelRenderer().renderModelBrightness(model, state, 1, true);
            GlStateManager.popMatrix();
            if (growth >= .5) {
                state = bulbMap.get(soil.getMetadata());
                model = blockRenderer.getModelForState(state);
                if (model == null)
                    return false;
                GlStateManager.pushMatrix();
                GlStateManager.translate(0, 0, 1);
                float scale = (growth - .5f) * 2f;
                GlStateManager.translate(.5 - scale / 2, 1, -.5 + scale / 2);
                GlStateManager.scale(scale, scale, scale);
                blockRenderer.getBlockModelRenderer().renderModelBrightness(model, state, 1, true);
                GlStateManager.popMatrix();
            }
            return true;
        }
    });
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IBlockState(net.minecraft.block.state.IBlockState) ResourceLocation(net.minecraft.util.ResourceLocation) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) IPlantHandler(blusunrize.immersiveengineering.api.tool.BelljarHandler.IPlantHandler) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) ItemStack(net.minecraft.item.ItemStack) BlockRendererDispatcher(net.minecraft.client.renderer.BlockRendererDispatcher)

Example 14 with BlockRendererDispatcher

use of net.minecraft.client.renderer.BlockRendererDispatcher in project ImmersiveEngineering by BluSunrize.

the class EntityRenderIEExplosive method doRender.

@Override
public void doRender(EntityIEExplosive entity, double x, double y, double z, float entityYaw, float partialTicks) {
    if (entity.block == null)
        return;
    BlockRendererDispatcher blockrendererdispatcher = Minecraft.getMinecraft().getBlockRendererDispatcher();
    GlStateManager.pushMatrix();
    GlStateManager.translate((float) x, (float) y + 0.5F, (float) z);
    if (entity.getFuse() - partialTicks + 1 < 10) {
        float f = 1.0F - ((float) entity.getFuse() - partialTicks + 1.0F) / 10.0F;
        f = MathHelper.clamp(f, 0.0F, 1.0F);
        f = f * f;
        f = f * f;
        float f1 = 1.0F + f * 0.3F;
        GlStateManager.scale(f1, f1, f1);
    }
    float f2 = (1 - (entity.getFuse() - partialTicks + 1) / 100F) * .8F;
    this.bindEntityTexture(entity);
    GlStateManager.translate(-0.5F, -0.5F, 0.5F);
    blockrendererdispatcher.renderBlockBrightness(entity.block, entity.getBrightness());
    GlStateManager.translate(0.0F, 0.0F, 1.0F);
    if (entity.getFuse() / 5 % 2 == 0) {
        GlStateManager.disableTexture2D();
        GlStateManager.disableLighting();
        GlStateManager.enableBlend();
        GlStateManager.blendFunc(770, 772);
        GlStateManager.color(1.0F, 1.0F, 1.0F, f2);
        GlStateManager.doPolygonOffset(-3.0F, -3.0F);
        GlStateManager.enablePolygonOffset();
        blockrendererdispatcher.renderBlockBrightness(entity.block, 1.0F);
        GlStateManager.doPolygonOffset(0.0F, 0.0F);
        GlStateManager.disablePolygonOffset();
        GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
        GlStateManager.disableBlend();
        GlStateManager.enableLighting();
        GlStateManager.enableTexture2D();
    }
    GlStateManager.popMatrix();
    super.doRender(entity, x, y, z, entityYaw, partialTicks);
}
Also used : BlockRendererDispatcher(net.minecraft.client.renderer.BlockRendererDispatcher)

Example 15 with BlockRendererDispatcher

use of net.minecraft.client.renderer.BlockRendererDispatcher in project ICBM-Classic by BuiltBrokenModding.

the class RenderFragments method doRender.

@Override
public void doRender(EntityFragments entity, double x, double y, double z, float entityYaw, float partialTicks) {
    this.bindEntityTexture(entity);
    if (entity.isAnvil) {
        final IBlockState blockState = Blocks.ANVIL.getDefaultState().withProperty(BlockAnvil.DAMAGE, entity.world.rand.nextInt(2)).withProperty(BlockAnvil.FACING, EnumFacing.Plane.HORIZONTAL.facings()[entity.world.rand.nextInt(3)]);
        // TODO store rotation and damage in entity to reduce random nature
        final BlockRendererDispatcher blockrendererdispatcher = Minecraft.getMinecraft().getBlockRendererDispatcher();
        GlStateManager.pushMatrix();
        GlStateManager.translate((float) x, (float) y + 0.5F, (float) z);
        this.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
        GlStateManager.rotate(-90.0F, 0.0F, 1.0F, 0.0F);
        GlStateManager.translate(-0.5F, -0.5F, 0.5F);
        blockrendererdispatcher.renderBlockBrightness(blockState, entity.getBrightness());
        GlStateManager.translate(0.0F, 0.0F, 1.0F);
        GlStateManager.popMatrix();
    } else {
        GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
        GlStateManager.pushMatrix();
        GlStateManager.disableLighting();
        GlStateManager.translate((float) x, (float) y, (float) z);
        GlStateManager.rotate(entity.prevRotationYaw + (entity.rotationYaw - entity.prevRotationYaw) * partialTicks - 90.0F, 0.0F, 1.0F, 0.0F);
        GlStateManager.rotate(entity.prevRotationPitch + (entity.rotationPitch - entity.prevRotationPitch) * partialTicks, 0.0F, 0.0F, 1.0F);
        Tessellator tessellator = Tessellator.getInstance();
        BufferBuilder bufferbuilder = tessellator.getBuffer();
        GlStateManager.enableRescaleNormal();
        float f9 = (float) entity.arrowShake - partialTicks;
        if (f9 > 0.0F) {
            float f10 = -MathHelper.sin(f9 * 3.0F) * f9;
            GlStateManager.rotate(f10, 0.0F, 0.0F, 1.0F);
        }
        GlStateManager.rotate(45.0F, 1.0F, 0.0F, 0.0F);
        GlStateManager.scale(0.05625F, 0.05625F, 0.05625F);
        GlStateManager.translate(-4.0F, 0.0F, 0.0F);
        GlStateManager.glNormal3f(0.05625F, 0.0F, 0.0F);
        bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX);
        bufferbuilder.pos(-7.0D, -2.0D, -2.0D).tex(0.0D, 0.15625D).endVertex();
        bufferbuilder.pos(-7.0D, -2.0D, 2.0D).tex(0.15625D, 0.15625D).endVertex();
        bufferbuilder.pos(-7.0D, 2.0D, 2.0D).tex(0.15625D, 0.3125D).endVertex();
        bufferbuilder.pos(-7.0D, 2.0D, -2.0D).tex(0.0D, 0.3125D).endVertex();
        tessellator.draw();
        GlStateManager.glNormal3f(-0.05625F, 0.0F, 0.0F);
        bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX);
        bufferbuilder.pos(-7.0D, 2.0D, -2.0D).tex(0.0D, 0.15625D).endVertex();
        bufferbuilder.pos(-7.0D, 2.0D, 2.0D).tex(0.15625D, 0.15625D).endVertex();
        bufferbuilder.pos(-7.0D, -2.0D, 2.0D).tex(0.15625D, 0.3125D).endVertex();
        bufferbuilder.pos(-7.0D, -2.0D, -2.0D).tex(0.0D, 0.3125D).endVertex();
        tessellator.draw();
        for (int j = 0; j < 4; ++j) {
            GlStateManager.rotate(90.0F, 1.0F, 0.0F, 0.0F);
            GlStateManager.glNormal3f(0.0F, 0.0F, 0.05625F);
            bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX);
            bufferbuilder.pos(-8.0D, -2.0D, 0.0D).tex(0.0D, 0.0D).endVertex();
            bufferbuilder.pos(8.0D, -2.0D, 0.0D).tex(0.5D, 0.0D).endVertex();
            bufferbuilder.pos(8.0D, 2.0D, 0.0D).tex(0.5D, 0.15625D).endVertex();
            bufferbuilder.pos(-8.0D, 2.0D, 0.0D).tex(0.0D, 0.15625D).endVertex();
            tessellator.draw();
        }
        GlStateManager.disableRescaleNormal();
        GlStateManager.enableLighting();
        GlStateManager.popMatrix();
    }
    super.doRender(entity, x, y, z, entityYaw, partialTicks);
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) Tessellator(net.minecraft.client.renderer.Tessellator) BufferBuilder(net.minecraft.client.renderer.BufferBuilder) BlockRendererDispatcher(net.minecraft.client.renderer.BlockRendererDispatcher)

Aggregations

BlockRendererDispatcher (net.minecraft.client.renderer.BlockRendererDispatcher)44 IBlockState (net.minecraft.block.state.IBlockState)20 IBakedModel (net.minecraft.client.renderer.block.model.IBakedModel)15 BufferBuilder (net.minecraft.client.renderer.BufferBuilder)13 BlockPos (net.minecraft.util.math.BlockPos)13 Tessellator (net.minecraft.client.renderer.Tessellator)12 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)5 World (net.minecraft.world.World)5 Block (net.minecraft.block.Block)4 BlockModelShapes (net.minecraft.client.renderer.BlockModelShapes)4 VertexBuffer (net.minecraft.client.renderer.VertexBuffer)3 IBakedModel (net.minecraft.client.renderer.model.IBakedModel)3 TileEntity (net.minecraft.tileentity.TileEntity)3 EnumFacing (net.minecraft.util.EnumFacing)3 IBlockAccess (net.minecraft.world.IBlockAccess)3 IVertexBuilder (com.mojang.blaze3d.vertex.IVertexBuilder)2 Nullable (javax.annotation.Nullable)2 BlockChest (net.minecraft.block.BlockChest)2 BlockEnderChest (net.minecraft.block.BlockEnderChest)2 BlockSign (net.minecraft.block.BlockSign)2