-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix DatapackBuiltinEntriesProvider issues with forge registries, Fixes …
- Loading branch information
Showing
9 changed files
with
208 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 6 additions & 5 deletions
11
patches/minecraft/net/minecraft/data/registries/RegistryPatchGenerator.java.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
--- a/net/minecraft/data/registries/RegistryPatchGenerator.java | ||
+++ b/net/minecraft/data/registries/RegistryPatchGenerator.java | ||
@@ -20,6 +_,7 @@ | ||
RegistryDataLoader.WORLDGEN_REGISTRIES.forEach((p_313050_) -> { | ||
@@ -17,7 +_,7 @@ | ||
return p_310881_.thenApply((p_309945_) -> { | ||
RegistryAccess.Frozen registryaccess$frozen = RegistryAccess.fromRegistryOfRegistries(BuiltInRegistries.REGISTRY); | ||
Cloner.Factory cloner$factory = new Cloner.Factory(); | ||
- RegistryDataLoader.WORLDGEN_REGISTRIES.forEach((p_313050_) -> { | ||
+ RegistryDataLoader.getWorldGenAndDimensionStream().forEach((p_313050_) -> { | ||
p_313050_.runWithArguments(cloner$factory::addCodec); | ||
}); | ||
+ RegistryDataLoader.DIMENSION_REGISTRIES.forEach(reg -> reg.runWithArguments(cloner$factory::addCodec)); | ||
RegistrySetBuilder.PatchedRegistries registrysetbuilder$patchedregistries = p_310262_.buildPatch(registryaccess$frozen, p_309945_, cloner$factory); | ||
HolderLookup.Provider holderlookup$provider = registrysetbuilder$patchedregistries.full(); | ||
Optional<HolderLookup.RegistryLookup<Biome>> optional = holderlookup$provider.lookup(Registries.BIOME); |
15 changes: 15 additions & 0 deletions
15
patches/minecraft/net/minecraft/resources/RegistryDataLoader.java.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 0 additions & 11 deletions
11
patches/minecraft/net/minecraft/server/WorldLoader.java.patch
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
...test/data/datapack_builtin_entries_provider_test/biome_modifier/mossy_stone_modifier.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"type": "forge:add_features", | ||
"biomes": "#minecraft:is_overworld", | ||
"features": "datapack_builtin_entries_provider_test:mossy_stone", | ||
"step": "underground_ores" | ||
} |
27 changes: 27 additions & 0 deletions
27
.../data/datapack_builtin_entries_provider_test/worldgen/configured_feature/mossy_stone.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"type": "minecraft:ore", | ||
"config": { | ||
"discard_chance_on_air_exposure": 0.0, | ||
"size": 5, | ||
"targets": [ | ||
{ | ||
"state": { | ||
"Name": "minecraft:mossy_cobblestone" | ||
}, | ||
"target": { | ||
"predicate_type": "minecraft:tag_match", | ||
"tag": "minecraft:stone_ore_replaceables" | ||
} | ||
}, | ||
{ | ||
"state": { | ||
"Name": "minecraft:mossy_cobblestone" | ||
}, | ||
"target": { | ||
"predicate_type": "minecraft:tag_match", | ||
"tag": "minecraft:deepslate_ore_replaceables" | ||
} | ||
} | ||
] | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...test/data/datapack_builtin_entries_provider_test/worldgen/placed_feature/mossy_stone.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"feature": "datapack_builtin_entries_provider_test:mossy_stone", | ||
"placement": [ | ||
{ | ||
"type": "minecraft:count", | ||
"count": 8 | ||
}, | ||
{ | ||
"type": "minecraft:in_square" | ||
}, | ||
{ | ||
"type": "minecraft:height_range", | ||
"height": { | ||
"type": "minecraft:uniform", | ||
"max_inclusive": { | ||
"absolute": 64 | ||
}, | ||
"min_inclusive": { | ||
"absolute": -64 | ||
} | ||
} | ||
}, | ||
{ | ||
"type": "minecraft:biome" | ||
} | ||
] | ||
} |
106 changes: 106 additions & 0 deletions
106
src/test/java/net/minecraftforge/debug/gameplay/data/DatapackBuiltinEntriesProviderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/* | ||
* Copyright (c) Forge Development LLC and contributors | ||
* SPDX-License-Identifier: LGPL-2.1-only | ||
*/ | ||
|
||
package net.minecraftforge.debug.gameplay.data; | ||
|
||
import net.minecraft.DetectedVersion; | ||
import net.minecraft.core.*; | ||
import net.minecraft.core.registries.Registries; | ||
import net.minecraft.data.metadata.PackMetadataGenerator; | ||
import net.minecraft.data.worldgen.BootstapContext; | ||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.resources.ResourceKey; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.server.packs.PackType; | ||
import net.minecraft.server.packs.metadata.pack.PackMetadataSection; | ||
import net.minecraft.tags.BiomeTags; | ||
import net.minecraft.tags.BlockTags; | ||
import net.minecraft.world.level.biome.Biome; | ||
import net.minecraft.world.level.block.Blocks; | ||
import net.minecraft.world.level.levelgen.GenerationStep; | ||
import net.minecraft.world.level.levelgen.VerticalAnchor; | ||
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature; | ||
import net.minecraft.world.level.levelgen.feature.Feature; | ||
import net.minecraft.world.level.levelgen.feature.configurations.OreConfiguration; | ||
import net.minecraft.world.level.levelgen.placement.*; | ||
import net.minecraft.world.level.levelgen.structure.templatesystem.TagMatchTest; | ||
import net.minecraftforge.common.data.DatapackBuiltinEntriesProvider; | ||
import net.minecraftforge.common.world.BiomeModifier; | ||
import net.minecraftforge.common.world.ForgeBiomeModifiers; | ||
import net.minecraftforge.data.event.GatherDataEvent; | ||
import net.minecraftforge.eventbus.api.SubscribeEvent; | ||
import net.minecraftforge.fml.common.Mod; | ||
import net.minecraftforge.registries.ForgeRegistries; | ||
import net.minecraftforge.test.BaseTestMod; | ||
|
||
import java.util.*; | ||
import java.util.function.Supplier; | ||
|
||
@Mod(DatapackBuiltinEntriesProviderTest.MOD_ID) | ||
public class DatapackBuiltinEntriesProviderTest extends BaseTestMod { | ||
|
||
public static final String MOD_ID = "datapack_builtin_entries_provider_test"; | ||
// Vanilla registry entries | ||
public static final ResourceKey<ConfiguredFeature<?, ?>> MOSSY_STONE_FEATURE = ResourceKey.create(Registries.CONFIGURED_FEATURE, new ResourceLocation(MOD_ID, "mossy_stone")); | ||
public static final ResourceKey<PlacedFeature> MOSSY_STONE_PLACEMENT = ResourceKey.create(Registries.PLACED_FEATURE, new ResourceLocation(MOD_ID, "mossy_stone")); | ||
// Forge registry entries | ||
public static final ResourceKey<BiomeModifier> MOSSY_STONE_MODIFIER = ResourceKey.create(ForgeRegistries.Keys.BIOME_MODIFIERS, new ResourceLocation(MOD_ID, "mossy_stone_modifier")); | ||
// The ore targets | ||
public static final Supplier<List<OreConfiguration.TargetBlockState>> MOSSY_STONE_TARGETS = () -> { | ||
return List.of( | ||
OreConfiguration.target(new TagMatchTest(BlockTags.STONE_ORE_REPLACEABLES), Blocks.MOSSY_COBBLESTONE.defaultBlockState()), | ||
OreConfiguration.target(new TagMatchTest(BlockTags.DEEPSLATE_ORE_REPLACEABLES), Blocks.MOSSY_COBBLESTONE.defaultBlockState()) | ||
); | ||
}; | ||
|
||
@SubscribeEvent | ||
public void onDataGen(GatherDataEvent event) { | ||
var gen = event.getGenerator(); | ||
var packOutput = gen.getPackOutput(); | ||
/* Adds the DataPackBuiltinEntriesProvider to the data generator | ||
* If the registry is not correctly patched (it does only include the vanilla registries), the provider will fail with an exception | ||
* Reason: The RegistrySetBuilder creates a full patched registry including a lookup for all registries | ||
* For the lookup a cloner is needed, which is not available for forge registries | ||
*/ | ||
gen.addProvider(event.includeServer(), new DatapackBuiltinEntriesProvider(packOutput, event.getLookupProvider(), this.createProvider(), Set.of(MOD_ID))); | ||
} | ||
|
||
// Creates the registry builder for 2 vanilla and 1 forge registry | ||
private RegistrySetBuilder createProvider() { | ||
var builder = new RegistrySetBuilder(); | ||
builder.add(Registries.CONFIGURED_FEATURE, c -> this.createFeature(c)); | ||
builder.add(Registries.PLACED_FEATURE, this::createPlacement); | ||
builder.add(ForgeRegistries.Keys.BIOME_MODIFIERS, this::createModifier); | ||
return builder; | ||
} | ||
|
||
// Registers the mossy stone feature | ||
private void createFeature(BootstapContext<ConfiguredFeature<?, ?>> context) { | ||
context.register(MOSSY_STONE_FEATURE, new ConfiguredFeature<>( | ||
Feature.ORE, | ||
new OreConfiguration(MOSSY_STONE_TARGETS.get(), 5) | ||
)); | ||
} | ||
|
||
// Registers the mossy stone placement | ||
private void createPlacement(BootstapContext<PlacedFeature> context) { | ||
HolderGetter<ConfiguredFeature<?, ?>> featureRegistry = context.lookup(Registries.CONFIGURED_FEATURE); | ||
context.register(MOSSY_STONE_PLACEMENT, new PlacedFeature( | ||
featureRegistry.getOrThrow(MOSSY_STONE_FEATURE), | ||
List.of(CountPlacement.of(8), InSquarePlacement.spread(), HeightRangePlacement.uniform(VerticalAnchor.absolute(-64), VerticalAnchor.absolute(64)), BiomeFilter.biome()) | ||
)); | ||
} | ||
|
||
// Registers the mossy stone biome modifier | ||
private void createModifier(BootstapContext<BiomeModifier> context) { | ||
HolderGetter<Biome> biomeRegistry = context.lookup(Registries.BIOME); | ||
HolderGetter<PlacedFeature> placementRegistry = context.lookup(Registries.PLACED_FEATURE); | ||
context.register(MOSSY_STONE_MODIFIER, new ForgeBiomeModifiers.AddFeaturesBiomeModifier( | ||
biomeRegistry.getOrThrow(BiomeTags.IS_OVERWORLD), | ||
HolderSet.direct(placementRegistry.getOrThrow(MOSSY_STONE_PLACEMENT)), | ||
GenerationStep.Decoration.UNDERGROUND_ORES | ||
)); | ||
} | ||
} |