"Set damage of provided itemstack to [number]" block function issue.

Started by AwesomeSauce999 on Sat, 11/07/2020 - 20:44

Topic category: Help with modding (Java Edition)

Last seen on 00:24, 9. Oct 2021
Joined Apr 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
"Set damage of provided itemstack to [number]" block function issue.
Sat, 11/07/2020 - 20:44

So, I wanted to make a custom enchantment that increases the damage of a weapon(better than sharpness) however, when I used the "set damage of provided itemstact to [#]" block, it seemed to just decrease the durability of the item very quickly until it broke (with the enchantment applied) If this block does damage the durability of an item, how can I increase it's damage?

Last seen on 16:26, 22. Feb 2022
Joined Feb 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
The damage means taking away…
Sun, 11/22/2020 - 17:05

The damage means taking away durability, so if you set it so it increases the damage by 1, it will slowly eat away at you swords durability, causes the weapon to break.

Last seen on 00:24, 9. Oct 2021
Joined Apr 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
so how would I refer to the…
Tue, 02/16/2021 - 02:06

so how would I refer to the actual attack damage of the weapon?

Last seen on 19:17, 5. May 2021
Joined Feb 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
First of all use the "before…
Sat, 02/20/2021 - 23:10

First of all use the "before entity is hurt" global trigger in your procedure. Next, check if the item you hit with has your enchantment. Now there are two ways to go about this next. Either you can code to set the amount of damage for the attack, which will save you a lot of work! The other method is to use procedures. However you are going to find out that you will have to recreate minecrafts combat system this way, as there is no "set number dependency" block and it´s a lot more math heavy. You´ll need to use sourceentity instead of event/target entity in both cases, as we want to edit the attacker, not the receiver!

Now to code this, first of all finish your procedure, as you can not edit it without coding afterwards. At the top in between the curly brackets of "public static void executeProcedure(...)" add this:

 

LivingHurtEvent VARIABLENAME = (LivingHurtEvent) dependencies.get("event");

 

VARIABLENAME can be replaced by whatever you want it to be, but you need to use your name instead of VARIABLENAME!

This ensures we can use everything of the LivingHurtEvent, which will enable us to edit the damage of the hit. Now look for something like this:

 

if (((EnchantmentHelper.getEnchantmentLevel(SSdfsfsaaEnchantment.enchantment,
                /* @ItemStack */((sourceentity instanceof LivingEntity)
                        
                        ? ((LivingEntity) sourceentity).getHeldItemMainhand()
                
                        : ItemStack.EMPTY)) != 0)))
        {

                        Look at the picture i linked to see what could be inside this bracket!

        }

EnchantmentNBTTag should automatically be named right, so you will most likely not need to adjust anything!

If you use the standard enchantments created by MCreator this will look different!

Inside those Curly Brackets you will find everything you will find normally, if you were to open it without the code editor. If you put more if statements inside of this one you will have to find the right one to enter the following code:

 

float damage = (float) dependencies.get("amount") * 1.2f;
                    VARIABLENAME.setAmount((float)damage);

 

Instead of VARIABLENAME you now put in the name you gave it. What i did is just an example. If will link a picture at the bottom of this response. Basically you are done. A bit detailed, but if something is not understandable feel free to ask!

 

 

If you don´t want to use code, you have to keep in mind that minecraft has a damage priority. This means that minecraft will always deal the highest amount of damage dealt that tick (This is only important if you want to reduce damage. For those cases you need to use "set health of entity" instead of "deal damage to entity"). The problem with this however is that it is a lot more math heavy to use "set health", as you need to convert it in the correct way. If you want to use the "deal damage to entity" procedure block, be warned that things like knockback, sweep attacks, crits, xp drops, certain enchantments like looting, fire aspect etc. do no longer work with that item, so i do not recommend using it in this scenario! If you have questions about specific maths, ask them.

I apologize for this response to be such a mess, but it´s really late, where i live.

Anyway, the picture i promised: https://ibb.co/PNwJJMk