Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[1.18.2] Render an entity at a certain position

Featured Replies

Posted

Hey !

I'm trying to render an entity (for example a cow) just above a custom block entity. Of course, the renderer is correctly registered.

final EntityRenderDispatcher entityDispatcher = Minecraft.getInstance().getEntityRenderDispatcher();
final BlockRenderDispatcher dispatcher = this.context.getBlockRenderDispatcher();
//        pPoseStack.pushPose();
//        pPoseStack.translate(0.5f, 0.5f, 0.5f);
//        dispatcher.renderSingleBlock(Blocks.GLASS.defaultBlockState(), pPoseStack, pBufferSource, pPackedLight, pPackedOverlay,
//                EmptyModelData.INSTANCE);

//        pPoseStack.popPose();

Entity entityToSpawn = EntityType.COW.create(pBlockEntity.getLevel());
//        LOGGER.debug("ENTITY TO SPAWN " + entityToSpawn.getName());
//        pPoseStack.pushPose();
pPoseStack.translate(0.5f, 2f, 0.5f);
pPoseStack.scale(2f, 2f, 2f);
entityDispatcher.render(entityToSpawn, pBlockEntity.getBlockPos().getX(), pBlockEntity.getBlockPos().getY(), pBlockEntity.getBlockPos().getZ(),
                0.0f, pPartialTick, pPoseStack, pBufferSource, pPackedLight);
pPoseStack.popPose();

Is there something I do not correctly ?

Edited by Sweetmimike
Add info

  • Author

I finally solved the problem !

If anyone is interested on how render an entity, you can find the code I used just below

final EntityRenderDispatcher entityDispatcher = Minecraft.getInstance().getEntityRenderDispatcher();
Entity entityToSpawn = entityType.create(pBlockEntity.getLevel());

float scale = 0.3f;
pPoseStack.pushPose();
pPoseStack.translate(0.5f, 1f, 0.5f);
pPoseStack.scale(scale, scale, scale);

entityDispatcher.render(entityToSpawn, 0.0D, 0.0D, 0.0D, 0.0F, 1.0F, pPoseStack, pBufferSource, 15728880);
pPoseStack.popPose();

 

  • Author
22 minutes ago, diesieben07 said:

Do not create a new entity instance every time.

Right.

I modified the code just as follows

	final EntityRenderDispatcher entityDispatcher = Minecraft.getInstance().getEntityRenderDispatcher();
        Entity entityToSpawn = pBlockEntity.getEntityToDisplay();
        if(entityToSpawn == null || entityToSpawn.getType() != entityType) {
            LOGGER.debug("NEED TO CREATE A NEW ENTITY");
            entityToSpawn = entityType.create(pBlockEntity.getLevel());
            pBlockEntity.setEntityToDisplay(entityToSpawn);
        }

        float scale = 0.3f;
        pPoseStack.pushPose();
        pPoseStack.translate(0.5f, 1f, 0.5f);
        pPoseStack.scale(scale, scale, scale);

        entityDispatcher.render(entityToSpawn, 0.0D, 0.0D, 0.0D, 0.0F, 1.0F, pPoseStack, pBufferSource, 15728880);
        pPoseStack.popPose();

So the entity I want to display is stored in a block entity

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.