Jump to content

[1.19.3] Trouble with rendering and translating model parts of the player


DrNickenstein

Recommended Posts

Hello, after I finally figured out how to actually render and translate a model part, it's behaving in a way I do not understand: the video explains it better, but it looks like the arm is going down and then it's not getting rendered anymore, which is very confusing. I also couldn't find any github repositories or other topics that could be helpful for this.

 

This is my RenderArmEvent handler/hook: https://gist.github.com/DrNickenstein/b6c9e6178729111bab9d20382059d53b

 

Video of arm behaviour: https://imgur.com/a/41Hy0G4

 

Link to comment
Share on other sites

17 hours ago, DrNickenstein said:

Hello, after I finally figured out how to actually render and translate a model part, it's behaving in a way I do not understand: the video explains it better, but it looks like the arm is going down and then it's not getting rendered anymore, which is very confusing. I also couldn't find any github repositories or other topics that could be helpful for this.

The event determines how the arm is rendered. You are rendering the arm at an offset, and the offset is applied when you swing your arm on top of the offset already for that animation. As such, it works exactly as you wrote it.

Link to comment
Share on other sites

2 hours ago, ChampionAsh5357 said:

The event determines how the arm is rendered. You are rendering the arm at an offset, and the offset is applied when you swing your arm on top of the offset already for that animation. As such, it works exactly as you wrote it.

I don't think I understand: in the clip I'm not swinging my arm at all and it should not be moving at all, I thought translating the poseStack would just translate my arm not animate it?

 

Edit:

To be clear: my question is, why on earth is the arm moving and then disappearing?

Edited by DrNickenstein
Clarification
Link to comment
Share on other sites

4 minutes ago, ChampionAsh5357 said:

An animation is playing when you swing the item on attack or use.

It's going back to where it was originally rendered.

Ok this would make sense if I was either using the item, attacking or swinging my arm. In this case, I'm not, so why is the arm moving? And if that determines an animation, where should I put the code to move the arm so that it doesn't move?

Link to comment
Share on other sites

22 minutes ago, DrNickenstein said:

Ok this would make sense if I was either using the item, attacking or swinging my arm. In this case, I'm not, so why is the arm moving?

Swapping the items in the hand also plays an animation, so it's probably that.

23 minutes ago, DrNickenstein said:

And if that determines an animation, where should I put the code to move the arm so that it doesn't move?

Why not just leave the rendering alone and let it play it's animation? Also, why not just play the animation only when using the item.

Link to comment
Share on other sites

1 minute ago, ChampionAsh5357 said:

Swapping the items in the hand also plays an animation, so it's probably that.

Oh yeah in that case that could be it

2 minutes ago, ChampionAsh5357 said:

Why not just leave the rendering alone and let it play it's animation? Also, why not just play the animation only when using the item.

I need rendering because normally the left arm is not rendered in first person when holding an item, correct? I could render it only when using the item, sure, but still it's not meant to move or be animated at all, I wanted to just render it on the left side of the screen. 

Link to comment
Share on other sites

3 minutes ago, DrNickenstein said:

I wanted to just render it on the left side of the screen. 

I would look at ItemInHandRenderer to see how the hand is rendered and essentially copy the logic in RenderHandEvent, check for offhand rendering when mainhand has your item, and render the left hand. Pretty much need to copy #renderPlayerArm.

Link to comment
Share on other sites

50 minutes ago, ChampionAsh5357 said:

I would look at ItemInHandRenderer to see how the hand is rendered and essentially copy the logic in RenderHandEvent, check for offhand rendering when mainhand has your item, and render the left hand. Pretty much need to copy #renderPlayerArm.

