// Path: src/main/java/com/lordmau5/ffs/network/handlers/client/OnTankBreak.java
// public class OnTankBreak extends SimpleChannelInboundHandler<FFSPacket.Client.OnTankBreak> {
// 
//     @Override
//     protected void channelRead0(ChannelHandlerContext ctx, FFSPacket.Client.OnTankBreak msg) throws Exception {
//         FancyFluidStorage.tankManager.remove(msg.getDimension(), msg.getValvePos());
//     }
// }
// 
// Path: src/main/java/com/lordmau5/ffs/network/handlers/client/OnTankBuild.java
// public class OnTankBuild extends SimpleChannelInboundHandler<FFSPacket.Client.OnTankBuild> {
// 
//     @Override
//     protected void channelRead0(ChannelHandlerContext ctx, FFSPacket.Client.OnTankBuild msg) throws Exception {
//         if ( Minecraft.getMinecraft().world != null ) {
//             TileEntity tile = Minecraft.getMinecraft().world.getTileEntity(msg.getValvePos());
//             if ( tile != null && tile instanceof AbstractTankValve ) {
//                 FancyFluidStorage.tankManager.add(Minecraft.getMinecraft().world, msg.getValvePos(), msg.getAirBlocks(), msg.getFrameBlocks());
//             }
//         }
//     }
// }
// 
// Path: src/main/java/com/lordmau5/ffs/network/handlers/server/OnTankRequest.java
// public class OnTankRequest extends SimpleChannelInboundHandler<FFSPacket.Server.OnTankRequest> {
// 
//     @Override
//     protected void channelRead0(ChannelHandlerContext ctx, FFSPacket.Server.OnTankRequest msg) throws Exception {
//         World world = NetworkHandler.getPlayer(ctx).getEntityWorld();
//         if ( world != null ) {
//             TileEntity tile = world.getTileEntity(msg.getPos());
//             if ( tile != null && tile instanceof AbstractTankValve ) {
//                 NetworkHandler.sendPacketToPlayer(new FFSPacket.Client.OnTankBuild((AbstractTankValve) tile), NetworkHandler.getPlayer(ctx));
//             }
//         }
//     }
// }
// 
// Path: src/main/java/com/lordmau5/ffs/network/handlers/server/UpdateFluidLock_Server.java
// public class UpdateFluidLock_Server extends SimpleChannelInboundHandler<FFSPacket.Server.UpdateFluidLock> {
// 
//     @Override
//     protected void channelRead0(ChannelHandlerContext ctx, FFSPacket.Server.UpdateFluidLock msg) throws Exception {
//         World world = NetworkHandler.getPlayer(ctx).getEntityWorld();
//         if ( world != null ) {
//             TileEntity tile = world.getTileEntity(msg.getPos());
//             if ( tile != null && tile instanceof AbstractTankValve ) {
//                 AbstractTankValve valve = (AbstractTankValve) tile;
//                 valve.toggleFluidLock(msg.isFluidLock());
//             }
//         }
//     }
// }
// 
// Path: src/main/java/com/lordmau5/ffs/network/handlers/server/UpdateTileName_Server.java
// public class UpdateTileName_Server extends SimpleChannelInboundHandler<FFSPacket.Server.UpdateTileName> {
// 
//     @Override
//     protected void channelRead0(ChannelHandlerContext ctx, FFSPacket.Server.UpdateTileName msg) throws Exception {
//         World world = NetworkHandler.getPlayer(ctx).getEntityWorld();
//         if ( world != null ) {
//             TileEntity w_Tile = world.getTileEntity(msg.getPos());
//             if ( w_Tile != null && w_Tile instanceof AbstractTankTile && w_Tile instanceof INameableTile ) {
//                 AbstractTankTile tile = (AbstractTankTile) w_Tile;
//                 ((INameableTile) tile).setTileName(msg.getName());
//                 tile.markForUpdateNow();
//             }
//         }
//     }
// }


import com.lordmau5.ffs.network.handlers.client.OnTankBreak;
import com.lordmau5.ffs.network.handlers.client.OnTankBuild;
import com.lordmau5.ffs.network.handlers.server.OnTankRequest;
import com.lordmau5.ffs.network.handlers.server.UpdateFluidLock_Server;
import com.lordmau5.ffs.network.handlers.server.UpdateTileName_Server;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPipeline;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.network.NetHandlerPlayServer;
import net.minecraft.network.Packet;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.network.FMLEmbeddedChannel;
import net.minecraftforge.fml.common.network.FMLOutboundHandler;
import net.minecraftforge.fml.common.network.NetworkRegistry;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import java.util.EnumMap;
package com.lordmau5.ffs.network;



/**
 * Created by Dustin on 07.07.2015.
 */
public class NetworkHandler {
    private static EnumMap<Side, FMLEmbeddedChannel> channels;

