User Tools

Site Tools


tutorial:damagetypes

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
tutorial:damagetypes [2023/09/03 08:29] – Add notice of non-intermediary names hiisuuiitutorial:damagetypes [2023/09/24 18:53] (current) – Use new minecraft wiki mattidragon
Line 1: Line 1:
-FIXME This page contains non-Intermediary named references to classes and fields. The wiki's map2fabricyarn plugin must be updated to current mappings before these references can be renamed to Intermediary. 
 ====== Adding a Damage Type (1.19.4+) ====== ====== Adding a Damage Type (1.19.4+) ======
  
Line 9: Line 8:
 ==== Creating a Damage Type ==== ==== Creating a Damage Type ====
  
-First, create a json file for your custom damage type following the format [[https://minecraft.fandom.com/wiki/Damage_type|here]]. It should be placed in your mod's ''data'' folder in a new subfolder called ''damage_type''. For example:+First, create a json file for your custom damage type following the format [[https://minecraft.wiki/w/Damage_type|here]]. It should be placed in your mod's ''data'' folder in a new subfolder called ''damage_type''. For example:
 <code json data/tutorial/damage_type/custom_damage_type.json [enable_line_numbers="true"]> <code json data/tutorial/damage_type/custom_damage_type.json [enable_line_numbers="true"]>
 { {
Line 18: Line 17:
 </code> </code>
  
-Our new custom damage type will now cause 0.1 [[https://minecraft.fandom.com/wiki/Hunger#Exhaustion_level_increase|hunger exhaustion]] each time a player takes damage of this type, and the if the damage is caused by a living, non-player source (like being hit by a Zombie), the amount of damage dealt will scale with the world's difficulty. You can see all possible keys and values on the [[https://minecraft.fandom.com/wiki/Damage_type|respective Minecraft wiki page]].+Our new custom damage type will now cause 0.1 [[https://minecraft.wiki/w/Hunger#Exhaustion_level_increase|hunger exhaustion]] each time a player takes damage of this type, and the if the damage is caused by a living, non-player source (like being hit by a Zombie), the amount of damage dealt will scale with the world's difficulty. You can see all possible keys and values on the [[https://minecraft.wiki/w/Damage_type|respective Minecraft wiki page]].
  
 ==== Getting our damage type in code ==== ==== Getting our damage type in code ====
Line 27: Line 26:
  
     /*      /* 
-     * Store the class_5321 of our DamageType into a new constant called CUSTOM_DAMAGE_TYPE+     * Store the class_5321 of our class_8110 into a new constant called CUSTOM_DAMAGE_TYPE
      * The class_2960 in use here points to our JSON file we created earlier.      * The class_2960 in use here points to our JSON file we created earlier.
     */     */
-    public static final class_5321<DamageType> CUSTOM_DAMAGE_TYPE = class_5321.method_29179(class_7924.DAMAGE_TYPE, new class_2960("tutorial", "custom_damage_type"));+    public static final class_5321<class_8110> CUSTOM_DAMAGE_TYPE = class_5321.method_29179(class_7924.field_42534, new class_2960("tutorial", "custom_damage_type"));
  
-    public static class_1282 of(class_1937 world, class_5321<DamageType> key) { +    public static class_1282 of(class_1937 world, class_5321<class_8110> key) { 
-        return new class_1282(world.method_30349().method_30530(class_7924.DAMAGE_TYPE).method_40290(key));+        return new class_1282(world.method_30349().method_30530(class_7924.field_42534).method_40290(key));
     }     }
 } }
 </yarncode> </yarncode>
  
-Our static method ''of'' allows us to get the ''<yarn class_1282>'' we need to actually use our custom damage type in code, as any methods that deal damage will typically take a ''<yarn class_1282>'' and not a ''DamageType''+Our static method ''of'' allows us to get the ''<yarn class_1282>'' we need to actually use our custom damage type in code, as any methods that deal damage will typically take a ''<yarn class_1282>'' and not a ''<yarn class_8110>''
  
 ==== Using our damage type ==== ==== Using our damage type ====
Line 57: Line 56:
 } }
 </yarncode> </yarncode>
-You'll notice that ''<yarn class_1297>#<yarn method_5643>'' takes a ''<yarn class_1282>'' and not a ''DamageType'' as its first argument. This is why we use our helper method ''of'', to get a useable ''<yarn class_1282>'' of our custom damage type!+You'll notice that ''<yarn class_1297>#<yarn method_5643>'' takes a ''<yarn class_1282>'' and not a ''<yarn class_8110>'' as its first argument. This is why we use our helper method ''of'', to get a useable ''<yarn class_1282>'' of our custom damage type!
  
 Now whenever a ``<yarn class_1309>`` steps on our custom block, they'll take 1 damage (half a heart) using our custom damage type! However, if you notice, when you die from our custom damage type, the death message will simply be "death.attack.custom"! That's no good. We need to provide a translation for when something dies of our custom damage type! Add an entry to your language file: Now whenever a ``<yarn class_1309>`` steps on our custom block, they'll take 1 damage (half a heart) using our custom damage type! However, if you notice, when you die from our custom damage type, the death message will simply be "death.attack.custom"! That's no good. We need to provide a translation for when something dies of our custom damage type! Add an entry to your language file:
Line 89: Line 88:
 | avoids_guardian_thorns | Does not trigger the Thorns effect when attacking Guardians | | | avoids_guardian_thorns | Does not trigger the Thorns effect when attacking Guardians | |
 | burns_armor_stands | Deals a flat 4.0 damage to armor stands | | | burns_armor_stands | Deals a flat 4.0 damage to armor stands | |
-| bypasses_armor | Ignores all armor protection value | |+| bypasses_armor | Ignores all armor base protection value. Does not ignore Protection enchantments. | |
 | bypasses_effects | Bypasses both Resistance effect and Protection enchantments, but not armor. | | | bypasses_effects | Bypasses both Resistance effect and Protection enchantments, but not armor. | |
-| bypasses_enchantments | Ignores all types of Protection enchantments | |+| bypasses_enchantments | Ignores all types of Protection enchantments, but not base armor protection. | |
 | bypasses_invulnerability | Damages players who are invulnerable, such as in Creative or Spectator mode | | | bypasses_invulnerability | Damages players who are invulnerable, such as in Creative or Spectator mode | |
 | bypasses_resistance | Bypasses Resistance effect |  | | bypasses_resistance | Bypasses Resistance effect |  |
tutorial/damagetypes.1693729792.txt.gz · Last modified: 2023/09/03 08:29 by hiisuuii