@Override
  public void readFromNBT(NBTTagCompound nbttagcompound) {
    super.readFromNBT(nbttagcompound);
    try {
      this.IC_Outputpacketamount = nbttagcompound.getShort("ICOutputpacketamount");
    } catch (Exception e) {
      this.IC_Outputpacketamount = nbttagcompound.getInteger("ICOutputpacketamount");
    }
    this.IC_Output = nbttagcompound.getInteger("ICOutput");
    this.IC_Outputpacketsize = nbttagcompound.getInteger("ICOutputpacketsize");
    this.UE_Output = nbttagcompound.getInteger("UEOutput");
    this.UE_Outputvoltage = nbttagcompound.getInteger("UEOutputvoltage");
    this.UE_Outputamp = nbttagcompound.getInteger("UEOutputamp");

    NBTTagList nbttaglist = nbttagcompound.getTagList("Items");
    this.inventory = new ItemStack[getSizeInventory()];
    for (int i = 0; i < nbttaglist.tagCount(); i++) {
      NBTTagCompound nbttagcompound1 = (NBTTagCompound) nbttaglist.tagAt(i);

      byte byte0 = nbttagcompound1.getByte("Slot");
      if ((byte0 >= 0) && (byte0 < this.inventory.length)) {
        this.inventory[byte0] = ItemStack.loadItemStackFromNBT(nbttagcompound1);
      }
    }
  }
 @Override
 public void invalidate() {
   if (this.addedToEnergyNet) {
     MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent(this));
     this.addedToEnergyNet = false;
   }
   FrequencyGrid.getWorldMap(this.worldObj).getConverter().remove(Integer.valueOf(getDeviceID()));
   super.invalidate();
 }
  @Override
  public void updateEntity() {
    if (!this.worldObj.isRemote) {
      if ((!this.addedToEnergyNet) && (this.Industriecraftfound)) {
        try {
          MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent(this));
          this.addedToEnergyNet = true;
        } catch (Exception ex) {
          this.Industriecraftfound = false;
        }
      }

      if (hasPowerSource()) {
        setLinkPower((int) getForcePower());
      } else {
        setLinkPower(0);
      }

      if ((getSwitchMode() == 1) && (!getSwitchValue()) && (isPoweredByRedstone())) {
        onSwitch();
      }
      if ((getSwitchMode() == 1) && (getSwitchValue()) && (!isPoweredByRedstone())) {
        onSwitch();
      }

      if ((getSwitchValue()) && (hasPowerSource()) && (!isActive())) {
        setActive(true);
      }
      if (((!getSwitchValue()) || (!hasPowerSource())) && (isActive())) {
        setActive(false);
      }
      if ((isActive()) && (getIC_Output() == 1)) {
        EmitICpower(getIC_Outputpacketsize(), getIC_Outputpacketamount());
      }

      EmitUEPower(getUE_Outputvoltage(), getUE_Outputamp());
    }

    super.updateEntity();
  }
  @Override
  public void writeToNBT(NBTTagCompound nbttagcompound) {
    super.writeToNBT(nbttagcompound);

    nbttagcompound.setInteger("ICOutput", this.IC_Output);
    nbttagcompound.setInteger("ICOutputpacketsize", this.IC_Outputpacketsize);
    nbttagcompound.setInteger("ICOutputpacketamount", this.IC_Outputpacketamount);

    nbttagcompound.setInteger("UEOutput", this.UE_Output);
    nbttagcompound.setInteger("UEOutputvoltage", this.UE_Outputvoltage);
    nbttagcompound.setInteger("UEOutputamp", this.UE_Outputamp);

    NBTTagList nbttaglist = new NBTTagList();
    for (int i = 0; i < this.inventory.length; i++) {
      if (this.inventory[i] != null) {
        NBTTagCompound nbttagcompound1 = new NBTTagCompound();
        nbttagcompound1.setByte("Slot", (byte) i);
        this.inventory[i].writeToNBT(nbttagcompound1);
        nbttaglist.appendTag(nbttagcompound1);
      }
    }

    nbttagcompound.setTag("Items", nbttaglist);
  }
  @Override
  public void onNetworkHandlerEvent(int key, String value) {
    if (key == 100) {
      if (getIC_Output() == 0) {
        setIC_Output(1);
      } else {
        setIC_Output(0);
      }
    }

    if (key == 101) {
      if (getUE_Output() == 0) {
        setUE_Output(1);
      } else {
        setUE_Output(0);
      }
    }

    if (getIC_Output() == 0) {
      if (key == 200) {
        if (value.equalsIgnoreCase("+")) {
          switch (this.IC_Outputpacketsize) {
            case 1:
              this.IC_Outputpacketsize = 32;
              break;
            case 32:
              this.IC_Outputpacketsize = 128;
              break;
            case 128:
              this.IC_Outputpacketsize = 512;
              break;
            case 512:
              this.IC_Outputpacketsize = 2048;
              break;
            case 2048:
              this.IC_Outputpacketsize = 1;
          }
        }
        if (value.equalsIgnoreCase("-")) {
          switch (this.IC_Outputpacketsize) {
            case 1:
              this.IC_Outputpacketsize = 2048;
              break;
            case 32:
              this.IC_Outputpacketsize = 1;
              break;
            case 128:
              this.IC_Outputpacketsize = 32;
              break;
            case 512:
              this.IC_Outputpacketsize = 128;
              break;
            case 2048:
              this.IC_Outputpacketsize = 512;
          }
        }
      }
      if (key == 201) {
        if (value.equalsIgnoreCase("+")) {
          if (this.IC_Outputpacketamount == 9) {
            this.IC_Outputpacketamount = 1;
          } else {
            this.IC_Outputpacketamount += 1;
          }
        }
        if (value.equalsIgnoreCase("-")) {
          if (this.IC_Outputpacketamount == 1) {
            this.IC_Outputpacketamount = 9;
          } else {
            this.IC_Outputpacketamount -= 1;
          }
        }
      }
    }
    if (getUE_Output() == 0) {
      if (key == 202) {
        if (value.equalsIgnoreCase("+")) {
          switch (this.UE_Outputvoltage) {
            case 60:
              this.UE_Outputvoltage = 120;
              break;
            case 120:
              this.UE_Outputvoltage = 240;
              break;
            case 240:
              this.UE_Outputvoltage = 60;
          }
        }
        if (value.equalsIgnoreCase("-")) {
          switch (this.UE_Outputvoltage) {
            case 60:
              this.UE_Outputvoltage = 240;
              break;
            case 120:
              this.UE_Outputvoltage = 60;
              break;
            case 240:
              this.UE_Outputvoltage = 120;
          }
        }
      }
      if (key == 203) {
        if (value.equalsIgnoreCase("+")) {
          if (this.UE_Outputamp == 50) {
            this.UE_Outputamp = 1;
          } else {
            this.UE_Outputamp += 1;
          }
        }
        if (value.equalsIgnoreCase("-")) {
          if (this.UE_Outputamp == 1) {
            this.UE_Outputamp = 50;
          } else {
            this.UE_Outputamp -= 1;
          }
        }
      }
    }

    super.onNetworkHandlerEvent(key, value);
  }
 @Override
 public void setDirection(ForgeDirection facingDirection) {
   super.setDirection(facingDirection);
   this.setUEwireConnection();
 }
 @Override
 public void initiate() {
   super.initiate();
   setUEwireConnection();
 }