    public static void registerChannels(Side side) {
        channels = NetworkRegistry.INSTANCE.newChannel("ffs", new PacketCodec());

        ChannelPipeline pipeline = channels.get(Side.SERVER).pipeline();
        String targetName = channels.get(Side.SERVER).findChannelHandlerNameForType(PacketCodec.class);

        pipeline.addAfter(targetName, "UpdateTileName_Server", new UpdateTileName_Server());
// Path: src/main/java/com/lordmau5/ffs/network/handlers/client/OnTankBreak.java
// public class OnTankBreak extends SimpleChannelInboundHandler<FFSPacket.Client.OnTankBreak> {
// 
//     @Override
//     protected void channelRead0(ChannelHandlerContext ctx, FFSPacket.Client.OnTankBreak msg) throws Exception {
//         FancyFluidStorage.tankManager.remove(msg.getDimension(), msg.getValvePos());
//     }
// }
// 
// Path: src/main/java/com/lordmau5/ffs/network/handlers/client/OnTankBuild.java
// public class OnTankBuild extends SimpleChannelInboundHandler<FFSPacket.Client.OnTankBuild> {
// 
//     @Override
//     protected void channelRead0(ChannelHandlerContext ctx, FFSPacket.Client.OnTankBuild msg) throws Exception {
//         if ( Minecraft.getMinecraft().world != null ) {
//             TileEntity tile = Minecraft.getMinecraft().world.getTileEntity(msg.getValvePos());
//             if ( tile != null && tile instanceof AbstractTankValve ) {
//                 FancyFluidStorage.tankManager.add(Minecraft.getMinecraft().world, msg.getValvePos(), msg.getAirBlocks(), msg.getFrameBlocks());
//             }
//         }
//     }
// }
// 
// Path: src/main/java/com/lordmau5/ffs/network/handlers/server/OnTankRequest.java
// public class OnTankRequest extends SimpleChannelInboundHandler<FFSPacket.Server.OnTankRequest> {
// 
//     @Override
//     protected void channelRead0(ChannelHandlerContext ctx, FFSPacket.Server.OnTankRequest msg) throws Exception {
//         World world = NetworkHandler.getPlayer(ctx).getEntityWorld();
//         if ( world != null ) {
//             TileEntity tile = world.getTileEntity(msg.getPos());
//             if ( tile != null && tile instanceof AbstractTankValve ) {
//                 NetworkHandler.sendPacketToPlayer(new FFSPacket.Client.OnTankBuild((AbstractTankValve) tile), NetworkHandler.getPlayer(ctx));
//             }
//         }
//     }
// }
// 
// Path: src/main/java/com/lordmau5/ffs/network/handlers/server/UpdateFluidLock_Server.java
// public class UpdateFluidLock_Server extends SimpleChannelInboundHandler<FFSPacket.Server.UpdateFluidLock> {
// 
//     @Override
//     protected void channelRead0(ChannelHandlerContext ctx, FFSPacket.Server.UpdateFluidLock msg) throws Exception {
//         World world = NetworkHandler.getPlayer(ctx).getEntityWorld();
//         if ( world != null ) {
//             TileEntity tile = world.getTileEntity(msg.getPos());
//             if ( tile != null && tile instanceof AbstractTankValve ) {
//                 AbstractTankValve valve = (AbstractTankValve) tile;
//                 valve.toggleFluidLock(msg.isFluidLock());
//             }
//         }
//     }
// }
// 
// Path: src/main/java/com/lordmau5/ffs/network/handlers/server/UpdateTileName_Server.java
// public class UpdateTileName_Server extends SimpleChannelInboundHandler<FFSPacket.Server.UpdateTileName> {
// 
//     @Override
//     protected void channelRead0(ChannelHandlerContext ctx, FFSPacket.Server.UpdateTileName msg) throws Exception {
//         World world = NetworkHandler.getPlayer(ctx).getEntityWorld();
//         if ( world != null ) {
//             TileEntity w_Tile = world.getTileEntity(msg.getPos());
//             if ( w_Tile != null && w_Tile instanceof AbstractTankTile && w_Tile instanceof INameableTile ) {
//                 AbstractTankTile tile = (AbstractTankTile) w_Tile;
//                 ((INameableTile) tile).setTileName(msg.getName());
//                 tile.markForUpdateNow();
//             }
//         }
//     }
// }


// Path: src/main/java/com/lordmau5/ffs/network/NetworkHandler.java
import com.lordmau5.ffs.network.handlers.client.OnTankBreak;
import com.lordmau5.ffs.network.handlers.client.OnTankBuild;
import com.lordmau5.ffs.network.handlers.server.OnTankRequest;
import com.lordmau5.ffs.network.handlers.server.UpdateFluidLock_Server;
import com.lordmau5.ffs.network.handlers.server.UpdateTileName_Server;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPipeline;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.network.NetHandlerPlayServer;
import net.minecraft.network.Packet;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.network.FMLEmbeddedChannel;
import net.minecraftforge.fml.common.network.FMLOutboundHandler;
import net.minecraftforge.fml.common.network.NetworkRegistry;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import java.util.EnumMap;

package com.lordmau5.ffs.network;



/**
 * Created by Dustin on 07.07.2015.
 */
public class NetworkHandler {
    private static EnumMap<Side, FMLEmbeddedChannel> channels;

    public static void registerChannels(Side side) {
        channels = NetworkRegistry.INSTANCE.newChannel("ffs", new PacketCodec());

        ChannelPipeline pipeline = channels.get(Side.SERVER).pipeline();
        String targetName = channels.get(Side.SERVER).findChannelHandlerNameForType(PacketCodec.class);

        pipeline.addAfter(targetName, "UpdateTileName_Server", new UpdateTileName_Server());
        pipeline.addAfter(targetName, "UpdateFluidLock_Server", new UpdateFluidLock_Server());