forked from virt-mirrors/Sit

# Conflicts: # gradle.properties # src/main/java/one/oth3r/sit/Sit.java # src/main/java/one/oth3r/sit/SitClient.java # src/main/java/one/oth3r/sit/packet/CustomPayloads.java # src/main/resources/fabric.mod.json
31 lines
1 KiB
Java
31 lines
1 KiB
Java
package one.oth3r.sit;
|
|
|
|
import com.google.gson.Gson;
|
|
import com.google.gson.GsonBuilder;
|
|
import net.fabricmc.api.ClientModInitializer;
|
|
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents;
|
|
|
|
public class SitClient implements ClientModInitializer {
|
|
public static boolean inGame = false;
|
|
@Override
|
|
public void onInitializeClient() {
|
|
Sit.isClient = true;
|
|
ClientPlayConnectionEvents.JOIN.register((handler, sender, client) -> {
|
|
inGame = true;
|
|
// send a data packet whenever joining a server
|
|
sendSettingsPackets();
|
|
});
|
|
// reset inGame
|
|
ClientPlayConnectionEvents.DISCONNECT.register((handler, client) -> inGame = false);
|
|
}
|
|
|
|
/**
|
|
* sends the settings packets to the server is the client is in game
|
|
*/
|
|
public static void sendSettingsPackets() {
|
|
if (inGame) {
|
|
Gson gson = new GsonBuilder().disableHtmlEscaping().create();
|
|
new PacketBuilder(gson.toJson(Utl.HandSettings.getHandSettings())).send();
|
|
}
|
|
}
|
|
}
|