Jump to content

Rendering an Item


Jimmeh

Recommended Posts

Hi there. I'm wanting to create 'slots' that exist on the player's back and hip so that they may equip a weapon in either. So if I equip an item on my back slot, it should then render in game on my back. I'm trying to think about how to do this. I see there's an

Minecraft.getInstance().getItemRenderer()

with multiple different render() methods, most of which I think are GUI related. I do see it has this:

render(ItemStack pItemStack, ItemCameraTransforms.TransformType pTransformType, boolean pLeftHand, MatrixStack pMatrixStack, IRenderTypeBuffer pBuffer, int pCombinedLight, int pCombinedOverlay, IBakedModel pModel)

which might be want I should use. Although, I'm unsure how to get/create an IRenderTypeBuffer.

 

I found this outdated mod that did exactly what I'm looking to do, where he has the item being represented by a BipedModel. Is this the same approach that should be taken in 1.16.5? I'm not sure if it's possible, but I'd like to avoid the rendered items as being entities (I'm not sure if that even makes sense, to be honest), ideally for performance (in my head, if I had 100 players in an area, there'd be 200 entities by default since each could have a rendered weapon on their back or hip. If this is the only solution, I could make a culling system of sorts). Here's what I'm wanting to essentially accomplish:

wNMIT.png

 

Thanks for any input! 

 

Edit:

I've found the HeldItemLayer class which, I believe, renders held items. I'm thinking I can create my own LayerRenderer that's essentially mimicking this but at a different place on the player.

Edited by Jimmeh
Link to comment
Share on other sites

10 minutes ago, diesieben07 said:

This is the route I would suggest as well.

Question with this. If I make a WornItemLayer extends LayerRenderer, I implement the following render method:

@Override
    public void render(MatrixStack pMatrixStack,
                       IRenderTypeBuffer pBuffer,
                       int pPackedLight,
                       Entity pLivingEntity,
                       float pLimbSwing,
                       float pLimbSwingAmount,
                       float pPartialTicks,
                       float pAgeInTicks,
                       float pNetHeadYaw,
                       float pHeadPitch) {
        if(this.equipped == null) return;

        //Get the player's facing direction
        //Reverse that to know the direction the location offset will be for positioning
        //Rotate the item 135 degrees

        final float rotation = this.minecraft.player.yBodyRot;
    }

I don't think this will work for multiplayer, as in, it won't render other players' equipped items on my screen, since I'm getting the local player from Minecraft. Can you think of a way so that this may be applied to all players? Perhaps some sort of loop through viewable players each render() call?

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

    • A friend found this code, but I don't know where. It seems to be very outdated, maybe from 1.12? and so uses TextureManager$loadTexture and TextureManager$deleteTexture which both don't seem to exist anymore. It also uses Minecraft.getMinecraft().mcDataDir.getCanonicalPath() which I replaced with the resource location of my texture .getPath()? Not sure if thats entirely correct. String textureName = "entitytest.png"; File textureFile = null; try { textureFile = new File(Minecraft.getMinecraft().mcDataDir.getCanonicalPath(), textureName); } catch (Exception ex) { } if (textureFile != null && textureFile.exists()) { ResourceLocation MODEL_TEXTURE = Resources.OTHER_TESTMODEL_CUSTOM; TextureManager texturemanager = Minecraft.getMinecraft().getTextureManager(); texturemanager.deleteTexture(MODEL_TEXTURE); Object object = new ThreadDownloadImageData(textureFile, null, MODEL_TEXTURE, new ImageBufferDownload()); texturemanager.loadTexture(MODEL_TEXTURE, (ITextureObject)object); return true; } else { return false; }   Then I've been trying to go through the source code of the reload resource packs from minecraft, to see if I can "cache" some data and simply reload some textures and swap them out, but I can't seem to figure out where exactly its "loading" the texture files and such. Minecraft$reloadResourcePacks(bool) seems to be mainly controlling the loading screen, and using this.resourcePackRepository.reload(); which is PackRepository$reload(), but that function seems to be using this absolute confusion of a line List<String> list = this.selected.stream().map(Pack::getId).collect(ImmutableList.toImmutableList()); and then this.discoverAvailable() and this.rebuildSelected. The rebuild selected seemed promising, but it seems to just be going through each pack and doing this to them? pack.getDefaultPosition().insert(list, pack, Functions.identity(), false); e.g. putting them into a list of packs and returning that into this.selected? Where do the textures actually get baked/loaded/whatever? Any info on how Minecraft reloads resource packs or how the texture manager works would be appreciated!
    • This might be a long shot , but do you remember how you fixed that?
    • Yeah, I'll start with the ones I added last night.  Wasn't crashing until today and wasn't crashing at all yesterday (+past few days since removing Cupboard), so deductive reasoning says it's likeliest to be one of the new ones.  A few horse armor mods and a corn-based add-on to Farmer's Delight, the latter which I hope to keep - I could do without the horse armor mods if necessary.  Let me try a few things and we'll see. 
    • Add crash-reports with sites like https://mclo.gs/ Add this mod: https://www.curseforge.com/minecraft/mc-mods/packet-fixer/files/5416165
  • Topics

×
×
  • Create New...

Important Information

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