-
Notifications
You must be signed in to change notification settings - Fork 5
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
10 changed files
with
381 additions
and
73 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
forge/origin/src/main/java/io/github/kituin/chatimage/network/BChannelPacket.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,30 @@ | ||
package io.github.kituin.chatimage.network; | ||
|
||
// IF forge-1.16.5 | ||
//import net.minecraft.network.PacketBuffer; | ||
// ELSE | ||
//import net.minecraft.network.FriendlyByteBuf; | ||
// END IF | ||
public class BChannelPacket { | ||
public String message; | ||
|
||
public BChannelPacket(String message) { | ||
this.message = message; | ||
} | ||
|
||
// IF forge-1.16.5 | ||
// public BChannelPacket(PacketBuffer buffer) { | ||
// this.message = buffer.readUtf(); | ||
// } | ||
// public void toBytes(PacketBuffer buffer) { | ||
// buffer.writeUtf(this.message); | ||
// } | ||
// ELSE | ||
// public BChannelPacket(FriendlyByteBuf buffer) { | ||
// this.message = buffer.readUtf(); | ||
// } | ||
// public void toBytes(FriendlyByteBuf buffer) { | ||
// buffer.writeUtf(this.message); | ||
// } | ||
// END IF | ||
} |
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
81 changes: 81 additions & 0 deletions
81
forge/origin/src/main/java/io/github/kituin/chatimage/network/DownloadFileChannel.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,81 @@ | ||
package io.github.kituin.chatimage.network; | ||
|
||
// IF forge-1.16.5 | ||
//import net.minecraft.entity.player.ServerPlayerEntity; | ||
//import net.minecraft.util.ResourceLocation; | ||
//import net.minecraftforge.fml.network.NetworkDirection; | ||
//import net.minecraftforge.fml.network.PacketDistributor; | ||
//import net.minecraftforge.fml.network.simple.SimpleChannel; | ||
// ELSE | ||
//import net.minecraft.entity.player.ServerPlayer; | ||
//import net.minecraft.resources.ResourceLocation; | ||
//import net.minecraftforge.network.NetworkDirection; | ||
//import net.minecraftforge.network.simple.SimpleChannel; | ||
// END IF | ||
// IF forge-1.16.5 | ||
//import net.minecraftforge.fml.network.NetworkRegistry.ChannelBuilder; | ||
// | ||
//import static io.github.kituin.chatimage.ChatImage.MOD_ID; | ||
// ELSE IF <= forge-1.20 | ||
//import net.minecraftforge.network.NetworkRegistry.ChannelBuilder; | ||
// ELSE | ||
//import net.minecraftforge.network.ChannelBuilder; | ||
//import net.minecraftforge.network.PacketDistributor; | ||
// END IF | ||
/** | ||
* 发送文件分块到客户端通道 | ||
*/ | ||
public class DownloadFileChannel { | ||
|
||
private static SimpleChannel INSTANCE; | ||
public static final String VERSION = "1.0"; | ||
private static int ID = 0; | ||
|
||
public static int nextID() { | ||
return ID++; | ||
} | ||
|
||
|
||
|
||
public static void register() { | ||
SimpleChannel net = ChannelBuilder | ||
.named(new ResourceLocation(MOD_ID, "download_file_channel")) | ||
// IF <= forge-1.20 | ||
// .networkProtocolVersion(() -> VERSION) | ||
// .clientAcceptedVersions(s -> true) | ||
// .serverAcceptedVersions(s -> true) | ||
// ELSE | ||
// .networkProtocolVersion(1) | ||
// .acceptedVersions((s, v) -> v == 1) | ||
// .clientAcceptedVersions((s, v) -> true) | ||
// .serverAcceptedVersions((s, v) -> true) | ||
// END IF | ||
.simpleChannel(); | ||
|
||
INSTANCE = net; | ||
|
||
net.messageBuilder(DownloadFileChannelPacket.class, nextID(), NetworkDirection.PLAY_TO_CLIENT) | ||
.decoder(DownloadFileChannelPacket::new) | ||
.encoder(DownloadFileChannelPacket::toBytes) | ||
// IF <= forge-1.20 | ||
// .consumer(DownloadFileChannelPacket::clientHandle) | ||
// ELSE | ||
// .consumerNetworkThread(DownloadFileChannelPacket::clientHandle) | ||
// END IF | ||
.add(); | ||
} | ||
|
||
|
||
// IF forge-1.16.5 | ||
// public static <MSG> void sendToPlayer(MSG message, ServerPlayerEntity player) { | ||
// ELSE | ||
// public static <MSG> void sendToPlayer(MSG message, ServerPlayer player) { | ||
// END IF | ||
|
||
// IF <= forge-1.20 | ||
// INSTANCE.send(PacketDistributor.PLAYER.with(() -> player), message); | ||
// ELSE | ||
// INSTANCE.send(message,PacketDistributor.PLAYER.with(player)); | ||
// END IF | ||
} | ||
} |
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
71 changes: 71 additions & 0 deletions
71
forge/origin/src/main/java/io/github/kituin/chatimage/network/FileBackChannel.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,71 @@ | ||
package io.github.kituin.chatimage.network; | ||
|
||
import io.github.kituin.chatimage.ChatImage; | ||
// IF forge-1.16.5 | ||
//import net.minecraft.entity.player.ServerPlayerEntity; | ||
//import net.minecraft.util.ResourceLocation; | ||
//import net.minecraftforge.fml.network.NetworkDirection; | ||
//import net.minecraftforge.fml.network.PacketDistributor; | ||
//import net.minecraftforge.fml.network.simple.SimpleChannel; | ||
// ELSE | ||
//import net.minecraft.entity.player.ServerPlayer; | ||
//import net.minecraft.resources.ResourceLocation; | ||
//import net.minecraftforge.network.NetworkDirection; | ||
//import net.minecraftforge.network.simple.SimpleChannel; | ||
// END IF | ||
// IF forge-1.16.5 | ||
//import net.minecraftforge.fml.network.NetworkRegistry.ChannelBuilder; | ||
// ELSE IF <= forge-1.20 | ||
//import net.minecraftforge.network.NetworkRegistry.ChannelBuilder; | ||
// ELSE | ||
//import net.minecraftforge.network.ChannelBuilder; | ||
//import net.minecraftforge.network.PacketDistributor; | ||
// END IF | ||
public class FileBackChannel { | ||
private static SimpleChannel INSTANCE; | ||
public static final String VERSION = "1.0"; | ||
private static int ID = 0; | ||
|
||
public static int nextID() { | ||
return ID++; | ||
} | ||
|
||
|
||
public static void register() { | ||
INSTANCE = ChannelBuilder | ||
.named(new ResourceLocation(ChatImage.MOD_ID, "file_back")) | ||
// IF <= forge-1.20 | ||
// .networkProtocolVersion(() -> VERSION) | ||
// .clientAcceptedVersions(s -> true) | ||
// .serverAcceptedVersions(s -> true) | ||
// ELSE | ||
// .networkProtocolVersion(1) | ||
// .acceptedVersions((s, v) -> v == 1) | ||
// .clientAcceptedVersions((s, v) -> true) | ||
// .serverAcceptedVersions((s, v) -> true) | ||
// END IF | ||
.simpleChannel(); | ||
|
||
INSTANCE.messageBuilder(FileInfoChannelPacket.class, nextID(), NetworkDirection.PLAY_TO_CLIENT) | ||
.encoder(FileInfoChannelPacket::toBytes) | ||
.decoder(FileInfoChannelPacket::new) | ||
// IF <= forge-1.20 | ||
// .consumer(FileInfoChannelPacket::clientHandle) | ||
// ELSE | ||
// .consumerNetworkThread(FileInfoChannelPacket::clientHandle) | ||
// END IF | ||
.add(); | ||
} | ||
// IF forge-1.16.5 | ||
// public static <MSG> void sendToPlayer(MSG message, ServerPlayerEntity player) { | ||
// ELSE | ||
// public static <MSG> void sendToPlayer(MSG message, ServerPlayer player) { | ||
// END IF | ||
|
||
// IF <= forge-1.20 | ||
// INSTANCE.send(PacketDistributor.PLAYER.with(() -> player), message); | ||
// ELSE | ||
// INSTANCE.send(message,PacketDistributor.PLAYER.with(player)); | ||
// END IF | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
forge/origin/src/main/java/io/github/kituin/chatimage/network/FileChannel.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,70 @@ | ||
package io.github.kituin.chatimage.network; | ||
|
||
import io.github.kituin.chatimage.ChatImage; | ||
// IF forge-1.16.5 | ||
//import net.minecraft.util.ResourceLocation; | ||
//import net.minecraftforge.fml.network.NetworkDirection; | ||
//import net.minecraftforge.fml.network.simple.SimpleChannel; | ||
// ELSE | ||
//import net.minecraft.resources.ResourceLocation; | ||
//import net.minecraftforge.network.NetworkDirection; | ||
//import net.minecraftforge.network.simple.SimpleChannel; | ||
// END IF | ||
// IF forge-1.16.5 | ||
//import net.minecraftforge.fml.network.NetworkRegistry.ChannelBuilder; | ||
// ELSE IF <= forge-1.20 | ||
//import net.minecraftforge.network.NetworkRegistry.ChannelBuilder; | ||
// ELSE | ||
//import net.minecraftforge.network.ChannelBuilder; | ||
//import net.minecraftforge.network.PacketDistributor; | ||
// END IF | ||
/** | ||
* 客户端发送文件分块到服务器通道 | ||
*/ | ||
public class FileChannel { | ||
/** | ||
* 客户端发送文件分块到服务器通道(Map) | ||
*/ | ||
private static SimpleChannel INSTANCE; | ||
public static final String VERSION = "1.0"; | ||
private static int ID = 0; | ||
|
||
public static int nextID() { | ||
return ID++; | ||
} | ||
|
||
public static void register() { | ||
INSTANCE = ChannelBuilder | ||
.named(new ResourceLocation(ChatImage.MOD_ID, "file_channel")) | ||
// IF <= forge-1.20 | ||
// .networkProtocolVersion(() -> VERSION) | ||
// .clientAcceptedVersions(s -> true) | ||
// .serverAcceptedVersions(s -> true) | ||
// ELSE | ||
// .networkProtocolVersion(1) | ||
// .acceptedVersions((s, v) -> v == 1) | ||
// .clientAcceptedVersions((s, v) -> true) | ||
// .serverAcceptedVersions((s, v) -> true) | ||
// END IF | ||
.simpleChannel(); | ||
|
||
INSTANCE.messageBuilder(FileChannelPacket.class, nextID(), NetworkDirection.PLAY_TO_SERVER) | ||
.encoder(FileChannelPacket::toBytes) | ||
.decoder(FileChannelPacket::new) | ||
// IF <= forge-1.20 | ||
// .consumer(FileChannelPacket::serverHandle) | ||
// ELSE | ||
// .consumerNetworkThread(FileChannelPacket::serverHandle) | ||
// END IF | ||
.add(); | ||
|
||
} | ||
|
||
public static <MSG> void sendToServer(MSG message) { | ||
// IF <= forge-1.20 | ||
// INSTANCE.sendToServer(message); | ||
// ELSE | ||
// INSTANCE.send(message,PacketDistributor.SERVER.noArg()); | ||
// END IF | ||
} | ||
} |
47 changes: 22 additions & 25 deletions
47
forge/origin/src/main/java/io/github/kituin/chatimage/network/FileChannelPacket.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
Oops, something went wrong.