package mtr.sound.bve;

import mtr.mappings.Utilities;
import mtr.mappings.UtilitiesClient;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.resources.Resource;
import net.minecraft.server.packs.resources.ResourceManager;
import org.apache.commons.io.IOUtils;

import java.nio.charset.StandardCharsets;
import java.util.List;

public class BveTrainSoundConfig {

	public final String baseName;
	public final String audioBaseName;
	public final ConfigFile soundCfg;
	public final MotorDataBase motorData;

	public BveTrainSoundConfig(ResourceManager manager, String baseName) {
		this.baseName = baseName;
		final String configBaseName = "mtr:sounds/" + baseName;
		audioBaseName = "mtr:" + baseName + "_";
		soundCfg = new ConfigFile(readResource(manager, new ResourceLocation(configBaseName + "/sound.cfg")), this);
		if (soundCfg.motorNoiseDataType == 4) {
			motorData = new MotorData4(manager, configBaseName);
		} else {
			motorData = new MotorData5(manager, configBaseName);
		}
	}

	public static String readResource(ResourceManager manager, ResourceLocation location) {
		try {
			final List<Resource> resources = UtilitiesClient.getResources(manager, location);
			if (resources.size() < 1) {
				return "";
			}
			return IOUtils.toString(Utilities.getInputStream(resources.get(0)), StandardCharsets.UTF_8);
		} catch (Exception e) {
			return "";
		}
	}
}

@@ -610,127 +610,336 @@
 %7B%0A%09%09
-this.baseName = baseName;%0A%09%09final String configBaseName = %22mtr:sounds/%22 + baseName;%0A%09%09audioBaseName = %22mtr:%22 + baseName
+ResourceLocation baseLocation = new ResourceLocation(baseName.contains(%22:%22) ? baseName : %22mtr:%22 + baseName);%0A%0A%09%09this.baseName = baseLocation.toString();%0A%09%09final String configBaseName = baseLocation.getNamespace() + %22:sounds/%22 + baseLocation.getPath();%0A%09%09audioBaseName = baseLocation.getNamespace() + %22:%22 + baseLocation.getPath()
  + %22

Add support for BVE sound from other namespaces