1
0
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:
Eclipse
2025-10-18 13:18:34 +00:00
parent 002ea50d37
commit 95da47e824
3 changed files with 48 additions and 29 deletions

View File

@@ -52,26 +52,44 @@ public abstract class RainbowModelProvider extends FabricModelProvider {
private final CompletableFuture<HolderLookup.Provider> registries; private final CompletableFuture<HolderLookup.Provider> registries;
private final Map<ResourceKey<EquipmentAsset>, EquipmentClientInfo> equipmentInfos; 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<Item, ClientItem> itemInfos;
private Map<ResourceLocation, ModelInstance> models; private Map<ResourceLocation, ModelInstance> models;
protected RainbowModelProvider(FabricDataOutput output, CompletableFuture<HolderLookup.Provider> registries, 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); super(output);
this.registries = registries; this.registries = registries;
this.equipmentInfos = equipmentInfos; 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(); .file(outputRoot, "").getParent();
this.geyserMappingsPath = computedOutputRoot.resolve(geyserMappingsPath);
this.packPath = computedOutputRoot.resolve(packPath);
} }
protected RainbowModelProvider(FabricDataOutput output, CompletableFuture<HolderLookup.Provider> registries, protected RainbowModelProvider(FabricDataOutput output, CompletableFuture<HolderLookup.Provider> registries,
Map<ResourceKey<EquipmentAsset>, EquipmentClientInfo> equipmentInfos) { Map<ResourceKey<EquipmentAsset>, EquipmentClientInfo> equipmentInfos, String packName,
this(output, registries, equipmentInfos, ResourceLocation.withDefaultNamespace("bedrock")); 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) { protected RainbowModelProvider(FabricDataOutput output, CompletableFuture<HolderLookup.Provider> registries) {
this(output, registries, Map.of()); this(output, registries, Rainbow.MOD_ID + "-generated");
} }
@Override @Override
@@ -81,7 +99,7 @@ public abstract class RainbowModelProvider extends FabricModelProvider {
CompletableFuture<BedrockPack> bedrockPack = ClientPackLoader.openClientResources() CompletableFuture<BedrockPack> bedrockPack = ClientPackLoader.openClientResources()
.thenCompose(resourceManager -> registries.thenApply(registries -> { .thenCompose(resourceManager -> registries.thenApply(registries -> {
try (resourceManager) { try (resourceManager) {
BedrockPack pack = createBedrockPack(outputRoot, new Serializer(output, registries), BedrockPack pack = createBedrockPack(new Serializer(output, registries),
new DatagenResolver(resourceManager, equipmentInfos, itemInfos, models)).build(); new DatagenResolver(resourceManager, equipmentInfos, itemInfos, models)).build();
for (Item item : itemInfos.keySet()) { for (Item item : itemInfos.keySet()) {
@@ -94,8 +112,8 @@ public abstract class RainbowModelProvider extends FabricModelProvider {
return CompletableFuture.allOf(vanillaModels, bedrockPack.thenCompose(BedrockPack::save)); return CompletableFuture.allOf(vanillaModels, bedrockPack.thenCompose(BedrockPack::save));
} }
protected BedrockPack.Builder createBedrockPack(Path outputRoot, PackSerializer serializer, AssetResolver resolver) { protected BedrockPack.Builder createBedrockPack(PackSerializer serializer, AssetResolver resolver) {
return BedrockPack.builder("rainbow", outputRoot.resolve("geyser_mappings.json"), outputRoot.resolve("pack"), serializer, resolver) return BedrockPack.builder(packName, geyserMappingsPath, packPath, serializer, resolver)
.withReporter(path -> new ProblemReporter.ScopedCollector(path, PROBLEM_LOGGER)); .withReporter(path -> new ProblemReporter.ScopedCollector(path, PROBLEM_LOGGER));
} }

View File

@@ -12,29 +12,29 @@ import org.geysermc.rainbow.definition.predicate.GeyserPredicate;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.function.Function;
// TODO other keys, etc. // 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 // TODO display name can be a component
public record GeyserBaseDefinition(ResourceLocation bedrockIdentifier, Optional<String> displayName, public record GeyserBaseDefinition(ResourceLocation bedrockIdentifier, Optional<String> displayName,
List<GeyserPredicate> predicates, BedrockOptions bedrockOptions, DataComponentPatch components) { List<GeyserPredicate> predicates, BedrockOptions bedrockOptions, DataComponentPatch components) {
private static final List<DataComponentType<?>> SUPPORTED_COMPONENTS = List.of(DataComponents.CONSUMABLE, DataComponents.EQUIPPABLE, DataComponents.FOOD, 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); 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 -> { private static final MapCodec<DataComponentPatch> FILTERED_COMPONENT_MAP_CODEC = DataComponentPatch.CODEC.optionalFieldOf("components")
DataComponentPatch.Builder filtered = DataComponentPatch.builder(); .xmap(optional -> optional.orElse(DataComponentPatch.EMPTY), patch -> {
patch.entrySet().stream() DataComponentPatch.Builder filtered = DataComponentPatch.builder();
.filter(entry -> entry.getValue().isEmpty() || SUPPORTED_COMPONENTS.contains(entry.getKey())) patch.entrySet().stream()
.forEach(entry -> { .filter(entry -> entry.getValue().isEmpty() || SUPPORTED_COMPONENTS.contains(entry.getKey()))
if (entry.getValue().isPresent()) { .forEach(entry -> {
filtered.set((DataComponentType) entry.getKey(), entry.getValue().orElseThrow()); if (entry.getValue().isPresent()) {
} else { filtered.set((DataComponentType) entry.getKey(), entry.getValue().orElseThrow());
filtered.remove(entry.getKey()); } else {
} filtered.remove(entry.getKey());
}); }
return filtered.build(); });
}); DataComponentPatch built = filtered.build();
return built.isEmpty() ? Optional.empty() : Optional.of(built);
});
public static final MapCodec<GeyserBaseDefinition> MAP_CODEC = RecordCodecBuilder.mapCodec(instance -> public static final MapCodec<GeyserBaseDefinition> MAP_CODEC = RecordCodecBuilder.mapCodec(instance ->
instance.group( instance.group(
@@ -42,7 +42,7 @@ public record GeyserBaseDefinition(ResourceLocation bedrockIdentifier, Optional<
Codec.STRING.optionalFieldOf("display_name").forGetter(GeyserBaseDefinition::displayName), Codec.STRING.optionalFieldOf("display_name").forGetter(GeyserBaseDefinition::displayName),
GeyserPredicate.LIST_CODEC.optionalFieldOf("predicate", List.of()).forGetter(GeyserBaseDefinition::predicates), GeyserPredicate.LIST_CODEC.optionalFieldOf("predicate", List.of()).forGetter(GeyserBaseDefinition::predicates),
BedrockOptions.CODEC.optionalFieldOf("bedrock_options", BedrockOptions.DEFAULT).forGetter(GeyserBaseDefinition::bedrockOptions), 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) ).apply(instance, GeyserBaseDefinition::new)
); );

View File

@@ -37,7 +37,7 @@ import java.util.function.UnaryOperator;
public class BedrockPack { public class BedrockPack {
private final String name; private final String name;
private final PackManifest manifest; private final Optional<PackManifest> manifest;
private final PackPaths paths; private final PackPaths paths;
private final PackSerializer serializer; private final PackSerializer serializer;
@@ -49,7 +49,7 @@ public class BedrockPack {
private final PackContext context; private final PackContext context;
private final ProblemReporter reporter; 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, Optional<GeometryRenderer> geometryRenderer, ProblemReporter reporter,
boolean reportSuccesses) { boolean reportSuccesses) {
this.name = name; this.name = name;
@@ -122,7 +122,7 @@ public class BedrockPack {
List<CompletableFuture<?>> futures = new ArrayList<>(); List<CompletableFuture<?>> futures = new ArrayList<>();
futures.add(serializer.saveJson(GeyserMappings.CODEC, context.mappings(), paths.mappings())); 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())); futures.add(serializer.saveJson(BedrockTextureAtlas.CODEC, BedrockTextureAtlas.itemAtlas(name, itemTextures), paths.itemAtlas()));
Function<TextureHolder, CompletableFuture<?>> textureSaver = texture -> { Function<TextureHolder, CompletableFuture<?>> textureSaver = texture -> {
@@ -275,7 +275,8 @@ public class BedrockPack {
PackPaths paths = new PackPaths(mappingsPath, packRootPath, attachablesPath.apply(packRootPath), PackPaths paths = new PackPaths(mappingsPath, packRootPath, attachablesPath.apply(packRootPath),
geometryPath.apply(packRootPath), animationPath.apply(packRootPath), manifestPath.apply(packRootPath), geometryPath.apply(packRootPath), animationPath.apply(packRootPath), manifestPath.apply(packRootPath),
itemAtlasPath.apply(packRootPath), Optional.ofNullable(packZipFile)); 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) { private static UnaryOperator<Path> resolve(Path child) {