Jump to content

[1.19.4, SOLVED] Add damage type tag to custom damage source


Recommended Posts

Posted (edited)

I have successfully created a new damage source "bullet". But now I would like to add the damage type tag "is_projectile" to it.

Even though I added the file /resources/data/thingamabobs/tags/damage_type/is_projectile.json with the appropriate JSON content, the game still does not seem to register the damage source as a projectile. So I was wondering if I needed to also register it through a bootstrap method--and call that method using an event handler:

public interface ModDamageTypes {

    ResourceKey<DamageType> BULLET = register("bullet");

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

    // bootstrap method
    static void bootstrap(BootstapContext<DamageType> bootstapContext) {
        bootstapContext.register(BULLET, new DamageType("bullet", 0.1f));
    }

}

 

@Mod.EventBusSubscriber(modid = ThingamabobsAndDoohickeys.MODID, bus = Mod.EventBusSubscriber.Bus.MOD)
public class ModDataGenerationHandler {

    private static final RegistrySetBuilder BUILDER = new RegistrySetBuilder().add(Registries.DAMAGE_TYPE, ModDamageTypes::bootstrap);

    @SubscribeEvent
    public static void gatherDataEvent(GatherDataEvent event) {
        DataGenerator dataGenerator = event.getGenerator();
        PackOutput packOutput = dataGenerator.getPackOutput();
        dataGenerator.addProvider(event.includeServer(), new DatapackBuiltinEntriesProvider(
                packOutput, event.getLookupProvider(), BUILDER, Set.of(ThingamabobsAndDoohickeys.MODID)));
    }

}

Unfortunately, the GatherDataEvent does not seem to fire. I heard that I had to run "runData", but the process fails, outputting the log below:

  Reveal hidden contents

What could I be missing? BTW, I was using this post for guidance: https://forums.minecraftforge.net/topic/122311-1194-how-to-create-custom-damagesources/

 

 

The rest of my code + JSON files:

  Reveal hidden contents

 

Edited by LeeCrafts
  • LeeCrafts changed the title to [1.19.4, SOLVED] Add damage type tag to custom damage source
Posted (edited)

Good golly gee I'm dense. I put the is_projectile.json file in the wrong path. It was supposed to be /resources/data/minecraft/tags/damage_type/is_projectile.json, not /resources/data/thingamabobs/tags/damage_type/is_projectile.json! That being said, I do NOT need the bootstrap method in ModDamageTypes.java, and ModDataGenerationHandler.java at all; "runData" does not need to be run either. I had already done the datagen manually.

Edited by LeeCrafts
  • 8 months later...
Posted

Hey! I know it has been almost a year but I have a question about this, maybe you can give me a hint...

I also added a DamageType almost exactly like you did and also added the .json file in the data folder for my mod.
However, I find no way to interface with/use my added DamageType whatsoever...

 

From what I understand, 

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

adds the desired DamageType to the DAMAGE_TYPE registry. 

 

Any class that uses RegistryObjects of this registry should now also "see" the new custom DamageType.

 

In my case, that would be the LivingEntity class. It references the Entity and finally the Level class, which uses the registry via:

this.registryAccess = pRegistryAccess;
        this.damageSources = new DamageSources(pRegistryAccess);

But sadly, my custom damage type is nowhere to be found if I try to use it as a damageSource().custom_damagetype().

 

Again, sorry to bother but I don't see how to use my added DamageType in the mod.

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.

Announcements



×
×
  • Create New...

Important Information

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