Jump to content

[1.20.1 && 47.3.0] Custom DamageType isn't register.


Recommended Posts

 

So, I am trying to create and add tags to my custom damage type, but looks like I made something wrong, since it crashing with error that "cannot register" damage type. Im trying to register it, and in datagen add tags, but it everytime crashing due to not register "grimtales:entropy". Full code there - https://github.com/undertakerJ/Grim-Tales-Forge
ModDamageTypes class

public class ModDamageTypes {
  public static final DeferredRegister<DamageType> DAMAGE_TYPES =
      DeferredRegister.create(Registries.DAMAGE_TYPE, GrimTales.MOD_ID);
  public static final ResourceKey<DamageType> ENTROPY_KEY =
          ResourceKey.create(Registries.DAMAGE_TYPE, new ResourceLocation(GrimTales.MOD_ID, "entropy"));

  public static final RegistryObject<DamageType> ENTROPY =
          DAMAGE_TYPES.register(
                  "entropy",
                  () -> new DamageType("entropy_effect", DamageScaling.ALWAYS, 1f, DamageEffects.HURT));
//
//  public static final DamageSource ENTROPY_SOURCE = new DamageSource(Holder.direct(ENTROPY.get()));

  public static void register(IEventBus eventBus) {
    DAMAGE_TYPES.register(eventBus);
  }
}

Datagen for damageTags

public class ModDamageTagsProvider extends DamageTypeTagsProvider {
  public ModDamageTagsProvider(
      PackOutput p_270719_,
      CompletableFuture<HolderLookup.Provider> p_270256_,
      @Nullable ExistingFileHelper existingFileHelper) {
    super(p_270719_, p_270256_, GrimTales.MOD_ID, existingFileHelper);
  }
    @Override
    protected void addTags(HolderLookup.Provider pProvider) {
        this.tag(DamageTypeTags.BYPASSES_INVULNERABILITY).add(ModDamageTypes.ENTROPY_KEY);
    }
}

Datagen class it self
 

@Mod.EventBusSubscriber(modid = GrimTales.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD)
public class DataGenerators {
    @SubscribeEvent
    public static void gatherData(GatherDataEvent event){
        DataGenerator generator = event.getGenerator();
        PackOutput packOutput = generator.getPackOutput();
        ExistingFileHelper helper = event.getExistingFileHelper();
        CompletableFuture<HolderLookup.Provider> lookupProvider = event.getLookupProvider();
 
        generator.addProvider(event.includeServer(), new ModDamageTagsProvider(packOutput, lookupProvider, helper));
     
    }
}

And register class in main class

 public GrimTales()
    {
        IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();

        ModDamageTypes.register(modEventBus);

        modEventBus.addListener(this::commonSetup);

        MinecraftForge.EVENT_BUS.register(this);

        modEventBus.addListener(this::addCreative);

    }

 

Link to comment
Share on other sites

So I came to this

public class ModDamageTypes{

  public static void bootstrap(BootstapContext<DamageType> context)
  {
    context.register(GTDamageTypes.ENTROPY_KEY, new DamageType(GrimTales.MOD_ID + "_entropy", 0.1f));
  }
}
public class GTDamageTypes implements DamageTypes {
  public static final ResourceKey<DamageType> ENTROPY_KEY = register("entropy");


  private static ResourceKey<DamageType> register(String name)
  {
    return ResourceKey.create(Registries.DAMAGE_TYPE, new ResourceLocation(GrimTales.MOD_ID, name));

  }
}
public class ModWorldGenProvider extends DatapackBuiltinEntriesProvider {
    public static final RegistrySetBuilder BUILDER = new RegistrySetBuilder()
            .add(Registries.DAMAGE_TYPE, ModDamageTypes::bootstrap);
    public ModWorldGenProvider(PackOutput output, CompletableFuture<HolderLookup.Provider> registries) {
        super(output, registries, BUILDER, Set.of(GrimTales.MOD_ID));
    }

But! I still have an issue that, I cannot just use Holder.direct, due to it will create error that
"Required type:  Holder<DamageType> 
Provided : Holder<ResourceKey<DamageType>>"
And I still have no clue how to fix it

Link to comment
Share on other sites

UPD: I DID IT
 

 @Override
  public void applyEffectTick(LivingEntity livingEntity, int pAmplifier) {
    Level level = livingEntity.level();
    if (!level.isClientSide()) {
      Holder<DamageType> entropyHolder =
          level
              .registryAccess()
              .registryOrThrow(Registries.DAMAGE_TYPE)
              .getHolderOrThrow(GTDamageTypes.ENTROPY_KEY);

      livingEntity.hurt(new DamageSource(entropyHolder), 1);
    }
    super.applyEffectTick(livingEntity, pAmplifier);
  }

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.