Move seasons stuff to datagen

This commit is contained in:
Sollace 2024-03-17 15:14:03 +00:00
parent 86cc754a7d
commit 9d59c89ac2
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB
32 changed files with 67 additions and 317 deletions

View file

@ -0,0 +1,34 @@
package com.minelittlepony.unicopia.datagen.providers;
import com.google.gson.JsonObject;
import net.minecraft.data.client.BlockStateModelGenerator;
import net.minecraft.util.Identifier;
class SeasonsModelGenerator {
private static final String[] SEASONS = { "fall", "summer", "winter" };
static UBlockStateModelGenerator create(BlockStateModelGenerator modelGenerator) {
return new UBlockStateModelGenerator(modelGenerator.blockStateCollector, (id, jsonSupplier) -> {
modelGenerator.modelCollector.accept(id, jsonSupplier);
modelGenerator.modelCollector.accept(id.withPrefixedPath("seasons/"), () -> {
JsonObject textures = jsonSupplier.get().getAsJsonObject().getAsJsonObject("textures");
JsonObject seasonTextures = new JsonObject();
for (String season : SEASONS) {
seasonTextures.add(season, createTextures(season, textures));
}
JsonObject model = new JsonObject();
model.add("textures", seasonTextures);
return model;
});
}, modelGenerator::excludeFromSimpleItemModelGeneration);
}
private static JsonObject createTextures(String season, JsonObject input) {
JsonObject textures = new JsonObject();
input.entrySet().forEach(entry -> {
textures.addProperty(entry.getKey(), new Identifier(entry.getValue().getAsString()).withPath(path -> path.replace("/", "/seasons/" + season + "/")).toString());
});
return textures;
}
}

View file

