Skip to content

Commit

Permalink
Merge branch '1.19a' into 1.19b
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/data/java/juuxel/woodsandmires/data/builtin/WamBiomes.java
  • Loading branch information
Juuxel committed Jul 15, 2023
2 parents cf00679 + d5629e3 commit a58c8d6
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 11 deletions.
26 changes: 18 additions & 8 deletions src/data/java/juuxel/woodsandmires/data/builtin/WamBiomes.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,9 @@ private static int getSkyColor(float temperature) {
return OverworldBiomeCreator.getSkyColor(temperature);
}

private Biome pineForest(float temperature,
Consumer<GenerationSettings.LookupBackedBuilder> earlyGenerationSettingsConfigurator,
Consumer<GenerationSettings.LookupBackedBuilder> generationSettingsConfigurator) {
private Biome pineForest(float temperature, Consumer<WamGenerationSettingsBuilder> generationSettingsConfigurator) {
GenerationSettings generationSettings = generationSettings(builder -> {
OverworldBiomeCreator.addBasicFeatures(builder);
earlyGenerationSettingsConfigurator.accept(builder);
DefaultBiomeFeatures.addForestFlowers(builder);
DefaultBiomeFeatures.addLargeFerns(builder);
DefaultBiomeFeatures.addDefaultOres(builder);
Expand Down Expand Up @@ -111,31 +108,44 @@ private Biome pineForest(float temperature,

private Biome pineForest() {
// noinspection CodeBlock2Expr
return pineForest(0.6f, builder -> {}, builder -> {
return pineForest(0.6f, builder -> {
builder.feature(GenerationStep.Feature.VEGETAL_DECORATION, WamPlacedFeatureKeys.FOREST_PINE);
});
}

private Biome snowyPineForest() {
// noinspection CodeBlock2Expr
return pineForest(0f, builder -> {}, builder -> {
return pineForest(0f, builder -> {
builder.feature(GenerationStep.Feature.VEGETAL_DECORATION, WamPlacedFeatureKeys.SNOWY_PINE_FOREST_TREES);
});
}

private Biome oldGrowthPineForest() {
return pineForest(0.4f, builder -> {}, builder -> {
return pineForest(0.4f, builder -> {
builder.feature(GenerationStep.Feature.VEGETAL_DECORATION, WamPlacedFeatureKeys.OLD_GROWTH_PINE_FOREST_TREES);
});
}

private Biome lushPineForest() {
return pineForest(0.6f, builder -> {
DefaultBiomeFeatures.addSavannaTallGrass(builder);
}, builder -> {
builder.feature(GenerationStep.Feature.VEGETAL_DECORATION, WamPlacedFeatureKeys.LUSH_PINE_FOREST_TREES);
builder.feature(GenerationStep.Feature.VEGETAL_DECORATION, WamPlacedFeatureKeys.LUSH_PINE_FOREST_FLOWERS);
DefaultBiomeFeatures.addExtraDefaultFlowers(builder);

// Required to keep vanilla order for savanna tall grass
builder.addOrdering(
GenerationStep.Feature.VEGETAL_DECORATION,
VegetationPlacedFeatures.PATCH_TALL_GRASS,
VegetationPlacedFeatures.FOREST_FLOWERS
);

// https://github.com/Juuxel/WoodsAndMires/issues/14
builder.addOrdering(
GenerationStep.Feature.VEGETAL_DECORATION,
VegetationPlacedFeatures.PATCH_GRASS_FOREST,
VegetationPlacedFeatures.FLOWER_WARM
);
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package juuxel.woodsandmires.data.builtin;

import juuxel.woodsandmires.data.mixin.GenerationSettingsBuilderAccessor;
import net.minecraft.util.TopologicalSorts;
import net.minecraft.util.registry.RegistryEntry;
import net.minecraft.world.biome.GenerationSettings;
import net.minecraft.world.gen.GenerationStep;
import net.minecraft.world.gen.carver.ConfiguredCarver;
import net.minecraft.world.gen.feature.PlacedFeature;

import java.util.EnumMap;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;

public class WamGenerationSettingsBuilder extends GenerationSettings.Builder {
// step -> before -> [after]
private final Map<GenerationStep.Feature, Map<RegistryEntry<PlacedFeature>, Set<RegistryEntry<PlacedFeature>>>> orderingsByStep =
new EnumMap<>(GenerationStep.Feature.class);

@Override
public WamGenerationSettingsBuilder feature(GenerationStep.Feature featureStep, RegistryEntry<PlacedFeature> feature) {
super.feature(featureStep, feature);
return this;
}

@Override
public WamGenerationSettingsBuilder feature(int stepIndex, RegistryEntry<PlacedFeature> featureEntry) {
super.feature(stepIndex, featureEntry);
return this;
}

@Override
public WamGenerationSettingsBuilder carver(GenerationStep.Carver carverStep, RegistryEntry<? extends ConfiguredCarver<?>> carver) {
super.carver(carverStep, carver);
return this;
}

public WamGenerationSettingsBuilder addOrdering(GenerationStep.Feature step, RegistryEntry<PlacedFeature> before, RegistryEntry<PlacedFeature> after) {
orderingsByStep.computeIfAbsent(step, s -> new HashMap<>())
.computeIfAbsent(before, entry -> new HashSet<>())
.add(after);
return this;
}

@Override
public GenerationSettings build() {
order();
return super.build();
}

private void order() {
orderingsByStep.forEach((step, orderings) -> {
List<RegistryEntry<PlacedFeature>> features = ((GenerationSettingsBuilderAccessor) this)
.getFeatures()
.get(step.ordinal());

Set<RegistryEntry<PlacedFeature>> visited = new HashSet<>();
Set<RegistryEntry<PlacedFeature>> visiting = new HashSet<>();
Consumer<RegistryEntry<PlacedFeature>> noopConsumer = x -> {};

// Iterate over all constraints
for (var before : orderings.keySet()) {
// Check that the ordering is consistent
if (TopologicalSorts.sort(orderings, visited, visiting, noopConsumer, before)) {
throw new IllegalStateException("Found inconsistent order in step " + step + "; cycle starting from " + before);
}
visited.clear();
visiting.clear();

// Add the order
// Note: we won't use the mc toposort here since we want to keep the general order.
// It's still useful for checking for cycles.
for (var after : orderings.get(before)) {
int beforeIndex = features.indexOf(before);
int afterIndex = features.indexOf(after);
if (beforeIndex <= afterIndex) continue;

// Move "after" to be after the "before" entry
features.add(beforeIndex + 1, after);
features.remove(afterIndex);
}
}
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package juuxel.woodsandmires.data.mixin;

import net.minecraft.util.registry.RegistryEntry;
import net.minecraft.world.biome.GenerationSettings;
import net.minecraft.world.gen.feature.PlacedFeature;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

import java.util.List;

@Mixin(GenerationSettings.Builder.class)
public interface GenerationSettingsBuilderAccessor {
@Accessor
List<List<RegistryEntry<PlacedFeature>>> getFeatures();
}
1 change: 1 addition & 0 deletions src/data/resources/mixins.woods_and_mires_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"compatibilityLevel": "JAVA_17",
"mixins": [
"DataProviderMixin",
"GenerationSettingsBuilderAccessor",
"RecipeProviderMixin"
],
"injectors": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,16 @@
],
[
"minecraft:glow_lichen",
"minecraft:patch_tall_grass",
"minecraft:forest_flowers",
"minecraft:patch_large_fern",
"woods_and_mires:fallen_pine",
"minecraft:flower_default",
"woods_and_mires:pine_forest_heather_patch",
"minecraft:patch_tall_grass",
"minecraft:forest_flowers",
"woods_and_mires:lush_pine_forest_trees",
"woods_and_mires:lush_pine_forest_flowers",
"minecraft:flower_warm",
"minecraft:patch_grass_forest",
"minecraft:flower_warm",
"minecraft:brown_mushroom_normal",
"minecraft:red_mushroom_normal",
"minecraft:patch_sugar_cane",
Expand Down

0 comments on commit a58c8d6

Please sign in to comment.