From 02e1615c7269715309f35cbbfc0cf80739c7e0ee Mon Sep 17 00:00:00 2001 From: Walker Fowlkes Date: Fri, 14 Jun 2024 16:21:20 -0700 Subject: [PATCH 1/3] possibly fix overcast dammage --- .../at/petrak/hexcasting/common/lib/HexDamageTypes.java | 2 +- .../data/minecraft/tags/damage_type/bypasses_armor.json | 7 +++++++ .../data/minecraft/tags/damage_type/bypasses_effects.json | 7 +++++++ .../minecraft/tags/damage_type/bypasses_enchantments.json | 7 +++++++ .../tags/damage_type/bypasses_invulnerability.json | 6 ++++++ .../data/minecraft/tags/damage_type/bypasses_shield.json | 7 +++++++ 6 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 Common/src/main/resources/data/minecraft/tags/damage_type/bypasses_armor.json create mode 100644 Common/src/main/resources/data/minecraft/tags/damage_type/bypasses_effects.json create mode 100644 Common/src/main/resources/data/minecraft/tags/damage_type/bypasses_enchantments.json create mode 100644 Common/src/main/resources/data/minecraft/tags/damage_type/bypasses_invulnerability.json create mode 100644 Common/src/main/resources/data/minecraft/tags/damage_type/bypasses_shield.json 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 e7ca5402c2..3c4424e729 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 @@ -8,5 +8,5 @@ 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("overcast")); + public static final ResourceKey SHAME_ON_YOU = ResourceKey.create(Registries.DAMAGE_TYPE, modLoc("shame")); } diff --git a/Common/src/main/resources/data/minecraft/tags/damage_type/bypasses_armor.json b/Common/src/main/resources/data/minecraft/tags/damage_type/bypasses_armor.json new file mode 100644 index 0000000000..2cd64d9380 --- /dev/null +++ b/Common/src/main/resources/data/minecraft/tags/damage_type/bypasses_armor.json @@ -0,0 +1,7 @@ +{ + "replace": false, + "values": [ + "hexcasting:overcast", + "hexcasting:shame" + ] +} \ No newline at end of file diff --git a/Common/src/main/resources/data/minecraft/tags/damage_type/bypasses_effects.json b/Common/src/main/resources/data/minecraft/tags/damage_type/bypasses_effects.json new file mode 100644 index 0000000000..2cd64d9380 --- /dev/null +++ b/Common/src/main/resources/data/minecraft/tags/damage_type/bypasses_effects.json @@ -0,0 +1,7 @@ +{ + "replace": false, + "values": [ + "hexcasting:overcast", + "hexcasting:shame" + ] +} \ No newline at end of file diff --git a/Common/src/main/resources/data/minecraft/tags/damage_type/bypasses_enchantments.json b/Common/src/main/resources/data/minecraft/tags/damage_type/bypasses_enchantments.json new file mode 100644 index 0000000000..2cd64d9380 --- /dev/null +++ b/Common/src/main/resources/data/minecraft/tags/damage_type/bypasses_enchantments.json @@ -0,0 +1,7 @@ +{ + "replace": false, + "values": [ + "hexcasting:overcast", + "hexcasting:shame" + ] +} \ No newline at end of file diff --git a/Common/src/main/resources/data/minecraft/tags/damage_type/bypasses_invulnerability.json b/Common/src/main/resources/data/minecraft/tags/damage_type/bypasses_invulnerability.json new file mode 100644 index 0000000000..a6ee0fa545 --- /dev/null +++ b/Common/src/main/resources/data/minecraft/tags/damage_type/bypasses_invulnerability.json @@ -0,0 +1,6 @@ +{ + "replace": false, + "values": [ + "hexcasting:shame" + ] +} \ No newline at end of file diff --git a/Common/src/main/resources/data/minecraft/tags/damage_type/bypasses_shield.json b/Common/src/main/resources/data/minecraft/tags/damage_type/bypasses_shield.json new file mode 100644 index 0000000000..2cd64d9380 --- /dev/null +++ b/Common/src/main/resources/data/minecraft/tags/damage_type/bypasses_shield.json @@ -0,0 +1,7 @@ +{ + "replace": false, + "values": [ + "hexcasting:overcast", + "hexcasting:shame" + ] +} \ No newline at end of file From b837297a2dba9bb014eb8e8f97991a293578fe7c Mon Sep 17 00:00:00 2001 From: Walker Fowlkes Date: Fri, 14 Jun 2024 18:46:07 -0700 Subject: [PATCH 2/3] remove redundant file --- .../minecraft/tags/damage_type/bypasses_enchantments.json | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 Common/src/main/resources/data/minecraft/tags/damage_type/bypasses_enchantments.json diff --git a/Common/src/main/resources/data/minecraft/tags/damage_type/bypasses_enchantments.json b/Common/src/main/resources/data/minecraft/tags/damage_type/bypasses_enchantments.json deleted file mode 100644 index 2cd64d9380..0000000000 --- a/Common/src/main/resources/data/minecraft/tags/damage_type/bypasses_enchantments.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "replace": false, - "values": [ - "hexcasting:overcast", - "hexcasting:shame" - ] -} \ No newline at end of file From 9be479b1d75641ddda9bd477feec60fe74578071 Mon Sep 17 00:00:00 2001 From: object-Object Date: Sun, 23 Jun 2024 15:55:51 -0400 Subject: [PATCH 3/3] Implement datagen for damage type definitions and tags --- .../data/hexcasting/damage_type/overcast.json | 2 +- .../data/hexcasting/damage_type/shame.json | 2 +- .../tags/damage_type/bypasses_armor.json | 1 - .../tags/damage_type/bypasses_effects.json | 1 - .../damage_type/bypasses_invulnerability.json | 1 - .../tags/damage_type/bypasses_shield.json | 1 - .../hexcasting/common/lib/HexDamageTypes.java | 16 +++++++ .../datagen/tag/HexDamageTypeTagProvider.java | 42 +++++++++++++++++++ .../forge/datagen/ForgeHexDataGenerators.java | 22 +++++++++- 9 files changed, 81 insertions(+), 7 deletions(-) rename Common/src/{main => generated}/resources/data/hexcasting/damage_type/overcast.json (81%) rename Common/src/{main => generated}/resources/data/hexcasting/damage_type/shame.json (80%) rename Common/src/{main => generated}/resources/data/minecraft/tags/damage_type/bypasses_armor.json (78%) rename Common/src/{main => generated}/resources/data/minecraft/tags/damage_type/bypasses_effects.json (78%) rename Common/src/{main => generated}/resources/data/minecraft/tags/damage_type/bypasses_invulnerability.json (68%) rename Common/src/{main => generated}/resources/data/minecraft/tags/damage_type/bypasses_shield.json (78%) create mode 100644 Common/src/main/java/at/petrak/hexcasting/datagen/tag/HexDamageTypeTagProvider.java 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);