| 1 | package net.minecraft.client.audio;
|
| 2 |
|
| 3 | import com.google.gson.JsonArray;
|
| 4 | import com.google.gson.JsonDeserializationContext;
|
| 5 | import com.google.gson.JsonDeserializer;
|
| 6 | import com.google.gson.JsonElement;
|
| 7 | import com.google.gson.JsonObject;
|
| 8 | import com.google.gson.JsonParseException;
|
| 9 | import java.lang.reflect.Type;
|
| 10 | import net.minecraft.util.JsonUtils;
|
| 11 | import org.apache.commons.lang3.Validate;
|
| 12 |
|
| 13 | public class SoundListSerializer implements JsonDeserializer<SoundList>
|
| 14 | {
|
| 15 | public SoundList deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException
|
| 16 | {
|
| 17 | JsonObject jsonobject = JsonUtils.getJsonObject(p_deserialize_1_, "entry");
|
| 18 | SoundList soundlist = new SoundList();
|
| 19 | soundlist.setReplaceExisting(JsonUtils.getBoolean(jsonobject, "replace", false));
|
| 20 | SoundCategory soundcategory = SoundCategory.getCategory(JsonUtils.getString(jsonobject, "category", SoundCategory.MASTER.getCategoryName()));
|
| 21 | soundlist.setSoundCategory(soundcategory);
|
| 22 | Validate.notNull(soundcategory, "Invalid category", new Object[0]);
|
| 23 |
|
| 24 | if (jsonobject.has("sounds"))
|
| 25 | {
|
| 26 | JsonArray jsonarray = JsonUtils.getJsonArray(jsonobject, "sounds");
|
| 27 |
|
| 28 | for (int i = 0; i < jsonarray.size(); ++i)
|
| 29 | {
|
| 30 | JsonElement jsonelement = jsonarray.get(i);
|
| 31 | SoundList.SoundEntry soundlist$soundentry = new SoundList.SoundEntry();
|
| 32 |
|
| 33 | if (JsonUtils.isString(jsonelement))
|
| 34 | {
|
| 35 | soundlist$soundentry.setSoundEntryName(JsonUtils.getString(jsonelement, "sound"));
|
| 36 | }
|
| 37 | else
|
| 38 | {
|
| 39 | JsonObject jsonobject1 = JsonUtils.getJsonObject(jsonelement, "sound");
|
| 40 | soundlist$soundentry.setSoundEntryName(JsonUtils.getString(jsonobject1, "name"));
|
| 41 |
|
| 42 | if (jsonobject1.has("type"))
|
| 43 | {
|
| 44 | SoundList.SoundEntry.Type soundlist$soundentry$type = SoundList.SoundEntry.Type.getType(JsonUtils.getString(jsonobject1, "type"));
|
| 45 | Validate.notNull(soundlist$soundentry$type, "Invalid type", new Object[0]);
|
| 46 | soundlist$soundentry.setSoundEntryType(soundlist$soundentry$type);
|
| 47 | }
|
| 48 |
|
| 49 | if (jsonobject1.has("volume"))
|
| 50 | {
|
| 51 | float f = JsonUtils.getFloat(jsonobject1, "volume");
|
| 52 | Validate.isTrue(f > 0.0F, "Invalid volume", new Object[0]);
|
| 53 | soundlist$soundentry.setSoundEntryVolume(f);
|
| 54 | }
|
| 55 |
|
| 56 | if (jsonobject1.has("pitch"))
|
| 57 | {
|
| 58 | float f1 = JsonUtils.getFloat(jsonobject1, "pitch");
|
| 59 | Validate.isTrue(f1 > 0.0F, "Invalid pitch", new Object[0]);
|
| 60 | soundlist$soundentry.setSoundEntryPitch(f1);
|
| 61 | }
|
| 62 |
|
| 63 | if (jsonobject1.has("weight"))
|
| 64 | {
|
| 65 | int j = JsonUtils.getInt(jsonobject1, "weight");
|
| 66 | Validate.isTrue(j > 0, "Invalid weight", new Object[0]);
|
| 67 | soundlist$soundentry.setSoundEntryWeight(j);
|
| 68 | }
|
| 69 |
|
| 70 | if (jsonobject1.has("stream"))
|
| 71 | {
|
| 72 | soundlist$soundentry.setStreaming(JsonUtils.getBoolean(jsonobject1, "stream"));
|
| 73 | }
|
| 74 | }
|
| 75 |
|
| 76 | soundlist.getSoundList().add(soundlist$soundentry);
|
| 77 | }
|
| 78 | }
|
| 79 |
|
| 80 | return soundlist;
|
| 81 | }
|
| 82 | }
|
| 83 |
|