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/WamBlockLootTableProvider.java
#	src/data/java/juuxel/woodsandmires/data/WamRecipeProvider.java
#	src/data/java/juuxel/woodsandmires/data/builtin/WamBiomes.java
#	src/data/java/juuxel/woodsandmires/data/builtin/WamGenerationSettingsBuilder.java
#	src/data/java/juuxel/woodsandmires/data/mixin/GenerationSettingsBuilderAccessor.java
#	src/main/java/juuxel/woodsandmires/item/WamItems.java
#	src/main/java/juuxel/woodsandmires/tree/AgedTrunkTreeDecorator.java
#	src/main/java/juuxel/woodsandmires/tree/BranchTreeDecorator.java
#	src/main/java/juuxel/woodsandmires/tree/ReplaceTrunkTreeDecorator.java
#	src/main/resources/woods_and_mires.accesswidener
  • Loading branch information
Juuxel committed Jul 21, 2023
2 parents 211222c + 93cbc4a commit 686f944
Show file tree
Hide file tree
Showing 36 changed files with 312 additions and 82 deletions.
6 changes: 4 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id 'fabric-loom' version '1.2-SNAPSHOT'
id 'io.github.juuxel.loom-quiltflower' version '1.10.0'
id 'fabric-loom' version '1.3-SNAPSHOT'
id 'io.github.juuxel.loom-vineflower' version '1.11.0'
id 'maven-publish'
}

Expand Down Expand Up @@ -72,6 +72,8 @@ dependencies {
implementation include("com.typesafe:config:$project.typesafe_config_version")

dataImplementation sourceSets.main.output
// Used for sorting features in the data generator
dataImplementation "org.jgrapht:jgrapht-core:$project.jgrapht_version"
}

