How to fire a projectile when left click is pressed with procedures?

Started by Spyjetray on Sun, 08/30/2020 - 18:07

Topic category: Help with modding (Java Edition)

Last seen on 14:17, 4. Dec 2020
Joined Jul 2015
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
How to fire a projectile when left click is pressed with procedures?
Sun, 08/30/2020 - 18:07

Hi,

For my mod, I want it so whenever you press left click (swing hand), it fires a projectile.

Since this is something that should always be active when the right conditions are met, I want to use a procedure but I'm unsure how to do this?

Thanks.

Last seen on 01:02, 19. Jun 2021
Joined May 2014
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
You can make this work with…
Sun, 08/30/2020 - 19:12

You can make this work with Semi-automatic weapons, but you cannot get anything to continuously fire this way- at least, not to my knowledge.

There is a trigger in items (and maybe tools) to run a procedure when the player left-clicks (swings) the item. However, of course, this only applies to that one item and cannot be applied globally to all items.

if you're willing to get your hands dirty with custom code, I'm sure there are quite a few demonstrations of something like this working. Take The Crafting Dead, for example. It's super old but it used left and right-click to fire weapons.

Last seen on 14:17, 4. Dec 2020
Joined Jul 2015
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
What I meant was if you were…
Sun, 08/30/2020 - 20:05

What I meant was if you were wearing a specific piece of armour, you would be able to left click and it would fire a projectile regardless of whether you had an item in your hand or not. Is this possible?

Last seen on 19:13, 24. May 2021
Joined Apr 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
Yes, with very simple custom…
Sun, 08/30/2020 - 20:50

Yes, with very simple custom code, using keypress events. I suggest looking it up, tutorials would have more knowledge than I.

Last seen on 01:02, 19. Jun 2021
Joined May 2014
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
I've tried using custom…
Wed, 09/02/2020 - 01:12

I've tried using custom hotkeys and binding them to leftclick, however they are always overridden by the player's default leftclick action (mining). The procedure is never triggered. 

Straight-up detecting if leftclick is being pressed might, in fact, be an option, but from my experience setting up a key listener is super annoying given MCreator's coding and file structure. You can still give it a go, I suppose. It can't hurt and I'm honestly pretty curious as well.

Last seen on 17:22, 8. Jun 2021
Joined Nov 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
use custom code snippets…
Wed, 09/02/2020 - 13:28

use custom code snippets. check for the living entity boolean field "isSwingInProgress", if true, shoot projectile.