@ -3,6 +3,10 @@ package com.minelittlepony.unicopia.datagen.providers;
import java.util.HashMap;
import java.util.Map;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Supplier;
import com.google.gson.JsonElement;
import com.minelittlepony.unicopia.Unicopia;
import com.minelittlepony.unicopia.block.EdibleBlock;
import com.minelittlepony.unicopia.block.FruitBearingBlock;
@ -22,6 +26,7 @@ import net.minecraft.block.ConnectingBlock;
import net.minecraft.block.enums.DoorHinge;
import net.minecraft.block.enums.DoubleBlockHalf;
import net.minecraft.data.client.BlockStateModelGenerator;
import net.minecraft.data.client.BlockStateSupplier;
import net.minecraft.data.client.BlockStateVariant;
import net.minecraft.data.client.BlockStateVariantMap;
import net.minecraft.data.client.Model;
@ -55,27 +60,33 @@ public class UBlockStateModelGenerator extends BlockStateModelGenerator {
static final Identifier AIR_ITEM_ID = new Identifier("item/air");
static UBlockStateModelGenerator create(BlockStateModelGenerator modelGenerator) {
return new UBlockStateModelGenerator(modelGenerator);
return new UBlockStateModelGenerator(modelGenerator.blockStateCollector, modelGenerator.modelCollector, modelGenerator::excludeFromSimpleItemModelGeneration);
}
private UBlockStateModelGenerator(BlockStateModelGenerator modelGenerator) {
super(modelGenerator.blockStateCollector,
(id, jsonSupplier) -> {
if (AIR_BLOCK_ID.equals(id) || AIR_ITEM_ID.equals(id)) {
throw new IllegalStateException("Registered air id for block model: " + jsonSupplier.get().toString());
}
modelGenerator.modelCollector.accept(id, jsonSupplier);
},
item -> modelGenerator.excludeFromSimpleItemModelGeneration(Block.getBlockFromItem(item))
);
protected UBlockStateModelGenerator(BlockStateModelGenerator modelGenerator) {
this(modelGenerator.blockStateCollector, modelGenerator.modelCollector, modelGenerator::excludeFromSimpleItemModelGeneration);
}
for (int i = 0; i < Models.STEM_GROWTH_STAGES.length; i++) {
Models.STEM_GROWTH_STAGES[i].upload(Unicopia.id("block/apple_sprout_stage" + i), TextureMap.stem(Blocks.MELON_STEM), modelCollector);
}
public UBlockStateModelGenerator(
Consumer<BlockStateSupplier> blockStateCollector,
BiConsumer<Identifier, Supplier<JsonElement>> modelCollector,
Consumer<Block> simpleItemModelExemptionCollector) {
super(blockStateCollector, (id, jsonSupplier) -> {
if (AIR_BLOCK_ID.equals(id) || AIR_ITEM_ID.equals(id)) {
throw new IllegalStateException("Registered air id for block model: " + jsonSupplier.get().toString());
}
modelCollector.accept(id, jsonSupplier);
}, item -> simpleItemModelExemptionCollector.accept(Block.getBlockFromItem(item)));
}
@Override
public void register() {
UBlockStateModelGenerator seasonsModelGenerator = SeasonsModelGenerator.create(this);
for (int i = 0; i < Models.STEM_GROWTH_STAGES.length; i++) {
Models.STEM_GROWTH_STAGES[i].upload(Unicopia.id("block/apple_sprout_stage" + i), TextureMap.stem(Blocks.MELON_STEM), modelCollector);
}
// handmade
registerAll((g, block) -> g.registerParentedItemModel(block, ModelIds.getBlockModelId(block)), UBlocks.SHAPING_BENCH, UBlocks.SURFACE_CHITIN);
registerAll(UBlockStateModelGenerator::registerSimpleState, UBlocks.SHAPING_BENCH, UBlocks.BANANAS);
@ -150,9 +161,13 @@ public class UBlockStateModelGenerator extends BlockStateModelGenerator {
Tree.REGISTRY.stream().filter(tree -> tree.sapling().isPresent()).forEach(tree -> registerFlowerPotPlant(tree.sapling().get(), tree.pot().get(), TintType.NOT_TINTED));
registerTintableCross(UBlocks.CURING_JOKE, TintType.NOT_TINTED);
registerWithStages(UBlocks.GOLD_ROOT, Properties.AGE_7, BlockModels.CROP, 0, 0, 1, 1, 2, 2, 2, 3);
registerWithStages(UBlocks.OATS, UBlocks.OATS.getAgeProperty(), BlockModels.CROP, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11);
registerWithStages(UBlocks.OATS_STEM, UBlocks.OATS_STEM.getAgeProperty(), BlockModels.CROP, 0, 1, 2, 3, 4, 5, 6);
registerWithStages(UBlocks.OATS_CROWN, UBlocks.OATS_CROWN.getAgeProperty(), BlockModels.CROP, 0, 1);
seasonsModelGenerator.registerWithStages(UBlocks.OATS, UBlocks.OATS.getAgeProperty(), BlockModels.CROP, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11);
seasonsModelGenerator.registerWithStages(UBlocks.OATS_STEM, UBlocks.OATS_STEM.getAgeProperty(), BlockModels.CROP, 0, 1, 2, 3, 4, 5, 6);
seasonsModelGenerator.registerWithStages(UBlocks.OATS_CROWN, UBlocks.OATS_CROWN.getAgeProperty(), BlockModels.CROP, 0, 1);
seasonsModelGenerator.registerItemModel(UItems.OATS);
seasonsModelGenerator.registerItemModel(UItems.OAT_SEEDS);
registerTallCrop(UBlocks.PINEAPPLE, Properties.AGE_7, Properties.BLOCK_HALF,
new int[] { 0, 1, 2, 3, 4, 5, 5, 6 },
new int[] { 0, 0, 1, 2, 3, 4, 5, 6 }

View file

@ -41,7 +41,7 @@ public class UModelProvider extends FabricModelProvider {
UItems.JAM_TOAST, UItems.JUICE,
UItems.LIGHTNING_JAR,
UItems.MANGO, UItems.MUFFIN,
UItems.OAT_SEEDS, UItems.OATMEAL, UItems.OATS,
UItems.OATMEAL,
UItems.PEBBLES, UItems.PEGASUS_FEATHER, UItems.PINECONE, UItems.PINEAPPLE_CROWN,
UItems.RAIN_CLOUD_JAR, UItems.ROCK_STEW, UItems.ROCK, UItems.ROTTEN_APPLE,
UItems.SALT_CUBE, UItems.SCALLOP_SHELL, UItems.SHELLY, UItems.SOUR_APPLE_SEEDS, UItems.SOUR_APPLE, UItems.SPELLBOOK, UItems.STORM_CLOUD_JAR,

View file

@ -1,13 +0,0 @@
{
"textures": {
"summer": {
"crop": "unicopia:block/summer_oats_stage0"
},
"fall": {
"crop": "unicopia:block/fall_oats_stage0"
},
"winter": {
"crop": "unicopia:block/winter_oats_stage0"
}
}
}

View file

@ -1,13 +0,0 @@
{
"textures": {
"summer": {
"crop": "unicopia:block/summer_oats_stage1"
},
"fall": {
"crop": "unicopia:block/fall_oats_stage1"
},
"winter": {
"crop": "unicopia:block/winter_oats_stage1"
}
}
}

View file

@ -1,13 +0,0 @@
{
"textures": {
"summer": {
"crop": "unicopia:block/summer_oats_stage10_lower"
},
"fall": {
"crop": "unicopia:block/fall_oats_stage10_lower"
},
"winter": {
"crop": "unicopia:block/winter_oats_stage10_lower"
}
}
}

View file

@ -1,13 +0,0 @@
{
"textures": {
"summer": {
"crop": "unicopia:block/summer_oats_stage10_mid"
},
"fall": {
"crop": "unicopia:block/fall_oats_stage10_mid"
},
"winter": {
"crop": "unicopia:block/winter_oats_stage10_mid"
}
}
}

View file

@ -1,13 +0,0 @@
{
"textures": {
"summer": {
"crop": "unicopia:block/summer_oats_stage10_upper"
},
"fall": {
"crop": "unicopia:block/fall_oats_stage10_upper"
},
"winter": {
"crop": "unicopia:block/winter_oats_stage10_upper"
}
}
}

View file

@ -1,13 +0,0 @@
{
"textures": {
"summer": {
"crop": "unicopia:block/summer_oats_stage11_lower"
},
"fall": {
"crop": "unicopia:block/fall_oats_stage11_lower"
},
"winter": {
"crop": "unicopia:block/winter_oats_stage11_lower"
}
}
}

View file

@ -1,13 +0,0 @@
{
"textures": {
"summer": {
"crop": "unicopia:block/summer_oats_stage11_mid"
},
"fall": {
"crop": "unicopia:block/fall_oats_stage11_mid"
},
"winter": {
"crop": "unicopia:block/winter_oats_stage11_mid"
}
}
}

View file

@ -1,13 +0,0 @@
{
"textures": {
"summer": {
"crop": "unicopia:block/summer_oats_stage11_upper"
},
"fall": {
"crop": "unicopia:block/fall_oats_stage11_upper"
},
"winter": {
"crop": "unicopia:block/winter_oats_stage11_upper"
}
}
}

View file

@ -1,13 +0,0 @@
{
"textures": {
"summer": {
"crop": "unicopia:block/summer_oats_stage2"
},
"fall": {
"crop": "unicopia:block/fall_oats_stage2"
},
"winter": {
"crop": "unicopia:block/winter_oats_stage2"
}
}
}

View file

@ -1,13 +0,0 @@
{
"textures": {
"summer": {
"crop": "unicopia:block/summer_oats_stage3"
},
"fall": {
"crop": "unicopia:block/fall_oats_stage3"
},
"winter": {
"crop": "unicopia:block/winter_oats_stage3"
}
}
}

View file

@ -1,13 +0,0 @@
{
"textures": {
"summer": {
"crop": "unicopia:block/summer_oats_stage4"
},
"fall": {
"crop": "unicopia:block/fall_oats_stage4"
},
"winter": {
"crop": "unicopia:block/winter_oats_stage4"
}
}
}

View file

@ -1,13 +0,0 @@
{
"textures": {
"summer": {
"crop": "unicopia:block/summer_oats_stage5_lower"
},
"fall": {
"crop": "unicopia:block/fall_oats_stage5_lower"
},
"winter": {
"crop": "unicopia:block/winter_oats_stage5_lower"
}
}
}

View file

@ -1,13 +0,0 @@
{
"textures": {
"summer": {
"crop": "unicopia:block/summer_oats_stage5_upper"
},
"fall": {
"crop": "unicopia:block/fall_oats_stage5_upper"
},
"winter": {
"crop": "unicopia:block/winter_oats_stage5_upper"
}
}
}

View file

@ -1,13 +0,0 @@
{
"textures": {
"summer": {
"crop": "unicopia:block/summer_oats_stage6_lower"
},
"fall": {
"crop": "unicopia:block/fall_oats_stage6_lower"
},
"winter": {
"crop": "unicopia:block/winter_oats_stage6_lower"
}
}
}

View file

@ -1,13 +0,0 @@
{
"textures": {
"summer": {
"crop": "unicopia:block/summer_oats_stage6_upper"
},
"fall": {
"crop": "unicopia:block/fall_oats_stage6_upper"
},
"winter": {
"crop": "unicopia:block/winter_oats_stage6_upper"
}
}
}

View file

@ -1,13 +0,0 @@
{
"textures": {
"summer": {
"crop": "unicopia:block/summer_oats_stage7_lower"
},
"fall": {
"crop": "unicopia:block/fall_oats_stage7_lower"
},
"winter": {
"crop": "unicopia:block/winter_oats_stage7_lower"
}
}
}

View file

@ -1,13 +0,0 @@
{
"textures": {
"summer": {
"crop": "unicopia:block/summer_oats_stage7_upper"
},
"fall": {
"crop": "unicopia:block/fall_oats_stage7_upper"
},
"winter": {
"crop": "unicopia:block/winter_oats_stage7_upper"
}
}
}

View file

@ -1,13 +0,0 @@
{
"textures": {
"summer": {
"crop": "unicopia:block/summer_oats_stage8_lower"
},
"fall": {
"crop": "unicopia:block/fall_oats_stage8_lower"
},
"winter": {
"crop": "unicopia:block/winter_oats_stage8_lower"
}
}
}

View file

@ -1,13 +0,0 @@
{
"textures": {
"summer": {
"crop": "unicopia:block/summer_oats_stage8_upper"
},
"fall": {
"crop": "unicopia:block/fall_oats_stage8_upper"
},
"winter": {
"crop": "unicopia:block/winter_oats_stage8_upper"
}
}
}

View file

@ -1,13 +0,0 @@
{
"textures": {
"summer": {
"crop": "unicopia:block/summer_oats_stage9_lower"
},
"fall": {
"crop": "unicopia:block/fall_oats_stage9_lower"
},
"winter": {
"crop": "unicopia:block/winter_oats_stage9_lower"
}
}
}

View file

@ -1,13 +0,0 @@
{
"textures": {
"summer": {
"crop": "unicopia:block/summer_oats_stage9_upper"
},
"fall": {
"crop": "unicopia:block/fall_oats_stage9_upper"
},
"winter": {
"crop": "unicopia:block/winter_oats_stage9_upper"
}
}
}

View file

@ -1,13 +0,0 @@
{
"textures": {
"summer": {
"layer0": "unicopia:item/summer_oat_seeds"
},
"fall": {
"layer0": "unicopia:item/fall_oat_seeds"
},
"winter": {
"layer0": "unicopia:item/winter_oat_seeds"
}
}
}

View file

@ -1,13 +0,0 @@
{
"textures": {
"summer": {
"layer0": "unicopia:item/summer_oats"
},
"fall": {
"layer0": "unicopia:item/fall_oats"
},
"winter": {
"layer0": "unicopia:item/winter_oats"
}
}
}

View file

Before

Width:  |  Height:  |  Size: 6.6 KiB

After

Width:  |  Height:  |  Size: 6.6 KiB