Jump to content

Questions while studying events


WeAthFolD

Recommended Posts

I saw codes like this in ItemBow's code:

 

    public void onPlayerStoppedUsing(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer, int par4)
    {
        int var6 = this.getMaxItemUseDuration(par1ItemStack) - par4;

        ArrowLooseEvent event = new ArrowLooseEvent(par3EntityPlayer, par1ItemStack, var6);
        MinecraftForge.EVENT_BUS.post(event);
        if (event.isCanceled())
        {
            return;
        }

 

    public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
    {
    	
        ArrowNockEvent event = new ArrowNockEvent(par3EntityPlayer, par1ItemStack);
        MinecraftForge.EVENT_BUS.post(event);
        if (event.isCanceled())
        {
            return event.result;
        }

 

Judging from the code, I think those two events' function is to determine whether the movement of shooting arrow is normally continuing, if not the arrow will not be shot and action is cancelled.

 

but the two events' classes are so simple that I don't really understand how the func is done.

 

Question 1 : When and where are the events "setCancel"ed, and how does Forge EventBus handle this during the player's movement?

Question 2: How do I do similar task in my Items? Do I need to just simply copy and paste the event code and do "MinecraftForge.EVENT_BUS.register()"?

Question 3: What can I do with events mainly ?

 

Thanks a lot for you time of reading this topic and answering ;D

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.