forked from virt-mirrors/Sit
complete rewrite
This commit is contained in:
parent
d059cd4b8d
commit
1316686d85
24 changed files with 1808 additions and 871 deletions
|
@ -1,25 +1,40 @@
|
|||
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;
|
||||
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
|
||||
import one.oth3r.sit.file.Data;
|
||||
import one.oth3r.sit.packet.SitPayloads;
|
||||
import one.oth3r.sit.utl.Utl;
|
||||
|
||||
public class SitClient implements ClientModInitializer {
|
||||
public static boolean inGame = false;
|
||||
private static boolean IN_GAME = false;
|
||||
|
||||
@Override
|
||||
public void onInitializeClient() {
|
||||
Sit.isClient = true;
|
||||
Sit.client = true;
|
||||
|
||||
ClientPlayConnectionEvents.JOIN.register((handler, sender, client) -> {
|
||||
inGame = true;
|
||||
IN_GAME = true;
|
||||
if (client.isInSingleplayer()) Sit.singleplayer = true;
|
||||
// send a data packet whenever joining a server
|
||||
client.execute(SitClient::sendPackets);
|
||||
sendSettingsPackets();
|
||||
});
|
||||
|
||||
// reset cashed things
|
||||
ClientPlayConnectionEvents.DISCONNECT.register((handler, client) -> {
|
||||
IN_GAME = false;
|
||||
if (Sit.singleplayer) {
|
||||
// flip the single player switch
|
||||
Sit.singleplayer = false;
|
||||
}
|
||||
});
|
||||
// reset inGame
|
||||
ClientPlayConnectionEvents.DISCONNECT.register((handler, client) -> inGame = false);
|
||||
}
|
||||
public static void sendPackets() {
|
||||
Gson gson = new GsonBuilder().disableHtmlEscaping().create();
|
||||
new PacketBuilder(gson.toJson(Utl.PlayerSettings.getHandSettings())).send();
|
||||
|
||||
/**
|
||||
* sends the settings packets to the server
|
||||
*/
|
||||
public static void sendSettingsPackets() {
|
||||
if (IN_GAME) ClientPlayNetworking.send(new SitPayloads.SettingsPayload(Utl.getGson().toJson(Data.getHandConfig())));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue