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
41 changes: 37 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
plugins {
id "babric-loom" version "1.4.+"
id "java"
id("fabric-loom") version "1.10.0-bta"
id("java")
}

import org.gradle.internal.os.OperatingSystem
project.ext.lwjglVersion = "3.3.4"

switch (OperatingSystem.current()) {
case OperatingSystem.LINUX:
project.ext.lwjglNatives = "natives-linux"
break
case OperatingSystem.WINDOWS:
project.ext.lwjglNatives = "natives-windows"
break
case OperatingSystem.MAC_OS:
project.ext.lwjglNatives = "natives-macos"
}

group = project.mod_group
archivesBaseName = project.mod_name
version = project.mod_version

loom {
gluedMinecraftJar()
noIntermediateMappings()
customMinecraftManifest.set("https://github.com/Turnip-Labs/bta-manifest-repo/releases/download/v${project.bta_version}/${project.bta_version}.json")
customMinecraftMetadata.set("https://downloads.betterthanadventure.net/bta-client/${project.bta_channel}/v${project.bta_version}/manifest.json")
accessWidenerPath = file("src/main/resources/proxvc.accesswidener")
}

Expand Down Expand Up @@ -70,6 +83,21 @@ dependencies {
implementation "com.google.guava:guava:33.0.0-jre"

modRuntimeOnly "ModMenu:ModMenu-bta:${project.mod_menu_version}"

implementation(platform("org.lwjgl:lwjgl-bom:$lwjglVersion"))

runtimeOnly("org.lwjgl:lwjgl::$lwjglNatives")
runtimeOnly("org.lwjgl:lwjgl-assimp::$lwjglNatives")
runtimeOnly("org.lwjgl:lwjgl-glfw::$lwjglNatives")
runtimeOnly("org.lwjgl:lwjgl-openal::$lwjglNatives")
runtimeOnly("org.lwjgl:lwjgl-opengl::$lwjglNatives")
runtimeOnly("org.lwjgl:lwjgl-stb::$lwjglNatives")
implementation("org.lwjgl:lwjgl:$lwjglVersion")
implementation("org.lwjgl:lwjgl-assimp:$lwjglVersion")
implementation("org.lwjgl:lwjgl-glfw:$lwjglVersion")
implementation("org.lwjgl:lwjgl-openal:$lwjglVersion")
implementation("org.lwjgl:lwjgl-opengl:$lwjglVersion")
implementation("org.lwjgl:lwjgl-stb:$lwjglVersion")
}

java {
Expand All @@ -88,6 +116,11 @@ jar {
}
}

configurations.configureEach {
// Removes LWJGL2 dependencies.
exclude group: "org.lwjgl.lwjgl"
}

