Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 25 additions & 18 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
plugins {
id 'fabric-loom' version "${loom_version}"
id 'fabric-loom' version '1.14.10'
id 'maven-publish'
}

version = project.mod_version
group = project.maven_group

base {
archivesName = project.archives_base_name
archivesName = project.archivesBaseName
}

repositories {
// Add repositories to retrieve artifacts from in here.
// You should only use this when depending on other mods because
// Loom adds the essential maven repositories to download Minecraft and libraries from automatically.
// See https://docs.gradle.org/current/userguide/declaring_repositories.html
// for more information about repositories.
maven { url = "https://api.modrinth.com/maven" }
maven { url = "https://maven.terraformersmc.com/" } // Mod Menu
exclusiveContent {
forRepository {
maven {
name = "Terraformers"
url = "https://maven.terraformersmc.com/"
}
}
filter {
includeGroup 'com.terraformersmc'
}
}
// Fallback
mavenCentral()
}

dependencies {
Expand All @@ -26,20 +32,21 @@ dependencies {
mappings loom.officialMojangMappings()
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"

// Fabric API. This is technically optional, but you probably want it anyway.
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_api_version}"

// Tells Gradle to use mod menu
modImplementation "com.terraformersmc:modmenu:${project.modmenu_version}", {
exclude module: 'fabric-api'
}
modLocalRuntime(modCompileOnly "com.terraformersmc:modmenu:${project.modmenu_version}")
}

processResources {
inputs.property "version", project.version

filesMatching("fabric.mod.json") {
expand "version": project.version
expand "version": project.version,
"id": project.archivesBaseName,
"minecraft_version": project.minecraft_version,
"loader_version": project.loader_version,
"fabric_api_version": project.fabric_api_version,
"modmenu_version": project.modmenu_version
}
}

Expand Down Expand Up @@ -67,7 +74,7 @@ jar {
publishing {
publications {
create("mavenJava", MavenPublication) {
artifactId = project.archives_base_name
artifactId = project.archivesBaseName
from components.java
}
}
Expand All @@ -79,4 +86,4 @@ publishing {
// The repositories here will be used for publishing your artifact, not for
// retrieving dependencies.
}
}
}
14 changes: 6 additions & 8 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,17 @@ org.gradle.jvmargs=-Xmx1G
org.gradle.parallel=true

# Mod Properties
mod_version = 1.2.4
maven_group = com.bvengo
archives_base_name = soundcontroller
mod_version=1.2.5
maven_group=com.bvengo
archivesBaseName=soundcontroller

# Versioning
## Fabric: https://fabricmc.net/develop
## ModMenu: https://maven.terraformersmc.com/com/terraformersmc/modmenu

modmenu_version=17.0.0-alpha.1
modmenu_version=17.0.0-beta.1

minecraft_version=1.21.11
loader_version=0.18.1
loom_version=1.13-SNAPSHOT
loader_version=0.18.4

# Fabric API
fabric_version=0.139.4+1.21.11
fabric_api_version=0.139.4+1.21.11
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
9 changes: 3 additions & 6 deletions gradlew

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions gradlew.bat

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 6 additions & 8 deletions src/main/java/com/bvengo/soundcontroller/SoundController.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
package com.bvengo.soundcontroller;

import net.fabricmc.fabric.api.resource.v1.ResourceLoader;
import net.minecraft.server.packs.PackType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.bvengo.soundcontroller.config.VolumeConfig;

import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents;
import net.fabricmc.fabric.api.resource.v1.ResourceLoader;
import net.minecraft.server.packs.PackType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Environment(EnvType.CLIENT)
public class SoundController implements ClientModInitializer {
Expand All @@ -26,8 +24,8 @@ public void onInitializeClient() {
});

ResourceLoader.get(PackType.CLIENT_RESOURCES)
.registerReloader(SoundReloadListener.ID, new SoundReloadListener());
.registerReloader(SoundReloadListener.ID, new SoundReloadListener());

