/* * Decompiled with CFR 0.152. * * Could not load the following classes: * net.minecraft.nbt.CompoundNBT */ package com.example.soundmod.common; import com.example.soundmod.common.ActivationMode; import com.example.soundmod.common.AttenuationMode; import com.example.soundmod.common.RedstoneMode; import net.minecraft.nbt.CompoundNBT; public class SoundSettings { public String soundId = ""; public float volume = 1.0f; public float pitch = 1.0f; public float radius = 16.0f; public boolean loop; public int startDelayTicks; public int repeatDelayTicks; public AttenuationMode attenuationMode = AttenuationMode.LINEAR; public String category = "ambient"; public int priority; public boolean use3d = true; public boolean doppler; public boolean occlusion; public boolean reverb; public float reverbStrength; public float occlusionStrength; public int fadeInTicks; public int fadeOutTicks; public boolean crossfade; public ActivationMode activationMode = ActivationMode.CLICK; public RedstoneMode redstoneMode = RedstoneMode.EDGE; public PitchModulationMode pitchMode = PitchModulationMode.STATIC; public float pitchModSpeed = 1.0f; public float pitchModDepth = 0.25f; public CompoundNBT toNbt() { CompoundNBT tag = new CompoundNBT(); tag.putString("soundId", this.soundId); tag.putFloat("volume", this.volume); tag.putFloat("pitch", this.pitch); tag.putFloat("radius", this.radius); tag.putBoolean("loop", this.loop); tag.putInt("startDelayTicks", this.startDelayTicks); tag.putInt("repeatDelayTicks", this.repeatDelayTicks); tag.putString("attenuationMode", this.attenuationMode.name()); tag.putString("category", this.category); tag.putInt("priority", this.priority); tag.putBoolean("use3d", this.use3d); tag.putBoolean("doppler", this.doppler); tag.putBoolean("occlusion", this.occlusion); tag.putBoolean("reverb", this.reverb); tag.putFloat("reverbStrength", this.reverbStrength); tag.putFloat("occlusionStrength", this.occlusionStrength); tag.putInt("fadeInTicks", this.fadeInTicks); tag.putInt("fadeOutTicks", this.fadeOutTicks); tag.putBoolean("crossfade", this.crossfade); tag.putString("activationMode", this.activationMode.name()); tag.putString("redstoneMode", this.redstoneMode.name()); tag.putString("pitchMode", this.pitchMode.name()); tag.putFloat("pitchModSpeed", this.pitchModSpeed); tag.putFloat("pitchModDepth", this.pitchModDepth); return tag; } public static SoundSettings fromNbt(CompoundNBT tag) { SoundSettings s = new SoundSettings(); if (tag.contains("soundId")) { s.soundId = tag.getString("soundId"); } if (tag.contains("volume")) { s.volume = tag.getFloat("volume"); } if (tag.contains("pitch")) { s.pitch = tag.getFloat("pitch"); } if (tag.contains("radius")) { s.radius = tag.getFloat("radius"); } if (tag.contains("loop")) { s.loop = tag.getBoolean("loop"); } if (tag.contains("startDelayTicks")) { s.startDelayTicks = tag.getInt("startDelayTicks"); } if (tag.contains("repeatDelayTicks")) { s.repeatDelayTicks = tag.getInt("repeatDelayTicks"); } if (tag.contains("attenuationMode")) { s.attenuationMode = SoundSettings.parse(tag.getString("attenuationMode"), AttenuationMode.LINEAR); } if (tag.contains("category")) { s.category = tag.getString("category"); } if (tag.contains("priority")) { s.priority = tag.getInt("priority"); } if (tag.contains("use3d")) { s.use3d = tag.getBoolean("use3d"); } if (tag.contains("doppler")) { s.doppler = tag.getBoolean("doppler"); } if (tag.contains("occlusion")) { s.occlusion = tag.getBoolean("occlusion"); } if (tag.contains("reverb")) { s.reverb = tag.getBoolean("reverb"); } if (tag.contains("reverbStrength")) { s.reverbStrength = tag.getFloat("reverbStrength"); } if (tag.contains("occlusionStrength")) { s.occlusionStrength = tag.getFloat("occlusionStrength"); } if (tag.contains("fadeInTicks")) { s.fadeInTicks = tag.getInt("fadeInTicks"); } if (tag.contains("fadeOutTicks")) { s.fadeOutTicks = tag.getInt("fadeOutTicks"); } if (tag.contains("crossfade")) { s.crossfade = tag.getBoolean("crossfade"); } if (tag.contains("activationMode")) { s.activationMode = SoundSettings.parse(tag.getString("activationMode"), ActivationMode.CLICK); } if (tag.contains("redstoneMode")) { s.redstoneMode = SoundSettings.parse(tag.getString("redstoneMode"), RedstoneMode.EDGE); } if (tag.contains("pitchMode")) { s.pitchMode = SoundSettings.parse(tag.getString("pitchMode"), PitchModulationMode.STATIC); } if (tag.contains("pitchModSpeed")) { s.pitchModSpeed = tag.getFloat("pitchModSpeed"); } if (tag.contains("pitchModDepth")) { s.pitchModDepth = tag.getFloat("pitchModDepth"); } SoundSettings.sanitizeInPlace(s); return s; } public static SoundSettings sanitizedCopy(SoundSettings source) { SoundSettings copy = SoundSettings.fromNbt(source.toNbt()); SoundSettings.sanitizeInPlace(copy); return copy; } private static void sanitizeInPlace(SoundSettings s) { if (s.soundId == null) { s.soundId = ""; } if (!Float.isFinite(s.volume) || s.volume < 0.0f || s.volume > 8.0f) { s.volume = 1.0f; } if (!Float.isFinite(s.pitch) || s.pitch < 0.05f || s.pitch > 4.0f) { s.pitch = 1.0f; } if (!Float.isFinite(s.radius) || s.radius < 0.1f || s.radius > 512.0f) { s.radius = 16.0f; } if (!Float.isFinite(s.reverbStrength) || s.reverbStrength < 0.0f || s.reverbStrength > 1.0f) { s.reverbStrength = 0.0f; } if (!Float.isFinite(s.occlusionStrength) || s.occlusionStrength < 0.0f || s.occlusionStrength > 1.0f) { s.occlusionStrength = 0.0f; } if (s.reverb && s.reverbStrength <= 0.01f) { s.reverbStrength = 0.45f; } if (s.occlusion && s.occlusionStrength <= 0.01f) { s.occlusionStrength = 0.65f; } if (s.startDelayTicks < 0) { s.startDelayTicks = 0; } if (s.repeatDelayTicks < 0) { s.repeatDelayTicks = 0; } if (s.fadeInTicks < 0) { s.fadeInTicks = 0; } if (s.fadeOutTicks < 0) { s.fadeOutTicks = 0; } if (s.redstoneMode == null) { s.redstoneMode = RedstoneMode.EDGE; } if (s.pitchMode == null) { s.pitchMode = PitchModulationMode.STATIC; } if (!Float.isFinite(s.pitchModSpeed) || s.pitchModSpeed < 0.05f || s.pitchModSpeed > 20.0f) { s.pitchModSpeed = 1.0f; } if (!Float.isFinite(s.pitchModDepth) || s.pitchModDepth < 0.0f || s.pitchModDepth > 2.0f) { s.pitchModDepth = 0.25f; } } private static > E parse(String raw, E fallback) { try { return Enum.valueOf(fallback.getDeclaringClass(), raw); } catch (Exception ignored) { return fallback; } } }