I copied the function and edited the variables that I couldn't get (swingProgress and equippedProgress), trying to replicate what they would be from my understanding. The arm is moving differently now but it's still twitching, moving around and then disappearing. Would using an AT make sense here to change the access modifier of renderPlayerArm or not?

 

	@SubscribeEvent
	public void renderInjectedArm(RenderArmEvent event) {

		AbstractClientPlayer player = event.getPlayer();
		MultiBufferSource source = event.getMultiBufferSource();
		PoseStack poseStack = new PoseStack();
		int combinedLight = event.getPackedLight();

		Minecraft minecraft = Minecraft.getInstance();
		Item mainHandItem = player.getMainHandItem().getItem();
		ItemStack offHandItem = player.getOffhandItem();
		PlayerRenderer renderer = (PlayerRenderer)minecraft.getEntityRenderDispatcher().getRenderer(player);

		if(event.getArm() == HumanoidArm.RIGHT && mainHandItem instanceof EndiriumMetalSyringe && offHandItem.isEmpty()) {

			float partialTicks = minecraft.getPartialTick();
			float equippedProgress = partialTicks - Mth.lerp(partialTicks, 1, 1);
			float f = -1.0F;
			float f1 = Mth.sqrt(partialTicks);
			float f2 = -0.3F * Mth.sin(f1 * (float)Math.PI);
			float f3 = 0.4F * Mth.sin(f1 * ((float)Math.PI * 2F));
			float f4 = -0.4F * Mth.sin(partialTicks * (float)Math.PI);
			poseStack.translate(f * (f2 + 0.64000005F), f3 + -0.6F + equippedProgress * -0.6F, f4 + -0.71999997F);
			poseStack.mulPose(Axis.YP.rotationDegrees(f * 45.0F));
			float f5 = Mth.sin(partialTicks * partialTicks * (float)Math.PI);
			float f6 = Mth.sin(f1 * (float)Math.PI);
			poseStack.mulPose(Axis.YP.rotationDegrees(f * f6 * 70.0F));
			poseStack.mulPose(Axis.ZP.rotationDegrees(f * f5 * -20.0F));
			RenderSystem.setShaderTexture(0, player.getSkinTextureLocation());
			poseStack.translate(f * -1.0F, 3.6F, 3.5F);
			poseStack.mulPose(Axis.ZP.rotationDegrees(f * 120.0F));
			poseStack.mulPose(Axis.XP.rotationDegrees(200.0F));
			poseStack.mulPose(Axis.YP.rotationDegrees(f * -135.0F));
			poseStack.translate(f * 5.6F, 0.0F, 0.0F);
			renderer.renderLeftHand(poseStack, source, combinedLight, player);
			poseStack.popPose();
			System.out.println("Left arm rendered");

		}

	}

This is my code right now in case it's needed

Link to comment
Share on other sites

20 hours ago, DrNickenstein said:
	public void renderInjectedArm(RenderArmEvent event) {

Again, use RenderHandEvent and check if you are rendering the offhand. Cancel the event if the hand has your item in the mainhand and no item in the current hand. Then, render the offhand. You are given the variables necessary to properly render it since you are currently neglecting two values.

20 hours ago, DrNickenstein said:

Would using an AT make sense here to change the access modifier of renderPlayerArm or not

You could if you wanted, makes no difference as long as the logic is correct.

Link to comment
Share on other sites

1 hour ago, ChampionAsh5357 said:

Again, use RenderHandEvent and check if you are rendering the offhand. Cancel the event if the hand has your item in the mainhand and no item in the current hand. Then, render the offhand. You are given the variables necessary to properly render it since you are currently neglecting two values.

You could if you wanted, makes no difference as long as the logic is correct.

Oh, thank you, it works now! Although I didn't really understand what I was doing wrong before, is it the fact that canceling the event nullifies all of the changes vanilla normally applies to the arm or is there something else I should understand?

Link to comment
Share on other sites

2 hours ago, DrNickenstein said:

Although I didn't really understand what I was doing wrong before, is it the fact that canceling the event nullifies all of the changes vanilla normally applies to the arm or is there something else I should understand?

There were just two rendering changes which affected where the hand was rendered that you didn't take into account.

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.

Announcements



×
×
  • Create New...

Important Information

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