-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
src/main/java/com/megadoxs/megalib/access/UserInterfaceViewer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.megadoxs.megalib.access; | ||
|
||
import com.megadoxs.megalib.data.UserInterfaceData; | ||
|
||
public interface UserInterfaceViewer { | ||
void megalib$showInterface(UserInterfaceData toastData); | ||
} |
39 changes: 39 additions & 0 deletions
39
src/main/java/com/megadoxs/megalib/networking/ModPacketsS2C.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.megadoxs.megalib.networking; | ||
|
||
import com.megadoxs.megalib.access.UserInterfaceViewer; | ||
import com.megadoxs.megalib.networking.packet.s2c.UserInterfaceS2CPacket; | ||
import io.github.apace100.apoli.Apoli; | ||
import io.github.apace100.apoli.networking.packet.VersionHandshakePacket; | ||
import net.fabricmc.api.EnvType; | ||
import net.fabricmc.api.Environment; | ||
import net.fabricmc.fabric.api.client.networking.v1.ClientConfigurationNetworking; | ||
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents; | ||
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; | ||
import net.fabricmc.fabric.api.networking.v1.PacketSender; | ||
import net.minecraft.client.network.ClientPlayerEntity; | ||
|
||
@SuppressWarnings("UnstableApiUsage") | ||
@Environment(EnvType.CLIENT) | ||
public class ModPacketsS2C { | ||
|
||
public static void register() { | ||
|
||
ClientConfigurationNetworking.registerGlobalReceiver(VersionHandshakePacket.TYPE, ModPacketsS2C::handleHandshake); | ||
|
||
ClientPlayConnectionEvents.INIT.register(((clientPlayNetworkHandler, minecraftClient) -> { | ||
ClientPlayNetworking.registerReceiver(UserInterfaceS2CPacket.TYPE, ModPacketsS2C::onShowInterface); | ||
})); | ||
|
||
} | ||
|
||
private static void handleHandshake(VersionHandshakePacket packet, PacketSender responseSender) { | ||
responseSender.sendPacket(new VersionHandshakePacket(Apoli.SEMVER)); | ||
} | ||
|
||
public static void onShowInterface(UserInterfaceS2CPacket packet, ClientPlayerEntity player, PacketSender responseSender) { | ||
if (player instanceof UserInterfaceViewer viewer) { | ||
viewer.megalib$showInterface(packet.InterfaceData()); | ||
} | ||
} | ||
|
||
} |