mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-20 20:22:28 +00:00
Forge 1.19.3
Created a CreativeModeTabEvent to register creative mode tabs and populate entries per tab Moved datapack registries to DataPackRegistryEvent.NewRegistry event instead of tying them to ForgeRegistry Made it easier for mods to datagen datapack builtin entries with DatapackBuiltinEntriesProvider Provided access to lookupProvider for datagen Updated dependencies to match versions used by vanilla and update JarJar to 0.3.18 Added a test mod for the new CreativeModeTabEvent Throws better error message for Forge registries in tag datagen Deleted ForgeRegistryTagsProvider Updated ClientChatReceivedEvent and ServerChatEvent for Mojang changes Added patches for both sign related methods in ModelLayers Changed RegisterShadersEvent to use ResourceProvider Migrated old Mojang math types to JOML Co-authored-by: Marc Hermans <[email protected]> Co-authored-by: LexManos <[email protected]> Co-authored-by: sciwhiz12 <[email protected]> Co-authored-by: coehlrich <[email protected]>
This commit is contained in:
1 parent
617ecb7ad3
commit
8255d7aed3
726 files changed
+7615
-6653
No files matched your search
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.common.data;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import net.minecraft.core.HolderLookup;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.data.PackOutput;
|
||||
import net.minecraft.data.tags.IntrinsicHolderTagsProvider;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public abstract class BlockTagsProvider extends IntrinsicHolderTagsProvider<Block>
|
||||
{
|
||||
@SuppressWarnings("deprecation")
|
||||
public BlockTagsProvider(PackOutput output, CompletableFuture<HolderLookup.Provider> lookupProvider, String modId, @Nullable ExistingFileHelper existingFileHelper)
|
||||
{
|
||||
super(output, Registries.BLOCK, lookupProvider, block -> block.builtInRegistryHolder().key(), modId, existingFileHelper);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package net.minecraftforge.common.data;
|
||||
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.core.HolderLookup;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.core.RegistrySetBuilder;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.data.PackOutput;
|
||||
import net.minecraft.data.registries.RegistriesDatapackGenerator;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class DatapackBuiltinEntriesProvider extends RegistriesDatapackGenerator
|
||||
{
|
||||
public DatapackBuiltinEntriesProvider(PackOutput output, Supplier<HolderLookup.Provider> registriesSupplier)
|
||||
{
|
||||
super(output, CompletableFuture.supplyAsync(registriesSupplier, Util.backgroundExecutor()));
|
||||
}
|
||||
|
||||
public DatapackBuiltinEntriesProvider(PackOutput output, RegistrySetBuilder datapackEntriesBuilder)
|
||||
{
|
||||
this(output, () -> createLookup(datapackEntriesBuilder));
|
||||
}
|
||||
|
||||
public static HolderLookup.Provider createLookup(RegistrySetBuilder datapackEntriesBuilder) {
|
||||
return datapackEntriesBuilder.build(RegistryAccess.fromRegistryOfRegistries(BuiltInRegistries.REGISTRY));
|
||||
}
|
||||
}
|
||||
@@ -18,12 +18,10 @@ import com.google.common.collect.HashMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
|
||||
import net.minecraft.client.resources.ClientPackSource;
|
||||
import net.minecraft.client.resources.AssetIndex;
|
||||
import net.minecraft.client.resources.DefaultClientPackResources;
|
||||
import net.minecraft.client.resources.IndexedAssetSource;
|
||||
import net.minecraft.data.DataProvider;
|
||||
import net.minecraft.data.HashCache;
|
||||
import net.minecraft.server.packs.FilePackResources;
|
||||
import net.minecraft.server.packs.FolderPackResources;
|
||||
import net.minecraft.server.packs.PathPackResources;
|
||||
import net.minecraft.server.packs.repository.ServerPacksSource;
|
||||
import net.minecraft.server.packs.resources.MultiPackResourceManager;
|
||||
import net.minecraft.server.packs.resources.Resource;
|
||||
@@ -98,15 +96,14 @@ public class ExistingFileHelper {
|
||||
List<PackResources> candidateClientResources = new ArrayList<>();
|
||||
List<PackResources> candidateServerResources = new ArrayList<>();
|
||||
|
||||
candidateClientResources.add(new VanillaPackResources(ClientPackSource.BUILT_IN, "minecraft", "realms"));
|
||||
if (assetIndex != null && assetsDir != null)
|
||||
if (assetIndex != null && assetsDir != null && assetsDir.exists())
|
||||
{
|
||||
candidateClientResources.add(new DefaultClientPackResources(ClientPackSource.BUILT_IN, new AssetIndex(assetsDir, assetIndex)));
|
||||
candidateClientResources.add(ClientPackSource.createVanillaPackSource(IndexedAssetSource.createIndexFs(assetsDir.toPath(), assetIndex)));
|
||||
}
|
||||
candidateServerResources.add(new VanillaPackResources(ServerPacksSource.BUILT_IN_METADATA, "minecraft"));
|
||||
candidateServerResources.add(ServerPacksSource.createVanillaPackSource());
|
||||
for (Path existing : existingPacks) {
|
||||
File file = existing.toFile();
|
||||
PackResources pack = file.isDirectory() ? new FolderPackResources(file) : new FilePackResources(file);
|
||||
PackResources pack = file.isDirectory() ? new PathPackResources(file.getName(), file.toPath(), false) : new FilePackResources(file.getName(), file, false);
|
||||
candidateClientResources.add(pack);
|
||||
candidateServerResources.add(pack);
|
||||
}
|
||||
|
||||
@@ -5,7 +5,8 @@
|
||||
|
||||
package net.minecraftforge.common.data;
|
||||
|
||||
import net.minecraft.data.DataGenerator;
|
||||
import net.minecraft.core.HolderLookup;
|
||||
import net.minecraft.data.PackOutput;
|
||||
import net.minecraft.data.tags.BiomeTagsProvider;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.tags.BiomeTags;
|
||||
@@ -14,16 +15,18 @@ import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.biome.Biomes;
|
||||
import net.minecraftforge.common.Tags;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public final class ForgeBiomeTagsProvider extends BiomeTagsProvider
|
||||
{
|
||||
|
||||
public ForgeBiomeTagsProvider(DataGenerator arg, ExistingFileHelper existingFileHelper)
|
||||
public ForgeBiomeTagsProvider(PackOutput output, CompletableFuture<HolderLookup.Provider> lookupProvider, ExistingFileHelper existingFileHelper)
|
||||
{
|
||||
super(arg, "forge", existingFileHelper);
|
||||
super(output, lookupProvider, "forge", existingFileHelper);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addTags()
|
||||
protected void addTags(HolderLookup.Provider lookupProvider)
|
||||
{
|
||||
tag(Biomes.PLAINS, Tags.Biomes.IS_PLAINS);
|
||||
tag(Biomes.DESERT, Tags.Biomes.IS_HOT_OVERWORLD, Tags.Biomes.IS_DRY_OVERWORLD, Tags.Biomes.IS_SANDY, Tags.Biomes.IS_DESERT);
|
||||
|
||||
@@ -5,8 +5,10 @@
|
||||
|
||||
package net.minecraftforge.common.data;
|
||||
|
||||
import net.minecraft.data.DataGenerator;
|
||||
import net.minecraft.data.tags.BlockTagsProvider;
|
||||
import net.minecraft.core.HolderLookup;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.data.PackOutput;
|
||||
import net.minecraft.data.tags.IntrinsicHolderTagsProvider;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.BlockTags;
|
||||
import net.minecraft.tags.TagKey;
|
||||
@@ -15,22 +17,24 @@ import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraftforge.common.Tags;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static net.minecraftforge.common.Tags.Blocks.*;
|
||||
|
||||
public final class ForgeBlockTagsProvider extends BlockTagsProvider
|
||||
{
|
||||
public ForgeBlockTagsProvider(DataGenerator gen, ExistingFileHelper existingFileHelper)
|
||||
public ForgeBlockTagsProvider(PackOutput output, CompletableFuture<HolderLookup.Provider> lookupProvider, @Nullable ExistingFileHelper existingFileHelper)
|
||||
{
|
||||
super(gen, "forge", existingFileHelper);
|
||||
super(output, lookupProvider, "forge", existingFileHelper);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void addTags()
|
||||
public void addTags(HolderLookup.Provider p_256380_)
|
||||
{
|
||||
tag(BARRELS).addTag(BARRELS_WOODEN);
|
||||
tag(BARRELS_WOODEN).add(Blocks.BARREL);
|
||||
|
||||
@@ -5,21 +5,24 @@
|
||||
|
||||
package net.minecraftforge.common.data;
|
||||
|
||||
import net.minecraft.data.DataGenerator;
|
||||
import net.minecraft.core.HolderLookup;
|
||||
import net.minecraft.data.PackOutput;
|
||||
import net.minecraft.data.tags.EntityTypeTagsProvider;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraftforge.common.Tags;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class ForgeEntityTypeTagsProvider extends EntityTypeTagsProvider
|
||||
{
|
||||
|
||||
public ForgeEntityTypeTagsProvider(DataGenerator generator, ExistingFileHelper existingFileHelper)
|
||||
|
||||
public ForgeEntityTypeTagsProvider(PackOutput output, CompletableFuture<HolderLookup.Provider> lookupProvider, ExistingFileHelper existingFileHelper)
|
||||
{
|
||||
super(generator, "forge", existingFileHelper);
|
||||
super(output, lookupProvider, "forge", existingFileHelper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addTags()
|
||||
public void addTags(HolderLookup.Provider lookupProvider)
|
||||
{
|
||||
tag(Tags.EntityTypes.BOSSES).add(EntityType.ENDER_DRAGON, EntityType.WITHER);
|
||||
}
|
||||
|
||||
@@ -5,21 +5,24 @@
|
||||
|
||||
package net.minecraftforge.common.data;
|
||||
|
||||
import net.minecraft.data.DataGenerator;
|
||||
import net.minecraft.core.HolderLookup;
|
||||
import net.minecraft.data.PackOutput;
|
||||
import net.minecraft.data.tags.FluidTagsProvider;
|
||||
import net.minecraftforge.common.ForgeMod;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import static net.minecraftforge.common.Tags.Fluids.MILK;
|
||||
|
||||
public final class ForgeFluidTagsProvider extends FluidTagsProvider
|
||||
{
|
||||
public ForgeFluidTagsProvider(DataGenerator gen, ExistingFileHelper existingFileHelper)
|
||||
public ForgeFluidTagsProvider(PackOutput output, CompletableFuture<HolderLookup.Provider> lookupProvider, ExistingFileHelper existingFileHelper)
|
||||
{
|
||||
super(gen, "forge", existingFileHelper);
|
||||
super(output, lookupProvider, "forge", existingFileHelper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addTags()
|
||||
public void addTags(HolderLookup.Provider lookupProvider)
|
||||
{
|
||||
tag(MILK).addOptional(ForgeMod.MILK.getId()).addOptional(ForgeMod.FLOWING_MILK.getId());
|
||||
}
|
||||
|
||||
@@ -5,9 +5,10 @@
|
||||
|
||||
package net.minecraftforge.common.data;
|
||||
|
||||
import net.minecraft.data.DataGenerator;
|
||||
import net.minecraft.data.tags.BlockTagsProvider;
|
||||
import net.minecraft.core.HolderLookup;
|
||||
import net.minecraft.data.PackOutput;
|
||||
import net.minecraft.data.tags.ItemTagsProvider;
|
||||
import net.minecraft.data.tags.TagsProvider;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.world.item.DyeColor;
|
||||
@@ -18,18 +19,19 @@ import net.minecraftforge.common.Tags;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public final class ForgeItemTagsProvider extends ItemTagsProvider
|
||||
{
|
||||
public ForgeItemTagsProvider(DataGenerator gen, BlockTagsProvider blockTagProvider, ExistingFileHelper existingFileHelper)
|
||||
public ForgeItemTagsProvider(PackOutput output, CompletableFuture<HolderLookup.Provider> lookupProvider, TagsProvider<Block> blockTagProvider, ExistingFileHelper existingFileHelper)
|
||||
{
|
||||
super(gen, blockTagProvider, "forge", existingFileHelper);
|
||||
super(output, lookupProvider, blockTagProvider, "forge", existingFileHelper);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void addTags()
|
||||
public void addTags(HolderLookup.Provider lookupProvider)
|
||||
{
|
||||
copy(Tags.Blocks.BARRELS, Tags.Items.BARRELS);
|
||||
copy(Tags.Blocks.BARRELS_WOODEN, Tags.Items.BARRELS_WOODEN);
|
||||
|
||||
@@ -5,10 +5,11 @@
|
||||
|
||||
package net.minecraftforge.common.data;
|
||||
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import net.minecraft.advancements.critereon.ItemPredicate;
|
||||
import net.minecraft.data.DataGenerator;
|
||||
import net.minecraft.data.PackOutput;
|
||||
import net.minecraft.data.loot.LootTableProvider;
|
||||
import net.minecraft.data.loot.LootTableSubProvider;
|
||||
import net.minecraft.data.loot.packs.VanillaLootTableProvider;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
@@ -24,9 +25,6 @@ import net.minecraftforge.fml.util.ObfuscationReflectionHelper;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import net.minecraft.world.level.storage.loot.LootPool;
|
||||
@@ -34,32 +32,30 @@ import net.minecraft.world.level.storage.loot.LootTable;
|
||||
import net.minecraft.world.level.storage.loot.ValidationContext;
|
||||
import net.minecraft.world.level.storage.loot.entries.CompositeEntryBase;
|
||||
import net.minecraft.world.level.storage.loot.entries.LootPoolEntryContainer;
|
||||
import net.minecraft.world.level.storage.loot.parameters.LootContextParamSet;
|
||||
|
||||
/**
|
||||
* Currently used only for replacing shears item to shears_dig tool action
|
||||
*/
|
||||
public final class ForgeLootTableProvider extends LootTableProvider {
|
||||
|
||||
public ForgeLootTableProvider(DataGenerator gen) {
|
||||
super(gen);
|
||||
public ForgeLootTableProvider(PackOutput packOutput) {
|
||||
super(packOutput, Set.of(), VanillaLootTableProvider.create(packOutput).getTables());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void validate(Map<ResourceLocation, LootTable> map, ValidationContext validationtracker) {
|
||||
// do not validate against all registered loot tables
|
||||
protected void validate(Map<ResourceLocation, LootTable> map, ValidationContext validationcontext) {
|
||||
// Do not validate against all registered loot tables
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<Pair<Supplier<Consumer<BiConsumer<ResourceLocation, LootTable.Builder>>>, LootContextParamSet>> getTables() {
|
||||
return super.getTables().stream().map(pair -> {
|
||||
// provides new consumer with filtering only changed loot tables and replacing condition item to condition tag
|
||||
return new Pair<Supplier<Consumer<BiConsumer<ResourceLocation, LootTable.Builder>>>, LootContextParamSet>(() -> replaceAndFilterChangesOnly(pair.getFirst().get()), pair.getSecond());
|
||||
public List<LootTableProvider.SubProviderEntry> getTables() {
|
||||
return super.getTables().stream().map(entry -> {
|
||||
// Provides new sub provider with filtering only changed loot tables and replacing condition item to condition tag
|
||||
return new LootTableProvider.SubProviderEntry(() -> replaceAndFilterChangesOnly(entry.provider().get()), entry.paramSet());
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private Consumer<BiConsumer<ResourceLocation, LootTable.Builder>> replaceAndFilterChangesOnly(Consumer<BiConsumer<ResourceLocation, LootTable.Builder>> consumer) {
|
||||
return (newConsumer) -> consumer.accept((resourceLocation, builder) -> {
|
||||
private LootTableSubProvider replaceAndFilterChangesOnly(LootTableSubProvider subProvider) {
|
||||
return newConsumer -> subProvider.generate((resourceLocation, builder) -> {
|
||||
if (findAndReplaceInLootTableBuilder(builder, Items.SHEARS, ToolActions.SHEARS_DIG)) {
|
||||
newConsumer.accept(resourceLocation, builder);
|
||||
}
|
||||
|
||||
@@ -6,12 +6,13 @@
|
||||
package net.minecraftforge.common.data;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.advancements.Advancement;
|
||||
import net.minecraft.data.CachedOutput;
|
||||
import net.minecraft.data.DataGenerator;
|
||||
import net.minecraft.data.PackOutput;
|
||||
import net.minecraft.data.recipes.FinishedRecipe;
|
||||
import net.minecraft.data.recipes.RecipeProvider;
|
||||
import net.minecraft.data.recipes.ShapedRecipeBuilder;
|
||||
import net.minecraft.data.recipes.ShapelessRecipeBuilder;
|
||||
import net.minecraft.data.recipes.packs.VanillaRecipeProvider;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.world.item.Item;
|
||||
@@ -30,16 +31,17 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.lang.reflect.Field;
|
||||
import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public final class ForgeRecipeProvider extends RecipeProvider
|
||||
public final class ForgeRecipeProvider extends VanillaRecipeProvider
|
||||
{
|
||||
private final Map<Item, TagKey<Item>> replacements = new HashMap<>();
|
||||
private final Set<ResourceLocation> excludes = new HashSet<>();
|
||||
|
||||
public ForgeRecipeProvider(DataGenerator generatorIn)
|
||||
public ForgeRecipeProvider(PackOutput packOutput)
|
||||
{
|
||||
super(generatorIn);
|
||||
super(packOutput);
|
||||
}
|
||||
|
||||
private void exclude(ItemLike item)
|
||||
@@ -53,7 +55,7 @@ public final class ForgeRecipeProvider extends RecipeProvider
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void buildCraftingRecipes(Consumer<FinishedRecipe> consumer)
|
||||
protected void buildRecipes(Consumer<FinishedRecipe> consumer)
|
||||
{
|
||||
replace(Items.STICK, Tags.Items.RODS_WOODEN);
|
||||
replace(Items.GOLD_INGOT, Tags.Items.INGOTS_GOLD);
|
||||
@@ -84,7 +86,7 @@ public final class ForgeRecipeProvider extends RecipeProvider
|
||||
exclude(Blocks.COBBLED_DEEPSLATE_SLAB);
|
||||
exclude(Blocks.COBBLED_DEEPSLATE_WALL);
|
||||
|
||||
super.buildCraftingRecipes(vanilla -> {
|
||||
super.buildRecipes(vanilla -> {
|
||||
FinishedRecipe modified = enhance(vanilla);
|
||||
if (modified != null)
|
||||
consumer.accept(modified);
|
||||
@@ -118,10 +120,19 @@ public final class ForgeRecipeProvider extends RecipeProvider
|
||||
return modified ? vanilla : null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
protected void saveAdvancement(CachedOutput output, JsonObject advancementJson, Path pathIn)
|
||||
protected CompletableFuture<?> saveAdvancement(CachedOutput output, FinishedRecipe finishedRecipe, JsonObject advancementJson)
|
||||
{
|
||||
//NOOP - We dont replace any of the advancement things yet...
|
||||
// NOOP - We don't replace any of the advancement things yet...
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CompletableFuture<?> buildAdvancement(CachedOutput p_253674_, ResourceLocation p_254102_, Advancement.Builder p_253712_)
|
||||
{
|
||||
// NOOP - We don't replace any of the advancement things yet...
|
||||
return CompletableFuture.allOf();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.common.data;
|
||||
|
||||
import com.mojang.serialization.Lifecycle;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.data.DataGenerator;
|
||||
import net.minecraft.data.tags.TagsProvider;
|
||||
import net.minecraftforge.registries.GameData;
|
||||
import net.minecraftforge.registries.IForgeRegistry;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public abstract class ForgeRegistryTagsProvider<T> extends TagsProvider<T>
|
||||
{
|
||||
private static <T> Registry<T> wrapRegistry(IForgeRegistry<T> forgeRegistry)
|
||||
{
|
||||
if (forgeRegistry.tags() == null)
|
||||
throw new IllegalArgumentException("Forge registry " + forgeRegistry.getRegistryName() + " does not have support for tags");
|
||||
if (forgeRegistry.getDefaultKey() == null)
|
||||
return GameData.getWrapper(forgeRegistry.getRegistryKey(), Lifecycle.experimental());
|
||||
return GameData.getWrapper(forgeRegistry.getRegistryKey(), Lifecycle.experimental(), "default");
|
||||
}
|
||||
|
||||
public ForgeRegistryTagsProvider(DataGenerator generator, IForgeRegistry<T> forgeRegistry, String modId, @Nullable ExistingFileHelper existingFileHelper)
|
||||
{
|
||||
super(generator, wrapRegistry(forgeRegistry), modId, existingFileHelper);
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
package net.minecraftforge.common.data;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonElement;
|
||||
@@ -14,6 +15,7 @@ import cpw.mods.modlauncher.api.LamdbaExceptionUtils;
|
||||
import net.minecraft.data.CachedOutput;
|
||||
import net.minecraft.data.DataGenerator;
|
||||
import net.minecraft.data.DataProvider;
|
||||
import net.minecraft.data.PackOutput;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraftforge.common.loot.IGlobalLootModifier;
|
||||
import net.minecraftforge.common.loot.LootModifier;
|
||||
@@ -24,6 +26,7 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -59,26 +62,30 @@ public abstract class GlobalLootModifierProvider implements DataProvider
|
||||
protected abstract void start();
|
||||
|
||||
@Override
|
||||
public void run(CachedOutput cache) throws IOException
|
||||
public CompletableFuture<?> run(CachedOutput cache)
|
||||
{
|
||||
start();
|
||||
|
||||
Path forgePath = gen.getOutputFolder().resolve("data/forge/loot_modifiers/global_loot_modifiers.json");
|
||||
String modPath = "data/" + modid + "/loot_modifiers/";
|
||||
Path forgePath = this.gen.getPackOutput().getOutputFolder(PackOutput.Target.DATA_PACK).resolve("forge").resolve("loot_modifiers").resolve("global_loot_modifiers.json");
|
||||
Path modifierFolderPath = this.gen.getPackOutput().getOutputFolder(PackOutput.Target.DATA_PACK).resolve(this.modid).resolve("loot_modifiers");
|
||||
List<ResourceLocation> entries = new ArrayList<>();
|
||||
|
||||
ImmutableList.Builder<CompletableFuture<?>> futuresBuilder = new ImmutableList.Builder<>();
|
||||
|
||||
toSerialize.forEach(LamdbaExceptionUtils.rethrowBiConsumer((name, json) ->
|
||||
{
|
||||
entries.add(new ResourceLocation(modid, name));
|
||||
Path modifierPath = gen.getOutputFolder().resolve(modPath + name + ".json");
|
||||
DataProvider.saveStable(cache, json, modifierPath);
|
||||
Path modifierPath = modifierFolderPath.resolve(name + ".json");
|
||||
futuresBuilder.add(DataProvider.saveStable(cache, json, modifierPath));
|
||||
}));
|
||||
|
||||
JsonObject forgeJson = new JsonObject();
|
||||
forgeJson.addProperty("replace", this.replace);
|
||||
forgeJson.add("entries", GSON.toJsonTree(entries.stream().map(ResourceLocation::toString).collect(Collectors.toList())));
|
||||
|
||||
DataProvider.saveStable(cache, forgeJson, forgePath);
|
||||
futuresBuilder.add(DataProvider.saveStable(cache, forgeJson, forgePath));
|
||||
|
||||
return CompletableFuture.allOf(futuresBuilder.build().toArray(CompletableFuture[]::new));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,25 +5,26 @@
|
||||
|
||||
package net.minecraftforge.common.data;
|
||||
|
||||
import com.mojang.logging.LogUtils;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.mojang.logging.LogUtils;
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.DynamicOps;
|
||||
import com.mojang.serialization.JsonOps;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
import cpw.mods.modlauncher.api.LamdbaExceptionUtils;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.BiConsumer;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.data.CachedOutput;
|
||||
import net.minecraft.data.DataGenerator;
|
||||
import net.minecraft.data.DataProvider;
|
||||
import net.minecraft.data.PackOutput;
|
||||
import net.minecraft.resources.RegistryDataLoader;
|
||||
import net.minecraft.resources.RegistryOps;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
@@ -31,6 +32,8 @@ import net.minecraft.server.packs.PackType;
|
||||
import net.minecraftforge.common.crafting.CraftingHelper;
|
||||
import net.minecraftforge.common.crafting.conditions.ICondition;
|
||||
import net.minecraftforge.common.data.ExistingFileHelper.ResourceType;
|
||||
import net.minecraftforge.data.event.GatherDataEvent;
|
||||
import net.minecraftforge.registries.DataPackRegistriesHooks;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
/**
|
||||
@@ -57,7 +60,7 @@ public class JsonCodecProvider<T> implements DataProvider
|
||||
|
||||
/**
|
||||
* @param dataGenerator DataGenerator provided by {@link GatherDataEvent}.
|
||||
* @param dynamicOps DynamicOps to encode values to jsons with using the provided Codec, e.g. {@link JsonOps.INSTANCE}.
|
||||
* @param dynamicOps DynamicOps to encode values to jsons with using the provided Codec, e.g. {@link JsonOps#INSTANCE}.
|
||||
* @param packType PackType specifying whether to generate entries in assets or data.
|
||||
* @param directory String representing the directory to generate jsons in, e.g. "dimension" or "cheesemod/cheese".
|
||||
* @param codec Codec to encode values to jsons with using the provided DynamicOps.
|
||||
@@ -95,6 +98,7 @@ public class JsonCodecProvider<T> implements DataProvider
|
||||
* @param registryKey ResourceKey identifying the registry and its directory.
|
||||
* @param entries Map of entries to encode and their ResourceLocations. Paths for values are derived from the ResourceLocation's entryid:entrypath.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> JsonCodecProvider<T> forDatapackRegistry(DataGenerator dataGenerator, ExistingFileHelper existingFileHelper, String modid,
|
||||
RegistryOps<JsonElement> registryOps, ResourceKey<Registry<T>> registryKey, Map<ResourceLocation, T> entries)
|
||||
{
|
||||
@@ -104,21 +108,25 @@ public class JsonCodecProvider<T> implements DataProvider
|
||||
final String registryFolder = registryId.getNamespace().equals("minecraft")
|
||||
? registryId.getPath()
|
||||
: registryId.getNamespace() + "/" + registryId.getPath();
|
||||
final Codec<T> codec = (Codec<T>) RegistryAccess.REGISTRIES.get(registryKey).codec();
|
||||
RegistryDataLoader.RegistryData<?> registryData = DataPackRegistriesHooks.getDataPackRegistries().stream().filter(data -> data.key() == registryKey).findAny().orElseThrow();
|
||||
final Codec<T> codec = (Codec<T>) registryData.elementCodec();
|
||||
return new JsonCodecProvider<>(dataGenerator, existingFileHelper, modid, registryOps, PackType.SERVER_DATA, registryFolder, codec, entries);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(final CachedOutput cache) throws IOException
|
||||
public CompletableFuture<?> run(final CachedOutput cache)
|
||||
{
|
||||
final Path outputFolder = this.dataGenerator.getOutputFolder();
|
||||
final String dataFolder = this.packType.getDirectory();
|
||||
final Path outputFolder = this.dataGenerator.getPackOutput().getOutputFolder(this.packType == PackType.CLIENT_RESOURCES
|
||||
? PackOutput.Target.RESOURCE_PACK
|
||||
: PackOutput.Target.DATA_PACK);
|
||||
ImmutableList.Builder<CompletableFuture<?>> futuresBuilder = new ImmutableList.Builder<>();
|
||||
|
||||
gather(LamdbaExceptionUtils.rethrowBiConsumer((id, value) -> {
|
||||
final Path path = outputFolder.resolve(String.join("/", dataFolder, id.getNamespace(), this.directory, id.getPath() + ".json"));
|
||||
final Path path = outputFolder.resolve(id.getNamespace()).resolve(this.directory).resolve(id.getPath() + ".json");
|
||||
JsonElement encoded = this.codec.encodeStart(this.dynamicOps, value)
|
||||
.getOrThrow(false, msg -> LOGGER.error("Failed to encode {}: {}", path, msg));
|
||||
ICondition[] conditions = this.conditions.get(id);
|
||||
if (conditions != null && conditions.length > 0)
|
||||
if (conditions != null && conditions.length > 0)
|
||||
{
|
||||
if(encoded instanceof JsonObject obj)
|
||||
{
|
||||
@@ -129,8 +137,10 @@ public class JsonCodecProvider<T> implements DataProvider
|
||||
LOGGER.error("Attempted to apply conditions to a type that is not a JsonObject! - Path: {}", path);
|
||||
}
|
||||
}
|
||||
DataProvider.saveStable(cache, encoded, path);
|
||||
futuresBuilder.add(DataProvider.saveStable(cache, encoded, path));
|
||||
}));
|
||||
|
||||
return CompletableFuture.allOf(futuresBuilder.build().toArray(CompletableFuture[]::new));
|
||||
}
|
||||
|
||||
protected void gather(BiConsumer<ResourceLocation, T> consumer)
|
||||
|
||||
@@ -5,36 +5,24 @@
|
||||
|
||||
package net.minecraftforge.common.data;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import com.google.gson.JsonObject;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.TreeMap;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.google.common.hash.Hashing;
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.data.CachedOutput;
|
||||
import org.apache.commons.lang3.text.translate.JavaUnicodeEscaper;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.data.DataGenerator;
|
||||
import net.minecraft.data.HashCache;
|
||||
import net.minecraft.data.DataProvider;
|
||||
import net.minecraft.world.item.enchantment.Enchantment;
|
||||
import net.minecraft.data.PackOutput;
|
||||
import net.minecraft.world.effect.MobEffect;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.effect.MobEffect;
|
||||
import net.minecraft.world.item.enchantment.Enchantment;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public abstract class LanguageProvider implements DataProvider {
|
||||
private static final Gson GSON = (new GsonBuilder()).setPrettyPrinting().disableHtmlEscaping().setLenient().create();
|
||||
private final Map<String, String> data = new TreeMap<>();
|
||||
private final DataGenerator gen;
|
||||
private final String modid;
|
||||
@@ -49,10 +37,13 @@ public abstract class LanguageProvider implements DataProvider {
|
||||
protected abstract void addTranslations();
|
||||
|
||||
@Override
|
||||
public void run(CachedOutput cache) throws IOException {
|
||||
public CompletableFuture<?> run(CachedOutput cache) {
|
||||
addTranslations();
|
||||
|
||||
if (!data.isEmpty())
|
||||
save(cache, data, this.gen.getOutputFolder().resolve("assets/" + modid + "/lang/" + locale + ".json"));
|
||||
return save(cache, this.gen.getPackOutput().getOutputFolder(PackOutput.Target.RESOURCE_PACK).resolve(this.modid).resolve("lang").resolve(this.locale + ".json"));
|
||||
|
||||
return CompletableFuture.allOf();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -60,14 +51,12 @@ public abstract class LanguageProvider implements DataProvider {
|
||||
return "Languages: " + locale;
|
||||
}
|
||||
|
||||
private void save(CachedOutput cache, Object object, Path target) throws IOException {
|
||||
private CompletableFuture<?> save(CachedOutput cache, Path target) {
|
||||
// TODO: DataProvider.saveStable handles the caching and hashing already, but creating the JSON Object this way seems unreliable. -C
|
||||
JsonObject json = new JsonObject();
|
||||
for (Map.Entry<String, String> pair : data.entrySet()) {
|
||||
json.addProperty(pair.getKey(), pair.getValue());
|
||||
}
|
||||
this.data.forEach(json::addProperty);
|
||||
|
||||
DataProvider.saveStable(cache, json, target);
|
||||
return DataProvider.saveStable(cache, json, target);
|
||||
}
|
||||
|
||||
public void addBlock(Supplier<? extends Block> key, String name) {
|
||||
|
||||
@@ -5,13 +5,17 @@
|
||||
|
||||
package net.minecraftforge.common.data;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonObject;
|
||||
import java.nio.file.Path;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Supplier;
|
||||
import net.minecraft.data.CachedOutput;
|
||||
import net.minecraft.data.DataGenerator;
|
||||
import net.minecraft.data.HashCache;
|
||||
import net.minecraft.data.DataProvider;
|
||||
import net.minecraft.data.PackOutput;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.packs.PackType;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
@@ -19,14 +23,6 @@ import net.minecraftforge.registries.ForgeRegistries;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Data provider for the {@code sounds.json} file, which identifies sound definitions
|
||||
* for the various sound events in Minecraft.
|
||||
@@ -34,7 +30,6 @@ import java.util.stream.Collectors;
|
||||
public abstract class SoundDefinitionsProvider implements DataProvider
|
||||
{
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
private static final Gson GSON = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create();
|
||||
private final DataGenerator generator;
|
||||
private final String modId;
|
||||
private final ExistingFileHelper helper;
|
||||
@@ -61,15 +56,17 @@ public abstract class SoundDefinitionsProvider implements DataProvider
|
||||
public abstract void registerSounds();
|
||||
|
||||
@Override
|
||||
public void run(CachedOutput cache) throws IOException
|
||||
public CompletableFuture<?> run(CachedOutput cache)
|
||||
{
|
||||
this.sounds.clear();
|
||||
this.registerSounds();
|
||||
this.validate();
|
||||
if (!this.sounds.isEmpty())
|
||||
{
|
||||
this.save(cache, this.generator.getOutputFolder().resolve("assets/" + this.modId + "/sounds.json"));
|
||||
return this.save(cache, this.generator.getPackOutput().getOutputFolder(PackOutput.Target.RESOURCE_PACK).resolve(this.modId).resolve("sounds.json"));
|
||||
}
|
||||
|
||||
return CompletableFuture.allOf();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -208,7 +205,7 @@ public abstract class SoundDefinitionsProvider implements DataProvider
|
||||
.filter(it -> !this.validate(it.getKey(), it.getValue()))
|
||||
.map(Map.Entry::getKey)
|
||||
.map(it -> this.modId + ":" + it)
|
||||
.collect(Collectors.toList());
|
||||
.toList();
|
||||
if (!notValid.isEmpty())
|
||||
{
|
||||
throw new IllegalStateException("Found invalid sound events: " + notValid);
|
||||
@@ -228,7 +225,7 @@ public abstract class SoundDefinitionsProvider implements DataProvider
|
||||
case EVENT: return this.validateEvent(name, sound.name());
|
||||
}
|
||||
// Differently from all the other errors, this is not a 'missing sound' but rather something completely different
|
||||
// that has broken the invariants of this sound definitions provider. In fact, a sound may only be either of
|
||||
// that has broken the invariants of this sound definition's provider. In fact, a sound may only be either of
|
||||
// SOUND or EVENT type. Any other values is somebody messing with the internals, reflectively adding something
|
||||
// to an enum or passing `null` to a parameter annotated with `@NotNull`.
|
||||
throw new IllegalArgumentException("The given sound '" + sound.name() + "' does not have a valid type: expected either SOUND or EVENT, but found " + sound.type());
|
||||
@@ -255,9 +252,9 @@ public abstract class SoundDefinitionsProvider implements DataProvider
|
||||
return valid;
|
||||
}
|
||||
|
||||
private void save(final CachedOutput cache, final Path targetFile) throws IOException
|
||||
private CompletableFuture<?> save(final CachedOutput cache, final Path targetFile)
|
||||
{
|
||||
DataProvider.saveStable(cache, this.mapToJson(this.sounds), targetFile);
|
||||
return DataProvider.saveStable(cache, this.mapToJson(this.sounds), targetFile);
|
||||
}
|
||||
|
||||
private JsonObject mapToJson(final Map<String, SoundDefinition> map)
|
||||
|
||||
Reference in new issue
Block a user