mirror of
https://github.com/Sollace/Unicopia.git
synced 2025-02-21 12:24:22 +01:00
Fix incorrectly-generated seasons models
This commit is contained in:
parent
ffc66293fd
commit
1922c02f5b
4 changed files with 75 additions and 14 deletions
|
@ -0,0 +1,38 @@
|
||||||
|
package com.minelittlepony.unicopia.datagen;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
import com.google.common.base.Preconditions;
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
|
||||||
|
import net.minecraft.data.DataOutput.PathResolver;
|
||||||
|
import net.minecraft.data.DataProvider;
|
||||||
|
import net.minecraft.data.DataWriter;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
|
public class DataCollector {
|
||||||
|
private final HashMap<Identifier, Supplier<JsonElement>> values = new HashMap<>();
|
||||||
|
|
||||||
|
private final PathResolver resolver;
|
||||||
|
|
||||||
|
public DataCollector(PathResolver resolver) {
|
||||||
|
this.resolver = resolver;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BiConsumer<Identifier, Supplier<JsonElement>> prime() {
|
||||||
|
values.clear();
|
||||||
|
return (Identifier id, Supplier<JsonElement> value) ->
|
||||||
|
Preconditions.checkState(values.put(id, value) == null, "Duplicate model definition for " + id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompletableFuture<?> upload(DataWriter cache) {
|
||||||
|
return CompletableFuture.allOf(values.entrySet()
|
||||||
|
.stream()
|
||||||
|
.map(entry -> DataProvider.writeToPath(cache, entry.getValue().get(), resolver.resolveJson(entry.getKey())))
|
||||||
|
.toArray(CompletableFuture[]::new)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,17 +1,24 @@
|
||||||
package com.minelittlepony.unicopia.datagen.providers;
|
package com.minelittlepony.unicopia.datagen.providers;
|
||||||
|
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
|
import com.minelittlepony.unicopia.block.UBlocks;
|
||||||
|
import com.minelittlepony.unicopia.item.UItems;
|
||||||
|
|
||||||
import net.minecraft.data.client.BlockStateModelGenerator;
|
import net.minecraft.data.client.BlockStateModelGenerator;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
class SeasonsModelGenerator {
|
public class SeasonsModelGenerator extends UBlockStateModelGenerator {
|
||||||
|
|
||||||
private static final String[] SEASONS = { "fall", "summer", "winter" };
|
private static final String[] SEASONS = { "fall", "summer", "winter" };
|
||||||
|
|
||||||
static UBlockStateModelGenerator create(BlockStateModelGenerator modelGenerator) {
|
public SeasonsModelGenerator(BlockStateModelGenerator modelGenerator, BiConsumer<Identifier, Supplier<JsonElement>> seasonsModelConsumer) {
|
||||||
return new UBlockStateModelGenerator(modelGenerator.blockStateCollector, (id, jsonSupplier) -> {
|
super(modelGenerator.blockStateCollector, (id, jsonSupplier) -> {
|
||||||
modelGenerator.modelCollector.accept(id, jsonSupplier);
|
modelGenerator.modelCollector.accept(id, jsonSupplier);
|
||||||
modelGenerator.modelCollector.accept(id.withPrefixedPath("seasons/"), () -> {
|
seasonsModelConsumer.accept(id, () -> {
|
||||||
JsonObject textures = jsonSupplier.get().getAsJsonObject().getAsJsonObject("textures");
|
JsonObject textures = jsonSupplier.get().getAsJsonObject().getAsJsonObject("textures");
|
||||||
JsonObject seasonTextures = new JsonObject();
|
JsonObject seasonTextures = new JsonObject();
|
||||||
for (String season : SEASONS) {
|
for (String season : SEASONS) {
|
||||||
|
@ -31,4 +38,14 @@ class SeasonsModelGenerator {
|
||||||
});
|
});
|
||||||
return textures;
|
return textures;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void register() {
|
||||||
|
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);
|
||||||
|
|
||||||
|
registerItemModel(UItems.OATS);
|
||||||
|
registerItemModel(UItems.OAT_SEEDS);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,6 @@ import com.minelittlepony.unicopia.block.ShellsBlock;
|
||||||
import com.minelittlepony.unicopia.block.SlimePustuleBlock;
|
import com.minelittlepony.unicopia.block.SlimePustuleBlock;
|
||||||
import com.minelittlepony.unicopia.block.UBlocks;
|
import com.minelittlepony.unicopia.block.UBlocks;
|
||||||
import com.minelittlepony.unicopia.block.zap.ZapAppleLeavesBlock;
|
import com.minelittlepony.unicopia.block.zap.ZapAppleLeavesBlock;
|
||||||
import com.minelittlepony.unicopia.item.UItems;
|
|
||||||
import com.minelittlepony.unicopia.server.world.Tree;
|
import com.minelittlepony.unicopia.server.world.Tree;
|
||||||
|
|
||||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||||
|
@ -81,8 +80,6 @@ public class UBlockStateModelGenerator extends BlockStateModelGenerator {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void register() {
|
public void register() {
|
||||||
UBlockStateModelGenerator seasonsModelGenerator = SeasonsModelGenerator.create(this);
|
|
||||||
|
|
||||||
for (int i = 0; i < Models.STEM_GROWTH_STAGES.length; i++) {
|
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);
|
Models.STEM_GROWTH_STAGES[i].upload(Unicopia.id("block/apple_sprout_stage" + i), TextureMap.stem(Blocks.MELON_STEM), modelCollector);
|
||||||
}
|
}
|
||||||
|
@ -161,12 +158,6 @@ 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));
|
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);
|
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.GOLD_ROOT, Properties.AGE_7, BlockModels.CROP, 0, 0, 1, 1, 2, 2, 2, 3);
|
||||||
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,
|
registerTallCrop(UBlocks.PINEAPPLE, Properties.AGE_7, Properties.BLOCK_HALF,
|
||||||
new int[] { 0, 1, 2, 3, 4, 5, 5, 6 },
|
new int[] { 0, 1, 2, 3, 4, 5, 5, 6 },
|
||||||
|
|
|
@ -2,14 +2,17 @@ package com.minelittlepony.unicopia.datagen.providers;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
import com.minelittlepony.unicopia.Race;
|
import com.minelittlepony.unicopia.Race;
|
||||||
import com.minelittlepony.unicopia.block.UBlocks;
|
import com.minelittlepony.unicopia.block.UBlocks;
|
||||||
|
import com.minelittlepony.unicopia.datagen.DataCollector;
|
||||||
import com.minelittlepony.unicopia.item.BedsheetsItem;
|
import com.minelittlepony.unicopia.item.BedsheetsItem;
|
||||||
import com.minelittlepony.unicopia.item.UItems;
|
import com.minelittlepony.unicopia.item.UItems;
|
||||||
import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput;
|
import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput;
|
||||||
import net.fabricmc.fabric.api.datagen.v1.provider.FabricModelProvider;
|
import net.fabricmc.fabric.api.datagen.v1.provider.FabricModelProvider;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
|
import net.minecraft.data.DataOutput;
|
||||||
|
import net.minecraft.data.DataWriter;
|
||||||
import net.minecraft.data.client.BlockStateModelGenerator;
|
import net.minecraft.data.client.BlockStateModelGenerator;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.Items;
|
import net.minecraft.item.Items;
|
||||||
|
@ -29,13 +32,25 @@ public class UModelProvider extends FabricModelProvider {
|
||||||
UBlocks.ZAP_BULB, UItems.ZAP_BULB
|
UBlocks.ZAP_BULB, UItems.ZAP_BULB
|
||||||
);
|
);
|
||||||
|
|
||||||
|
private final DataCollector seasonsModels;
|
||||||
|
|
||||||
public UModelProvider(FabricDataOutput output) {
|
public UModelProvider(FabricDataOutput output) {
|
||||||
super(output);
|
super(output);
|
||||||
|
seasonsModels = new DataCollector(output.getResolver(DataOutput.OutputType.RESOURCE_PACK, "seasons/models"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void generateBlockStateModels(BlockStateModelGenerator modelGenerator0) {
|
public void generateBlockStateModels(BlockStateModelGenerator modelGenerator0) {
|
||||||
UBlockStateModelGenerator.create(modelGenerator0).register();
|
UBlockStateModelGenerator.create(modelGenerator0).register();
|
||||||
|
new SeasonsModelGenerator(modelGenerator0, seasonsModels.prime()).register();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<?> run(DataWriter writer) {
|
||||||
|
return CompletableFuture.allOf(
|
||||||
|
super.run(writer),
|
||||||
|
seasonsModels.upload(writer)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue