aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/api/net/GT_Packet.java
blob: d06ea7d0d3874e59db1d4749cb1fcff2ee479dbf (plain)
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
package gregtech.api.net;

import net.minecraft.network.INetHandler;
import net.minecraft.world.IBlockAccess;

import com.google.common.io.ByteArrayDataInput;

import io.netty.buffer.ByteBuf;

/**
 * @deprecated Use {@link GT_Packet_New} instead
 */
@Deprecated
public abstract class GT_Packet {

    public GT_Packet(boolean aIsReference) {
        //
    }

    /**
     * I use constant IDs instead of Dynamic ones, since that is much more fail safe
     *
     * @return a Packet ID for this Class
     */
    public abstract byte getPacketID();

    /**
     * @return encoded byte Stream
     * @deprecated Use {@link #encode(ByteBuf)} instead
     */
    @Deprecated
    public abstract byte[] encode();

    /**
     * Encode the data into given byte buffer without creating an intermediate byte array. Default implementation just
     * throw {@link UnsupportedOperationException}.
     */
    public void encode(ByteBuf aOut) {
        throw new UnsupportedOperationException();
    }

    /**
     * @return encoded byte Stream
     */
    public abstract GT_Packet decode(ByteArrayDataInput aData);

    /**
     * Process the packet
     *
     * @param aWorld null if message is received on server side, the client world if message is received on client side
     */
    public abstract void process(IBlockAccess aWorld);

    /**
     * This will be called just before {@link #process(IBlockAccess)} to inform the handler about the source and type of
     * connection
     */
    public void setINetHandler(INetHandler aHandler) {}
}