Jump to content

(1.16.5 MCP) detect LEFT click in items


ElTotisPro50

Recommended Posts

7 hours ago, diesieben07 said:

Events are added by Forge, Mojang has nothing to do with them.

You are looking for PlayerInteractEvent.LeftClickEmpty.

diesieben why im trying to shoot a fireball with left click event but is not working

("is not working" i mean that the fireball DOESNT appear/add to the world/spawn)

@SubscribeEvent
    public static void leftClickItemEvent(PlayerInteractEvent.LeftClickEmpty event)
    {
        PlayerEntity player = event.getPlayer();
        World world = player.world;
        ItemStack stack = player.getHeldItemMainhand();
        if(stack.getItem() instanceof MYITEM) { //or if(stack.getItem() == ModItems.MYITEM.get()) none of those works
            FireballEntity fireball = new FireballEntity(EntityType.FIREBALL,world);
            Vector3d aim = player.getLookVec();
            fireball.setPositionAndUpdate(player.getPosX() + aim.x * 1.7,
                    player.getPosY() + aim.y * 1.7,
                    player.getPosZ() + aim.z * 1.7);
            fireball.accelerationX = aim.x * 0.6;
            fireball.accelerationY = aim.y * 0.6;
            fireball.accelerationZ = aim.z * 0.6;
            world.addEntity(fireball);
        }
    }

 

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