mirror of
https://github.com/GTNewHorizons/Opis.git
synced 2026-11-19 11:59:05 +00:00
Refactoring of client side packet handling.
It is using the same enum and same generic design as the server side.
This commit is contained in:
1 parent
3f8fcac81c
commit
dcbc5e2f59
15 files changed
+265
-257
No files matched your search
@@ -0,0 +1,44 @@
|
||||
package mcp.mobius.opis.network.packets.server;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import mcp.mobius.opis.network.enums.Message;
|
||||
import mcp.mobius.opis.network.enums.Packets;
|
||||
import net.minecraft.network.packet.Packet250CustomPayload;
|
||||
|
||||
public class Packet_DataCommand {
|
||||
|
||||
public byte header;
|
||||
public Message msg;
|
||||
|
||||
public Packet_DataCommand(Packet250CustomPayload packet) {
|
||||
DataInputStream inputStream = new DataInputStream(new ByteArrayInputStream(packet.data));
|
||||
try{
|
||||
this.header = inputStream.readByte();
|
||||
this.msg = Message.values()[inputStream.readInt()];
|
||||
} catch (IOException e){}
|
||||
|
||||
}
|
||||
|
||||
public static Packet250CustomPayload create(Message msg){
|
||||
Packet250CustomPayload packet = new Packet250CustomPayload();
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream(1);
|
||||
DataOutputStream outputStream = new DataOutputStream(bos);
|
||||
|
||||
try{
|
||||
outputStream.writeByte(Packets.CLIENT_CMD);
|
||||
outputStream.writeInt(msg.ordinal());
|
||||
}catch(IOException e){}
|
||||
|
||||
packet.channel = "Opis";
|
||||
packet.data = bos.toByteArray();
|
||||
packet.length = bos.size();
|
||||
|
||||
return packet;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user