forked from LazDude2012/SGExtensions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SGChannel.java
80 lines (67 loc) · 2.16 KB
/
SGChannel.java
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
//------------------------------------------------------------------------------------------------
//
// SG Craft - Packet Handling
//
//------------------------------------------------------------------------------------------------
package sgextensions;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
//import net.minecraft.item.Item;
//import net.minecraft.item.ItemStack;
enum PacketType
{
SetHomeAddress, ConnectOrDisconnect;
}
public class SGChannel extends BaseNBTChannel<PacketType>
{
static SGChannel network;
public SGChannel(String channelName)
{
super(channelName);
network = this;
}
@Override
public void onReceiveFromClient(PacketType type, NBTTagCompound nbt, EntityPlayer player)
{
switch (type)
{
case SetHomeAddress:
//handleSetHomeAddressFromClient(nbt, player);
break;
case ConnectOrDisconnect:
handleConnectOrDisconnectFromClient(nbt, player);
break;
}
}
public static void sendConnectOrDisconnectToServer(SGBaseTE te, String address)
{
NBTTagCompound nbt = te.nbtWithCoords();
nbt.setString("address", address);
network.sendToServer(PacketType.ConnectOrDisconnect, nbt);
}
static void handleConnectOrDisconnectFromClient(NBTTagCompound nbt, EntityPlayer player)
{
SGBaseTE te = SGBaseTE.at(player.worldObj, nbt);
String address = nbt.getString("address");
te.connectOrDisconnect(address, player);
}
public static void sendSetHomeAddressToServer(SGBaseTE te, String address)
{
NBTTagCompound nbt = new NBTTagCompound();
nbt.setInteger("x", te.xCoord);
nbt.setInteger("y", te.yCoord);
nbt.setInteger("z", te.zCoord);
nbt.setString("address", address);
network.sendToServer(PacketType.SetHomeAddress, nbt);
}
// void handleSetHomeAddressFromClient(NBTTagCompound nbt, EntityPlayer player) {
// int x = nbt.getInteger("x");
// int y = nbt.getInteger("y");
// int z = nbt.getInteger("z");
// String address = nbt.getString("address");
// System.out.printf("SGChannel.handleSetHomeAddressFromClient: (%d,%d,%d) '%s' \n", x, y, z, address);
// SGBaseTE te = SGBaseTE.at(player.worldObj, x, y, z);
// if (te != null)
// te.setHomeAddress(address);
// }
}