Jump to content

[1.15.2] Render Item on Block


Ryze

Recommended Posts

How would I go about rendering an item on my block, when right-clicked with the item.

 

Reading through forum posts, I've seen people suggesting using a TileEntityRenderer and also baking the Item into the block using the IModel(s) (however I cant find that in the same package in 1.15 although its on the 1.15 docs, is something else used now?)

 

Which approach is better in certain circumstances and how would I go about implementing either of them? Any advice is greatly appreciated.

Link to comment
Share on other sites

4 hours ago, Ryze said:

How would I go about rendering an item on my block, when right-clicked with the item.

It depends on your situation. Is there a finite number of possible Items? Will there be animation IE moving parts?

If there are finite possible items just make a model for each state.

If there are moving parts you have to use a TER.

If there are no moving parts, but an infinite amount of possible Items then you should have a custom IBakedModel.

 

The first is obvious how to do. The second vanilla has a Model class that it uses, you should probably use that. Take a peek at the Vanilla TileEntityRenderers. For the third option you need your own IBakedModel implementation that combines the Quads of an Item(s) with the Quads of your Block model. Then you must register it using the ModelBakeEvent by just putting it in the registry.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

I have the Item rendering on the block using a custom IBakedModel implementation, but the item seems to have a 16 x 16 invisible background that clips through the model at certain angles, any ideas?

 

The model without an item

Spoiler

TQPd0IE.png

And with

Spoiler

ZoT9Efq.png

My IBakedModel implementation

Spoiler

public class MicroscopeBakedModel implements IBakedModel {

    private IBakedModel baseModel;

    public ModelProperty<ItemStack> RENDER_ITEM = new ModelProperty<>();

    public ModelDataMap getEmptyIModelData() {
        ModelDataMap.Builder builder = new ModelDataMap.Builder();
        builder.withInitial(RENDER_ITEM, null);
        return builder.build();
    }

    public MicroscopeBakedModel(IBakedModel baseModel) {
        this.baseModel = baseModel;
    }

    @Nonnull
    @Override
    public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, @Nonnull Random rand, @Nonnull IModelData extraData) {
        IBakedModel base = this.baseModel;
        if (!extraData.hasProperty(RENDER_ITEM)) {
            return base.getQuads(state, side, rand, extraData);
        }
        ItemStack item = extraData.getData(RENDER_ITEM);
        if (item == null) {
            return base.getQuads(state, side, rand, extraData);
        }
        ItemRenderer itemRenderer = Minecraft.getInstance().getItemRenderer();
        IBakedModel itemModel = itemRenderer.getItemModelWithOverrides(item, null, null);
        Matrix4f matrix = new Matrix4f(new Quaternion(-90.0f, 0.0f, 0.0f, true));
        matrix.mul(Matrix4f.makeScale(0.4f, 0.4f, 0.4f));
        matrix.mul(Matrix4f.makeTranslate(0.7f, -2.05f, 0.45f));
        TransformationMatrix tm = new TransformationMatrix(matrix);
        QuadTransformer transformer = new QuadTransformer(tm);
        List<BakedQuad> updatedItemQuads = transformer.processMany(itemModel.getQuads(state, side, rand, extraData));
        List<BakedQuad> quads = new ArrayList<>();
        quads.addAll(base.getQuads(state, side, rand, extraData));
        quads.addAll(updatedItemQuads);
        return quads;
    }

    @Nonnull
    @Override
    public IModelData getModelData(@Nonnull ILightReader world, @Nonnull BlockPos pos, @Nonnull BlockState state, @Nonnull IModelData tileData) {
        if (state == world.getBlockState(pos)) {
            TileEntity te = world.getTileEntity(pos);
            if (te instanceof MicroscopeTileEntity) {
                if (((MicroscopeTileEntity) te).getItemStack().getItem() != Blocks.AIR.asItem()) {
                    ItemStack item = ((MicroscopeTileEntity) te).getItemStack().copy();
                    ModelDataMap map = getEmptyIModelData();
                    map.setData(RENDER_ITEM, item);
                    return map;
                }
            }
        }
        return getEmptyIModelData();
    }

    @Override
    public TextureAtlasSprite getParticleTexture(@Nonnull IModelData data) {
        return baseModel.getParticleTexture();
    }

    // IBakedModel Methods
    @Override
    public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand) {
        return null;
    }

    @Override
    public boolean isAmbientOcclusion() {
        return baseModel.isAmbientOcclusion();
    }

    @Override
    public boolean isGui3d() {
        return baseModel.isGui3d();
    }

    @Override
    public boolean func_230044_c_() {
        return baseModel.func_230044_c_();
    }

    @Override
    public boolean isBuiltInRenderer() {
        return baseModel.isBuiltInRenderer();
    }

    @Override
    public TextureAtlasSprite getParticleTexture() {
        return baseModel.getParticleTexture();
    }

    @Override
    public ItemCameraTransforms getItemCameraTransforms() {
        return baseModel.getItemCameraTransforms();
    }

    @Override
    public ItemOverrideList getOverrides() {
        return baseModel.getOverrides();
    }
}

 

 

