// Path: src/main/java/cn/academy/energy/api/block/IWirelessGenerator.java
// public interface IWirelessGenerator extends IWirelessUser {
// 
//     /**
//      * @param req How much energy is required
//      * @return How much energy this generator can provide. Must be guaranteed 0<=ret<=req
//      */
//     public double getProvidedEnergy(double req);
// 
//     /**
//      * @return Max energy transmitted each tick
//      */
//     public double getBandwidth();
// 
// }
// 
// Path: src/main/java/cn/academy/energy/api/block/IWirelessReceiver.java
// public interface IWirelessReceiver extends IWirelessUser {
// 
//     double getRequiredEnergy();
// 
//     /**
//      * Inject some amount of energy into the machine. ALWAYS positive
//      * @return energy not injected
//      */
//     double injectEnergy(double amt);
// 
//     /**
//      * Pull some energy out of the machine. ALWAYS positive
//      * @param amt The amount
//      * @return energy really pulled out.
//      */
//     double pullEnergy(double amt);
// 
//     /**
//      * @return How much energy this receiver can retrieve each tick.
//      */
//     double getBandwidth();
// 
// }
// 
// Path: src/main/java/cn/academy/energy/api/event/WirelessUserEvent.java
// public enum UserType {GENERATOR, RECEIVER}
// 
// Path: src/main/java/cn/academy/energy/api/event/node/LinkUserEvent.java
// @Cancelable
// public class LinkUserEvent extends WirelessUserEvent {
// 
//     public final IWirelessNode node;
// 
//     public LinkUserEvent(IWirelessTile _tile, IWirelessNode _node) {
//         super(_tile);
//         node = _node;
//     }
// 
// }
// 
// Path: src/main/java/cn/academy/energy/api/event/node/UnlinkUserEvent.java
// public class UnlinkUserEvent extends WirelessUserEvent {
// 
//     public UnlinkUserEvent(IWirelessTile _tile) {
//         super(_tile);
//     }
// 
// }
// 
// Path: src/main/java/cn/academy/energy/internal/VBlocks.java
// static class VNGenerator extends VBlock<IWirelessGenerator> {
//     public VNGenerator(IWirelessGenerator te) {
//         super((TileEntity) te, true);
//     }
// 
//     public VNGenerator(NBTTagCompound tag) {
//         super(tag, true);
//     }
// 
//     @Override
//     protected boolean isAcceptable(TileEntity tile) {
//         return tile instanceof IWirelessGenerator;
//     }
// }
// 
// Path: src/main/java/cn/academy/energy/internal/VBlocks.java
// static class VNReceiver extends VBlock<IWirelessReceiver> {
//     public VNReceiver(IWirelessReceiver te) {
//         super((TileEntity) te, true);
//     }
// 
//     public VNReceiver(NBTTagCompound tag) {
//         super(tag, true);
//     }
// 
//     @Override
//     protected boolean isAcceptable(TileEntity tile) {
//         return tile instanceof IWirelessReceiver;
//     }
// }
// 
// Path: src/main/java/cn/academy/energy/internal/VBlocks.java
// static class VWNode extends VBlock<IWirelessNode> {
// 
//     public VWNode(IWirelessNode te) {
//         super((TileEntity) te, false);
//     }
// 
//     public VWNode(NBTTagCompound tag) {
//         super(tag, false);
//     }
// 
//     @Override
//     protected boolean isAcceptable(TileEntity tile) {
//         return tile instanceof IWirelessNode;
//     }
// 
// }


import cn.academy.energy.api.block.IWirelessGenerator;
import cn.academy.energy.api.block.IWirelessReceiver;
import cn.academy.energy.api.event.WirelessUserEvent.UserType;
import cn.academy.energy.api.event.node.LinkUserEvent;
import cn.academy.energy.api.event.node.UnlinkUserEvent;
import cn.academy.energy.api.event.wen.*;
import cn.academy.energy.internal.VBlocks.VNGenerator;
import cn.academy.energy.internal.VBlocks.VNReceiver;
import cn.academy.energy.internal.VBlocks.VWNode;
import cn.annoreg.core.RegEventHandler;
import cn.annoreg.core.Registrant;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.WorldServer;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent.ServerTickEvent;

    @SubscribeEvent
    public void onCreateNet(CreateNetworkEvent event) {
        WiWorldData data = WiWorldData.get(event.getWorld());
        if (!data.createNetwork(event.mat, event.ssid, event.pwd)) {
            event.setCanceled(true);
        }
    }

    @SubscribeEvent
    public void onDestroyNet(DestroyNetworkEvent event) {
        WiWorldData data = WiWorldData.get(event.getWorld());
        WirelessNet net = data.getNetwork(event.mat);
        if (net != null) net.dispose();
    }

    @SubscribeEvent
    public void changePass(ChangePassEvent event) {
        WiWorldData data = WiWorldData.get(event.getWorld());
        WirelessNet net = data.getNetwork(event.mat);
        if (net == null || !net.resetPassword(event.oldpwd, event.pwd)) {
            event.setCanceled(true);
        }
    }

    @SubscribeEvent
    public void linkNode(LinkNodeEvent event) {
        WiWorldData data = WiWorldData.get(event.getWorld());
        WirelessNet net = data.getNetwork(event.ssid);

// Path: src/main/java/cn/academy/energy/api/block/IWirelessGenerator.java
// public interface IWirelessGenerator extends IWirelessUser {
// 
//     /**
//      * @param req How much energy is required
//      * @return How much energy this generator can provide. Must be guaranteed 0<=ret<=req
//      */
//     public double getProvidedEnergy(double req);
// 
//     /**
//      * @return Max energy transmitted each tick
//      */
//     public double getBandwidth();
// 
// }
// 
// Path: src/main/java/cn/academy/energy/api/block/IWirelessReceiver.java
// public interface IWirelessReceiver extends IWirelessUser {
// 
//     double getRequiredEnergy();
// 
//     /**
//      * Inject some amount of energy into the machine. ALWAYS positive
//      * @return energy not injected
//      */
//     double injectEnergy(double amt);
// 
//     /**
//      * Pull some energy out of the machine. ALWAYS positive
//      * @param amt The amount
//      * @return energy really pulled out.
//      */
//     double pullEnergy(double amt);
// 
//     /**
//      * @return How much energy this receiver can retrieve each tick.
//      */
//     double getBandwidth();
// 
// }
// 
// Path: src/main/java/cn/academy/energy/api/event/WirelessUserEvent.java
// public enum UserType {GENERATOR, RECEIVER}
// 
// Path: src/main/java/cn/academy/energy/api/event/node/LinkUserEvent.java
// @Cancelable
// public class LinkUserEvent extends WirelessUserEvent {
// 
//     public final IWirelessNode node;
// 
//     public LinkUserEvent(IWirelessTile _tile, IWirelessNode _node) {
//         super(_tile);
//         node = _node;
//     }
// 
// }
// 
// Path: src/main/java/cn/academy/energy/api/event/node/UnlinkUserEvent.java
// public class UnlinkUserEvent extends WirelessUserEvent {
// 
//     public UnlinkUserEvent(IWirelessTile _tile) {
//         super(_tile);
//     }
// 
// }
// 
// Path: src/main/java/cn/academy/energy/internal/VBlocks.java
// static class VNGenerator extends VBlock<IWirelessGenerator> {
//     public VNGenerator(IWirelessGenerator te) {
//         super((TileEntity) te, true);
//     }
// 
//     public VNGenerator(NBTTagCompound tag) {
//         super(tag, true);
//     }
// 
//     @Override
//     protected boolean isAcceptable(TileEntity tile) {
//         return tile instanceof IWirelessGenerator;
//     }
// }
// 
// Path: src/main/java/cn/academy/energy/internal/VBlocks.java
// static class VNReceiver extends VBlock<IWirelessReceiver> {
//     public VNReceiver(IWirelessReceiver te) {
//         super((TileEntity) te, true);
//     }
// 
//     public VNReceiver(NBTTagCompound tag) {
//         super(tag, true);
//     }
// 
//     @Override
//     protected boolean isAcceptable(TileEntity tile) {
//         return tile instanceof IWirelessReceiver;
//     }
// }
// 
// Path: src/main/java/cn/academy/energy/internal/VBlocks.java
// static class VWNode extends VBlock<IWirelessNode> {
// 
//     public VWNode(IWirelessNode te) {
//         super((TileEntity) te, false);
//     }
// 
//     public VWNode(NBTTagCompound tag) {
//         super(tag, false);
//     }
// 
//     @Override
//     protected boolean isAcceptable(TileEntity tile) {
//         return tile instanceof IWirelessNode;
//     }
// 
// }


// Path: src/main/java/cn/academy/energy/internal/WirelessSystem.java
import cn.academy.energy.api.block.IWirelessGenerator;
import cn.academy.energy.api.block.IWirelessReceiver;
import cn.academy.energy.api.event.WirelessUserEvent.UserType;
import cn.academy.energy.api.event.node.LinkUserEvent;
import cn.academy.energy.api.event.node.UnlinkUserEvent;
import cn.academy.energy.api.event.wen.*;
import cn.academy.energy.internal.VBlocks.VNGenerator;
import cn.academy.energy.internal.VBlocks.VNReceiver;
import cn.academy.energy.internal.VBlocks.VWNode;
import cn.annoreg.core.RegEventHandler;
import cn.annoreg.core.Registrant;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.WorldServer;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent.ServerTickEvent;


    @SubscribeEvent
    public void onCreateNet(CreateNetworkEvent event) {
        WiWorldData data = WiWorldData.get(event.getWorld());
        if (!data.createNetwork(event.mat, event.ssid, event.pwd)) {
            event.setCanceled(true);
        }
    }

    @SubscribeEvent
    public void onDestroyNet(DestroyNetworkEvent event) {
        WiWorldData data = WiWorldData.get(event.getWorld());
        WirelessNet net = data.getNetwork(event.mat);
        if (net != null) net.dispose();
    }

    @SubscribeEvent
    public void changePass(ChangePassEvent event) {
        WiWorldData data = WiWorldData.get(event.getWorld());
        WirelessNet net = data.getNetwork(event.mat);
        if (net == null || !net.resetPassword(event.oldpwd, event.pwd)) {
            event.setCanceled(true);
        }
    }

    @SubscribeEvent
    public void linkNode(LinkNodeEvent event) {
        WiWorldData data = WiWorldData.get(event.getWorld());
        WirelessNet net = data.getNetwork(event.ssid);

        if (net == null || !net.addNode(new VWNode(event.node), event.pwd))