Rendering item on Block

Started by CBJaxxx on

Topic category: Advanced modding

Joined Mar 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Rendering item on Block

Hello, I don't know java code but I am am smart enough to use an example or copy and paste a line of code in Mcreator.

I am making Player Shops and I wanted to know what the code looks set a itemstack equal to a inventory slot of the Player Shop Block, and render the itemstack on the Player Shop Block.

would I need to copy some lines of code to the one of the classes of the Player Shop Blocks?

I would be so very grateful to anyone with any clue on how I would do this. 

Joined Oct 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
This is a small code block …
Thu, 04/27/2023 - 12:15

This is a small code block (about 10 lines) in the block render class, but it needs to be adapted to the specific case, which requires Java knowledge.

 

Here's an example of rendering an item in an entity's hand (for the block, the code is the same, but you need to get the ItemStack from the block slot and don't need to use translateToHand method):

https://github.com/ObscuriaLithium/Aquamirae/blob/1.19.2-Forge-v5.6/src/main/java/com/obscuria/aquamirae/client/renderers/CaptainCorneliaRenderer.java#L53-L63

 

ItemStack stack = <get your item>
if (!stack.isEmpty()) {
     pose.pushPose(); 
     pose.scale(1F, 1F, 1F); //Scale 
     pose.mulPose(Vector3f.XP.rotationDegrees(0.0F)); //X Rot
     pose.mulPose(Vector3f.YP.rotationDegrees(0.0F)); //Y Rot
     pose.mulPose(Vector3f.ZP.rotationDegrees(0.0F)); //Z Rot
     pose.translate(0.0D, 0.0D, 0.0D); //Position
     
     Minecraft.getInstance().gameRenderer.itemInHandRenderer.renderItem(blockEntity, stack, ItemTransforms.TransformType.FIXED, false, pose, source, i1);
     
     pose.popPose(); 
}