-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPacketHandler.java
More file actions
97 lines (84 loc) · 2.53 KB
/
PacketHandler.java
File metadata and controls
97 lines (84 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package knight37x.lance;
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.IOException;
import net.minecraft.network.INetworkManager;
import net.minecraft.network.packet.Packet250CustomPayload;
import cpw.mods.fml.common.network.IPacketHandler;
import cpw.mods.fml.common.network.Player;
public class PacketHandler implements IPacketHandler
{
public static int entityID;
public static HitValueUntil hit;
public static boolean isForwardKeyPressed;
@Override
public void onPacketData(INetworkManager manager, Packet250CustomPayload packet, Player player)
{
if (packet.channel.equals("lance"))
{
handlePacket(packet);
} else if (packet.channel.equals("lanceHitEntity"))
{
handlePacketHitEntity(packet);
} else if (packet.channel.equals("lanceHitValue"))
{
handlePacketHitValue(packet);
} else if (packet.channel.equals("lanceIsForward"))
{
handlePacketIsForwardKeyPressed(packet);
}
}
private void handlePacketIsForwardKeyPressed(Packet250CustomPayload packet) {
DataInputStream inputStream = new DataInputStream(new ByteArrayInputStream(packet.data));
try
{
isForwardKeyPressed = inputStream.readBoolean();
}
catch(IOException e)
{
e.printStackTrace();
return;
}
}
private void handlePacketHitValue(Packet250CustomPayload packet) {
DataInputStream inputStream = new DataInputStream(new ByteArrayInputStream(packet.data));
try
{
hit = new HitValueUntil(inputStream.readFloat(), inputStream.readLong());
}
catch(IOException e)
{
e.printStackTrace();
return;
}
}
private void handlePacketHitEntity(Packet250CustomPayload packet) {
DataInputStream inputStream = new DataInputStream(new ByteArrayInputStream(packet.data));
try
{
entityID = inputStream.readInt();
}
catch(IOException e)
{
e.printStackTrace();
return;
}
}
private void handlePacket(Packet250CustomPayload packet)
{
DataInputStream inputStream = new DataInputStream(new ByteArrayInputStream(packet.data));
int randomInt1;
int randomInt2;
try
{
randomInt1 = inputStream.readInt();
randomInt2 = inputStream.readInt();
}
catch(IOException e)
{
e.printStackTrace();
return;
}
System.out.println(randomInt1 + " " + randomInt2);
}
}