Skip to content

Commit

Permalink
Port previous changes to 1.19.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Juuxel committed Jul 21, 2023
1 parent 686f944 commit 879fc00
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import juuxel.woodsandmires.data.builtin.CommonItemTags;
import juuxel.woodsandmires.item.WamItemTags;
import juuxel.woodsandmires.item.WamItems;
import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator;
import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput;
import net.fabricmc.fabric.api.datagen.v1.provider.FabricRecipeProvider;
import net.minecraft.data.family.BlockFamilies;
Expand Down Expand Up @@ -62,7 +61,7 @@ public void generate(Consumer<RecipeJsonProvider> exporter) {
offerShapelessRecipe(exporter, Items.YELLOW_DYE, WamBlocks.TANSY, "yellow_dye", 1);

// Other
ShapelessRecipeJsonBuilder.create(WamItems.PINE_CONE_JAM)
ShapelessRecipeJsonBuilder.create(RecipeCategory.FOOD, WamItems.PINE_CONE_JAM)
.input(Items.GLASS_BOTTLE)
.input(Ingredient.fromTag(CommonItemTags.PINE_CONES), 2)
.input(CommonItemTags.SUGAR)
Expand Down
33 changes: 24 additions & 9 deletions src/data/java/juuxel/woodsandmires/data/builtin/WamBiomes.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
package juuxel.woodsandmires.data.builtin;

import com.mojang.serialization.Lifecycle;
import juuxel.woodsandmires.biome.WamBiomeKeys;
import juuxel.woodsandmires.feature.WamPlacedFeatureKeys;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.SpawnGroup;
import net.minecraft.registry.Registerable;
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryEntryLookup;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.sound.BiomeMoodSound;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.BiomeEffects;
import net.minecraft.world.biome.BuiltinBiomes;
import net.minecraft.world.biome.GenerationSettings;
import net.minecraft.world.biome.OverworldBiomeCreator;
import net.minecraft.world.biome.SpawnSettings;
Expand All @@ -30,7 +34,7 @@ public final class WamBiomes {
private static final float WARM_BIOME_MINIMUM_TEMPERATURE = 0.15f;

private final Registerable<Biome> registerable;
private static final DirectedAcyclicGraph<RegistryEntry<PlacedFeature>, DefaultEdge> FEATURE_GRAPH =
private final DirectedAcyclicGraph<RegistryEntry<PlacedFeature>, DefaultEdge> featureGraph =
new DirectedAcyclicGraph<>(DefaultEdge.class);

private WamBiomes(Registerable<Biome> registerable) {
Expand All @@ -53,25 +57,36 @@ private void registerAll() {
register(WamBiomeKeys.PINY_GROVE, pinyGrove());
}

private static void initGraph() {
for (var biome : BuiltinRegistries.BIOME) {
addBiomeToGraph(biome);
private void initGraph() {
record CapturingRegisterable<T>(Registerable<?> parent, Consumer<T> sink) implements Registerable<T> {
@Override
public RegistryEntry.Reference<T> register(RegistryKey<T> key, T value, Lifecycle lifecycle) {
sink.accept(value);
return null;
}

@Override
public <S> RegistryEntryLookup<S> getRegistryLookup(RegistryKey<? extends Registry<? extends S>> registryRef) {
return parent.getRegistryLookup(registryRef);
}
}

BuiltinBiomes.bootstrap(new CapturingRegisterable<>(registerable, this::addBiomeToGraph));
}

private static void addBiomeToGraph(Biome biome) {
private void addBiomeToGraph(Biome biome) {
for (var features : biome.getGenerationSettings().getFeatures()) {
if (features.size() == 0) continue;

var before = features.get(0);
FEATURE_GRAPH.addVertex(before);
featureGraph.addVertex(before);

for (int i = 1; i < features.size(); i++) {
var after = features.get(i);
FEATURE_GRAPH.addVertex(after);
featureGraph.addVertex(after);

try {
FEATURE_GRAPH.addEdge(before, after);
featureGraph.addEdge(before, after);
} catch (GraphCycleProhibitedException e) {
throw new IllegalStateException("Feature order cycle found between " + before.getKey() + " and " + after.getKey(), e);
}
Expand Down Expand Up @@ -313,7 +328,7 @@ private GenerationSettings generationSettings(Consumer<WamGenerationSettingsBuil
RegistryEntryLookup<ConfiguredCarver<?>> configuredCarvers = registerable.getRegistryLookup(RegistryKeys.CONFIGURED_CARVER);
WamGenerationSettingsBuilder builder = new WamGenerationSettingsBuilder(placedFeatures, configuredCarvers);
configurator.accept(builder);
return builder.build(FEATURE_GRAPH);
return builder.build(featureGraph);
}

private static SpawnSettings spawnSettings(Consumer<SpawnSettings.Builder> configurator) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public GenerationSettings build(DirectedAcyclicGraph<RegistryEntry<PlacedFeature

private void order(DirectedAcyclicGraph<RegistryEntry<PlacedFeature>, DefaultEdge> globalGraph) {
var steps = GenerationStep.Feature.values();
for (int i = 0; i < this.features.size(); i++) {
var features = this.features.get(i);
for (int i = 0; i < this.indexedFeaturesList.size(); i++) {
var features = this.indexedFeaturesList.get(i);
var localGraph = new DirectedAcyclicGraph<RegistryEntry<PlacedFeature>, DefaultEdge>(DefaultEdge.class);
Graphs.addGraph(localGraph, globalGraph);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"type": "minecraft:crafting_shapeless",
"category": "misc",
"ingredients": [
{
"item": "minecraft:glass_bottle"
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/woods_and_mires.accesswidener
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ accessible method net/minecraft/world/gen/treedecorator/TreeDecoratorType <init>
accessible method net/minecraft/world/gen/feature/VegetationConfiguredFeatures createRandomPatchFeatureConfig (Lnet/minecraft/world/gen/stateprovider/BlockStateProvider;I)Lnet/minecraft/world/gen/feature/RandomPatchFeatureConfig;

# Data generation
accessible field net/minecraft/data/server/BlockLootTableGenerator WITHOUT_SILK_TOUCH_NOR_SHEARS Lnet/minecraft/loot/condition/LootCondition$Builder;
accessible field net/minecraft/world/biome/GenerationSettings$Builder features Ljava/util/List;
accessible field net/minecraft/data/server/loottable/BlockLootTableGenerator WITHOUT_SILK_TOUCH_NOR_SHEARS Lnet/minecraft/loot/condition/LootCondition$Builder;
accessible field net/minecraft/world/biome/GenerationSettings$Builder indexedFeaturesList Ljava/util/List;

# Rendering
accessible field net/minecraft/client/render/entity/BoatEntityRenderer texturesAndModels Ljava/util/Map;
Expand Down

0 comments on commit 879fc00

Please sign in to comment.