Jump to content

[1.17] Help about BlockEntityWithoutLevelRenderer


Zemelua

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

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now


×
×
  • Create New...

Important Information

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