How can i register the DamageType in Minecraft Fabric 1.20.1

65 Views Asked by At

I am developing a Minecraft Fabric mod now, but i dont konw how can i register the DamageType

The development environment is as follows:
Minecraft version: 1.20.1
Fabric Loader: 0.15.3
Fabric API: 0.91.0+1.20.1
mapping nameSpace: yarn

The current is here.

package dev.skydynamic.damage;

import net.minecraft.entity.damage.DamageType;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.util.Identifier;

public class Honkai3rdDamageSources {
    public static final RegistryKey<DamageType> SHUHDAKU_OF_URIEL_COMMON_DAMAGE =
        RegistryKey.of(RegistryKeys.DAMAGE_TYPE, new Identifier("honkai3rd", "shuhdaku_of_uriel"));

    public static final RegistryKey<DamageType> SHAMASH_UNLEASHED_DAMAGE_TYPE =
        RegistryKey.of(RegistryKeys.DAMAGE_TYPE, new Identifier("honkai3rd", "shamash_unleashed"));

    public static void initDamageSources() {
        // call this method when mod init
        // register there
    }
}

if i dont register. the game will crash when use this damageType, because
java.lang.IllegalStateException: Missing key in ResourceKey[minecraft:root / minecraft:damage_type]: ResourceKey[minecraft:damage_type / honkai3rd:shamash_unleashed]

I want to use net.minecraft.registy.Registy.register method.
But i dont know how to use it

0

There are 0 best solutions below