Jump to content

[1.16.5] Help with custom player animation


mclich

Recommended Posts

I have an item that activates while holding right-click button. I want it to show my own third-person player animation while it is active. Since vanilla animations are specified in UseAction class, which is enum, i can't create my own instance of it. What i did is subscribed to RenderPlayerEvent.Pre and changed player position values there, but it didn't work at all. Any ideas how i can implement this?
My code is below:

@EventBusSubscriber(modid=ElderNorseGods.MOD_ID, bus=EventBusSubscriber.Bus.FORGE, value=Dist.CLIENT)
public class HealingStaffItem extends Item implements IVanishable
{
	public static final String ID="healing_staff";
	
	public HealingStaffItem(Rarity rarity, int durability)
	{
		super(new Item.Properties().rarity(rarity).durability(durability).tab(ENGTabs.COMBAT));
	}

	@Override
	public int getUseDuration(ItemStack itemStack)
	{
		return 72000;
	}

	@Override
	public UseAction getUseAnimation(ItemStack itemStack)
	{
		return UseAction.BOW;
	}
  
	@Override
	public boolean isValidRepairItem(ItemStack itemStack, ItemStack repairStack)
	{
		return false;
	}

	@Override
	public ActionResult<ItemStack> use(World world, PlayerEntity player, Hand hand)
	{
		player.startUsingItem(hand);
		return ActionResult.consume(player.getItemInHand(hand));
	}
	
	@SubscribeEvent
	public static void renderArmsPoses(RenderPlayerEvent.Pre event)
	{
		if(event.getPlayer().getUseItem().getItem()==ENGItems.HEALING_STAFF.get())
		{
			PlayerModel<AbstractClientPlayerEntity> model=event.getRenderer().getModel();
			model.rightArm.xRot=model.rightArm.xRot*0.5F-(float)Math.PI;
			model.rightArm.yRot=0.0F;
			model.leftArm.xRot=model.leftArm.xRot*0.5F-(float)Math.PI;
			model.leftArm.yRot=0.0F;
		}
	}
}
Link to comment
Share on other sites

10 hours ago, LocusAzzurro said:

You're updating the model itself, which only controls how the base model looks like. The rendering itself is done by the renderer, so changes should be done at this level to actually affect the rendering result.

What method should i use in that case? I tried PlayerRenderer#render, but it throws an "net.minecraft.crash.ReportedException: Rendering entity in world". How do i fix it?

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.