Jump to content

[1.12.2] Correct event for setting EntityPlayerSP.activeHand


Fusseel

Recommended Posts

I'm trying to manually set EntityPlayerSP.activeHand using EntityPlayerSP.setActiveHand(). Which would be the correct Forge event to do this through? I can't solve this via getItemUseAction() or something similar since I want to implement a new right click action for an existing vanilla item and not a new one from my mod.

I already tried LivingEvent.LivingUpdateEvent, but that one didn't seem to work for my purpose. So which event would be correct?

Edited by Fusseel
Link to comment
Share on other sites

51 minutes ago, Fusseel said:

I'm trying to manually set EntityPlayerSP.activeHand using EntityPlayerSP.setActiveHand(). Which would be the correct Forge event to do this through? I can't solve this via getItemUseAction() or something similar since I want to implement a new right click action for an existing vanilla item and not a new one from my mod.

I already tried LivingEvent.LivingUpdateEvent, but that one didn't seem to work for my purpose. So which event would be correct?

Just use one of PlayerInteractEvent sub events to add a new rightClick for an item.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

Thanks a lot guys for the very quick responses as usual!

Turns out I actually had it working before using LivingEvent.LivingUpdateEvent, but I just didn't notice since the effect I was looking for didn't occur. Isn't setActiveHand supposed to eventually slow down the player by a lot and disable sprinting? That's what I'm going for and what I thought would be happening, but it's not.

My current implementation looks this:

@SubscribeEvent
public void rightClickItem(PlayerInteractEvent.RightClickItem event) {
    if (event.getItemStack().getItem() instanceof ItemSword) {
        this.mc.player.setActiveHand(EnumHand.MAIN_HAND);
    }
}

From my understanding due to isHandActive being true now (and it really is, I checked) this code in EntityPlayerSP (line 992-) would be executed now:

if (this.isHandActive() && !this.isRiding())
{
    this.movementInput.moveStrafe *= 0.2F;
    this.movementInput.moveForward *= 0.2F;
    this.sprintToggleTimer = 0;
}

So either it isn't or it's not slowing the player down like I thought it would...

Any idea what's wrong?

Edited by Fusseel
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.