Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.17] Help about BlockEntityWithoutLevelRenderer


Zemelua
 Share

Recommended Posts

I'm currently working on rendering a BlockEntityWithoutLevelRenderer. The custom item model is in the shape of a book and I want to draw a page-specific icon on it. This icon, like particles, always points towards the camera and is directly above the book I look from anywhere. What should I do with poseStack to draw this?

 

public class CodexItemStackRenderer extends BlockEntityWithoutLevelRenderer {
	public CodexItemStackRenderer() {
		super(Minecraft.getInstance().getBlockEntityRenderDispatcher(), Minecraft.getInstance().getEntityModels());
	}

	@Override
	public void renderByItem(ItemStack itemStack, ItemTransforms.TransformType transformType, PoseStack poseStack, MultiBufferSource source, int light, int overlay) {
		// poseStack.pushPose();

		UMUArcanum.LOGGER.info("custom model is rendered.");

		// Camera camera = Minecraft.getInstance().gameRenderer.getMainCamera();
		// poseStack.mulPose(Vector3f.YP.rotationDegrees(180F - camera.getYRot()));
		// poseStack.mulPose(Vector3f.XP.rotationDegrees(180F - camera.getXRot()));

		VertexConsumer consumer = source.getBuffer(RenderType.translucentNoCrumbling());
		//test sprite
		TextureAtlasSprite sprite = Minecraft.getInstance().getTextureAtlas(TextureAtlas.LOCATION_BLOCKS).apply(new ResourceLocation("minecraft", "block/water_still"));
		Matrix4f matrix = poseStack.last().pose();

		consumer.vertex(matrix, 0.0F, 1.0F, 0.0F).color(255, 255, 255, 255)
				.uv(sprite.getU( 0F), sprite.getV( 0F)).uv2(light).normal(0.0F, 1.0F, 0.0F).endVertex();
		consumer.vertex(matrix, 0.0F, 1.0F, 1.0F).color(255, 255, 255, 255)
				.uv(sprite.getU(16F), sprite.getV( 0F)).uv2(light).normal(0.0F, 1.0F, 0.0F).endVertex();
		consumer.vertex(matrix, 1.0F, 1.0F, 1.0F).color(255, 255, 255, 255)
				.uv(sprite.getU(16F), sprite.getV(16F)).uv2(light).normal(0.0F, 1.0F, 0.0F).endVertex();
		consumer.vertex(matrix, 1.0F, 1.0F, 0.0F).color(255, 255, 255, 255)
				.uv(sprite.getU( 0F), sprite.getV(16F)).uv2(light).normal(0.0F, 1.0F, 0.0F).endVertex();

		// poseStack.popPose();

		// render Item model
	}
}

 

Link to comment
Share on other sites

It dosent work......

@Override
	public void renderByItem(ItemStack itemStack, ItemTransforms.TransformType transformType, PoseStack poseStack, MultiBufferSource source, int light, int overlay) {
		// poseStack.pushPose();

		UMUArcanum.LOGGER.info("custom model is rendered.");

		// Camera camera = Minecraft.getInstance().gameRenderer.getMainCamera();
		// poseStack.mulPose(Vector3f.YP.rotationDegrees(180F - camera.getYRot()));
		// poseStack.mulPose(Vector3f.XP.rotationDegrees(180F - camera.getXRot()));

		VertexConsumer consumer = source.getBuffer(RenderType.translucentNoCrumbling());
		//test sprite
		TextureAtlasSprite sprite = Minecraft.getInstance().getTextureAtlas(TextureAtlas.LOCATION_BLOCKS).apply(new ResourceLocation("minecraft", "block/water_still"));
		poseStack.mulPose(Minecraft.getInstance().getEntityRenderDispatcher().cameraOrientation());
		Matrix4f matrix = poseStack.last().pose();

		consumer.vertex(matrix, 0.0F, 1.0F, 0.0F).color(255, 255, 255, 255)
				.uv(sprite.getU( 0F), sprite.getV( 0F)).uv2(light).normal(0.0F, 1.0F, 0.0F).endVertex();
		consumer.vertex(matrix, 0.0F, 1.0F, 1.0F).color(255, 255, 255, 255)
				.uv(sprite.getU(16F), sprite.getV( 0F)).uv2(light).normal(0.0F, 1.0F, 0.0F).endVertex();
		consumer.vertex(matrix, 1.0F, 1.0F, 1.0F).color(255, 255, 255, 255)
				.uv(sprite.getU(16F), sprite.getV(16F)).uv2(light).normal(0.0F, 1.0F, 0.0F).endVertex();
		consumer.vertex(matrix, 1.0F, 1.0F, 0.0F).color(255, 255, 255, 255)
				.uv(sprite.getU( 0F), sprite.getV(16F)).uv2(light).normal(0.0F, 1.0F, 0.0F).endVertex();

		// poseStack.popPose();

		// render Item model
	}

2021-09-02_22_21_59.png.5c88ab0e57d114864783b7b768619a24.png

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

 Share



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.