Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add datagen for damage types, fix missing damage type tags #686

Merged
merged 4 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"exhaustion": 0,
"exhaustion": 0.0,
"message_id": "hexcasting.overcast",
"scaling": "when_caused_by_living_non_player"
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"exhaustion": 0,
"exhaustion": 0.0,
"message_id": "hexcasting.shame",
"scaling": "when_caused_by_living_non_player"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"values": [
"hexcasting:overcast",
"hexcasting:shame"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"values": [
"hexcasting:overcast",
"hexcasting:shame"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"values": [
"hexcasting:shame"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"values": [
"hexcasting:overcast",
"hexcasting:shame"
]
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
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;

public class HexDamageTypes {
public static final ResourceKey<DamageType> OVERCAST = ResourceKey.create(Registries.DAMAGE_TYPE, modLoc("overcast"));
public static final ResourceKey<DamageType> SHAME_ON_YOU = ResourceKey.create(Registries.DAMAGE_TYPE, modLoc("overcast"));
public static final ResourceKey<DamageType> SHAME_ON_YOU = ResourceKey.create(Registries.DAMAGE_TYPE, modLoc("shame"));

public static void bootstrap(BootstapContext<DamageType> 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
));
}
}
Original file line number Diff line number Diff line change
@@ -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<HolderLookup.Provider> 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> damageType, TagKey<DamageType>... tags) {
for (var tag : tags) {
this.tag(tag).add(damageType);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
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;
import at.petrak.hexcasting.datagen.recipe.HexplatRecipes;
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;
Expand All @@ -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;
Expand Down Expand Up @@ -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");

Expand All @@ -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);
Expand Down
Loading