Package de.eydamos.backpack.network.message

Source Code of de.eydamos.backpack.network.message.MessageGuiCommand

package de.eydamos.backpack.network.message;

import io.netty.buffer.ByteBuf;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.inventory.Container;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
import de.eydamos.backpack.inventory.container.ContainerWorkbenchBackpack;
import de.eydamos.backpack.misc.Constants;

public class MessageGuiCommand implements IMessage, IMessageHandler<MessageGuiCommand, IMessage> {
    protected byte command;

    public MessageGuiCommand() {}
   
    public MessageGuiCommand(byte guiCommand) {
        command = guiCommand;
    }

    @Override
    public void fromBytes(ByteBuf buffer) {
        command = buffer.readByte();
    }

    @Override
    public void toBytes(ByteBuf buffer) {
        buffer.writeByte(command);
    }

    @Override
    public IMessage onMessage(MessageGuiCommand message, MessageContext ctx) {
        EntityPlayerMP entityPlayer = ctx.getServerHandler().playerEntity;

        Container container = entityPlayer.openContainer;

        switch(message.command) {
            case Constants.GuiCommands.CLEAR:
                if(container instanceof ContainerWorkbenchBackpack) {
                    ((ContainerWorkbenchBackpack) container).clearCraftMatrix();
                }
                break;
            case Constants.GuiCommands.SAVE:
                if(container instanceof ContainerWorkbenchBackpack) {
                    ((ContainerWorkbenchBackpack) container).setSaveMode();
                }
                break;
        }

        return null;
    }

}
TOP

Related Classes of de.eydamos.backpack.network.message.MessageGuiCommand

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.