diff --git a/Common/src/main/resources/data/hexcasting/damage_type/overcast.json b/Common/src/generated/resources/data/hexcasting/damage_type/overcast.json similarity index 81% rename from Common/src/main/resources/data/hexcasting/damage_type/overcast.json rename to Common/src/generated/resources/data/hexcasting/damage_type/overcast.json index cc59d47153..012582c4b2 100644 --- a/Common/src/main/resources/data/hexcasting/damage_type/overcast.json +++ b/Common/src/generated/resources/data/hexcasting/damage_type/overcast.json @@ -1,5 +1,5 @@ { - "exhaustion": 0, + "exhaustion": 0.0, "message_id": "hexcasting.overcast", "scaling": "when_caused_by_living_non_player" } \ No newline at end of file diff --git a/Common/src/main/resources/data/hexcasting/damage_type/shame.json b/Common/src/generated/resources/data/hexcasting/damage_type/shame.json similarity index 80% rename from Common/src/main/resources/data/hexcasting/damage_type/shame.json rename to Common/src/generated/resources/data/hexcasting/damage_type/shame.json index e7cd1eda85..2a9dbc393e 100644 --- a/Common/src/main/resources/data/hexcasting/damage_type/shame.json +++ b/Common/src/generated/resources/data/hexcasting/damage_type/shame.json @@ -1,5 +1,5 @@ { - "exhaustion": 0, + "exhaustion": 0.0, "message_id": "hexcasting.shame", "scaling": "when_caused_by_living_non_player" } \ No newline at end of file diff --git a/Common/src/main/resources/data/minecraft/tags/damage_type/bypasses_armor.json b/Common/src/generated/resources/data/minecraft/tags/damage_type/bypasses_armor.json similarity index 78% rename from Common/src/main/resources/data/minecraft/tags/damage_type/bypasses_armor.json rename to Common/src/generated/resources/data/minecraft/tags/damage_type/bypasses_armor.json index 2cd64d9380..ef37abe999 100644 --- a/Common/src/main/resources/data/minecraft/tags/damage_type/bypasses_armor.json +++ b/Common/src/generated/resources/data/minecraft/tags/damage_type/bypasses_armor.json @@ -1,5 +1,4 @@ { - "replace": false, "values": [ "hexcasting:overcast", "hexcasting:shame" diff --git a/Common/src/main/resources/data/minecraft/tags/damage_type/bypasses_effects.json b/Common/src/generated/resources/data/minecraft/tags/damage_type/bypasses_effects.json similarity index 78% rename from Common/src/main/resources/data/minecraft/tags/damage_type/bypasses_effects.json rename to Common/src/generated/resources/data/minecraft/tags/damage_type/bypasses_effects.json index 2cd64d9380..ef37abe999 100644 --- a/Common/src/main/resources/data/minecraft/tags/damage_type/bypasses_effects.json +++ b/Common/src/generated/resources/data/minecraft/tags/damage_type/bypasses_effects.json @@ -1,5 +1,4 @@ { - "replace": false, "values": [ "hexcasting:overcast", "hexcasting:shame" diff --git a/Common/src/main/resources/data/minecraft/tags/damage_type/bypasses_invulnerability.json b/Common/src/generated/resources/data/minecraft/tags/damage_type/bypasses_invulnerability.json similarity index 68% rename from Common/src/main/resources/data/minecraft/tags/damage_type/bypasses_invulnerability.json rename to Common/src/generated/resources/data/minecraft/tags/damage_type/bypasses_invulnerability.json index a6ee0fa545..8d8be7f423 100644 --- a/Common/src/main/resources/data/minecraft/tags/damage_type/bypasses_invulnerability.json +++ b/Common/src/generated/resources/data/minecraft/tags/damage_type/bypasses_invulnerability.json @@ -1,5 +1,4 @@ { - "replace": false, "values": [ "hexcasting:shame" ] diff --git a/Common/src/main/resources/data/minecraft/tags/damage_type/bypasses_shield.json b/Common/src/generated/resources/data/minecraft/tags/damage_type/bypasses_shield.json similarity index 78% rename from Common/src/main/resources/data/minecraft/tags/damage_type/bypasses_shield.json rename to Common/src/generated/resources/data/minecraft/tags/damage_type/bypasses_shield.json index 2cd64d9380..ef37abe999 100644 --- a/Common/src/main/resources/data/minecraft/tags/damage_type/bypasses_shield.json +++ b/Common/src/generated/resources/data/minecraft/tags/damage_type/bypasses_shield.json @@ -1,5 +1,4 @@ { - "replace": false, "values": [ "hexcasting:overcast", "hexcasting:shame" diff --git a/Common/src/main/java/at/petrak/hexcasting/common/lib/HexDamageTypes.java b/Common/src/main/java/at/petrak/hexcasting/common/lib/HexDamageTypes.java index 3c4424e729..d9f5ad2111 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/lib/HexDamageTypes.java +++ b/Common/src/main/java/at/petrak/hexcasting/common/lib/HexDamageTypes.java @@ -1,7 +1,9 @@ package at.petrak.hexcasting.common.lib; import net.minecraft.core.registries.Registries; +import net.minecraft.data.worldgen.BootstapContext; import net.minecraft.resources.ResourceKey; +import net.minecraft.world.damagesource.DamageScaling; import net.minecraft.world.damagesource.DamageType; import static at.petrak.hexcasting.api.HexAPI.modLoc; @@ -9,4 +11,18 @@ public class HexDamageTypes { public static final ResourceKey OVERCAST = ResourceKey.create(Registries.DAMAGE_TYPE, modLoc("overcast")); public static final ResourceKey SHAME_ON_YOU = ResourceKey.create(Registries.DAMAGE_TYPE, modLoc("shame")); + + public static void bootstrap(BootstapContext ctx) { + ctx.register(OVERCAST, new DamageType( + "hexcasting.overcast", + DamageScaling.WHEN_CAUSED_BY_LIVING_NON_PLAYER, + 0f + )); + + ctx.register(SHAME_ON_YOU, new DamageType( + "hexcasting.shame", + DamageScaling.WHEN_CAUSED_BY_LIVING_NON_PLAYER, + 0f + )); + } } diff --git a/Common/src/main/java/at/petrak/hexcasting/datagen/tag/HexDamageTypeTagProvider.java b/Common/src/main/java/at/petrak/hexcasting/datagen/tag/HexDamageTypeTagProvider.java new file mode 100644 index 0000000000..82eb35e7e2 --- /dev/null +++ b/Common/src/main/java/at/petrak/hexcasting/datagen/tag/HexDamageTypeTagProvider.java @@ -0,0 +1,42 @@ +package at.petrak.hexcasting.datagen.tag; + +import at.petrak.hexcasting.common.lib.HexDamageTypes; +import net.minecraft.core.HolderLookup; +import net.minecraft.data.PackOutput; +import net.minecraft.data.tags.DamageTypeTagsProvider; +import net.minecraft.resources.ResourceKey; +import net.minecraft.tags.DamageTypeTags; +import net.minecraft.tags.TagKey; +import net.minecraft.world.damagesource.DamageType; +import org.jetbrains.annotations.NotNull; + +import java.util.concurrent.CompletableFuture; + +public class HexDamageTypeTagProvider extends DamageTypeTagsProvider { + public HexDamageTypeTagProvider(PackOutput output, CompletableFuture provider) { + super(output, provider); + } + + @Override + protected void addTags(@NotNull HolderLookup.Provider provider) { + add(HexDamageTypes.OVERCAST, + DamageTypeTags.BYPASSES_ARMOR, + DamageTypeTags.BYPASSES_EFFECTS, + DamageTypeTags.BYPASSES_SHIELD + ); + + add(HexDamageTypes.SHAME_ON_YOU, + DamageTypeTags.BYPASSES_ARMOR, + DamageTypeTags.BYPASSES_EFFECTS, + DamageTypeTags.BYPASSES_INVULNERABILITY, + DamageTypeTags.BYPASSES_SHIELD + ); + } + + @SafeVarargs + private void add(ResourceKey damageType, TagKey... tags) { + for (var tag : tags) { + this.tag(tag).add(damageType); + } + } +} diff --git a/Forge/src/main/java/at/petrak/hexcasting/forge/datagen/ForgeHexDataGenerators.java b/Forge/src/main/java/at/petrak/hexcasting/forge/datagen/ForgeHexDataGenerators.java index 1e3a9bcb6a..c5ed351ea7 100644 --- a/Forge/src/main/java/at/petrak/hexcasting/forge/datagen/ForgeHexDataGenerators.java +++ b/Forge/src/main/java/at/petrak/hexcasting/forge/datagen/ForgeHexDataGenerators.java @@ -1,6 +1,7 @@ package at.petrak.hexcasting.forge.datagen; import at.petrak.hexcasting.api.HexAPI; +import at.petrak.hexcasting.common.lib.HexDamageTypes; import at.petrak.hexcasting.datagen.HexAdvancements; import at.petrak.hexcasting.datagen.HexLootTables; import at.petrak.hexcasting.datagen.IXplatIngredients; @@ -8,12 +9,15 @@ import at.petrak.hexcasting.datagen.recipe.builders.FarmersDelightToolIngredient; import at.petrak.hexcasting.datagen.tag.HexActionTagProvider; import at.petrak.hexcasting.datagen.tag.HexBlockTagProvider; +import at.petrak.hexcasting.datagen.tag.HexDamageTypeTagProvider; import at.petrak.hexcasting.datagen.tag.HexItemTagProvider; import at.petrak.hexcasting.forge.datagen.xplat.HexBlockStatesAndModels; import at.petrak.hexcasting.forge.datagen.xplat.HexItemModels; import at.petrak.hexcasting.forge.recipe.ForgeModConditionalIngredient; import at.petrak.hexcasting.xplat.IXplatAbstractions; import com.google.gson.JsonObject; +import net.minecraft.core.RegistrySetBuilder; +import net.minecraft.core.registries.Registries; import net.minecraft.data.DataGenerator; import net.minecraft.data.advancements.AdvancementProvider; import net.minecraft.data.loot.LootTableProvider; @@ -26,6 +30,7 @@ import net.minecraft.world.level.storage.loot.parameters.LootContextParamSets; import net.minecraftforge.common.Tags; import net.minecraftforge.common.ToolActions; +import net.minecraftforge.common.data.DatapackBuiltinEntriesProvider; import net.minecraftforge.common.data.ExistingFileHelper; import net.minecraftforge.data.event.GatherDataEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; @@ -53,14 +58,28 @@ private static void configureXplatDatagen(GatherDataEvent ev) { var output = gen.getPackOutput(); var lookup = ev.getLookupProvider(); ExistingFileHelper efh = ev.getExistingFileHelper(); + + // https://docs.minecraftforge.net/en/latest/datagen/server/datapackregistries/ + // https://github.com/MinecraftForge/MinecraftForge/pull/9580 + var datapackProvider = new DatapackBuiltinEntriesProvider( + output, + lookup, + new RegistrySetBuilder() + .add(Registries.DAMAGE_TYPE, HexDamageTypes::bootstrap), + Set.of(HexAPI.MOD_ID) + ); + var datapackLookup = datapackProvider.getRegistryProvider(); + gen.addProvider(ev.includeClient(), new HexItemModels(output, efh)); gen.addProvider(ev.includeClient(), new HexBlockStatesAndModels(output, efh)); gen.addProvider(ev.includeServer(), new AdvancementProvider( output, lookup, List.of(new HexAdvancements()) )); + gen.addProvider(ev.includeServer(), datapackProvider); + gen.addProvider(ev.includeServer(), new HexDamageTypeTagProvider(output, datapackLookup)); } - @SuppressWarnings("DataFlowIssue") + @SuppressWarnings({"DataFlowIssue", "UnreachableCode"}) private static void configureForgeDatagen(GatherDataEvent ev) { HexAPI.LOGGER.info("Starting Forge-specific datagen"); @@ -73,6 +92,7 @@ private static void configureForgeDatagen(GatherDataEvent ev) { )); gen.addProvider(ev.includeServer(), new HexplatRecipes(output, INGREDIENTS, ForgeHexConditionsBuilder::new)); + // TODO: refactor? var xtags = IXplatAbstractions.INSTANCE.tags(); var blockTagProvider = new HexBlockTagProvider(output, lookup, xtags); ((TagsProviderEFHSetter) blockTagProvider).setEFH(efh);