processResources {
inputs.property "mod_version", project.mod_version
filesMatching("fabric.mod.json") {
Expand Down
9 changes: 5 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
org.gradle.jvmargs=-Xmx2G

bta_version=7.2_01
loader_version=0.15.6-babric.6-bta
bta_version=7.3_01
loader_version=0.15.6-bta.7
bta_channel=release

halplibe_version=4.1.3
mod_menu_version=2.0.6
halplibe_version=5.2.2
mod_menu_version=3.0.0

mod_version=1.5.2
mod_group=fiveavian
Expand Down
18 changes: 13 additions & 5 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,20 @@ pluginManagement {
repositories {
gradlePluginPortal()
maven {
name = "Fabric"
url = "https://maven.fabricmc.net/"
name = 'Fabric'
url = 'https://maven.fabricmc.net/'
}
maven {
name = "Babric"
url = "https://maven.glass-launcher.net/babric"
name = 'Jitpack'
url = 'https://jitpack.io'
}
maven {
name = 'Babric'
url = 'https://maven.glass-launcher.net/babric'
}
maven {
name = 'SignalumMavenInfrastructure'
url = 'https://maven.thesignalumproject.net/infrastructure'
}
}
}
}
68 changes: 39 additions & 29 deletions src/main/java/fiveavian/proxvc/ProxVCClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
import net.minecraft.client.option.*;
import net.minecraft.client.render.tessellator.Tessellator;
import net.minecraft.client.render.WorldRenderer;
import net.minecraft.core.block.Block;
import net.minecraft.core.block.Blocks;
import net.minecraft.core.entity.Entity;
import net.minecraft.core.entity.player.EntityPlayer;
import net.minecraft.core.net.packet.Packet1Login;
import net.minecraft.core.util.phys.Vec3d;
import net.minecraft.core.entity.player.Player;
import net.minecraft.core.net.packet.PacketLogin;
import net.minecraft.core.util.phys.Vec3;
import net.minecraft.client.render.texture.Texture;
import org.lwjgl.input.Keyboard;
import org.lwjgl.openal.AL10;
import org.lwjgl.openal.AL11;
Expand All @@ -45,14 +46,15 @@ public class ProxVCClient implements ClientModInitializer {
public SocketAddress serverAddress;
private Thread inputThread;
private Thread outputThread;
public Texture statusIconTexture;

public final KeyBinding keyMute = new KeyBinding("key.mute").setDefault(InputDevice.keyboard, Keyboard.KEY_M);
public final KeyBinding keyPushToTalk = new KeyBinding("key.push_to_talk").setDefault(InputDevice.keyboard, Keyboard.KEY_V);
public final KeyBinding[] keyBindings = {keyMute, keyPushToTalk};
public FloatOption voiceChatVolume;
public BooleanOption isMuted;
public BooleanOption usePushToTalk;
public StringOption selectedInputDevice;
public OptionFloat voiceChatVolume;
public OptionBoolean isMuted;
public OptionBoolean usePushToTalk;
public OptionString selectedInputDevice;
public Option<?>[] options;
public Path optionFilePath;
private boolean isMutePressed = false;
Expand All @@ -73,10 +75,11 @@ public void onInitializeClient() {

private void start(Minecraft client) {
this.client = client;
voiceChatVolume = new FloatOption(client.gameSettings, "sound.voice_chat", 1.0f);
isMuted = new BooleanOption(client.gameSettings, "is_muted", false);
usePushToTalk = new BooleanOption(client.gameSettings, "use_push_to_talk", false);
selectedInputDevice = new StringOption(client.gameSettings, "selected_input_device", null);
statusIconTexture = client.textureManager.loadTexture("/gui/proxvc.png");
voiceChatVolume = new OptionFloat(client.gameSettings, "sound.voice_chat", 1.0f);
isMuted = new OptionBoolean(client.gameSettings, "is_muted", false);
usePushToTalk = new OptionBoolean(client.gameSettings, "use_push_to_talk", false);
selectedInputDevice = new OptionString(client.gameSettings, "selected_input_device", null);
options = new Option[]{voiceChatVolume, isMuted, usePushToTalk, selectedInputDevice};
optionFilePath = FabricLoader.getInstance().getConfigDir().resolve("proxvc_client.properties");
OptionStore.loadOptions(optionFilePath, options, keyBindings);
Expand All @@ -99,11 +102,12 @@ private void start(Minecraft client) {
OptionsCategory controlsCategory = new OptionsCategory("gui.options.page.proxvc.category.controls")
.withComponent(new KeyBindingComponent(keyMute))
.withComponent(new KeyBindingComponent(keyPushToTalk));
OptionsPages.register(new OptionsPage("gui.options.page.proxvc.title", Block.noteblock.getDefaultStack()))
OptionsPages.register(new OptionsPage("gui.options.page.proxvc.title", Blocks.NOTEBLOCK.getDefaultStack()))
.withComponent(generalCategory)
.withComponent(devicesCategory)
.withComponent(controlsCategory);
device.open(selectedInputDevice.value);
System.out.println("ProxVC successfully started.");
} catch (SocketException ex) {
System.out.println("Failed to start the ProxVC client because of an exception.");
System.out.println("Continuing without ProxVC.");
Expand Down Expand Up @@ -139,8 +143,8 @@ private void tick(Minecraft client) {

Set<Integer> toRemove = new HashSet<>(sources.keySet());
Set<Integer> toAdd = new HashSet<>();
for (Entity entity : client.theWorld.loadedEntityList) {
if (entity instanceof EntityPlayer && entity.id != client.thePlayer.id) {
for (Entity entity : client.currentWorld.loadedEntityList) {
if (entity instanceof Player && entity.id != client.thePlayer.id) {
toRemove.remove(entity.id);
toAdd.add(entity.id);
}
Expand All @@ -155,25 +159,27 @@ private void tick(Minecraft client) {
}

if (client.currentScreen == null) {
if (keyMute.isPressEvent(InputDevice.keyboard))
isMutePressed = true;
if (keyMute.isReleaseEvent(InputDevice.keyboard) && isMutePressed) {
if (keyMute.isPressed()) {
if (!isMutePressed) {
isMutePressed = true;
isMuted.value = !isMuted.value;
}
} else {
isMutePressed = false;
isMuted.value = !isMuted.value;
}
}

for (Entity entity : client.theWorld.loadedEntityList) {
for (Entity entity : client.currentWorld.loadedEntityList) {
StreamingAudioSource source = sources.get(entity.id);
if (source == null) {
continue;
}
Vec3d look = entity.getLookAngle();
Vec3 look = entity.getLookAngle();
AL10.alDistanceModel(AL11.AL_LINEAR_DISTANCE);
AL10.alSourcef(source.source, AL10.AL_MAX_DISTANCE, 32f);
AL10.alSourcef(source.source, AL10.AL_REFERENCE_DISTANCE, 16f);
AL10.alSource3f(source.source, AL10.AL_POSITION, (float) entity.x, (float) entity.y, (float) entity.z);
AL10.alSource3f(source.source, AL10.AL_DIRECTION, (float) look.xCoord, (float) look.yCoord, (float) look.zCoord);
AL10.alSource3f(source.source, AL10.AL_DIRECTION, (float) look.x, (float) look.y, (float) look.z);
AL10.alSource3f(source.source, AL10.AL_VELOCITY, (float) entity.xd, (float) entity.yd, (float) entity.zd);
AL10.alSourcef(source.source, AL10.AL_GAIN, voiceChatVolume.value);
}
Expand All @@ -183,24 +189,28 @@ private void render(Minecraft client, WorldRenderer renderer) {
if (isDisconnected() || !client.gameSettings.immersiveMode.drawOverlays()) {
return;
}
GL11.glBindTexture(GL11.GL_TEXTURE_2D, client.renderEngine.getTexture("/proxvc.png"));
statusIconTexture.bind();
GL11.glColor4d(1.0, 1.0, 1.0, 1.0);
double u = 0.0;
if (isMuted.value) {
u = 0.25;
u = 0.2;
} else if (device.isClosed()) {
u = 0.5;
u = 0.4;
} else if (usePushToTalk.value && !keyPushToTalk.isPressed()) {
u = 0.75;
u = 0.6;
} else if (device.isClosed()) {
u = 0.2;
} else if (device.isTalking()) {
u = 0.8;
}
Tessellator.instance.startDrawingQuads();
Tessellator.instance.setColorRGBA_F(1f, 1f, 1f, 0.5f);
Tessellator.instance.drawRectangleWithUV(4, client.resolution.scaledHeight - 24 - 4, 24, 24, u, 0.0, 0.25, 1.0);
Tessellator.instance.drawRectangleWithUV(4, client.resolution.getScaledHeightScreenCoords() - 24 - 4, 24, 24, u, 0.0, 0.20, 1.0);
Tessellator.instance.draw();
}

private void login(Minecraft client, Packet1Login packet) {
Socket socket = client.getSendQueue().netManager.networkSocket;
private void login(Minecraft client, PacketLogin packet) {
Socket socket = (Socket) client.getSendQueue().netManager.socket;
serverAddress = socket.getRemoteSocketAddress();
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/fiveavian/proxvc/api/ClientEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import net.minecraft.client.Minecraft;
import net.minecraft.client.render.WorldRenderer;
import net.minecraft.core.net.packet.Packet1Login;
import net.minecraft.core.net.packet.PacketLogin;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -15,6 +15,6 @@ public class ClientEvents {
public static final List<Consumer<Minecraft>> TICK = new ArrayList<>();
public static final List<BiConsumer<Minecraft, WorldRenderer>> RENDER = new ArrayList<>();

public static final List<BiConsumer<Minecraft, Packet1Login>> LOGIN = new ArrayList<>();
public static final List<BiConsumer<Minecraft, PacketLogin>> LOGIN = new ArrayList<>();
public static final List<Consumer<Minecraft>> DISCONNECT = new ArrayList<>();
}
17 changes: 10 additions & 7 deletions src/main/java/fiveavian/proxvc/gui/MicrophoneListComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,29 @@
import fiveavian.proxvc.vc.AudioInputDevice;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.options.components.OptionsComponent;
import net.minecraft.client.option.StringOption;
import net.minecraft.client.render.FontRenderer;
import net.minecraft.client.option.OptionString;
import net.minecraft.client.render.Font;
import net.minecraft.client.render.tessellator.Tessellator;
import net.minecraft.core.lang.I18n;
import org.lwjgl.opengl.GL11;

import java.util.Objects;
import java.util.regex.Pattern;

public class MicrophoneListComponent implements OptionsComponent {
private static final int MARGIN = 3;
private static final int BUTTON_HEIGHT = 16;
private static final int BUTTON_HEIGHT_WITH_MARGIN = BUTTON_HEIGHT + MARGIN;
// I ended up using a negative look ahead at the end plus the end modifier to prevent replacing entire string with blank
private static final Pattern SPECIFIER_PATTERN = Pattern.compile("OpenAL Soft on\\s+(?!($|\\s+$))");

private final AudioInputDevice device;
private final StringOption specifierOption;
private final OptionString specifierOption;
private Minecraft mc;
private String[] specifiers;
private int updateTickCount = 0;

public MicrophoneListComponent(AudioInputDevice device, StringOption specifierOption) {
public MicrophoneListComponent(AudioInputDevice device, OptionString specifierOption) {
this.device = device;
this.specifierOption = specifierOption;
}
Expand Down Expand Up @@ -71,10 +74,10 @@ public int getHeight() {
@Override
public void render(int x, int y, int width, int relativeMouseX, int relativeMouseY) {
Tessellator tessellator = Tessellator.instance;
FontRenderer fontRenderer = mc.fontRenderer;
Font font = mc.font;
I18n i18n = I18n.getInstance();
if (specifiers.length == 0) {
fontRenderer.drawCenteredString(i18n.translateKey("gui.options.page.proxvc.label.no_devices"), x + width / 2, y + 4, 0x5F7F7F7F);
font.drawCenteredString(i18n.translateKey("gui.options.page.proxvc.label.no_devices"), x + width / 2, y + 4, 0x5F7F7F7F);
return;
}
y += MARGIN;
Expand All @@ -98,7 +101,7 @@ public void render(int x, int y, int width, int relativeMouseX, int relativeMous
tessellator.draw();
GL11.glEnable(GL11.GL_TEXTURE_2D);
}
fontRenderer.drawString(specifier, x + 1, y + 4, 0xFFFFFF);
font.drawString(SPECIFIER_PATTERN.matcher(specifier).replaceFirst(""), x + 1, y + 4, 0xFFFFFF);
y += BUTTON_HEIGHT_WITH_MARGIN;
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/fiveavian/proxvc/mixin/client/ALC10Mixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.lwjgl.openal.ALC10;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Pseudo;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
Expand All @@ -12,14 +13,15 @@
/**
* Ensures that Minecraft doesn't crash on certain devices.
*/
@Pseudo
@Mixin(value = ALC10.class, remap = false)
public class ALC10Mixin {
@Unique
private static final CharsetDecoder DECODER = StandardCharsets.UTF_8.newDecoder()
.onMalformedInput(CodingErrorAction.REPLACE)
.onUnmappableCharacter(CodingErrorAction.REPLACE);

@Redirect(method = "alcGetString", at = @At(value = "INVOKE", target = "Lorg/lwjgl/MemoryUtil;decodeUTF8(Ljava/nio/ByteBuffer;)Ljava/lang/String;"))
@Redirect(method = "alcGetString", at = @At(value = "INVOKE", target = "Lorg/lwjgl/MemoryUtil;decodeUTF8(Ljava/nio/ByteBuffer;)Ljava/lang/String;"), require = 0)
private static String decodeUTF8(ByteBuffer buffer) {
if (buffer == null) {
return null;
Expand All @@ -31,4 +33,4 @@ private static String decodeUTF8(ByteBuffer buffer) {
throw new RuntimeException(ex);
}
}
}
}
Loading