public class OpenCustomGuiPacket {
public static final Identifier ID = new Identifier(TheClassicofMountainsandOceans.MOD_ID,"opengui");
public static void sendToClient(ServerPlayerEntity player) {
PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer());
ServerPlayNetworking.send(player, ID, buf);
}
public static void registerReceiver() {
ClientPlayNetworking.registerGlobalReceiver(ID, (client, handler, buf, responseSender) -> {
client.execute(() -> {
MinecraftClient.getInstance().setScreen(new CustomScreen(
new CustomScreenHandler(0, MinecraftClient.getInstance().player.getInventory()),
MinecraftClient.getInstance().player.getInventory(),
MinecraftClient.getInstance().player.getName()
));
});
});
}
registerReceiver這個方法是用來註冊一個接收器,當minecraft客戶端接收到特定訊息時可以進行某些操作。
registerGlobalReceiver用於註冊一個接收器,ID 是唯一標識符,用來區分不同的網路訊息。
當Minecraft客戶端接收到訊號的時候就會開啟全新的GUI。