Remove Stage 2 Handshake and switch to using gradle kotlin (and added kotlin source as a test)

This commit is contained in:
Kai 2022-11-05 12:08:18 +00:00
parent 3e72533aa8
commit c527062515
13 changed files with 131 additions and 149 deletions

View File

@ -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.
}
}

71
build.gradle.kts Normal file
View File

@ -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<MavenPublication>("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()
}

View File

@ -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

View File

@ -1,9 +0,0 @@
pluginManagement {
repositories {
maven {
name = 'Fabric'
url = 'https://maven.fabricmc.net/'
}
gradlePluginPortal()
}
}

20
settings.gradle.kts Normal file
View File

@ -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
}
}

View File

@ -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<UUID, Stage1HandshakeBuilder> tracked_players = new HashMap<>();
public static HashMap<UUID, HandshakeBuilder> tracked_players = new HashMap<>();
public static final Logger LOGGER = LoggerFactory.getLogger("OPCFabric");
@Override
public void onInitialize() {

View File

@ -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);

View File

@ -1,5 +0,0 @@
package org.muellerssoftware.openproximitychatfabric.connect;
public class Connection {
}

View File

@ -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();
}
}

View File

@ -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");
}

View File

@ -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();
}
}

View File

@ -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());

View File

@ -0,0 +1,4 @@
package org.muellerssoftware.openproximitychatfabric.voice
public class Connection {
}