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:
@@ -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