mirror of
https://github.com/GeyserMC/Rainbow.git
synced 2025-12-19 14:59:16 +00:00
Allow using custom paths in datagen
This commit is contained in:
@@ -37,20 +37,26 @@ import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public abstract class RainbowModelProvider extends FabricModelProvider {
|
||||
private final CompletableFuture<HolderLookup.Provider> registries;
|
||||
private final PackOutput.PathProvider bedrockPackPathProvider;
|
||||
private final Map<ResourceKey<EquipmentAsset>, EquipmentClientInfo> equipmentInfos;
|
||||
private final Path outputRoot;
|
||||
private Map<Item, ClientItem> itemInfos;
|
||||
private Map<ResourceLocation, ModelInstance> models;
|
||||
|
||||
public RainbowModelProvider(FabricDataOutput output, CompletableFuture<HolderLookup.Provider> registries,
|
||||
Map<ResourceKey<EquipmentAsset>, EquipmentClientInfo> equipmentInfos) {
|
||||
protected RainbowModelProvider(FabricDataOutput output, CompletableFuture<HolderLookup.Provider> registries,
|
||||
Map<ResourceKey<EquipmentAsset>, EquipmentClientInfo> equipmentInfos, ResourceLocation outputRoot) {
|
||||
super(output);
|
||||
this.registries = registries;
|
||||
this.equipmentInfos = equipmentInfos;
|
||||
bedrockPackPathProvider = output.createPathProvider(PackOutput.Target.RESOURCE_PACK, "bedrock");
|
||||
this.outputRoot = output.createPathProvider(PackOutput.Target.RESOURCE_PACK, outputRoot.getPath())
|
||||
.file(outputRoot, "").getParent();
|
||||
}
|
||||
|
||||
public RainbowModelProvider(FabricDataOutput output, CompletableFuture<HolderLookup.Provider> registries) {
|
||||
protected RainbowModelProvider(FabricDataOutput output, CompletableFuture<HolderLookup.Provider> registries,
|
||||
Map<ResourceKey<EquipmentAsset>, EquipmentClientInfo> equipmentInfos) {
|
||||
this(output, registries, equipmentInfos, ResourceLocation.withDefaultNamespace("bedrock"));
|
||||
}
|
||||
|
||||
protected RainbowModelProvider(FabricDataOutput output, CompletableFuture<HolderLookup.Provider> registries) {
|
||||
this(output, registries, Map.of());
|
||||
}
|
||||
|
||||
@@ -61,7 +67,7 @@ public abstract class RainbowModelProvider extends FabricModelProvider {
|
||||
CompletableFuture<BedrockPack> bedrockPack = ClientPackLoader.openClientResources()
|
||||
.thenCompose(resourceManager -> registries.thenApply(registries -> {
|
||||
try (resourceManager) {
|
||||
BedrockPack pack = createBedrockPack(new Serializer(output, registries, bedrockPackPathProvider),
|
||||
BedrockPack pack = createBedrockPack(outputRoot, new Serializer(output, registries),
|
||||
new DatagenResolver(resourceManager, equipmentInfos, itemInfos, models)).build();
|
||||
|
||||
for (Item item : itemInfos.keySet()) {
|
||||
@@ -74,8 +80,8 @@ public abstract class RainbowModelProvider extends FabricModelProvider {
|
||||
return CompletableFuture.allOf(vanillaModels, bedrockPack.thenCompose(BedrockPack::save));
|
||||
}
|
||||
|
||||
protected BedrockPack.Builder createBedrockPack(PackSerializer serializer, AssetResolver resolver) {
|
||||
return BedrockPack.builder("rainbow", Path.of("geyser_mappings"), Path.of("pack"), serializer, resolver);
|
||||
protected BedrockPack.Builder createBedrockPack(Path outputRoot, PackSerializer serializer, AssetResolver resolver) {
|
||||
return BedrockPack.builder("rainbow", outputRoot.resolve("geyser_mappings.json"), outputRoot.resolve("pack"), serializer, resolver);
|
||||
}
|
||||
|
||||
protected abstract Item getVanillaItem(Item modded);
|
||||
@@ -96,12 +102,11 @@ public abstract class RainbowModelProvider extends FabricModelProvider {
|
||||
this.models = models;
|
||||
}
|
||||
|
||||
private record Serializer(CachedOutput output, HolderLookup.Provider registries, PackOutput.PathProvider provider) implements PackSerializer {
|
||||
private record Serializer(CachedOutput output, HolderLookup.Provider registries) implements PackSerializer {
|
||||
|
||||
@Override
|
||||
public <T> CompletableFuture<?> saveJson(Codec<T> codec, T object, Path path) {
|
||||
ResourceLocation location = ResourceLocation.withDefaultNamespace(path.toString());
|
||||
return DataProvider.saveStable(output, registries, codec, object, provider.json(location));
|
||||
return DataProvider.saveStable(output, registries, codec, object, path);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -81,6 +81,7 @@ public class BedrockItemMapper {
|
||||
}
|
||||
|
||||
public static void tryMapStack(ItemStack stack, int customModelData, ProblemReporter reporter, PackContext context) {
|
||||
// TODO Improve this, use resouce log in problemreporter
|
||||
ItemModel.Unbaked vanillaModel = context.assetResolver().getClientItem(stack.get(DataComponents.ITEM_MODEL)).map(ClientItem::model).orElseThrow();
|
||||
ProblemReporter childReporter = reporter.forChild(() -> "item model " + vanillaModel + " with custom model data " + customModelData + " ");
|
||||
if (vanillaModel instanceof RangeSelectItemModel.Unbaked(RangeSelectItemModelProperty property, float scale, List<RangeSelectItemModel.Entry> entries, Optional<ItemModel.Unbaked> fallback)) {
|
||||
|
||||
@@ -174,8 +174,8 @@ public class BedrockPack {
|
||||
private static final Path GEOMETRY_DIRECTORY = Path.of("models/entity");
|
||||
private static final Path ANIMATION_DIRECTORY = Path.of("animations");
|
||||
|
||||
private static final Path MANIFEST_FILE = Path.of("manifest");
|
||||
private static final Path ITEM_ATLAS_FILE = Path.of("textures/item_texture");
|
||||
private static final Path MANIFEST_FILE = Path.of("manifest.json");
|
||||
private static final Path ITEM_ATLAS_FILE = Path.of("textures/item_texture.json");
|
||||
|
||||
private final String name;
|
||||
private final Path mappingsPath;
|
||||
|
||||
@@ -26,7 +26,7 @@ public record BedrockAnimation(BedrockVersion formatVersion, Map<String, Animati
|
||||
);
|
||||
|
||||
public CompletableFuture<?> save(PackSerializer serializer, Path animationDirectory, String identifier) {
|
||||
return serializer.saveJson(CODEC, this, animationDirectory.resolve(identifier + ".animation"));
|
||||
return serializer.saveJson(CODEC, this, animationDirectory.resolve(identifier + ".animation.json"));
|
||||
}
|
||||
|
||||
public static Builder builder() {
|
||||
|
||||
@@ -37,7 +37,7 @@ public record BedrockAttachable(BedrockVersion formatVersion, AttachableInfo inf
|
||||
|
||||
public CompletableFuture<?> save(PackSerializer serializer, Path attachablesDirectory) {
|
||||
// Get a safe attachable path by using Geyser's way of getting icons
|
||||
return serializer.saveJson(CODEC, this, attachablesDirectory.resolve(Rainbow.fileSafeResourceLocation(info.identifier)));
|
||||
return serializer.saveJson(CODEC, this, attachablesDirectory.resolve(Rainbow.fileSafeResourceLocation(info.identifier) + ".json"));
|
||||
}
|
||||
|
||||
public static Builder builder(ResourceLocation identifier) {
|
||||
|
||||
@@ -33,7 +33,7 @@ public record BedrockGeometry(BedrockVersion formatVersion, List<GeometryDefinit
|
||||
);
|
||||
|
||||
public CompletableFuture<?> save(PackSerializer serializer, Path geometryDirectory) {
|
||||
return serializer.saveJson(CODEC, this, geometryDirectory.resolve(definitions.getFirst().info.identifier + ".geo"));
|
||||
return serializer.saveJson(CODEC, this, geometryDirectory.resolve(definitions.getFirst().info.identifier + ".geo.json"));
|
||||
}
|
||||
|
||||
public static BedrockGeometry of(GeometryDefinition... definitions) {
|
||||
|
||||
Reference in New Issue
Block a user