@Override
  public void onEntityCollidedWithBlock(World world, int x, int y, int z, Entity entity) {

    float shrinkAmount = 1f / 45f;
    if (entity.boundingBox.minY >= y + (1f - shrinkAmount)
        || entity.boundingBox.maxY <= y + shrinkAmount) return;
    entity.fallDistance = 0;
    if (entity.isCollidedHorizontally) {
      entity.motionY = 0.2D;
    } else if (entity.isSneaking()) {
      double diff = entity.prevPosY - entity.posY;
      entity.boundingBox.minY += diff;
      entity.boundingBox.maxY += diff;
      entity.posY = entity.prevPosY;
    } else {
      entity.motionY = -0.12D;
    }
  }
 /**
  * Called when the shield blocks an attack when held in the normal fashion (i.e. non-BG2) used by
  * Deku Shield to damage / destroy the stack and by Mirror Shield to reflect projectiles
  *
  * @return Return the amount of damage remaining, if any; 0 cancels the hurt event
  */
 public float onBlock(EntityPlayer player, ItemStack shield, DamageSource source, float damage) {
   ZSSPlayerInfo.get(player).onAttackBlocked(shield, damage);
   WorldUtils.playSoundAtEntity(player, Sounds.HAMMER, 0.4F, 0.5F);
   float damageBlocked = damage;
   if (toolMaterial == ToolMaterial.WOOD) {
     if (source.isProjectile()
         && !source.isExplosion()
         && source.getSourceOfDamage() instanceof IProjectile) {
       if (ZSSMain.isBG2Enabled
           && player.getHeldItem() == shield
           && shield.getItem() instanceof IArrowCatcher) {
         if (((IArrowCatcher) shield.getItem())
             .catchArrow(shield, player, (IProjectile) source.getSourceOfDamage())) {
           ((InventoryPlayerBattle) player.inventory).hasChanged = true;
         }
       }
     } else if (source instanceof IDamageAoE && ((IDamageAoE) source).isAoEDamage()) {
       damageBlocked *= magicReduction;
     }
     int dmg = Math.round(source.isFireDamage() ? damage + 10.0F : damage - 2.0F);
     if (dmg > 0) {
       shield.damageItem(dmg, player);
       if (shield.stackSize <= 0) {
         ForgeEventFactory.onPlayerDestroyItem(player, shield);
         if (ZSSMain.isBG2Enabled && BattlegearUtils.isPlayerInBattlemode(player)) {
           BattlegearUtils.setPlayerOffhandItem(player, null);
         } else {
           player.destroyCurrentEquippedItem();
         }
       }
     }
   } else if (toolMaterial == ToolMaterial.EMERALD) {
     if (source.isProjectile() && !source.isExplosion() && source.getSourceOfDamage() != null) {
       float chance = (source.isMagicDamage() ? (1F / 3F) : 1.0F);
       if (source.getSourceOfDamage() instanceof IReflectable) {
         ((IReflectable) source.getSourceOfDamage())
             .getReflectChance(shield, player, source.getEntity());
       }
       if (player.worldObj.rand.nextFloat() < chance) {
         Entity projectile = null;
         try {
           projectile =
               source
                   .getSourceOfDamage()
                   .getClass()
                   .getConstructor(World.class)
                   .newInstance(player.worldObj);
         } catch (Exception e) {;
         }
         if (projectile != null) {
           NBTTagCompound data = new NBTTagCompound();
           source.getSourceOfDamage().writeToNBT(data);
           projectile.readFromNBT(data);
           projectile.getEntityData().setBoolean("isReflected", true);
           projectile.posX -= projectile.motionX;
           projectile.posY -= projectile.motionY;
           projectile.posZ -= projectile.motionZ;
           double motionX =
               (double)
                   (-MathHelper.sin(player.rotationYaw / 180.0F * (float) Math.PI)
                       * MathHelper.cos(player.rotationPitch / 180.0F * (float) Math.PI));
           double motionZ =
               (double)
                   (MathHelper.cos(player.rotationYaw / 180.0F * (float) Math.PI)
                       * MathHelper.cos(player.rotationPitch / 180.0F * (float) Math.PI));
           double motionY =
               (double) (-MathHelper.sin(player.rotationPitch / 180.0F * (float) Math.PI));
           TargetUtils.setEntityHeading(
               projectile,
               motionX,
               motionY,
               motionZ,
               1.0F,
               2.0F + (20.0F * player.worldObj.rand.nextFloat()),
               false);
           if (projectile instanceof IReflectable) {
             ((IReflectable) projectile)
                 .onReflected(shield, player, source.getEntity(), source.getSourceOfDamage());
           }
           player.worldObj.spawnEntityInWorld(projectile);
         }
       } else if (source.isUnblockable()
           || (source instanceof IDamageAoE
               && ((IDamageAoE) source).isAoEDamage())) { // failed to reflect projectile
         damageBlocked *= magicReduction;
       }
     }
   } else if (source.isUnblockable()
       || (source instanceof IDamageAoE && ((IDamageAoE) source).isAoEDamage())) {
     damageBlocked *=
         magicReduction; // default shield behavior blocks half damage from AoE magic attacks
   }
   return (damage - damageBlocked);
 }
  /** Transfers an entity from a world to another world. */
  public void transferEntityToWorld(
      Entity entityIn, int p_82448_2_, WorldServer p_82448_3_, WorldServer p_82448_4_) {
    double var5 = entityIn.posX;
    double var7 = entityIn.posZ;
    double var9 = 8.0D;
    float var11 = entityIn.rotationYaw;
    p_82448_3_.theProfiler.startSection("moving");

    if (entityIn.dimension == -1) {
      var5 =
          MathHelper.clamp_double(
              var5 / var9,
              p_82448_4_.getWorldBorder().minX() + 16.0D,
              p_82448_4_.getWorldBorder().maxX() - 16.0D);
      var7 =
          MathHelper.clamp_double(
              var7 / var9,
              p_82448_4_.getWorldBorder().minZ() + 16.0D,
              p_82448_4_.getWorldBorder().maxZ() - 16.0D);
      entityIn.setLocationAndAngles(
          var5, entityIn.posY, var7, entityIn.rotationYaw, entityIn.rotationPitch);

      if (entityIn.isEntityAlive()) {
        p_82448_3_.updateEntityWithOptionalForce(entityIn, false);
      }
    } else if (entityIn.dimension == 0) {
      var5 =
          MathHelper.clamp_double(
              var5 * var9,
              p_82448_4_.getWorldBorder().minX() + 16.0D,
              p_82448_4_.getWorldBorder().maxX() - 16.0D);
      var7 =
          MathHelper.clamp_double(
              var7 * var9,
              p_82448_4_.getWorldBorder().minZ() + 16.0D,
              p_82448_4_.getWorldBorder().maxZ() - 16.0D);
      entityIn.setLocationAndAngles(
          var5, entityIn.posY, var7, entityIn.rotationYaw, entityIn.rotationPitch);

      if (entityIn.isEntityAlive()) {
        p_82448_3_.updateEntityWithOptionalForce(entityIn, false);
      }
    } else {
      BlockPos var12;

      if (p_82448_2_ == 1) {
        var12 = p_82448_4_.getSpawnPoint();
      } else {
        var12 = p_82448_4_.func_180504_m();
      }

      var5 = (double) var12.getX();
      entityIn.posY = (double) var12.getY();
      var7 = (double) var12.getZ();
      entityIn.setLocationAndAngles(var5, entityIn.posY, var7, 90.0F, 0.0F);

      if (entityIn.isEntityAlive()) {
        p_82448_3_.updateEntityWithOptionalForce(entityIn, false);
      }
    }

    p_82448_3_.theProfiler.endSection();

    if (p_82448_2_ != 1) {
      p_82448_3_.theProfiler.startSection("placing");
      var5 = (double) MathHelper.clamp_int((int) var5, -29999872, 29999872);
      var7 = (double) MathHelper.clamp_int((int) var7, -29999872, 29999872);

      if (entityIn.isEntityAlive()) {
        entityIn.setLocationAndAngles(
            var5, entityIn.posY, var7, entityIn.rotationYaw, entityIn.rotationPitch);
        p_82448_4_.getDefaultTeleporter().func_180266_a(entityIn, var11);
        p_82448_4_.spawnEntityInWorld(entityIn);
        p_82448_4_.updateEntityWithOptionalForce(entityIn, false);
      }

      p_82448_3_.theProfiler.endSection();
    }

    entityIn.setWorld(p_82448_4_);
  }
  /** Transfers an entity from a world to another world. */
  public void transferEntityToWorld(
      Entity par1Entity, int par2, WorldServer par3WorldServer, WorldServer par4WorldServer) {
    double var5 = par1Entity.posX;
    double var7 = par1Entity.posZ;
    double var9 = 8.0D;
    double var11 = par1Entity.posX;
    double var13 = par1Entity.posY;
    double var15 = par1Entity.posZ;
    float var17 = par1Entity.rotationYaw;
    par3WorldServer.theProfiler.startSection("moving");

    if (par1Entity.dimension == -1) {
      var5 /= var9;
      var7 /= var9;
      par1Entity.setLocationAndAngles(
          var5, par1Entity.posY, var7, par1Entity.rotationYaw, par1Entity.rotationPitch);

      if (par1Entity.isEntityAlive()) {
        par3WorldServer.updateEntityWithOptionalForce(par1Entity, false);
      }
    } else if (par1Entity.dimension == 0) {
      var5 *= var9;
      var7 *= var9;
      par1Entity.setLocationAndAngles(
          var5, par1Entity.posY, var7, par1Entity.rotationYaw, par1Entity.rotationPitch);

      if (par1Entity.isEntityAlive()) {
        par3WorldServer.updateEntityWithOptionalForce(par1Entity, false);
      }
    } else {
      ChunkCoordinates var18;

      if (par2 == 1) {
        var18 = par4WorldServer.getSpawnPoint();
      } else {
        var18 = par4WorldServer.getEntrancePortalLocation();
      }

      var5 = (double) var18.posX;
      par1Entity.posY = (double) var18.posY;
      var7 = (double) var18.posZ;
      par1Entity.setLocationAndAngles(var5, par1Entity.posY, var7, 90.0F, 0.0F);

      if (par1Entity.isEntityAlive()) {
        par3WorldServer.updateEntityWithOptionalForce(par1Entity, false);
      }
    }

    par3WorldServer.theProfiler.endSection();

    if (par2 != 1) {
      par3WorldServer.theProfiler.startSection("placing");
      var5 = (double) MathHelper.clamp_int((int) var5, -29999872, 29999872);
      var7 = (double) MathHelper.clamp_int((int) var7, -29999872, 29999872);

      if (par1Entity.isEntityAlive()) {
        par4WorldServer.spawnEntityInWorld(par1Entity);
        par1Entity.setLocationAndAngles(
            var5, par1Entity.posY, var7, par1Entity.rotationYaw, par1Entity.rotationPitch);
        par4WorldServer.updateEntityWithOptionalForce(par1Entity, false);
        par4WorldServer.func_85176_s().placeInPortal(par1Entity, var11, var13, var15, var17);
      }

      par3WorldServer.theProfiler.endSection();
    }

    par1Entity.setWorld(par4WorldServer);
  }