@Override
  public void read(ByteArrayDataInput dataStream, EntityPlayer player, World world)
      throws Exception {
    ItemStack itemstack = player.getCurrentEquippedItem();

    if (itemstack != null && itemstack.getItem() instanceof ItemPortableTeleporter) {
      ItemPortableTeleporter item = (ItemPortableTeleporter) itemstack.getItem();

      if (item.getStatus(itemstack) == 1) {
        Object3D coords =
            MekanismUtils.getClosestCoords(
                new Teleporter.Code(
                    item.getDigit(itemstack, 0),
                    item.getDigit(itemstack, 1),
                    item.getDigit(itemstack, 2),
                    item.getDigit(itemstack, 3)),
                player);

        item.setEnergy(
            itemstack, item.getEnergy(itemstack) - item.calculateEnergyCost(player, coords));

        if (world.provider.dimensionId != coords.dimensionId) {
          ((EntityPlayerMP) player).travelToDimension(coords.dimensionId);
        }

        ((EntityPlayerMP) player)
            .playerNetServerHandler.setPlayerLocation(
                coords.xCoord + 0.5,
                coords.yCoord + 1,
                coords.zCoord + 0.5,
                player.rotationYaw,
                player.rotationPitch);

        world.playSoundAtEntity(player, "mob.endermen.portal", 1.0F, 1.0F);
        PacketHandler.sendPacket(
            Transmission.CLIENTS_RANGE, new PacketPortalFX().setParams(coords), coords, 40D);
      }
    }
  }
  @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();
  }