Skip to content

Commit

Permalink
Damage type datagen fix
Browse files Browse the repository at this point in the history
Add data generation for damage types
  • Loading branch information
BrokenK3yboard committed Jun 20, 2024
1 parent 99c660e commit c295d15
Show file tree
Hide file tree
Showing 24 changed files with 140 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,19 @@

import net.fabricmc.fabric.api.datagen.v1.DataGeneratorEntrypoint;
import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator;
import net.minecraft.core.RegistrySetBuilder;
import net.minecraft.core.registries.Registries;
import net.minecraft.data.PackOutput;

import net.minecraft.data.worldgen.BootstapContext;
import net.minecraft.world.damagesource.DamageEffects;
import net.minecraft.world.damagesource.DamageScaling;
import net.minecraft.world.damagesource.DamageType;
import vazkii.botania.data.*;
import vazkii.botania.data.recipes.*;

import static vazkii.botania.common.BotaniaDamageTypes.*;

public class FabricDatagenInitializer implements DataGeneratorEntrypoint {
@Override
public void onInitializeDataGenerator(FabricDataGenerator generator) {
Expand All @@ -40,7 +48,8 @@ private static void configureXplatDatagen(FabricDataGenerator.Pack pack) {
pack.addProvider(EntityTagProvider::new);
pack.addProvider(BannerPatternTagsProvider::new);
pack.addProvider(BiomeTagProvider::new);
// pack.addProvider(DamageTypeTagProvider::new);
pack.addProvider(FabricDynamicProvider::new);
pack.addProvider(DamageTypeTagProvider::new);
pack.addProvider((PackOutput output) -> new StonecuttingProvider(output));
pack.addProvider((PackOutput output) -> new CraftingRecipeProvider(output));
pack.addProvider((PackOutput output) -> new SmeltingProvider(output));
Expand All @@ -58,4 +67,15 @@ private static void configureXplatDatagen(FabricDataGenerator.Pack pack) {
pack.addProvider((PackOutput output) -> new PottedPlantModelProvider(output));
pack.addProvider(AdvancementProvider::create);
}

@Override
public void buildRegistry(RegistrySetBuilder builder) {
builder.add(Registries.DAMAGE_TYPE, FabricDatagenInitializer::damageTypeBC);
}

protected static void damageTypeBC(BootstapContext<DamageType> context) {
context.register(RELIC_DAMAGE, new DamageType("botania-relic", DamageScaling.NEVER, 1F, DamageEffects.FREEZING));
context.register(PLAYER_ATTACK_ARMOR_PIERCING, new DamageType("player", DamageScaling.WHEN_CAUSED_BY_LIVING_NON_PLAYER, 0.1F));
context.register(KEY_EXPLOSION, new DamageType("botania.key_explosion", DamageScaling.ALWAYS, 0.1F));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package vazkii.botania.fabric.data;

import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput;
import net.fabricmc.fabric.api.datagen.v1.provider.FabricDynamicRegistryProvider;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.registries.Registries;
import net.minecraft.tags.DamageTypeTags;
import net.minecraft.world.damagesource.DamageEffects;
import net.minecraft.world.damagesource.DamageScaling;
import net.minecraft.world.damagesource.DamageType;
import net.minecraft.world.damagesource.DamageTypes;

import java.util.concurrent.CompletableFuture;

import static vazkii.botania.common.BotaniaDamageTypes.*;

public class FabricDynamicProvider extends FabricDynamicRegistryProvider {

public FabricDynamicProvider(FabricDataOutput output, CompletableFuture<HolderLookup.Provider> registriesFuture) {
super(output, registriesFuture);
}

@Override
protected void configure(HolderLookup.Provider registries, Entries entries) {
entries.add(RELIC_DAMAGE, new DamageType("botania-relic", DamageScaling.NEVER, 1F, DamageEffects.FREEZING));
entries.add(PLAYER_ATTACK_ARMOR_PIERCING, new DamageType("player", DamageScaling.WHEN_CAUSED_BY_LIVING_NON_PLAYER, 0.1F));
entries.add(KEY_EXPLOSION, new DamageType("botania.key_explosion", DamageScaling.ALWAYS, 0.1F));
}

@Override
public String getName() {
return "damageTypes";
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import java.util.concurrent.CompletableFuture;

// Unused currently. Crashes on tag gen because it can't find botania's damage types, as they're not registered yet.
public class DamageTypeTagProvider extends TagsProvider<DamageType> {

public DamageTypeTagProvider(PackOutput packOutput, CompletableFuture<HolderLookup.Provider> lookupProvider) {
Expand All @@ -24,14 +23,18 @@ public DamageTypeTagProvider(PackOutput packOutput, CompletableFuture<HolderLook

@Override
protected void addTags(@NotNull HolderLookup.Provider provider) {
this.tag(DamageTypeTags.IS_FIRE);
this.tag(BotaniaTags.DamageTypes.RING_OF_ODIN_IMMUNE)
.add(DamageTypes.DROWN)
.add(DamageTypes.FALL)
.add(DamageTypes.IN_WALL)
.add(DamageTypes.STARVE)
.add(DamageTypes.FLY_INTO_WALL)
.addTag(DamageTypeTags.IS_FIRE);
.addOptionalTag(DamageTypeTags.IS_FIRE.location());

/*
Optional tag workaround for error:
java.lang.IllegalArgumentException: Couldn't define tag botania:ring_of_odin_immune as it is missing following references: #minecraft:is_fire
*/

this.tag(DamageTypeTags.BYPASSES_ARMOR)
.add(BotaniaDamageTypes.PLAYER_ATTACK_ARMOR_PIERCING)
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit c295d15

Please sign in to comment.