mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-18 03:25:18 +00:00
[1.19.3] Fix Datagen Tests and Providers (#9212)
This commit is contained in:
1 parent
cc393818e4
commit
58d6f072e4
9 files changed
+229
-200
No files matched your search
+35
@@ -1,5 +1,29 @@
|
||||
--- a/net/minecraft/data/registries/RegistriesDatapackGenerator.java
|
||||
+++ b/net/minecraft/data/registries/RegistriesDatapackGenerator.java
|
||||
@@ -18,12 +_,23 @@
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
+/**
|
||||
+ * @deprecated Forge: Use {@link net.minecraftforge.common.data.DatapackBuiltinEntriesProvider} instead
|
||||
+ */
|
||||
+@Deprecated
|
||||
public class RegistriesDatapackGenerator implements DataProvider {
|
||||
private static final Logger f_254654_ = LogUtils.getLogger();
|
||||
private final PackOutput f_254743_;
|
||||
private final CompletableFuture<HolderLookup.Provider> f_254747_;
|
||||
+ private final java.util.function.Predicate<String> namespacePredicate;
|
||||
|
||||
+ @Deprecated
|
||||
public RegistriesDatapackGenerator(PackOutput p_256643_, CompletableFuture<HolderLookup.Provider> p_255780_) {
|
||||
+ this(p_256643_, p_255780_, null);
|
||||
+ }
|
||||
+
|
||||
+ public RegistriesDatapackGenerator(PackOutput p_256643_, CompletableFuture<HolderLookup.Provider> p_255780_, @org.jetbrains.annotations.Nullable java.util.Set<String> modIds) {
|
||||
+ this.namespacePredicate = modIds == null ? namespace -> true : modIds::contains;
|
||||
this.f_254747_ = p_255780_;
|
||||
this.f_254743_ = p_256643_;
|
||||
}
|
||||
@@ -31,7 +_,7 @@
|
||||
public CompletableFuture<?> m_213708_(CachedOutput p_255785_) {
|
||||
return this.f_254747_.thenCompose((p_256533_) -> {
|
||||
@@ -9,3 +33,14 @@
|
||||
return this.m_254918_(p_255785_, p_256533_, dynamicops, p_256552_).stream();
|
||||
}).toArray((p_255809_) -> {
|
||||
return new CompletableFuture[p_255809_];
|
||||
@@ -42,8 +_,8 @@
|
||||
private <T> Optional<CompletableFuture<?>> m_254918_(CachedOutput p_256502_, HolderLookup.Provider p_256492_, DynamicOps<JsonElement> p_256000_, RegistryDataLoader.RegistryData<T> p_256449_) {
|
||||
ResourceKey<? extends Registry<T>> resourcekey = p_256449_.f_243794_();
|
||||
return p_256492_.m_254861_(resourcekey).map((p_255847_) -> {
|
||||
- PackOutput.PathProvider packoutput$pathprovider = this.f_254743_.m_245269_(PackOutput.Target.DATA_PACK, resourcekey.m_135782_().m_135815_());
|
||||
- return CompletableFuture.allOf(p_255847_.m_214062_().map((p_256105_) -> {
|
||||
+ PackOutput.PathProvider packoutput$pathprovider = this.f_254743_.m_245269_(PackOutput.Target.DATA_PACK, net.minecraftforge.common.ForgeHooks.prefixNamespace(resourcekey.m_135782_()));
|
||||
+ return CompletableFuture.allOf(p_255847_.m_214062_().filter(holder -> this.namespacePredicate.test(holder.m_205785_().m_135782_().m_135827_())).map((p_256105_) -> {
|
||||
return m_255283_(packoutput$pathprovider.m_245731_(p_256105_.m_205785_().m_135782_()), p_256502_, p_256000_, p_256449_.f_244580_(), p_256105_.m_203334_());
|
||||
}).toArray((p_256279_) -> {
|
||||
return new CompletableFuture[p_256279_];
|
||||
@@ -5,29 +5,66 @@
|
||||
|
||||
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;
|
||||
import net.minecraftforge.registries.DataPackRegistriesHooks;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
/**
|
||||
* An extension of the {@link RegistriesDatapackGenerator} which properly handles
|
||||
* referencing existing dynamic registry objects within another dynamic registry
|
||||
* object.
|
||||
*/
|
||||
public class DatapackBuiltinEntriesProvider extends RegistriesDatapackGenerator
|
||||
{
|
||||
public DatapackBuiltinEntriesProvider(PackOutput output, Supplier<HolderLookup.Provider> registriesSupplier)
|
||||
|
||||
/**
|
||||
* Constructs a new datapack provider which generates all registry objects
|
||||
* from the provided mods using the holder.
|
||||
*
|
||||
* @param output the target directory of the data generator
|
||||
* @param registries a future of a lookup for registries and their objects
|
||||
* @param modIds a set of mod ids to generate the dynamic registry objects of
|
||||
*/
|
||||
public DatapackBuiltinEntriesProvider(PackOutput output, CompletableFuture<HolderLookup.Provider> registries, Set<String> modIds)
|
||||
{
|
||||
super(output, CompletableFuture.supplyAsync(registriesSupplier, Util.backgroundExecutor()));
|
||||
super(output, registries, modIds);
|
||||
}
|
||||
|
||||
public DatapackBuiltinEntriesProvider(PackOutput output, RegistrySetBuilder datapackEntriesBuilder)
|
||||
/**
|
||||
* Constructs a new datapack provider which generates all registry objects
|
||||
* from the provided mods using the holder. All entries that need to be
|
||||
* bootstrapped are provided within the {@link RegistrySetBuilder}.
|
||||
*
|
||||
* @param output the target directory of the data generator
|
||||
* @param registries a future of a lookup for registries and their objects
|
||||
* @param datapackEntriesBuilder a builder containing the dynamic registry objects added by this provider
|
||||
* @param modIds a set of mod ids to generate the dynamic registry objects of
|
||||
*/
|
||||
public DatapackBuiltinEntriesProvider(PackOutput output, CompletableFuture<HolderLookup.Provider> registries, RegistrySetBuilder datapackEntriesBuilder, Set<String> modIds)
|
||||
{
|
||||
this(output, () -> createLookup(datapackEntriesBuilder));
|
||||
this(output, registries.thenApply(r -> constructRegistries(r, datapackEntriesBuilder)), modIds);
|
||||
}
|
||||
|
||||
public static HolderLookup.Provider createLookup(RegistrySetBuilder datapackEntriesBuilder) {
|
||||
return datapackEntriesBuilder.build(RegistryAccess.fromRegistryOfRegistries(BuiltInRegistries.REGISTRY));
|
||||
/**
|
||||
* A method used to construct empty bootstraps for all registries this provider
|
||||
* did not touch such that existing dynamic registry objects do not get inlined.
|
||||
*
|
||||
* @param original a future of a lookup for registries and their objects
|
||||
* @param datapackEntriesBuilder a builder containing the dynamic registry objects added by this provider
|
||||
* @return a new lookup containing the existing and to be generated registries and their objects
|
||||
*/
|
||||
private static HolderLookup.Provider constructRegistries(HolderLookup.Provider original, RegistrySetBuilder datapackEntriesBuilder)
|
||||
{
|
||||
var builderKeys = new HashSet<>(datapackEntriesBuilder.getEntryKeys());
|
||||
DataPackRegistriesHooks.getDataPackRegistries().stream().filter(data -> !builderKeys.contains(data.key())).forEach(data -> datapackEntriesBuilder.add(data.key(), context -> {}));
|
||||
return datapackEntriesBuilder.buildPatch(RegistryAccess.fromRegistryOfRegistries(BuiltInRegistries.REGISTRY), original);
|
||||
}
|
||||
}
|
||||
@@ -20,10 +20,11 @@ import java.util.function.Consumer;
|
||||
* An extension of the {@link AdvancementProvider} to provide a feature-complete
|
||||
* experience to generate modded advancements.
|
||||
*/
|
||||
public abstract class ForgeAdvancementProvider extends AdvancementProvider
|
||||
public class ForgeAdvancementProvider extends AdvancementProvider
|
||||
{
|
||||
/**
|
||||
* Default constructor.
|
||||
* Constructs an advancement provider using the generators to write the
|
||||
* advancements to a file.
|
||||
*
|
||||
* @param output the target directory of the data generator
|
||||
* @param registries a future of a lookup for registries and their objects
|
||||
|
||||
@@ -84,34 +84,6 @@ public class JsonCodecProvider<T> implements DataProvider
|
||||
this.entries = entries;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return DatapackRegistryProvider that encodes using the registered loading codec for the provided registry key}
|
||||
* Ensures the correct directory and codec are used.
|
||||
* Only vanilla datapack registries enumerated in {@link RegistryAccess} and custom forge datapack registries can
|
||||
* be generated this way.
|
||||
*
|
||||
* @param <T> Registry element type, e.g. Biome
|
||||
* @param output {@linkplain PackOutput} provided by the {@link DataGenerator}.
|
||||
* @param modid namespace of the mod adding this DataProvider, for logging purposes.
|
||||
* @param registryOps RegistryOps to encode values to json with.
|
||||
* @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(PackOutput output, ExistingFileHelper existingFileHelper, String modid,
|
||||
RegistryOps<JsonElement> registryOps, ResourceKey<Registry<T>> registryKey, Map<ResourceLocation, T> entries)
|
||||
{
|
||||
final ResourceLocation registryId = registryKey.location();
|
||||
// Minecraft datapack registry folders are in data/json-namespace/registry-name/
|
||||
// Non-vanilla registry folders are data/json-namespace/registry-namespace/registry-name/
|
||||
final String registryFolder = registryId.getNamespace().equals("minecraft")
|
||||
? registryId.getPath()
|
||||
: registryId.getNamespace() + "/" + registryId.getPath();
|
||||
RegistryDataLoader.RegistryData<?> registryData = DataPackRegistriesHooks.getDataPackRegistries().stream().filter(data -> data.key() == registryKey).findAny().orElseThrow();
|
||||
final Codec<T> codec = (Codec<T>) registryData.elementCodec();
|
||||
return new JsonCodecProvider<>(output, existingFileHelper, modid, registryOps, PackType.SERVER_DATA, registryFolder, codec, entries);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<?> run(final CachedOutput cache)
|
||||
{
|
||||
@@ -164,4 +136,4 @@ public class JsonCodecProvider<T> implements DataProvider
|
||||
this.conditions = conditions;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -185,6 +185,7 @@ public net.minecraft.data.recipes.packs.VanillaRecipeProvider f_244369_ # GOLD_S
|
||||
public net.minecraft.data.recipes.packs.VanillaRecipeProvider f_244430_ # EMERALD_SMELTABLES
|
||||
public net.minecraft.data.recipes.packs.VanillaRecipeProvider f_244565_ # REDSTONE_SMELTABLES
|
||||
public net.minecraft.data.recipes.packs.VanillaRecipeProvider f_244628_ # LAPIS_SMELTABLES
|
||||
public-f net.minecraft.data.registries.RegistriesDatapackGenerator m_6055_()Ljava/lang/String; # getName
|
||||
public net.minecraft.data.tags.IntrinsicHolderTagsProvider$IntrinsicTagAppender
|
||||
protected net.minecraft.data.tags.TagsProvider f_126543_ # builders
|
||||
public-f net.minecraft.data.tags.TagsProvider m_6055_()Ljava/lang/String; # getName
|
||||
@@ -452,4 +453,4 @@ public net.minecraft.world.level.levelgen.feature.trunkplacers.TrunkPlacerType <
|
||||
protected net.minecraft.world.level.portal.PortalForcer f_77648_ # level
|
||||
public net.minecraft.world.level.storage.LevelResource <init>(Ljava/lang/String;)V # constructor
|
||||
private-f net.minecraft.world.level.storage.loot.LootPool f_79028_ # rolls
|
||||
private-f net.minecraft.world.level.storage.loot.LootPool f_79029_ # bonusRolls
|
||||
private-f net.minecraft.world.level.storage.loot.LootPool f_79029_ # bonusRolls
|
||||
@@ -31,6 +31,7 @@ net/minecraft/client/resources/model/MultiPartBakedModel.getQuads(Lnet/minecraft
|
||||
net/minecraft/client/resources/model/SimpleBakedModel$Builder.build(Lnet/minecraftforge/client/RenderTypeGroup;)Lnet/minecraft/client/resources/model/BakedModel;=|renderTypes
|
||||
net/minecraft/client/resources/model/SimpleBakedModel.<init>(Ljava/util/List;Ljava/util/Map;ZZZLnet/minecraft/client/renderer/texture/TextureAtlasSprite;Lnet/minecraft/client/renderer/block/model/ItemTransforms;Lnet/minecraft/client/renderer/block/model/ItemOverrides;Lnet/minecraftforge/client/RenderTypeGroup;)V=|p_119489_,p_119490_,p_119491_,p_119492_,p_119493_,p_119494_,p_119495_,p_119496_,renderTypes
|
||||
net/minecraft/client/resources/model/WeightedBakedModel.getQuads(Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/core/Direction;Lnet/minecraft/util/RandomSource;Lnet/minecraftforge/client/model/data/ModelData;Lnet/minecraft/client/renderer/RenderType;)Ljava/util/List;=|p_235058_,p_235059_,p_235060_,modelData,renderType
|
||||
net/minecraft/data/registries/RegistriesDatapackGenerator.<init>(Lnet/minecraft/data/PackOutput;Ljava/util/concurrent/CompletableFuture;Ljava.util.Set;)V=|p_256643_,p_255780_,modIds
|
||||
net/minecraft/data/tags/BannerPatternTagsProvider.<init>(Lnet/minecraft/data/PackOutput;Ljava/util/concurrent/CompletableFuture;Ljava/lang/String;Lnet/minecraftforge/common/data/ExistingFileHelper;)V=|p_256451_,p_256420_,modId,existingFileHelper
|
||||
net/minecraft/data/tags/BiomeTagsProvider.<init>(Lnet/minecraft/data/PackOutput;Ljava/util/concurrent/CompletableFuture;Ljava/lang/String;Lnet/minecraftforge/common/data/ExistingFileHelper;)V=|p_255800_,p_256205_,modId,existingFileHelper
|
||||
net/minecraft/data/tags/CatVariantTagsProvider.<init>(Lnet/minecraft/data/PackOutput;Ljava/util/concurrent/CompletableFuture;Ljava/lang/String;Lnet/minecraftforge/common/data/ExistingFileHelper;)V=|p_256547_,p_256090_,modId,existingFileHelper
|
||||
|
||||
@@ -31,11 +31,14 @@ import com.google.gson.JsonPrimitive;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.advancements.critereon.InventoryChangeTrigger;
|
||||
import net.minecraft.core.HolderLookup;
|
||||
import net.minecraft.core.RegistrySetBuilder;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.data.CachedOutput;
|
||||
import net.minecraft.data.PackOutput;
|
||||
import net.minecraft.data.recipes.*;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.tags.ItemTags;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
@@ -45,6 +48,7 @@ import net.minecraft.world.level.block.DoorBlock;
|
||||
import net.minecraft.world.level.block.PressurePlateBlock;
|
||||
import net.minecraft.world.level.block.StandingSignBlock;
|
||||
import net.minecraft.world.level.block.WallSignBlock;
|
||||
import net.minecraft.world.level.levelgen.NoiseGeneratorSettings;
|
||||
import net.minecraftforge.common.crafting.CompoundIngredient;
|
||||
import net.minecraftforge.common.crafting.PartialNBTIngredient;
|
||||
import net.minecraftforge.common.crafting.DifferenceIngredient;
|
||||
@@ -121,6 +125,11 @@ public class DataGeneratorTest
|
||||
|
||||
private static Gson GSON = null;
|
||||
|
||||
// Datapack registry objects
|
||||
private static final ResourceKey<NoiseGeneratorSettings> TEST_SETTINGS = ResourceKey.create(Registries.NOISE_SETTINGS, new ResourceLocation(MODID, "test_settings"));
|
||||
private static final RegistrySetBuilder BUILDER = new RegistrySetBuilder()
|
||||
.add(Registries.NOISE_SETTINGS, context -> context.register(TEST_SETTINGS, NoiseGeneratorSettings.floatingIslands(context)));
|
||||
|
||||
@SubscribeEvent
|
||||
public static void gatherData(GatherDataEvent event)
|
||||
{
|
||||
@@ -138,12 +147,13 @@ public class DataGeneratorTest
|
||||
// Let blockstate provider see generated item models by passing its existing file helper
|
||||
ItemModelProvider itemModels = new ItemModels(packOutput, event.getExistingFileHelper());
|
||||
gen.addProvider(event.includeClient(), itemModels);
|
||||
gen.addProvider(event.includeClient(), new BlockStates(gen.getPackOutput(), itemModels.existingFileHelper));
|
||||
gen.addProvider(event.includeClient(), new BlockStates(packOutput, itemModels.existingFileHelper));
|
||||
gen.addProvider(event.includeClient(), new SoundDefinitions(packOutput, event.getExistingFileHelper()));
|
||||
|
||||
gen.addProvider(event.includeServer(), new Recipes(packOutput));
|
||||
gen.addProvider(event.includeServer(), new Tags(packOutput, lookupProvider, event.getExistingFileHelper()));
|
||||
gen.addProvider(event.includeServer(), new Advancements(packOutput, lookupProvider, event.getExistingFileHelper()));
|
||||
gen.addProvider(event.includeServer(), new ForgeAdvancementProvider(packOutput, lookupProvider, event.getExistingFileHelper(), List.of(new Advancements())));
|
||||
gen.addProvider(event.includeServer(), new DatapackBuiltinEntriesProvider(packOutput, lookupProvider, BUILDER, Set.of(MODID)));
|
||||
}
|
||||
|
||||
public static class Recipes extends RecipeProvider implements IConditionBuilder
|
||||
@@ -1014,54 +1024,47 @@ public class DataGeneratorTest
|
||||
}
|
||||
}
|
||||
|
||||
public static class Advancements extends ForgeAdvancementProvider
|
||||
private static class Advancements implements ForgeAdvancementProvider.AdvancementGenerator
|
||||
{
|
||||
|
||||
|
||||
public Advancements(PackOutput output, CompletableFuture<HolderLookup.Provider> providerCompletableFuture, ExistingFileHelper existingFileHelper)
|
||||
@Override
|
||||
public void generate(HolderLookup.Provider registries, Consumer<Advancement> saver, ExistingFileHelper existingFileHelper)
|
||||
{
|
||||
super(output, providerCompletableFuture, existingFileHelper, List.of(new Provider()));
|
||||
}
|
||||
Advancement.Builder.advancement().display(Items.DIRT,
|
||||
Component.translatable(Items.DIRT.getDescriptionId()),
|
||||
Component.translatable("dirt_description"),
|
||||
new ResourceLocation("textures/gui/advancements/backgrounds/stone.png"),
|
||||
FrameType.TASK,
|
||||
true,
|
||||
true,
|
||||
false)
|
||||
.addCriterion("has_dirt", InventoryChangeTrigger.TriggerInstance.hasItems(Items.DIRT))
|
||||
.save(saver, new ResourceLocation(MODID, "obtain_dirt"), existingFileHelper);
|
||||
|
||||
private static class Provider implements AdvancementGenerator {
|
||||
Advancement.Builder.advancement().display(Items.DIAMOND_BLOCK,
|
||||
Component.translatable(Items.DIAMOND_BLOCK.getDescriptionId()),
|
||||
Component.literal("You obtained a DiamondBlock"),
|
||||
new ResourceLocation("textures/gui/advancements/backgrounds/stone.png"),
|
||||
FrameType.CHALLENGE,
|
||||
true,
|
||||
true,
|
||||
false)
|
||||
.addCriterion("obtained_diamond_block", InventoryChangeTrigger.TriggerInstance.hasItems(Items.DIAMOND_BLOCK))
|
||||
.save(saver, new ResourceLocation("obtain_diamond_block"), existingFileHelper);
|
||||
|
||||
@Override
|
||||
public void generate(HolderLookup.Provider registries, Consumer<Advancement> saver, ExistingFileHelper existingFileHelper) {
|
||||
Advancement.Builder.advancement().display(Items.DIRT,
|
||||
Component.translatable(Items.DIRT.getDescriptionId()),
|
||||
Component.translatable("dirt_description"),
|
||||
new ResourceLocation("textures/gui/advancements/backgrounds/stone.png"),
|
||||
FrameType.TASK,
|
||||
true,
|
||||
true,
|
||||
false)
|
||||
.addCriterion("has_dirt", InventoryChangeTrigger.TriggerInstance.hasItems(Items.DIRT))
|
||||
.save(saver, new ResourceLocation(MODID, "obtain_dirt"), existingFileHelper);
|
||||
Advancement.Builder.advancement()
|
||||
.display(Blocks.GRASS_BLOCK,
|
||||
Component.translatable("advancements.story.root.title"),
|
||||
Component.literal("Changed Description"),
|
||||
new ResourceLocation("textures/gui/advancements/backgrounds/stone.png"),
|
||||
FrameType.TASK,
|
||||
false,
|
||||
false,
|
||||
false)
|
||||
.addCriterion("crafting_table", InventoryChangeTrigger.TriggerInstance.hasItems(Blocks.CRAFTING_TABLE))
|
||||
.save(saver, new ResourceLocation("story/root"), existingFileHelper);
|
||||
|
||||
Advancement.Builder.advancement().display(Items.DIAMOND_BLOCK,
|
||||
Component.translatable(Items.DIAMOND_BLOCK.getDescriptionId()),
|
||||
Component.literal("You obtained a DiamondBlock"),
|
||||
new ResourceLocation("textures/gui/advancements/backgrounds/stone.png"),
|
||||
FrameType.CHALLENGE,
|
||||
true,
|
||||
true,
|
||||
false)
|
||||
.addCriterion("obtained_diamond_block", InventoryChangeTrigger.TriggerInstance.hasItems(Items.DIAMOND_BLOCK))
|
||||
.save(saver, new ResourceLocation("obtain_diamond_block"), existingFileHelper);
|
||||
|
||||
Advancement.Builder.advancement()
|
||||
.display(Blocks.GRASS_BLOCK,
|
||||
Component.translatable("advancements.story.root.title"),
|
||||
Component.literal("Changed Description"),
|
||||
new ResourceLocation("textures/gui/advancements/backgrounds/stone.png"),
|
||||
FrameType.TASK,
|
||||
false,
|
||||
false,
|
||||
false)
|
||||
.addCriterion("crafting_table", InventoryChangeTrigger.TriggerInstance.hasItems(Blocks.CRAFTING_TABLE))
|
||||
.save(saver, new ResourceLocation("story/root"), existingFileHelper);
|
||||
|
||||
// This should cause an error because of the parent not existing
|
||||
// This should cause an error because of the parent not existing
|
||||
/* Advancement.Builder.advancement().display(Blocks.COBBLESTONE,
|
||||
new TranslationTextComponent(Items.COBBLESTONE.getDescriptionId()),
|
||||
new StringTextComponent("You got cobblestone"),
|
||||
@@ -1074,18 +1077,17 @@ public class DataGeneratorTest
|
||||
.parent(new ResourceLocation("not_there/not_here"))
|
||||
.save(consumer, new ResourceLocation("illegal_parent"), fileHelper);*/
|
||||
|
||||
Advancement.Builder.advancement().display(Blocks.COBBLESTONE,
|
||||
Component.translatable(Items.COBBLESTONE.getDescriptionId()),
|
||||
Component.literal("You got cobblestone"),
|
||||
new ResourceLocation("textures/gui/advancements/backgrounds/stone.png"),
|
||||
FrameType.TASK,
|
||||
false,
|
||||
false,
|
||||
false)
|
||||
.addCriterion("get_cobbleStone", InventoryChangeTrigger.TriggerInstance.hasItems(Items.COBBLESTONE))
|
||||
.parent(new ResourceLocation("forge", "dummy_parent"))
|
||||
.save(saver, new ResourceLocation("good_parent"), existingFileHelper);
|
||||
}
|
||||
Advancement.Builder.advancement().display(Blocks.COBBLESTONE,
|
||||
Component.translatable(Items.COBBLESTONE.getDescriptionId()),
|
||||
Component.literal("You got cobblestone"),
|
||||
new ResourceLocation("textures/gui/advancements/backgrounds/stone.png"),
|
||||
FrameType.TASK,
|
||||
false,
|
||||
false,
|
||||
false)
|
||||
.addCriterion("get_cobbleStone", InventoryChangeTrigger.TriggerInstance.hasItems(Items.COBBLESTONE))
|
||||
.parent(new ResourceLocation("forge", "dummy_parent"))
|
||||
.save(saver, new ResourceLocation("good_parent"), existingFileHelper);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,28 +3,24 @@
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
TODO: 1.19.3: Datagen went async for registries and holder lookups!
|
||||
|
||||
|
||||
package net.minecraftforge.debug.world;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.JsonOps;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.HolderSet;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.data.DataGenerator;
|
||||
import net.minecraft.core.HolderLookup;
|
||||
import net.minecraft.core.HolderSet;;
|
||||
import net.minecraft.core.RegistrySetBuilder;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.data.DataProvider;
|
||||
import net.minecraft.data.PackOutput;
|
||||
import net.minecraft.data.worldgen.features.NetherFeatures;
|
||||
import net.minecraft.resources.RegistryOps;
|
||||
import net.minecraft.data.worldgen.placement.VegetationPlacements;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.BiomeTags;
|
||||
@@ -34,14 +30,10 @@ import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.biome.Biome.Precipitation;
|
||||
import net.minecraft.world.level.biome.MobSpawnSettings.SpawnerData;
|
||||
import net.minecraft.world.level.levelgen.GenerationStep.Decoration;
|
||||
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
|
||||
import net.minecraft.world.level.levelgen.placement.BiomeFilter;
|
||||
import net.minecraft.world.level.levelgen.placement.CountOnEveryLayerPlacement;
|
||||
import net.minecraft.world.level.levelgen.placement.PlacedFeature;
|
||||
import net.minecraftforge.common.crafting.conditions.ICondition;
|
||||
import net.minecraftforge.common.crafting.conditions.ModLoadedCondition;
|
||||
import net.minecraftforge.common.data.ExistingFileHelper;
|
||||
import net.minecraftforge.common.data.JsonCodecProvider;
|
||||
import net.minecraftforge.common.data.DatapackBuiltinEntriesProvider;
|
||||
import net.minecraftforge.common.world.BiomeModifier;
|
||||
import net.minecraftforge.common.world.ForgeBiomeModifiers.AddFeaturesBiomeModifier;
|
||||
import net.minecraftforge.common.world.ForgeBiomeModifiers.AddSpawnsBiomeModifier;
|
||||
@@ -56,7 +48,6 @@ import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraftforge.registries.RegistryObject;
|
||||
|
||||
*/
|
||||
/**
|
||||
* <p>This tests the following features and requirements of biome modifier jsons::</p>
|
||||
* <ul>
|
||||
@@ -68,35 +59,73 @@ import net.minecraftforge.registries.RegistryObject;
|
||||
* <p>If the biome modifiers are applied correctly, then badlands biomes should generate large basalt columns,
|
||||
* spawn magma cubes, have red-colored water, and be snowy. Additionally, biomes in the is_forest tag are missing
|
||||
* oak trees, pine trees, and skeletons.</p>
|
||||
*//*
|
||||
|
||||
*/
|
||||
@Mod(BiomeModifierTest.MODID)
|
||||
public class BiomeModifierTest
|
||||
{
|
||||
public static final String MODID = "biome_modifiers_test";
|
||||
private static final boolean ENABLED = true;
|
||||
|
||||
private static final String LARGE_BASALT_COLUMNS = "large_basalt_columns";
|
||||
private static final ResourceLocation LARGE_BASALT_COLUMNS_RL = new ResourceLocation(MODID, LARGE_BASALT_COLUMNS);
|
||||
private static final ResourceKey<PlacedFeature> LARGE_BASALT_COLUMNS_KEY = ResourceKey.create(Registry.PLACED_FEATURE_REGISTRY, LARGE_BASALT_COLUMNS_RL);
|
||||
/* Static registry objects */
|
||||
|
||||
private static final String MODIFY_BIOMES = "modify_biomes";
|
||||
private static final ResourceLocation MODIFY_BIOMES_RL = new ResourceLocation(MODID, MODIFY_BIOMES);
|
||||
// Biome Modifier Serializers
|
||||
private static final DeferredRegister<Codec<? extends BiomeModifier>> BIOME_MODIFIER_SERIALIZERS = DeferredRegister.create(ForgeRegistries.Keys.BIOME_MODIFIER_SERIALIZERS, MODID);
|
||||
private static final RegistryObject<Codec<TestModifier>> MODIFY_BIOMES = BIOME_MODIFIER_SERIALIZERS.register("modify_biomes", () ->
|
||||
RecordCodecBuilder.create(builder -> builder.group(
|
||||
Biome.LIST_CODEC.fieldOf("biomes").forGetter(TestModifier::biomes),
|
||||
Precipitation.CODEC.fieldOf("precipitation").forGetter(TestModifier::precipitation),
|
||||
Codec.INT.fieldOf("water_color").forGetter(TestModifier::waterColor)
|
||||
).apply(builder, TestModifier::new))
|
||||
);
|
||||
|
||||
private static final String ADD_BASALT = "add_basalt";
|
||||
private static final ResourceLocation ADD_BASALT_RL = new ResourceLocation(MODID, ADD_BASALT);
|
||||
/* Dynamic registry objects */
|
||||
|
||||
private static final String ADD_MAGMA_CUBES = "add_magma_cubes";
|
||||
private static final ResourceLocation ADD_MAGMA_CUBES_RL = new ResourceLocation(MODID, ADD_MAGMA_CUBES);
|
||||
private static final ResourceKey<PlacedFeature> LARGE_BASALT_COLUMNS = ResourceKey.create(Registries.PLACED_FEATURE, new ResourceLocation(MODID, "large_basalt_columns"));
|
||||
|
||||
private static final String MODIFY_BADLANDS = "modify_badlands";
|
||||
private static final ResourceLocation MODIFY_BADLANDS_RL = new ResourceLocation(MODID, MODIFY_BADLANDS);
|
||||
private static final ResourceKey<BiomeModifier> ADD_BASALT_MODIFIER = ResourceKey.create(ForgeRegistries.Keys.BIOME_MODIFIERS, new ResourceLocation(MODID, "add_basalt"));
|
||||
private static final ResourceKey<BiomeModifier> ADD_MAGMA_CUBES_MODIFIER = ResourceKey.create(ForgeRegistries.Keys.BIOME_MODIFIERS, new ResourceLocation(MODID, "add_magma_cubes"));
|
||||
private static final ResourceKey<BiomeModifier> MODIFY_BADLANDS_MODIFIER = ResourceKey.create(ForgeRegistries.Keys.BIOME_MODIFIERS, new ResourceLocation(MODID, "modify_badlands"));
|
||||
private static final ResourceKey<BiomeModifier> REMOVE_FOREST_TREES_MODIFIER = ResourceKey.create(ForgeRegistries.Keys.BIOME_MODIFIERS, new ResourceLocation(MODID, "remove_forest_trees"));
|
||||
private static final ResourceKey<BiomeModifier> REMOVE_FOREST_SKELETONS_MODIFIER = ResourceKey.create(ForgeRegistries.Keys.BIOME_MODIFIERS, new ResourceLocation(MODID, "remove_forest_skeletons"));
|
||||
|
||||
private static final String REMOVE_FOREST_TREES = "remove_forest_trees";
|
||||
private static final ResourceLocation REMOVE_FOREST_TREES_RL = new ResourceLocation(MODID, REMOVE_FOREST_TREES);
|
||||
private static final RegistrySetBuilder BUILDER = new RegistrySetBuilder()
|
||||
.add(Registries.PLACED_FEATURE, context -> context.register(LARGE_BASALT_COLUMNS,
|
||||
new PlacedFeature(
|
||||
context.lookup(Registries.CONFIGURED_FEATURE).getOrThrow(NetherFeatures.LARGE_BASALT_COLUMNS),
|
||||
List.of(CountOnEveryLayerPlacement.of(1), BiomeFilter.biome())
|
||||
)
|
||||
))
|
||||
.add(ForgeRegistries.Keys.BIOME_MODIFIERS, context -> {
|
||||
var badlandsTag = context.lookup(Registries.BIOME).getOrThrow(BiomeTags.IS_BADLANDS);
|
||||
var forestTag = context.lookup(Registries.BIOME).getOrThrow(BiomeTags.IS_FOREST);
|
||||
|
||||
private static final String REMOVE_FOREST_SKELETONS = "remove_forest_skeletons";
|
||||
private static final ResourceLocation REMOVE_FOREST_SKELETONS_RL = new ResourceLocation(MODID, REMOVE_FOREST_SKELETONS);
|
||||
context.register(ADD_BASALT_MODIFIER, new AddFeaturesBiomeModifier(
|
||||
badlandsTag,
|
||||
HolderSet.direct(context.lookup(Registries.PLACED_FEATURE).getOrThrow(LARGE_BASALT_COLUMNS)),
|
||||
Decoration.TOP_LAYER_MODIFICATION
|
||||
));
|
||||
|
||||
context.register(ADD_MAGMA_CUBES_MODIFIER, AddSpawnsBiomeModifier.singleSpawn(
|
||||
badlandsTag,
|
||||
new SpawnerData(EntityType.MAGMA_CUBE, 100, 1, 4)
|
||||
));
|
||||
|
||||
context.register(MODIFY_BADLANDS_MODIFIER, new TestModifier(
|
||||
badlandsTag,
|
||||
Precipitation.SNOW,
|
||||
0xFF000
|
||||
));
|
||||
|
||||
context.register(REMOVE_FOREST_TREES_MODIFIER, RemoveFeaturesBiomeModifier.allSteps(
|
||||
forestTag,
|
||||
HolderSet.direct(context.lookup(Registries.PLACED_FEATURE).getOrThrow(VegetationPlacements.TREES_BIRCH_AND_OAK))
|
||||
));
|
||||
|
||||
context.register(REMOVE_FOREST_SKELETONS_MODIFIER, new RemoveSpawnsBiomeModifier(
|
||||
forestTag,
|
||||
context.lookup(Registries.ENTITY_TYPE).getOrThrow(EntityTypeTags.SKELETONS)
|
||||
));
|
||||
});
|
||||
|
||||
public BiomeModifierTest()
|
||||
{
|
||||
@@ -106,81 +135,40 @@ public class BiomeModifierTest
|
||||
IEventBus modBus = FMLJavaModLoadingContext.get().getModEventBus();
|
||||
|
||||
// Serializer types can be registered via deferred register.
|
||||
final DeferredRegister<Codec<? extends BiomeModifier>> serializers = DeferredRegister.create(ForgeRegistries.Keys.BIOME_MODIFIER_SERIALIZERS, MODID);
|
||||
serializers.register(modBus);
|
||||
serializers.register(MODIFY_BIOMES, TestModifier::makeCodec);
|
||||
BIOME_MODIFIER_SERIALIZERS.register(modBus);
|
||||
|
||||
modBus.addListener(this::onGatherData);
|
||||
}
|
||||
|
||||
private void onGatherData(GatherDataEvent event)
|
||||
{
|
||||
// Example of how to datagen datapack registry objects.
|
||||
final DataGenerator generator = event.getGenerator();
|
||||
final ExistingFileHelper existingFileHelper = event.getExistingFileHelper();
|
||||
final RegistryOps<JsonElement> ops = RegistryOps.create(JsonOps.INSTANCE, RegistryAccess.builtinCopy());
|
||||
event.getGenerator().addProvider(event.includeServer(), (DataProvider.Factory<BiomeModifiers>) output -> new BiomeModifiers(output, event.getLookupProvider()));
|
||||
}
|
||||
|
||||
// Create our placed feature and biome modifiers.
|
||||
final ResourceKey<ConfiguredFeature<?,?>> configuredFeatureKey = NetherFeatures.LARGE_BASALT_COLUMNS.unwrapKey().get().cast(Registry.CONFIGURED_FEATURE_REGISTRY).get();
|
||||
// Make sure we're using the holder from the registryaccess/registryops, the static ones won't work.
|
||||
final Holder<ConfiguredFeature<?,?>> configuredFeatureHolder = ops.registry(Registry.CONFIGURED_FEATURE_REGISTRY).get().getOrCreateHolderOrThrow(configuredFeatureKey);
|
||||
final PlacedFeature basaltFeature = new PlacedFeature(
|
||||
configuredFeatureHolder,
|
||||
List.of(CountOnEveryLayerPlacement.of(1), BiomeFilter.biome()));
|
||||
private static class BiomeModifiers extends DatapackBuiltinEntriesProvider
|
||||
{
|
||||
|
||||
final HolderSet.Named<Biome> badlandsTag = new HolderSet.Named<>(ops.registry(Registry.BIOME_REGISTRY).get(), BiomeTags.IS_BADLANDS);
|
||||
final HolderSet.Named<Biome> forestsTag = new HolderSet.Named<>(ops.registry(Registry.BIOME_REGISTRY).get(), BiomeTags.IS_FOREST);
|
||||
public BiomeModifiers(PackOutput output, CompletableFuture<HolderLookup.Provider> registries)
|
||||
{
|
||||
super(output, registries, BUILDER, Set.of(MODID));
|
||||
}
|
||||
|
||||
final BiomeModifier addBasaltFeature = new AddFeaturesBiomeModifier(
|
||||
badlandsTag,
|
||||
HolderSet.direct(ops.registry(Registry.PLACED_FEATURE_REGISTRY).get().getOrCreateHolderOrThrow(ResourceKey.create(Registry.PLACED_FEATURE_REGISTRY, LARGE_BASALT_COLUMNS_KEY.location()))),
|
||||
Decoration.TOP_LAYER_MODIFICATION);
|
||||
|
||||
final BiomeModifier addSpawn = AddSpawnsBiomeModifier.singleSpawn(
|
||||
badlandsTag,
|
||||
new SpawnerData(EntityType.MAGMA_CUBE, 100, 1, 4));
|
||||
|
||||
final BiomeModifier biomeModifier = new TestModifier(
|
||||
new HolderSet.Named<>(ops.registry(Registry.BIOME_REGISTRY).get(), BiomeTags.IS_BADLANDS),
|
||||
Precipitation.SNOW,
|
||||
0xFF0000
|
||||
);
|
||||
|
||||
final BiomeModifier removeFeature = RemoveFeaturesBiomeModifier.allSteps(
|
||||
forestsTag,
|
||||
HolderSet.direct(ops.registry(Registry.PLACED_FEATURE_REGISTRY).get().getOrCreateHolderOrThrow(ResourceKey.create(Registry.PLACED_FEATURE_REGISTRY, new ResourceLocation("trees_birch_and_oak"))))
|
||||
);
|
||||
|
||||
final BiomeModifier removeSpawn = new RemoveSpawnsBiomeModifier(
|
||||
forestsTag,
|
||||
new HolderSet.Named<>(ops.registry(Registry.ENTITY_TYPE_REGISTRY).get(), EntityTypeTags.SKELETONS)
|
||||
);
|
||||
|
||||
// Create and add dataproviders.
|
||||
generator.addProvider(event.includeServer(), JsonCodecProvider.forDatapackRegistry(
|
||||
generator, existingFileHelper, MODID, ops, Registry.PLACED_FEATURE_REGISTRY, Map.of(
|
||||
LARGE_BASALT_COLUMNS_RL, basaltFeature)).setConditions(Map.of(LARGE_BASALT_COLUMNS_RL, new ICondition[] { new ModLoadedCondition("forge") })));
|
||||
|
||||
generator.addProvider(event.includeServer(), JsonCodecProvider.forDatapackRegistry(
|
||||
generator, existingFileHelper, MODID, ops, ForgeRegistries.Keys.BIOME_MODIFIERS, Map.of(
|
||||
MODIFY_BADLANDS_RL, biomeModifier,
|
||||
ADD_BASALT_RL, addBasaltFeature,
|
||||
ADD_MAGMA_CUBES_RL, addSpawn,
|
||||
REMOVE_FOREST_TREES_RL, removeFeature,
|
||||
REMOVE_FOREST_SKELETONS_RL, removeSpawn)));
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return "Biome Modifier Registries: " + MODID;
|
||||
}
|
||||
}
|
||||
|
||||
public record TestModifier(HolderSet<Biome> biomes, Precipitation precipitation, int waterColor) implements BiomeModifier
|
||||
{
|
||||
private static final RegistryObject<Codec<? extends BiomeModifier>> SERIALIZER = RegistryObject.create(MODIFY_BIOMES_RL, ForgeRegistries.Keys.BIOME_MODIFIER_SERIALIZERS, MODID);
|
||||
|
||||
@Override
|
||||
public void modify(Holder<Biome> biome, Phase phase, Builder builder)
|
||||
{
|
||||
if (phase == Phase.MODIFY && this.biomes.contains(biome))
|
||||
{
|
||||
builder.getClimateSettings().setPrecipitation(this.precipitation);
|
||||
builder.getEffects().waterColor(this.waterColor);
|
||||
builder.getSpecialEffects().waterColor(this.waterColor);
|
||||
if (this.precipitation == Precipitation.SNOW)
|
||||
builder.getClimateSettings().setTemperature(0F);
|
||||
}
|
||||
@@ -189,17 +177,7 @@ public class BiomeModifierTest
|
||||
@Override
|
||||
public Codec<? extends BiomeModifier> codec()
|
||||
{
|
||||
return SERIALIZER.get();
|
||||
}
|
||||
|
||||
private static Codec<TestModifier> makeCodec()
|
||||
{
|
||||
return RecordCodecBuilder.create(builder -> builder.group(
|
||||
Biome.LIST_CODEC.fieldOf("biomes").forGetter(TestModifier::biomes),
|
||||
Precipitation.CODEC.fieldOf("precipitation").forGetter(TestModifier::precipitation),
|
||||
Codec.INT.fieldOf("water_color").forGetter(TestModifier::waterColor)
|
||||
).apply(builder, TestModifier::new));
|
||||
return MODIFY_BIOMES.get();
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
@@ -14,6 +14,8 @@ license="LGPL v2.1"
|
||||
modId="potentialspawnsevent_test"
|
||||
[[mods]]
|
||||
modId="block_grow_feature_test"
|
||||
[[mods]]
|
||||
modId="biome_modifiers_test"
|
||||
|
||||
[[mods]]
|
||||
modId="advancement_event_test"
|
||||
|
||||
Reference in new issue
Block a user