aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/customblockzones/CustomBlockSounds.java
diff options
context:
space:
mode:
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.java156
1 files changed, 79 insertions, 77 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
index 45f22163..dec011d3 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/customblockzones/CustomBlockSounds.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/customblockzones/CustomBlockSounds.java
@@ -21,82 +21,84 @@ 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;
- }
+ 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;
+ }
}