processResources {
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ archives_base_name = WoodsAndMires
fabric_version = 0.85.0+1.19.4
terrablender_version = 1.19.4-2.2.0.154
typesafe_config_version = 1.4.2
jgrapht_version = 1.5.2
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package juuxel.woodsandmires.data;

import juuxel.woodsandmires.block.WamBlocks;
import juuxel.woodsandmires.item.WamItems;
import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput;
import net.fabricmc.fabric.api.datagen.v1.provider.FabricBlockLootTableProvider;
import net.minecraft.block.TallPlantBlock;
Expand Down Expand Up @@ -31,7 +32,15 @@ public void generate() {
addDrop(WamBlocks.PINE_SIGN);
addDrop(WamBlocks.PINE_DOOR, this::doorDrops);
addDrop(WamBlocks.PINE_TRAPDOOR);
addDrop(WamBlocks.PINE_LEAVES, block -> leavesDrops(block, WamBlocks.PINE_SAPLING, SAPLING_DROP_CHANCE));
addDrop(WamBlocks.PINE_LEAVES,
block -> leavesDrops(block, WamBlocks.PINE_SAPLING, SAPLING_DROP_CHANCE)
.pool(addSurvivesExplosionCondition(WamItems.PINE_CONE, LootPool.builder()
.conditionally(WITHOUT_SILK_TOUCH_NOR_SHEARS)
.with(ItemEntry.builder(WamItems.PINE_CONE)
.apply(SetCountLootFunction.builder(BinomialLootNumberProvider.create(3, 0.04f)))
)
))
);
addDrop(WamBlocks.PINE_SAPLING);
addPottedPlantDrops(WamBlocks.POTTED_PINE_SAPLING);
addDrop(WamBlocks.PINE_WOOD);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ protected void configure(RegistryWrapper.WrapperLookup arg) {
.add(WamBlocks.PINE_SNAG_LOG, WamBlocks.PINE_SNAG_WOOD);

// Common tags
builder(CommonItemTags.HONEY)
.add(WamItems.PINE_CONE_JAM);
builder(CommonItemTags.JAMS)
.add(WamItems.PINE_CONE_JAM);
builder(CommonItemTags.PINE_CONES)
.add(WamItems.PINE_CONE);
builder(CommonItemTags.SUGAR)
.add(Items.SUGAR);
builder(CommonItemTags.WOODEN_CHESTS)
.add(Items.CHEST, Items.TRAPPED_CHEST);
builder(CommonItemTags.WOODEN_RODS)
Expand Down
10 changes: 10 additions & 0 deletions src/data/java/juuxel/woodsandmires/data/WamRecipeProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import juuxel.woodsandmires.WoodsAndMires;
import juuxel.woodsandmires.block.WamBlocks;
import juuxel.woodsandmires.data.builtin.CommonItemTags;
import juuxel.woodsandmires.item.WamItemTags;
import juuxel.woodsandmires.item.WamItems;
import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator;
Expand All @@ -13,6 +14,7 @@
import net.minecraft.data.server.recipe.ShapelessRecipeJsonBuilder;
import net.minecraft.item.ItemConvertible;
import net.minecraft.item.Items;
import net.minecraft.recipe.Ingredient;
import net.minecraft.recipe.book.RecipeCategory;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -58,6 +60,14 @@ public void generate(Consumer<RecipeJsonProvider> exporter) {
offerShapelessRecipe(exporter, Items.MAGENTA_DYE, WamBlocks.FIREWEED, "magenta_dye", 2);
offerShapelessRecipe(exporter, Items.PINK_DYE, WamBlocks.HEATHER, "pink_dye", 1);
offerShapelessRecipe(exporter, Items.YELLOW_DYE, WamBlocks.TANSY, "yellow_dye", 1);

// Other
ShapelessRecipeJsonBuilder.create(WamItems.PINE_CONE_JAM)
.input(Items.GLASS_BOTTLE)
.input(Ingredient.fromTag(CommonItemTags.PINE_CONES), 2)
.input(CommonItemTags.SUGAR)
.criterion(hasItem(WamItems.PINE_CONE), conditionsFromItem(WamItems.PINE_CONE))
.offerTo(exporter);
}

public static void offerShapelessRecipe(Consumer<RecipeJsonProvider> exporter, ItemConvertible output, ItemConvertible input, @Nullable String group, int outputCount) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
import net.minecraft.util.Identifier;

public final class CommonItemTags {
public static final TagKey<Item> HONEY = of("honey");
public static final TagKey<Item> JAMS = of("jams");
public static final TagKey<Item> PINE_CONES = of("pine_cones");
public static final TagKey<Item> SUGAR = of("sugar");
public static final TagKey<Item> WOODEN_CHESTS = of("wooden_chests");
public static final TagKey<Item> WOODEN_RODS = of("wooden_rods");

Expand Down
49 changes: 41 additions & 8 deletions src/data/java/juuxel/woodsandmires/data/builtin/WamBiomes.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
import net.minecraft.world.gen.feature.DefaultBiomeFeatures;
import net.minecraft.world.gen.feature.PlacedFeature;
import net.minecraft.world.gen.feature.VegetationPlacedFeatures;
import org.jgrapht.graph.DefaultEdge;
import org.jgrapht.graph.DirectedAcyclicGraph;
import org.jgrapht.graph.GraphCycleProhibitedException;

import java.util.function.Consumer;

Expand All @@ -27,9 +30,12 @@ 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 =
new DirectedAcyclicGraph<>(DefaultEdge.class);

private WamBiomes(Registerable<Biome> registerable) {
this.registerable = registerable;
initGraph();
}

public static void register(Registerable<Biome> registerable) {
Expand All @@ -47,8 +53,42 @@ private void registerAll() {
register(WamBiomeKeys.PINY_GROVE, pinyGrove());
}

private static void initGraph() {
for (var biome : BuiltinRegistries.BIOME) {
addBiomeToGraph(biome);
}
}

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

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

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

try {
FEATURE_GRAPH.addEdge(before, after);
} catch (GraphCycleProhibitedException e) {
throw new IllegalStateException("Feature order cycle found between " + before.getKey() + " and " + after.getKey(), e);
}

before = after;
}
}
}

private void register(RegistryKey<Biome> key, Biome biome) {
registerable.register(key, biome);

try {
addBiomeToGraph(biome);
} catch (Exception e) {
throw new IllegalStateException(e.getMessage() + " [biome=" + key.getValue() + "]", e);
}
}

private static int getSkyColor(float temperature) {
Expand Down Expand Up @@ -133,13 +173,6 @@ private Biome lushPineForest() {
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,
Expand Down Expand Up @@ -280,7 +313,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();
return builder.build(FEATURE_GRAPH);
}

private static SpawnSettings spawnSettings(Consumer<SpawnSettings.Builder> configurator) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
package juuxel.woodsandmires.data.builtin;

import juuxel.woodsandmires.data.mixin.GenerationSettingsBuilderAccessor;
import net.minecraft.registry.RegistryEntryLookup;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.util.TopologicalSorts;
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 org.jgrapht.Graphs;
import org.jgrapht.graph.DefaultEdge;
import org.jgrapht.graph.DirectedAcyclicGraph;

import java.util.ArrayList;
import java.util.Comparator;
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.LookupBackedBuilder {
// step -> before -> [after]
Expand All @@ -36,44 +37,41 @@ public WamGenerationSettingsBuilder addOrdering(GenerationStep.Feature step, Reg
return this;
}

@Deprecated
@Override
public GenerationSettings build() {
order();
throw new UnsupportedOperationException("Use build(DirectedAcyclicGraph) instead");
}

public GenerationSettings build(DirectedAcyclicGraph<RegistryEntry<PlacedFeature>, DefaultEdge> globalGraph) {
order(globalGraph);
return super.build();
}

private void order() {
orderingsByStep.forEach((step, orderings) -> {
List<RegistryEntry<PlacedFeature>> features = ((GenerationSettingsBuilderAccessor) this)
.getIndexedFeaturesList()
.get(step.ordinal());
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);
var localGraph = new DirectedAcyclicGraph<RegistryEntry<PlacedFeature>, DefaultEdge>(DefaultEdge.class);
Graphs.addGraph(localGraph, globalGraph);

Set<RegistryEntry<PlacedFeature>> visited = new HashSet<>();
Set<RegistryEntry<PlacedFeature>> visiting = new HashSet<>();
Consumer<RegistryEntry<PlacedFeature>> noopConsumer = x -> {};
for (var feature : features) {
localGraph.addVertex(feature);
}

// 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);
var step = steps[i];
orderingsByStep.getOrDefault(step, Map.of()).forEach((before, allAfter) -> {
for (var after : allAfter) {
localGraph.addEdge(before, after);
}
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);
}
var orderProvider = new ArrayList<RegistryEntry<PlacedFeature>>(localGraph.vertexSet().size());
for (var feature : localGraph) {
orderProvider.add(feature);
}
});

features.sort(Comparator.comparingInt(orderProvider::indexOf));
}
}
}

This file was deleted.

1 change: 0 additions & 1 deletion src/data/resources/mixins.woods_and_mires_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"compatibilityLevel": "JAVA_17",
"mixins": [
"DataProviderMixin",
"GenerationSettingsBuilderAccessor",
"RecipeProviderMixin"
],
"injectors": {
Expand Down
6 changes: 6 additions & 0 deletions src/generated/resources/data/c/tags/items/honey.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"replace": false,
"values": [
"woods_and_mires:pine_cone_jam"
]
}
6 changes: 6 additions & 0 deletions src/generated/resources/data/c/tags/items/jams.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"replace": false,
"values": [
"woods_and_mires:pine_cone_jam"
]
}
6 changes: 6 additions & 0 deletions src/generated/resources/data/c/tags/items/pine_cones.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"replace": false,
"values": [
"woods_and_mires:pine_cone"
]
}
6 changes: 6 additions & 0 deletions src/generated/resources/data/c/tags/items/sugar.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"replace": false,
"values": [
"minecraft:sugar"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"parent": "minecraft:recipes/root",
"criteria": {
"has_pine_cone": {
"conditions": {
"items": [
{
"items": [
"woods_and_mires:pine_cone"
]
}
]
},
"trigger": "minecraft:inventory_changed"
},
"has_the_recipe": {
"conditions": {
"recipe": "woods_and_mires:pine_cone_jam"
},
"trigger": "minecraft:recipe_unlocked"
}
},
"requirements": [
[
"has_pine_cone",
"has_the_recipe"
]
],
"rewards": {
"recipes": [
"woods_and_mires:pine_cone_jam"
]
}
}
Loading

0 comments on commit 686f944

Please sign in to comment.