@Override
  public void readFromNBT(NBTTagCompound nbt) {
    super.readFromNBT(nbt);
    NBTTagList var2 = nbt.getTagList("Items", 10);
    this.containingItems = new ItemStack[this.getSizeInventory()];

    for (int var3 = 0; var3 < var2.tagCount(); ++var3) {
      NBTTagCompound var4 = var2.getCompoundTagAt(var3);
      int var5 = var4.getByte("Slot") & 255;

      if (var5 < this.containingItems.length) {
        this.containingItems[var5] = ItemStack.loadItemStackFromNBT(var4);
      }
    }

    this.setAddress(nbt.getInteger("Address"));
    this.targetAddress = nbt.getInteger("TargetAddress");
    this.owner = nbt.getString("Owner");
  }
  @Override
  public void writeToNBT(NBTTagCompound nbt) {
    super.writeToNBT(nbt);
    NBTTagList var2 = new NBTTagList();

    for (int var3 = 0; var3 < this.containingItems.length; ++var3) {
      if (this.containingItems[var3] != null) {
        NBTTagCompound var4 = new NBTTagCompound();
        var4.setByte("Slot", (byte) var3);
        this.containingItems[var3].writeToNBT(var4);
        var2.appendTag(var4);
      }
    }

    nbt.setTag("Items", var2);

    nbt.setInteger("TargetAddress", this.targetAddress);
    nbt.setInteger("Address", this.address);
    nbt.setString("Owner", this.owner);
  }
  @Override
  public void update() {
    if (this.ticks % 40 == 0 && !worldObj.isRemote) {
      this.setAddress(this.address);
      this.setTargetAddress(this.targetAddress);
    }

    if (!this.worldObj.isRemote) {
      if (this.targetAddressResult == EnumTelepadSearchResult.VALID
          && (this.ticks % 5 == 0 || teleporting)) {
        List containedEntities =
            worldObj.getEntitiesWithinAABB(
                EntityLivingBase.class,
                AxisAlignedBB.fromBounds(
                    this.getPos().getX(),
                    this.getPos().getY(),
                    this.getPos().getZ(),
                    this.getPos().getX() + 1,
                    this.getPos().getY() + 2,
                    this.getPos().getZ() + 1));

        if (containedEntities.size() > 0 && this.getEnergyStoredGC() >= ENERGY_USE_ON_TELEPORT) {
          ShortRangeTelepadHandler.TelepadEntry entry =
              ShortRangeTelepadHandler.getLocationFromAddress(this.targetAddress);

          if (entry != null) {
            teleporting = true;
          }
        } else {
          teleporting = false;
        }
      }

      if (this.teleporting) {
        this.teleportTime++;

        if (teleportTime >= MAX_TELEPORT_TIME) {
          ShortRangeTelepadHandler.TelepadEntry entry =
              ShortRangeTelepadHandler.getLocationFromAddress(this.targetAddress);

          BlockVec3 finalPos = (entry == null) ? null : entry.position;

          if (finalPos != null) {
            TileEntity tileAt = finalPos.getTileEntity(this.worldObj);
            List<EntityLivingBase> containedEntities =
                worldObj.getEntitiesWithinAABB(
                    EntityLivingBase.class,
                    AxisAlignedBB.fromBounds(
                        this.getPos().getX(),
                        this.getPos().getY(),
                        this.getPos().getZ(),
                        this.getPos().getX() + 1,
                        this.getPos().getY() + 2,
                        this.getPos().getZ() + 1));

            if (tileAt != null && tileAt instanceof TileEntityShortRangeTelepad) {
              TileEntityShortRangeTelepad destTelepad = (TileEntityShortRangeTelepad) tileAt;
              int teleportResult = destTelepad.canTeleportHere();
              if (teleportResult == 0) {
                for (EntityLivingBase e : containedEntities) {
                  e.setPosition(finalPos.x + 0.5F, finalPos.y + 1.0F, finalPos.z + 0.5F);
                  this.worldObj.updateEntityWithOptionalForce(e, true);
                  if (e instanceof EntityPlayerMP) {
                    ((EntityPlayerMP) e)
                        .playerNetServerHandler.setPlayerLocation(
                            finalPos.x, finalPos.y, finalPos.z, e.rotationYaw, e.rotationPitch);
                  }
                  GalacticraftCore.packetPipeline.sendToDimension(
                      new PacketSimpleAsteroids(
                          PacketSimpleAsteroids.EnumSimplePacketAsteroids.C_TELEPAD_SEND,
                          this.worldObj.provider.getDimensionId(),
                          new Object[] {finalPos, e.getEntityId()}),
                      this.worldObj.provider.getDimensionId());
                }

                if (containedEntities.size() > 0) {
                  this.storage.setEnergyStored(
                      this.storage.getEnergyStoredGC() - ENERGY_USE_ON_TELEPORT);
                  destTelepad.storage.setEnergyStored(
                      this.storage.getEnergyStoredGC() - ENERGY_USE_ON_TELEPORT);
                }
              } else {
                switch (teleportResult) {
                  case -1:
                    for (EntityLivingBase e : containedEntities) {
                      if (e instanceof EntityPlayer) {
                        ((EntityPlayer) e)
                            .addChatComponentMessage(
                                new ChatComponentText(
                                    "Cannot Send client-side")); // No need for translation, since
                                                                 // this should never happen
                      }
                    }
                    break;
                  case 1:
                    for (EntityLivingBase e : containedEntities) {
                      if (e instanceof EntityPlayer) {
                        ((EntityPlayer) e)
                            .addChatComponentMessage(
                                new ChatComponentText(
                                    "Target address invalid")); // No need for translation, since
                                                                // this should never happen
                      }
                    }
                    break;
                  case 2:
                    for (EntityLivingBase e : containedEntities) {
                      if (e instanceof EntityPlayer) {
                        ((EntityPlayer) e)
                            .addChatComponentMessage(
                                new ChatComponentText(
                                    GCCoreUtil.translate("gui.message.target_no_energy.name")));
                      }
                    }
                    break;
                }
              }
            }
          }

          this.teleportTime = 0;
          this.teleporting = false;
        }
      } else {
        this.teleportTime = Math.max(--this.teleportTime, 0);
      }
    }

    super.update();
  }
 @Override
 public void readExtraNetworkedData(ByteBuf dataStream) {
   super.readExtraNetworkedData(dataStream);
   targetAddressResult = EnumTelepadSearchResult.values()[dataStream.readInt()];
 }
 @Override
 public void addExtraNetworkedData(List<Object> networkedList) {
   super.addExtraNetworkedData(networkedList);
   networkedList.add(targetAddressResult.ordinal());
 }