mirror of
https://github.com/GeyserMC/Rainbow.git
synced 2025-12-19 14:59:16 +00:00
Remove empty components object from exported Geyser mappings, make pack manifest generation optional, more options in datagen
This commit is contained in:
@@ -52,26 +52,44 @@ public abstract class RainbowModelProvider extends FabricModelProvider {
|
||||
|
||||
private final CompletableFuture<HolderLookup.Provider> registries;
|
||||
private final Map<ResourceKey<EquipmentAsset>, EquipmentClientInfo> equipmentInfos;
|
||||
private final Path outputRoot;
|
||||
private final String packName;
|
||||
private final Path geyserMappingsPath;
|
||||
private final Path packPath;
|
||||
|
||||
private Map<Item, ClientItem> itemInfos;
|
||||
private Map<ResourceLocation, ModelInstance> models;
|
||||
|
||||
protected RainbowModelProvider(FabricDataOutput output, CompletableFuture<HolderLookup.Provider> registries,
|
||||
Map<ResourceKey<EquipmentAsset>, EquipmentClientInfo> equipmentInfos, ResourceLocation outputRoot) {
|
||||
Map<ResourceKey<EquipmentAsset>, EquipmentClientInfo> equipmentInfos, String packName,
|
||||
ResourceLocation outputRoot, Path geyserMappingsPath, Path packPath) {
|
||||
super(output);
|
||||
this.registries = registries;
|
||||
this.equipmentInfos = equipmentInfos;
|
||||
this.outputRoot = output.createPathProvider(PackOutput.Target.RESOURCE_PACK, outputRoot.getPath())
|
||||
this.packName = packName;
|
||||
|
||||
Path computedOutputRoot = output.createPathProvider(PackOutput.Target.RESOURCE_PACK, outputRoot.getPath())
|
||||
.file(outputRoot, "").getParent();
|
||||
this.geyserMappingsPath = computedOutputRoot.resolve(geyserMappingsPath);
|
||||
this.packPath = computedOutputRoot.resolve(packPath);
|
||||
}
|
||||
|
||||
protected RainbowModelProvider(FabricDataOutput output, CompletableFuture<HolderLookup.Provider> registries,
|
||||
Map<ResourceKey<EquipmentAsset>, EquipmentClientInfo> equipmentInfos) {
|
||||
this(output, registries, equipmentInfos, ResourceLocation.withDefaultNamespace("bedrock"));
|
||||
Map<ResourceKey<EquipmentAsset>, EquipmentClientInfo> equipmentInfos, String packName,
|
||||
ResourceLocation outputRoot) {
|
||||
this(output, registries, equipmentInfos, packName, outputRoot, Path.of("geyser_mappings.json"), Path.of("pack"));
|
||||
}
|
||||
|
||||
protected RainbowModelProvider(FabricDataOutput output, CompletableFuture<HolderLookup.Provider> registries,
|
||||
Map<ResourceKey<EquipmentAsset>, EquipmentClientInfo> equipmentInfos, String packName) {
|
||||
this(output, registries, equipmentInfos, packName, ResourceLocation.withDefaultNamespace("bedrock"));
|
||||
}
|
||||
|
||||
protected RainbowModelProvider(FabricDataOutput output, CompletableFuture<HolderLookup.Provider> registries, String packName) {
|
||||
this(output, registries, Map.of(), packName);
|
||||
}
|
||||
|
||||
protected RainbowModelProvider(FabricDataOutput output, CompletableFuture<HolderLookup.Provider> registries) {
|
||||
this(output, registries, Map.of());
|
||||
this(output, registries, Rainbow.MOD_ID + "-generated");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -81,7 +99,7 @@ public abstract class RainbowModelProvider extends FabricModelProvider {
|
||||
CompletableFuture<BedrockPack> bedrockPack = ClientPackLoader.openClientResources()
|
||||
.thenCompose(resourceManager -> registries.thenApply(registries -> {
|
||||
try (resourceManager) {
|
||||
BedrockPack pack = createBedrockPack(outputRoot, new Serializer(output, registries),
|
||||
BedrockPack pack = createBedrockPack(new Serializer(output, registries),
|
||||
new DatagenResolver(resourceManager, equipmentInfos, itemInfos, models)).build();
|
||||
|
||||
for (Item item : itemInfos.keySet()) {
|
||||
@@ -94,8 +112,8 @@ public abstract class RainbowModelProvider extends FabricModelProvider {
|
||||
return CompletableFuture.allOf(vanillaModels, bedrockPack.thenCompose(BedrockPack::save));
|
||||
}
|
||||
|
||||
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 BedrockPack.Builder createBedrockPack(PackSerializer serializer, AssetResolver resolver) {
|
||||
return BedrockPack.builder(packName, geyserMappingsPath, packPath, serializer, resolver)
|
||||
.withReporter(path -> new ProblemReporter.ScopedCollector(path, PROBLEM_LOGGER));
|
||||
}
|
||||
|
||||
|
||||
@@ -12,29 +12,29 @@ import org.geysermc.rainbow.definition.predicate.GeyserPredicate;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
|
||||
// TODO other keys, etc.
|
||||
// TODO sometimes still includes components key when patch before filtering is not empty but after is
|
||||
// TODO display name can be a component
|
||||
public record GeyserBaseDefinition(ResourceLocation bedrockIdentifier, Optional<String> displayName,
|
||||
List<GeyserPredicate> predicates, BedrockOptions bedrockOptions, DataComponentPatch components) {
|
||||
private static final List<DataComponentType<?>> SUPPORTED_COMPONENTS = List.of(DataComponents.CONSUMABLE, DataComponents.EQUIPPABLE, DataComponents.FOOD,
|
||||
DataComponents.MAX_DAMAGE, DataComponents.MAX_STACK_SIZE, DataComponents.USE_COOLDOWN, DataComponents.ENCHANTABLE, DataComponents.ENCHANTMENT_GLINT_OVERRIDE);
|
||||
|
||||
private static final Codec<DataComponentPatch> FILTERED_COMPONENT_MAP_CODEC = DataComponentPatch.CODEC.xmap(Function.identity(), patch -> {
|
||||
DataComponentPatch.Builder filtered = DataComponentPatch.builder();
|
||||
patch.entrySet().stream()
|
||||
.filter(entry -> entry.getValue().isEmpty() || SUPPORTED_COMPONENTS.contains(entry.getKey()))
|
||||
.forEach(entry -> {
|
||||
if (entry.getValue().isPresent()) {
|
||||
filtered.set((DataComponentType) entry.getKey(), entry.getValue().orElseThrow());
|
||||
} else {
|
||||
filtered.remove(entry.getKey());
|
||||
}
|
||||
});
|
||||
return filtered.build();
|
||||
});
|
||||
private static final MapCodec<DataComponentPatch> FILTERED_COMPONENT_MAP_CODEC = DataComponentPatch.CODEC.optionalFieldOf("components")
|
||||
.xmap(optional -> optional.orElse(DataComponentPatch.EMPTY), patch -> {
|
||||
DataComponentPatch.Builder filtered = DataComponentPatch.builder();
|
||||
patch.entrySet().stream()
|
||||
.filter(entry -> entry.getValue().isEmpty() || SUPPORTED_COMPONENTS.contains(entry.getKey()))
|
||||
.forEach(entry -> {
|
||||
if (entry.getValue().isPresent()) {
|
||||
filtered.set((DataComponentType) entry.getKey(), entry.getValue().orElseThrow());
|
||||
} else {
|
||||
filtered.remove(entry.getKey());
|
||||
}
|
||||
});
|
||||
DataComponentPatch built = filtered.build();
|
||||
return built.isEmpty() ? Optional.empty() : Optional.of(built);
|
||||
});
|
||||
|
||||
public static final MapCodec<GeyserBaseDefinition> MAP_CODEC = RecordCodecBuilder.mapCodec(instance ->
|
||||
instance.group(
|
||||
@@ -42,7 +42,7 @@ public record GeyserBaseDefinition(ResourceLocation bedrockIdentifier, Optional<
|
||||
Codec.STRING.optionalFieldOf("display_name").forGetter(GeyserBaseDefinition::displayName),
|
||||
GeyserPredicate.LIST_CODEC.optionalFieldOf("predicate", List.of()).forGetter(GeyserBaseDefinition::predicates),
|
||||
BedrockOptions.CODEC.optionalFieldOf("bedrock_options", BedrockOptions.DEFAULT).forGetter(GeyserBaseDefinition::bedrockOptions),
|
||||
FILTERED_COMPONENT_MAP_CODEC.optionalFieldOf("components", DataComponentPatch.EMPTY).forGetter(GeyserBaseDefinition::components)
|
||||
FILTERED_COMPONENT_MAP_CODEC.forGetter(GeyserBaseDefinition::components)
|
||||
).apply(instance, GeyserBaseDefinition::new)
|
||||
);
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ import java.util.function.UnaryOperator;
|
||||
|
||||
public class BedrockPack {
|
||||
private final String name;
|
||||
private final PackManifest manifest;
|
||||
private final Optional<PackManifest> manifest;
|
||||
private final PackPaths paths;
|
||||
private final PackSerializer serializer;
|
||||
|
||||
@@ -49,7 +49,7 @@ public class BedrockPack {
|
||||
private final PackContext context;
|
||||
private final ProblemReporter reporter;
|
||||
|
||||
public BedrockPack(String name, PackManifest manifest, PackPaths paths, PackSerializer serializer, AssetResolver assetResolver,
|
||||
public BedrockPack(String name, Optional<PackManifest> manifest, PackPaths paths, PackSerializer serializer, AssetResolver assetResolver,
|
||||
Optional<GeometryRenderer> geometryRenderer, ProblemReporter reporter,
|
||||
boolean reportSuccesses) {
|
||||
this.name = name;
|
||||
@@ -122,7 +122,7 @@ public class BedrockPack {
|
||||
List<CompletableFuture<?>> futures = new ArrayList<>();
|
||||
|
||||
futures.add(serializer.saveJson(GeyserMappings.CODEC, context.mappings(), paths.mappings()));
|
||||
futures.add(serializer.saveJson(PackManifest.CODEC, manifest, paths.manifest()));
|
||||
manifest.ifPresent(manifest -> futures.add(serializer.saveJson(PackManifest.CODEC, manifest, paths.manifest())));
|
||||
futures.add(serializer.saveJson(BedrockTextureAtlas.CODEC, BedrockTextureAtlas.itemAtlas(name, itemTextures), paths.itemAtlas()));
|
||||
|
||||
Function<TextureHolder, CompletableFuture<?>> textureSaver = texture -> {
|
||||
@@ -275,7 +275,8 @@ public class BedrockPack {
|
||||
PackPaths paths = new PackPaths(mappingsPath, packRootPath, attachablesPath.apply(packRootPath),
|
||||
geometryPath.apply(packRootPath), animationPath.apply(packRootPath), manifestPath.apply(packRootPath),
|
||||
itemAtlasPath.apply(packRootPath), Optional.ofNullable(packZipFile));
|
||||
return new BedrockPack(name, manifest, paths, packSerializer, assetResolver, Optional.ofNullable(geometryRenderer), reporter.apply(() -> "Bedrock pack " + name + " "), reportSuccesses);
|
||||
return new BedrockPack(name, Optional.ofNullable(manifest), paths, packSerializer, assetResolver, Optional.ofNullable(geometryRenderer),
|
||||
reporter.apply(() -> "Bedrock pack " + name + " "), reportSuccesses);
|
||||
}
|
||||
|
||||
private static UnaryOperator<Path> resolve(Path child) {
|
||||
|
||||
Reference in New Issue
Block a user