LOGGER.info("{} loaded.", LOGGER.getName());
LOGGER.info("{} loaded", LOGGER.getName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@ public class SoundReloadListener implements ResourceManagerReloadListener {
/**
* Invoked every time client resources are reloaded
* (e.g. F3+T, resource pack change, initial load).
*
* @param resourceManager the active resource manager
*/
@Override
public void onResourceManagerReload(final @NotNull ResourceManager resourceManager) {
if (SoundController.CONFIG == null) {
return;
}

SoundController.CONFIG.updateVolumes();
SoundController.CONFIG.reload();
}
}
28 changes: 14 additions & 14 deletions src/main/java/com/bvengo/soundcontroller/Translations.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
import net.minecraft.network.chat.Component;

public abstract class Translations {
// Text constants
public static final Component SOUND_SCREEN_TITLE = translatableOf("title");
public static final Component SEARCH_FIELD_PLACEHOLDER = translatableOf("search.placeholder");
public static final Component SEARCH_FIELD_TITLE = translatableOf("search.title");
public static final Component FILTER_BUTTON_TOOLTIP = translatableOf("filter.tooltip");
public static final Component SUBTITLES_BUTTON_TOOLTIP = translatableOf("subtitles.tooltip");
public static final Component RESET_BUTTON_TOOLTIP = translatableOf("reset.tooltip");
public static final Component PLAY_BUTTON_TOOLTIP = translatableOf("play.tooltip");
// Text constants
public static final Component SOUND_SCREEN_TITLE = translatableOf("title");
public static final Component SEARCH_FIELD_PLACEHOLDER = translatableOf("search.placeholder");
public static final Component SEARCH_FIELD_TITLE = translatableOf("search.title");
public static final Component FILTER_BUTTON_TOOLTIP = translatableOf("filter.tooltip");
public static final Component SUBTITLES_BUTTON_TOOLTIP = translatableOf("subtitles.tooltip");
public static final Component RESET_BUTTON_TOOLTIP = translatableOf("reset.tooltip");
public static final Component PLAY_BUTTON_TOOLTIP = translatableOf("play.tooltip");

public static Component translatableOf(String key) {
return Component.translatable(getTranslationKey(key));
}
public static Component translatableOf(String key) {
return Component.translatable(getTranslationKey(key));
}

public static String getTranslationKey(String key) {
return SoundController.MOD_ID + ".options." + key;
}
public static String getTranslationKey(String key) {
return SoundController.MOD_ID + ".options." + key;
}
}
10 changes: 0 additions & 10 deletions src/main/java/com/bvengo/soundcontroller/Utils.java

This file was deleted.

69 changes: 20 additions & 49 deletions src/main/java/com/bvengo/soundcontroller/VolumeData.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
package com.bvengo.soundcontroller;

import net.minecraft.client.Minecraft;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.client.resources.sounds.SimpleSoundInstance;
import net.minecraft.client.resources.sounds.SoundInstance;
import net.minecraft.client.sounds.SoundManager;
import net.minecraft.resources.Identifier;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundSource;
import net.minecraft.util.RandomSource;

import java.util.Objects;

public class VolumeData {
public static final Float DEFAULT_VOLUME = 1.0f;

private final Identifier soundId;
private Float volume;

private SimpleSoundInstance currentSoundInstance = null;
private float volume;

public VolumeData(Identifier id, float volume) {
this.soundId = id;
Expand All @@ -28,58 +20,37 @@ public VolumeData(Identifier id) {
}

public Identifier getId() {
return soundId;
return this.soundId;
}

public Float getVolume() {
return volume;
public float getVolume() {
return this.volume;
}

public void setVolume(float volume) {
this.volume = volume;
}

public boolean isModified() {
return !this.volume.equals(DEFAULT_VOLUME);
return !Objects.equals(DEFAULT_VOLUME, this.volume);
}

public boolean inFilter(String search, boolean showModifiedOnly) {
return (this.soundId.toString().toLowerCase().contains(search) &&
(!showModifiedOnly || this.isModified()));
return this.soundId.toString().toLowerCase().contains(search) &&
(!showModifiedOnly || this.isModified());
}

public void playSound(SoundManager soundManager) {
final LocalPlayer player = Minecraft.getInstance().player;
SoundEvent soundEvent = SoundEvent.createVariableRangeEvent(soundId);

if (player != null) {
this.currentSoundInstance = new SimpleSoundInstance(
soundEvent, SoundSource.MASTER,
this.volume, // Volume
1.0f, // Pitch
RandomSource.create(),
player.getX(), player.getY(), player.getZ() // Position
);
} else {
this.currentSoundInstance = SimpleSoundInstance.forUI(
soundEvent,
this.volume // Volume
);
}
@Override
public final boolean equals(Object o) {
if (!(o instanceof VolumeData that)) return false;

soundManager.play(this.currentSoundInstance);
return Objects.equals(this.soundId, that.soundId) && Objects.equals(this.getVolume(), that.getVolume());
}

public void toggleSound(SoundManager soundManager) {
if (isActive(soundManager)) {
soundManager.stop(currentSoundInstance);
currentSoundInstance = null;
} else {
playSound(soundManager);
}
}

public boolean isActive(SoundManager soundManager) {
return soundManager.isActive(currentSoundInstance);
}
}
@Override
public int hashCode() {
int result = Objects.hashCode(this.soundId);
result = 31 * result + Objects.hashCode(this.getVolume());
return result;
}
}
Loading