diff options
| author | Roman / Nea <roman.graef@gmail.com> | 2022-01-16 01:03:04 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-01-15 19:03:04 -0500 |
| commit | c81b6a34ae7bbb70a11f23f49422f2fceffa689c (patch) | |
| tree | 44d2f2ba99a7e1746293489ee9b00dc9c307735b /src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/customblockzones/CustomBlockSounds.java | |
| parent | 2aa911fa84399a5a8cc9f36715246c7f3eee7133 (diff) | |
| download | notenoughupdates-c81b6a34ae7bbb70a11f23f49422f2fceffa689c.tar.gz notenoughupdates-c81b6a34ae7bbb70a11f23f49422f2fceffa689c.tar.bz2 notenoughupdates-c81b6a34ae7bbb70a11f23f49422f2fceffa689c.zip | |
Add sounds and rework the existing textures to custom Dwarven Mines /… (#51)
* Pre Work of custom biomes
* Work on auto chunk update, Add Debug command
* Added 6 new biomes that are used in crystal hollows
* Made it so the biomes are registered in the main class so it loads properly
* Add sounds and rework the existing textures to custom Dwarven Mines / CH blocks
* Config fixups
* make titanium sounds work
* Added sounds per gemstone type
* fix dwarven mines sounds
* stop spamming sound effects with config
* Changelog for CH custom blocks
* add all the files
* Update src/main/resources/assets/notenoughupdates/sounds/titaniumbreak.json
* Update src/main/resources/assets/notenoughupdates/sounds/mithrilbreak.json
* Update src/main/resources/assets/notenoughupdates/sounds/gemstonetopazbreak.json
* Update src/main/resources/assets/notenoughupdates/sounds/gemstonerubybreak.json
* Update src/main/resources/assets/notenoughupdates/sounds/gemstonesapphirebreak.json
* Update src/main/resources/assets/notenoughupdates/sounds/gemstonejasperbreak.json
* Update src/main/resources/assets/notenoughupdates/sounds/gemstoneamethystbreak.json
* Update src/main/resources/assets/notenoughupdates/sounds/gemstonejadebreak.json
* Update src/main/resources/assets/notenoughupdates/sounds/gemstoneamberbreak.json
* Update src/main/java/io/github/moulberry/notenoughupdates/commands/Commands.java
* Update src/main/java/io/github/moulberry/notenoughupdates/commands/Commands.java
* Update src/main/java/io/github/moulberry/notenoughupdates/commands/Commands.java
* Update src/main/java/io/github/moulberry/notenoughupdates/commands/Commands.java
* Update src/main/java/io/github/moulberry/notenoughupdates/commands/Commands.java
* Update src/main/java/io/github/moulberry/notenoughupdates/commands/Commands.java
Co-authored-by: DoKM <mcazzyman@gmail.com>
Co-authored-by: nopothegamer <40329022+nopothegamer@users.noreply.github.com>
Co-authored-by: IRONM00N <64110067+IRONM00N@users.noreply.github.com>
Diffstat (limited to 'src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/customblockzones/CustomBlockSounds.java')
| -rw-r--r-- | src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/customblockzones/CustomBlockSounds.java | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/customblockzones/CustomBlockSounds.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/customblockzones/CustomBlockSounds.java new file mode 100644 index 00000000..45f22163 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/customblockzones/CustomBlockSounds.java @@ -0,0 +1,102 @@ +package io.github.moulberry.notenoughupdates.miscfeatures.customblockzones; + +import com.google.gson.Gson; +import com.google.gson.JsonObject; +import io.github.moulberry.notenoughupdates.NotEnoughUpdates; +import net.minecraft.client.Minecraft; +import net.minecraft.client.audio.ISound; +import net.minecraft.client.audio.PositionedSoundRecord; +import net.minecraft.client.resources.IResource; +import net.minecraft.client.resources.IResourceManager; +import net.minecraft.client.resources.IResourceManagerReloadListener; +import net.minecraft.util.ResourceLocation; + +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.Reader; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; + +public class CustomBlockSounds { + + static Gson gson = new Gson(); + + static List<CustomSoundEvent> allCustomSoundEvents = new ArrayList<>(); + + public static final CustomSoundEvent mithrilBreak = newCustomSoundEvent("mithril"); + public static final CustomSoundEvent gemstoneBreakRuby = newCustomSoundEvent("gemstoneRuby"); + public static final CustomSoundEvent gemstoneBreakAmber = newCustomSoundEvent("gemstoneAmber"); + public static final CustomSoundEvent gemstoneBreakAmethyst = newCustomSoundEvent("gemstoneAmethyst"); + public static final CustomSoundEvent gemstoneBreakSapphire = newCustomSoundEvent("gemstoneSapphire"); + public static final CustomSoundEvent gemstoneBreakJade = newCustomSoundEvent("gemstoneJade"); + public static final CustomSoundEvent gemstoneBreakTopaz = newCustomSoundEvent("gemstoneTopaz"); + public static final CustomSoundEvent gemstoneBreakJasper = newCustomSoundEvent("gemstoneJasper"); + public static final CustomSoundEvent titaniumBreak = newCustomSoundEvent("titanium"); + + + public static class ReloaderListener implements IResourceManagerReloadListener { + @Override + public void onResourceManagerReload(IResourceManager iResourceManager) { + allCustomSoundEvents.forEach(CustomSoundEvent::reload); + } + } + + public static class CustomSoundEvent { + public ResourceLocation soundEvent; + public ResourceLocation configFile; + private boolean loaded = false; + private int timer = 0; + private long lastReplaced = 0L; + + public CustomSoundEvent() { + allCustomSoundEvents.add(this); + } + + public boolean shouldReplace() { + if (!loaded) reload(); + if (timer < 0) return true; + long now = System.currentTimeMillis(); + if (now - lastReplaced >= timer) { + lastReplaced = now; + return true; + } + return false; + } + + public ISound replaceSoundEvent(ISound sound) { + return new PositionedSoundRecord( + this.soundEvent, + sound.getPitch(), sound.getVolume(), + sound.getXPosF(), sound.getYPosF(), sound.getZPosF() + ); + } + + public void reload() { + loaded = true; + IResource resource; + try { + resource = Minecraft.getMinecraft().getResourceManager().getResource(configFile); + } catch (IOException e) { + timer = -1; + return; + } + try (Reader r = new InputStreamReader(resource.getInputStream(), StandardCharsets.UTF_8)) { + JsonObject jsonObject = gson.fromJson(r, JsonObject.class); + timer = jsonObject.getAsJsonPrimitive("debouncer").getAsInt() * 1000 / 20; + } catch (IOException e) { + e.printStackTrace(); + } + } + + } + + private static CustomSoundEvent newCustomSoundEvent(String soundEvent) { + CustomSoundEvent event = new CustomSoundEvent(); + event.soundEvent = new ResourceLocation("notenoughupdates", soundEvent + ".break"); + event.configFile = new ResourceLocation("notenoughupdates", "sounds/" + soundEvent.toLowerCase(Locale.ROOT) + "break.json"); + return event; + } + +} |
