(SOLVED) With the triggers provided, how do I make my item NOT hurt the player on right click?

Started by Thistle on

Topic category: Help with MCreator software

Joined Mar 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
(SOLVED) With the triggers provided, how do I make my item NOT hurt the player on right click?
Tue, 02/11/2025 - 17:12 (edited)

So, I've searched far and wide for this:
 I know this is a duplicate post, I know someone is going to state that I should read the API reference and come up with my own solution,
 but that isn't helpful as it's only led me in circles. So instead; We're going to bud heads and figure this out together for everyone who stumbles on this page.
 This will be the page people link to for future duplicate posts.


 The version I'm using is 2023.2,
 my loader is for Fabric 1.19.2.

 

This generator was a pain to set up, but yes, the mod I wish to create must be on this version; and made using this generator or one similar to it (if some of you can find one, if you do find one, tell me exactly how to install it, because I feel like plugins are just kinda convoluted to set up for my version.)

 Due to this inconvenience, assume which ever solution you give me is for this version, even if it isn't: It'll give me a place to look to and do research and will be just as useful.

Alright, with all of that out of the way, my issue is as follows:


 This code damages the player, and I know why it does so, but I cannot get around this problem.
 in the iterative loop my statement compares Entity iterator to the event/target entity, which is basically the player in this case.

I understand that normally the solution is to change this out with source-entity, that way the comparison functions properly, but the item I'm making requires the trigger "Player right clicks on entity", which is under the procedure "Player right click (entity pos)" which does not offer "source entity" as a dependency, the reason being damage targeting needs the specification of which entity I'm referring to.




The desired result is: I right click with my chainsaw, I deal 7 damage to the target entity in front of me within a 4-block radius of local: (interaction distance).
 The item MUST take 10 durability damage when it attempts this, so I need access to itemstack or an alternative like shown in the picture.
 I do not need a cooldown; Minecraft has natural I-frames which limit the damage this thing can deal.

Normally, all the dependencies required to make this happen without issue are:
Itemstack,
entity,
sourceentity,
x,
y,
z,
world,

but unfortunately, there are zero triggers out there that offer all 7 of those at once.

Edited by Thistle on Tue, 02/11/2025 - 17:12
Joined Mar 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
(Solved), this was much…
Tue, 02/11/2025 - 17:11

(Solved), this was much simpler than I thought.

You can actually separate code-blocks and not link them to an item so as long as you reference it properly.
 This took be awhile to get functional, because for whatever reason it didn't work immediately, but I eventually got it to.

 Infact, you can separate multiple functions if you're out of dependencies to use that you'd otherwise need; Yes, this is messy, but I genuinely believe based on what I currently know: This is a limitation of Mcreator but it's one you'll need to work with.

I HIGHLY recommend people link this page because I see this question asked too much for comfort with people who genuinely have no clue how to answer usually replying to these forums, and for people that do, usually don't do the best at communicating it.




So, I'm going to break this down step by step, and if you're taking these code blocks without first understanding this: you WILL keep asking the question in the future.

To start off, this is the damage script, this code block is NOT connected to my item, it has its own trigger too.
 To do this, create a new procedure, then REFERENCE THE ITEM WITH AN IF STATEMENT:
If -> item in main-hand of: Source entity = Your item.
 Do not try linking this code block to an item, it will not work, there are zero triggers that items provide that give you all the dependencies required to do this all at once, keep it separate.

Notice how my item has no durability damage taken in this code block, that's because to get the dependencies for itemstack, I need to do that separately.
This part of the script is purely to deal damage and get access to source entity which unfortunately, this version does not have a trigger that does all of these things at once.
Target entity is compared to the source entity holding the item, it checks if this is NOT the target to deal damage to, then, checks to see if the target is classified as a living entity, then, deals 7 damage as type: player_attack.


Moving on, this is the full list of code blocks I use that ARE linked to my item, notice how my right click event 
is being used to damage to item, this is by design, because remember I didn't have access to item stack above. For context: This item is a chainsaw, its purpose is to chop wood but can be misused as a weapon, taking extra durability damage just like an axe would in combat:
Which is what the right click on block state is for. Then finally I have a condition where you smack someone with the chainsaw, this deals the most damage to the chainsaw and is completely useless other than it deals extra knockback, but I thought it was funny so I added it.

Before I go, this is the code block for damaging the item, I also take advantage of the Itemstack dependency to "animate" the item, this is pretty crude, and it just makes the player swing the item.
 Quick suggestion for people who add sound effects: Add a pitch randomizer, this makes it less annoying when you hear the same sound over and over, I had forgotten to do that here but I still recommend it!


I hope this helps.

Joined Mar 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Update: I'm noticing a small…
Wed, 02/12/2025 - 13:25

Update: I'm noticing a small issue with this separate function, the tool will take damage, but for whatever reason it'll repair itself right after.

 I don't know why this happens.