aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/GoodGenerator/Network/MessageSetNeutronSensorData.java
blob: 39d08d92c3295788f9c651d55353e1279e5d8d53 (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
package GoodGenerator.Network;

import GoodGenerator.Blocks.TEs.MetaTE.NeutronSensor;
import com.github.technus.tectech.TecTech;
import cpw.mods.fml.common.network.ByteBufUtils;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
import cpw.mods.fml.relauncher.Side;
import gregtech.api.interfaces.metatileentity.IMetaTileEntity;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import io.netty.buffer.ByteBuf;

public class MessageSetNeutronSensorData extends MessageMTEBase {
    protected String data;

    public MessageSetNeutronSensorData() {
    }

    public MessageSetNeutronSensorData(IGregTechTileEntity tile, String data) {
        super(tile);
        this.data = data;
    }

    @Override
    public void fromBytes(ByteBuf buf) {
        super.fromBytes(buf);
        data = ByteBufUtils.readUTF8String(buf);
    }

    @Override
    public void toBytes(ByteBuf buf) {
        super.toBytes(buf);
        ByteBufUtils.writeUTF8String(buf, data);
    }

    public static class ServerHandler extends MessageMTEBase.Handler<MessageSetNeutronSensorData, IMessage> {
        @Override
        protected IMessage onError(MessageSetNeutronSensorData message, MessageContext ctx) {
            return null;
        }

        @Override
        protected IMessage onSuccess(MessageSetNeutronSensorData message, MessageContext ctx, IMetaTileEntity mte) {
            if (mte instanceof NeutronSensor) {
                ((NeutronSensor) mte).setText(message.data);
                if (ctx.side == Side.CLIENT)
                    mte.getBaseMetaTileEntity().openGUI(TecTech.proxy.getPlayer());
            }
            return null;
        }
    }
}