From 873d0cb8549bdd87824e987ed280cd81ee6a48a1 Mon Sep 17 00:00:00 2001 From: pistonpoek Date: Fri, 5 Dec 2025 12:37:43 +0100 Subject: [PATCH 01/13] Update sound type builder Extend the sound type builder with the missing replace value that is accepted by the vanilla SoundEventRegistrationSerializer. --- .../datagen/v1/builder/SoundTypeBuilder.java | 11 ++++++++++- .../datagen/client/SoundTypeBuilderImpl.java | 17 ++++++++++++++--- .../DataGeneratorClientTestEntrypoint.java | 2 +- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/fabric-data-generation-api-v1/src/client/java/net/fabricmc/fabric/api/client/datagen/v1/builder/SoundTypeBuilder.java b/fabric-data-generation-api-v1/src/client/java/net/fabricmc/fabric/api/client/datagen/v1/builder/SoundTypeBuilder.java index 982e15ff5cf..99ee2a42ccc 100644 --- a/fabric-data-generation-api-v1/src/client/java/net/fabricmc/fabric/api/client/datagen/v1/builder/SoundTypeBuilder.java +++ b/fabric-data-generation-api-v1/src/client/java/net/fabricmc/fabric/api/client/datagen/v1/builder/SoundTypeBuilder.java @@ -38,7 +38,7 @@ *