Link to comment
Share on other sites

9 minutes ago, Ryze said:

I have the Item rendering on the block using a custom IBakedModel implementation, but the item seems to have a 16 x 16 invisible background that clips through the model at certain angles, any ideas?

Nevermind, just had to change the RenderType for the block.

Link to comment
Share on other sites

check net.minecraft.client.renderer.ItemRenderer#renderItem out

you can get it with Minecraft#getItemRenderer

and the minecraft instance just with Minecraft#getInstance

 

 I will make fun of you if you are not able to look into the (vanilla-) code.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Baba  Serege [[+27-73 590 8989]] has experience of 27 years in helping and guiding many people from all over the world. His psychic abilities may help you answer and resolve many unanswered questions. He specialize in helping women and men from all walks of life.. 1) – Bring back lost lover. even if lost for a long time. 2) – My lover is abusing alcohol, partying and cheating on me I urgently need help” 3) – Divorce or court issues. 4) – Is your love falling apart? 5) – Do you want your love to grow stronger? 6) – Is your partner losing interest in you? 7) – Do you want to catch your partner cheating on you? – We help to keep your partner faithful and loyal to you. 9) – We recover love and happiness when relationship breaks down. 10) – Making your partner loves you alone. 11) – We create loyalty and everlasting love between couples. 12) – Get a divorce settlement quickly from your ex-partner. 13) – We create everlasting love between couples. 14) – We help you look for the best suitable partner. 15) – We bring back lost lover even if lost for a long time. 16) – We strengthen bonds in all love relationship and marriages 17) – Are you an herbalist who wants to get more powers? 18) – Buy a house or car of your dream. 19) – Unfinished jobs by other doctors come to me. 20) – I help those seeking employment. 21) – Pensioners free treatment. 22) – Win business tenders and contracts. 23) – Do you need to recover your lost property? 24) – Promotion at work and better pay. 25) – Do you want to be protected from bad spirits and nightmares? 26) – Financial problems. 27) – Why you can’t keep money or lovers? 28) – Why you have a lot of enemies? 29) – Why you are fired regularly on jobs? 30) – Speed up money claim spell, delayed payments, pension and accident funds 31) – I help students pass their exams/interviews. 33) – Removal of bad luck and debts. 34) – Are struggling to sleep because of a spiritual wife or husband. 35- ) Recover stolen property
    • OLXTOTO adalah situs bandar togel online resmi terbesar dan terpercaya di Indonesia. Bergabunglah dengan OLXTOTO dan nikmati pengalaman bermain togel yang aman dan terjamin. Koleksi toto 4D dan togel toto terlengkap di OLXTOTO membuat para member memiliki pilihan taruhan yang lebih banyak. Sebagai situs togel terpercaya, OLXTOTO menjaga keamanan dan kenyamanan para membernya dengan sistem keamanan terbaik dan enkripsi data. Transaksi yang cepat, aman, dan terpercaya merupakan jaminan dari OLXTOTO. Nikmati layanan situs toto terbaik dari OLXTOTO dengan tampilan yang user-friendly dan mudah digunakan. Layanan pelanggan tersedia 24/7 untuk membantu para member. Bergabunglah dengan OLXTOTO sekarang untuk merasakan pengalaman bermain togel yang menyenangkan dan menguntungkan.
    • Baba  Serege [[+27-73 590 8989]] has experience of 27 years in helping and guiding many people from all over the world. His psychic abilities may help you answer and resolve many unanswered questions. He specialize in helping women and men from all walks of life.. 1) – Bring back lost lover. even if lost for a long time. 2) – My lover is abusing alcohol, partying and cheating on me I urgently need help” 3) – Divorce or court issues. 4) – Is your love falling apart? 5) – Do you want your love to grow stronger? 6) – Is your partner losing interest in you? 7) – Do you want to catch your partner cheating on you? – We help to keep your partner faithful and loyal to you. 9) – We recover love and happiness when relationship breaks down. 10) – Making your partner loves you alone. 11) – We create loyalty and everlasting love between couples. 12) – Get a divorce settlement quickly from your ex-partner. 13) – We create everlasting love between couples. 14) – We help you look for the best suitable partner. 15) – We bring back lost lover even if lost for a long time. 16) – We strengthen bonds in all love relationship and marriages 17) – Are you an herbalist who wants to get more powers? 18) – Buy a house or car of your dream. 19) – Unfinished jobs by other doctors come to me. 20) – I help those seeking employment. 21) – Pensioners free treatment. 22) – Win business tenders and contracts. 23) – Do you need to recover your lost property? 24) – Promotion at work and better pay. 25) – Do you want to be protected from bad spirits and nightmares? 26) – Financial problems. 27) – Why you can’t keep money or lovers? 28) – Why you have a lot of enemies? 29) – Why you are fired regularly on jobs? 30) – Speed up money claim spell, delayed payments, pension and accident funds 31) – I help students pass their exams/interviews. 33) – Removal of bad luck and debts. 34) – Are struggling to sleep because of a spiritual wife or husband. 35- ) Recover stolen property
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.