Jump to content

Rendering Issues with custom item rendering


Recommended Posts

Hello, I'm doing a gun mod, I'm canceling the render hand event and making my own rendering system,

I can render the hands and everything is fine, but when I try to render the item (gun), it renders 2 times,

I have also tried to render only 1 quad and still the problem, another gun and still the problem,

another Minecraft vanilla item and still the problem.

Here is the code

 

Rendering code

	BakedModel model = ModelUtils.getModel(player.getMainHandItem().getItem());
	model = net.minecraftforge.client.ForgeHooksClient.handleCameraTransforms(mat, model, TransformType.FIRST_PERSON_RIGHT_HAND, false);
	mat.translate(-0.5D, -0.5D, -0.5D);
	VertexConsumer builder = ItemRenderer.getFoilBuffer(e.getMultiBufferSource(), Sheets.translucentItemSheet(), true,
						player.getMainHandItem().hasFoil());
		        
	//ItemRenderer
		        
	//I have tried each of these methods and they all draw it 2 times
	Minecraft.getInstance().getItemInHandRenderer().renderItem(player, player.getMainHandItem(), TransformType.FIRST_PERSON_RIGHT_HAND, false, mat, e.getMultiBufferSource(), e.getPackedLight());
	Minecraft.getInstance().getItemRenderer().renderQuadList(mat, builder, model.getQuads(null, null, null), player.getMainHandItem(), e.getPackedLight(), OverlayTexture.NO_OVERLAY);
	Minecraft.getInstance().getItemRenderer().render(player.getMainHandItem() , TransformType.FIRST_PERSON_RIGHT_HAND, false, mat, e.getMultiBufferSource(), e.getPackedLight(), OverlayTexture.NO_OVERLAY, model);
	Minecraft.getInstance().getItemRenderer().renderModelLists(model, player.getMainHandItem(), e.getPackedLight(), OverlayTexture.NO_OVERLAY, mat, builder);
				

 

ModelUtils.getModel

public static BakedModel getModel(String path) {
	return Minecraft.getInstance().getModelManager().getModel(new ModelResourceLocation(path, "inventory"));
}
	
public static BakedModel getModel(Item path) {
	return Minecraft.getInstance().getModelManager().getModel(new ModelResourceLocation(path.getRegistryName().toString(), "inventory"));
}

 

Here is an image of how it looks

b5pC6te.png

Another picture with Minecraft vanilla item

VtjbgTe.png

Link to comment
Share on other sites

public static void renderFirstPerson(RenderHandEvent e) {
	LocalPlayer player = Minecraft.getInstance().player;
	if (player != null) {
		if (player.getMainHandItem().getItem() instanceof Item) {
			e.setCanceled(true);
			AimHandler.renderPartialTicks = e.getPartialTicks();
			PoseStack mat = e.getPoseStack();
				
			handler.animMan.update();
				
			//Rendering arm
			mat.pushPose();
			int i = e.getHand() == InteractionHand.MAIN_HAND ? 1 : -1;
			BufferSource impl = MultiBufferSource.immediate(Tesselator.getInstance().getBuilder());
			RenderUtils.renderArm(mat, impl, e.getPackedLight(), 0, 1, HumanoidArm.RIGHT);
			impl.endBatch();
			mat.popPose();
				
			//Rendering gun
			mat.pushPose();
				
			//Translating gun to item position
			mat.translate((double) ((float) i * 0.56F), (double) (-0.52F + e.getEquipProgress() * -0.6F),
						(double) -0.72F);
				
			//Doing recoil transformations
			float rec = handler.getRecHandler().getRecoil(e.getItemStack());
			//mat.translate(0, 0, Math.sin(Math.PI*rec*0.01f));
				
			//Debug aim
			//mat.translate(x, y, z);
			//mat.mulPose(new Quaternion(rx, ry, rz, false));
			if(!handler.animMan.model.getTransforms().isEmpty()) {
				mat.translate(
						handler.model.getTransform("gun").data[0],
						handler.model.getTransform("gun").data[1],
						handler.model.getTransform("gun").data[2]);
				mat.mulPose(new Quaternion(
						handler.model.getTransform("gun").data[3],
						handler.model.getTransform("gun").data[4],
						handler.model.getTransform("gun").data[5], false));
			}
				
			mat.translate(0, 0, Mth.lerp(rec, 0, 0.05f));
			mat.mulPose(Vector3f.XP.rotation(Mth.lerp(rec, 0, 0.01f)));
			mat.mulPose(Vector3f.YP.rotation(Mth.lerp(rec, 0, Mth.randomBetween(new Random(), -0.008f, 0.008f))));
			mat.mulPose(Vector3f.ZP.rotation(Mth.lerp(rec, 0, Mth.randomBetween(new Random(), -0.008f, 0.008f))));
				
			mat.translate(Mth.lerp(handler.getAimHandler().getProgress(), 0, -0.231f), Mth.lerp(handler.getAimHandler().getProgress(), 0, 0.13f), 0);
				
			float sway = 0.3f;
			MouseTracker.tick();
			mat.mulPose(Quaternion.fromXYZDegrees(new Vector3f(MouseTracker.dy*sway, MouseTracker.dx*sway, 0)));
				
			BakedModel model = ModelUtils.getModel(player.getMainHandItem().getItem());
			model = net.minecraftforge.client.ForgeHooksClient.handleCameraTransforms(mat, model, TransformType.FIRST_PERSON_RIGHT_HAND, false);
		        mat.translate(-0.5D, -0.5D, -0.5D);
		        VertexConsumer builder = ItemRenderer.getFoilBuffer(e.getMultiBufferSource(), Sheets.translucentItemSheet(), true,
					player.getMainHandItem().hasFoil());
		        
		        //ItemRenderer
		        
		        //I have tried each of these methods and they all draw it 2 times
		        //Minecraft.getInstance().getItemInHandRenderer().renderItem(player, player.getMainHandItem(), 
				//TransformType.FIRST_PERSON_RIGHT_HAND, false, mat, e.getMultiBufferSource(), e.getPackedLight());
		        Minecraft.getInstance().getItemRenderer().renderQuadList(mat, builder, model.getQuads(null, null, null), 
				player.getMainHandItem(), e.getPackedLight(), OverlayTexture.NO_OVERLAY);
		        //Minecraft.getInstance().getItemRenderer().render(player.getMainHandItem() , 
				//TransformType.FIRST_PERSON_RIGHT_HAND, false, mat, 				
				//e.getMultiBufferSource(), e.getPackedLight(), 
				//OverlayTexture.NO_OVERLAY, model);
		        //Minecraft.getInstance().getItemRenderer().renderModelLists(model, player.getMainHandItem(), e.getPackedLight(),
				//OverlayTexture.NO_OVERLAY, mat, builder);
				
		        mat.popPose();
			}
		}
	}

 

Edited by Juggernogking
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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.



×
×
  • Create New...

Important Information

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