From c52706251564c84525f39387e11ee37116f35033 Mon Sep 17 00:00:00 2001 From: Kai Date: Sat, 5 Nov 2022 12:08:18 +0000 Subject: [PATCH] Remove Stage 2 Handshake and switch to using gradle kotlin (and added kotlin source as a test) --- build.gradle | 81 ------------------- build.gradle.kts | 71 ++++++++++++++++ gradle.properties | 5 ++ settings.gradle | 9 --- settings.gradle.kts | 20 +++++ .../openproximitychatfabric/OPCFabric.java | 4 +- .../client/OPCFabricClient.java | 20 ++--- .../connect/Connection.java | 5 -- .../{Stage1Handshake.java => Handshake.java} | 9 ++- ...hakeBuilder.java => HandshakeBuilder.java} | 10 +-- .../connect/Stage2HandshakeBuilder.java | 29 ------- .../mixins/OtherClientPlayerEntityMixin.java | 13 +-- .../voice/Connection.kt | 4 + 13 files changed, 131 insertions(+), 149 deletions(-) delete mode 100644 build.gradle create mode 100644 build.gradle.kts delete mode 100644 settings.gradle create mode 100644 settings.gradle.kts delete mode 100644 src/main/java/org/muellerssoftware/openproximitychatfabric/connect/Connection.java rename src/main/java/org/muellerssoftware/openproximitychatfabric/connect/{Stage1Handshake.java => Handshake.java} (64%) rename src/main/java/org/muellerssoftware/openproximitychatfabric/connect/{Stage1HandshakeBuilder.java => HandshakeBuilder.java} (93%) delete mode 100644 src/main/java/org/muellerssoftware/openproximitychatfabric/connect/Stage2HandshakeBuilder.java create mode 100644 src/main/kotlin/org/muellerssoftware/openproximitychatfabric/voice/Connection.kt diff --git a/build.gradle b/build.gradle deleted file mode 100644 index 0dc1fdf..0000000 --- a/build.gradle +++ /dev/null @@ -1,81 +0,0 @@ -plugins { - id 'fabric-loom' version '1.0-SNAPSHOT' - id 'maven-publish' -} - -version = project.mod_version -group = project.maven_group - -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. -} - -dependencies { - // To change the versions see the gradle.properties file - minecraft "com.mojang:minecraft:${project.minecraft_version}" - mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" - 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}" -} - -processResources { - inputs.property "version", project.version - filteringCharset "UTF-8" - - filesMatching("fabric.mod.json") { - expand "version": project.version - } -} - -def targetJavaVersion = 17 -tasks.withType(JavaCompile).configureEach { - // ensure that the encoding is set to UTF-8, no matter what the system default is - // this fixes some edge cases with special characters not displaying correctly - // see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html - // If Javadoc is generated, this must be specified in that task too. - it.options.encoding = "UTF-8" - if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible()) { - it.options.release = targetJavaVersion - } -} - -java { - def javaVersion = JavaVersion.toVersion(targetJavaVersion) - if (JavaVersion.current() < javaVersion) { - toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion) - } - archivesBaseName = project.archives_base_name - // Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task - // if it is present. - // If you remove this line, sources will not be generated. - withSourcesJar() -} - -jar { - from("LICENSE") { - rename { "${it}_${project.archivesBaseName}" } - } -} - -// configure the maven publication -publishing { - publications { - mavenJava(MavenPublication) { - from components.java - } - } - - // See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing. - repositories { - // Add repositories to publish to here. - // Notice: This block does NOT have the same function as the block in the top level. - // The repositories here will be used for publishing your artifact, not for - // retrieving dependencies. - } -} diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000..2a12833 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,71 @@ +plugins { + kotlin("jvm") + id("fabric-loom") + `maven-publish` + java +} + +group = property("maven_group")!! +version = property("mod_version")!! + +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. +} + +dependencies { + minecraft("com.mojang:minecraft:${property("minecraft_version")}") + mappings("net.fabricmc:yarn:${property("yarn_mappings")}:v2") + modImplementation("net.fabricmc:fabric-loader:${property("loader_version")}") + + modImplementation("net.fabricmc:fabric-language-kotlin:${property("fabric_kotlin_version")}") + modImplementation("net.fabricmc.fabric-api:fabric-api:${property("fabric_api_version")}") +} + +tasks { + + processResources { + inputs.property("version", project.version) + filesMatching("fabric.mod.json") { + expand(mutableMapOf("version" to project.version)) + } + } + + jar { + from("LICENSE") + } + + publishing { + publications { + create("mavenJava") { + artifact(remapJar) { + builtBy(remapJar) + } + artifact(kotlinSourcesJar) { + builtBy(remapSourcesJar) + } + } + } + + // select the repositories you want to publish to + repositories { + // uncomment to publish to the local maven + // mavenLocal() + } + } + + compileKotlin { + kotlinOptions.jvmTarget = "17" + } + +} + +java { + // Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task + // if it is present. + // If you remove this line, sources will not be generated. + withSourcesJar() +} diff --git a/gradle.properties b/gradle.properties index 2e85828..a36ab7f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,10 +1,12 @@ # Done to increase the memory available to gradle. org.gradle.jvmargs=-Xmx1G +kotlin.code.style=official # Fabric Properties # check these on https://modmuss50.me/fabric.html minecraft_version=1.19.2 yarn_mappings=1.19.2+build.28 loader_version=0.14.10 +loom_version=1.0-SNAPSHOT # Mod Properties mod_version=1.0-SNAPSHOT maven_group=org.muellerssoftware @@ -12,3 +14,6 @@ archives_base_name=OpenProximityChatFabric # Dependencies # check this on https://modmuss50.me/fabric.html fabric_version=0.64.0+1.19.2 +fabric_kotlin_version=1.8.3+kotlin.1.7.10 +fabric_api_version=0.64.0+1.19.2 + diff --git a/settings.gradle b/settings.gradle deleted file mode 100644 index f91a4fe..0000000 --- a/settings.gradle +++ /dev/null @@ -1,9 +0,0 @@ -pluginManagement { - repositories { - maven { - name = 'Fabric' - url = 'https://maven.fabricmc.net/' - } - gradlePluginPortal() - } -} diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 0000000..5e7757b --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1,20 @@ +rootProject.name = "OpenProximityChatFabric" +pluginManagement { + repositories { + maven("https://maven.fabricmc.net/") { + name = "Fabric" + } + mavenCentral() + gradlePluginPortal() + } + + val loom_version: String by settings + val fabric_kotlin_version: String by settings + plugins { + id("fabric-loom") version loom_version + id("org.jetbrains.kotlin.jvm") version + fabric_kotlin_version + .split("+kotlin.")[1] // Grabs the sentence after `+kotlin.` + .split("+")[0] // Ensures sentences like `+build.1` are ignored + } +} \ No newline at end of file diff --git a/src/main/java/org/muellerssoftware/openproximitychatfabric/OPCFabric.java b/src/main/java/org/muellerssoftware/openproximitychatfabric/OPCFabric.java index 13f3665..3d220c7 100644 --- a/src/main/java/org/muellerssoftware/openproximitychatfabric/OPCFabric.java +++ b/src/main/java/org/muellerssoftware/openproximitychatfabric/OPCFabric.java @@ -1,7 +1,7 @@ package org.muellerssoftware.openproximitychatfabric; import net.fabricmc.api.ModInitializer; -import org.muellerssoftware.openproximitychatfabric.connect.Stage1HandshakeBuilder; +import org.muellerssoftware.openproximitychatfabric.connect.HandshakeBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -9,7 +9,7 @@ import java.util.HashMap; import java.util.UUID; public class OPCFabric implements ModInitializer { - public static HashMap tracked_players = new HashMap<>(); + public static HashMap tracked_players = new HashMap<>(); public static final Logger LOGGER = LoggerFactory.getLogger("OPCFabric"); @Override public void onInitialize() { diff --git a/src/main/java/org/muellerssoftware/openproximitychatfabric/client/OPCFabricClient.java b/src/main/java/org/muellerssoftware/openproximitychatfabric/client/OPCFabricClient.java index 29ce12f..dab2171 100644 --- a/src/main/java/org/muellerssoftware/openproximitychatfabric/client/OPCFabricClient.java +++ b/src/main/java/org/muellerssoftware/openproximitychatfabric/client/OPCFabricClient.java @@ -9,21 +9,21 @@ import net.minecraft.client.option.KeyBinding; import net.minecraft.client.util.InputUtil; import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket; import org.lwjgl.glfw.GLFW; -import org.muellerssoftware.openproximitychatfabric.connect.Stage1HandshakeBuilder; +import org.muellerssoftware.openproximitychatfabric.connect.HandshakeBuilder; import org.muellerssoftware.openproximitychatfabric.mixins.ClientConnectionInvoker; @Environment(EnvType.CLIENT) public class OPCFabricClient implements ClientModInitializer { private static KeyBinding keyBinding; - private static final Stage1HandshakeBuilder.HandshakeMovement[] movements = { - new Stage1HandshakeBuilder.HandshakeMovement(90,-45), - new Stage1HandshakeBuilder.HandshakeMovement(90,45), - new Stage1HandshakeBuilder.HandshakeMovement(-90,45), - new Stage1HandshakeBuilder.HandshakeMovement(90,-45), - new Stage1HandshakeBuilder.HandshakeMovement(-90,45), - new Stage1HandshakeBuilder.HandshakeMovement(90, 45), - new Stage1HandshakeBuilder.HandshakeMovement(0, 0) + private static final HandshakeBuilder.HandshakeMovement[] movements = { + new HandshakeBuilder.HandshakeMovement(90,-45), + new HandshakeBuilder.HandshakeMovement(90,45), + new HandshakeBuilder.HandshakeMovement(-90,45), + new HandshakeBuilder.HandshakeMovement(90,-45), + new HandshakeBuilder.HandshakeMovement(-90,45), + new HandshakeBuilder.HandshakeMovement(90, 45), + new HandshakeBuilder.HandshakeMovement(0, 0) }; @Override public void onInitializeClient() { @@ -42,7 +42,7 @@ public class OPCFabricClient implements ClientModInitializer { ClientConnectionInvoker invoker = (ClientConnectionInvoker) client.player.networkHandler.getConnection(); //ViewLock.setLocked(true); - for (Stage1HandshakeBuilder.HandshakeMovement movement : movements) { + for (HandshakeBuilder.HandshakeMovement movement : movements) { invoker.sendIm(new PlayerMoveC2SPacket.LookAndOnGround(movement.yaw, movement.pitch, client.player.isOnGround()), null); try { Thread.sleep(100); diff --git a/src/main/java/org/muellerssoftware/openproximitychatfabric/connect/Connection.java b/src/main/java/org/muellerssoftware/openproximitychatfabric/connect/Connection.java deleted file mode 100644 index 5b03ac1..0000000 --- a/src/main/java/org/muellerssoftware/openproximitychatfabric/connect/Connection.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.muellerssoftware.openproximitychatfabric.connect; - -public class Connection { - -} diff --git a/src/main/java/org/muellerssoftware/openproximitychatfabric/connect/Stage1Handshake.java b/src/main/java/org/muellerssoftware/openproximitychatfabric/connect/Handshake.java similarity index 64% rename from src/main/java/org/muellerssoftware/openproximitychatfabric/connect/Stage1Handshake.java rename to src/main/java/org/muellerssoftware/openproximitychatfabric/connect/Handshake.java index 4da7d19..68fb953 100644 --- a/src/main/java/org/muellerssoftware/openproximitychatfabric/connect/Stage1Handshake.java +++ b/src/main/java/org/muellerssoftware/openproximitychatfabric/connect/Handshake.java @@ -1,9 +1,10 @@ package org.muellerssoftware.openproximitychatfabric.connect; import net.minecraft.entity.player.PlayerEntity; +import org.muellerssoftware.openproximitychatfabric.voice.Connection; -public class Stage1Handshake { - Stage1Handshake(ConnectionFilterType type, PlayerEntity player) { +public class Handshake { + Handshake(ConnectionFilterType type, PlayerEntity player) { this.filterType = type; this.player = player; } @@ -17,4 +18,8 @@ public class Stage1Handshake { public ConnectionFilterType getFilterType() { return filterType; } + + public Connection connect() { + return new Connection(); + } } diff --git a/src/main/java/org/muellerssoftware/openproximitychatfabric/connect/Stage1HandshakeBuilder.java b/src/main/java/org/muellerssoftware/openproximitychatfabric/connect/HandshakeBuilder.java similarity index 93% rename from src/main/java/org/muellerssoftware/openproximitychatfabric/connect/Stage1HandshakeBuilder.java rename to src/main/java/org/muellerssoftware/openproximitychatfabric/connect/HandshakeBuilder.java index 8f23c4c..0557227 100644 --- a/src/main/java/org/muellerssoftware/openproximitychatfabric/connect/Stage1HandshakeBuilder.java +++ b/src/main/java/org/muellerssoftware/openproximitychatfabric/connect/HandshakeBuilder.java @@ -8,7 +8,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Objects; -public class Stage1HandshakeBuilder { +public class HandshakeBuilder { public static class HandshakeMovement { public float yaw; public float pitch; @@ -81,12 +81,12 @@ public class Stage1HandshakeBuilder { private static final HandshakeMovement OMNIFRIEND_MOVE = new HandshakeMovement(90, 45); - public Stage1HandshakeBuilder withPlayer(PlayerEntity player) { + public HandshakeBuilder withPlayer(PlayerEntity player) { this.player = player; return this; } - public Stage1HandshakeBuilder add(HandshakeMovement movement) { + public HandshakeBuilder add(HandshakeMovement movement) { if (this.movements.size() == 0) { this.movements.add(movement); } @@ -101,7 +101,7 @@ public class Stage1HandshakeBuilder { } @Nullable - public Stage1Handshake tryBuild() throws HandshakeException { + public Handshake tryBuild() throws HandshakeException { if (this.movements.size() < 24) { throw new HandshakeException("Too few stored head movements (need at least 24)"); } @@ -130,7 +130,7 @@ public class Stage1HandshakeBuilder { if (this.player != null) { player = this.player; - return new Stage1Handshake(filterType, player); + return new Handshake(filterType, player); } else { throw new HandshakeException("Player not set in Stage 1 Handshake"); } diff --git a/src/main/java/org/muellerssoftware/openproximitychatfabric/connect/Stage2HandshakeBuilder.java b/src/main/java/org/muellerssoftware/openproximitychatfabric/connect/Stage2HandshakeBuilder.java deleted file mode 100644 index 82be866..0000000 --- a/src/main/java/org/muellerssoftware/openproximitychatfabric/connect/Stage2HandshakeBuilder.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.muellerssoftware.openproximitychatfabric.connect; - -import net.minecraft.server.MinecraftServer; -import net.minecraft.server.network.ServerPlayerEntity; - -public class Stage2HandshakeBuilder { - private ServerPlayerEntity target_player; - private MinecraftServer target_server; - - public Stage2HandshakeBuilder() { - - } - - public Stage2HandshakeBuilder withPlayer(ServerPlayerEntity player) { - target_player = player; - return this; - } - - public Stage2HandshakeBuilder onServer(MinecraftServer server) { - target_server = server; - return this; - } - - Connection connect() { - - - return new Connection(); - } -} diff --git a/src/main/java/org/muellerssoftware/openproximitychatfabric/mixins/OtherClientPlayerEntityMixin.java b/src/main/java/org/muellerssoftware/openproximitychatfabric/mixins/OtherClientPlayerEntityMixin.java index 871c4cf..daa7a90 100644 --- a/src/main/java/org/muellerssoftware/openproximitychatfabric/mixins/OtherClientPlayerEntityMixin.java +++ b/src/main/java/org/muellerssoftware/openproximitychatfabric/mixins/OtherClientPlayerEntityMixin.java @@ -3,8 +3,8 @@ package org.muellerssoftware.openproximitychatfabric.mixins; import net.minecraft.client.network.OtherClientPlayerEntity; import org.muellerssoftware.openproximitychatfabric.OPCFabric; import org.muellerssoftware.openproximitychatfabric.connect.HandshakeException; -import org.muellerssoftware.openproximitychatfabric.connect.Stage1Handshake; -import org.muellerssoftware.openproximitychatfabric.connect.Stage1HandshakeBuilder; +import org.muellerssoftware.openproximitychatfabric.connect.Handshake; +import org.muellerssoftware.openproximitychatfabric.connect.HandshakeBuilder; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -17,20 +17,21 @@ public class OtherClientPlayerEntityMixin { LivingEntityAccessor accessor = (LivingEntityAccessor) this; OtherClientPlayerEntity player = (OtherClientPlayerEntity) (Object) this; if (!OPCFabric.tracked_players.containsKey(player.getUuid())) { - OPCFabric.tracked_players.put(player.getUuid(), new Stage1HandshakeBuilder().withPlayer(player)); + OPCFabric.tracked_players.put(player.getUuid(), new HandshakeBuilder().withPlayer(player)); } - Stage1HandshakeBuilder builder = OPCFabric.tracked_players.get(player.getUuid()); + HandshakeBuilder builder = OPCFabric.tracked_players.get(player.getUuid()); if (!builder.built) { try { - builder.add(new Stage1HandshakeBuilder.HandshakeMovement(accessor.getServerHeadYaw(), accessor.getServerPitch()).convertToHandshakeForm()); + builder.add(new HandshakeBuilder.HandshakeMovement(accessor.getServerHeadYaw(), accessor.getServerPitch()).convertToHandshakeForm()); } catch (IllegalArgumentException ignored) { } if (builder.readyToBuild()) { try { - Stage1Handshake handshake = builder.tryBuild(); + Handshake handshake = builder.tryBuild(); if (handshake != null) { OPCFabric.LOGGER.info("Found Stage 1 Handshake for player {}", handshake.getPlayer().getName()); builder.built = true; + handshake.connect(); } } catch (HandshakeException e) { OPCFabric.LOGGER.info("Caught HandshakeException ({})", e.getMessage()); diff --git a/src/main/kotlin/org/muellerssoftware/openproximitychatfabric/voice/Connection.kt b/src/main/kotlin/org/muellerssoftware/openproximitychatfabric/voice/Connection.kt new file mode 100644 index 0000000..30ec915 --- /dev/null +++ b/src/main/kotlin/org/muellerssoftware/openproximitychatfabric/voice/Connection.kt @@ -0,0 +1,4 @@ +package org.muellerssoftware.openproximitychatfabric.voice + +public class Connection { +} \ No newline at end of file