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
98
99
100
101
102
103
104
105
106
107
108
109
|
package gregtech.api.net;
import com.google.common.io.ByteArrayDataInput;
import gregtech.api.enums.GT_Values;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.common.GT_Proxy;
import io.netty.buffer.ByteBuf;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.DimensionManager;
/**
* Client -> Server: Request that the server opens a Gregtech GUI for us after providing us with the required data.
*/
public class GT_Packet_GtTileEntityGuiRequest extends GT_Packet_New {
protected int mX;
protected short mY;
protected int mZ;
protected int guiId;
protected int dimId, playerId;
protected int parentGuiId;
public GT_Packet_GtTileEntityGuiRequest() {
super(true);
}
public GT_Packet_GtTileEntityGuiRequest(
int mX, short mY, int mZ, int guiId, int dimID, int playerID, int parentGuiId) {
super(false);
this.mX = mX;
this.mY = mY;
this.mZ = mZ;
this.guiId = guiId;
this.dimId = dimID;
this.playerId = playerID;
this.parentGuiId = parentGuiId;
}
public GT_Packet_GtTileEntityGuiRequest(int mX, short mY, int mZ, int guiId, int dimID, int playerID) {
this(mX, mY, mZ, guiId, dimID, playerID, -1);
}
@Override
public void encode(ByteBuf aOut) {
aOut.writeInt(mX);
aOut.writeShort(mY);
aOut.writeInt(mZ);
aOut.writeInt(guiId);
aOut.writeInt(dimId);
aOut.writeInt(playerId);
aOut.writeInt(parentGuiId);
}
@Override
public GT_Packet_New decode(ByteArrayDataInput aData) {
return new GT_Packet_GtTileEntityGuiRequest(
aData.readInt(),
aData.readShort(),
aData.readInt(),
aData.readInt(),
aData.readInt(),
aData.readInt(),
aData.readInt());
}
@Override
public byte getPacketID() {
return 15;
}
@Override
public void process(IBlockAccess aWorld) {
World world = DimensionManager.getWorld(this.dimId);
if (world == null) return;
TileEntity tile = world.getTileEntity(this.mX, this.mY, this.mZ);
if (!(tile instanceof IGregTechTileEntity) || ((IGregTechTileEntity) tile).isDead()) return;
IGregTechTileEntity gtTile = ((IGregTechTileEntity) tile);
EntityPlayerMP player = (EntityPlayerMP) world.getEntityByID(playerId);
// If the requested Gui ID corresponds to a cover, send the cover data to the client so they can open it.
if (GT_Proxy.GUI_ID_COVER_SIDE_BASE <= guiId && guiId < GT_Proxy.GUI_ID_COVER_SIDE_BASE + 6) {
byte coverSide = (byte) (guiId - GT_Proxy.GUI_ID_COVER_SIDE_BASE);
GT_Packet_TileEntityCoverGUI packet = new GT_Packet_TileEntityCoverGUI(
this.mX,
this.mY,
this.mZ,
coverSide,
gtTile.getCoverIDAtSide(coverSide),
gtTile.getComplexCoverDataAtSide(coverSide),
this.dimId,
this.playerId,
parentGuiId);
GT_Values.NW.sendToPlayer(packet, player);
} else if (guiId == 0) {
gtTile.openGUI(player);
}
}
}
|