Add sound id to name mappings as generator for 1.9 thru 1.20 (#17)

* Add sound id to name mappings as generator for 1.9 thru 1.20

* Fix issues in generators

* Add generator to all versions.

* Fix versions that offset ID by one for network.
This commit is contained in:
William Gaylord
2024-03-17 16:13:19 +01:00
committed by GitHub
parent 665bf9b7c7
commit 44f49b4ab5
40 changed files with 552 additions and 2 deletions
@@ -34,6 +34,7 @@ public class DataGenerators {
// register(new RecipeDataGenerator()); - On hold until mcdata supports multiple materials for a recipe
register(new LanguageDataGenerator());
register(new InstrumentsDataGenerator());
register(new SoundsDataGenerator());
}
public static void register(IDataGenerator generator) {
@@ -0,0 +1,32 @@
package dev.u9g.minecraftdatagenerator.generators;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import net.minecraft.sound.SoundEvent;
import net.minecraft.util.registry.Registry;
public class SoundsDataGenerator implements IDataGenerator {
public static JsonObject generateSound(Registry<SoundEvent> registry, SoundEvent soundEvent) {
JsonObject soundDesc = new JsonObject();
soundDesc.addProperty("id", registry.getRawId(soundEvent)+1); // the plus 1 is required for 1.19.2+ due to Mojang using 0 in the packet to say that you should read a string id instead.
soundDesc.addProperty("name", soundEvent.getId().getPath());
return soundDesc;
}
@Override
public String getDataName() {
return "sounds";
}
@Override
public JsonArray generateDataJson() {
JsonArray resultsArray = new JsonArray();
Registry<SoundEvent> soundEventRegistry = Registry.SOUND_EVENT;
soundEventRegistry.forEach(sound -> resultsArray.add(generateSound(soundEventRegistry, sound)));
return resultsArray;
}
}