Use in conjunction with {@link FabricSoundsProvider} to generate sound definitions. * * @see net.minecraft.client.sounds.SoundManager - * @see net.minecraft.client.sounds.WeighedSoundEvents + * @see net.minecraft.client.resources.sounds.SoundEventRegistration */ @ApiStatus.NonExtendable public interface SoundTypeBuilder { @@ -70,6 +70,13 @@ static SoundTypeBuilder of() { */ SoundTypeBuilder category(SoundSource category); + /** + * Sets an optional replace boolean, which on true allows this sound type to override others. + * + *

The default is false. + */ + SoundTypeBuilder replace(boolean replace); + /** * Sets an optional translation key string to use for the sound's subtitle. * @@ -134,6 +141,8 @@ public String getSerializedName() { /** * Builder for creating a weighted sound entry that can be played for a particular sound type. + * + * @see net.minecraft.client.resources.sounds.Sound */ @ApiStatus.NonExtendable interface EntryBuilder { diff --git a/fabric-data-generation-api-v1/src/client/java/net/fabricmc/fabric/impl/datagen/client/SoundTypeBuilderImpl.java b/fabric-data-generation-api-v1/src/client/java/net/fabricmc/fabric/impl/datagen/client/SoundTypeBuilderImpl.java index 65fc3e33643..6e330c83a85 100644 --- a/fabric-data-generation-api-v1/src/client/java/net/fabricmc/fabric/impl/datagen/client/SoundTypeBuilderImpl.java +++ b/fabric-data-generation-api-v1/src/client/java/net/fabricmc/fabric/impl/datagen/client/SoundTypeBuilderImpl.java @@ -46,6 +46,7 @@ public final class SoundTypeBuilderImpl implements SoundTypeBuilder { private static final Logger LOGGER = LoggerFactory.getLogger(SoundTypeBuilderImpl.class); private SoundSource category = SoundSource.NEUTRAL; + private boolean replace = false; @Nullable private String subtitle; private final List sounds = new ArrayList<>(); @@ -59,6 +60,12 @@ public SoundTypeBuilder category(SoundSource category) { return this; } + @Override + public SoundTypeBuilder replace(boolean replace) { + this.replace = replace; + return this; + } + @Override public SoundTypeBuilder subtitle(@Nullable String subtitle) { this.subtitle = subtitle; @@ -93,15 +100,19 @@ public SoundType build() { } } - return new SoundType(sounds, category, Optional.ofNullable(subtitle)); + return new SoundType(sounds, category, replace, Optional.ofNullable(subtitle)); } - public record SoundType(List sounds, SoundSource category, Optional subtitle) { + public record SoundType(List sounds, SoundSource category, boolean replace, Optional subtitle) { private static final Map CATEGORIES = Arrays.stream(SoundSource.values()).collect(Collectors.toMap(SoundSource::getName, Function.identity())); private static final Codec SOUND_CATEGORY_CODEC = Codec.stringResolver(SoundSource::getName, name -> CATEGORIES.getOrDefault(name.toLowerCase(Locale.ROOT), SoundSource.NEUTRAL)); + /** + * @see net.minecraft.client.resources.sounds.SoundEventRegistrationSerializer + */ public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( Entry.CODEC.listOf().fieldOf("sounds").forGetter(SoundType::sounds), - SOUND_CATEGORY_CODEC.fieldOf("category").forGetter(SoundType::category), + SOUND_CATEGORY_CODEC.optionalFieldOf("category", SoundSource.NEUTRAL).forGetter(SoundType::category), + Codec.BOOL.optionalFieldOf("replace", false).forGetter(SoundType::replace), Codec.STRING.optionalFieldOf("subtitle").forGetter(SoundType::subtitle) ).apply(instance, SoundType::new)); } diff --git a/fabric-data-generation-api-v1/src/testmodClient/java/net/fabricmc/fabric/test/datagen/client/DataGeneratorClientTestEntrypoint.java b/fabric-data-generation-api-v1/src/testmodClient/java/net/fabricmc/fabric/test/datagen/client/DataGeneratorClientTestEntrypoint.java index 311b4a4acfb..e6b407eceac 100644 --- a/fabric-data-generation-api-v1/src/testmodClient/java/net/fabricmc/fabric/test/datagen/client/DataGeneratorClientTestEntrypoint.java +++ b/fabric-data-generation-api-v1/src/testmodClient/java/net/fabricmc/fabric/test/datagen/client/DataGeneratorClientTestEntrypoint.java @@ -113,7 +113,7 @@ protected void configure(HolderLookup.Provider registryLookup, SoundExporter exp .sound(SoundTypeBuilder.EntryBuilder.ofEvent(SoundEvents.ARMOR_EQUIP_GENERIC)) .sound(SoundTypeBuilder.EntryBuilder.ofFile(Identifier.withDefaultNamespace("mob/parrot/idle")) .volume(0.3F).pitch(0.5F).stream(true).preload(true).attenuationDistance(8) - ) + ).replace(true) ); } } From d84c0d82a71391bd952b58bd5910255b40d1df84 Mon Sep 17 00:00:00 2001 From: pistonpoek Date: Fri, 5 Dec 2025 12:44:11 +0100 Subject: [PATCH 02/13] Update SoundTypeBuilder.java Add API note to clarify the existence of the category field. --- .../fabric/api/client/datagen/v1/builder/SoundTypeBuilder.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fabric-data-generation-api-v1/src/client/java/net/fabricmc/fabric/api/client/datagen/v1/builder/SoundTypeBuilder.java b/fabric-data-generation-api-v1/src/client/java/net/fabricmc/fabric/api/client/datagen/v1/builder/SoundTypeBuilder.java index 99ee2a42ccc..7e675162eb1 100644 --- a/fabric-data-generation-api-v1/src/client/java/net/fabricmc/fabric/api/client/datagen/v1/builder/SoundTypeBuilder.java +++ b/fabric-data-generation-api-v1/src/client/java/net/fabricmc/fabric/api/client/datagen/v1/builder/SoundTypeBuilder.java @@ -67,6 +67,9 @@ static SoundTypeBuilder of() { * Sets the sound category the sound event must play on. * *

The default category is {@link SoundSource#NEUTRAL}. GUI elements should use {@link SoundSource#MASTER}. + * + * @apiNote Category is not used by vanilla for the sound event registration, + * but can be specified for fabric and other mods to use. */ SoundTypeBuilder category(SoundSource category); From ec2ed015e88c42bdfbe28f44afb4a21bfa2e3e9d Mon Sep 17 00:00:00 2001 From: pistonpoek Date: Fri, 5 Dec 2025 17:09:21 +0100 Subject: [PATCH 03/13] Update SoundTypeBuilderImpl.java Add codec validation to the sound class record. Add additional documentation comments making the goal of data generation explicit. --- .../datagen/client/SoundTypeBuilderImpl.java | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/fabric-data-generation-api-v1/src/client/java/net/fabricmc/fabric/impl/datagen/client/SoundTypeBuilderImpl.java b/fabric-data-generation-api-v1/src/client/java/net/fabricmc/fabric/impl/datagen/client/SoundTypeBuilderImpl.java index 6e330c83a85..22bde8bce18 100644 --- a/fabric-data-generation-api-v1/src/client/java/net/fabricmc/fabric/impl/datagen/client/SoundTypeBuilderImpl.java +++ b/fabric-data-generation-api-v1/src/client/java/net/fabricmc/fabric/impl/datagen/client/SoundTypeBuilderImpl.java @@ -103,6 +103,15 @@ public SoundType build() { return new SoundType(sounds, category, replace, Optional.ofNullable(subtitle)); } + /** + * Extension of the sound event registration class for data generation. + * + * @param sounds List of sounds to use by the sound event. + * @param category Sound source that can be used by fabric and mods to play the sound event with. + * @param replace Whether the sound type is allowed to override an existing sound event. + * @param subtitle Optional string to use as translation key for subtitle text. + * @see net.minecraft.client.resources.sounds.SoundEventRegistration + */ public record SoundType(List sounds, SoundSource category, boolean replace, Optional subtitle) { private static final Map CATEGORIES = Arrays.stream(SoundSource.values()).collect(Collectors.toMap(SoundSource::getName, Function.identity())); private static final Codec SOUND_CATEGORY_CODEC = Codec.stringResolver(SoundSource::getName, name -> CATEGORIES.getOrDefault(name.toLowerCase(Locale.ROOT), SoundSource.NEUTRAL)); @@ -117,13 +126,19 @@ public record SoundType(List sounds, SoundSource category, boolean replac ).apply(instance, SoundType::new)); } - private record Entry(Identifier name, RegistrationType type, float volume, float pitch, int weight, int attenuationDistance, boolean stream, boolean preload) { + /** + * Record of the sound class to use for data generation. + * + * @see net.minecraft.client.resources.sounds.Sound + */ + private record Entry(Identifier name, RegistrationType type, float volume, float pitch, int weight, + int attenuationDistance, boolean stream, boolean preload) { private static final Codec MAP_CODEC = RecordCodecBuilder.create(instance -> instance.group( Identifier.CODEC.fieldOf("name").forGetter(Entry::name), RegistrationType.CODEC.optionalFieldOf("type", RegistrationType.FILE).forGetter(Entry::type), - Codec.FLOAT.optionalFieldOf("volume", EntryBuilder.DEFAULT_VOLUME).forGetter(Entry::volume), - Codec.FLOAT.optionalFieldOf("pitch", EntryBuilder.DEFAULT_PITCH).forGetter(Entry::pitch), - Codec.INT.optionalFieldOf("weight", EntryBuilder.DEFAULT_WEIGHT).forGetter(Entry::weight), + Codec.floatRange(0.0F, Float.MAX_VALUE).optionalFieldOf("volume", EntryBuilder.DEFAULT_VOLUME).forGetter(Entry::volume), + Codec.floatRange(0.0F, Float.MAX_VALUE).optionalFieldOf("pitch", EntryBuilder.DEFAULT_PITCH).forGetter(Entry::pitch), + Codec.intRange(0, Integer.MAX_VALUE).optionalFieldOf("weight", EntryBuilder.DEFAULT_WEIGHT).forGetter(Entry::weight), Codec.INT.optionalFieldOf("attenuation_distance", EntryBuilder.DEFAULT_ATTENUATION_DISTANCE).forGetter(Entry::attenuationDistance), Codec.BOOL.optionalFieldOf("stream", false).forGetter(Entry::stream), Codec.BOOL.optionalFieldOf("preload", false).forGetter(Entry::preload) From 8544dae9d2876c5b33279eac9787b2d11a06a570 Mon Sep 17 00:00:00 2001 From: pistonpoek Date: Fri, 5 Dec 2025 17:26:44 +0100 Subject: [PATCH 04/13] Deprecate category field Remove the category field of the sound event registration class to be added in data generation, as it is not interpreted by vanilla in the sounds file. --- .../client/datagen/v1/builder/SoundTypeBuilder.java | 8 ++------ .../impl/datagen/client/SoundTypeBuilderImpl.java | 13 +++---------- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/fabric-data-generation-api-v1/src/client/java/net/fabricmc/fabric/api/client/datagen/v1/builder/SoundTypeBuilder.java b/fabric-data-generation-api-v1/src/client/java/net/fabricmc/fabric/api/client/datagen/v1/builder/SoundTypeBuilder.java index 7e675162eb1..3b0aaa99297 100644 --- a/fabric-data-generation-api-v1/src/client/java/net/fabricmc/fabric/api/client/datagen/v1/builder/SoundTypeBuilder.java +++ b/fabric-data-generation-api-v1/src/client/java/net/fabricmc/fabric/api/client/datagen/v1/builder/SoundTypeBuilder.java @@ -64,13 +64,9 @@ static SoundTypeBuilder of() { } /** - * Sets the sound category the sound event must play on. - * - *

The default category is {@link SoundSource#NEUTRAL}. GUI elements should use {@link SoundSource#MASTER}. - * - * @apiNote Category is not used by vanilla for the sound event registration, - * but can be specified for fabric and other mods to use. + * @deprecated Category is not a field interpreted by vanilla in the sounds file. */ + @Deprecated SoundTypeBuilder category(SoundSource category); /** diff --git a/fabric-data-generation-api-v1/src/client/java/net/fabricmc/fabric/impl/datagen/client/SoundTypeBuilderImpl.java b/fabric-data-generation-api-v1/src/client/java/net/fabricmc/fabric/impl/datagen/client/SoundTypeBuilderImpl.java index 22bde8bce18..871389f470e 100644 --- a/fabric-data-generation-api-v1/src/client/java/net/fabricmc/fabric/impl/datagen/client/SoundTypeBuilderImpl.java +++ b/fabric-data-generation-api-v1/src/client/java/net/fabricmc/fabric/impl/datagen/client/SoundTypeBuilderImpl.java @@ -45,7 +45,6 @@ public final class SoundTypeBuilderImpl implements SoundTypeBuilder { private static final Logger LOGGER = LoggerFactory.getLogger(SoundTypeBuilderImpl.class); - private SoundSource category = SoundSource.NEUTRAL; private boolean replace = false; @Nullable private String subtitle; @@ -55,8 +54,6 @@ public SoundTypeBuilderImpl() { } @Override public SoundTypeBuilder category(SoundSource category) { - Objects.requireNonNull(category, "Sound event category must not be null."); - this.category = category; return this; } @@ -100,27 +97,23 @@ public SoundType build() { } } - return new SoundType(sounds, category, replace, Optional.ofNullable(subtitle)); + return new SoundType(sounds, replace, Optional.ofNullable(subtitle)); } /** - * Extension of the sound event registration class for data generation. + * Record of the sound event registration class for data generation. * * @param sounds List of sounds to use by the sound event. - * @param category Sound source that can be used by fabric and mods to play the sound event with. * @param replace Whether the sound type is allowed to override an existing sound event. * @param subtitle Optional string to use as translation key for subtitle text. * @see net.minecraft.client.resources.sounds.SoundEventRegistration */ - public record SoundType(List sounds, SoundSource category, boolean replace, Optional subtitle) { - private static final Map CATEGORIES = Arrays.stream(SoundSource.values()).collect(Collectors.toMap(SoundSource::getName, Function.identity())); - private static final Codec SOUND_CATEGORY_CODEC = Codec.stringResolver(SoundSource::getName, name -> CATEGORIES.getOrDefault(name.toLowerCase(Locale.ROOT), SoundSource.NEUTRAL)); + public record SoundType(List sounds, boolean replace, Optional subtitle) { /** * @see net.minecraft.client.resources.sounds.SoundEventRegistrationSerializer */ public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( Entry.CODEC.listOf().fieldOf("sounds").forGetter(SoundType::sounds), - SOUND_CATEGORY_CODEC.optionalFieldOf("category", SoundSource.NEUTRAL).forGetter(SoundType::category), Codec.BOOL.optionalFieldOf("replace", false).forGetter(SoundType::replace), Codec.STRING.optionalFieldOf("subtitle").forGetter(SoundType::subtitle) ).apply(instance, SoundType::new)); From 52aaecd4268297cbfc5c1efa597d9a2919db290b Mon Sep 17 00:00:00 2001 From: pistonpoek Date: Sat, 6 Dec 2025 23:25:11 +0100 Subject: [PATCH 05/13] Add sounds type tests Update codec to match validation with entry builder. Add test class for sound type builder to ensure sound types are build correctly. Add test class for sound type codec to ensure sound types generate and are interpreted to sound event registration classes as expected. --- .../datagen/client/SoundTypeBuilderImpl.java | 11 +- .../datagen/client/SoundsTypeBuilderTest.java | 147 ++++++++++++++++ .../datagen/client/SoundsTypeCodecTest.java | 164 ++++++++++++++++++ .../sounds.json | 2 +- 4 files changed, 316 insertions(+), 8 deletions(-) create mode 100644 fabric-data-generation-api-v1/src/test/java/net/frabricmc/fabric/test/datagen/client/SoundsTypeBuilderTest.java create mode 100644 fabric-data-generation-api-v1/src/test/java/net/frabricmc/fabric/test/datagen/client/SoundsTypeCodecTest.java diff --git a/fabric-data-generation-api-v1/src/client/java/net/fabricmc/fabric/impl/datagen/client/SoundTypeBuilderImpl.java b/fabric-data-generation-api-v1/src/client/java/net/fabricmc/fabric/impl/datagen/client/SoundTypeBuilderImpl.java index 871389f470e..1fcc63ceaee 100644 --- a/fabric-data-generation-api-v1/src/client/java/net/fabricmc/fabric/impl/datagen/client/SoundTypeBuilderImpl.java +++ b/fabric-data-generation-api-v1/src/client/java/net/fabricmc/fabric/impl/datagen/client/SoundTypeBuilderImpl.java @@ -103,9 +103,6 @@ public SoundType build() { /** * Record of the sound event registration class for data generation. * - * @param sounds List of sounds to use by the sound event. - * @param replace Whether the sound type is allowed to override an existing sound event. - * @param subtitle Optional string to use as translation key for subtitle text. * @see net.minecraft.client.resources.sounds.SoundEventRegistration */ public record SoundType(List sounds, boolean replace, Optional subtitle) { @@ -124,14 +121,14 @@ public record SoundType(List sounds, boolean replace, Optional su * * @see net.minecraft.client.resources.sounds.Sound */ - private record Entry(Identifier name, RegistrationType type, float volume, float pitch, int weight, + public record Entry(Identifier name, RegistrationType type, float volume, float pitch, int weight, int attenuationDistance, boolean stream, boolean preload) { private static final Codec MAP_CODEC = RecordCodecBuilder.create(instance -> instance.group( Identifier.CODEC.fieldOf("name").forGetter(Entry::name), RegistrationType.CODEC.optionalFieldOf("type", RegistrationType.FILE).forGetter(Entry::type), - Codec.floatRange(0.0F, Float.MAX_VALUE).optionalFieldOf("volume", EntryBuilder.DEFAULT_VOLUME).forGetter(Entry::volume), - Codec.floatRange(0.0F, Float.MAX_VALUE).optionalFieldOf("pitch", EntryBuilder.DEFAULT_PITCH).forGetter(Entry::pitch), - Codec.intRange(0, Integer.MAX_VALUE).optionalFieldOf("weight", EntryBuilder.DEFAULT_WEIGHT).forGetter(Entry::weight), + Codec.floatRange(Float.MIN_VALUE, 1.0F).optionalFieldOf("volume", EntryBuilder.DEFAULT_VOLUME).forGetter(Entry::volume), + Codec.floatRange(0.5F, 2.0F).optionalFieldOf("pitch", EntryBuilder.DEFAULT_PITCH).forGetter(Entry::pitch), + Codec.intRange(1, Integer.MAX_VALUE).optionalFieldOf("weight", EntryBuilder.DEFAULT_WEIGHT).forGetter(Entry::weight), Codec.INT.optionalFieldOf("attenuation_distance", EntryBuilder.DEFAULT_ATTENUATION_DISTANCE).forGetter(Entry::attenuationDistance), Codec.BOOL.optionalFieldOf("stream", false).forGetter(Entry::stream), Codec.BOOL.optionalFieldOf("preload", false).forGetter(Entry::preload) diff --git a/fabric-data-generation-api-v1/src/test/java/net/frabricmc/fabric/test/datagen/client/SoundsTypeBuilderTest.java b/fabric-data-generation-api-v1/src/test/java/net/frabricmc/fabric/test/datagen/client/SoundsTypeBuilderTest.java new file mode 100644 index 00000000000..599ee219548 --- /dev/null +++ b/fabric-data-generation-api-v1/src/test/java/net/frabricmc/fabric/test/datagen/client/SoundsTypeBuilderTest.java @@ -0,0 +1,147 @@ +package net.frabricmc.fabric.test.datagen.client; + +import net.fabricmc.fabric.api.client.datagen.v1.builder.SoundTypeBuilder; + +import net.fabricmc.fabric.impl.datagen.client.SoundTypeBuilderImpl; + +import net.minecraft.SharedConstants; +import net.minecraft.resources.Identifier; +import net.minecraft.server.Bootstrap; +import net.minecraft.sounds.SoundEvents; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import java.util.List; +import java.util.Optional; + +public class SoundsTypeBuilderTest { + @BeforeAll + static void beforeAll() { + SharedConstants.tryDetectVersion(); + Bootstrap.bootStrap(); + } + + @Test + public void buildSoundType1() { + SoundTypeBuilderImpl.SoundType expected = new SoundTypeBuilderImpl.SoundType( + List.of( + new SoundTypeBuilderImpl.Entry(Identifier.withDefaultNamespace("mob/parrot/idle1"), + SoundTypeBuilder.RegistrationType.FILE, 0.7F, 1.0F, 1, + 16, false, false), + new SoundTypeBuilderImpl.Entry(Identifier.withDefaultNamespace("mob/parrot/idle2"), + SoundTypeBuilder.RegistrationType.FILE, 1.0F, 1.0F, 1, + 16, false, false), + new SoundTypeBuilderImpl.Entry(SoundEvents.ANVIL_HIT.location(), + SoundTypeBuilder.RegistrationType.SOUND_EVENT, 1.0F, 1.0F, 100, + 16, false, false), + new SoundTypeBuilderImpl.Entry(SoundEvents.ARMOR_EQUIP_GENERIC.value().location(), + SoundTypeBuilder.RegistrationType.SOUND_EVENT, 1.0F, 1.0F, 1, + 16, false, false), + new SoundTypeBuilderImpl.Entry(Identifier.withDefaultNamespace("mob/parrot/idle"), + SoundTypeBuilder.RegistrationType.FILE, 0.3F, 0.5F, 1, + 8, true, true) + ), + true, + Optional.of("subtitles.minecraft.block.anvil.use") + ); + + SoundTypeBuilderImpl.SoundType soundType = ((SoundTypeBuilderImpl) SoundTypeBuilder.of(SoundEvents.ANVIL_USE) + .sound(SoundTypeBuilder.EntryBuilder.ofFile(Identifier.withDefaultNamespace("mob/parrot/idle")) + .volume(0.7F), 1) + .sound(SoundTypeBuilder.EntryBuilder.ofFile(Identifier.withDefaultNamespace("mob/parrot/idle2"))) + .sound(SoundTypeBuilder.EntryBuilder.ofEvent(SoundEvents.ANVIL_HIT) + .weight(100)) + .sound(SoundTypeBuilder.EntryBuilder.ofEvent(SoundEvents.ARMOR_EQUIP_GENERIC)) + .sound(SoundTypeBuilder.EntryBuilder.ofFile(Identifier.withDefaultNamespace("mob/parrot/idle")) + .volume(0.3F).pitch(0.5F).stream(true).preload(true).attenuationDistance(8) + ).replace(true)).build(); + + soundTypeEquals(expected, soundType); + } + + @Test + public void buildSoundType2() { + SoundTypeBuilderImpl.SoundType expected = new SoundTypeBuilderImpl.SoundType( + List.of( + new SoundTypeBuilderImpl.Entry(Identifier.withDefaultNamespace("mob/creeper/hurt"), + SoundTypeBuilder.RegistrationType.FILE, 1.0F, 2.0F, 1, + 16, false, false), + new SoundTypeBuilderImpl.Entry(SoundEvents.STONE_BREAK.location(), + SoundTypeBuilder.RegistrationType.SOUND_EVENT, 1.0F, 1.0F, 1, + 16, false, false), + new SoundTypeBuilderImpl.Entry(Identifier.withDefaultNamespace("block/beacon/power"), + SoundTypeBuilder.RegistrationType.FILE, Float.MIN_VALUE, 0.5F, 1, + 0, false, false) + ), + false, + Optional.empty() + ); + + SoundTypeBuilderImpl.SoundType soundType = ((SoundTypeBuilderImpl) SoundTypeBuilder.of() + .sound(SoundTypeBuilder.EntryBuilder.ofFile(Identifier.withDefaultNamespace("mob/creeper/hurt")) + .volume(1.0F).pitch(2.0F)) + .sound(SoundTypeBuilder.EntryBuilder.ofEvent(SoundEvents.STONE_BREAK) + .weight(1)) + .sound(SoundTypeBuilder.EntryBuilder.ofFile(Identifier.withDefaultNamespace("block/beacon/power")) + .volume(Float.MIN_VALUE).pitch(0.5F).stream(false).preload(false).attenuationDistance(0) + )).build(); + + soundTypeEquals(expected, soundType); + } + + @Test + public void buildSoundType3() { + SoundTypeBuilderImpl.SoundType expected = new SoundTypeBuilderImpl.SoundType( + List.of( + new SoundTypeBuilderImpl.Entry(Identifier.withDefaultNamespace("sound"), + SoundTypeBuilder.RegistrationType.FILE, 1.0F, 1.0F, 1, + 16, false, false) + ), + false, + Optional.of("super_subtitle") + ); + + SoundTypeBuilderImpl.SoundType soundType = ((SoundTypeBuilderImpl) SoundTypeBuilder.of() + .subtitle("super_subtitle") + .sound(SoundTypeBuilder.EntryBuilder.ofFile(Identifier.withDefaultNamespace("sound")))).build(); + + soundTypeEquals(expected, soundType); + } + + /** + * Assert that the expected and specified sound type equal. + * + * @param expected Sound type to be expected. + * @param soundType Sound type to assert against the expected sound type. + */ + public void soundTypeEquals(SoundTypeBuilderImpl.SoundType expected, SoundTypeBuilderImpl.SoundType soundType) { + Assertions.assertEquals(expected.subtitle(), soundType.subtitle()); + Assertions.assertEquals(expected.replace(), soundType.replace()); + Assertions.assertEquals(expected.sounds().size(), soundType.sounds().size()); + + for (int i = 0; i < expected.sounds().size(); i++) { + SoundTypeBuilderImpl.Entry expectedEntry = expected.sounds().get(i); + SoundTypeBuilderImpl.Entry entry = soundType.sounds().get(i); + entryEquals(expectedEntry, entry); + } + } + + /** + * Assert that all fields of the expected and specified entry equal each other. + * + * @param expected Entry with fields to be expected. + * @param entry Entry to assert against the expected entry. + */ + public void entryEquals(SoundTypeBuilderImpl.Entry expected, SoundTypeBuilderImpl.Entry entry) { + Assertions.assertEquals(expected.name().getNamespace(), entry.name().getNamespace()); + Assertions.assertEquals(expected.type().name(), entry.type().name()); + Assertions.assertEquals(expected.stream(), entry.stream()); + Assertions.assertEquals(expected.preload(), entry.preload()); + Assertions.assertEquals(expected.attenuationDistance(), entry.attenuationDistance()); + Assertions.assertEquals(expected.weight(), entry.weight()); + Assertions.assertEquals(expected.volume(), entry.volume()); + Assertions.assertEquals(expected.pitch(), entry.pitch()); + } +} diff --git a/fabric-data-generation-api-v1/src/test/java/net/frabricmc/fabric/test/datagen/client/SoundsTypeCodecTest.java b/fabric-data-generation-api-v1/src/test/java/net/frabricmc/fabric/test/datagen/client/SoundsTypeCodecTest.java new file mode 100644 index 00000000000..299b2598dd4 --- /dev/null +++ b/fabric-data-generation-api-v1/src/test/java/net/frabricmc/fabric/test/datagen/client/SoundsTypeCodecTest.java @@ -0,0 +1,164 @@ +package net.frabricmc.fabric.test.datagen.client; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonElement; +import com.google.gson.reflect.TypeToken; +import com.mojang.serialization.Codec; +import com.mojang.serialization.DataResult; +import com.mojang.serialization.JsonOps; + +import net.fabricmc.fabric.api.client.datagen.v1.builder.SoundTypeBuilder; +import net.fabricmc.fabric.impl.datagen.client.SoundTypeBuilderImpl; + +import net.minecraft.SharedConstants; +import net.minecraft.client.resources.sounds.Sound; +import net.minecraft.client.resources.sounds.SoundEventRegistration; +import net.minecraft.client.resources.sounds.SoundEventRegistrationSerializer; +import net.minecraft.resources.Identifier; +import net.minecraft.server.Bootstrap; +import net.minecraft.sounds.SoundEvents; + +import net.minecraft.util.RandomSource; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import java.util.List; +import java.util.Map; + +public class SoundsTypeCodecTest { + /** + * {@link net.fabricmc.fabric.api.client.datagen.v1.provider.FabricSoundsProvider#CODEC} + */ + private static final Codec> CODEC = + Codec.unboundedMap(Codec.STRING, SoundTypeBuilderImpl.SoundType.CODEC); + /** + * {@link net.minecraft.client.sounds.SoundManager#GSON} + */ + final Gson GSON = new GsonBuilder().registerTypeAdapter(SoundEventRegistration.class, + new SoundEventRegistrationSerializer()).create(); + /** + * {@link net.minecraft.client.sounds.SoundManager#SOUND_EVENT_REGISTRATION_TYPE} + */ + final TypeToken> SOUND_EVENT_REGISTRATION_TYPE = new TypeToken<>() {}; + + private static final Identifier IDENTIFIER = + Identifier.fromNamespaceAndPath("datagen-test", "sound-event-registrable-codec"); + + @BeforeAll + static void beforeAll() { + SharedConstants.tryDetectVersion(); + Bootstrap.bootStrap(); + } + + @Test + public void soundsTypeCodec1() { + SoundTypeBuilder builder = SoundTypeBuilder.of(SoundEvents.ANVIL_USE) + .sound(SoundTypeBuilder.EntryBuilder.ofFile(Identifier.withDefaultNamespace("mob/parrot/idle")) + .volume(0.7F), 1) + .sound(SoundTypeBuilder.EntryBuilder.ofFile(Identifier.withDefaultNamespace("mob/parrot/idle2"))) + .sound(SoundTypeBuilder.EntryBuilder.ofEvent(SoundEvents.ANVIL_HIT) + .weight(100)) + .sound(SoundTypeBuilder.EntryBuilder.ofEvent(SoundEvents.ARMOR_EQUIP_GENERIC)) + .sound(SoundTypeBuilder.EntryBuilder.ofFile(Identifier.withDefaultNamespace("mob/parrot/idle")) + .volume(0.3F).pitch(0.5F).stream(true).preload(true).attenuationDistance(8) + ).replace(true); + + final Map data = + Map.of(IDENTIFIER.getPath(), ((SoundTypeBuilderImpl) builder).build()); + + expectInputDataInOutput(data, process(data)); + } + + @Test + public void soundsTypeCodec2() { + SoundTypeBuilder builder = SoundTypeBuilder.of() + .sound(SoundTypeBuilder.EntryBuilder.ofFile(Identifier.withDefaultNamespace("mob/creeper/hurt")) + .volume(1.0F).pitch(2.0F)) + .sound(SoundTypeBuilder.EntryBuilder.ofEvent(SoundEvents.STONE_BREAK) + .weight(1)) + .sound(SoundTypeBuilder.EntryBuilder.ofFile(Identifier.withDefaultNamespace("block/beacon/power")) + .volume(Float.MIN_VALUE).pitch(0.5F).stream(false).preload(false).attenuationDistance(0) + ); + + final Map data = + Map.of(IDENTIFIER.getPath(), ((SoundTypeBuilderImpl) builder).build()); + + expectInputDataInOutput(data, process(data)); + } + + @Test + public void soundsTypeCodec3() { + SoundTypeBuilder builder = SoundTypeBuilder.of() + .subtitle("super_subtitle") + .sound(SoundTypeBuilder.EntryBuilder.ofFile(Identifier.withDefaultNamespace("sound"))); + + final Map data = + Map.of(IDENTIFIER.getPath(), ((SoundTypeBuilderImpl) builder).build()); + + expectInputDataInOutput(data, process(data)); + } + + /** + * Test if the output data has all values present in the input data. + * + * @param inputData Sounds input data used for data generation. + * @param outputData Sounds output data interpreted from sounds file. + */ + private static void expectInputDataInOutput(Map inputData, + Map outputData) { + for (String identifier : inputData.keySet()) { + SoundEventRegistration soundEventRegistration = outputData.get(identifier); + Assertions.assertNotNull(soundEventRegistration); + + SoundTypeBuilderImpl.SoundType soundType = inputData.get(identifier); + + Assertions.assertEquals(soundType.replace(), soundEventRegistration.isReplace()); + Assertions.assertEquals(soundType.subtitle().orElse(null), soundEventRegistration.getSubtitle()); + + List entryList = soundType.sounds(); + List soundList = soundEventRegistration.getSounds(); + Assertions.assertEquals(entryList.size(), soundList.size()); + + for (int i = 0; i < entryList.size(); i++) { + SoundTypeBuilderImpl.Entry entry = entryList.get(i); + Sound sound = soundList.get(i); + expectInputDataInOutput(entry, sound); + } + + } + } + + /** + * Test if the output data has all values present in the input data. + * + * @param entry Entry used to represent sound for data generation. + * @param sound Sound interpreted from sounds file. + */ + private static void expectInputDataInOutput(SoundTypeBuilderImpl.Entry entry, Sound sound) { + Assertions.assertEquals(entry.name(), sound.getLocation()); + Assertions.assertEquals(entry.type().name(), sound.getType().name()); + Assertions.assertEquals(entry.stream(), sound.shouldStream()); + Assertions.assertEquals(entry.preload(), sound.shouldPreload()); + Assertions.assertEquals(entry.attenuationDistance(), sound.getAttenuationDistance()); + Assertions.assertEquals(entry.weight(), sound.getWeight()); + Assertions.assertEquals(entry.volume(), sound.getVolume().sample(RandomSource.create())); + Assertions.assertEquals(entry.pitch(), sound.getPitch().sample(RandomSource.create())); + } + + /** + * Generate and interpret data like the sounds provider and sounds manager respectively. + * + * @see net.fabricmc.fabric.api.client.datagen.v1.provider.FabricSoundsProvider + * @see net.minecraft.client.sounds.SoundManager + */ + private Map process(Map data) { + // Generate json element, matching the codec from fabric sounds provider. + DataResult result = CODEC.encodeStart(JsonOps.INSTANCE, data); + + // Interpret json data, matching the Gson and type from sound manager. + return GSON.fromJson(result.getOrThrow(), SOUND_EVENT_REGISTRATION_TYPE); + } +} diff --git a/fabric-data-generation-api-v1/src/testmod/generated/resourcepacks/example_builtin/assets/fabric-data-gen-api-v1-testmod/sounds.json b/fabric-data-generation-api-v1/src/testmod/generated/resourcepacks/example_builtin/assets/fabric-data-gen-api-v1-testmod/sounds.json index 8421e08e010..c13621c44ce 100644 --- a/fabric-data-generation-api-v1/src/testmod/generated/resourcepacks/example_builtin/assets/fabric-data-gen-api-v1-testmod/sounds.json +++ b/fabric-data-generation-api-v1/src/testmod/generated/resourcepacks/example_builtin/assets/fabric-data-gen-api-v1-testmod/sounds.json @@ -1,6 +1,6 @@ { "test_sound": { - "category": "neutral", + "replace": true, "sounds": [ { "name": "minecraft:mob/parrot/idle1", From 3eb31f08323dedf80142e3d2e5b630ae5ad30a4e Mon Sep 17 00:00:00 2001 From: pistonpoek Date: Sat, 6 Dec 2025 23:34:51 +0100 Subject: [PATCH 06/13] Update SoundTypeBuilder.java Clarify deprecated behavior of category method. --- .../fabric/api/client/datagen/v1/builder/SoundTypeBuilder.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fabric-data-generation-api-v1/src/client/java/net/fabricmc/fabric/api/client/datagen/v1/builder/SoundTypeBuilder.java b/fabric-data-generation-api-v1/src/client/java/net/fabricmc/fabric/api/client/datagen/v1/builder/SoundTypeBuilder.java index 3b0aaa99297..c1dc9ce6716 100644 --- a/fabric-data-generation-api-v1/src/client/java/net/fabricmc/fabric/api/client/datagen/v1/builder/SoundTypeBuilder.java +++ b/fabric-data-generation-api-v1/src/client/java/net/fabricmc/fabric/api/client/datagen/v1/builder/SoundTypeBuilder.java @@ -64,7 +64,8 @@ static SoundTypeBuilder of() { } /** - * @deprecated Category is not a field interpreted by vanilla in the sounds file. + * @deprecated Category is not a field interpreted by vanilla in the sounds file, + * calling this method will have no effect. */ @Deprecated SoundTypeBuilder category(SoundSource category); From d08d29cd0d447b61e0b37bd1f0777a03fc26bde1 Mon Sep 17 00:00:00 2001 From: pistonpoek Date: Sat, 6 Dec 2025 23:43:23 +0100 Subject: [PATCH 07/13] Update SoundsTypeBuilderTest.java Update param doc to conform to yarn conventions --- .../fabric/test/datagen/client/SoundsTypeBuilderTest.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fabric-data-generation-api-v1/src/test/java/net/frabricmc/fabric/test/datagen/client/SoundsTypeBuilderTest.java b/fabric-data-generation-api-v1/src/test/java/net/frabricmc/fabric/test/datagen/client/SoundsTypeBuilderTest.java index 599ee219548..0d67c7f6018 100644 --- a/fabric-data-generation-api-v1/src/test/java/net/frabricmc/fabric/test/datagen/client/SoundsTypeBuilderTest.java +++ b/fabric-data-generation-api-v1/src/test/java/net/frabricmc/fabric/test/datagen/client/SoundsTypeBuilderTest.java @@ -113,8 +113,8 @@ public void buildSoundType3() { /** * Assert that the expected and specified sound type equal. * - * @param expected Sound type to be expected. - * @param soundType Sound type to assert against the expected sound type. + * @param expected sound type to be expected + * @param soundType sound type to assert against */ public void soundTypeEquals(SoundTypeBuilderImpl.SoundType expected, SoundTypeBuilderImpl.SoundType soundType) { Assertions.assertEquals(expected.subtitle(), soundType.subtitle()); @@ -131,8 +131,8 @@ public void soundTypeEquals(SoundTypeBuilderImpl.SoundType expected, SoundTypeBu /** * Assert that all fields of the expected and specified entry equal each other. * - * @param expected Entry with fields to be expected. - * @param entry Entry to assert against the expected entry. + * @param expected entry with fields to be expected + * @param entry entry to assert against */ public void entryEquals(SoundTypeBuilderImpl.Entry expected, SoundTypeBuilderImpl.Entry entry) { Assertions.assertEquals(expected.name().getNamespace(), entry.name().getNamespace()); From 3dea6370285b0bae65ad67e0f50088c5d63f8a27 Mon Sep 17 00:00:00 2001 From: pistonpoek Date: Sat, 6 Dec 2025 23:50:25 +0100 Subject: [PATCH 08/13] Update SoundTypeBuilder.java Remove see tag that might be more distracting than helpful --- .../fabric/api/client/datagen/v1/builder/SoundTypeBuilder.java | 1 - 1 file changed, 1 deletion(-) diff --git a/fabric-data-generation-api-v1/src/client/java/net/fabricmc/fabric/api/client/datagen/v1/builder/SoundTypeBuilder.java b/fabric-data-generation-api-v1/src/client/java/net/fabricmc/fabric/api/client/datagen/v1/builder/SoundTypeBuilder.java index c1dc9ce6716..058afe1ba1b 100644 --- a/fabric-data-generation-api-v1/src/client/java/net/fabricmc/fabric/api/client/datagen/v1/builder/SoundTypeBuilder.java +++ b/fabric-data-generation-api-v1/src/client/java/net/fabricmc/fabric/api/client/datagen/v1/builder/SoundTypeBuilder.java @@ -37,7 +37,6 @@ * *

Use in conjunction with {@link FabricSoundsProvider} to generate sound definitions. * - * @see net.minecraft.client.sounds.SoundManager * @see net.minecraft.client.resources.sounds.SoundEventRegistration */ @ApiStatus.NonExtendable From 8238438e850be7ad26d1639b34c9f1ed053218d7 Mon Sep 17 00:00:00 2001 From: pistonpoek Date: Sun, 7 Dec 2025 11:35:46 +0100 Subject: [PATCH 09/13] Update SoundTypeBuilderImpl.java Remove unused imports. Remove space indentation. --- .../fabric/impl/datagen/client/SoundTypeBuilderImpl.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/fabric-data-generation-api-v1/src/client/java/net/fabricmc/fabric/impl/datagen/client/SoundTypeBuilderImpl.java b/fabric-data-generation-api-v1/src/client/java/net/fabricmc/fabric/impl/datagen/client/SoundTypeBuilderImpl.java index 1fcc63ceaee..78d9a48d3a9 100644 --- a/fabric-data-generation-api-v1/src/client/java/net/fabricmc/fabric/impl/datagen/client/SoundTypeBuilderImpl.java +++ b/fabric-data-generation-api-v1/src/client/java/net/fabricmc/fabric/impl/datagen/client/SoundTypeBuilderImpl.java @@ -17,14 +17,9 @@ package net.fabricmc.fabric.impl.datagen.client; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; -import java.util.Locale; -import java.util.Map; import java.util.Objects; import java.util.Optional; -import java.util.function.Function; -import java.util.stream.Collectors; import com.mojang.datafixers.util.Either; import com.mojang.serialization.Codec; @@ -122,7 +117,7 @@ public record SoundType(List sounds, boolean replace, Optional su * @see net.minecraft.client.resources.sounds.Sound */ public record Entry(Identifier name, RegistrationType type, float volume, float pitch, int weight, - int attenuationDistance, boolean stream, boolean preload) { + int attenuationDistance, boolean stream, boolean preload) { private static final Codec MAP_CODEC = RecordCodecBuilder.create(instance -> instance.group( Identifier.CODEC.fieldOf("name").forGetter(Entry::name), RegistrationType.CODEC.optionalFieldOf("type", RegistrationType.FILE).forGetter(Entry::type), From aba3ed79fb419483d66021d1fe5b590fe2796d88 Mon Sep 17 00:00:00 2001 From: pistonpoek Date: Sun, 7 Dec 2025 11:36:41 +0100 Subject: [PATCH 10/13] Add licences Apply Spotless to add licenses. --- .../datagen/client/SoundsTypeBuilderTest.java | 31 ++++++++++++----- .../datagen/client/SoundsTypeCodecTest.java | 34 +++++++++++++------ 2 files changed, 47 insertions(+), 18 deletions(-) diff --git a/fabric-data-generation-api-v1/src/test/java/net/frabricmc/fabric/test/datagen/client/SoundsTypeBuilderTest.java b/fabric-data-generation-api-v1/src/test/java/net/frabricmc/fabric/test/datagen/client/SoundsTypeBuilderTest.java index 0d67c7f6018..a645cde0968 100644 --- a/fabric-data-generation-api-v1/src/test/java/net/frabricmc/fabric/test/datagen/client/SoundsTypeBuilderTest.java +++ b/fabric-data-generation-api-v1/src/test/java/net/frabricmc/fabric/test/datagen/client/SoundsTypeBuilderTest.java @@ -1,20 +1,35 @@ +/* + * Copyright (c) 2016, 2017, 2018, 2019 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package net.frabricmc.fabric.test.datagen.client; -import net.fabricmc.fabric.api.client.datagen.v1.builder.SoundTypeBuilder; +import java.util.List; +import java.util.Optional; -import net.fabricmc.fabric.impl.datagen.client.SoundTypeBuilderImpl; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import net.minecraft.SharedConstants; import net.minecraft.resources.Identifier; import net.minecraft.server.Bootstrap; import net.minecraft.sounds.SoundEvents; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; - -import java.util.List; -import java.util.Optional; +import net.fabricmc.fabric.api.client.datagen.v1.builder.SoundTypeBuilder; +import net.fabricmc.fabric.impl.datagen.client.SoundTypeBuilderImpl; public class SoundsTypeBuilderTest { @BeforeAll diff --git a/fabric-data-generation-api-v1/src/test/java/net/frabricmc/fabric/test/datagen/client/SoundsTypeCodecTest.java b/fabric-data-generation-api-v1/src/test/java/net/frabricmc/fabric/test/datagen/client/SoundsTypeCodecTest.java index 299b2598dd4..d0828ac8bba 100644 --- a/fabric-data-generation-api-v1/src/test/java/net/frabricmc/fabric/test/datagen/client/SoundsTypeCodecTest.java +++ b/fabric-data-generation-api-v1/src/test/java/net/frabricmc/fabric/test/datagen/client/SoundsTypeCodecTest.java @@ -1,5 +1,24 @@ +/* + * Copyright (c) 2016, 2017, 2018, 2019 FabricMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package net.frabricmc.fabric.test.datagen.client; +import java.util.List; +import java.util.Map; + import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonElement; @@ -7,9 +26,9 @@ import com.mojang.serialization.Codec; import com.mojang.serialization.DataResult; import com.mojang.serialization.JsonOps; - -import net.fabricmc.fabric.api.client.datagen.v1.builder.SoundTypeBuilder; -import net.fabricmc.fabric.impl.datagen.client.SoundTypeBuilderImpl; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import net.minecraft.SharedConstants; import net.minecraft.client.resources.sounds.Sound; @@ -18,15 +37,10 @@ import net.minecraft.resources.Identifier; import net.minecraft.server.Bootstrap; import net.minecraft.sounds.SoundEvents; - import net.minecraft.util.RandomSource; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; - -import java.util.List; -import java.util.Map; +import net.fabricmc.fabric.api.client.datagen.v1.builder.SoundTypeBuilder; +import net.fabricmc.fabric.impl.datagen.client.SoundTypeBuilderImpl; public class SoundsTypeCodecTest { /** From 25e8189dfbe10a6cf42886adbeda6a2c2f86d0c1 Mon Sep 17 00:00:00 2001 From: pistonpoek Date: Sun, 7 Dec 2025 12:00:09 +0100 Subject: [PATCH 11/13] Fix check issues Fix package name of sounds test. Replace hard coded value checks with the already existing default variables. --- .../impl/datagen/client/SoundTypeBuilderImpl.java | 8 ++++---- .../test/datagen/client/SoundsTypeBuilderTest.java | 2 +- .../test/datagen/client/SoundsTypeCodecTest.java | 13 ++++++------- 3 files changed, 11 insertions(+), 12 deletions(-) rename fabric-data-generation-api-v1/src/test/java/net/{frabricmc => fabricmc}/fabric/test/datagen/client/SoundsTypeBuilderTest.java (99%) rename fabric-data-generation-api-v1/src/test/java/net/{frabricmc => fabricmc}/fabric/test/datagen/client/SoundsTypeCodecTest.java (91%) diff --git a/fabric-data-generation-api-v1/src/client/java/net/fabricmc/fabric/impl/datagen/client/SoundTypeBuilderImpl.java b/fabric-data-generation-api-v1/src/client/java/net/fabricmc/fabric/impl/datagen/client/SoundTypeBuilderImpl.java index 78d9a48d3a9..08401147099 100644 --- a/fabric-data-generation-api-v1/src/client/java/net/fabricmc/fabric/impl/datagen/client/SoundTypeBuilderImpl.java +++ b/fabric-data-generation-api-v1/src/client/java/net/fabricmc/fabric/impl/datagen/client/SoundTypeBuilderImpl.java @@ -135,10 +135,10 @@ public record Entry(Identifier name, RegistrationType type, float volume, float ); private static final Codec CODEC = Codec.xor(STRING_CODEC, MAP_CODEC).xmap(Either::unwrap, sound -> { if (sound.type() != RegistrationType.FILE - || sound.volume() != 1F - || sound.pitch() != 1F - || sound.weight() != 1 - || sound.attenuationDistance() != 16 + || sound.volume() != EntryBuilder.DEFAULT_VOLUME + || sound.pitch() != EntryBuilder.DEFAULT_PITCH + || sound.weight() != EntryBuilder.DEFAULT_WEIGHT + || sound.attenuationDistance() != EntryBuilder.DEFAULT_ATTENUATION_DISTANCE || sound.stream() || sound.preload()) { return Either.right(sound); diff --git a/fabric-data-generation-api-v1/src/test/java/net/frabricmc/fabric/test/datagen/client/SoundsTypeBuilderTest.java b/fabric-data-generation-api-v1/src/test/java/net/fabricmc/fabric/test/datagen/client/SoundsTypeBuilderTest.java similarity index 99% rename from fabric-data-generation-api-v1/src/test/java/net/frabricmc/fabric/test/datagen/client/SoundsTypeBuilderTest.java rename to fabric-data-generation-api-v1/src/test/java/net/fabricmc/fabric/test/datagen/client/SoundsTypeBuilderTest.java index a645cde0968..2b8ad737743 100644 --- a/fabric-data-generation-api-v1/src/test/java/net/frabricmc/fabric/test/datagen/client/SoundsTypeBuilderTest.java +++ b/fabric-data-generation-api-v1/src/test/java/net/fabricmc/fabric/test/datagen/client/SoundsTypeBuilderTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.frabricmc.fabric.test.datagen.client; +package net.fabricmc.fabric.test.datagen.client; import java.util.List; import java.util.Optional; diff --git a/fabric-data-generation-api-v1/src/test/java/net/frabricmc/fabric/test/datagen/client/SoundsTypeCodecTest.java b/fabric-data-generation-api-v1/src/test/java/net/fabricmc/fabric/test/datagen/client/SoundsTypeCodecTest.java similarity index 91% rename from fabric-data-generation-api-v1/src/test/java/net/frabricmc/fabric/test/datagen/client/SoundsTypeCodecTest.java rename to fabric-data-generation-api-v1/src/test/java/net/fabricmc/fabric/test/datagen/client/SoundsTypeCodecTest.java index d0828ac8bba..75892db65e6 100644 --- a/fabric-data-generation-api-v1/src/test/java/net/frabricmc/fabric/test/datagen/client/SoundsTypeCodecTest.java +++ b/fabric-data-generation-api-v1/src/test/java/net/fabricmc/fabric/test/datagen/client/SoundsTypeCodecTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package net.frabricmc.fabric.test.datagen.client; +package net.fabricmc.fabric.test.datagen.client; import java.util.List; import java.util.Map; @@ -44,19 +44,19 @@ public class SoundsTypeCodecTest { /** - * {@link net.fabricmc.fabric.api.client.datagen.v1.provider.FabricSoundsProvider#CODEC} + * Codec copied from {@link net.fabricmc.fabric.api.client.datagen.v1.provider.FabricSoundsProvider} to use in testing, as it is not accessible. */ private static final Codec> CODEC = Codec.unboundedMap(Codec.STRING, SoundTypeBuilderImpl.SoundType.CODEC); /** - * {@link net.minecraft.client.sounds.SoundManager#GSON} + * Gson copied from {@link net.minecraft.client.sounds.SoundManager} to use in testing, as it is not accessible. */ - final Gson GSON = new GsonBuilder().registerTypeAdapter(SoundEventRegistration.class, + private static final Gson GSON = new GsonBuilder().registerTypeAdapter(SoundEventRegistration.class, new SoundEventRegistrationSerializer()).create(); /** - * {@link net.minecraft.client.sounds.SoundManager#SOUND_EVENT_REGISTRATION_TYPE} + * Type token copied from {@link net.minecraft.client.sounds.SoundManager} to use in testing, as it is not accessible. */ - final TypeToken> SOUND_EVENT_REGISTRATION_TYPE = new TypeToken<>() {}; + private static final TypeToken> SOUND_EVENT_REGISTRATION_TYPE = new TypeToken<>() { }; private static final Identifier IDENTIFIER = Identifier.fromNamespaceAndPath("datagen-test", "sound-event-registrable-codec"); @@ -141,7 +141,6 @@ private static void expectInputDataInOutput(Map Date: Sun, 7 Dec 2025 12:07:00 +0100 Subject: [PATCH 12/13] Update SoundTypeBuilder Add default implementation to deprecated method, so implementation does not need to use it anymore. --- .../api/client/datagen/v1/builder/SoundTypeBuilder.java | 4 +++- .../fabric/impl/datagen/client/SoundTypeBuilderImpl.java | 6 ------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/fabric-data-generation-api-v1/src/client/java/net/fabricmc/fabric/api/client/datagen/v1/builder/SoundTypeBuilder.java b/fabric-data-generation-api-v1/src/client/java/net/fabricmc/fabric/api/client/datagen/v1/builder/SoundTypeBuilder.java index 058afe1ba1b..711d6c2a840 100644 --- a/fabric-data-generation-api-v1/src/client/java/net/fabricmc/fabric/api/client/datagen/v1/builder/SoundTypeBuilder.java +++ b/fabric-data-generation-api-v1/src/client/java/net/fabricmc/fabric/api/client/datagen/v1/builder/SoundTypeBuilder.java @@ -67,7 +67,9 @@ static SoundTypeBuilder of() { * calling this method will have no effect. */ @Deprecated - SoundTypeBuilder category(SoundSource category); + default SoundTypeBuilder category(SoundSource category) { + return this; + } /** * Sets an optional replace boolean, which on true allows this sound type to override others. diff --git a/fabric-data-generation-api-v1/src/client/java/net/fabricmc/fabric/impl/datagen/client/SoundTypeBuilderImpl.java b/fabric-data-generation-api-v1/src/client/java/net/fabricmc/fabric/impl/datagen/client/SoundTypeBuilderImpl.java index 08401147099..f90305bacb5 100644 --- a/fabric-data-generation-api-v1/src/client/java/net/fabricmc/fabric/impl/datagen/client/SoundTypeBuilderImpl.java +++ b/fabric-data-generation-api-v1/src/client/java/net/fabricmc/fabric/impl/datagen/client/SoundTypeBuilderImpl.java @@ -33,7 +33,6 @@ import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.resources.Identifier; import net.minecraft.sounds.SoundEvent; -import net.minecraft.sounds.SoundSource; import net.fabricmc.fabric.api.client.datagen.v1.builder.SoundTypeBuilder; @@ -47,11 +46,6 @@ public final class SoundTypeBuilderImpl implements SoundTypeBuilder { public SoundTypeBuilderImpl() { } - @Override - public SoundTypeBuilder category(SoundSource category) { - return this; - } - @Override public SoundTypeBuilder replace(boolean replace) { this.replace = replace; From 61a3089acc7c2b9946dd4437ac66cdeddb64e2ad Mon Sep 17 00:00:00 2001 From: pistonpoek Date: Sun, 7 Dec 2025 21:10:51 +0100 Subject: [PATCH 13/13] Update SoundTypeBuilder.java Add for removal to category property method. --- .../fabric/api/client/datagen/v1/builder/SoundTypeBuilder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fabric-data-generation-api-v1/src/client/java/net/fabricmc/fabric/api/client/datagen/v1/builder/SoundTypeBuilder.java b/fabric-data-generation-api-v1/src/client/java/net/fabricmc/fabric/api/client/datagen/v1/builder/SoundTypeBuilder.java index 711d6c2a840..87182f73b6e 100644 --- a/fabric-data-generation-api-v1/src/client/java/net/fabricmc/fabric/api/client/datagen/v1/builder/SoundTypeBuilder.java +++ b/fabric-data-generation-api-v1/src/client/java/net/fabricmc/fabric/api/client/datagen/v1/builder/SoundTypeBuilder.java @@ -66,7 +66,7 @@ static SoundTypeBuilder of() { * @deprecated Category is not a field interpreted by vanilla in the sounds file, * calling this method will have no effect. */ - @Deprecated + @Deprecated(forRemoval = true) default SoundTypeBuilder category(SoundSource category) { return this; }