Skip to content

Commit

Permalink
Add Set Volume effect
Browse files Browse the repository at this point in the history
  • Loading branch information
MoSadie committed Nov 11, 2024
1 parent 1253a16 commit 17aaed4
Show file tree
Hide file tree
Showing 47 changed files with 922 additions and 42 deletions.
2 changes: 1 addition & 1 deletion MinecraftMod/core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
id 'application'
}

version = 3.0
version = '3.1.0'
group = 'com.mosadie.effectmc'
archivesBaseName = "EffectMC-Core"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,6 @@ public interface EffectExecutor {
String getSPWorldName();

String getServerIP();

void setVolume(SetVolumeEffect.VOLUME_CATEGORIES category, int volume);
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public EffectMCCore(File configFile, File trustFile, EffectExecutor executor) {
registerEffect(new SetRenderDistanceEffect());
registerEffect(new RejoinEffect());
registerEffect(new ShowItemToastEffect());
registerEffect(new SetVolumeEffect());

effectHandler = new EffectHandler(this, effectMap);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package com.mosadie.effectmc.core.effect;

import com.mosadie.effectmc.core.EffectMCCore;
import com.mosadie.effectmc.core.effect.internal.Effect;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class SetVolumeEffect extends Effect {

private final static int MAX_VOLUME = 100;
private final static int MIN_VOLUME = 0;

public SetVolumeEffect() {
super();
getPropertyManager().addIntegerProperty("volume", 100, true, "Volume", "100");
getPropertyManager().addCommentProperty("Use whole numbers between 0 and 100.");
getPropertyManager().addSelectionProperty("category", VOLUME_CATEGORIES.MASTER.toString(), true, "Category", VOLUME_CATEGORIES.toStringArray());
getPropertyManager().lock();
}
@Override
public String getEffectName() {
return "Set Volume";
}

@Override
public String getEffectTooltip() {
return "Set the volume of a specific category.";
}

@Override
public EffectResult execute(EffectMCCore core, Map<String, Object> args) {
if (!getPropertyManager().argumentCheck(args)) {
return new EffectResult("Invalid Arguments", EffectResult.Result.ERROR);
}

int volume = getPropAsInt(args, "volume");
VOLUME_CATEGORIES category = VOLUME_CATEGORIES.getFromName(getPropAsString(args, "category"));

if (category == null) {
return new EffectResult("Invalid category", EffectResult.Result.ERROR);
}

volume = Math.min(MAX_VOLUME, Math.max(MIN_VOLUME, volume));

core.getExecutor().setVolume(category, volume);
return new EffectResult("Set volume of " + category + " to " + volume, EffectResult.Result.SUCCESS);
}

public enum VOLUME_CATEGORIES {
MASTER,
MUSIC,
RECORDS,
WEATHER,
BLOCKS,
HOSTILE,
NEUTRAL,
PLAYERS,
AMBIENT,
VOICE;

public static VOLUME_CATEGORIES getFromName(String name) {
try {
return VOLUME_CATEGORIES.valueOf(name);
} catch (IllegalArgumentException e) {
return null;
}
}

public static String[] toStringArray() {
List<String> list = new ArrayList<>();
for (VOLUME_CATEGORIES category : VOLUME_CATEGORIES.values()) {
list.add(category.name());
}
return list.toArray(new String[0]);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ public EffectResult execute(EffectMCCore core, Map<String, Object> args) {
return new EffectResult("Invalid Arguments", EffectResult.Result.ERROR);
}

VISIBILITY visibility = VISIBILITY.valueOf(getPropAsString(args, "visibility"));
SKIN_SECTION section = SKIN_SECTION.valueOf(getPropAsString(args, "section"));
VISIBILITY visibility = VISIBILITY.getFromName(getPropAsString(args, "visibility"));
SKIN_SECTION section = SKIN_SECTION.getFromName(getPropAsString(args, "section"));

if (visibility == VISIBILITY.TOGGLE) {
if (core.getExecutor().toggleSkinLayer(section))
if (section != null && core.getExecutor().toggleSkinLayer(section))
return new EffectResult("Toggled " + section + " skin section", EffectResult.Result.SUCCESS);
else
return new EffectResult("Failed to toggle skin section.", EffectResult.Result.ERROR);
} else {
if (core.getExecutor().setSkinLayer(section, visibility == VISIBILITY.SHOW))
if (section != null && core.getExecutor().setSkinLayer(section, visibility == VISIBILITY.SHOW))
return new EffectResult("Set " + section + " to " + visibility, EffectResult.Result.SUCCESS);
else
return new EffectResult("Failed to set skin section visibility.", EffectResult.Result.ERROR);
Expand Down Expand Up @@ -89,5 +89,13 @@ public static String[] toStringArray() {
}
return list.toArray(new String[0]);
}

public static VISIBILITY getFromName(String name) {
try {
return VISIBILITY.valueOf(name.toUpperCase());
} catch (IllegalArgumentException e) {
return null;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public enum Result {
SKIPPED,
UNAUTHORIZED,
ERROR,
UNSUPPORTED,
UNKNOWN
}

Expand All @@ -42,7 +43,7 @@ public boolean isSuccess() {
}

public boolean isError() {
return result == Result.ERROR || result == Result.UNAUTHORIZED || result == Result.SKIPPED;
return result == Result.ERROR || result == Result.UNAUTHORIZED || result == Result.SKIPPED || result == Result.UNKNOWN || result == Result.UNSUPPORTED;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ public Effect.EffectResult handleRequest(Device device, EffectRequest request) {
}

// Execute the effect
return effect.execute(core, request.getArgs());
Effect.EffectResult result = effect.execute(core, request.getArgs());
core.getExecutor().log("Effect Result: (" + result.result.name() + ") " + result.message);
return result;
}

public static class EffectTranslatableComponent {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ public void handle(HttpExchange exchange) throws IOException {
case SUCCESS:
status = 200;
break;
case UNSUPPORTED:
status = 501;
break;
}

// Send response
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ public void handle(HttpExchange exchange) throws IOException {
case SUCCESS:
status = 200;
break;
case UNSUPPORTED:
status = 501;
break;
}

// Send response
Expand Down
4 changes: 2 additions & 2 deletions MinecraftMod/fabric/1.16.4/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ org.gradle.jvmargs=-Xmx1G
loader_version=0.14.8

# Mod Properties
mod_version = 3.0.0
mod_version = 3.1.0
maven_group = com.mosadie.effectmc
archives_base_name = effectmc-fabric-1.16.4

# Dependencies
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api
fabric_version=0.42.0+1.16

effectmc_core_version=3.0
effectmc_core_version=3.1.0
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,62 @@ public String getServerIP() {
return null;
}

@Override
public void setVolume(SetVolumeEffect.VOLUME_CATEGORIES category, int volume) {
MinecraftClient.getInstance().execute(() -> {
SoundCategory mcCategory;

switch (category) {
case MASTER:
mcCategory = SoundCategory.MASTER;
break;

case MUSIC:
mcCategory = SoundCategory.MUSIC;
break;

case RECORDS:
mcCategory = SoundCategory.RECORDS;
break;

case WEATHER:
mcCategory = SoundCategory.WEATHER;
break;

case BLOCKS:
mcCategory = SoundCategory.BLOCKS;
break;

case HOSTILE:
mcCategory = SoundCategory.HOSTILE;
break;

case NEUTRAL:
mcCategory = SoundCategory.NEUTRAL;
break;

case PLAYERS:
mcCategory = SoundCategory.PLAYERS;
break;

case AMBIENT:
mcCategory = SoundCategory.AMBIENT;
break;

case VOICE:
mcCategory = SoundCategory.VOICE;
break;

default:
LOGGER.error("Unknown volume category!");
return;
}

MinecraftClient.getInstance().options.setSoundVolume(mcCategory, (volume / 100.0f));
MinecraftClient.getInstance().options.write();
});
}

private void connectIfTrue(boolean connect) {
if (connect) {
joinServer(serverInfo.address);
Expand Down
4 changes: 2 additions & 2 deletions MinecraftMod/fabric/1.17.1/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ org.gradle.jvmargs=-Xmx1G
loader_version=0.14.8

# Mod Properties
mod_version = 3.0.0
mod_version = 3.1.0
maven_group = com.mosadie.effectmc
archives_base_name = effectmc-fabric-1.17.1

# Dependencies
fabric_version=0.46.1+1.17

effectmc_core_version=3.0
effectmc_core_version=3.1.0
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,62 @@ public String getServerIP() {
return null;
}

@Override
public void setVolume(SetVolumeEffect.VOLUME_CATEGORIES category, int volume) {
MinecraftClient.getInstance().execute(() -> {
SoundCategory mcCategory;

switch (category) {
case MASTER:
mcCategory = SoundCategory.MASTER;
break;

case MUSIC:
mcCategory = SoundCategory.MUSIC;
break;

case RECORDS:
mcCategory = SoundCategory.RECORDS;
break;

case WEATHER:
mcCategory = SoundCategory.WEATHER;
break;

case BLOCKS:
mcCategory = SoundCategory.BLOCKS;
break;

case HOSTILE:
mcCategory = SoundCategory.HOSTILE;
break;

case NEUTRAL:
mcCategory = SoundCategory.NEUTRAL;
break;

case PLAYERS:
mcCategory = SoundCategory.PLAYERS;
break;

case AMBIENT:
mcCategory = SoundCategory.AMBIENT;
break;

case VOICE:
mcCategory = SoundCategory.VOICE;
break;

default:
LOGGER.error("Unknown volume category!");
return;
}

MinecraftClient.getInstance().options.setSoundVolume(mcCategory, (volume / 100.0f));
MinecraftClient.getInstance().options.write();
});
}

private void connectIfTrue(boolean connect) {
if (connect) {
joinServer(serverInfo.address);
Expand Down
4 changes: 2 additions & 2 deletions MinecraftMod/fabric/1.18.2/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ org.gradle.jvmargs=-Xmx1G
loader_version=0.14.8

# Mod Properties
mod_version = 3.0.0
mod_version = 3.1.0
maven_group = com.mosadie.effectmc
archives_base_name = effectmc-fabric-1.18.2

# Dependencies
fabric_version=0.56.1+1.18.2

effectmc_core_version=3.0
effectmc_core_version=3.1.0
Loading

0 comments on commit 17aaed4

Please sign in to comment.