-
Notifications
You must be signed in to change notification settings - Fork 508
Update sounds.json data generation to match vanilla #5030
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 13 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
873d0cb
Update sound type builder
pistonpoek d84c0d8
Update SoundTypeBuilder.java
pistonpoek ec2ed01
Update SoundTypeBuilderImpl.java
pistonpoek 8544dae
Deprecate category field
pistonpoek 52aaecd
Add sounds type tests
pistonpoek 294c1c3
Merge branch '1.21.11' of https://github.com/pistonpoek/fabric into 1…
pistonpoek 3eb31f0
Update SoundTypeBuilder.java
pistonpoek d08d29c
Update SoundsTypeBuilderTest.java
pistonpoek 3dea637
Update SoundTypeBuilder.java
pistonpoek 8238438
Update SoundTypeBuilderImpl.java
pistonpoek aba3ed7
Add licences
pistonpoek 25e8189
Fix check issues
pistonpoek 778cffe
Update SoundTypeBuilder
pistonpoek 61a3089
Update SoundTypeBuilder.java
pistonpoek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
162 changes: 162 additions & 0 deletions
162
...n-api-v1/src/test/java/net/fabricmc/fabric/test/datagen/client/SoundsTypeBuilderTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,162 @@ | ||
| /* | ||
| * 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.fabricmc.fabric.test.datagen.client; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Optional; | ||
|
|
||
| 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 net.fabricmc.fabric.api.client.datagen.v1.builder.SoundTypeBuilder; | ||
| import net.fabricmc.fabric.impl.datagen.client.SoundTypeBuilderImpl; | ||
|
|
||
| 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 | ||
| */ | ||
| 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 | ||
| */ | ||
| 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()); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe use
@Deprecated(forRemoval = true)if we know its tottaly broken?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, seems sensible to eventually want to get rid of it. I will add a commit for it.