Jump to content

[1.14.4] Item#doesSneakBypassUse() and PlayerInteractEvent#RightClickBlock


Recommended Posts

Posted

Now that Item#doesSneakBypassUse() is back in, I've been trying to get my item to work properly again when dual wielding. In 1.12.2 I used PlayerInteractEvent#RightClickBlock to get Block#onBlockActivated() to trigger even when sneaking and holding an item in both hands (by setting UseBlock to Allow and UseItem to Deny under the right circumstances). Without this, half the functionalty of my wrench doesn't work if the player is holding a shield for example and tries to use the wrench while sneaking.

This approach doesn't seem to work anymore, because it is now required for both items to return true in doesSneakBypassUse() when sneaking, which is never the case for vanilla items (because the default behavior of IForgeItem#doesSneakBypassUse() is to return false).

boolean flag = !p_219441_1_.getHeldItemMainhand().isEmpty() || !p_219441_1_.getHeldItemOffhand().isEmpty();
boolean flag1 = !(p_219441_1_.isSneaking() && flag) || (p_219441_1_.getHeldItemMainhand().doesSneakBypassUse(p_219441_2_,blockpos,p_219441_1_) && p_219441_1_.getHeldItemOffhand().doesSneakBypassUse(p_219441_2_,blockpos,p_219441_1_));
if (event.getUseBlock() != net.minecraftforge.eventbus.api.Event.Result.DENY && flag1 && blockstate.onBlockActivated(p_219441_2_, p_219441_1_, p_219441_4_, p_219441_5_)) {
	return ActionResultType.SUCCESS;
}

Is this broken or intended behavior ...  or am I missing something ? I mean, isn't the whole purpose of PlayerInteractEvent#RightClickBlock to override default behavior?

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.