Posted June 4, 20223 yr 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 June 4, 20223 yr by Sweetmimike Add info
June 5, 20223 yr 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();
June 5, 20223 yr 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.