Jump to content

RightClickItem event bugs or documentation lies?


Eiachh

Recommended Posts

So basically documentation says:
 

/**
     * This event is fired on both sides before the player triggers {@link net.minecraft.item.Item#onItemRightClick}.
     * Note that this is NOT fired if the player is targeting a block {@link RightClickBlock} or entity {@link EntityInteract} {@link EntityInteractSpecific}.
     *
     * Let result be the return value of {@link net.minecraft.item.Item#onItemRightClick}, or {@link #cancellationResult} if the event is cancelled.
     * If we are on the client and result is not {@link EnumActionResult#SUCCESS}, the client will then continue to other hands.
     */
    @Cancelable
    public static class RightClickItem extends PlayerInteractEvent


 Note that this is NOT fired if the player is targeting a block
 Note that this is NOT fired if the player is targeting a block
 Note that this is NOT fired if the player is targeting a block

Meanwhile me targetting a block guess what happens? It does triggers.

My code 
 

public class EventHandlingForPortalRodTool {
    @SubscribeEvent
    public void catchPlayerInterract(PlayerInteractEvent.RightClickBlock event) {
        if (event.getEntityPlayer().world.isRemote == false) {
            if (event.getEntityPlayer().getHeldItemMainhand().getItem() instanceof PortaRodTool) {
                if (event.getEntityPlayer().isSneaking()) {
                    PortaRodTool temp = (PortaRodTool) event.getEntityPlayer().getHeldItemMainhand().getItem();
                    temp.placePlaceholderAt(event.getEntityPlayer().world, event.getPos());
                }
            }
        }
    }

    @SubscribeEvent
    public void catchPlayerRightclick(PlayerInteractEvent.RightClickItem event) {
        if (event.getEntityPlayer().getHeldItemMainhand().getItem() instanceof PortaRodTool) {
            if (event.getEntity().isSneaking()) {
                if (event.getEntityPlayer().world.isRemote == false) {
                    PortaRodTool temp = (PortaRodTool) event.getEntityPlayer().getHeldItemMainhand().getItem();
                    System.out.println("wat");
                    temp.teleportEntity(event.getEntity());
                }
                else{
                    PortaRodTool temp = (PortaRodTool) event.getEntityPlayer().getHeldItemMainhand().getItem();
                    System.out.println("true");
                    temp.teleportEntity(event.getEntity());
                }
            }
        }
    }


How do you separate/(tell them apart) the events or did i just use them wrong?

The base idea: when shift rightclicking on a block Locking the coordinates
                         when shift rightclicking NOT on a block teleport to the locked coords
result:

                        shift rightclick on a block places a "placeholderblock" but also teleports me to the previous selected coords 
                        the goal would be not to teleport if i shift rightclick on a block only to lock the coords

If the PlayerInteractEvent.RightClickItem would contain something that "event.targettedBlock" that would be gread as well.

Link to comment
Share on other sites

It looks like the RightClickItem docs are incorrect, since the RightClickBlock docs explicitly mention that the client will try RightClickItem unless the result is SUCCESS:

    /**
     * This event is fired on both sides whenever the player right clicks while targeting a block.
     * This event controls which of {@link net.minecraft.block.Block#onBlockActivated} and/or {@link net.minecraft.item.Item#onItemUse}
     * will be called after {@link net.minecraft.item.Item#onItemUseFirst} is called.
     * Canceling the event will cause none of the above three to be called
     *
     * Let result be a return value of the above three methods, or {@link #cancellationResult} if the event is cancelled.
     * If we are on the client and result is not {@link EnumActionResult#SUCCESS}, the client will then try {@link RightClickItem}.
     *
     * There are various results to this event, see the getters below.
     * Note that handling things differently on the client vs server may cause desynchronizations!
     */

 

If you perform some action, you should set the event's cancellation result to EnumActionResult.SUCCESS and then cancel the event. This will stop the Vanilla methods from being called and the other event from being fired.

 

That said, there's no need to use events to handle the right click behaviour of your own Item; just override the appropriate methods in the Item class instead.

  • Like 1

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

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.