From 3b4639d5dafb693e44acfffa8e300e8daec86722 Mon Sep 17 00:00:00 2001 From: Sollace Date: Wed, 20 Mar 2024 19:40:31 +0000 Subject: [PATCH] Move seasons data to datagen and add growth speeds for bananas, palm trees, and golden oak trees --- .../unicopia/datagen/Datagen.java | 2 + .../providers/SeasonsGrowthRatesProvider.java | 93 +++++++++++++++++++ .../seasons/crop/green_apple_leaves.json | 6 -- .../seasons/crop/green_apple_sapling.json | 6 -- .../seasons/crop/green_apple_sprout.json | 6 -- .../unicopia/seasons/crop/mango_leaves.json | 6 -- .../unicopia/seasons/crop/mango_sapling.json | 6 -- .../data/unicopia/seasons/crop/oats.json | 6 -- .../unicopia/seasons/crop/oats_crown.json | 6 -- .../data/unicopia/seasons/crop/oats_stem.json | 6 -- .../data/unicopia/seasons/crop/rocks.json | 6 -- .../seasons/crop/sour_apple_leaves.json | 6 -- .../seasons/crop/sour_apple_sapling.json | 6 -- .../seasons/crop/sour_apple_sprout.json | 6 -- .../seasons/crop/sweet_apple_leaves.json | 6 -- .../seasons/crop/sweet_apple_sapling.json | 6 -- .../seasons/crop/sweet_apple_sprout.json | 6 -- 17 files changed, 95 insertions(+), 90 deletions(-) create mode 100644 src/main/java/com/minelittlepony/unicopia/datagen/providers/SeasonsGrowthRatesProvider.java delete mode 100644 src/main/resources/data/unicopia/seasons/crop/green_apple_leaves.json delete mode 100644 src/main/resources/data/unicopia/seasons/crop/green_apple_sapling.json delete mode 100644 src/main/resources/data/unicopia/seasons/crop/green_apple_sprout.json delete mode 100644 src/main/resources/data/unicopia/seasons/crop/mango_leaves.json delete mode 100644 src/main/resources/data/unicopia/seasons/crop/mango_sapling.json delete mode 100644 src/main/resources/data/unicopia/seasons/crop/oats.json delete mode 100644 src/main/resources/data/unicopia/seasons/crop/oats_crown.json delete mode 100644 src/main/resources/data/unicopia/seasons/crop/oats_stem.json delete mode 100644 src/main/resources/data/unicopia/seasons/crop/rocks.json delete mode 100644 src/main/resources/data/unicopia/seasons/crop/sour_apple_leaves.json delete mode 100644 src/main/resources/data/unicopia/seasons/crop/sour_apple_sapling.json delete mode 100644 src/main/resources/data/unicopia/seasons/crop/sour_apple_sprout.json delete mode 100644 src/main/resources/data/unicopia/seasons/crop/sweet_apple_leaves.json delete mode 100644 src/main/resources/data/unicopia/seasons/crop/sweet_apple_sapling.json delete mode 100644 src/main/resources/data/unicopia/seasons/crop/sweet_apple_sprout.json diff --git a/src/main/java/com/minelittlepony/unicopia/datagen/Datagen.java b/src/main/java/com/minelittlepony/unicopia/datagen/Datagen.java index 9cfcbe8b..24f1f53b 100644 --- a/src/main/java/com/minelittlepony/unicopia/datagen/Datagen.java +++ b/src/main/java/com/minelittlepony/unicopia/datagen/Datagen.java @@ -3,6 +3,7 @@ package com.minelittlepony.unicopia.datagen; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import com.minelittlepony.unicopia.datagen.providers.SeasonsGrowthRatesProvider; import com.minelittlepony.unicopia.datagen.providers.UBlockTagProvider; import com.minelittlepony.unicopia.datagen.providers.UItemTagProvider; import com.minelittlepony.unicopia.datagen.providers.UModelProvider; @@ -36,6 +37,7 @@ public class Datagen implements DataGeneratorEntrypoint { pack.addProvider(UBlockLootTableProvider::new); pack.addProvider(UBlockAdditionsLootTableProvider::new); pack.addProvider(UChestAdditionsLootTableProvider::new); + pack.addProvider(SeasonsGrowthRatesProvider::new); } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/datagen/providers/SeasonsGrowthRatesProvider.java b/src/main/java/com/minelittlepony/unicopia/datagen/providers/SeasonsGrowthRatesProvider.java new file mode 100644 index 00000000..186c0685 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/datagen/providers/SeasonsGrowthRatesProvider.java @@ -0,0 +1,93 @@ +package com.minelittlepony.unicopia.datagen.providers; + +import java.util.concurrent.CompletableFuture; +import java.util.function.BiConsumer; + +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.minelittlepony.unicopia.block.UBlocks; +import com.minelittlepony.unicopia.datagen.DataCollector; +import com.minelittlepony.unicopia.server.world.UTreeGen; + +import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput; +import net.minecraft.block.Block; +import net.minecraft.data.DataOutput; +import net.minecraft.data.DataOutput.PathResolver; +import net.minecraft.registry.Registries; +import net.minecraft.data.DataProvider; +import net.minecraft.data.DataWriter; + +public class SeasonsGrowthRatesProvider implements DataProvider { + + private final PathResolver pathResolver; + + public SeasonsGrowthRatesProvider(FabricDataOutput output) { + this.pathResolver = output.getResolver(DataOutput.OutputType.DATA_PACK, "seasons/crop"); + } + + @Override + public String getName() { + return "Seasons Growth Rates"; + } + + @Override + public CompletableFuture run(DataWriter writer) { + DataCollector collectedData = new DataCollector(pathResolver); + var exporter = collectedData.prime(); + generate((block, crop) -> { + exporter.accept(Registries.BLOCK.getId(block), crop::toJson); + }); + return collectedData.upload(writer); + } + + private void generate(BiConsumer exporter) { + Crop greenApple = new Crop(0.5F, 0.6F, 1, 0); + exporter.accept(UBlocks.GREEN_APPLE_LEAVES, greenApple); + exporter.accept(UBlocks.GREEN_APPLE_SPROUT, greenApple); + exporter.accept(UTreeGen.GREEN_APPLE_TREE.sapling().get(), greenApple); + + Crop sourApple = new Crop(0.25F, 0.5F, 1, 0.5F); + exporter.accept(UBlocks.SOUR_APPLE_LEAVES, sourApple); + exporter.accept(UBlocks.SOUR_APPLE_SPROUT, sourApple); + exporter.accept(UTreeGen.SOUR_APPLE_TREE.sapling().get(), sourApple); + + Crop sweetApple = new Crop(1, 1, 0.6F, 0); + exporter.accept(UBlocks.SWEET_APPLE_LEAVES, sweetApple); + exporter.accept(UBlocks.SWEET_APPLE_SPROUT, sweetApple); + exporter.accept(UTreeGen.SWEET_APPLE_TREE.sapling().get(), sweetApple); + + Crop goldenOak = new Crop(1.5F, 1.4F, 0.6F, 0); + exporter.accept(UBlocks.GOLDEN_OAK_LEAVES, goldenOak); + exporter.accept(UBlocks.GOLDEN_OAK_SPROUT, goldenOak); + exporter.accept(UTreeGen.GOLDEN_APPLE_TREE.sapling().get(), goldenOak); + + Crop palm = new Crop(1.1F, 0.9F, 0.2F, 0); + exporter.accept(UBlocks.PALM_LEAVES, palm); + exporter.accept(UBlocks.BANANAS, palm); + exporter.accept(UTreeGen.BANANA_TREE.sapling().get(), palm); + + Crop mango = new Crop(1, 1.6F, 0.5F, 0); + exporter.accept(UBlocks.MANGO_LEAVES, mango); + exporter.accept(UTreeGen.MANGO_TREE.sapling().get(), mango); + + Crop oats = new Crop(0.6F, 1, 1, 0); + exporter.accept(UBlocks.OATS_CROWN, oats); + exporter.accept(UBlocks.OATS_STEM, oats); + exporter.accept(UBlocks.OATS, oats); + + exporter.accept(UBlocks.ROCKS, new Crop(1, 1, 1, 1)); + exporter.accept(UBlocks.PINEAPPLE, palm); + } + + record Crop(float spring, float summer, float fall, float winter) { + + JsonElement toJson() { + JsonObject json = new JsonObject(); + json.addProperty("spring", spring); + json.addProperty("summer", summer); + json.addProperty("winter", winter); + json.addProperty("fall", fall); + return json; + } + } +} diff --git a/src/main/resources/data/unicopia/seasons/crop/green_apple_leaves.json b/src/main/resources/data/unicopia/seasons/crop/green_apple_leaves.json deleted file mode 100644 index 7c87009a..00000000 --- a/src/main/resources/data/unicopia/seasons/crop/green_apple_leaves.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "spring": 0.5, - "summer": 0.6, - "fall": 1.0, - "winter": 0 -} \ No newline at end of file diff --git a/src/main/resources/data/unicopia/seasons/crop/green_apple_sapling.json b/src/main/resources/data/unicopia/seasons/crop/green_apple_sapling.json deleted file mode 100644 index 7c87009a..00000000 --- a/src/main/resources/data/unicopia/seasons/crop/green_apple_sapling.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "spring": 0.5, - "summer": 0.6, - "fall": 1.0, - "winter": 0 -} \ No newline at end of file diff --git a/src/main/resources/data/unicopia/seasons/crop/green_apple_sprout.json b/src/main/resources/data/unicopia/seasons/crop/green_apple_sprout.json deleted file mode 100644 index 7c87009a..00000000 --- a/src/main/resources/data/unicopia/seasons/crop/green_apple_sprout.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "spring": 0.5, - "summer": 0.6, - "fall": 1.0, - "winter": 0 -} \ No newline at end of file diff --git a/src/main/resources/data/unicopia/seasons/crop/mango_leaves.json b/src/main/resources/data/unicopia/seasons/crop/mango_leaves.json deleted file mode 100644 index 0197bee9..00000000 --- a/src/main/resources/data/unicopia/seasons/crop/mango_leaves.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "spring": 1.0, - "summer": 1.6, - "fall": 0.5, - "winter": 0 -} \ No newline at end of file diff --git a/src/main/resources/data/unicopia/seasons/crop/mango_sapling.json b/src/main/resources/data/unicopia/seasons/crop/mango_sapling.json deleted file mode 100644 index 0197bee9..00000000 --- a/src/main/resources/data/unicopia/seasons/crop/mango_sapling.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "spring": 1.0, - "summer": 1.6, - "fall": 0.5, - "winter": 0 -} \ No newline at end of file diff --git a/src/main/resources/data/unicopia/seasons/crop/oats.json b/src/main/resources/data/unicopia/seasons/crop/oats.json deleted file mode 100644 index 0cbd2f20..00000000 --- a/src/main/resources/data/unicopia/seasons/crop/oats.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "spring": 0.6, - "summer": 1.0, - "fall": 1.0, - "winter": 0 -} \ No newline at end of file diff --git a/src/main/resources/data/unicopia/seasons/crop/oats_crown.json b/src/main/resources/data/unicopia/seasons/crop/oats_crown.json deleted file mode 100644 index 0cbd2f20..00000000 --- a/src/main/resources/data/unicopia/seasons/crop/oats_crown.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "spring": 0.6, - "summer": 1.0, - "fall": 1.0, - "winter": 0 -} \ No newline at end of file diff --git a/src/main/resources/data/unicopia/seasons/crop/oats_stem.json b/src/main/resources/data/unicopia/seasons/crop/oats_stem.json deleted file mode 100644 index 0cbd2f20..00000000 --- a/src/main/resources/data/unicopia/seasons/crop/oats_stem.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "spring": 0.6, - "summer": 1.0, - "fall": 1.0, - "winter": 0 -} \ No newline at end of file diff --git a/src/main/resources/data/unicopia/seasons/crop/rocks.json b/src/main/resources/data/unicopia/seasons/crop/rocks.json deleted file mode 100644 index 139f30a0..00000000 --- a/src/main/resources/data/unicopia/seasons/crop/rocks.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "spring": 1.0, - "summer": 1.0, - "fall": 1.0, - "winter": 1.0 -} \ No newline at end of file diff --git a/src/main/resources/data/unicopia/seasons/crop/sour_apple_leaves.json b/src/main/resources/data/unicopia/seasons/crop/sour_apple_leaves.json deleted file mode 100644 index 8b9d321a..00000000 --- a/src/main/resources/data/unicopia/seasons/crop/sour_apple_leaves.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "spring": 0.25, - "summer": 0.5, - "fall": 1.0, - "winter": 0.5 -} \ No newline at end of file diff --git a/src/main/resources/data/unicopia/seasons/crop/sour_apple_sapling.json b/src/main/resources/data/unicopia/seasons/crop/sour_apple_sapling.json deleted file mode 100644 index 8b9d321a..00000000 --- a/src/main/resources/data/unicopia/seasons/crop/sour_apple_sapling.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "spring": 0.25, - "summer": 0.5, - "fall": 1.0, - "winter": 0.5 -} \ No newline at end of file diff --git a/src/main/resources/data/unicopia/seasons/crop/sour_apple_sprout.json b/src/main/resources/data/unicopia/seasons/crop/sour_apple_sprout.json deleted file mode 100644 index 8b9d321a..00000000 --- a/src/main/resources/data/unicopia/seasons/crop/sour_apple_sprout.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "spring": 0.25, - "summer": 0.5, - "fall": 1.0, - "winter": 0.5 -} \ No newline at end of file diff --git a/src/main/resources/data/unicopia/seasons/crop/sweet_apple_leaves.json b/src/main/resources/data/unicopia/seasons/crop/sweet_apple_leaves.json deleted file mode 100644 index 06ea5e21..00000000 --- a/src/main/resources/data/unicopia/seasons/crop/sweet_apple_leaves.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "spring": 1.0, - "summer": 1.0, - "fall": 0.6, - "winter": 0 -} \ No newline at end of file diff --git a/src/main/resources/data/unicopia/seasons/crop/sweet_apple_sapling.json b/src/main/resources/data/unicopia/seasons/crop/sweet_apple_sapling.json deleted file mode 100644 index 06ea5e21..00000000 --- a/src/main/resources/data/unicopia/seasons/crop/sweet_apple_sapling.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "spring": 1.0, - "summer": 1.0, - "fall": 0.6, - "winter": 0 -} \ No newline at end of file diff --git a/src/main/resources/data/unicopia/seasons/crop/sweet_apple_sprout.json b/src/main/resources/data/unicopia/seasons/crop/sweet_apple_sprout.json deleted file mode 100644 index 06ea5e21..00000000 --- a/src/main/resources/data/unicopia/seasons/crop/sweet_apple_sprout.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "spring": 1.0, - "summer": 1.0, - "fall": 0.6, - "winter": 0 -} \ No newline at end of file